From 8874c90db2c238fa4c55df491675fe7fec9d93b2 Mon Sep 17 00:00:00 2001
From: fine <54142345+criver31@users.noreply.github.com>
Date: 星期二, 09 一月 2024 11:45:30 +0800
Subject: [PATCH] Merge branch '648540858:wvp-28181-2.0' into wvp-28181-2.0
---
src/main/java/com/genersoft/iot/vmp/vmanager/user/RoleController.java | 84 +++++++++++++++---------------------------
1 files changed, 30 insertions(+), 54 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/user/RoleController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/user/RoleController.java
old mode 100644
new mode 100755
index 6a75e1d..815b239
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/user/RoleController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/user/RoleController.java
@@ -1,28 +1,23 @@
package com.genersoft.iot.vmp.vmanager.user;
+import com.genersoft.iot.vmp.conf.exception.ControllerException;
+import com.genersoft.iot.vmp.conf.security.JwtUtils;
import com.genersoft.iot.vmp.conf.security.SecurityUtils;
import com.genersoft.iot.vmp.service.IRoleService;
-import com.genersoft.iot.vmp.service.IUserService;
import com.genersoft.iot.vmp.storager.dao.dto.Role;
-import com.genersoft.iot.vmp.storager.dao.dto.User;
-import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiImplicitParams;
-import io.swagger.annotations.ApiOperation;
+import com.genersoft.iot.vmp.utils.DateUtil;
+import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.security.SecurityRequirement;
+import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-import org.springframework.security.authentication.AuthenticationManager;
-import org.springframework.util.DigestUtils;
-import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
-import java.text.SimpleDateFormat;
import java.util.List;
-@Api(tags = "瑙掕壊绠$悊")
-@CrossOrigin
+@Tag(name = "瑙掕壊绠$悊")
+
@RestController
@RequestMapping("/api/role")
public class RoleController {
@@ -30,72 +25,53 @@
@Autowired
private IRoleService roleService;
- private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-
- @ApiOperation("娣诲姞瑙掕壊")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "name", required = true, value = "瑙掕壊鍚�", dataTypeClass = String.class),
- @ApiImplicitParam(name = "authority", required = true, value = "鏉冮檺锛堣嚜琛屽畾涔夊唴瀹癸紝鐩墠鏈娇鐢級", dataTypeClass = String.class),
- })
@PostMapping("/add")
- public ResponseEntity<WVPResult<Integer>> add(@RequestParam String name,
+ @Operation(summary = "娣诲姞瑙掕壊", security = @SecurityRequirement(name = JwtUtils.HEADER))
+ @Parameter(name = "name", description = "瑙掕壊鍚�", required = true)
+ @Parameter(name = "authority", description = "鏉冮檺锛堣嚜琛屽畾涔夊唴瀹癸紝鐩墠鏈娇鐢級", required = true)
+ public void add(@RequestParam String name,
@RequestParam(required = false) String authority){
- WVPResult<Integer> result = new WVPResult<>();
// 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛id
int currenRoleId = SecurityUtils.getUserInfo().getRole().getId();
if (currenRoleId != 1) {
// 鍙敤瑙掕壊id涓�1鎵嶅彲浠ュ垹闄ゅ拰娣诲姞鐢ㄦ埛
- result.setCode(-1);
- result.setMsg("鐢ㄦ埛鏃犳潈闄�");
- return new ResponseEntity<>(result, HttpStatus.FORBIDDEN);
+ throw new ControllerException(ErrorCode.ERROR403);
}
Role role = new Role();
role.setName(name);
role.setAuthority(authority);
- role.setCreateTime(format.format(System.currentTimeMillis()));
- role.setUpdateTime(format.format(System.currentTimeMillis()));
+ role.setCreateTime(DateUtil.getNow());
+ role.setUpdateTime(DateUtil.getNow());
int addResult = roleService.add(role);
-
- result.setCode(addResult > 0 ? 0 : -1);
- result.setMsg(addResult > 0 ? "success" : "fail");
- result.setData(addResult);
- return new ResponseEntity<>(result, HttpStatus.OK);
+ if (addResult <= 0) {
+ throw new ControllerException(ErrorCode.ERROR100);
+ }
}
- @ApiOperation("鍒犻櫎瑙掕壊")
- @ApiImplicitParams({
- @ApiImplicitParam(name = "id", required = true, value = "鐢ㄦ埛Id", dataTypeClass = Integer.class),
- })
@DeleteMapping("/delete")
- public ResponseEntity<WVPResult<String>> delete(@RequestParam Integer id){
+ @Operation(summary = "鍒犻櫎瑙掕壊", security = @SecurityRequirement(name = JwtUtils.HEADER))
+ @Parameter(name = "id", description = "鐢ㄦ埛Id", required = true)
+ public void delete(@RequestParam Integer id){
// 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛id
int currenRoleId = SecurityUtils.getUserInfo().getRole().getId();
- WVPResult<String> result = new WVPResult<>();
if (currenRoleId != 1) {
// 鍙敤瑙掕壊id涓�0鎵嶅彲浠ュ垹闄ゅ拰娣诲姞鐢ㄦ埛
- result.setCode(-1);
- result.setMsg("鐢ㄦ埛鏃犳潈闄�");
- return new ResponseEntity<>(result, HttpStatus.FORBIDDEN);
+ throw new ControllerException(ErrorCode.ERROR403);
}
int deleteResult = roleService.delete(id);
- result.setCode(deleteResult>0? 0 : -1);
- result.setMsg(deleteResult>0? "success" : "fail");
- return new ResponseEntity<>(result, HttpStatus.OK);
+ if (deleteResult <= 0) {
+ throw new ControllerException(ErrorCode.ERROR100);
+ }
}
- @ApiOperation("鏌ヨ瑙掕壊")
- @ApiImplicitParams({})
@GetMapping("/all")
- public ResponseEntity<WVPResult<List<Role>>> all(){
+ @Operation(summary = "鏌ヨ瑙掕壊", security = @SecurityRequirement(name = JwtUtils.HEADER))
+ public List<Role> all(){
// 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛id
List<Role> allRoles = roleService.getAll();
- WVPResult<List<Role>> result = new WVPResult<>();
- result.setCode(0);
- result.setMsg("success");
- result.setData(allRoles);
- return new ResponseEntity<>(result, HttpStatus.OK);
+ return roleService.getAll();
}
}
--
Gitblit v1.8.0