Sfoglia il codice sorgente

认证逻辑修改

small 2 anni fa
parent
commit
bac83ac013
32 ha cambiato i file con 811 aggiunte e 136 eliminazioni
  1. 16 0
      sckw-auth/src/main/java/com/sckw/auth/model/vo/res/EntInfoResVo.java
  2. 5 0
      sckw-auth/src/main/java/com/sckw/auth/model/vo/res/LoginResVo.java
  3. 59 11
      sckw-auth/src/main/java/com/sckw/auth/service/impl/AuthServiceImpl.java
  4. 76 15
      sckw-common/sckw-common-core/src/main/java/com/sckw/core/filter/LoginFilter.java
  5. 1 11
      sckw-common/sckw-common-core/src/main/java/com/sckw/core/model/base/BaseModel.java
  6. 1 1
      sckw-common/sckw-common-core/src/main/java/com/sckw/core/utils/PasswordUtils.java
  7. 50 0
      sckw-common/sckw-common-core/src/main/java/com/sckw/core/web/model/EntCertificateInfo.java
  8. 6 0
      sckw-common/sckw-common-core/src/main/java/com/sckw/core/web/model/LoginEntInfo.java
  9. 9 0
      sckw-modules-api/sckw-system-api/src/main/java/com/sckw/system/api/RemoteUserService.java
  10. 92 0
      sckw-modules-api/sckw-system-api/src/main/java/com/sckw/system/api/model/dto/res/EntCertificateResDto.java
  11. 17 2
      sckw-modules/sckw-system/src/main/java/com/sckw/system/controller/KwsEnterpriseController.java
  12. 3 3
      sckw-modules/sckw-system/src/main/java/com/sckw/system/controller/KwsMenuController.java
  13. 11 0
      sckw-modules/sckw-system/src/main/java/com/sckw/system/dao/KwsEntCertificateDao.java
  14. 18 0
      sckw-modules/sckw-system/src/main/java/com/sckw/system/dao/KwsEnterpriseDao.java
  15. 9 0
      sckw-modules/sckw-system/src/main/java/com/sckw/system/dao/KwsMenuDao.java
  16. 11 4
      sckw-modules/sckw-system/src/main/java/com/sckw/system/dubbo/RemoteUserServiceImpl.java
  17. 2 0
      sckw-modules/sckw-system/src/main/java/com/sckw/system/model/KwsMenu.java
  18. 25 0
      sckw-modules/sckw-system/src/main/java/com/sckw/system/model/pojo/FindManagePojo.java
  19. 30 0
      sckw-modules/sckw-system/src/main/java/com/sckw/system/model/vo/req/ApprovalReqVo.java
  20. 4 2
      sckw-modules/sckw-system/src/main/java/com/sckw/system/model/vo/req/BusinessLicense.java
  21. 1 1
      sckw-modules/sckw-system/src/main/java/com/sckw/system/model/vo/req/RoleBindMenuReqVo.java
  22. 26 0
      sckw-modules/sckw-system/src/main/java/com/sckw/system/model/vo/req/UpdateCertificateReqVo.java
  23. 6 0
      sckw-modules/sckw-system/src/main/java/com/sckw/system/model/vo/res/CertificateResVo.java
  24. 30 0
      sckw-modules/sckw-system/src/main/java/com/sckw/system/service/CommonService.java
  25. 105 38
      sckw-modules/sckw-system/src/main/java/com/sckw/system/service/KwsEnterpriseService.java
  26. 43 5
      sckw-modules/sckw-system/src/main/java/com/sckw/system/service/KwsMenuService.java
  27. 7 38
      sckw-modules/sckw-system/src/main/java/com/sckw/system/service/KwsRoleService.java
  28. 47 4
      sckw-modules/sckw-system/src/main/java/com/sckw/system/service/KwsUserService.java
  29. 5 0
      sckw-modules/sckw-system/src/main/resources/mapper/KwsEntCertificateDao.xml
  30. 39 0
      sckw-modules/sckw-system/src/main/resources/mapper/KwsEnterpriseDao.xml
  31. 56 0
      sckw-modules/sckw-system/src/main/resources/mapper/KwsMenuDao.xml
  32. 1 1
      sckw-modules/sckw-system/src/main/resources/mapper/KwsUserDao.xml

+ 16 - 0
sckw-auth/src/main/java/com/sckw/auth/model/vo/res/EntInfoResVo.java

@@ -1,5 +1,6 @@
 package com.sckw.auth.model.vo.res;
 
+import com.sckw.system.api.model.dto.res.EntCertificateResDto;
 import lombok.Data;
 
 import java.util.Date;
@@ -23,9 +24,24 @@ public class EntInfoResVo {
      */
     private String firmName;
 
+    /**
+     * 资料审批状态(0未审批、1通过、2未通过、3审批中)
+     */
+    private int approval;
+
+    /**
+     * 注册时间
+     */
+    private Date regTime;
+
     /**
      * 机构信息
      */
     private List<DeptInfoResVo> deptInfo;
 
+    /**
+     * 资质信息
+     */
+    private List<EntCertificateResDto> certificateInfo;
+
 }

+ 5 - 0
sckw-auth/src/main/java/com/sckw/auth/model/vo/res/LoginResVo.java

@@ -74,6 +74,11 @@ public class LoginResVo implements Serializable {
      */
     private String clientType;
 
+    /**
+     * 状态
+     */
+    private Integer status;
+
     /**
      * 企业信息
      */

+ 59 - 11
sckw-auth/src/main/java/com/sckw/auth/service/impl/AuthServiceImpl.java

@@ -8,7 +8,11 @@ import com.sckw.auth.model.vo.res.DeptInfoResVo;
 import com.sckw.auth.model.vo.res.EntInfoResVo;
 import com.sckw.auth.model.vo.res.LoginResVo;
 import com.sckw.auth.util.AsyncFactory;
+import com.sckw.core.model.enums.SystemTypeEnum;
 import com.sckw.core.utils.StringUtils;
+import com.sckw.core.web.model.EntCertificateInfo;
+import com.sckw.core.web.model.LoginEntInfo;
+import com.sckw.core.web.model.LoginUserInfo;
 import com.sckw.system.api.model.dto.req.ForgetPasswordReqDto;
 import com.sckw.system.api.model.dto.req.UserLoginReqDto;
 import com.sckw.system.api.model.dto.res.KwsRoleResDto;
@@ -48,23 +52,21 @@ public class AuthServiceImpl implements IAuthService {
         /*1、根据账号密码或者手机号校验码登录, 手机号后面处理*/
         KwsUserResDto kwsUser = checkLogin(reqDto);
         LoginResVo loginResVo = new LoginResVo();
+        loginResVo.setClientType(reqDto.getClientType());
         BeanUtils.copyProperties(kwsUser, loginResVo);
 
+        //平台管理员直接过了
+        if (kwsUser.getIsMain() == Global.YES && kwsUser.getSystemType() == SystemTypeEnum.MANAGE.getCode()) {
+            afterProcessor(loginResVo);
+            return loginResVo;
+        }
         /*2、登录成功,查询角色信息*/
         Long userId = kwsUser.getId();
         List<KwsRoleResDto> kwsRoleResDtos = remoteUserService.queryRoleInfoByUserId(userId);
-        EntInfoResVo entInfoResVo = new EntInfoResVo();
-        loginResVo.setEntInfo(entInfoResVo);
         loginResVo.setRoleInfo(kwsRoleResDtos);
-        loginResVo.setClientType(reqDto.getClientType());
-        if (CollectionUtils.isEmpty(kwsRoleResDtos)) {
-            //用户-角色信息为空,没有认证
-            afterProcessor(loginResVo);
-            return loginResVo;
-        }
 
 
-        /*2、登录成功,查询用户机构*/
+        /*3、查询用户机构*/
         List<KwsUserDeptResDto> kwsUserDeptResDtos = remoteUserService.queryUserDeptByUserId(userId);
         if (CollectionUtils.isEmpty(kwsUserDeptResDtos)) {
             throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
@@ -77,6 +79,7 @@ public class AuthServiceImpl implements IAuthService {
             afterProcessor(loginResVo);
             return loginResVo;
         }
+        EntInfoResVo entInfoResVo = new EntInfoResVo();
         entInfoResVo.setDeptInfo(BeanUtils.copyToList(kwsDepts, DeptInfoResVo.class));
 
         /*3、查企业*/
@@ -89,7 +92,11 @@ public class AuthServiceImpl implements IAuthService {
             return loginResVo;
         }
         BeanUtils.copyProperties(kwsEnterpriseResDto, entInfoResVo);
+        loginResVo.setEntInfo(entInfoResVo);
 
+        /* 4、查资质*/
+        List<EntCertificateResDto> entCertificateResDtoList = remoteUserService.queryCertificateByEntId(entId);
+        entInfoResVo.setCertificateInfo(entCertificateResDtoList);
         /*4、生成token,一些信息存redis*/
         afterProcessor(loginResVo);
         return loginResVo;
@@ -187,10 +194,51 @@ public class AuthServiceImpl implements IAuthService {
          */
         private void SaveBaseToCache(LoginResVo loginResVo) {
             //存用户登录信息
-            RedissonUtils.putString(Global.getFullUserLoginKey(loginResVo.getSystemType(), loginResVo.getId(), loginResVo.getClientType()), JSON.toJSONString(loginResVo), Global.PC_TOKEN_EXPIRE);
+            saveUserLoginInfo();
 
+            EntInfoResVo entInfo = loginResVo.getEntInfo();
+            if (Objects.isNull(entInfo)) {
+                return;
+            }
             //单独存用户企业
-            RedissonUtils.putString(Global.getFullUserEntKey(loginResVo.getSystemType(), loginResVo.getId()), JSON.toJSONString(loginResVo.getEntInfo()), Global.PC_TOKEN_EXPIRE);
+            RedissonUtils.putString(Global.getFullUserEntKey(loginResVo.getSystemType(), loginResVo.getId()), JSON.toJSONString(entInfo), Global.PC_TOKEN_EXPIRE);
+            //存企业信息
+            LoginEntInfo loginEntInfo = new LoginEntInfo();
+            loginEntInfo.setId(entInfo.getId());
+            loginEntInfo.setFirmName(entInfo.getFirmName());
+            loginEntInfo.setApproval(entInfo.getApproval());
+            loginEntInfo.setRegTime(entInfo.getRegTime());
+            loginEntInfo.setCertificateInfo(BeanUtils.copyToList(entInfo.getCertificateInfo(), EntCertificateInfo.class));
+
+            RedissonUtils.putString(Global.REDIS_ENTERPRISE_PREFIX + entInfo.getId(), JSON.toJSONString(loginEntInfo), Global.PC_TOKEN_EXPIRE);
+        }
+
+        /**
+         * @desc: 存用户登录信息
+         * @author: czh
+         * @date: 2023/6/29
+         */
+        private void saveUserLoginInfo() {
+            //存用户登录信息
+            LoginUserInfo loginUserInfo = new LoginUserInfo();
+            loginUserInfo.setId(loginResVo.getId());
+            loginUserInfo.setSystemType(loginResVo.getSystemType());
+            loginUserInfo.setAccount(loginResVo.getAccount());
+            loginUserInfo.setUserName(loginResVo.getName());
+            loginUserInfo.setPhone(loginResVo.getPhone());
+            loginUserInfo.setIsMain(loginResVo.getIsMain());
+            loginUserInfo.setStatus(loginResVo.getStatus());
+            loginUserInfo.setClientType(loginResVo.getClientType());
+            EntInfoResVo entInfo = loginResVo.getEntInfo();
+            if (!Objects.isNull(entInfo)) {
+                loginUserInfo.setEntId(entInfo.getId());
+                List<DeptInfoResVo> deptInfo = entInfo.getDeptInfo();
+                if (!CollectionUtils.isEmpty(deptInfo)) {
+                    loginUserInfo.setDeptIds(String.join(",", deptInfo.stream().map(item-> String.valueOf(item.getId())).toList()));
+                }
+            }
+            RedissonUtils.putString(Global.getFullUserLoginKey(loginResVo.getSystemType(), loginResVo.getId(), loginResVo.getClientType()), JSON.toJSONString(loginUserInfo), Global.PC_TOKEN_EXPIRE);
+
         }
 
         /**

+ 76 - 15
sckw-common/sckw-common-core/src/main/java/com/sckw/core/filter/LoginFilter.java

@@ -1,14 +1,21 @@
 package com.sckw.core.filter;
 
+import cn.hutool.core.date.DateUtil;
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.sckw.core.model.enums.ApprovalEnum;
+import com.sckw.core.model.enums.SystemTypeEnum;
+import com.sckw.core.utils.CollectionUtils;
+import com.sckw.core.web.config.CustomConfig;
 import com.sckw.core.exception.SystemException;
 import com.sckw.core.model.constant.Global;
 import com.sckw.core.utils.EncryUtil;
 import com.sckw.core.utils.StringUtils;
-import com.sckw.core.web.config.CustomConfig;
 import com.sckw.core.web.constant.HttpStatus;
 import com.sckw.core.web.constant.RequestConstant;
 import com.sckw.core.web.context.LoginUserHolder;
+import com.sckw.core.web.model.EntCertificateInfo;
+import com.sckw.core.web.model.LoginEntInfo;
 import com.sckw.core.web.model.LoginUserInfo;
 import com.sckw.redis.utils.RedissonUtils;
 import jakarta.annotation.PostConstruct;
@@ -18,10 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
 
 /**
  * @desc: 登录过滤
@@ -48,6 +52,16 @@ public class LoginFilter implements Filter {
         }
     }
 
+
+    /**
+     * @desc:  1、不需要token的请求直接放行
+     *         2、取token,校验
+     *         3、token校验没问题,判断当前用户角色 平台管理员直接放行
+     *         4、校验菜单权限,管理员不用校验,普通用户需要
+     *         4、菜单权限没问题,校验企业资质是否过期
+     * @author: czh
+     * @date: 2023/6/29
+     */
     @Override
     public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws ServletException, IOException {
         HttpServletRequest request = (HttpServletRequest) servletRequest;
@@ -75,30 +89,77 @@ public class LoginFilter implements Filter {
         //从redis获取用户信息
         String clientType = request.getHeader(RequestConstant.CLIENT_TYPE);
         String systemType = request.getHeader(RequestConstant.SYSTEM_TYPE);
-        String userLoginKey = Global.getFullUserLoginKey(Integer.parseInt(systemType), Long.parseLong(key), clientType);
-        Object object = RedissonUtils.getString(userLoginKey);
-        if (Objects.isNull(object)) {
+        String userInfo = RedissonUtils.getString(Global.getFullUserLoginKey(Integer.parseInt(systemType), Long.parseLong(key), clientType));
+        if (StringUtils.isBlank(userInfo)) {
             throw new SystemException(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.TOKEN_INVAILD);
         }
 
+        //将redis里的用户信息存入内存中,避免业务操作多次从redis获取值*/
+        LoginUserInfo loginUserInfo = JSONObject.parseObject(userInfo, LoginUserInfo.class);
+        LoginUserHolder.set(loginUserInfo);
 
-        //如果企业资质有效期已过,企业普通用户和管理员均不能访问
-
-        //有效期没有过,管理员不限制权限,普通用户做菜单权限的限制
+        /*3、平台管理员直接放行*/
+        if (loginUserInfo.getIsMain() == Global.YES && Integer.parseInt(systemType) == SystemTypeEnum.MANAGE.getCode()) {
+            RedissonUtils.putString(Global.getFullUserLoginKey(Integer.parseInt(systemType), Long.parseLong(key), clientType), JSON.toJSONString(loginUserInfo), Global.PC_TOKEN_EXPIRE);
+            filterChain.doFilter(servletRequest, servletResponse);
+            LoginUserHolder.remove();
+            return;
+        }
 
-        /*3、将redis里的用户信息存入内存中,避免业务操作多次从redis获取值*/
-        LoginUserInfo loginUserInfo = JSONObject.parseObject(object.toString(), LoginUserInfo.class);
         //管理员不限制权限,按钮有权限才放行
         if (loginUserInfo.getIsMain() != Global.YES && !checkMenu(systemType + Global.COLON + key, requestUri)) {
+            LoginUserHolder.remove();
             throw new SystemException(HttpStatus.AUTHORITY_NO_CODE, HttpStatus.ACCESS_FIAL);
         }
 
-        RedissonUtils.putString(userLoginKey, object.toString(), Global.PC_TOKEN_EXPIRE);
-        LoginUserHolder.set(loginUserInfo);
+        /*4、企业信息等校验*/
+        checkEntInfo(loginUserInfo);
+
+        RedissonUtils.putString(Global.getFullUserLoginKey(Integer.parseInt(systemType), Long.parseLong(key), clientType), JSON.toJSONString(loginUserInfo), Global.PC_TOKEN_EXPIRE);
         filterChain.doFilter(servletRequest, servletResponse);
         LoginUserHolder.remove();
     }
 
+    /**
+     * @param loginUserInfo 登录信息
+     * @desc: 企业校验
+     * @author: czh
+     * @date: 2023/6/29
+     */
+    private static void checkEntInfo(LoginUserInfo loginUserInfo) {
+        /*4、如果企业资质有效期已过,企业普通用户和管理员均不能访问*/
+        Long entId = loginUserInfo.getEntId();
+        String enterpriseInfo = RedissonUtils.getString(Global.REDIS_ENTERPRISE_PREFIX + entId);
+        //正常不存在企业等信息为空还能走到这里的请求,因为只能访问放开的权限,如果有恶意请求,这里会过滤
+        if (StringUtils.isBlank(enterpriseInfo)) {
+            LoginUserHolder.remove();
+            throw new SystemException(HttpStatus.AUTHORITY_NO_CODE, HttpStatus.ACCESS_FIAL);
+        }
+
+        //企业资料审批状态校验
+        LoginEntInfo loginEntInfo = JSON.parseObject(enterpriseInfo, LoginEntInfo.class);
+        int approval = loginEntInfo.getApproval();
+        if (approval == ApprovalEnum.NO.getCode() || approval == ApprovalEnum.PROCESS.getCode() || approval == ApprovalEnum.PASS.getCode()) {
+            LoginUserHolder.remove();
+            throw new SystemException(HttpStatus.AUTHORITY_NO_CODE, HttpStatus.ACCESS_FIAL);
+        }
+
+        List<EntCertificateInfo> certificateInfoList = loginEntInfo.getCertificateInfo();
+        if (CollectionUtils.isEmpty(certificateInfoList)) {
+            LoginUserHolder.remove();
+            throw new SystemException(HttpStatus.AUTHORITY_NO_CODE, HttpStatus.ACCESS_FIAL);
+        }
+
+        //有效期检验
+        for (EntCertificateInfo entCertificateInfo : certificateInfoList){
+            Date expireTime = entCertificateInfo.getExpireTime();
+            if (DateUtil.compare(new Date(), expireTime) > 0) {
+                LoginUserHolder.remove();
+                throw new SystemException(HttpStatus.AUTHORITY_NO_CODE, HttpStatus.ACCESS_FIAL);
+            }
+        }
+    }
+
     /**
      * @param key 用户菜单权限key  url 当前请求url
      * @return boolean

+ 1 - 11
sckw-common/sckw-common-core/src/main/java/com/sckw/core/model/base/BaseModel.java

@@ -15,6 +15,7 @@ import java.util.Date;
 @Data
 @Accessors(chain = true)
 public class BaseModel implements Serializable {
+
 	private static final long serialVersionUID = 1L;
 
 	/**
@@ -35,14 +36,8 @@ public class BaseModel implements Serializable {
 	/**
 	 * 创建人
 	 */
-//	@TableField(fill = FieldFill.INSERT)
 	private Long createBy;
 
-	/**
-	 * 创建人姓名
-	 */
-//	private String createByName;
-
 	/**
 	 * 创建时间
 	 */
@@ -52,13 +47,8 @@ public class BaseModel implements Serializable {
 	/**
 	 * 更新人
 	 */
-//	@TableField(fill = FieldFill.INSERT_UPDATE)
 	private Long updateBy;
 
-	/**
-	 * 跟新人姓名
-	 */
-//	private String updateByName;
 
 	/**
 	 * 更新时间

+ 1 - 1
sckw-common/sckw-common-core/src/main/java/com/sckw/core/utils/PasswordUtils.java

@@ -115,7 +115,7 @@ public class PasswordUtils {
     public static void main(String[] args) {
 
         String password = PasswordUtils.entryptPassword(PasswordUtils.md5("18482106067"));
-        String md5 = PasswordUtils.md5("18482106067");
+        String md5 = PasswordUtils.md5("123456");
         System.out.println(password);
         System.out.println(md5);
         System.out.println(validatePassword(md5, password));

+ 50 - 0
sckw-common/sckw-common-core/src/main/java/com/sckw/core/web/model/EntCertificateInfo.java

@@ -0,0 +1,50 @@
+package com.sckw.core.web.model;
+
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @author czh
+ * @desc 资质
+ * @date 2023/6/29
+ */
+@Data
+public class EntCertificateInfo implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = -1913060977212008558L;
+
+    /**
+     * 执照编号
+     */
+    private String code;
+
+    /**
+     * 证书类型 (1联系人身份证 2法人身份证 3营业执照 4道路运输许可证 5开户许可证号 6授权证书 6电子签章授权书)
+     */
+    private int type;
+
+    /**
+     * 证书正面
+     */
+    private String certificateMian;
+
+    /**
+     * 证书反面
+     */
+    private String certificateRevolt;
+
+    /**
+     * 有效期
+     */
+    private Date expireTime;
+
+    /**
+     * 备注
+     */
+    private String remark;
+
+}

+ 6 - 0
sckw-common/sckw-common-core/src/main/java/com/sckw/core/web/model/LoginEntInfo.java

@@ -2,6 +2,7 @@ package com.sckw.core.web.model;
 
 import lombok.Data;
 import java.util.Date;
+import java.util.List;
 
 /**
  * 登录中的用户企业信息
@@ -49,4 +50,9 @@ public class LoginEntInfo {
      * 企业注册时间
      */
     private Date regTime;
+
+    /**
+     * 资质
+     */
+    private List<EntCertificateInfo> certificateInfo;
 }

+ 9 - 0
sckw-modules-api/sckw-system-api/src/main/java/com/sckw/system/api/RemoteUserService.java

@@ -109,4 +109,13 @@ public interface RemoteUserService {
      * @date: 2023/6/19
      */
     UserLoginReqDto currentDayLogin(long userId);
+
+    /**
+     * @param entId 企业id
+     * @return EntCertificateResDto
+     * @desc: 查资质
+     * @author: czh
+     * @date: 2023/6/29
+     */
+    List<EntCertificateResDto> queryCertificateByEntId(Long entId);
 }

+ 92 - 0
sckw-modules-api/sckw-system-api/src/main/java/com/sckw/system/api/model/dto/res/EntCertificateResDto.java

@@ -0,0 +1,92 @@
+package com.sckw.system.api.model.dto.res;
+
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @author czh
+ * @desc 资质
+ * @date 2023/6/29
+ */
+@Data
+public class EntCertificateResDto implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 3427994770482466992L;
+
+    /**
+     * 主键
+     */
+    private Long id;
+
+    /**
+     * 备注
+     */
+    private String remark;
+
+    /**
+     * 状态:0正常/1锁定
+     */
+    private Integer status=0;
+
+    /**
+     * 创建人
+     */
+    private Long createBy;
+
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+
+    /**
+     * 更新人
+     */
+    private Long updateBy;
+
+
+    /**
+     * 更新时间
+     */
+    private Date updateTime;
+
+    /**
+     * 删除标识(0正常/-1删除)
+     */
+    private Integer delFlag;
+
+    /**
+     * 企业ID或企业子公司所属机构ID
+     */
+    private Long entId;
+
+    /**
+     * 证书类型(1联系人身份证 2法人身份证 3营业执照 4道路运输许可证 5开户许可证号 6授权证书 6电子签章授权书)
+     */
+    private Integer type;
+
+    /**
+     * 证书码
+     */
+    private String code;
+
+    /**
+     * 证书正面URL地址
+     */
+    private String certificateMian;
+
+    /**
+     * 证书反面URL地址
+     */
+    private String certificateRevolt;
+
+    /**
+     * 有效期
+     */
+    private Date expireTime;
+
+}

+ 17 - 2
sckw-modules/sckw-system/src/main/java/com/sckw/system/controller/KwsEnterpriseController.java

@@ -105,12 +105,27 @@ public class KwsEnterpriseController {
      * @author zk
      * @date 2023/06/02
      **/
+    @Deprecated
     @PostMapping("/update")
     public HttpResult update(@RequestBody KwsEnterpriseReqVo reqVo) throws Exception {
         kwsEntService.update(reqVo);
         return HttpResult.ok(HttpStatus.MSG_005);
     }
 
+    /**
+     * @return HttpResult
+     * @description 更新资质
+     * @author zk
+     * @date 2023/06/02
+     **/
+    @PostMapping("/updateCertificate")
+    public HttpResult updateCertificate(@RequestBody UpdateCertificateReqVo reqVo) throws Exception {
+        kwsEntService.updateCertificate(reqVo);
+        return HttpResult.ok(HttpStatus.MSG_005);
+    }
+
+
+
     /**
      * @param ids {ids:主键ID(多个以逗号隔开)}
      * @return HttpResult
@@ -132,8 +147,8 @@ public class KwsEnterpriseController {
      * @date 2023/06/02
      **/
     @PostMapping(value = "/approval")
-    public HttpResult approval(@Valid @RequestBody KwsEntCheckTrack params) {
-        kwsEntService.approval(params);
+    public HttpResult approval(@Valid @RequestBody ApprovalReqVo reqVo) {
+        kwsEntService.approval(reqVo);
         return HttpResult.ok(HttpStatus.MSG_004);
     }
 

+ 3 - 3
sckw-modules/sckw-system/src/main/java/com/sckw/system/controller/KwsMenuController.java

@@ -3,7 +3,7 @@ package com.sckw.system.controller;
 import com.sckw.core.web.response.HttpResult;
 import com.sckw.system.model.KwsMenu;
 import com.sckw.system.model.vo.req.FindMenuTreeReqVo;
-import com.sckw.system.model.vo.req.RoleBindMeunReqVo;
+import com.sckw.system.model.vo.req.RoleBindMenuReqVo;
 import com.sckw.system.service.KwsMenuService;
 import jakarta.validation.Valid;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -95,8 +95,8 @@ public class KwsMenuController {
      * @date: 2023/6/13
      */
     @PostMapping("/roleBindMeun")
-    public HttpResult roleBindMeun(@Valid @RequestBody RoleBindMeunReqVo reqVo) {
-        kwsMenuService.roleBindMeun(reqVo);
+    public HttpResult roleBindMenu(@Valid @RequestBody RoleBindMenuReqVo reqVo) {
+        kwsMenuService.roleBindMenu(reqVo);
         return HttpResult.ok();
     }
 }

+ 11 - 0
sckw-modules/sckw-system/src/main/java/com/sckw/system/dao/KwsEntCertificateDao.java

@@ -2,6 +2,8 @@ package com.sckw.system.dao;
 
 import com.sckw.system.model.KwsEntCertificate;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
 import java.util.List;
 
 /**
@@ -55,4 +57,13 @@ public interface KwsEntCertificateDao {
      * @date: 2023/6/25
      */
     List<KwsEntCertificate> selectByEntId(Long id);
+
+    /**
+     * @param entId 企业id, type 资质类型
+     * @return KwsEntCertificate
+     * @desc: 查某企业下的某类型的资质
+     * @author: czh
+     * @date: 2023/6/30
+     */
+    List<KwsEntCertificate> findByEntType(@Param(value = "entId") Long entId, @Param(value = "type") Integer type);
 }

+ 18 - 0
sckw-modules/sckw-system/src/main/java/com/sckw/system/dao/KwsEnterpriseDao.java

@@ -3,6 +3,7 @@ package com.sckw.system.dao;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.sckw.system.model.KwsEnterprise;
 import com.sckw.system.model.pojo.FindEntUserPojo;
+import com.sckw.system.model.pojo.FindManagePojo;
 import com.sckw.system.model.vo.req.EntFindPageReqVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -87,4 +88,21 @@ public interface KwsEnterpriseDao {
      */
     List<FindEntUserPojo> findUserByEntIds(List<Long> list);
 
+    /**
+     * @param entId 企业id
+     * @return FindManagePojo
+     * @desc: 查企业的管理员
+     * @author: czh
+     * @date: 2023/6/29
+     */
+    FindManagePojo findManageInfoByEntId(Long entId);
+
+    /**
+     * @param entId 企业id
+     * @return FindManagePojo
+     * @desc: 认证前查企业的管理员
+     * @author: czh
+     * @date: 2023/6/29
+     */
+    FindManagePojo findManageInfoByEntIdBeforeApproval(Long entId);
 }

+ 9 - 0
sckw-modules/sckw-system/src/main/java/com/sckw/system/dao/KwsMenuDao.java

@@ -16,6 +16,14 @@ import java.util.Map;
 @Mapper
 public interface KwsMenuDao {
 
+    /**
+     * @desc: 条件查询
+     * @author: czh
+     * @date: 2023/6/26
+     * @return
+     */
+    List<KwsMenu> select(KwsMenu kwsMenu);
+
     /**
      * @desc: 全量查
      * @author: czh
@@ -60,4 +68,5 @@ public interface KwsMenuDao {
      * @throws Exception
      */
     List<KwsMenuResVo> findList(FindMenuTreePojo params);
+
 }

+ 11 - 4
sckw-modules/sckw-system/src/main/java/com/sckw/system/dubbo/RemoteUserServiceImpl.java

@@ -12,6 +12,7 @@ import com.sckw.system.dao.KwsUserLoginDao;
 import com.sckw.system.model.*;
 import com.sckw.system.model.pojo.FindMenuTreePojo;
 import com.sckw.system.model.vo.req.ForgetPasswordReqVo;
+import com.sckw.system.model.vo.res.CertificateResVo;
 import com.sckw.system.model.vo.res.KwsMenuResVo;
 import com.sckw.system.service.KwsEnterpriseService;
 import com.sckw.system.service.KwsMenuService;
@@ -62,10 +63,7 @@ public class RemoteUserServiceImpl implements RemoteUserService {
         if (CollectionUtils.isEmpty(kwsUserDepts)) {
             return Collections.emptyList();
         }
-
-        List<KwsUserDeptResDto> list = new ArrayList<>();
-        BeanUtils.copyProperties(kwsUserDepts, list, false);
-        return list;
+        return BeanUtils.copyToList(kwsUserDepts, KwsUserDeptResDto.class);
     }
 
     @Override
@@ -141,6 +139,15 @@ public class RemoteUserServiceImpl implements RemoteUserService {
         return userLoginReqDto;
     }
 
+    @Override
+    public List<EntCertificateResDto> queryCertificateByEntId(Long entId) {
+        List<CertificateResVo> certificate = kwsEnterpriseService.queryCertificate(entId);
+        if (CollectionUtils.isEmpty(certificate)) {
+            return Collections.emptyList();
+        }
+        return BeanUtils.copyToList(certificate, EntCertificateResDto.class);
+    }
+
     @Override
     public void register(RegisterReqDto reqDto) throws SystemException {
         kwsUserService.register(reqDto);

+ 2 - 0
sckw-modules/sckw-system/src/main/java/com/sckw/system/model/KwsMenu.java

@@ -5,6 +5,7 @@ import jakarta.validation.constraints.NotBlank;
 import jakarta.validation.constraints.NotNull;
 import lombok.Data;
 
+import java.io.Serial;
 /**
  * 菜单
  * @author zk
@@ -38,6 +39,7 @@ public class KwsMenu extends BaseModel {
     /**
      * 权限标识
      */
+    @NotBlank(message = "菜单编号不能为空")
     private String perms;
 
     /**

+ 25 - 0
sckw-modules/sckw-system/src/main/java/com/sckw/system/model/pojo/FindManagePojo.java

@@ -0,0 +1,25 @@
+package com.sckw.system.model.pojo;
+
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+
+/**
+ * @author czh
+ * @desc 管理员信息
+ * @date 2023/6/29
+ */
+@Data
+public class FindManagePojo implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 5500630541611860912L;
+
+    private Long userId;
+
+    private Long deptId;
+
+    private Long roleId;
+
+}

+ 30 - 0
sckw-modules/sckw-system/src/main/java/com/sckw/system/model/vo/req/ApprovalReqVo.java

@@ -0,0 +1,30 @@
+package com.sckw.system.model.vo.req;
+
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @author czh
+ * @desc 审批入参
+ * @date 2023/6/30
+ */
+@Data
+public class ApprovalReqVo implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = -4901625560885540709L;
+
+    /**
+     * 资质id
+     */
+    private String certificateIds;
+
+    /**
+     * 状态
+     */
+    private Integer status;
+
+}

+ 4 - 2
sckw-modules/sckw-system/src/main/java/com/sckw/system/model/vo/req/BusinessLicense.java

@@ -5,7 +5,9 @@ import lombok.Data;
 import java.util.Date;
 
 /**
- * 执照
+ * @desc: 资质
+ * @author: czh
+ * @date: 2023/6/30
  */
 @Data
 public class BusinessLicense {
@@ -38,7 +40,7 @@ public class BusinessLicense {
     /**
      * 有效期
      */
-    private Date validity;
+    private Date expireTime;
 
     /**
      * 备注

+ 1 - 1
sckw-modules/sckw-system/src/main/java/com/sckw/system/model/vo/req/RoleBindMeunReqVo.java → sckw-modules/sckw-system/src/main/java/com/sckw/system/model/vo/req/RoleBindMenuReqVo.java

@@ -13,7 +13,7 @@ import java.io.Serializable;
  * @date 2023/6/13
  */
 @Data
-public class RoleBindMeunReqVo implements Serializable {
+public class RoleBindMenuReqVo implements Serializable {
 
     @Serial
     private static final long serialVersionUID = -9121728977645694470L;

+ 26 - 0
sckw-modules/sckw-system/src/main/java/com/sckw/system/model/vo/req/UpdateCertificateReqVo.java

@@ -0,0 +1,26 @@
+package com.sckw.system.model.vo.req;
+
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author czh
+ * @desc 更新企业资质
+ * @date 2023/6/29
+ */
+@Data
+public class UpdateCertificateReqVo implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = -7685010332822613036L;
+
+    /**
+     * 资质
+     */
+    List<BusinessLicense> certificateInfo;
+
+}

+ 6 - 0
sckw-modules/sckw-system/src/main/java/com/sckw/system/model/vo/res/CertificateResVo.java

@@ -3,6 +3,7 @@ package com.sckw.system.model.vo.res;
 import lombok.Data;
 
 import java.io.Serializable;
+import java.util.Date;
 
 @Data
 public class CertificateResVo implements Serializable {
@@ -32,4 +33,9 @@ public class CertificateResVo implements Serializable {
      */
     private String certificateRevolt;
 
+    /**
+     * 有效期
+     */
+    private Date expireTime;
+
 }

+ 30 - 0
sckw-modules/sckw-system/src/main/java/com/sckw/system/service/CommonService.java

@@ -0,0 +1,30 @@
+package com.sckw.system.service;
+
+import com.alibaba.fastjson.JSON;
+import com.sckw.core.model.constant.Global;
+import com.sckw.core.utils.StringUtils;
+import com.sckw.core.web.model.EntCertificateInfo;
+import com.sckw.core.web.model.LoginEntInfo;
+import com.sckw.redis.utils.RedissonUtils;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * @author czh
+ * @desc TODO
+ * @date 2023/6/30
+ */
+@Service
+public class CommonService {
+
+
+    public void updateEntCertificate(Long entId, List<EntCertificateInfo> entCertificateInfoList) {
+        String string = RedissonUtils.getString(Global.REDIS_ENTERPRISE_PREFIX + entId);
+        if (StringUtils.isBlank(string)) {
+            LoginEntInfo loginEntInfo = JSON.parseObject(string, LoginEntInfo.class);
+            loginEntInfo.setCertificateInfo(entCertificateInfoList);
+            RedissonUtils.putString(Global.REDIS_ENTERPRISE_PREFIX + entId, JSON.toJSONString(loginEntInfo), Global.COMMON_EXPIRE);
+        }
+    }
+}

+ 105 - 38
sckw-modules/sckw-system/src/main/java/com/sckw/system/service/KwsEnterpriseService.java

@@ -19,14 +19,15 @@ import com.sckw.core.utils.IdWorker;
 import com.sckw.core.utils.StringUtils;
 import com.sckw.core.web.constant.HttpStatus;
 import com.sckw.core.web.context.LoginUserHolder;
+import com.sckw.core.web.model.EntCertificateInfo;
 import com.sckw.system.api.model.dto.req.RegisterReqDto;
 import com.sckw.system.api.model.dto.res.RegisterResDto;
 import com.sckw.system.dao.*;
 import com.sckw.system.model.*;
 import com.sckw.system.model.pojo.FindEntUserPojo;
+import com.sckw.system.model.pojo.FindManagePojo;
 import com.sckw.system.model.vo.req.*;
 import com.sckw.system.model.vo.res.CertificateResVo;
-import com.sckw.system.model.vo.res.IdResVo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -65,7 +66,7 @@ public class KwsEnterpriseService {
     private KwsDeptService kwsDeptService;
 
     @Autowired
-    private KwsMenuService kwsMenuService;
+    private CommonService commonService;
 
     @Autowired
     private KwsRoleService kwsRoleService;
@@ -313,12 +314,12 @@ public class KwsEnterpriseService {
             KwsEntCertificate kwsEntCertificate = new KwsEntCertificate();
             //todo 上传证书正反面,将url放到两个入参里
             kwsEntCertificate.setEntId(entId);
-            kwsEntCertificate.setStatus(Global.NO);
             kwsEntCertificate.setCreateBy(userId);
             kwsEntCertificate.setCreateTime(date);
             kwsEntCertificate.setUpdateBy(userId);
             kwsEntCertificate.setUpdateTime(date);
             kwsEntCertificate.setDelFlag(Global.NO);
+            kwsEntCertificate.setStatus(ApprovalEnum.PROCESS.getCode());
             BeanUtils.copyProperties(businessLicense, kwsEntCertificate);
             kwsEntCertificate.setId(new IdWorker(1).nextId());
             kwsEntCertificates.add(kwsEntCertificate);
@@ -344,55 +345,65 @@ public class KwsEnterpriseService {
      * 企业审批
      */
     @Transactional(rollbackFor = Exception.class)
-    public void approval(KwsEntCheckTrack kwsEntCheckTrack) throws SystemException {
+    public void approval(ApprovalReqVo reqVo) throws SystemException {
+        Integer status = reqVo.getStatus();
+        Long entId = null;
+        String certificateIds = reqVo.getCertificateIds();
+        List<KwsEntCertificate> kwsEntCertificates = new ArrayList<>();
+        for (String id : certificateIds.split(",")) {
+            KwsEntCertificate kwsEntCertificate = kwsEntCertificateDao.selectByKey(Long.parseLong(id));
+            if (Objects.isNull(kwsEntCertificate)) {
+                throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
+            }
+            kwsEntCertificate.setStatus(ApprovalEnum.OK.getCode() == status ? Global.NO : Global.YES);
+            kwsEntCertificateDao.update(kwsEntCertificate);
+
+            List<KwsEntCertificate> previous = kwsEntCertificateDao.findByEntType(kwsEntCertificate.getEntId(), kwsEntCertificate.getType());
+            previous = previous.stream().filter(item -> item.getId() != Long.parseLong(id)).toList();
+            if (!CollectionUtils.isEmpty(previous)) {
+                for (KwsEntCertificate kwsEntCertificate1 : previous) {
+                    kwsEntCertificate1.setDelFlag(Global.YES);
+                    kwsEntCertificateDao.update(kwsEntCertificate1);
+                }
+            }
+
+            entId = kwsEntCertificate.getEntId();
+            kwsEntCertificates.add(kwsEntCertificate);
+        }
+
         /*更新企业信息主表审批状态*/
-        Long entId = kwsEntCheckTrack.getEntId();
         KwsEnterprise kwsEnterprise = checkKwsEnterpriseById(entId);
         Integer currentApproval = kwsEnterprise.getApproval();
-        kwsEnterprise.setApproval(kwsEntCheckTrack.getStatus());
+        kwsEnterprise.setApproval(reqVo.getStatus());
         if (kwsEnterpriseDao.approval(kwsEnterprise) <= 0) {
             throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
         }
 
         /*新增审批记录*/
+        KwsEntCheckTrack kwsEntCheckTrack = new KwsEntCheckTrack();
+        kwsEntCheckTrack.setEntId(entId);
         if (kwsEntCheckTrackDao.insert(kwsEntCheckTrack) <= 0) {
             throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
         }
 
         /*第一次审批通过(非更新资质审批通过),构建机构角色等*/
-        if (ApprovalEnum.OK.getCode() == kwsEntCheckTrack.getStatus() && ApprovalEnum.PROCESS.getCode() == currentApproval) {
-            /*审批通过,构建管理员角色及权限*/
-            /*1、新增管理员机构*/
-            KwsDept kwsDept = new KwsDept();
-            Integer systemType = SystemTypeEnum.COMPANY.getCode();
-            long deptId = new IdWorker(1L).nextId();
-            kwsDept.setEntId(entId);
-            kwsDept.setName(Global.MANAGE_DEPT_NAME);
-            kwsDept.setSystemType(systemType);
-            kwsDept.setCompany(Global.NO);
-            kwsDept.setId(deptId);
-            kwsDeptService.add(kwsDept);
-
-            /*2、新增管理员角色*/
-            EditRoleReqVo editRoleReqVo = new EditRoleReqVo();
-            List<KwsMenu> list = kwsMenuService.selectAll();
-            if (CollectionUtils.isEmpty(list)) {
-                throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
-            }
-            editRoleReqVo.setName(Global.MANAGE_NAME);
-            editRoleReqVo.setCurrentUnitId(entId);
-            editRoleReqVo.setMenuIds(String.join(",", list.stream().map(KwsMenu::getId).map(String::valueOf).toList()));
-            editRoleReqVo.setVisiblePersonal(false);
-            IdResVo idResVo = kwsRoleService.add(editRoleReqVo);
-
-            /*3、绑定角色等*/
-            KwsUser userByAccount = kwsUserService.getUserByAccount(kwsEnterprise.getPhone(), SystemTypeEnum.COMPANY.getCode());
-            if (Objects.isNull(userByAccount)) {
-                throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
+        if (ApprovalEnum.OK.getCode() == status) {
+            commonService.updateEntCertificate(entId, BeanUtils.copyToList(kwsEntCertificates, EntCertificateInfo.class));
+            if (ApprovalEnum.PROCESS.getCode() == currentApproval) {
+                /*审批通过,绑定角色*/
+                FindManagePojo findManagePojo = kwsEnterpriseDao.findManageInfoByEntIdBeforeApproval(entId);
+                if (Objects.isNull(findManagePojo)) {
+                    throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
+                }
+                KwsUser userByAccount = kwsUserService.getUserByAccount(kwsEnterprise.getPhone(), SystemTypeEnum.COMPANY.getCode());
+                if (Objects.isNull(userByAccount)) {
+                    throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
+                }
+                kwsUserService.fillUserRole(String.valueOf(findManagePojo.getRoleId()),userByAccount.getId(), SystemTypeEnum.COMPANY.getCode());
             }
-            kwsUserService.fillUserRole(String.valueOf(idResVo.getId()),userByAccount.getId(), systemType);
         }
 
+
     }
 
     private KwsEnterprise checkKwsEnterpriseById(long id) throws SystemException {
@@ -421,9 +432,9 @@ public class KwsEnterpriseService {
     /**
      * 企业证件信息
      */
-    public List<CertificateResVo> certificate(Long id) throws SystemException {
+    public List<CertificateResVo> certificate(Long entId) throws SystemException {
         /*查企业资质*/
-        List<KwsEntCertificate> kwsEntCertificates = kwsEntCertificateDao.selectByEntId(id);
+        List<KwsEntCertificate> kwsEntCertificates = kwsEntCertificateDao.selectByEntId(entId);
         if (CollectionUtils.isEmpty(kwsEntCertificates)) {
             throw new SystemException(HttpStatus.QUERY_FAIL_CODE, HttpStatus.ENTCERTIFICATES_NOT_EXISTS);
         }
@@ -439,6 +450,28 @@ public class KwsEnterpriseService {
         return list;
     }
 
+    /**
+     * 企业证件信息
+     */
+    public List<CertificateResVo> queryCertificate(Long entId) throws SystemException {
+        /*查企业资质*/
+        List<KwsEntCertificate> kwsEntCertificates = kwsEntCertificateDao.selectByEntId(entId);
+        if (CollectionUtils.isEmpty(kwsEntCertificates)) {
+            return Collections.emptyList();
+        }
+        /*拼装返参*/
+        List<CertificateResVo> list = new ArrayList<>();
+        kwsEntCertificates.forEach(item -> {
+            CertificateResVo certificateResVo = new CertificateResVo();
+            certificateResVo.setTypeName(Objects.requireNonNull(EntTypeEnum.getName(item.getType())).getName());
+            BeanUtils.copyProperties(item, certificateResVo);
+            list.add(certificateResVo);
+        });
+        return list;
+    }
+
+
+
     /**
      * @param userId 用户id
      * @return KwsEnterprise
@@ -476,4 +509,38 @@ public class KwsEnterpriseService {
     public List<KwsEntCheckTrack> entCheck(Long entId) {
         return kwsEntCheckTrackDao.findList(entId);
     }
+
+    /**
+     * @param reqVo 入参
+     * @desc: 更新企业资质
+     * @author: czh
+     * @date: 2023/6/29
+     */
+    public void updateCertificate(UpdateCertificateReqVo reqVo) {
+        for (BusinessLicense businessLicense : reqVo.getCertificateInfo()) {
+            long id = businessLicense.getId();
+            KwsEntCertificate kwsEntCertificate = kwsEntCertificateDao.selectByKey(id);
+            if (Objects.isNull(kwsEntCertificate)) {
+                throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
+            }
+
+            kwsEntCertificate.setCode(businessLicense.getCode());
+            kwsEntCertificate.setCertificateMian(businessLicense.getCertificateMian());
+            kwsEntCertificate.setCertificateRevolt(businessLicense.getCertificateRevolt());
+            kwsEntCertificate.setExpireTime(businessLicense.getExpireTime());
+            kwsEntCertificate.setRemark(businessLicense.getRemark());
+            kwsEntCertificate.setStatus(Global.YES);
+            kwsEntCertificate.setUpdateBy(LoginUserHolder.getUserId());
+            kwsEntCertificate.setUpdateTime(new Date());
+            kwsEntCertificate.setDelFlag(Global.NO);
+            if (kwsEntCertificateDao.update(kwsEntCertificate) <= 0) {
+                throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
+            }
+
+            KwsEnterprise kwsEnterprise = new KwsEnterprise();
+            kwsEnterprise.setId(kwsEntCertificate.getEntId());
+            kwsEnterprise.setApproval(ApprovalEnum.REFRESH.getCode());
+            kwsEnterpriseDao.update(kwsEnterprise);
+        }
+    }
 }

+ 43 - 5
sckw-modules/sckw-system/src/main/java/com/sckw/system/service/KwsMenuService.java

@@ -3,6 +3,7 @@ package com.sckw.system.service;
 import java.util.*;
 
 import cn.hutool.core.collection.CollectionUtil;
+import com.alibaba.fastjson.JSON;
 import com.sckw.core.exception.SystemException;
 import com.sckw.core.model.constant.Global;
 import com.sckw.core.utils.BeanUtils;
@@ -10,17 +11,16 @@ import com.sckw.core.utils.CollectionUtils;
 import com.sckw.core.utils.IdWorker;
 import com.sckw.core.web.constant.HttpStatus;
 import com.sckw.core.web.context.LoginUserHolder;
-import com.sckw.core.web.model.LoginUserInfo;
 import com.sckw.core.web.response.HttpResult;
-import com.sckw.redis.utils.RedissonUtils;
 import com.sckw.system.dao.*;
 import com.sckw.system.model.*;
 import com.sckw.system.model.pojo.FindMenuTreePojo;
 import com.sckw.system.model.vo.req.FindMenuTreeReqVo;
-import com.sckw.system.model.vo.req.RoleBindMeunReqVo;
+import com.sckw.system.model.vo.req.RoleBindMenuReqVo;
 import com.sckw.system.model.vo.res.KwsMenuResVo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 /**
  * 菜单service接口
@@ -53,6 +53,7 @@ public class KwsMenuService {
      * @return
      * @throws Exception
      */
+    @Transactional(rollbackFor = {})
     public void add(KwsMenu params) throws Exception {
         Long parentId = params.getParentId();
         if (parentId.compareTo(0L) != 0) {
@@ -62,11 +63,48 @@ public class KwsMenuService {
             }
         }
 
+        //有重复的序号,则把后面的都加1
+        if(!Objects.isNull(params.getSort())){
+            moveSort(params);
+        }
+
         if (kwsMenuDao.insert(params) <= 0) {
             throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
         }
     }
 
+    /**
+     * @param params 需要新增的菜单
+     * @return
+     * @desc: 菜单序号排序
+     * @author: czh
+     * @date: 2023/6/29
+     */
+    private void moveSort(KwsMenu params) {
+        KwsMenu param = new KwsMenu();
+        param.setParentId(params.getParentId());
+        List<KwsMenu> list = kwsMenuDao.select(param);
+        if (CollectionUtils.isEmpty(list)) {
+            return;
+        }
+        list = list.stream().filter(item -> !Objects.isNull(item.getSort())).toList();
+        if (CollectionUtils.isEmpty(list)) {
+            return;
+        }
+        List<Integer> sortList = list.stream().map(KwsMenu::getSort).toList();
+        int indexOf = sortList.indexOf(params.getSort());
+        if (indexOf >= 0) {
+            for (int n = indexOf; n < list.size(); n++) {
+                KwsMenu kwsMenu = list.get(n);
+                kwsMenu.setSort(kwsMenu.getSort() + 1);
+                kwsMenuDao.update(kwsMenu);
+                if (n + 1 < list.size() && list.get(n + 1).getSort() > kwsMenu.getSort()) {
+                    break;
+                }
+            }
+        }
+    }
+
     /**
      * @param ids 主键di
      * @desc: 根据主键删除菜单
@@ -240,7 +278,7 @@ public class KwsMenuService {
      * @author: czh
      * @date: 2023/6/13
      */
-    public void roleBindMeun(RoleBindMeunReqVo reqVo) {
+    public void roleBindMenu(RoleBindMenuReqVo reqVo) {
         String[] split = reqVo.getMenuIds().split(",");
         List<KwsMenuRights> list = new ArrayList<>();
         Date date = new Date();
@@ -264,7 +302,7 @@ public class KwsMenuService {
         }
     }
 
-    public List<KwsMenu> selectAll(){
+    public List<KwsMenu> selectAll() {
         return kwsMenuDao.selectAll();
     }
 }

+ 7 - 38
sckw-modules/sckw-system/src/main/java/com/sckw/system/service/KwsRoleService.java

@@ -9,13 +9,12 @@ import com.sckw.core.utils.StringUtils;
 import com.sckw.core.web.config.CustomConfig;
 import com.sckw.core.web.constant.HttpStatus;
 import com.sckw.core.web.context.LoginUserHolder;
-import com.sckw.core.web.response.HttpResult;
 import com.sckw.redis.utils.RedissonUtils;
 import com.sckw.system.dao.*;
 import com.sckw.system.model.*;
 import com.sckw.system.model.pojo.FindMenuTreePojo;
 import com.sckw.system.model.vo.req.EditRoleReqVo;
-import com.sckw.system.model.vo.req.RoleBindMeunReqVo;
+import com.sckw.system.model.vo.req.RoleBindMenuReqVo;
 import com.sckw.system.model.vo.req.UserBindRoleReqVo;
 import com.sckw.system.model.vo.res.IdResVo;
 import com.sckw.system.model.vo.res.KwsMenuResVo;
@@ -92,11 +91,11 @@ public class KwsRoleService {
         }
 
         /*2、绑定菜单功能*/
-        RoleBindMeunReqVo roleBindMeunReqVo = new RoleBindMeunReqVo();
-        roleBindMeunReqVo.setRoleId(roleId);
-        roleBindMeunReqVo.setEntId(reqVo.getCurrentUnitId());
-        roleBindMeunReqVo.setMenuIds(reqVo.getMenuIds());
-        kwsMenuService.roleBindMeun(roleBindMeunReqVo);
+        RoleBindMenuReqVo roleBindMenuReqVo = new RoleBindMenuReqVo();
+        roleBindMenuReqVo.setRoleId(roleId);
+        roleBindMenuReqVo.setEntId(reqVo.getCurrentUnitId());
+        roleBindMenuReqVo.setMenuIds(reqVo.getMenuIds());
+        kwsMenuService.roleBindMenu(roleBindMenuReqVo);
 
         /*3、设置数据权限*/
         if (reqVo.getVisiblePersonal()) {
@@ -290,28 +289,7 @@ public class KwsRoleService {
             throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
         }
 
-        /*3、存用户机构信息*/
-        List<KwsRole> kwsRoles = kwsRoleDao.selectBatchByKeys(roleIdList);
-        List<KwsUserDept> kwsUserDeptList = new ArrayList<>();
-        kwsRoles.forEach(item -> {
-            KwsUserDept kwsUserDept = new KwsUserDept();
-            kwsUserDept.setUserId(userId);
-            kwsUserDept.setDeptId(item.getDeptId());
-            kwsUserDept.setId(new IdWorker(1).nextId());
-            kwsUserDept.setRemark("");
-            kwsUserDept.setStatus(Global.NO);
-            kwsUserDept.setCreateBy(currentUserId);
-            kwsUserDept.setCreateTime(date);
-            kwsUserDept.setUpdateBy(currentUserId);
-            kwsUserDept.setUpdateTime(date);
-            kwsUserDept.setDelFlag(Global.NO);
-            kwsUserDeptList.add(kwsUserDept);
-        });
-        if (kwsUserDeptDao.saveBatch(kwsUserDeptList) < kwsUserDeptList.size()) {
-            throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
-        }
-
-        /*4、后置处理,修改redis中的信息*/
+        /*3、后置处理,修改redis中的信息*/
         FindMenuTreePojo findMenuTreePojo = new FindMenuTreePojo();
         findMenuTreePojo.setRoleIds(roleIdList);
         List<KwsMenuResVo> kwsMenuResVos = kwsMenuService.findList(findMenuTreePojo);
@@ -342,15 +320,6 @@ public class KwsRoleService {
             }
         }
 
-        List<KwsUserDept> currentUserDeptList = kwsUserDeptDao.findAllByUserId(reqVo.getUserId());
-        if (!CollectionUtils.isEmpty(currentUserDeptList)) {
-            for (KwsUserDept kwsUserDept : currentUserDeptList) {
-                kwsUserDept.setDelFlag(Global.YES);
-                if (kwsUserDeptDao.update(kwsUserDept) <= 0) {
-                    throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
-                }
-            }
-        }
     }
 
 

+ 47 - 4
sckw-modules/sckw-system/src/main/java/com/sckw/system/service/KwsUserService.java

@@ -13,11 +13,9 @@ 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.model.KwsDept;
-import com.sckw.system.model.KwsEnterprise;
-import com.sckw.system.model.KwsUser;
-import com.sckw.system.model.KwsUserDept;
+import com.sckw.system.model.*;
 import com.sckw.system.model.vo.req.*;
+import com.sckw.system.model.vo.res.IdResVo;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -81,6 +79,16 @@ public class KwsUserService {
 
     @Transactional(rollbackFor = {})
     public RegisterResDto register(RegisterReqDto reqDto) throws SystemException {
+        EntFindPageReqVo entFindPageReqVo = new EntFindPageReqVo();
+        entFindPageReqVo.setFirmName(reqDto.getEntName());
+        List<KwsEnterprise> list = kwsEnterpriseDao.findList(entFindPageReqVo);
+        if (!CollectionUtils.isEmpty(list)) {
+            throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
+        }
+
+        /*1、数据校验*/
+        checkAccountValid(reqDto.getPhone(), reqDto.getSystemType());
+
         /*存用户表、企业表,暂时不处理角色关系,需要认证*/
         KwsUser kwsUser = new KwsUser();
         long userId = new IdWorker(1).nextId();
@@ -117,6 +125,41 @@ public class KwsUserService {
             if (kwsEnterpriseDao.insert(kwsEnterprise) <= 0) {
                 throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
             }
+
+            /*1、新增管理员机构*/
+            KwsDept kwsDept = new KwsDept();
+            Integer systemType = SystemTypeEnum.COMPANY.getCode();
+            long deptId = new IdWorker(1L).nextId();
+            kwsDept.setEntId(entId);
+            kwsDept.setName(Global.MANAGE_DEPT_NAME);
+            kwsDept.setSystemType(systemType);
+            kwsDept.setCompany(Global.NO);
+            kwsDept.setId(deptId);
+            kwsDeptService.add(kwsDept);
+
+            /*3、绑定用户机构关系*/
+            KwsUserDept kwsUserDept = new KwsUserDept();
+            kwsUserDept.setUserId(userId);
+            kwsUserDept.setDeptId(deptId);
+            kwsUserDept.setId(new IdWorker(1).nextId());
+            kwsUserDept.setRemark("");
+            kwsUserDept.setStatus(Global.NO);
+            kwsUserDept.setDelFlag(Global.NO);
+            if (kwsUserDeptDao.insert(kwsUserDept) <= 0) {
+                throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
+            }
+
+            /*2、新增管理员角色*/
+            EditRoleReqVo editRoleReqVo = new EditRoleReqVo();
+            List<KwsMenu> kwsMenus = kwsMenuService.selectAll();
+            if (CollectionUtils.isEmpty(kwsMenus)) {
+                throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
+            }
+            editRoleReqVo.setName(Global.MANAGE_NAME);
+            editRoleReqVo.setCurrentUnitId(entId);
+            editRoleReqVo.setMenuIds(String.join(",", kwsMenus.stream().map(KwsMenu::getId).map(String::valueOf).toList()));
+            editRoleReqVo.setVisiblePersonal(false);
+            kwsRoleService.add(editRoleReqVo);
         }
 
         return registerResDto;

+ 5 - 0
sckw-modules/sckw-system/src/main/resources/mapper/KwsEntCertificateDao.xml

@@ -29,10 +29,15 @@
     from kws_ent_certificate
     where id = #{id,jdbcType=BIGINT}
   </select>
+
   <select id="selectByEntId" resultType="com.sckw.system.model.KwsEntCertificate">
     select a.* from kws_ent_certificate a where a.ent_id = #{id} and a.del_flag = 0
   </select>
 
+  <select id="findByEntType" resultType="com.sckw.system.model.KwsEntCertificate">
+    select a.* from kws_ent_certificate a where a.ent_id = #{id} and a.type = #{type} and a.del_flag = 0
+  </select>
+
   <insert id="insert" parameterType="com.sckw.system.model.KwsEntCertificate">
     insert into kws_ent_certificate
     <trim prefix="(" suffix=")" suffixOverrides=",">

+ 39 - 0
sckw-modules/sckw-system/src/main/resources/mapper/KwsEnterpriseDao.xml

@@ -121,6 +121,45 @@
           #{item}
         </foreach>
   </select>
+  <select id="findManageInfoByEntId" resultType="com.sckw.system.model.pojo.FindManagePojo">
+    select distinct d.id userId,
+           b.id deptId,
+           f.id roleId
+      from kws_enterprise a
+      left join kws_dept b on a.id = b.ent_id
+      left join kws_user_dept c on b.id = c.dept_id
+      left join kws_user d on c.user_id = d.id
+      left join kws_user_role e on d.id = e.user_id
+      left join kws_role f on e.role_id = f.id
+     where a.del_flag = 0
+       and b.del_flag = 0
+       and c.del_flag = 0
+       and d.del_flag = 0
+       and e.del_flag = 0
+       and f.del_flag = 0
+       and d.is_main = 1
+       and d.system_type = 2
+       and a.id = #{entId}
+  </select>
+  <select id="findManageInfoByEntIdBeforeApproval" resultType="com.sckw.system.model.pojo.FindManagePojo">
+    select distinct d.id userId,
+                    b.id deptId,
+                    f.id roleId
+    from kws_enterprise a
+           left join kws_dept b on a.id = b.ent_id
+           left join kws_user_dept c on b.id = c.dept_id
+           left join kws_user d on c.user_id = d.id
+           left join kws_role f on a.id = f.dept_id
+    where a.del_flag = 0
+      and b.del_flag = 0
+      and c.del_flag = 0
+      and d.del_flag = 0
+      and f.del_flag = 0
+      and d.is_main = 1
+      and d.system_type = 2
+      and a.id = #{entId}
+      and f.name = '系统管理员'
+  </select>
 
   <insert id="insert" parameterType="com.sckw.system.model.KwsEnterprise">
     insert into kws_enterprise

+ 56 - 0
sckw-modules/sckw-system/src/main/resources/mapper/KwsMenuDao.xml

@@ -298,7 +298,63 @@
       #{item}
     </foreach>
   </select>
+
   <select id="selectAll" resultType="com.sckw.system.model.KwsMenu">
     select * from kws_menu where del_flag = 0
   </select>
+
+  <select id="select" resultType="com.sckw.system.model.KwsMenu">
+    select *
+      from kws_menu
+     where del_flag = 0
+    <if test="id != null">
+      and id = #{id,jdbcType=BIGINT}
+    </if>
+    <if test="clientType != null">
+      and client_type = #{clientType,jdbcType=INTEGER}
+    </if>
+    <if test="parentId != null">
+      and parent_id = #{parentId,jdbcType=BIGINT}
+    </if>
+    <if test="name != null">
+      and name = #{name,jdbcType=VARCHAR}
+    </if>
+    <if test="url != null">
+      and url = #{url,jdbcType=VARCHAR}
+    </if>
+    <if test="links != null">
+      and links = #{links,jdbcType=VARCHAR}
+    </if>
+    <if test="perms != null">
+      and perms = #{perms,jdbcType=VARCHAR}
+    </if>
+    <if test="type != null">
+      and type = #{type,jdbcType=INTEGER}
+    </if>
+    <if test="icon != null">
+      and icon = #{icon,jdbcType=VARCHAR}
+    </if>
+    <if test="sort != null">
+      and sort = #{sort,jdbcType=INTEGER}
+    </if>
+    <if test="level != null">
+      and level = #{level,jdbcType=INTEGER}
+    </if>
+    <if test="custom != null">
+      and custom = #{custom,jdbcType=INTEGER}
+    </if>
+    <if test="isDisplay != null">
+      and is_display = #{isDisplay,jdbcType=INTEGER}
+    </if>
+    <if test="isMain != null">
+      and is_main = #{isMain,jdbcType=INTEGER}
+    </if>
+    <if test="usingRoles != null">
+      and using_roles = #{usingRoles,jdbcType=VARCHAR}
+    </if>
+    <if test="remark != null">
+     and remark = #{remark,jdbcType=VARCHAR}
+    </if>
+    order by sort
+  </select>
 </mapper>

+ 1 - 1
sckw-modules/sckw-system/src/main/resources/mapper/KwsUserDao.xml

@@ -271,7 +271,7 @@
   </select>
 
   <select id="queryUserDeptByUserId" resultType="com.sckw.system.model.KwsUserDept">
-    select a.* from kws_user_depot a where a.user_id = #{userId} and a.del_flag = 0
+    select a.* from kws_user_dept a where a.user_id = #{userId} and a.del_flag = 0
   </select>
 
   <select id="queryDeptByIds" resultType="com.sckw.system.model.KwsDept">