|
@@ -0,0 +1,512 @@
|
|
|
+package com.jiayue.ssi.controller;
|
|
|
+
|
|
|
+import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import cn.dev33.satoken.util.SaResult;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.lang.Validator;
|
|
|
+import cn.hutool.core.util.IdcardUtil;
|
|
|
+import cn.hutool.core.util.NumberUtil;
|
|
|
+import cn.hutool.crypto.SmUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.jiayue.ssi.annotation.AgainVerify;
|
|
|
+import com.jiayue.ssi.backenum.ApproveOperaterEnum;
|
|
|
+import com.jiayue.ssi.backenum.ApproveStatusEnum;
|
|
|
+import com.jiayue.ssi.constant.ApproveConstants;
|
|
|
+import com.jiayue.ssi.constant.CacheConstants;
|
|
|
+import com.jiayue.ssi.constant.CustomException;
|
|
|
+import com.jiayue.ssi.constant.SecretKeyConstants;
|
|
|
+import com.jiayue.ssi.entity.*;
|
|
|
+import com.jiayue.ssi.service.*;
|
|
|
+import com.jiayue.ssi.service.impl.SysPermissionService;
|
|
|
+import com.jiayue.ssi.util.*;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 用户信息接口
|
|
|
+ *
|
|
|
+ * @author xsl
|
|
|
+ * @since 2023/03/13
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/sysUserController")
|
|
|
+@Slf4j
|
|
|
+public class SysUserController {
|
|
|
+ @Autowired
|
|
|
+ SysUserService sysUserService;
|
|
|
+ @Autowired
|
|
|
+ SysPermissionService sysPermissionService;
|
|
|
+ @Autowired
|
|
|
+ SysUserRoleService sysUserRoleService;
|
|
|
+ @Autowired
|
|
|
+ SysApproveService sysApproveService;
|
|
|
+ @Autowired
|
|
|
+ SysRoleService sysRoleService;
|
|
|
+ @Autowired
|
|
|
+ SysPolicyService sysPolicyService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取用户分页信息
|
|
|
+ *
|
|
|
+ * @return 用户信息
|
|
|
+ */
|
|
|
+ @GetMapping(value = "/getAll")
|
|
|
+ public SaResultRefit getAll(String username, String phonenumber,
|
|
|
+ String status) throws CustomException {
|
|
|
+ try {
|
|
|
+ if (StringUtils.isNotEmpty(username)) {
|
|
|
+ if (username.length() > 20) {
|
|
|
+ return SaResultRefit.errorTips("用户账号长度不能超过20个字符!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(phonenumber)) {
|
|
|
+ if (phonenumber.length() > 11) {
|
|
|
+ return SaResultRefit.errorTips("手机号码长度不能超过11个字符!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询全部
|
|
|
+ List<SysUser> sysUserList = sysUserService.queryAllUserByDecrypt();
|
|
|
+
|
|
|
+ // 根据查询条件过滤结果
|
|
|
+ if (StringUtils.isNotEmpty(username)) {
|
|
|
+ sysUserList = sysUserList.stream().filter(user -> username.equals(user.getUsername())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(phonenumber)) {
|
|
|
+ sysUserList = sysUserList.stream().filter(user -> phonenumber.equals(user.getPhonenumber())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(status)) {
|
|
|
+ sysUserList = sysUserList.stream().filter(user -> status.equals(user.getStatus())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ return SaResultRefit.data(sysUserList);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new CustomException("获取所有用户异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当前用户信息
|
|
|
+ *
|
|
|
+ * @return 用户信息
|
|
|
+ */
|
|
|
+ @GetMapping(value = "/getCurrentUser")
|
|
|
+ public SaResultRefit getCurrentUser() throws CustomException {
|
|
|
+ try {
|
|
|
+ long userId = Long.parseLong(StpUtil.getLoginId().toString());
|
|
|
+ SysUser sysUser = sysUserService.getById(userId);;
|
|
|
+ // 权限集合
|
|
|
+ Set<String> permissions = sysPermissionService.getMenuPermission(userId);
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ sysUser.setMailbox(SM2CryptUtils.decrypt(sysUser.getMailbox(), SecretKeyConstants.SERVER_PRIVATE_KEY));
|
|
|
+ sysUser.setPhonenumber(SM2CryptUtils.decrypt(sysUser.getPhonenumber(), SecretKeyConstants.SERVER_PRIVATE_KEY));
|
|
|
+ sysUser.setNickname(SM2CryptUtils.decrypt(sysUser.getNickname(), SecretKeyConstants.SERVER_PRIVATE_KEY));
|
|
|
+ sysUser.setIdcard(SM2CryptUtils.decrypt(sysUser.getIdcard(), SecretKeyConstants.SERVER_PRIVATE_KEY));
|
|
|
+ map.put("sysUser", sysUser);
|
|
|
+ map.put("permissions", permissions);
|
|
|
+ return SaResultRefit.data(map);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new CustomException("获取当前用户异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增用户
|
|
|
+ */
|
|
|
+ @AgainVerify
|
|
|
+ @PostMapping(value = "/addUser")
|
|
|
+ public SaResultRefit addUser(@RequestBody SysUser user) throws CustomException {
|
|
|
+ try {
|
|
|
+ String username="";
|
|
|
+ SysUser sysUser = new SysUser();
|
|
|
+ if (StringUtils.isEmpty(user.getUsername()) || StringUtils.isEmpty(user.getUsername().trim())) {
|
|
|
+ return SaResultRefit.errorTips("用户账号不能为空!");
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ username = user.getUsername();
|
|
|
+ if (username.contains(" ")){
|
|
|
+ return SaResultRefit.errorTips("账号中不能含有空格!");
|
|
|
+ }
|
|
|
+
|
|
|
+ String regExp = "^[^0-9][\\w_]{4,19}$";
|
|
|
+ if (!username.matches(regExp)) {
|
|
|
+ return SaResultRefit.errorTips("用户账号长度必须是5-20位,只能包含字母、数字和下划线,不能数字开头!");
|
|
|
+ }
|
|
|
+ sysUser.setUsername(username);
|
|
|
+ }
|
|
|
+
|
|
|
+ SysPolicy sysPolicy = sysPolicyService.getOne(new QueryWrapper<>());
|
|
|
+ String ruleInfo = PasswordRuleUtil.ruleRegx(sysPolicy.getPasswordRule(),user.getPassword());
|
|
|
+ if (!"true".equals(ruleInfo)){
|
|
|
+ return SaResultRefit.errorTips(ruleInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!IdcardUtil.isValidCard(user.getIdcard())) {
|
|
|
+ return SaResultRefit.errorTips("身份证无效!");
|
|
|
+ }
|
|
|
+ // sm2加密身份证
|
|
|
+ sysUser.setIdcard(SM2CryptUtils.encrypt(user.getIdcard(), SecretKeyConstants.SERVER_PUBLIC_KEY));
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(user.getPhonenumber())) {
|
|
|
+ return SaResultRefit.errorTips("手机号码不能为空!");
|
|
|
+ } else if (!Validator.isMobile(user.getPhonenumber())) {
|
|
|
+ return SaResultRefit.errorTips("请输入正确的手机号码!");
|
|
|
+ }
|
|
|
+ // 加密手机号
|
|
|
+ sysUser.setPhonenumber(SM2CryptUtils.encrypt(user.getPhonenumber(), SecretKeyConstants.SERVER_PUBLIC_KEY));
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(user.getNickname()) || StringUtils.isEmpty(user.getNickname().trim())) {
|
|
|
+ return SaResultRefit.errorTips("姓名不能为空!");
|
|
|
+ } else {
|
|
|
+ String nickName = user.getNickname().trim();
|
|
|
+ if (nickName.length() > 30) {
|
|
|
+ return SaResultRefit.errorTips("姓名长度不能超过30个字符!");
|
|
|
+ }
|
|
|
+ // 加密姓名
|
|
|
+ sysUser.setNickname(SM2CryptUtils.encrypt(nickName, SecretKeyConstants.SERVER_PUBLIC_KEY));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(user.getMailbox())) {
|
|
|
+ return SaResultRefit.errorTips("邮箱不能为空!");
|
|
|
+ } else if (!Validator.isEmail(user.getMailbox())) {
|
|
|
+ return SaResultRefit.errorTips("请输入正确的邮箱地址!");
|
|
|
+ } else if (user.getMailbox().length() > 50) {
|
|
|
+ return SaResultRefit.errorTips("邮箱长度不能超过50个字符!");
|
|
|
+ }
|
|
|
+ // 加密邮箱
|
|
|
+ sysUser.setMailbox(SM2CryptUtils.encrypt(user.getMailbox(), SecretKeyConstants.SERVER_PUBLIC_KEY));
|
|
|
+ List<SysUser> sysUserList = sysUserService.queryAllUserByDecrypt();
|
|
|
+ for (SysUser ul:sysUserList){
|
|
|
+ // 判断手机号和邮箱是否存在
|
|
|
+ if (user.getUsername().equals(ul.getUsername())){
|
|
|
+ return SaResultRefit.errorTips("账号"+user.getUsername() + "存在,不能新增!");
|
|
|
+ }
|
|
|
+ if (user.getIdcard().equals(ul.getIdcard())){
|
|
|
+ return SaResultRefit.errorTips("身份证"+user.getIdcard() + "存在,不能新增!");
|
|
|
+ }
|
|
|
+ if (user.getPhonenumber().equals(ul.getPhonenumber())){
|
|
|
+ return SaResultRefit.errorTips("手机号码"+user.getPhonenumber() + "存在,不能新增!");
|
|
|
+ }
|
|
|
+ if (user.getMailbox().equals(ul.getMailbox())){
|
|
|
+ return SaResultRefit.errorTips("用户邮箱"+user.getMailbox() + "存在,不能新增!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sysUser.setUsertype(user.getUsertype());
|
|
|
+ sysUser.setStatus("0");
|
|
|
+ sysUser.setSignstr("0");
|
|
|
+ // 新密码加密
|
|
|
+ String sm3newpwd = SmUtil.sm3(user.getPassword()).toUpperCase();
|
|
|
+ // 再次sm2加密
|
|
|
+ String sm2password = SM2CryptUtils.encrypt(sm3newpwd,SecretKeyConstants.SERVER_PUBLIC_KEY);
|
|
|
+ sysUser.setPassword(sm2password);
|
|
|
+ sysUser.setCheckPassword(sm3newpwd);
|
|
|
+ sysUser.setBakPassword(sm2password);
|
|
|
+
|
|
|
+ boolean bo = sysUserService.save(sysUser);
|
|
|
+
|
|
|
+ if (bo) {
|
|
|
+ return SaResultRefit.ok("添加用户信息成功!");
|
|
|
+ } else {
|
|
|
+ return SaResultRefit.errorTips("添加用户信息失败");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new CustomException("添加用户信息异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新用户
|
|
|
+ *
|
|
|
+ * @param user 参数
|
|
|
+ * @return 执行结果
|
|
|
+ */
|
|
|
+ @PostMapping(value = "/updateUser")
|
|
|
+ public SaResultRefit updateUser(@RequestBody SysUser user) throws CustomException {
|
|
|
+ try {
|
|
|
+ SysUser existUser = sysUserService.getById(user.getId());
|
|
|
+ if (existUser == null) {
|
|
|
+ return SaResultRefit.errorTips("id为空不能修改!");
|
|
|
+ }
|
|
|
+
|
|
|
+ String username = "";
|
|
|
+ if (StringUtils.isEmpty(user.getUsername()) || StringUtils.isEmpty(user.getUsername().trim())) {
|
|
|
+ return SaResultRefit.errorTips("用户账号不能为空!");
|
|
|
+ } else{
|
|
|
+ username = user.getUsername().trim();
|
|
|
+ if (username.contains(" ")){
|
|
|
+ return SaResultRefit.errorTips("账号中不能含有空格!");
|
|
|
+ }
|
|
|
+ String regExp = "^[^0-9][\\w_]{4,19}$";
|
|
|
+ if (!username.matches(regExp)){
|
|
|
+ return SaResultRefit.errorTips("用户账号长度必须是5-20位,只能包含字母、数字和下划线,不能数字开头!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!IdcardUtil.isValidCard(user.getIdcard())) {
|
|
|
+ return SaResultRefit.errorTips("身份证无效!");
|
|
|
+ }
|
|
|
+ // sm2加密身份证
|
|
|
+ user.setIdcard(SM2CryptUtils.encrypt(user.getIdcard(), SecretKeyConstants.SERVER_PUBLIC_KEY));
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(user.getMailbox())) {
|
|
|
+ return SaResultRefit.errorTips("邮箱不能为空!");
|
|
|
+ } else if (!Validator.isEmail(user.getMailbox())) {
|
|
|
+ return SaResultRefit.errorTips("请输入正确的邮箱地址!");
|
|
|
+ } else if (user.getMailbox().length() > 50) {
|
|
|
+ return SaResultRefit.errorTips("邮箱长度不能超过50个字符!");
|
|
|
+ }
|
|
|
+ // 加密邮箱
|
|
|
+ user.setMailbox(SM2CryptUtils.encrypt(user.getMailbox(), SecretKeyConstants.SERVER_PUBLIC_KEY));
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(user.getPhonenumber())) {
|
|
|
+ return SaResultRefit.errorTips("手机号码不能为空!");
|
|
|
+ } else if (!Validator.isMobile(user.getPhonenumber())) {
|
|
|
+ return SaResultRefit.errorTips("请输入正确的手机号码!");
|
|
|
+ }
|
|
|
+ // 加密手机号
|
|
|
+ user.setPhonenumber(SM2CryptUtils.encrypt(user.getPhonenumber(), SecretKeyConstants.SERVER_PUBLIC_KEY));
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(user.getNickname()) || StringUtils.isEmpty(user.getNickname().trim())) {
|
|
|
+ return SaResultRefit.errorTips("姓名不能为空!");
|
|
|
+ } else {
|
|
|
+ String nickName = user.getNickname().trim();
|
|
|
+ if (nickName.length() > 30) {
|
|
|
+ return SaResultRefit.errorTips("姓名长度不能超过30个字符!");
|
|
|
+ }
|
|
|
+ // 加密姓名
|
|
|
+ user.setNickname(SM2CryptUtils.encrypt(nickName, SecretKeyConstants.SERVER_PUBLIC_KEY));
|
|
|
+ }
|
|
|
+
|
|
|
+ List<SysUser> sysUserList = sysUserService.queryAllUserByDecrypt();
|
|
|
+ for (SysUser sysUser:sysUserList){
|
|
|
+ // 判断手机号和邮箱是否存在
|
|
|
+ if (user.getPhonenumber().equals(sysUser.getPhonenumber()) && user.getId().longValue()!=sysUser.getId().longValue()){
|
|
|
+ return SaResultRefit.errorTips("手机号码"+user.getPhonenumber() + "存在,不能修改!");
|
|
|
+ }
|
|
|
+ if (user.getMailbox().equals(sysUser.getMailbox()) && user.getId().longValue()!=sysUser.getId().longValue()){
|
|
|
+ return SaResultRefit.errorTips("用户邮箱"+user.getMailbox() + "存在,不能修改!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 新密码加密
|
|
|
+ String sm3newpwd = SmUtil.sm3(user.getPassword()).toUpperCase();
|
|
|
+ // 再次sm2加密
|
|
|
+ String sm2password = SM2CryptUtils.encrypt(sm3newpwd,SecretKeyConstants.SERVER_PUBLIC_KEY);
|
|
|
+ user.setPassword(sm2password);
|
|
|
+ user.setCheckPassword(sm3newpwd);
|
|
|
+ user.setBakPassword(sm2password);
|
|
|
+
|
|
|
+ boolean bo = sysUserService.updateUser(user);
|
|
|
+ if (bo) {
|
|
|
+ return SaResultRefit.ok("修改用户信息成功!");
|
|
|
+ } else {
|
|
|
+ return SaResultRefit.errorTips("修改用户信息失败");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new CustomException("修改用户信息异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改密码
|
|
|
+ */
|
|
|
+ @PostMapping(value = "/updatePassword")
|
|
|
+ public SaResultRefit updatePassword(String id, String oldPassword, String newPassword, String confirmPassword) throws CustomException {
|
|
|
+ try {
|
|
|
+ oldPassword = oldPassword.trim();
|
|
|
+ newPassword = newPassword.trim();
|
|
|
+ confirmPassword = confirmPassword.trim();
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(id)) {
|
|
|
+ return SaResultRefit.errorTips("修改密码缺失id!");
|
|
|
+ }
|
|
|
+ // id获取用户
|
|
|
+ SysUser sysUser = sysUserService.getById(id);
|
|
|
+ if (sysUser == null) {
|
|
|
+ return SaResultRefit.errorTips("找不到用户,修改密码失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (newPassword == null) {
|
|
|
+ // 返回密码长度问题
|
|
|
+ return SaResultRefit.errorTips("密码长度需要8~20位之间!");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(oldPassword)) {
|
|
|
+ return SaResultRefit.errorTips("旧密码不能为空!");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(newPassword)) {
|
|
|
+ return SaResultRefit.errorTips("新密码不能为空!");
|
|
|
+ } else if (StringUtils.isEmpty(confirmPassword)) {
|
|
|
+ return SaResultRefit.errorTips("确认密码不能为空!");
|
|
|
+ } else if (!newPassword.equals(confirmPassword)) {
|
|
|
+ return SaResultRefit.errorTips("新密码两次输入的密码不一致!");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (newPassword.contains(" ")){
|
|
|
+ return SaResultRefit.errorTips("新密码中不能含有空格!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 对新密码规则验证
|
|
|
+ if (newPassword.contains(sysUser.getUsername())) {
|
|
|
+ return SaResultRefit.errorTips("密码不能含有账号!");
|
|
|
+ }
|
|
|
+ String oldpwd = SM2CryptUtils.decrypt(sysUser.getPassword(),SecretKeyConstants.SERVER_PRIVATE_KEY);
|
|
|
+ if (SmUtil.sm3(newPassword).toUpperCase().equals(oldpwd)) {
|
|
|
+ return SaResultRefit.errorTips("新密码不能与上次密码相同!");
|
|
|
+ }
|
|
|
+
|
|
|
+ SysPolicy sysPolicy = sysPolicyService.getOne(new QueryWrapper<>());
|
|
|
+ String ruleInfo = PasswordRuleUtil.ruleRegx(sysPolicy.getPasswordRule(),newPassword);
|
|
|
+ if (!"true".equals(ruleInfo)){
|
|
|
+ return SaResultRefit.errorTips(ruleInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证旧密码是否正确
|
|
|
+ if (!oldpwd.equals(SmUtil.sm3(oldPassword).toUpperCase())){
|
|
|
+ return SaResultRefit.errorTips("旧密码不正确!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 新密码加密
|
|
|
+ String sm3newpwd = SmUtil.sm3(newPassword).toUpperCase();
|
|
|
+ // 再次sm2加密
|
|
|
+ String sm2password = SM2CryptUtils.encrypt(sm3newpwd,SecretKeyConstants.SERVER_PUBLIC_KEY);
|
|
|
+ sysUser.setPassword(sm2password);
|
|
|
+ sysUser.setCheckPassword(sm3newpwd);
|
|
|
+ sysUser.setBakPassword(sm2password);
|
|
|
+ sysUser.setLastUpdatePwdTime(new Date());
|
|
|
+ boolean bo = sysUserService.updateById(sysUser);
|
|
|
+ if (!bo) {
|
|
|
+ return SaResultRefit.errorTips("修改密码失败!");
|
|
|
+ }
|
|
|
+ return SaResultRefit.ok();
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new CustomException("修改密码异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解锁用户信息
|
|
|
+ */
|
|
|
+ @PostMapping(value = "/relockUser")
|
|
|
+ public SaResultRefit relockUser(String id) throws CustomException {
|
|
|
+ try {
|
|
|
+ if (StringUtils.isEmpty(id)) {
|
|
|
+ return SaResultRefit.errorTips("id不能为空!");
|
|
|
+ }
|
|
|
+ // id获取用户
|
|
|
+ SysUser sysUser = sysUserService.getById(id);
|
|
|
+ if (sysUser == null) {
|
|
|
+ return SaResultRefit.errorTips("不能解锁用户!");
|
|
|
+ }
|
|
|
+ if (!"1".equals(sysUser.getStatus())) {
|
|
|
+ return SaResultRefit.errorTips("只能对【锁定】状态的进行解锁!");
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean bo = sysUserService.relockUserById(Integer.parseInt(id));
|
|
|
+ if (bo) {
|
|
|
+ return SaResultRefit.ok("解锁成功");
|
|
|
+ } else {
|
|
|
+ log.error("解锁失败");
|
|
|
+ return SaResultRefit.errorTips("解锁失败");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new CustomException("解锁异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户授权角色
|
|
|
+ */
|
|
|
+ @AgainVerify
|
|
|
+ @PostMapping("/authRole")
|
|
|
+ public SaResultRefit authRole(String userId, String roleId) throws CustomException {
|
|
|
+ try {
|
|
|
+ if (StringUtils.isEmpty(userId)) {
|
|
|
+ return SaResultRefit.errorTips("id不能为空!");
|
|
|
+ }
|
|
|
+ // id获取用户
|
|
|
+ SysUser sysUser = sysUserService.getById(userId);
|
|
|
+ if (sysUser == null) {
|
|
|
+ return SaResultRefit.errorTips("id为空不能授权用户!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // id获取用户
|
|
|
+ SysRole sysRole = sysRoleService.getById(roleId);
|
|
|
+ if (sysRole == null) {
|
|
|
+ return SaResultRefit.errorTips("角色id为空不能授权用户!");
|
|
|
+ }
|
|
|
+
|
|
|
+ int i = sysUserService.insertUserAuth(Long.parseLong(userId), Long.parseLong(roleId));
|
|
|
+
|
|
|
+ if (i>0) {
|
|
|
+ return SaResultRefit.ok("授权用户成功!");
|
|
|
+ } else {
|
|
|
+ log.error("授权用户信息失败");
|
|
|
+ return SaResultRefit.errorTips("授权用户信息失败");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new CustomException("分配角色异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据用户ID获取角色
|
|
|
+ *
|
|
|
+ * @param userId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("/getUserRole")
|
|
|
+ public SaResultRefit getUserRole(Long userId) throws CustomException {
|
|
|
+ try {
|
|
|
+ if (userId == null) {
|
|
|
+ return SaResultRefit.errorTips("用户id不能为空!");
|
|
|
+ }
|
|
|
+
|
|
|
+ QueryWrapper<SysUserRole> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("user_id", userId);
|
|
|
+ SysUserRole sysUserRole = sysUserRoleService.getOne(wrapper);
|
|
|
+ return SaResultRefit.data(sysUserRole);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new CustomException("获取用户角色异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 注销用户信息
|
|
|
+ */
|
|
|
+ @AgainVerify
|
|
|
+ @PostMapping(value = "/logOffUser")
|
|
|
+ public SaResultRefit logOffUser(String id) throws CustomException {
|
|
|
+ try {
|
|
|
+ if (StringUtils.isEmpty(id)) {
|
|
|
+ return SaResultRefit.errorTips("id不能为空!");
|
|
|
+ }
|
|
|
+ // id获取用户
|
|
|
+ SysUser sysUser = sysUserService.getById(id);
|
|
|
+ if (sysUser == null) {
|
|
|
+ return SaResultRefit.errorTips("id为空不能删除用户!");
|
|
|
+ }
|
|
|
+
|
|
|
+ sysUser.setStatus("2");
|
|
|
+ boolean bo = sysUserService.updateById(sysUser);
|
|
|
+
|
|
|
+ if (bo) {
|
|
|
+ return SaResultRefit.ok("注销用户成功!");
|
|
|
+ } else {
|
|
|
+ return SaResultRefit.errorTips("注销用户失败");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new CustomException("注销用户异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|