|
@@ -13,6 +13,7 @@ import com.jiayue.ssi.backenum.ApproveStatusEnum;
|
|
import com.jiayue.ssi.backenum.AuditType;
|
|
import com.jiayue.ssi.backenum.AuditType;
|
|
import com.jiayue.ssi.backenum.BusinessType;
|
|
import com.jiayue.ssi.backenum.BusinessType;
|
|
import com.jiayue.ssi.config.SendMailUtil;
|
|
import com.jiayue.ssi.config.SendMailUtil;
|
|
|
|
+import com.jiayue.ssi.constant.CustomException;
|
|
import com.jiayue.ssi.constant.SecretKeyConstants;
|
|
import com.jiayue.ssi.constant.SecretKeyConstants;
|
|
import com.jiayue.ssi.entity.SysApprove;
|
|
import com.jiayue.ssi.entity.SysApprove;
|
|
import com.jiayue.ssi.entity.SysUser;
|
|
import com.jiayue.ssi.entity.SysUser;
|
|
@@ -59,7 +60,7 @@ public class SysUserController {
|
|
@GetMapping(value = "/getAll")
|
|
@GetMapping(value = "/getAll")
|
|
@PreAuthorize("@ss.hasPermi('system:user:list')")
|
|
@PreAuthorize("@ss.hasPermi('system:user:list')")
|
|
public ResponseVO getAll(Integer currentPage, Integer pageSize, String username, String phonenumber,
|
|
public ResponseVO getAll(Integer currentPage, Integer pageSize, String username, String phonenumber,
|
|
- String status) {
|
|
|
|
|
|
+ String status) throws CustomException {
|
|
try {
|
|
try {
|
|
if (StringUtils.isNotEmpty(username)) {
|
|
if (StringUtils.isNotEmpty(username)) {
|
|
if (username.length() > 20) {
|
|
if (username.length() > 20) {
|
|
@@ -76,7 +77,7 @@ public class SysUserController {
|
|
wrapper.eq("username", username);
|
|
wrapper.eq("username", username);
|
|
}
|
|
}
|
|
if (StringUtils.isNotEmpty(phonenumber)) {
|
|
if (StringUtils.isNotEmpty(phonenumber)) {
|
|
- wrapper.eq("AES_DECRYPT(UNHEX(phonenumber), '"+new String(AesUtils.key)+"')", phonenumber);
|
|
|
|
|
|
+ wrapper.eq("AES_DECRYPT(UNHEX(phonenumber), '" + new String(AesUtils.key) + "')", phonenumber);
|
|
}
|
|
}
|
|
if (StringUtils.isNotEmpty(status)) {
|
|
if (StringUtils.isNotEmpty(status)) {
|
|
wrapper.eq("status", status);
|
|
wrapper.eq("status", status);
|
|
@@ -85,7 +86,7 @@ public class SysUserController {
|
|
List<SysUser> records = result.getRecords();
|
|
List<SysUser> records = result.getRecords();
|
|
//遍历对象数组的方法
|
|
//遍历对象数组的方法
|
|
records.forEach(
|
|
records.forEach(
|
|
- record->{
|
|
|
|
|
|
+ record -> {
|
|
record.setMailbox(AesUtils.decryptStr(record.getMailbox()));
|
|
record.setMailbox(AesUtils.decryptStr(record.getMailbox()));
|
|
record.setPhonenumber(AesUtils.decryptStr(record.getPhonenumber()));
|
|
record.setPhonenumber(AesUtils.decryptStr(record.getPhonenumber()));
|
|
record.setNickname(AesUtils.decryptStr(record.getNickname()));
|
|
record.setNickname(AesUtils.decryptStr(record.getNickname()));
|
|
@@ -93,9 +94,7 @@ public class SysUserController {
|
|
);
|
|
);
|
|
return ResponseVO.success(result);
|
|
return ResponseVO.success(result);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- e.printStackTrace();
|
|
|
|
- log.error("获取所有用户异常");
|
|
|
|
- return ResponseVO.error(null);
|
|
|
|
|
|
+ throw new CustomException("获取所有用户异常", e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -105,7 +104,7 @@ public class SysUserController {
|
|
* @return 用户信息
|
|
* @return 用户信息
|
|
*/
|
|
*/
|
|
@GetMapping(value = "/getCurrentUser")
|
|
@GetMapping(value = "/getCurrentUser")
|
|
- public ResponseVO getCurrentUser() {
|
|
|
|
|
|
+ public ResponseVO getCurrentUser() throws CustomException {
|
|
try {
|
|
try {
|
|
SysUser sysUser = SecurityContextUtil.getSysUser();
|
|
SysUser sysUser = SecurityContextUtil.getSysUser();
|
|
// 权限集合
|
|
// 权限集合
|
|
@@ -118,9 +117,7 @@ public class SysUserController {
|
|
map.put("permissions", permissions);
|
|
map.put("permissions", permissions);
|
|
return ResponseVO.success(map);
|
|
return ResponseVO.success(map);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- e.printStackTrace();
|
|
|
|
- log.error("获取当前用户异常");
|
|
|
|
- return ResponseVO.error(null);
|
|
|
|
|
|
+ throw new CustomException("获取当前用户异常", e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -130,50 +127,49 @@ public class SysUserController {
|
|
@PostMapping(value = "/addUser")
|
|
@PostMapping(value = "/addUser")
|
|
@OperateLog(title = "用户管理", businessType = BusinessType.INSERT, auditType = AuditType.SYS)
|
|
@OperateLog(title = "用户管理", businessType = BusinessType.INSERT, auditType = AuditType.SYS)
|
|
@PreAuthorize("@ss.hasPermi('system:user:add')")
|
|
@PreAuthorize("@ss.hasPermi('system:user:add')")
|
|
- public ResponseVO addUser(@RequestBody SysUser user) {
|
|
|
|
- if (StringUtils.isEmpty(user.getUsername())) {
|
|
|
|
- return ResponseVO.fail("用户账号不能为空!");
|
|
|
|
- } else if (sysUserService.queryUserName(user.getUsername()) != null) {
|
|
|
|
- return ResponseVO.fail(user.getUsername() + "账号已存在!");
|
|
|
|
- } else if (user.getUsername().length() < 5 || user.getUsername().length() > 20) {
|
|
|
|
- return ResponseVO.fail(user.getUsername() + "用户账号长度必须介于5和20之间!");
|
|
|
|
- }
|
|
|
|
|
|
+ public ResponseVO addUser(@RequestBody SysUser user) throws CustomException {
|
|
|
|
+ try {
|
|
|
|
+ if (StringUtils.isEmpty(user.getUsername())) {
|
|
|
|
+ return ResponseVO.fail("用户账号不能为空!");
|
|
|
|
+ } else if (sysUserService.queryUserName(user.getUsername()) != null) {
|
|
|
|
+ return ResponseVO.fail(user.getUsername() + "账号已存在!");
|
|
|
|
+ } else if (user.getUsername().length() < 5 || user.getUsername().length() > 20) {
|
|
|
|
+ return ResponseVO.fail(user.getUsername() + "用户账号长度必须介于5和20之间!");
|
|
|
|
+ }
|
|
|
|
|
|
- if (StringUtils.isEmpty(user.getPhonenumber())) {
|
|
|
|
- return ResponseVO.fail("手机号码不能为空!");
|
|
|
|
- } else if (!Validator.isMobile(user.getPhonenumber())) {
|
|
|
|
- return ResponseVO.fail("请输入正确的手机号码!");
|
|
|
|
- }
|
|
|
|
- // 加密手机号
|
|
|
|
- user.setPhonenumber(AesUtils.encryptHex(user.getPhonenumber()).toUpperCase());
|
|
|
|
|
|
+ if (StringUtils.isEmpty(user.getPhonenumber())) {
|
|
|
|
+ return ResponseVO.fail("手机号码不能为空!");
|
|
|
|
+ } else if (!Validator.isMobile(user.getPhonenumber())) {
|
|
|
|
+ return ResponseVO.fail("请输入正确的手机号码!");
|
|
|
|
+ }
|
|
|
|
+ // 加密手机号
|
|
|
|
+ user.setPhonenumber(AesUtils.encryptHex(user.getPhonenumber()).toUpperCase());
|
|
|
|
|
|
- if (StringUtils.isEmpty(user.getNickname())) {
|
|
|
|
- return ResponseVO.fail("姓名不能为空!");
|
|
|
|
- } else if (user.getNickname().length() > 30) {
|
|
|
|
- return ResponseVO.fail("姓名长度不能超过30个字符!");
|
|
|
|
- }
|
|
|
|
- // 加密姓名
|
|
|
|
- user.setNickname(AesUtils.encryptHex(user.getNickname()).toUpperCase());
|
|
|
|
|
|
+ if (StringUtils.isEmpty(user.getNickname())) {
|
|
|
|
+ return ResponseVO.fail("姓名不能为空!");
|
|
|
|
+ } else if (user.getNickname().length() > 30) {
|
|
|
|
+ return ResponseVO.fail("姓名长度不能超过30个字符!");
|
|
|
|
+ }
|
|
|
|
+ // 加密姓名
|
|
|
|
+ user.setNickname(AesUtils.encryptHex(user.getNickname()).toUpperCase());
|
|
|
|
|
|
- if (StringUtils.isEmpty(user.getMailbox())) {
|
|
|
|
- return ResponseVO.fail("邮箱不能为空!");
|
|
|
|
- } else if (!Validator.isEmail(user.getMailbox())) {
|
|
|
|
- return ResponseVO.fail("请输入正确的邮箱地址!");
|
|
|
|
- } else if (user.getMailbox().length() > 50) {
|
|
|
|
- return ResponseVO.fail("邮箱长度不能超过50个字符!");
|
|
|
|
- } else if (sysUserService.queryMailBox(user.getMailbox()) != null) {
|
|
|
|
- return ResponseVO.fail(user.getMailbox() + "邮箱已存在!");
|
|
|
|
- }
|
|
|
|
- // 加密邮箱
|
|
|
|
- user.setMailbox(AesUtils.encryptHex(user.getMailbox()).toUpperCase());
|
|
|
|
|
|
+ if (StringUtils.isEmpty(user.getMailbox())) {
|
|
|
|
+ return ResponseVO.fail("邮箱不能为空!");
|
|
|
|
+ } else if (!Validator.isEmail(user.getMailbox())) {
|
|
|
|
+ return ResponseVO.fail("请输入正确的邮箱地址!");
|
|
|
|
+ } else if (user.getMailbox().length() > 50) {
|
|
|
|
+ return ResponseVO.fail("邮箱长度不能超过50个字符!");
|
|
|
|
+ } else if (sysUserService.queryMailBox(user.getMailbox()) != null) {
|
|
|
|
+ return ResponseVO.fail(user.getMailbox() + "邮箱已存在!");
|
|
|
|
+ }
|
|
|
|
+ // 加密邮箱
|
|
|
|
+ user.setMailbox(AesUtils.encryptHex(user.getMailbox()).toUpperCase());
|
|
|
|
|
|
// // 生成8位初始密码
|
|
// // 生成8位初始密码
|
|
// String randomPwd = RandomPwd.getRandomPwd(8);
|
|
// String randomPwd = RandomPwd.getRandomPwd(8);
|
|
// user.setPassword(SmUtil.sm3(randomPwd).toUpperCase());
|
|
// user.setPassword(SmUtil.sm3(randomPwd).toUpperCase());
|
|
// user.setErrNum(0);
|
|
// user.setErrNum(0);
|
|
// user.setLockTime(0L);
|
|
// user.setLockTime(0L);
|
|
-
|
|
|
|
- try {
|
|
|
|
boolean bo = sysUserService.save(user);
|
|
boolean bo = sysUserService.save(user);
|
|
if (bo) {
|
|
if (bo) {
|
|
return ResponseVO.success("添加用户信息成功");
|
|
return ResponseVO.success("添加用户信息成功");
|
|
@@ -182,9 +178,7 @@ public class SysUserController {
|
|
return ResponseVO.fail("添加用户信息失败");
|
|
return ResponseVO.fail("添加用户信息失败");
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- e.printStackTrace();
|
|
|
|
- log.error("添加用户信息异常");
|
|
|
|
- return ResponseVO.error(e);
|
|
|
|
|
|
+ throw new CustomException("添加用户信息异常", e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -197,53 +191,54 @@ public class SysUserController {
|
|
@PostMapping(value = "/updateUser")
|
|
@PostMapping(value = "/updateUser")
|
|
@OperateLog(title = "用户管理", businessType = BusinessType.UPDATE, auditType = AuditType.SYS)
|
|
@OperateLog(title = "用户管理", businessType = BusinessType.UPDATE, auditType = AuditType.SYS)
|
|
@PreAuthorize("@ss.hasPermi('system:user:edit')")
|
|
@PreAuthorize("@ss.hasPermi('system:user:edit')")
|
|
- public ResponseVO updateUser(@RequestBody SysUser user) {
|
|
|
|
- SysUser existUser = sysUserService.getById(user.getId());
|
|
|
|
- if (existUser == null) {
|
|
|
|
- return ResponseVO.fail("非法访问不能修改!");
|
|
|
|
- }
|
|
|
|
|
|
+ public ResponseVO updateUser(@RequestBody SysUser user) throws CustomException {
|
|
|
|
+ try {
|
|
|
|
+ SysUser existUser = sysUserService.getById(user.getId());
|
|
|
|
+ if (existUser == null) {
|
|
|
|
+ return ResponseVO.fail("非法访问不能修改!");
|
|
|
|
+ }
|
|
|
|
|
|
- if (StringUtils.isEmpty(user.getUsername())) {
|
|
|
|
- return ResponseVO.fail("用户账号不能为空!");
|
|
|
|
- } else if (user.getUsername().length() < 5 || user.getUsername().length() > 20) {
|
|
|
|
- return ResponseVO.fail(user.getUsername() + "用户账号长度必须介于5和20之间!");
|
|
|
|
- } else if (!existUser.getUsername().equals(user.getUsername())) {
|
|
|
|
- if (sysUserService.queryUserName(user.getUsername()) != null) {
|
|
|
|
- return ResponseVO.fail(user.getUsername() + "账号已存在!");
|
|
|
|
|
|
+ if (StringUtils.isEmpty(user.getUsername())) {
|
|
|
|
+ return ResponseVO.fail("用户账号不能为空!");
|
|
|
|
+ } else if (user.getUsername().length() < 5 || user.getUsername().length() > 20) {
|
|
|
|
+ return ResponseVO.fail(user.getUsername() + "用户账号长度必须介于5和20之间!");
|
|
|
|
+ } else if (!existUser.getUsername().equals(user.getUsername())) {
|
|
|
|
+ if (sysUserService.queryUserName(user.getUsername()) != null) {
|
|
|
|
+ return ResponseVO.fail(user.getUsername() + "账号已存在!");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- if (StringUtils.isEmpty(user.getMailbox())) {
|
|
|
|
- return ResponseVO.fail("邮箱不能为空!");
|
|
|
|
- } else if (!Validator.isEmail(user.getMailbox())) {
|
|
|
|
- return ResponseVO.fail("请输入正确的邮箱地址!");
|
|
|
|
- } else if (user.getMailbox().length() > 50) {
|
|
|
|
- return ResponseVO.fail("邮箱长度不能超过50个字符!");
|
|
|
|
- } else if (!existUser.getMailbox().equals(user.getMailbox())) {
|
|
|
|
- if (sysUserService.queryMailBox(user.getMailbox()) != null) {
|
|
|
|
- return ResponseVO.fail(user.getMailbox() + "邮箱已存在!");
|
|
|
|
|
|
+ if (StringUtils.isEmpty(user.getMailbox())) {
|
|
|
|
+ return ResponseVO.fail("邮箱不能为空!");
|
|
|
|
+ } else if (!Validator.isEmail(user.getMailbox())) {
|
|
|
|
+ return ResponseVO.fail("请输入正确的邮箱地址!");
|
|
|
|
+ } else if (user.getMailbox().length() > 50) {
|
|
|
|
+ return ResponseVO.fail("邮箱长度不能超过50个字符!");
|
|
|
|
+ } else if (!existUser.getMailbox().equals(user.getMailbox())) {
|
|
|
|
+ if (sysUserService.queryMailBox(user.getMailbox()) != null) {
|
|
|
|
+ return ResponseVO.fail(user.getMailbox() + "邮箱已存在!");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
- // 加密邮箱
|
|
|
|
- user.setMailbox(AesUtils.encryptHex(user.getMailbox()).toUpperCase());
|
|
|
|
|
|
+ // 加密邮箱
|
|
|
|
+ user.setMailbox(AesUtils.encryptHex(user.getMailbox()).toUpperCase());
|
|
|
|
|
|
- if (StringUtils.isEmpty(user.getPhonenumber())) {
|
|
|
|
- return ResponseVO.fail("手机号码不能为空!");
|
|
|
|
- } else if (!Validator.isMobile(user.getPhonenumber())) {
|
|
|
|
- return ResponseVO.fail("请输入正确的手机号码!");
|
|
|
|
- }
|
|
|
|
- // 加密手机号
|
|
|
|
- user.setPhonenumber(AesUtils.encryptHex(user.getPhonenumber()).toUpperCase());
|
|
|
|
|
|
+ if (StringUtils.isEmpty(user.getPhonenumber())) {
|
|
|
|
+ return ResponseVO.fail("手机号码不能为空!");
|
|
|
|
+ } else if (!Validator.isMobile(user.getPhonenumber())) {
|
|
|
|
+ return ResponseVO.fail("请输入正确的手机号码!");
|
|
|
|
+ }
|
|
|
|
+ // 加密手机号
|
|
|
|
+ user.setPhonenumber(AesUtils.encryptHex(user.getPhonenumber()).toUpperCase());
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isEmpty(user.getNickname())) {
|
|
|
|
+ return ResponseVO.fail("姓名不能为空!");
|
|
|
|
+ } else if (user.getNickname().length() > 30) {
|
|
|
|
+ return ResponseVO.fail("姓名长度不能超过30个字符!");
|
|
|
|
+ }
|
|
|
|
+ // 加密姓名
|
|
|
|
+ user.setNickname(AesUtils.encryptHex(user.getNickname()).toUpperCase());
|
|
|
|
|
|
- if (StringUtils.isEmpty(user.getNickname())) {
|
|
|
|
- return ResponseVO.fail("姓名不能为空!");
|
|
|
|
- } else if (user.getNickname().length() > 30) {
|
|
|
|
- return ResponseVO.fail("姓名长度不能超过30个字符!");
|
|
|
|
- }
|
|
|
|
- // 加密姓名
|
|
|
|
- user.setNickname(AesUtils.encryptHex(user.getNickname()).toUpperCase());
|
|
|
|
|
|
|
|
- try {
|
|
|
|
if ("0".equals(user.getStatus())) {
|
|
if ("0".equals(user.getStatus())) {
|
|
user.setErrNum(0);
|
|
user.setErrNum(0);
|
|
user.setLockTime(0L);
|
|
user.setLockTime(0L);
|
|
@@ -256,9 +251,7 @@ public class SysUserController {
|
|
return ResponseVO.fail("修改用户信息失败");
|
|
return ResponseVO.fail("修改用户信息失败");
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- e.printStackTrace();
|
|
|
|
- log.error("修改用户信息异常");
|
|
|
|
- return ResponseVO.error(e);
|
|
|
|
|
|
+ throw new CustomException("修改用户信息异常", e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -300,16 +293,17 @@ public class SysUserController {
|
|
@AgainVerify
|
|
@AgainVerify
|
|
@OperateLog(title = "用户管理", businessType = BusinessType.DELETE, auditType = AuditType.SYS)
|
|
@OperateLog(title = "用户管理", businessType = BusinessType.DELETE, auditType = AuditType.SYS)
|
|
@PreAuthorize("@ss.hasPermi('system:user:remove')")
|
|
@PreAuthorize("@ss.hasPermi('system:user:remove')")
|
|
- public ResponseVO delete(String id) {
|
|
|
|
- if (StringUtils.isEmpty(id)) {
|
|
|
|
- return ResponseVO.fail("id不能为空!");
|
|
|
|
- }
|
|
|
|
- // id获取用户
|
|
|
|
- SysUser sysUser = sysUserService.getById(id);
|
|
|
|
- if (sysUser == null) {
|
|
|
|
- return ResponseVO.fail("不能删除用户!");
|
|
|
|
- }
|
|
|
|
|
|
+ public ResponseVO delete(String id) throws CustomException {
|
|
try {
|
|
try {
|
|
|
|
+ if (StringUtils.isEmpty(id)) {
|
|
|
|
+ return ResponseVO.fail("id不能为空!");
|
|
|
|
+ }
|
|
|
|
+ // id获取用户
|
|
|
|
+ SysUser sysUser = sysUserService.getById(id);
|
|
|
|
+ if (sysUser == null) {
|
|
|
|
+ return ResponseVO.fail("不能删除用户!");
|
|
|
|
+ }
|
|
|
|
+
|
|
// 获取审批表是否存在此操作
|
|
// 获取审批表是否存在此操作
|
|
QueryWrapper<SysApprove> wrapper = new QueryWrapper<>();
|
|
QueryWrapper<SysApprove> wrapper = new QueryWrapper<>();
|
|
// 条件:待审批
|
|
// 条件:待审批
|
|
@@ -319,7 +313,7 @@ public class SysUserController {
|
|
// 条件:实体名
|
|
// 条件:实体名
|
|
wrapper.eq("entity_name", "SysUser");
|
|
wrapper.eq("entity_name", "SysUser");
|
|
List<SysApprove> list = sysApproveService.list(wrapper);
|
|
List<SysApprove> list = sysApproveService.list(wrapper);
|
|
- if (list.size()>0){
|
|
|
|
|
|
+ if (list.size() > 0) {
|
|
return ResponseVO.fail("此记录存在未审批的操作,不能进行删除!");
|
|
return ResponseVO.fail("此记录存在未审批的操作,不能进行删除!");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -331,9 +325,7 @@ public class SysUserController {
|
|
return ResponseVO.fail("删除用户信息失败");
|
|
return ResponseVO.fail("删除用户信息失败");
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- e.printStackTrace();
|
|
|
|
- log.error("删除用户信息异常");
|
|
|
|
- return ResponseVO.error(e);
|
|
|
|
|
|
+ throw new CustomException("删除用户信息异常", e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -342,53 +334,57 @@ public class SysUserController {
|
|
*/
|
|
*/
|
|
@PostMapping(value = "/updatePassword")
|
|
@PostMapping(value = "/updatePassword")
|
|
@OperateLog(title = "用户管理", businessType = BusinessType.UPDATE, auditType = AuditType.SYS)
|
|
@OperateLog(title = "用户管理", businessType = BusinessType.UPDATE, auditType = AuditType.SYS)
|
|
- public ResponseVO updatePassword(String id, String oldPassword, String newPassword, String confirmPassword) {
|
|
|
|
- if (StringUtils.isEmpty(id)) {
|
|
|
|
- return ResponseVO.fail("修改密码缺失id!");
|
|
|
|
- }
|
|
|
|
- // id获取用户
|
|
|
|
- SysUser sysUser = sysUserService.getById(id);
|
|
|
|
- if (sysUser == null) {
|
|
|
|
- return ResponseVO.fail("修改密码失败!");
|
|
|
|
- }
|
|
|
|
|
|
+ public ResponseVO updatePassword(String id, String oldPassword, String newPassword, String confirmPassword) throws CustomException {
|
|
|
|
+ try {
|
|
|
|
+ if (StringUtils.isEmpty(id)) {
|
|
|
|
+ return ResponseVO.fail("修改密码缺失id!");
|
|
|
|
+ }
|
|
|
|
+ // id获取用户
|
|
|
|
+ SysUser sysUser = sysUserService.getById(id);
|
|
|
|
+ if (sysUser == null) {
|
|
|
|
+ return ResponseVO.fail("修改密码失败!");
|
|
|
|
+ }
|
|
|
|
|
|
- if (StringUtils.isEmpty(oldPassword)) {
|
|
|
|
- return ResponseVO.fail("旧密码不能为空!");
|
|
|
|
- } else if (!sysUser.getPassword().equals(SmUtil.sm3(oldPassword).toUpperCase())) {
|
|
|
|
- return ResponseVO.fail("旧密码不正确!");
|
|
|
|
- }
|
|
|
|
|
|
+ if (StringUtils.isEmpty(oldPassword)) {
|
|
|
|
+ return ResponseVO.fail("旧密码不能为空!");
|
|
|
|
+ } else if (!sysUser.getPassword().equals(SmUtil.sm3(oldPassword).toUpperCase())) {
|
|
|
|
+ return ResponseVO.fail("旧密码不正确!");
|
|
|
|
+ }
|
|
|
|
|
|
- if (StringUtils.isEmpty(newPassword)) {
|
|
|
|
- return ResponseVO.fail("新密码不能为空!");
|
|
|
|
- } else if (StringUtils.isEmpty(confirmPassword)) {
|
|
|
|
- return ResponseVO.fail("确认密码不能为空!");
|
|
|
|
- } else if (!newPassword.equals(confirmPassword)) {
|
|
|
|
- return ResponseVO.fail("新密码两次输入的密码不一致!");
|
|
|
|
- }
|
|
|
|
- // 对新密码规则验证
|
|
|
|
- if (newPassword.contains(sysUser.getUsername())) {
|
|
|
|
- return ResponseVO.fail("密码不能含有账号!");
|
|
|
|
- }
|
|
|
|
- if (SmUtil.sm3(newPassword).toUpperCase().equals(sysUser.getPassword())) {
|
|
|
|
- return ResponseVO.fail("新密码不能与上次密码相同!");
|
|
|
|
- }
|
|
|
|
- if (RegexUtil.sameReg(newPassword)) {
|
|
|
|
- return ResponseVO.fail("新密码不能含有连续4位相同的数字或字母!");
|
|
|
|
- } else if (RegexUtil.keyboardSlopeArr(newPassword)) {
|
|
|
|
- return ResponseVO.fail("新密码不能含有4位斜方向连续的字符!");
|
|
|
|
- } else if (RegexUtil.keyboardHorizontalReg(newPassword)) {
|
|
|
|
- return ResponseVO.fail("新密码不能含有4位连续的字符!");
|
|
|
|
- } else if (!RegexUtil.checkPwd(newPassword)) {
|
|
|
|
- return ResponseVO.fail("新密码不满足8~20位大写字母、小写字母、数字、特殊字符三种以上的组合!");
|
|
|
|
- }
|
|
|
|
|
|
+ if (StringUtils.isEmpty(newPassword)) {
|
|
|
|
+ return ResponseVO.fail("新密码不能为空!");
|
|
|
|
+ } else if (StringUtils.isEmpty(confirmPassword)) {
|
|
|
|
+ return ResponseVO.fail("确认密码不能为空!");
|
|
|
|
+ } else if (!newPassword.equals(confirmPassword)) {
|
|
|
|
+ return ResponseVO.fail("新密码两次输入的密码不一致!");
|
|
|
|
+ }
|
|
|
|
+ // 对新密码规则验证
|
|
|
|
+ if (newPassword.contains(sysUser.getUsername())) {
|
|
|
|
+ return ResponseVO.fail("密码不能含有账号!");
|
|
|
|
+ }
|
|
|
|
+ if (SmUtil.sm3(newPassword).toUpperCase().equals(sysUser.getPassword())) {
|
|
|
|
+ return ResponseVO.fail("新密码不能与上次密码相同!");
|
|
|
|
+ }
|
|
|
|
+ if (RegexUtil.sameReg(newPassword)) {
|
|
|
|
+ return ResponseVO.fail("新密码不能含有连续4位相同的数字或字母!");
|
|
|
|
+ } else if (RegexUtil.keyboardSlopeArr(newPassword)) {
|
|
|
|
+ return ResponseVO.fail("新密码不能含有4位斜方向连续的字符!");
|
|
|
|
+ } else if (RegexUtil.keyboardHorizontalReg(newPassword)) {
|
|
|
|
+ return ResponseVO.fail("新密码不能含有4位连续的字符!");
|
|
|
|
+ } else if (!RegexUtil.checkPwd(newPassword)) {
|
|
|
|
+ return ResponseVO.fail("新密码不满足8~20位大写字母、小写字母、数字、特殊字符三种以上的组合!");
|
|
|
|
+ }
|
|
|
|
|
|
- sysUser.setPassword(SmUtil.sm3(newPassword).toUpperCase());
|
|
|
|
- sysUser.setLastUpdatePwdTime(new Date());
|
|
|
|
- boolean bo = sysUserService.updateById(sysUser);
|
|
|
|
- if (!bo) {
|
|
|
|
- return ResponseVO.fail("修改密码失败!");
|
|
|
|
|
|
+ sysUser.setPassword(SmUtil.sm3(newPassword).toUpperCase());
|
|
|
|
+ sysUser.setLastUpdatePwdTime(new Date());
|
|
|
|
+ boolean bo = sysUserService.updateById(sysUser);
|
|
|
|
+ if (!bo) {
|
|
|
|
+ return ResponseVO.fail("修改密码失败!");
|
|
|
|
+ }
|
|
|
|
+ return ResponseVO.success();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw new CustomException("修改密码异常", e);
|
|
}
|
|
}
|
|
- return ResponseVO.success();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -397,19 +393,20 @@ public class SysUserController {
|
|
@PostMapping(value = "/relockUser")
|
|
@PostMapping(value = "/relockUser")
|
|
@OperateLog(title = "用户管理", businessType = BusinessType.OTHER, auditType = AuditType.SYS)
|
|
@OperateLog(title = "用户管理", businessType = BusinessType.OTHER, auditType = AuditType.SYS)
|
|
@PreAuthorize("@ss.hasPermi('system:user:relock')")
|
|
@PreAuthorize("@ss.hasPermi('system:user:relock')")
|
|
- public ResponseVO relockUser(String id) {
|
|
|
|
- if (StringUtils.isEmpty(id)) {
|
|
|
|
- return ResponseVO.fail("id不能为空!");
|
|
|
|
- }
|
|
|
|
- // id获取用户
|
|
|
|
- SysUser sysUser = sysUserService.getById(id);
|
|
|
|
- if (sysUser == null) {
|
|
|
|
- return ResponseVO.fail("不能解锁用户!");
|
|
|
|
- }
|
|
|
|
- if (!"1".equals(sysUser.getStatus())) {
|
|
|
|
- return ResponseVO.fail("只能对【锁定】状态的进行解锁!");
|
|
|
|
- }
|
|
|
|
|
|
+ public ResponseVO relockUser(String id) throws CustomException {
|
|
try {
|
|
try {
|
|
|
|
+ if (StringUtils.isEmpty(id)) {
|
|
|
|
+ return ResponseVO.fail("id不能为空!");
|
|
|
|
+ }
|
|
|
|
+ // id获取用户
|
|
|
|
+ SysUser sysUser = sysUserService.getById(id);
|
|
|
|
+ if (sysUser == null) {
|
|
|
|
+ return ResponseVO.fail("不能解锁用户!");
|
|
|
|
+ }
|
|
|
|
+ if (!"1".equals(sysUser.getStatus())) {
|
|
|
|
+ return ResponseVO.fail("只能对【锁定】状态的进行解锁!");
|
|
|
|
+ }
|
|
|
|
+
|
|
boolean bo = sysUserService.relockUserById(Integer.parseInt(id));
|
|
boolean bo = sysUserService.relockUserById(Integer.parseInt(id));
|
|
if (bo) {
|
|
if (bo) {
|
|
return ResponseVO.success("解锁成功");
|
|
return ResponseVO.success("解锁成功");
|
|
@@ -418,50 +415,47 @@ public class SysUserController {
|
|
return ResponseVO.fail("解锁失败");
|
|
return ResponseVO.fail("解锁失败");
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- e.printStackTrace();
|
|
|
|
- log.error("解锁异常");
|
|
|
|
- return ResponseVO.error(e);
|
|
|
|
|
|
+ throw new CustomException("解锁异常", e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 用户授权角色
|
|
* 用户授权角色
|
|
*/
|
|
*/
|
|
@PostMapping("/authRole")
|
|
@PostMapping("/authRole")
|
|
@PreAuthorize("@ss.hasPermi('system:user:role')")
|
|
@PreAuthorize("@ss.hasPermi('system:user:role')")
|
|
@OperateLog(title = "用户管理", businessType = BusinessType.GRANT, auditType = AuditType.SYS)
|
|
@OperateLog(title = "用户管理", businessType = BusinessType.GRANT, auditType = AuditType.SYS)
|
|
- public ResponseVO authRole(Long userId, Long roleId) {
|
|
|
|
- if (userId==null) {
|
|
|
|
- return ResponseVO.fail("用户id不能为空!");
|
|
|
|
- }
|
|
|
|
|
|
+ public ResponseVO authRole(Long userId, Long roleId) throws CustomException {
|
|
try {
|
|
try {
|
|
|
|
+ if (userId == null) {
|
|
|
|
+ return ResponseVO.fail("用户id不能为空!");
|
|
|
|
+ }
|
|
sysUserService.insertUserAuth(userId, roleId);
|
|
sysUserService.insertUserAuth(userId, roleId);
|
|
return ResponseVO.success("分配角色成功");
|
|
return ResponseVO.success("分配角色成功");
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- e.printStackTrace();
|
|
|
|
- log.error("分配角色异常");
|
|
|
|
- return ResponseVO.error(e);
|
|
|
|
|
|
+ throw new CustomException("分配角色异常", e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 根据用户ID获取角色
|
|
* 根据用户ID获取角色
|
|
|
|
+ *
|
|
* @param userId
|
|
* @param userId
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@GetMapping("/getUserRole")
|
|
@GetMapping("/getUserRole")
|
|
- public ResponseVO getUserRole(Long userId) {
|
|
|
|
- if (userId==null) {
|
|
|
|
- return ResponseVO.fail("用户id不能为空!");
|
|
|
|
- }
|
|
|
|
|
|
+ public ResponseVO getUserRole(Long userId) throws CustomException {
|
|
try {
|
|
try {
|
|
|
|
+ if (userId == null) {
|
|
|
|
+ return ResponseVO.fail("用户id不能为空!");
|
|
|
|
+ }
|
|
|
|
+
|
|
QueryWrapper<SysUserRole> wrapper = new QueryWrapper<>();
|
|
QueryWrapper<SysUserRole> wrapper = new QueryWrapper<>();
|
|
wrapper.eq("user_id", userId);
|
|
wrapper.eq("user_id", userId);
|
|
SysUserRole sysUserRole = sysUserRoleService.getOne(wrapper);
|
|
SysUserRole sysUserRole = sysUserRoleService.getOne(wrapper);
|
|
return ResponseVO.success(sysUserRole);
|
|
return ResponseVO.success(sysUserRole);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- e.printStackTrace();
|
|
|
|
- log.error("分配角色异常");
|
|
|
|
- return ResponseVO.error(e);
|
|
|
|
|
|
+ throw new CustomException("获取用户角色异常", e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|