PC 2 лет назад
Родитель
Сommit
99659b7398
24 измененных файлов с 658 добавлено и 110 удалено
  1. 2 5
      sckw-auth/src/main/java/com/sckw/auth/service/impl/IndexServiceImpl.java
  2. 12 16
      sckw-common/sckw-common-core/src/main/java/com/sckw/core/aspect/DaoAspect.java
  3. 3 6
      sckw-common/sckw-common-core/src/main/java/com/sckw/core/filter/LoginFilter.java
  4. 1 1
      sckw-common/sckw-common-core/src/main/java/com/sckw/core/global/GlobalExceptionHandler.java
  5. 1 7
      sckw-common/sckw-common-core/src/main/java/com/sckw/core/utils/IdWorker.java
  6. 3 5
      sckw-common/sckw-common-redis/src/main/java/com/sckw/redis/configure/RedissonConfiguration.java
  7. 1 1
      sckw-modules/sckw-system/src/main/java/com/sckw/system/controller/KwsDeptController.java
  8. 3 2
      sckw-modules/sckw-system/src/main/java/com/sckw/system/controller/KwsRoleController.java
  9. 1 1
      sckw-modules/sckw-system/src/main/java/com/sckw/system/controller/KwsUserController.java
  10. 47 0
      sckw-modules/sckw-system/src/main/java/com/sckw/system/dao/KwsAuthorityDao.java
  11. 1 3
      sckw-modules/sckw-system/src/main/java/com/sckw/system/dao/KwsDeptDao.java
  12. 35 0
      sckw-modules/sckw-system/src/main/java/com/sckw/system/dao/KwsEntDeptDao.java
  13. 1 0
      sckw-modules/sckw-system/src/main/java/com/sckw/system/dao/KwsEnterpriseDao.java
  14. 24 0
      sckw-modules/sckw-system/src/main/java/com/sckw/system/model/KwsAuthority.java
  15. 24 0
      sckw-modules/sckw-system/src/main/java/com/sckw/system/model/KwsEntDept.java
  16. 48 0
      sckw-modules/sckw-system/src/main/java/com/sckw/system/model/vo/req/AddRoleReqVo.java
  17. 10 0
      sckw-modules/sckw-system/src/main/java/com/sckw/system/model/vo/req/EntRegisterReqVo.java
  18. 13 2
      sckw-modules/sckw-system/src/main/java/com/sckw/system/service/KwsDeptService.java
  19. 35 7
      sckw-modules/sckw-system/src/main/java/com/sckw/system/service/KwsEnterpriseService.java
  20. 88 31
      sckw-modules/sckw-system/src/main/java/com/sckw/system/service/KwsRoleService.java
  21. 5 22
      sckw-modules/sckw-system/src/main/java/com/sckw/system/service/KwsUserService.java
  22. 168 0
      sckw-modules/sckw-system/src/main/resources/mapper/KwsAuthorityDao.xml
  23. 1 1
      sckw-modules/sckw-system/src/main/resources/mapper/KwsDeptDao.xml
  24. 131 0
      sckw-modules/sckw-system/src/main/resources/mapper/KwsEntDeptDao.xml

+ 2 - 5
sckw-auth/src/main/java/com/sckw/auth/service/impl/IndexServiceImpl.java

@@ -18,7 +18,6 @@ import com.sckw.system.api.model.dto.req.RegisterReqDto;
 import com.sckw.system.api.model.dto.res.*;
 import com.sckw.auth.service.IIndexService;
 import com.sckw.system.api.RemoteUserService;
-import jakarta.annotation.Resource;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.springframework.stereotype.Service;
@@ -34,8 +33,6 @@ public class IndexServiceImpl implements IIndexService {
     @DubboReference(version = "2.0.0", group = "design", check = false)
     private RemoteUserService remoteUserService;
 
-    @Resource
-    private RedissonUtils redissonUtils;
 
     @Override
     public LoginResVo login(LoginReqVo reqDto) {
@@ -100,11 +97,11 @@ public class IndexServiceImpl implements IIndexService {
             String id = String.valueOf(loginResVo.getId());
             String token = EncryUtil.encry(Global.PRI_KEY, id);
             loginResVo.setToken(token);
-            redissonUtils.add(CacheGroup.LOGININFO + id, JSON.toJSONString(loginResVo));
+            RedissonUtils.add(CacheGroup.LOGININFO + id, JSON.toJSONString(loginResVo));
 
             //存权限菜单
             List<UserAccessMenuInfoResDto> userAccessMenuInfo = remoteUserService.queryUserAccessMenu(loginResVo.getId());
-            redissonUtils.add(CacheGroup.ACCESSMENU + id, JSON.toJSONString(userAccessMenuInfo));
+            RedissonUtils.add(CacheGroup.ACCESSMENU + id, JSON.toJSONString(userAccessMenuInfo));
         } catch (Exception e) {
             throw new SystemException(HttpStatus.GLOBAL_EXCEPTION_CODE, HttpStatus.GLOBAL_EXCEPTION_MESSAGE);
         }

+ 12 - 16
sckw-common/sckw-common-core/src/main/java/com/sckw/core/aspect/DaoAspect.java

@@ -14,6 +14,7 @@ import org.springframework.stereotype.Component;
 import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
 import java.util.Date;
+import java.util.Objects;
 
 /**
  * DAO切面,插入创建人,创建时间,修改人,修改时间
@@ -54,13 +55,10 @@ public class DaoAspect {
             for (Object arg : objects) {
                 Long userId = LoginUserHolder.getUserId();
                 String userName = LoginUserHolder.getUserName();
-                if (isProperty(arg, UPDATE_BY) && BeanUtils.getProperty(arg, UPDATE_BY) == null && userId != null) {
+                if (isProperty(arg, UPDATE_BY) && Objects.isNull(BeanUtils.getProperty(arg, UPDATE_BY)) && userId != null) {
                     BeanUtils.setProperty(arg, UPDATE_BY, userId);
                 }
-                if (isProperty(arg, UPDATE_BY_NAME) && StringUtils.isBlank(BeanUtils.getProperty(arg, UPDATE_BY_NAME)) && userName != null) {
-                    BeanUtils.setProperty(arg, UPDATE_BY_NAME, userName);
-                }
-                if (isProperty(arg, UPDATE_TIME) && BeanUtils.getProperty(arg, UPDATE_TIME) != null) {
+                if (isProperty(arg, UPDATE_TIME) && Objects.isNull(BeanUtils.getProperty(arg, UPDATE_TIME))) {
                     BeanUtils.setProperty(arg, UPDATE_TIME, new Date());
                 }
             }
@@ -80,22 +78,20 @@ public class DaoAspect {
         if (objects != null && objects.length > 0) {
             for (Object arg : objects) {
                 Long userId = LoginUserHolder.getUserId();
-                String userName = LoginUserHolder.getUserName();
                 Date date = new Date();
                 if (userId != null) {
-                    if (isProperty(arg, CREATE_BY) && BeanUtils.getProperty(arg, CREATE_BY) == null) {
+                    if (isProperty(arg, CREATE_BY) && Objects.isNull(BeanUtils.getProperty(arg, CREATE_BY))) {
                         BeanUtils.setProperty(arg, CREATE_BY, userId);
                     }
-                    if (isProperty(arg, UPDATE_BY) && BeanUtils.getProperty(arg, UPDATE_BY) == null) {
+                    if (isProperty(arg, UPDATE_BY) && Objects.isNull(BeanUtils.getProperty(arg, UPDATE_BY))) {
                         BeanUtils.setProperty(arg, UPDATE_BY, userId);
                     }
                 } else {
                     userId = 1L;
-                    userName = "暂无";
-                    if (isProperty(arg, CREATE_BY) && BeanUtils.getProperty(arg, CREATE_BY) == null) {
+                    if (isProperty(arg, CREATE_BY) && Objects.isNull(BeanUtils.getProperty(arg, CREATE_BY))) {
                         BeanUtils.setProperty(arg, CREATE_BY, userId);
                     }
-                    if (isProperty(arg, UPDATE_BY) && BeanUtils.getProperty(arg, UPDATE_BY) == null) {
+                    if (isProperty(arg, UPDATE_BY) && Objects.isNull(BeanUtils.getProperty(arg, UPDATE_BY))) {
                         BeanUtils.setProperty(arg, UPDATE_BY, userId);
                     }
                 }
@@ -109,23 +105,23 @@ public class DaoAspect {
 //                    }
 //                }
 
-                if (isProperty(arg, CREATE_TIME) && StringUtils.isBlank(BeanUtils.getProperty(arg, CREATE_TIME))) {
+                if (isProperty(arg, CREATE_TIME) && Objects.isNull(BeanUtils.getProperty(arg, CREATE_TIME))) {
                     BeanUtils.setProperty(arg, CREATE_TIME, date);
                 }
 
-                if (isProperty(arg, UPDATE_TIME) && StringUtils.isBlank(BeanUtils.getProperty(arg, UPDATE_TIME))) {
+                if (isProperty(arg, UPDATE_TIME) && Objects.isNull(BeanUtils.getProperty(arg, UPDATE_TIME))) {
                     BeanUtils.setProperty(arg, UPDATE_TIME, date);
                 }
 
-                if (isProperty(arg, ID) && BeanUtils.getProperty(arg, ID) == null) {
+                if (isProperty(arg, ID) && Objects.isNull(BeanUtils.getProperty(arg, ID))) {
                     BeanUtils.setProperty(arg, ID, new IdWorker(1).nextId());
                 }
 
-                if (isProperty(arg, STATUS) && StringUtils.isBlank(BeanUtils.getProperty(arg, STATUS))) {
+                if (isProperty(arg, STATUS) && Objects.isNull(BeanUtils.getProperty(arg, STATUS))) {
                     BeanUtils.setProperty(arg, STATUS, Global.NO);
                 }
 
-                if (isProperty(arg, DEL_FLAG) && StringUtils.isBlank(BeanUtils.getProperty(arg, DEL_FLAG))) {
+                if (isProperty(arg, DEL_FLAG) && Objects.isNull((BeanUtils.getProperty(arg, DEL_FLAG)))) {
                     BeanUtils.setProperty(arg, DEL_FLAG, Global.NO);
                 }
             }

+ 3 - 6
sckw-common/sckw-common-core/src/main/java/com/sckw/core/filter/LoginFilter.java

@@ -41,9 +41,6 @@ public class LoginFilter implements Filter {
         EXCLUDEPATH.add("/kwsUser/forgetPassword");
     }
 
-    @Resource
-    private RedissonUtils redissonUtils;
-
     @Override
     public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws ServletException, IOException {
         HttpServletRequest request = (HttpServletRequest) servletRequest;
@@ -68,7 +65,7 @@ public class LoginFilter implements Filter {
         }
 
         //从redis获取用户信息
-        Object object = redissonUtils.get(CacheGroup.LOGININFO + key);
+        Object object = RedissonUtils.get(CacheGroup.LOGININFO + key);
         if (Objects.isNull(object)) {
             throw new SystemException(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.TOKEN_INVAILD);
         }
@@ -77,7 +74,7 @@ public class LoginFilter implements Filter {
         LoginUserInfo loginUserInfo = JSONObject.parseObject(object.toString(), LoginUserInfo.class);
         LoginUserHolder.set(loginUserInfo);
         //管理员不限制权限
-        if (loginUserInfo.getIsMain() == Global.NO){
+        if (loginUserInfo.getIsMain() == Global.YES){
             filterChain.doFilter(servletRequest, servletResponse);
             return;
         }
@@ -92,7 +89,7 @@ public class LoginFilter implements Filter {
 
     private List<String> getMenus(String key) {
         List<String> links = new ArrayList<>();
-        Object menuObject = redissonUtils.get(CacheGroup.ACCESSMENU + key);
+        Object menuObject = RedissonUtils.get(CacheGroup.ACCESSMENU + key);
         if (!Objects.isNull(menuObject)) {
             List<UserAccessMenuInfo> userAccessMenuInfos = JSONObject.parseArray(menuObject.toString(), UserAccessMenuInfo.class);
             if (!CollectionUtils.isEmpty(userAccessMenuInfos)) {

+ 1 - 1
sckw-common/sckw-common-core/src/main/java/com/sckw/core/global/GlobalExceptionHandler.java

@@ -30,7 +30,7 @@ public class GlobalExceptionHandler {
      * exception处理
      *
      * @param ex
-     * @return
+     * @returnh
      */
     @ResponseBody
     @ExceptionHandler(Exception.class)

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

@@ -31,7 +31,7 @@ public class IdWorker {
     private long workerId;
 
     /** 毫秒内序列(0~4095) */
-    private long sequence = 0L;
+    private static long sequence = 0L;
 
     /** 上次生成ID的时间截 */
     private static long lastTimestamp = -1L;
@@ -62,17 +62,13 @@ public class IdWorker {
         }
 
         //如果是同一时间生成的,则进行毫秒内序列
-        System.out.println("===============>   timestamp:" + timestamp);
-        System.out.println("===============>   lastTimestamp:" + lastTimestamp);
         if (lastTimestamp == timestamp) {
             //如果毫秒相同,则从0递增生成序列号
             sequence = (sequence + 1) & sequenceMask;
-            System.out.println("===============>   sequence:" + sequence);
             //毫秒内序列溢出
             if (sequence == 0) {
                 //阻塞到下一个毫秒,获得新的时间戳
                 timestamp = tilNextMillis(lastTimestamp);
-                System.out.println("===============>   new timestamp:" + timestamp);
             }
         }
         //时间戳改变,毫秒内序列重置
@@ -82,12 +78,10 @@ public class IdWorker {
 
         //上次生成ID的时间截
         lastTimestamp = timestamp;
-        System.out.println("===============>   new lastTimestamp:" + lastTimestamp);
         //移位并通过或运算拼到一起组成64位的ID
         long result = ((timestamp - twepoch) << timestampLeftShift)
                 | (workerId << workerIdShift)
                 | sequence;
-        System.out.println("===============>  result:" + result);
         return result;
     }
 

+ 3 - 5
sckw-common/sckw-common-redis/src/main/java/com/sckw/redis/configure/RedissonConfiguration.java

@@ -2,7 +2,6 @@ package com.sckw.redis.configure;
 
 import org.redisson.Redisson;
 import org.redisson.api.RedissonClient;
-import org.redisson.codec.JsonJacksonCodec;
 import org.redisson.config.Config;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
@@ -21,8 +20,8 @@ public class RedissonConfiguration {
     @Value("${spring.data.redis.port}")
     private String port;
 
-//    @Value("${spring.data.redis.password}")
-//    private String password;
+    @Value("${spring.data.redis.password}")
+    private String password;
 
     @Value("${spring.data.redis.database}")
     private String database;
@@ -33,10 +32,9 @@ public class RedissonConfiguration {
     @Bean
     public RedissonClient redisson() {
         Config config = new Config();
-        config.setCodec(new JsonJacksonCodec());
         config.useSingleServer()
                 .setAddress(address())
-//                .setPassword(password)
+                .setPassword(password)
                 .setDatabase(Integer.parseInt(database))
                 .setConnectTimeout(Integer.parseInt(timeout));
         return Redisson.create(config);

+ 1 - 1
sckw-modules/sckw-system/src/main/java/com/sckw/system/controller/KwsDeptController.java

@@ -40,7 +40,7 @@ public class KwsDeptController {
      * @date 2023/5/30
      **/
     @PostMapping("/findDeptTree")
-    public HttpResult findPage(@RequestBody HashMap params) throws Exception {
+    public HttpResult findPage(@RequestBody KwsDept params) throws Exception {
         return HttpResult.ok(kwsDeptService.findTree(params));
     }
 

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

@@ -6,6 +6,7 @@ import com.sckw.core.model.page.PageHelperUtil;
 import com.sckw.core.model.page.PageResult;
 import com.sckw.core.web.response.HttpResult;
 import com.sckw.system.model.KwsRole;
+import com.sckw.system.model.vo.req.AddRoleReqVo;
 import com.sckw.system.model.vo.req.UserBindRoleReqVo;
 import com.sckw.system.service.KwsRoleService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -62,8 +63,8 @@ public class KwsRoleController {
      * @date 2023/5/30
      **/
     @PostMapping("/add")
-    public HttpResult add(@RequestBody KwsRole params) throws Exception {
-        kwsRoleService.add(params);
+    public HttpResult add(@RequestBody AddRoleReqVo reqVo) throws Exception {
+        kwsRoleService.add(reqVo);
         return HttpResult.ok();
     }
 

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

@@ -116,7 +116,7 @@ public class KwsUserController {
     }
 
     /**
-     * @param  {account 账号、password 密码、captcha 验证码}
+     * @param  reqVo {account 账号、password 密码、captcha 验证码}
      * @description 忘记密码
      * @author zk
      * @date 2023/06/02

+ 47 - 0
sckw-modules/sckw-system/src/main/java/com/sckw/system/dao/KwsAuthorityDao.java

@@ -0,0 +1,47 @@
+package com.sckw.system.dao;
+
+import com.sckw.system.model.KwsAuthority;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * @author czh
+ * @desc 角色机构(数据权限)
+ * @date 2023/6/15
+ */
+@Mapper
+public interface KwsAuthorityDao {
+
+    /**
+     * 新增
+     * @param record
+     * @return
+     */
+    int insert(KwsAuthority record);
+
+    /**
+     * 更新
+     * @param record
+     * @return
+     */
+    int update(KwsAuthority record);
+
+    /**
+     * 详情查询
+     * @param id
+     * @return
+     */
+    List<KwsAuthority> selectByRoleId(Long id);
+
+    /**
+     * @param list KwsAuthority
+     * @return int
+     * @desc: 批量保存
+     * @author: czh
+     * @date: 2023/6/15
+     */
+    int saveBatch(@Param(value = "list") List<KwsAuthority> list);
+
+}

+ 1 - 3
sckw-modules/sckw-system/src/main/java/com/sckw/system/dao/KwsDeptDao.java

@@ -1,11 +1,9 @@
 package com.sckw.system.dao;
 
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.sckw.system.model.KwsDept;
 import com.sckw.system.model.vo.res.KwsDeptResVo;
 import org.apache.ibatis.annotations.Mapper;
 import java.util.List;
-import java.util.Map;
 
 /**
  * 组织机构
@@ -42,5 +40,5 @@ public interface KwsDeptDao {
      * @return
      * @throws Exception
      */
-    List<KwsDeptResVo> findList(Map<String, Object> params);
+    List<KwsDeptResVo> findList(KwsDept params);
 }

+ 35 - 0
sckw-modules/sckw-system/src/main/java/com/sckw/system/dao/KwsEntDeptDao.java

@@ -0,0 +1,35 @@
+package com.sckw.system.dao;
+
+import com.sckw.system.model.KwsEntDept;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * 组织机构
+ * @author zk
+ * @date 2023-05-31
+ */
+@Mapper
+public interface KwsEntDeptDao {
+
+    /**
+     * 新增
+     * @param record
+     * @return
+     */
+    int insert(KwsEntDept record);
+
+    /**
+     * 更新
+     * @param record
+     * @return
+     */
+    int update(KwsEntDept record);
+
+    /**
+     * 详情查询
+     * @param id
+     * @return
+     */
+    KwsEntDept selectByKey(Long id);
+
+}

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

@@ -56,4 +56,5 @@ public interface KwsEnterpriseDao {
      * @return
      */
     KwsEnterprise findByUserId(long id);
+
 }

+ 24 - 0
sckw-modules/sckw-system/src/main/java/com/sckw/system/model/KwsAuthority.java

@@ -0,0 +1,24 @@
+package com.sckw.system.model;
+
+import com.sckw.core.model.base.BaseModel;
+import lombok.Data;
+
+/**
+ * @author czh
+ * @desc 角色机构(数据权限)
+ * @date 2023/6/15
+ */
+@Data
+public class KwsAuthority extends BaseModel {
+
+    /**
+     * 角色ID
+     */
+    private long roleId;
+
+    /**
+     * 机构ID
+     */
+    private long deptId;
+
+}

+ 24 - 0
sckw-modules/sckw-system/src/main/java/com/sckw/system/model/KwsEntDept.java

@@ -0,0 +1,24 @@
+package com.sckw.system.model;
+
+import com.sckw.core.model.base.BaseModel;
+import lombok.Data;
+
+/**
+ * 企业部门机构
+ * @author zk
+ * @date 2023-05-31
+ */
+@Data
+public class KwsEntDept extends BaseModel {
+
+    /**
+     * 企业id
+     */
+    private Long entId;
+
+    /**
+     * 机构名称
+     */
+    private Long entPid;
+
+}

+ 48 - 0
sckw-modules/sckw-system/src/main/java/com/sckw/system/model/vo/req/AddRoleReqVo.java

@@ -0,0 +1,48 @@
+package com.sckw.system.model.vo.req;
+
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+
+/**
+ * @author czh
+ * @desc 新增角色入参
+ * @date 2023/6/15
+ */
+@Data
+public class AddRoleReqVo implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 1977281964220931297L;
+
+    /**
+     * 角色名称
+     */
+    private String name;
+
+    /**
+     * 当前机构id
+     */
+    private Long currentDeptId;
+
+    /**
+     * 功能权限配置 菜单ID,多个用","隔开
+     */
+    private String menuIds;
+
+    /**
+     * 是否只能看见自己的数据
+     */
+    private Boolean visiblePersonal;
+
+    /**
+     * 数据权限配置 机构id,多个用","隔开
+     */
+    private String deptIds;
+
+    /**
+     * 备注
+     */
+    private String remark;
+}

+ 10 - 0
sckw-modules/sckw-system/src/main/java/com/sckw/system/model/vo/req/EntRegisterReqVo.java

@@ -6,12 +6,22 @@ import java.io.Serial;
 import java.io.Serializable;
 import java.util.List;
 
+/**
+ * @desc: 企业注册入参
+ * @author: czh
+ * @date: 2023/6/15
+ */
 @Data
 public class EntRegisterReqVo implements Serializable {
 
     @Serial
     private static final long serialVersionUID = 2800416148876795046L;
 
+    /**
+     * 母公司id(当注册的公司是一家子公司时,entPid必传)
+     */
+    private Long entPid;
+
     /**
      * 企业名称
      */

+ 13 - 2
sckw-modules/sckw-system/src/main/java/com/sckw/system/service/KwsDeptService.java

@@ -107,9 +107,9 @@ public class KwsDeptService {
      * @return
      * @throws Exception
      */
-    public List<KwsDeptResVo> findTree(Map<String, Object> params) throws Exception{
+    public List<KwsDeptResVo> findTree(KwsDept params) throws Exception{
         //机构数据
-        List<KwsDeptResVo> deptList = kwsDeptDao.findList(params);
+        List<KwsDeptResVo> deptList = findList(params);
         //跟节点
         List<KwsDeptResVo> rootList = new ArrayList();
 
@@ -132,6 +132,17 @@ public class KwsDeptService {
         return rootList;
     }
 
+    /**
+     * @param kwsDept
+     * @return  List<KwsDeptResVo>
+     * @desc: 全量查机构
+     * @author: czh
+     * @date: 2023/6/15
+     */
+    public List<KwsDeptResVo> findList(KwsDept kwsDept){
+        return kwsDeptDao.findList(kwsDept);
+    }
+
     /**
      * 递归获取下级机构
      * @param parentId 父级机构id

+ 35 - 7
sckw-modules/sckw-system/src/main/java/com/sckw/system/service/KwsEnterpriseService.java

@@ -18,14 +18,13 @@ import com.sckw.core.utils.CollectionUtils;
 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.response.HttpResult;
-import com.sckw.system.dao.KwsEntCertificateDao;
-import com.sckw.system.dao.KwsEntCheckTrackDao;
-import com.sckw.system.dao.KwsEntTypeDao;
-import com.sckw.system.dao.KwsEnterpriseDao;
+import com.sckw.system.dao.*;
 import com.sckw.system.model.*;
 import com.sckw.system.model.vo.req.*;
 import com.sckw.system.model.vo.res.CertificateResVo;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -51,6 +50,9 @@ public class KwsEnterpriseService {
     @Autowired
     private KwsEntCheckTrackDao kwsEntCheckTrackDao;
 
+    @Autowired
+    private KwsEntDeptDao kwsEntDeptDao;
+
     @Autowired
     private KwsDeptService kwsDeptService;
 
@@ -91,7 +93,7 @@ public class KwsEnterpriseService {
     /**
      * 更新记录,有的是更新有的是新增,两种情况
      */
-    @Transactional(rollbackFor = {})
+    @Transactional(rollbackFor = Exception.class)
     public void update(KwsEnterpriseReqVo reqVo) throws Exception {
         /*1、更新企业信息表*/
         long entId = reqVo.getId();
@@ -234,13 +236,14 @@ public class KwsEnterpriseService {
     /**
      * 新增企业(注册)
      */
-    @Transactional(rollbackFor = {})
+    @Transactional(rollbackFor = Exception.class)
     public void register(EntRegisterReqVo reqVo) {
         /*1、存企业信息表*/
         KwsEnterprise kwsEnterprise = new KwsEnterprise();
         long entId = new IdWorker(1).nextId();
         kwsEnterprise.setId(entId);
         Date date = new Date();
+        Long userId = LoginUserHolder.getUserId();
         BeanUtils.copyProperties(reqVo, kwsEnterprise);
 
         //一些待确认的字段
@@ -261,6 +264,12 @@ public class KwsEnterpriseService {
             kwsEntType.setEntId(entId);
             kwsEntType.setType(Integer.parseInt(item));
             kwsEntType.setId(new IdWorker(1).nextId());
+            kwsEntType.setStatus(Global.NO);
+            kwsEntType.setCreateBy(userId);
+            kwsEntType.setCreateTime(date);
+            kwsEntType.setUpdateBy(userId);
+            kwsEntType.setUpdateTime(date);
+            kwsEntType.setDelFlag(Global.NO);
             kwsEntTypes.add(kwsEntType);
         });
         if (kwsEntTypeDao.saveBatch(kwsEntTypes) != kwsEntTypes.size()) {
@@ -274,6 +283,12 @@ public class KwsEnterpriseService {
             //todo 上传证书正反面,将url放到两个入参里
             kwsEntCertificate.setEntId(entId);
             kwsEntCertificate.setId(new IdWorker(1).nextId());
+            kwsEntCertificate.setStatus(Global.NO);
+            kwsEntCertificate.setCreateBy(userId);
+            kwsEntCertificate.setCreateTime(date);
+            kwsEntCertificate.setUpdateBy(userId);
+            kwsEntCertificate.setUpdateTime(date);
+            kwsEntCertificate.setDelFlag(Global.NO);
             BeanUtils.copyProperties(item, kwsEntCertificate);
             kwsEntCertificates.add(kwsEntCertificate);
         });
@@ -281,6 +296,19 @@ public class KwsEnterpriseService {
             throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
         }
 
+        //子公司不用新建机构、角色等,直接返回
+        if (!Objects.isNull(reqVo.getEntPid())) {
+            KwsEntDept kwsEntDept = new KwsEntDept();
+            kwsEntDept.setEntId(entId);
+            kwsEntDept.setEntPid(reqVo.getEntPid());
+            kwsEntDept.setId(new IdWorker(1L).nextId());
+            kwsEntDept.setRemark("");
+            if(kwsEntDeptDao.insert(kwsEntDept) <= 0){
+                throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
+            }
+            return;
+        }
+
         /*4、新增管理员机构*/
         KwsDept kwsDept = new KwsDept();
         long deptId = new IdWorker(1L).nextId();
@@ -322,7 +350,7 @@ public class KwsEnterpriseService {
     /**
      * 企业审批
      */
-    @Transactional(rollbackFor = {})
+    @Transactional(rollbackFor = Exception.class)
     public void approval(KwsEntCheckTrack kwsEntCheckTrack) {
         /*更新企业信息主表审批状态*/
         KwsEnterprise kwsEnterprise = checkKwsEnterpriseById(kwsEntCheckTrack.getEntId());

+ 88 - 31
sckw-modules/sckw-system/src/main/java/com/sckw/system/service/KwsRoleService.java

@@ -3,22 +3,20 @@ import java.util.Date;
 
 import com.sckw.core.exception.SystemException;
 import com.sckw.core.model.constant.Global;
+import com.sckw.core.utils.CollectionUtils;
 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.LoginUserInfo;
 import com.sckw.core.web.response.HttpResult;
-import com.sckw.system.api.model.dto.res.KwsRoleResDto;
-import com.sckw.system.dao.KwsMenuRightsDao;
+import com.sckw.system.dao.KwsAuthorityDao;
 import com.sckw.system.dao.KwsRoleDao;
 import com.sckw.system.dao.KwsUserRoleDao;
-import com.sckw.system.model.KwsMenuRights;
-import com.sckw.system.model.KwsRole;
-import com.sckw.system.model.KwsUserDept;
-import com.sckw.system.model.KwsUserRole;
+import com.sckw.system.model.*;
+import com.sckw.system.model.vo.req.AddRoleReqVo;
+import com.sckw.system.model.vo.req.RoleBindMeunReqVo;
 import com.sckw.system.model.vo.req.UserBindRoleReqVo;
-import org.jetbrains.annotations.Nullable;
+import com.sckw.system.model.vo.res.KwsDeptResVo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -40,15 +38,19 @@ public class KwsRoleService {
     KwsUserRoleDao kwsUserRoleDao;
 
     @Autowired
-    KwsMenuRightsDao kwsMenuRightsDao;
+    KwsAuthorityDao kwsAuthorityDao;
 
     @Autowired
     KwsDeptService kwsDeptService;
+
+    @Autowired
+    KwsMenuService kwsMenuServicel;
+
     /**
-     * 添加新纪录
-     * @param params
-     * @return
-     * @throws Exception
+     * @param  params KwsRole
+     * @desc: 单表插入
+     * @author: czh
+     * @date: 2023/6/15
      */
     public void add(KwsRole params) {
         if (kwsRoleDao.insert(params) <= 0) {
@@ -56,22 +58,80 @@ public class KwsRoleService {
         }
     }
 
+    /**
+     * @param reqVo 新增角色
+     * @desc: 新增角色
+     * @author: czh
+     * @date: 2023/6/15
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public void add(AddRoleReqVo reqVo) {
+        /*1、存角色信息*/
+        KwsRole kwsRole = new KwsRole();
+        long roleId = new IdWorker(1L).nextId();
+        kwsRole.setId(roleId);
+        kwsRole.setName(reqVo.getName());
+        kwsRole.setDeptId(reqVo.getCurrentDeptId());
+        kwsRole.setRemark(reqVo.getRemark());
+        if (kwsRoleDao.insert(kwsRole) <= 0) {
+            throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
+        }
+
+        /*2、绑定菜单功能*/
+        KwsDept kwsDept = new KwsDept();
+        kwsDept.setId(reqVo.getCurrentDeptId());
+        List<KwsDeptResVo> list = kwsDeptService.findList(kwsDept);
+        if (CollectionUtils.isEmpty(list)) {
+            throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
+        }
+        RoleBindMeunReqVo roleBindMeunReqVo = new RoleBindMeunReqVo();
+        roleBindMeunReqVo.setRoleId(roleId);
+        roleBindMeunReqVo.setEntId(list.get(0).getEntId());
+        roleBindMeunReqVo.setMenuIds(reqVo.getMenuIds());
+        kwsMenuServicel.roleBindMeun(roleBindMeunReqVo);
+
+        /*3、设置数据权限*/
+        if (reqVo.getVisiblePersonal()) {
+            //只能看见自己的数据则不管
+            return;
+        }
+        String[] deptIds = reqVo.getDeptIds().split(",");
+        List<KwsAuthority> kwsAuthorities = new ArrayList<>();
+        Long userId = LoginUserHolder.getUserId();
+        Date date = new Date();
+        for (String deptId : deptIds) {
+            KwsAuthority kwsAuthority = new KwsAuthority();
+            kwsAuthority.setRoleId(roleId);
+            kwsAuthority.setDeptId(Long.parseLong(deptId));
+            kwsAuthority.setId(new IdWorker(1L).nextId());
+            kwsAuthority.setStatus(Global.NO);
+            kwsAuthority.setCreateBy(userId);
+            kwsAuthority.setCreateTime(date);
+            kwsAuthority.setUpdateBy(userId);
+            kwsAuthority.setUpdateTime(date);
+            kwsAuthority.setDelFlag(Global.NO);
+            kwsAuthorities.add(kwsAuthority);
+        }
+        if(kwsAuthorityDao.saveBatch(kwsAuthorities) != kwsAuthorities.size() ) {
+            throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
+        }
+
+    }
+
     /**
      * 删除记录-根据主键
-     * @param ids
-     * @return
-     * @throws Exception
+     * @param ids 主键
+     * @return HttpResult
      */
     public HttpResult deleteByKey(String ids) throws Exception {
-        /**1.数据校验**/
+        /*1.数据校验*/
         if (StringUtils.isBlank(ids)) {
             return HttpResult.error("请选择您要删除的角色信息!");
         }
 
         int resultCode = 0;
         String[] idArray = ids.split(",");
-        for (int i = 0; i < idArray.length; i++) {
-            String id = idArray[i];
+        for (String id : idArray) {
             KwsRole kwsRole = kwsRoleDao.selectByKey(Long.parseLong(id));
             if (null != kwsRole) {
                 kwsRole.setDelFlag(Global.YES);
@@ -83,9 +143,8 @@ public class KwsRoleService {
 
     /**
      * 更新记录
-     * @param params
-     * @return
-     * @throws Exception
+     * @param params KwsRole
+     * @return HttpResult
      */
     public HttpResult update(KwsRole params) throws Exception {
         int count = kwsRoleDao.update(params);
@@ -94,9 +153,8 @@ public class KwsRoleService {
 
     /**
      * 根据主键查询
-     * @param key
-     * @return
-     * @throws Exception
+     * @param key 主键
+     * @return KwsRole
      */
     public KwsRole selectByKey(Long key) {
         return kwsRoleDao.selectByKey(key);
@@ -104,17 +162,16 @@ public class KwsRoleService {
 
     /**
      * 分页查询
-     * @param params
-     * @return
-     * @throws Exception
+     * @param params 分页入参
+     * @return List
      */
     public List<KwsRole> findPage(Map<String, Object> params) throws Exception{
         return kwsRoleDao.findPage(params);
     }
 
     /**
-     * @param * @param 用户id
-     * @return
+     * @param userId 用户id
+     * @return List
      * @desc: 根据用户id查角色
      * @author: czh
      * @date: 2023/6/12
@@ -129,7 +186,7 @@ public class KwsRoleService {
      * @author: czh
      * @date: 2023/6/13
      */
-    @Transactional(rollbackFor = {})
+    @Transactional(rollbackFor = Exception.class)
     public void userBindRole(UserBindRoleReqVo reqVo) {
         /*1、存用户角色信息*/
         String[] roleIdArr = reqVo.getRoleIds().split(",");

+ 5 - 22
sckw-modules/sckw-system/src/main/java/com/sckw/system/service/KwsUserService.java

@@ -1,21 +1,13 @@
 package com.sckw.system.service;
-import java.util.Date;
-
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.sckw.core.exception.SystemException;
 import com.sckw.core.model.constant.Global;
 import com.sckw.core.utils.*;
 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.api.model.dto.res.KwsUserDeptResDto;
 import com.sckw.system.dao.KwsEntCheckTrackDao;
 import com.sckw.system.dao.KwsUserDao;
 import com.sckw.system.dao.KwsUserDeptDao;
 import com.sckw.system.model.KwsDept;
-import com.sckw.system.model.KwsRole;
 import com.sckw.system.model.KwsUser;
 import com.sckw.system.model.KwsUserDept;
 import com.sckw.system.model.vo.req.ForgetPasswordReqVo;
@@ -53,13 +45,7 @@ public class KwsUserService {
     @Autowired
     KwsDeptService kwsDeptService;
 
-    @Autowired
-    KwsEnterpriseService kwsEnterpriseService;
-
-    @Autowired
-    RedissonUtils redissonUtils;
-
-    @Transactional(rollbackFor = {})
+    @Transactional(rollbackFor = Exception.class)
     public void add(UserAddReqVo reqVo) {
         KwsUser kwsUser = new KwsUser();
         BeanUtils.copyProperties(reqVo, kwsUser);
@@ -106,15 +92,14 @@ public class KwsUserService {
      * 删除记录-根据主键
      */
     public void deleteByKey(String ids) throws Exception {
-        /**1.数据校验**/
+        /*1.数据校验*/
         if (StringUtils.isBlank(ids)) {
             throw new SystemException(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.ACCOUNT_MISSING);
         }
 
         int resultCode = 0;
         String[] idArray = ids.split(",");
-        for (int i = 0; i < idArray.length; i++) {
-            String id = idArray[i];
+        for (String id : idArray) {
             KwsUser kwsUser = kwsUserDao.selectByKey(Long.parseLong(id));
             if (null != kwsUser) {
                 kwsUser.setDelFlag(Global.YES);
@@ -129,9 +114,7 @@ public class KwsUserService {
 
     /**
      * 更新记录
-     * @param params
-     * @return
-     * @throws Exception
+     * @param params KwsUser
      */
     public void update(KwsUser params) throws Exception {
         //更换账号后账号唯一性校验
@@ -247,7 +230,7 @@ public class KwsUserService {
 
         //从缓存中取出验证码,校验
         //todo
-        String sms = redissonUtils.get("captcha:czh").toString();
+        String sms = RedissonUtils.get("captcha:czh").toString();
         if (!reqVo.getCaptcha().equals(sms)) {
             throw new SystemException(HttpStatus.CODE_10301, HttpStatus.CAPTCHA_ERROR);
         }

+ 168 - 0
sckw-modules/sckw-system/src/main/resources/mapper/KwsAuthorityDao.xml

@@ -0,0 +1,168 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.sckw.system.dao.KwsAuthorityDao">
+  <resultMap id="BaseResultMap" type="com.sckw.system.model.KwsAuthority">
+    <id column="id" jdbcType="BIGINT" property="id" />
+    <result column="role_id" jdbcType="BIGINT" property="roleId" />
+    <result column="dept_id" jdbcType="VARCHAR" property="deptId" />
+    <result column="remark" jdbcType="VARCHAR" property="remark" />
+    <result column="status" jdbcType="INTEGER" property="status" />
+    <result column="create_by" jdbcType="BIGINT" property="createBy" />
+    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
+    <result column="update_by" jdbcType="BIGINT" property="updateBy" />
+    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
+    <result column="del_flag" jdbcType="INTEGER" property="delFlag" />
+  </resultMap>
+
+  <sql id="Base_Column_List">
+    id, role_id, dept_id, remark, status, create_by, create_time, update_by, update_time, del_flag
+  </sql>
+
+  <select id="selectByKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
+    select 
+    <include refid="Base_Column_List" />
+    from kws_authority
+    where id = #{id,jdbcType=BIGINT}
+  </select>
+  <select id="selectByRoleId" resultType="com.sckw.system.model.KwsAuthority">
+    select a.*
+      from kws_authority a
+     where a.del_flag = 0
+       and a.status = 0
+       and a.role_id = #{id}
+  </select>
+
+  <insert id="insert" parameterType="com.sckw.system.model.KwsDept">
+    insert into kws_authority
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+      <if test="id != null">
+        id,
+      </if>
+      <if test="roleId != null">
+        role_id,
+      </if>
+      <if test="deptId != null">
+        dept_id,
+      </if>
+      <if test="remark != null">
+        remark,
+      </if>
+      <if test="status != null">
+        status,
+      </if>
+      <if test="createBy != null">
+        create_by,
+      </if>
+      <if test="createTime != null">
+        create_time,
+      </if>
+      <if test="updateBy != null">
+        update_by,
+      </if>
+      <if test="updateTime != null">
+        update_time,
+      </if>
+      <if test="delFlag != null">
+        del_flag,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides=",">
+      <if test="id != null">
+        #{id,jdbcType=BIGINT},
+      </if>
+      <if test="roleId != null">
+        #{roleId,jdbcType=BIGINT},
+      </if>
+      <if test="deptId != null">
+        #{deptId,jdbcType=VARCHAR},
+      </if>
+      <if test="remark != null">
+        #{remark,jdbcType=VARCHAR},
+      </if>
+      <if test="status != null">
+        #{status,jdbcType=INTEGER},
+      </if>
+      <if test="createBy != null">
+        #{createBy,jdbcType=BIGINT},
+      </if>
+      <if test="createTime != null">
+        #{createTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="updateBy != null">
+        #{updateBy,jdbcType=BIGINT},
+      </if>
+      <if test="updateTime != null">
+        #{updateTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="delFlag != null">
+        #{delFlag,jdbcType=INTEGER},
+      </if>
+    </trim>
+  </insert>
+
+  <insert id="saveBatch">
+    insert into kws_authority
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+        id,
+        role_id,
+        dept_id,
+        remark,
+        status,
+        create_by,
+        create_time,
+        update_by,
+        update_time,
+        del_flag
+    </trim>
+        values
+    <foreach collection="list" item="item" separator=",">
+      <trim prefix="(" suffix=")" suffixOverrides=",">
+        #{item.id,jdbcType=BIGINT},
+        #{item.roleId,jdbcType=BIGINT},
+        #{item.deptId,jdbcType=VARCHAR},
+        #{item.remark,jdbcType=VARCHAR},
+        #{item.status,jdbcType=INTEGER},
+        #{item.createBy,jdbcType=BIGINT},
+        #{item.createTime,jdbcType=TIMESTAMP},
+        #{item.updateBy,jdbcType=BIGINT},
+        #{item.updateTime,jdbcType=TIMESTAMP},
+        #{item.delFlag,jdbcType=INTEGER}
+      </trim>
+    </foreach>
+  </insert>
+
+  <update id="update" parameterType="com.sckw.system.model.KwsDept">
+    update kws_authority
+    <set>
+      <if test="roleId != null">
+        role_id = #{roleId,jdbcType=BIGINT},
+      </if>
+      <if test="deptId != null">
+        dept_id = #{deptId,jdbcType=VARCHAR},
+      </if>
+      <if test="remark != null">
+        remark = #{remark,jdbcType=VARCHAR},
+      </if>
+      <if test="status != null">
+        status = #{status,jdbcType=INTEGER},
+      </if>
+      <if test="createBy != null">
+        create_by = #{createBy,jdbcType=BIGINT},
+      </if>
+      <if test="createTime != null">
+        create_time = #{createTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="updateBy != null">
+        update_by = #{updateBy,jdbcType=BIGINT},
+      </if>
+      <if test="updateTime != null">
+        update_time = #{updateTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="delFlag != null">
+        del_flag = #{delFlag,jdbcType=INTEGER},
+      </if>
+    </set>
+    where id = #{id,jdbcType=BIGINT}
+  </update>
+
+</mapper>

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

@@ -188,7 +188,7 @@
     where id = #{id,jdbcType=BIGINT}
   </update>
 
-  <select id="findList" resultType="com.sckw.system.model.vo.res.KwsDeptResVo" parameterType="java.util.Map" >
+  <select id="findList" resultType="com.sckw.system.model.vo.res.KwsDeptResVo" parameterType="com.sckw.system.model.KwsDept" >
     select
       id, system_type systemType, ent_id entId, name, company, parent_id parentId, level, sort, remark,
       status, create_by createBy, create_time createTime, update_by updateBy, update_time updateTime

+ 131 - 0
sckw-modules/sckw-system/src/main/resources/mapper/KwsEntDeptDao.xml

@@ -0,0 +1,131 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.sckw.system.dao.KwsEntDeptDao">
+  <resultMap id="BaseResultMap" type="com.sckw.system.model.KwsEntDept">
+    <id column="id" jdbcType="BIGINT" property="id" />
+    <result column="ent_id" jdbcType="BIGINT" property="entId" />
+    <result column="ent_pid" jdbcType="BIGINT" property="entPid" />
+    <result column="remark" jdbcType="VARCHAR" property="remark" />
+    <result column="status" jdbcType="INTEGER" property="status" />
+    <result column="create_by" jdbcType="BIGINT" property="createBy" />
+    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
+    <result column="update_by" jdbcType="BIGINT" property="updateBy" />
+    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
+    <result column="del_flag" jdbcType="INTEGER" property="delFlag" />
+  </resultMap>
+
+  <sql id="Base_Column_List">
+    id, ent_id, ent_pid, remark,
+    status, create_by, create_time, update_by, update_time, del_flag
+  </sql>
+
+  <select id="selectByKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
+    select 
+    <include refid="Base_Column_List" />
+    from kws_ent_dept
+    where id = #{id,jdbcType=BIGINT}
+  </select>
+
+  <insert id="insert" parameterType="com.sckw.system.model.KwsEntDept">
+    insert into kws_ent_dept
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+      <if test="id != null">
+        id,
+      </if>
+      <if test="entId != null">
+        ent_id,
+      </if>
+      <if test="entPid != null">
+        ent_pid,
+      </if>
+      <if test="remark != null">
+        remark,
+      </if>
+      <if test="status != null">
+        status,
+      </if>
+      <if test="createBy != null">
+        create_by,
+      </if>
+      <if test="createTime != null">
+        create_time,
+      </if>
+      <if test="updateBy != null">
+        update_by,
+      </if>
+      <if test="updateTime != null">
+        update_time,
+      </if>
+      <if test="delFlag != null">
+        del_flag,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides=",">
+      <if test="id != null">
+        #{id,jdbcType=BIGINT},
+      </if>
+      <if test="entId != null">
+        #{entId,jdbcType=BIGINT},
+      </if>
+      <if test="entPid != null">
+        #{entPid,jdbcType=BIGINT},
+      </if>
+      <if test="remark != null">
+        #{remark,jdbcType=VARCHAR},
+      </if>
+      <if test="status != null">
+        #{status,jdbcType=INTEGER},
+      </if>
+      <if test="createBy != null">
+        #{createBy,jdbcType=BIGINT},
+      </if>
+      <if test="createTime != null">
+        #{createTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="updateBy != null">
+        #{updateBy,jdbcType=BIGINT},
+      </if>
+      <if test="updateTime != null">
+        #{updateTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="delFlag != null">
+        #{delFlag,jdbcType=INTEGER},
+      </if>
+    </trim>
+  </insert>
+
+  <update id="update" parameterType="com.sckw.system.model.KwsEntDept">
+    update kws_ent_dept
+    <set>
+      <if test="entId != null">
+        ent_id = #{entId,jdbcType=BIGINT},
+      </if>
+      <if test="entPid != null">
+        ent_pid = #{entPid,jdbcType=BIGINT},
+      </if>
+      <if test="remark != null">
+        remark = #{remark,jdbcType=VARCHAR},
+      </if>
+      <if test="status != null">
+        status = #{status,jdbcType=INTEGER},
+      </if>
+      <if test="createBy != null">
+        create_by = #{createBy,jdbcType=BIGINT},
+      </if>
+      <if test="createTime != null">
+        create_time = #{createTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="updateBy != null">
+        update_by = #{updateBy,jdbcType=BIGINT},
+      </if>
+      <if test="updateTime != null">
+        update_time = #{updateTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="delFlag != null">
+        del_flag = #{delFlag,jdbcType=INTEGER},
+      </if>
+    </set>
+    where id = #{id,jdbcType=BIGINT}
+  </update>
+
+</mapper>