|
@@ -17,6 +17,8 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.shiro.authz.annotation.Logical;
|
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.context.annotation.PropertySource;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
@@ -38,16 +40,17 @@ import java.util.Set;
|
|
|
@Api(tags = "系统-用户管理")
|
|
|
@RestController
|
|
|
@RequestMapping("sys/user")
|
|
|
+@PropertySource("classpath:config.properties")
|
|
|
public class UserController {
|
|
|
@Autowired
|
|
|
private UserService userService;
|
|
|
@Autowired
|
|
|
- private RoleService roleService;
|
|
|
- @Autowired
|
|
|
private RedisUtil redisUtil;
|
|
|
-
|
|
|
private String prefix = "sys/user";
|
|
|
|
|
|
+ @Value("${passwordMaxLen}")
|
|
|
+ private int PASSWORD_MAX_LEN;
|
|
|
+
|
|
|
@ApiOperation("用户管理-页面鉴权")
|
|
|
@RequiresPermissions("system:user:view")
|
|
|
@GetMapping()
|
|
@@ -55,29 +58,7 @@ public class UserController {
|
|
|
return prefix + "/user";
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@ApiOperation(value = "系统-用户添加")
|
|
|
- @ApiImplicitParams({
|
|
|
- @ApiImplicitParam(name = "loginName", value = "登录名", required = true, paramType = "query"),
|
|
|
- @ApiImplicitParam(name = "status", value = "账户状态 0正常 1 停用", required = false, paramType = "query"),
|
|
|
- @ApiImplicitParam(name = "phonenumber", value = "手机号", required = false, paramType = "query"),
|
|
|
- @ApiImplicitParam(name = "deptId", value = "部门id", required = true, paramType = "query"),
|
|
|
- @ApiImplicitParam(name = "password", value = "密码", required = true, paramType = "query"),
|
|
|
- @ApiImplicitParam(name = "roleIds", value = "角色", required = false, paramType = "query"),
|
|
|
- @ApiImplicitParam(name = "userName", value = "用户名", required = true, paramType = "query"),
|
|
|
- @ApiImplicitParam(name = "remark", value = "备注", required = false, paramType = "query"),
|
|
|
- })
|
|
|
-// @PostMapping("addUser")
|
|
|
-// public Result<?> addUser(
|
|
|
-// @RequestParam(value = "loginName", required = true) String loginName,
|
|
|
-// @RequestParam(value = "status", defaultValue = "0") String status,
|
|
|
-// @RequestParam(value = "phonenumber", required = true) String phonenumber,
|
|
|
-// @RequestParam(value = "deptId", required = true) Integer deptId,
|
|
|
-// @RequestParam(value = "password", required = true) String password,
|
|
|
-// @RequestParam(value = "userName", required = true) String userName,
|
|
|
-// @RequestParam(value = "roleIds", required = true) String roleIds,
|
|
|
-// @RequestParam(value = "remark", required = false) String remark
|
|
|
-// ) {
|
|
|
@PostMapping("addUser")
|
|
|
public Result<?> addUser(@Validated SysUserVO userVO) {
|
|
|
//登录名校验
|
|
@@ -85,22 +66,18 @@ public class UserController {
|
|
|
if (ListUtil.isNotBlank(sysUserVOList)) {
|
|
|
return Result.error("登录名已存在");
|
|
|
}
|
|
|
+ if (!Validator.isMobile(userVO.getPhonenumber())) {
|
|
|
+ return Result.error("手机号格式异常");
|
|
|
+ }
|
|
|
List<SysUserVO> phone = userService.listAll(new SysUserVO(), null, null, userVO.getPhonenumber(), null, null, null);
|
|
|
if (ListUtil.isNotBlank(phone)) {
|
|
|
return Result.error("手机号已存在");
|
|
|
}
|
|
|
- if (userVO.getPassword().length() > Constant.PASSWORD_MAX_LEN) {
|
|
|
+ if (userVO.getPassword().length() > PASSWORD_MAX_LEN) {
|
|
|
throw new CustomException("密码最多8位");
|
|
|
}
|
|
|
String key = AesCipherUtil.enCrypto(userVO.getLoginName() + userVO.getPassword());
|
|
|
-// SysUserVO user = new SysUserVO();
|
|
|
-// user.setLoginName(loginName);
|
|
|
-// user.setDeptId(deptId);
|
|
|
-// user.setRemark(remark);
|
|
|
-// user.setUserName(userName);
|
|
|
-// user.setPassword(key);
|
|
|
-// user.setStatus(status);
|
|
|
-// user.setRoleIds(roleIds);
|
|
|
+ userVO.setPassword(key);
|
|
|
userService.addUser(userVO);
|
|
|
return Result.OK();
|
|
|
}
|
|
@@ -136,7 +113,6 @@ public class UserController {
|
|
|
@ApiOperation(value = "用户查询-全部 -可用于导出")
|
|
|
@PostMapping("listAll")
|
|
|
@ApiImplicitParams({
|
|
|
- // @ApiImplicitParam(name = "loginName", value = "登录名", required = true, paramType = "query"),
|
|
|
@ApiImplicitParam(name = "loginName", value = "登录名", required = false, paramType = "query"),
|
|
|
@ApiImplicitParam(name = "status", value = "账户状态 0正常 1 停用", required = false, paramType = "query"),
|
|
|
@ApiImplicitParam(name = "phonenumber", value = "手机号", required = false, paramType = "query"),
|
|
@@ -181,6 +157,9 @@ public class UserController {
|
|
|
) {
|
|
|
if (StringUtils.isNotBlank(phonenumber)) {
|
|
|
//用户手机号校验
|
|
|
+ if (!Validator.isMobile(phonenumber)) {
|
|
|
+ return Result.error("手机号格式错误");
|
|
|
+ }
|
|
|
List<SysUserDTO> user = userService.queryUserByPhone(phonenumber);
|
|
|
if (ListUtil.isNotBlank(user)) {
|
|
|
return Result.error("手机号已存在!");
|
|
@@ -197,6 +176,7 @@ public class UserController {
|
|
|
userService.updateUser(user);
|
|
|
return Result.OK();
|
|
|
}
|
|
|
+
|
|
|
@ApiOperation("密码重置")
|
|
|
@RequiresPermissions("system:user:resetPwd")
|
|
|
@PostMapping("/resetPwd")
|
|
@@ -210,7 +190,7 @@ public class UserController {
|
|
|
if (userId == 1) {
|
|
|
return Result.error("管理员账户不允许修改!");
|
|
|
}
|
|
|
- if (password.length() > Constant.PASSWORD_MAX_LEN) {
|
|
|
+ if (password.length() > PASSWORD_MAX_LEN) {
|
|
|
throw new CustomException("密码最多8位");
|
|
|
}
|
|
|
SysUserDTO user = userService.queryUserById(userId);
|
|
@@ -219,6 +199,7 @@ public class UserController {
|
|
|
userService.reSetPW(user);
|
|
|
return Result.OK();
|
|
|
}
|
|
|
+
|
|
|
@ApiOperation(value = "在线用户查看")
|
|
|
@GetMapping("/online")
|
|
|
@RequiresPermissions("online:user:view")
|
|
@@ -240,6 +221,7 @@ public class UserController {
|
|
|
}
|
|
|
return Result.OK(userDtos);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 剔除在线用户
|
|
|
*/
|