|
@@ -10,6 +10,7 @@ import com.jiayue.ssi.annotation.OperateLog;
|
|
|
import com.jiayue.ssi.backenum.AuditType;
|
|
|
import com.jiayue.ssi.backenum.BusinessType;
|
|
|
import com.jiayue.ssi.config.SendMailUtil;
|
|
|
+import com.jiayue.ssi.constant.SecretKeyConstants;
|
|
|
import com.jiayue.ssi.entity.SysUser;
|
|
|
import com.jiayue.ssi.service.SysUserService;
|
|
|
import com.jiayue.ssi.service.impl.SysPermissionService;
|
|
@@ -19,10 +20,8 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 用户信息接口
|
|
@@ -49,7 +48,7 @@ public class SysUserController {
|
|
|
@GetMapping(value = "/getAll")
|
|
|
@PreAuthorize("@ss.hasPermi('system:user:list')")
|
|
|
public ResponseVO getAll(Integer currentPage, Integer pageSize, String username, String phonenumber,
|
|
|
- String status) {
|
|
|
+ String status) {
|
|
|
try {
|
|
|
if (StringUtils.isNotEmpty(username)) {
|
|
|
if (username.length() > 20) {
|
|
@@ -66,12 +65,21 @@ public class SysUserController {
|
|
|
wrapper.eq("username", username);
|
|
|
}
|
|
|
if (StringUtils.isNotEmpty(phonenumber)) {
|
|
|
- wrapper.eq("phonenumber", phonenumber);
|
|
|
+ wrapper.eq("AES_DECRYPT(UNHEX(phonenumber), '"+new String(AesUtils.key)+"')", phonenumber);
|
|
|
}
|
|
|
if (StringUtils.isNotEmpty(status)) {
|
|
|
wrapper.eq("status", status);
|
|
|
}
|
|
|
Page<SysUser> result = sysUserService.page(new Page<>(currentPage, pageSize), wrapper);
|
|
|
+ List<SysUser> records = result.getRecords();
|
|
|
+ //遍历对象数组的方法
|
|
|
+ records.forEach(
|
|
|
+ record->{
|
|
|
+ record.setMailbox(AesUtils.decryptStr(record.getMailbox()));
|
|
|
+ record.setPhonenumber(AesUtils.decryptStr(record.getPhonenumber()));
|
|
|
+ record.setNickname(AesUtils.decryptStr(record.getNickname()));
|
|
|
+ }
|
|
|
+ );
|
|
|
return ResponseVO.success(result);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
@@ -91,9 +99,12 @@ public class SysUserController {
|
|
|
SysUser sysUser = SecurityContextUtil.getSysUser();
|
|
|
// 权限集合
|
|
|
Set<String> permissions = sysPermissionService.getMenuPermission(sysUser.getId());
|
|
|
- Map<String,Object> map = new HashMap<>();
|
|
|
- map.put("sysUser",sysUser);
|
|
|
- map.put("permissions",permissions);
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ sysUser.setMailbox(AesUtils.decryptStr(sysUser.getMailbox()));
|
|
|
+ sysUser.setPhonenumber(AesUtils.decryptStr(sysUser.getPhonenumber()));
|
|
|
+ sysUser.setNickname(AesUtils.decryptStr(sysUser.getNickname()));
|
|
|
+ map.put("sysUser", sysUser);
|
|
|
+ map.put("permissions", permissions);
|
|
|
return ResponseVO.success(map);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
@@ -106,7 +117,7 @@ public class SysUserController {
|
|
|
* 新增用户
|
|
|
*/
|
|
|
@PostMapping
|
|
|
- @OperateLog(title = "用户管理", businessType = BusinessType.INSERT,auditType = AuditType.SYS)
|
|
|
+ @OperateLog(title = "用户管理", businessType = BusinessType.INSERT, auditType = AuditType.SYS)
|
|
|
@PreAuthorize("@ss.hasPermi('system:user:add')")
|
|
|
public ResponseVO add(@RequestBody SysUser user) {
|
|
|
if (StringUtils.isEmpty(user.getUsername())) {
|
|
@@ -122,12 +133,16 @@ public class SysUserController {
|
|
|
} 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.getMailbox())) {
|
|
|
return ResponseVO.fail("邮箱不能为空!");
|
|
@@ -138,12 +153,14 @@ public class SysUserController {
|
|
|
} else if (sysUserService.queryMailBox(user.getMailbox()) != null) {
|
|
|
return ResponseVO.fail(user.getMailbox() + "邮箱已存在!");
|
|
|
}
|
|
|
+ // 加密邮箱
|
|
|
+ user.setMailbox(AesUtils.encryptHex(user.getMailbox()).toUpperCase());
|
|
|
|
|
|
- // 生成8位初始密码
|
|
|
- String randomPwd = RandomPwd.getRandomPwd(8);
|
|
|
- user.setPassword(SmUtil.sm3(randomPwd).toUpperCase());
|
|
|
- user.setErrNum(0);
|
|
|
- user.setLockTime(0L);
|
|
|
+// // 生成8位初始密码
|
|
|
+// String randomPwd = RandomPwd.getRandomPwd(8);
|
|
|
+// user.setPassword(SmUtil.sm3(randomPwd).toUpperCase());
|
|
|
+// user.setErrNum(0);
|
|
|
+// user.setLockTime(0L);
|
|
|
|
|
|
try {
|
|
|
boolean bo = sysUserService.save(user);
|
|
@@ -167,7 +184,7 @@ public class SysUserController {
|
|
|
* @return 执行结果
|
|
|
*/
|
|
|
@PutMapping
|
|
|
- @OperateLog(title = "用户管理", businessType = BusinessType.UPDATE,auditType = AuditType.SYS)
|
|
|
+ @OperateLog(title = "用户管理", businessType = BusinessType.UPDATE, auditType = AuditType.SYS)
|
|
|
@PreAuthorize("@ss.hasPermi('system:user:edit')")
|
|
|
public ResponseVO update(@RequestBody SysUser user) {
|
|
|
SysUser existUser = sysUserService.getById(user.getId());
|
|
@@ -196,18 +213,24 @@ public class SysUserController {
|
|
|
return ResponseVO.fail(user.getMailbox() + "邮箱已存在!");
|
|
|
}
|
|
|
}
|
|
|
+ // 加密邮箱
|
|
|
+ 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.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())) {
|
|
@@ -232,7 +255,7 @@ public class SysUserController {
|
|
|
* 初始密码发送邮箱
|
|
|
*/
|
|
|
@PostMapping(value = "/resetPassword")
|
|
|
- @OperateLog(title = "用户管理", businessType = BusinessType.OTHER,auditType = AuditType.SYS)
|
|
|
+ @OperateLog(title = "用户管理", businessType = BusinessType.OTHER, auditType = AuditType.SYS)
|
|
|
@PreAuthorize("@ss.hasPermi('system:user:send')")
|
|
|
public ResponseVO resetPassword(String id) {
|
|
|
if (StringUtils.isEmpty(id)) {
|
|
@@ -263,7 +286,7 @@ public class SysUserController {
|
|
|
*/
|
|
|
@PostMapping(value = "/delUser")
|
|
|
@AgainVerify
|
|
|
- @OperateLog(title = "用户管理", businessType = BusinessType.DELETE,auditType = AuditType.SYS)
|
|
|
+ @OperateLog(title = "用户管理", businessType = BusinessType.DELETE, auditType = AuditType.SYS)
|
|
|
@PreAuthorize("@ss.hasPermi('system:user:remove')")
|
|
|
public ResponseVO delete(String id) {
|
|
|
if (StringUtils.isEmpty(id)) {
|
|
@@ -293,7 +316,7 @@ public class SysUserController {
|
|
|
* 修改密码
|
|
|
*/
|
|
|
@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!");
|
|
@@ -347,7 +370,7 @@ public class SysUserController {
|
|
|
* 解锁用户信息
|
|
|
*/
|
|
|
@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')")
|
|
|
public ResponseVO relockUser(String id) {
|
|
|
if (StringUtils.isEmpty(id)) {
|