浏览代码

冻结、解冻

czh 2 年之前
父节点
当前提交
77b74d47c0

+ 2 - 0
sckw-common/sckw-common-core/src/main/java/com/sckw/core/web/constant/HttpStatus.java

@@ -30,6 +30,8 @@ public class HttpStatus {
     public static final int PARAMETERS_MISSING_CODE = 60600;
     public static final String ID_MISSING = "id不能为空!";
     public static final String ACCOUNT_MISSING = "用户账号必填!";
+    public static final String ACCOUNT_FREEZE = "用户账号不能重复冻结!";
+    public static final String ACCOUNT_UNFREEZE = "用户账号不能重复解冻!";
     public static final String ACCOUNT_EXISTS = "用户账号已存在!";
     public static final String PWD_MISSING = "密码不能为空!";
     public static final String TOKEN_MISSING = "token不能为空!";

+ 29 - 2
sckw-modules/sckw-system/src/main/java/com/sckw/system/controller/KwsUserController.java

@@ -14,11 +14,13 @@ import com.sckw.system.service.KwsUserService;
 import jakarta.validation.Valid;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
+
 import java.util.HashMap;
 import java.util.List;
 
 /**
  * 用户
+ *
  * @author zk
  * @date 2023-05-30
  */
@@ -81,13 +83,13 @@ public class KwsUserController {
 
     /**
      * @param params {id:主键ID、systemType:系统类型(1运营端、2企业开户)、account:账号、password:密码、name:姓名、phone:联系电话
-     *      *               ,photo:头像,email:邮箱}
+     *               *               ,photo:头像,email:邮箱}
      * @description 更新
      * @author zk
      * @date 2023/5/30
      **/
     @PostMapping("/update")
-    public HttpResult update(@RequestBody KwsUser params) throws SystemException {
+    public HttpResult update(@Valid @RequestBody UserAddReqVo params) throws SystemException {
         kwsUserService.update(params);
         return HttpResult.ok(HttpStatus.MSG_005);
     }
@@ -117,6 +119,31 @@ public class KwsUserController {
     }
 
 
+    /**
+     * @param ids 主键
+     * @return HttpResult
+     * @desc: 冻结
+     * @author: czh
+     * @date: 2023/7/12
+     */
+    @GetMapping("freeze")
+    public HttpResult freeze(@RequestParam String ids) {
+        kwsUserService.freeze(ids);
+        return HttpResult.ok(HttpStatus.MSG_005);
+    }
+
+    /**
+     * @param ids 主键
+     * @return HttpResult
+     * @desc: 解冻
+     * @author: czh
+     * @date: 2023/7/12
+     */
+    @GetMapping("unFreeze")
+    public HttpResult unFreeze(@RequestParam String ids) {
+        kwsUserService.unFreeze(ids);
+        return HttpResult.ok(HttpStatus.MSG_005);
+    }
 
     @PostMapping("testEdit")
     public HttpResult testEdit() {

+ 6 - 3
sckw-modules/sckw-system/src/main/java/com/sckw/system/model/vo/req/UserAddReqVo.java

@@ -18,16 +18,20 @@ public class UserAddReqVo implements Serializable {
     @Serial
     private static final long serialVersionUID = 3710064198286583936L;
 
+    /**
+     * 主键
+     */
+    private Long id;
+
     /**
      * 系统类型(1运营端、2企业开户)
      */
-    @NotNull(message = "系统类型不能为空")
     private Integer systemType;
 
     /**
      * 账号
      */
-    @NotBlank(message = "系统类型不能为空")
+    @NotBlank(message = "账号不能为空")
     private String account;
 
     /**
@@ -65,7 +69,6 @@ public class UserAddReqVo implements Serializable {
     /**
      * 是否是企业管理(1是 0否)
      */
-    @NotNull(message = "用户身份不能为空")
     private Integer isMain;
 
     /**

+ 95 - 9
sckw-modules/sckw-system/src/main/java/com/sckw/system/service/KwsUserService.java

@@ -10,15 +10,13 @@ import com.sckw.redis.utils.RedissonUtils;
 import com.sckw.system.api.model.dto.req.RegisterReqDto;
 import com.sckw.system.api.model.dto.req.UpdatePasswordReqDto;
 import com.sckw.system.api.model.dto.res.RegisterResDto;
-import com.sckw.system.dao.KwsEntCheckTrackDao;
-import com.sckw.system.dao.KwsEnterpriseDao;
-import com.sckw.system.dao.KwsUserDao;
-import com.sckw.system.dao.KwsUserDeptDao;
+import com.sckw.system.dao.*;
 import com.sckw.system.model.*;
 import com.sckw.system.model.pojo.FindEntListPojo;
 import com.sckw.system.model.vo.req.*;
 import com.sckw.system.model.vo.res.KwsUserResVo;
 import lombok.extern.slf4j.Slf4j;
+import org.checkerframework.checker.units.qual.K;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -47,6 +45,9 @@ public class KwsUserService {
     @Autowired
     KwsRoleService kwsRoleService;
 
+    @Autowired
+    KwsUserRoleDao kwsUserRoleDao;
+
     @Autowired
     KwsDeptService kwsDeptService;
 
@@ -66,6 +67,9 @@ public class KwsUserService {
     public void add(UserAddReqVo reqVo) {
         KwsUser kwsUser = new KwsUser();
         BeanUtils.copyProperties(reqVo, kwsUser);
+        kwsUser.setPhone(kwsUser.getAccount());
+        kwsUser.setIsMain(Global.NO);
+        kwsUser.setSystemType(SystemTypeEnum.COMPANY.getCode());
 
         /*1、数据校验*/
         checkAccountValid(kwsUser.getAccount(), kwsUser.getSystemType());
@@ -99,7 +103,7 @@ public class KwsUserService {
     public RegisterResDto register(RegisterReqDto reqDto) throws SystemException {
         EntFindPageReqVo entFindPageReqVo = new EntFindPageReqVo();
         entFindPageReqVo.setFirmName(reqDto.getEntName());
-        List<KwsEnterprise > list = kwsEnterpriseDao.findList(entFindPageReqVo);
+        List<KwsEnterprise> list = kwsEnterpriseDao.findList(entFindPageReqVo);
         if (!CollectionUtils.isEmpty(list)) {
             throw new SystemException(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.ENT_EXISTS);
         }
@@ -256,7 +260,12 @@ public class KwsUserService {
      *
      * @param params KwsUser
      */
-    public void update(KwsUser params) throws SystemException {
+    @Transactional(rollbackFor = {})
+    public void update(UserAddReqVo params) throws SystemException {
+        KwsUser kwsUser = kwsUserDao.selectByKey(params.getId());
+        if (Objects.isNull(kwsUser)) {
+            throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.ACCOUNT_NOT_EXISTS);
+        }
         //更换账号后账号唯一性校验
         if (StringUtils.isNotBlank(params.getAccount())) {
             //用户信息
@@ -265,10 +274,36 @@ public class KwsUserService {
                 throw new SystemException(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.ACCOUNT_EXISTS);
             }
         }
-        //更新用户信息
-        if (kwsUserDao.update(params) <= 0) {
-            throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
+
+        //以前的关联数据先删除再新增
+        List<KwsUserDept> kwsUserDepts = kwsUserDeptDao.findAllByUserId(params.getId());
+        if (CollectionUtils.isNotEmpty(kwsUserDepts)) {
+            for (KwsUserDept kwsUserDept : kwsUserDepts) {
+                kwsUserDept.setDelFlag(Global.YES);
+                if (kwsUserDeptDao.update(kwsUserDept) <= 0) {
+                    throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
+                }
+            }
+        }
+
+        List<KwsUserRole> kwsUserRoles = kwsUserRoleDao.findAllByUserId(params.getId());
+        if (CollectionUtils.isNotEmpty(kwsUserRoles)) {
+            for (KwsUserRole kwsUserRole : kwsUserRoles) {
+                kwsUserRole.setDelFlag(Global.YES);
+                if (kwsUserRoleDao.update(kwsUserRole) <= 0) {
+                    throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
+                }
+            }
         }
+
+        kwsUser.setName(params.getName());
+        kwsUserDao.update(kwsUser);
+
+        /*填充用户角色*/
+        fillUserRole(params.getRoleIds(), kwsUser.getId(), kwsUser.getSystemType());
+
+        /*用户机构关系*/
+        fillUserDept(kwsUser.getId(), params.getDeptId());
     }
 
     /**
@@ -465,4 +500,55 @@ public class KwsUserService {
         }
     }
 
+
+    /**
+     * @param ids 主键
+     * @desc: 冻结
+     * @author: czh
+     * @date: 2023/7/12
+     */
+    public void freeze(String ids) {
+        if (StringUtils.isBlank(ids)) {
+            throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.ID_MISSING);
+        }
+
+        String[] split = ids.split(Global.COMMA);
+        for (String id : split) {
+            KwsUser kwsUser = kwsUserDao.selectByKey(Long.parseLong(id));
+            if (Objects.isNull(kwsUser) || !kwsUser.getStatus().equals(Global.NO)) {
+                throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.ACCOUNT_FREEZE);
+            }
+
+            kwsUser.setStatus(Global.YES);
+            if (kwsUserDao.update(kwsUser) <= 0) {
+                throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
+            }
+        }
+    }
+
+
+    /**
+     * @param ids 主键
+     * @desc: 解冻
+     * @author: czh
+     * @date: 2023/7/12
+     */
+    public void unFreeze(String ids) {
+        if (StringUtils.isBlank(ids)) {
+            throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.ID_MISSING);
+        }
+
+        String[] split = ids.split(Global.COMMA);
+        for (String id : split) {
+            KwsUser kwsUser = kwsUserDao.selectByKey(Long.parseLong(id));
+            if (Objects.isNull(kwsUser) || !kwsUser.getStatus().equals(Global.YES)) {
+                throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.ACCOUNT_UNFREEZE);
+            }
+
+            kwsUser.setStatus(Global.NO);
+            if (kwsUserDao.update(kwsUser) <= 0) {
+                throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
+            }
+        }
+    }
 }