|
@@ -12,6 +12,9 @@ import com.xiaoan.service.backend.UserService;
|
|
import com.xiaoan.web.aop.WebControllerLog;
|
|
import com.xiaoan.web.aop.WebControllerLog;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.apache.shiro.authz.annotation.Logical;
|
|
|
|
+import org.apache.shiro.authz.annotation.RequiresRoles;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
@@ -38,6 +41,7 @@ public class UserController extends BaseController {
|
|
@Autowired
|
|
@Autowired
|
|
private UserService userService;
|
|
private UserService userService;
|
|
|
|
|
|
|
|
+ @RequiresRoles(value = {"admin"}, logical = Logical.OR)
|
|
@WebControllerLog(description = "用户管理-查看用户列表/搜索")
|
|
@WebControllerLog(description = "用户管理-查看用户列表/搜索")
|
|
@ApiOperation("分页获取用户列表")
|
|
@ApiOperation("分页获取用户列表")
|
|
@PostMapping("list")
|
|
@PostMapping("list")
|
|
@@ -46,13 +50,14 @@ public class UserController extends BaseController {
|
|
return new ResultJson(MsgCode.SUCCESS_CODE, page);
|
|
return new ResultJson(MsgCode.SUCCESS_CODE, page);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @RequiresRoles(value = {"admin"}, logical = Logical.OR)
|
|
@ApiOperation("新增或修改用户信息")
|
|
@ApiOperation("新增或修改用户信息")
|
|
@PostMapping("save")
|
|
@PostMapping("save")
|
|
public ResultJson save(@RequestBody UserRequest param){
|
|
public ResultJson save(@RequestBody UserRequest param){
|
|
int n = 0;
|
|
int n = 0;
|
|
|
|
|
|
- UserEntity entity = userService.findById(param.getId());
|
|
|
|
- if (entity == null ){
|
|
|
|
|
|
+ UserEntity entity = null;
|
|
|
|
+ if (param.getId() == null){
|
|
entity = userService.findByUserName(param.getUserName());
|
|
entity = userService.findByUserName(param.getUserName());
|
|
if (entity != null) {
|
|
if (entity != null) {
|
|
return new ResultJson(MsgCode.ERROR_CODE, "用户名已存在");
|
|
return new ResultJson(MsgCode.ERROR_CODE, "用户名已存在");
|
|
@@ -66,6 +71,11 @@ public class UserController extends BaseController {
|
|
|
|
|
|
n = userService.save(entity);
|
|
n = userService.save(entity);
|
|
} else {
|
|
} else {
|
|
|
|
+
|
|
|
|
+ entity = userService.findById(param.getId());
|
|
|
|
+ if (entity == null) {
|
|
|
|
+ return new ResultJson(MsgCode.FAILURE_CODE_3002, MsgCode.FAILURE_MSG_3002);
|
|
|
|
+ }
|
|
// 每次修改,删除用户角色表信息,重新添加
|
|
// 每次修改,删除用户角色表信息,重新添加
|
|
userService.deleteUserRole(param.getId());
|
|
userService.deleteUserRole(param.getId());
|
|
|
|
|
|
@@ -75,6 +85,31 @@ public class UserController extends BaseController {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+// UserEntity entity = userService.findById(param.getId());
|
|
|
|
+// if (entity == null ){
|
|
|
|
+// entity = userService.findByUserName(param.getUserName());
|
|
|
|
+// if (entity != null) {
|
|
|
|
+// return new ResultJson(MsgCode.ERROR_CODE, "用户名已存在");
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// entity = new UserEntity();
|
|
|
|
+// param.setId(null);
|
|
|
|
+//
|
|
|
|
+// BeanUtils.copyProperties(param, entity);
|
|
|
|
+// entity.setPassword(PasswordUtils.encrypt(param.getUserName(), "123456", PasswordUtils.getStaticSalt()));
|
|
|
|
+//
|
|
|
|
+// n = userService.save(entity);
|
|
|
|
+// } else {
|
|
|
|
+// // 每次修改,删除用户角色表信息,重新添加
|
|
|
|
+// userService.deleteUserRole(param.getId());
|
|
|
|
+//
|
|
|
|
+// BeanUtils.copyProperties(param, entity);
|
|
|
|
+// entity.setUpdateTime(new Date());
|
|
|
|
+// n = userService.update(entity);
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+
|
|
if (n >= 0) {
|
|
if (n >= 0) {
|
|
if (param.getRoleId() != null) {
|
|
if (param.getRoleId() != null) {
|
|
// 一个用户只有一个角色
|
|
// 一个用户只有一个角色
|
|
@@ -85,14 +120,23 @@ public class UserController extends BaseController {
|
|
return new ResultJson(MsgCode.ERROR_CODE, MsgCode.ERROR_MSG);
|
|
return new ResultJson(MsgCode.ERROR_CODE, MsgCode.ERROR_MSG);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @RequiresRoles(value = {"admin"}, logical = Logical.OR)
|
|
@ApiOperation("删除用户")
|
|
@ApiOperation("删除用户")
|
|
@GetMapping("delete/{id}")
|
|
@GetMapping("delete/{id}")
|
|
public ResultJson delete(@PathVariable Long id){
|
|
public ResultJson delete(@PathVariable Long id){
|
|
userService.deleteById(id);
|
|
userService.deleteById(id);
|
|
-// userService.deleteUserRole(id);
|
|
|
|
return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.SUCCESS_MSG);
|
|
return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.SUCCESS_MSG);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @RequiresRoles(value = {"admin"}, logical = Logical.OR)
|
|
|
|
+ @ApiOperation("删除多用户")
|
|
|
|
+ @GetMapping("delete/all/{id}")
|
|
|
|
+ public ResultJson deleteAll(@PathVariable String id){
|
|
|
|
+ userService.deleteByIds(id);
|
|
|
|
+ return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.SUCCESS_MSG);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
@ApiOperation("查询用户信息")
|
|
@ApiOperation("查询用户信息")
|
|
@GetMapping("detail/{id}")
|
|
@GetMapping("detail/{id}")
|
|
public ResultJson detail(@PathVariable Long id){
|
|
public ResultJson detail(@PathVariable Long id){
|
|
@@ -116,6 +160,7 @@ public class UserController extends BaseController {
|
|
return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.SUCCESS_MSG);
|
|
return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.SUCCESS_MSG);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @RequiresRoles(value = {"admin"}, logical = Logical.OR)
|
|
@ApiOperation("重置密码")
|
|
@ApiOperation("重置密码")
|
|
@GetMapping("resetPass/{id}")
|
|
@GetMapping("resetPass/{id}")
|
|
public ResultJson resetPass(@PathVariable Long id){
|
|
public ResultJson resetPass(@PathVariable Long id){
|