Просмотр исходного кода

字典、用户、企业dubbo相关接口

small 2 лет назад
Родитель
Сommit
4f34eafb6f
18 измененных файлов с 701 добавлено и 151 удалено
  1. 0 1
      sckw-auth/src/main/java/com/sckw/auth/model/vo/res/LoginResVo.java
  2. 0 3
      sckw-common/sckw-common-core/src/main/java/com/sckw/core/filter/LoginFilterConfig.java
  3. 5 2
      sckw-common/sckw-common-core/src/main/java/com/sckw/core/model/constant/Global.java
  4. 2 0
      sckw-common/sckw-common-core/src/main/java/com/sckw/core/web/constant/HttpStatus.java
  5. 40 3
      sckw-modules-api/sckw-system-api/src/main/java/com/sckw/system/api/RemoteSystemService.java
  6. 57 0
      sckw-modules-api/sckw-system-api/src/main/java/com/sckw/system/api/model/dto/res/EntCacheResDto.java
  7. 44 0
      sckw-modules-api/sckw-system-api/src/main/java/com/sckw/system/api/model/dto/res/SysDictGroupResDto.java
  8. 85 0
      sckw-modules-api/sckw-system-api/src/main/java/com/sckw/system/api/model/dto/res/UserCacheResDto.java
  9. 33 0
      sckw-modules-api/sckw-system-api/src/main/java/com/sckw/system/api/model/pojo/DeptInfoPojo.java
  10. 22 16
      sckw-modules/sckw-system/src/main/java/com/sckw/system/controller/SysDictController.java
  11. 30 2
      sckw-modules/sckw-system/src/main/java/com/sckw/system/dao/SysDictDao.java
  12. 1 0
      sckw-modules/sckw-system/src/main/java/com/sckw/system/dao/SysDictTypeDao.java
  13. 109 0
      sckw-modules/sckw-system/src/main/java/com/sckw/system/dubbo/RemoteBaseService.java
  14. 155 6
      sckw-modules/sckw-system/src/main/java/com/sckw/system/dubbo/RemoteSystemServiceImpl.java
  15. 22 50
      sckw-modules/sckw-system/src/main/java/com/sckw/system/dubbo/RemoteUserServiceImpl.java
  16. 2 2
      sckw-modules/sckw-system/src/main/java/com/sckw/system/service/KwsRoleService.java
  17. 71 65
      sckw-modules/sckw-system/src/main/java/com/sckw/system/service/SysDictService.java
  18. 23 1
      sckw-modules/sckw-system/src/main/resources/mapper/SysDictDao.xml

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

@@ -1,7 +1,6 @@
 package com.sckw.auth.model.vo.res;
 package com.sckw.auth.model.vo.res;
 
 
 import com.sckw.system.api.model.dto.res.KwsRoleResDto;
 import com.sckw.system.api.model.dto.res.KwsRoleResDto;
-import jakarta.validation.constraints.NotBlank;
 import lombok.Data;
 import lombok.Data;
 
 
 import java.io.Serial;
 import java.io.Serial;

+ 0 - 3
sckw-common/sckw-common-core/src/main/java/com/sckw/core/filter/LoginFilterConfig.java

@@ -1,10 +1,7 @@
 package com.sckw.core.filter;
 package com.sckw.core.filter;
 
 
-import jakarta.annotation.Resource;
 import org.springframework.boot.web.servlet.FilterRegistrationBean;
 import org.springframework.boot.web.servlet.FilterRegistrationBean;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.core.annotation.Order;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Component;
 
 
 /**
 /**

+ 5 - 2
sckw-common/sckw-common-core/src/main/java/com/sckw/core/model/constant/Global.java

@@ -83,6 +83,7 @@ public class Global {
     public static final String USER_LOGIN_CAPTCHA = "userLoginCaptcha:";
     public static final String USER_LOGIN_CAPTCHA = "userLoginCaptcha:";
 
 
     /**redis用户信息前缀*/
     /**redis用户信息前缀*/
+    public static final String REDIS_USER_LOGIN_PREFIX = "userLoginInfo:";
     public static final String REDIS_USER_PREFIX = "userInfo:";
     public static final String REDIS_USER_PREFIX = "userInfo:";
 
 
     /**redis企业信息前缀*/
     /**redis企业信息前缀*/
@@ -92,7 +93,9 @@ public class Global {
     public static final String REDIS_SYS_MENU_PREFIX = "sysMenu:";
     public static final String REDIS_SYS_MENU_PREFIX = "sysMenu:";
 
 
     /**redis字典信息前缀*/
     /**redis字典信息前缀*/
-    public static final String REDIS_SYS_DICT_PREFIX = "dictInfo:";
+    public static final String REDIS_SYS_DICT_TYPE_PREFIX = "dictInfo:type:";
+    public static final String REDIS_SYS_DICT_PREFIX = "dictInfo:dict:";
+    public static final String REDIS_SYS_DICT_GROUP_PREFIX = "dictInfo:group:";
 
 
     /**redis用户车辆gps信息*/
     /**redis用户车辆gps信息*/
     public static final String REDIS_CACHE_GPS_CAR_PREFIX = "cacheGpsCar:";
     public static final String REDIS_CACHE_GPS_CAR_PREFIX = "cacheGpsCar:";
@@ -238,7 +241,7 @@ public class Global {
 
 
     /**完整的用户登录信息key*/
     /**完整的用户登录信息key*/
     public static String getFullUserLoginKey(Integer systemType, Long userId, String clientType) {
     public static String getFullUserLoginKey(Integer systemType, Long userId, String clientType) {
-        return REDIS_USER_PREFIX + systemType + COLON + userId + COLON + clientType;
+        return REDIS_USER_LOGIN_PREFIX + systemType + COLON + userId + COLON + clientType;
     }
     }
 
 
     /**完整的用户企业信息key*/
     /**完整的用户企业信息key*/

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

@@ -28,6 +28,7 @@ public class HttpStatus {
 
 
     /**参数缺失状态码*/
     /**参数缺失状态码*/
     public static final int PARAMETERS_MISSING_CODE = 60600;
     public static final int PARAMETERS_MISSING_CODE = 60600;
+    public static final String ID_MISSING = "id不能为空!";
     public static final String ACCOUNT_MISSING = "用户账号必填!";
     public static final String ACCOUNT_MISSING = "用户账号必填!";
     public static final String ACCOUNT_EXISTS = "用户账号已存在!";
     public static final String ACCOUNT_EXISTS = "用户账号已存在!";
     public static final String PWD_MISSING = "密码不能为空!";
     public static final String PWD_MISSING = "密码不能为空!";
@@ -37,6 +38,7 @@ public class HttpStatus {
     public static final String CAPCHA_ERROR = "验证码无效!";
     public static final String CAPCHA_ERROR = "验证码无效!";
     public static final String ENT_EXISTS = "企业已存在,不可重复!";
     public static final String ENT_EXISTS = "企业已存在,不可重复!";
     public static final String DICTTYPE_EXISTS = "字典类型已存在,不可重复!";
     public static final String DICTTYPE_EXISTS = "字典类型已存在,不可重复!";
+    public static final String DICT_EXISTS = "字典键值已存在,不可重复!";
 
 
 
 
 
 

+ 40 - 3
sckw-modules-api/sckw-system-api/src/main/java/com/sckw/system/api/RemoteSystemService.java

@@ -1,7 +1,9 @@
 package com.sckw.system.api;
 package com.sckw.system.api;
 
 
-
+import com.sckw.system.api.model.dto.res.EntCacheResDto;
+import com.sckw.system.api.model.dto.res.SysDictGroupResDto;
 import com.sckw.system.api.model.dto.res.SysDictResDto;
 import com.sckw.system.api.model.dto.res.SysDictResDto;
+import com.sckw.system.api.model.dto.res.UserCacheResDto;
 
 
 import java.util.List;
 import java.util.List;
 
 
@@ -13,12 +15,47 @@ import java.util.List;
 public interface RemoteSystemService {
 public interface RemoteSystemService {
 
 
     /**
     /**
-     * @param typeId 类型id
+     * @param type 类型
      * @return SysDictResDto
      * @return SysDictResDto
      * @desc: 根据类型id查字典,先查redis,没查到查数据库,查出来了存redis
      * @desc: 根据类型id查字典,先查redis,没查到查数据库,查出来了存redis
      * @author: czh
      * @author: czh
      * @date: 2023/7/5
      * @date: 2023/7/5
      */
      */
-    List<SysDictResDto> queryDictByTypeId(Long typeId);
+    List<SysDictResDto> queryDictByType(String type);
 
 
+    /**
+     * @param type 字典类型,value key
+     * @return SysDictResDto
+     * @desc: 根据字典类型和key查
+     * @author: czh
+     * @date: 2023/7/7
+     */
+    SysDictResDto queryDictByTypeAndValue(String type, String value);
+
+    /**
+     * @param  type 字典类型,value key
+     * @return SysDictGroupResDto
+     * @desc: 根据字典类型和key查字典组
+     * @author: czh
+     * @date: 2023/7/7
+     */
+    SysDictGroupResDto queryDictGroupByTypeAndValue(String type, String value);
+
+    /**
+     * @param entId 企业id
+     * @return EntCacheResDto
+     * @desc: 从缓存查企业信息
+     * @author: czh
+     * @date: 2023/7/7
+     */
+    EntCacheResDto queryEntCacheById(Long entId);
+
+    /**
+     * @param userId 用户id
+     * @return UserCacheResDto
+     * @desc: 从缓存查用户信息
+     * @author: czh
+     * @date: 2023/7/7
+     */
+    UserCacheResDto queryUserCacheById(Long userId);
 }
 }

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

@@ -0,0 +1,57 @@
+package com.sckw.system.api.model.dto.res;
+
+import com.sckw.system.api.model.pojo.DeptInfoPojo;
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author czh
+ * @desc 企业信息
+ * @date 2023/7/7
+ */
+
+@Data
+public class EntCacheResDto implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 964361929254956540L;
+
+    /**
+     * 企业id
+     */
+    private Long id;
+
+    /**
+     * 企业名称
+     */
+    private String firmName;
+
+    /**
+     * 资料审批状态(0未审批、1通过、2未通过、3审批中)
+     */
+    private int approval;
+
+    /**
+     * 注册时间
+     */
+    private Date regTime;
+
+    /**
+     * 是否有效
+     */
+    private Boolean valid;
+
+    /**
+     * 机构信息
+     */
+    private List<DeptInfoPojo> deptInfo;
+
+    /**
+     * 资质信息
+     */
+    private List<EntCertificateResDto> certificateInfo;
+}

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

@@ -0,0 +1,44 @@
+package com.sckw.system.api.model.dto.res;
+
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @author czh
+ * @desc 字典组
+ * @date 2023/7/7
+ */
+@Data
+public class SysDictGroupResDto implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 3830161200942542127L;
+
+    /**
+     * id
+     */
+    private Long id;
+
+    /**
+     * 类型
+     */
+    private String type;
+    /**
+     * 选项值
+     */
+    private String value;
+
+    /**
+     * 选项
+     */
+    private String label;
+
+    /**
+     * 下级
+     */
+    private List<SysDictGroupResDto> child;
+
+}

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

@@ -0,0 +1,85 @@
+package com.sckw.system.api.model.dto.res;
+
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @author czh
+ * @desc 用户信息
+ * @date 2023/7/7
+ */
+@Data
+public class UserCacheResDto implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 5711974940665217921L;
+
+    /**
+     * 用户id
+     */
+    private long id;
+
+    /**
+     * 系统类型(1运营端、2企业开户)
+     */
+    private Integer systemType;
+
+    /**
+     * 账号
+     */
+    private String account;
+
+    /**
+     * 姓名
+     */
+    private String name;
+
+    /**
+     * 电话
+     */
+    private String phone;
+
+    /**
+     * 头像
+     */
+    private String photo;
+
+    /**
+     * 邮箱
+     */
+    private String email;
+
+    /**
+     * 推送设备id
+     */
+    private String clientId;
+
+    /**
+     * 是否是企业管理(0是 1否)
+     */
+    private Integer isMain;
+
+    /**
+     * 设备类型
+     */
+    private String clientType;
+
+    /**
+     * 状态
+     */
+    private Integer status;
+
+    /**
+     * 企业信息
+     */
+    private EntCacheResDto entInfo;
+
+    /**
+     * 角色信息
+     */
+    private List<KwsRoleResDto> roleInfo;
+
+}

+ 33 - 0
sckw-modules-api/sckw-system-api/src/main/java/com/sckw/system/api/model/pojo/DeptInfoPojo.java

@@ -0,0 +1,33 @@
+package com.sckw.system.api.model.pojo;
+
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+
+/**
+ * @author czh
+ * @desc 机构信息
+ * @date 2023/7/7
+ */
+@Data
+public class DeptInfoPojo implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = -2727085431616491555L;
+
+    /**
+     * 机构ID
+     */
+    private long id;
+
+    /**
+     * 机构名称
+     */
+    private String name;
+
+    /**
+     * 是否是公司(0 机构部门/1 公司)
+     */
+    private Integer company;
+}

+ 22 - 16
sckw-modules/sckw-system/src/main/java/com/sckw/system/controller/SysDictController.java

@@ -2,6 +2,7 @@ package com.sckw.system.controller;
 
 
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.github.pagehelper.PageInfo;
+import com.sckw.core.exception.SystemException;
 import com.sckw.core.model.page.PageHelperUtil;
 import com.sckw.core.model.page.PageHelperUtil;
 import com.sckw.core.model.page.PageResult;
 import com.sckw.core.model.page.PageResult;
 import com.sckw.core.web.response.HttpResult;
 import com.sckw.core.web.response.HttpResult;
@@ -11,12 +12,14 @@ import com.sckw.system.model.vo.req.QueryDictTypePageReqVo;
 import com.sckw.system.service.SysDictService;
 import com.sckw.system.service.SysDictService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
+
 import java.util.HashMap;
 import java.util.HashMap;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
 
 
 /**
 /**
  * 字典
  * 字典
+ *
  * @author zk
  * @author zk
  * @date 2023-05-30
  * @date 2023-05-30
  */
  */
@@ -36,7 +39,7 @@ public class SysDictController {
      * @date 2023/5/30
      * @date 2023/5/30
      **/
      **/
     @PostMapping("/addType")
     @PostMapping("/addType")
-    public HttpResult addType(@RequestBody SysDictType params) throws Exception {
+    public HttpResult addType(@RequestBody SysDictType params) throws SystemException {
         sysDictService.addType(params);
         sysDictService.addType(params);
         return HttpResult.ok();
         return HttpResult.ok();
     }
     }
@@ -49,8 +52,9 @@ public class SysDictController {
      * @date 2023/5/30
      * @date 2023/5/30
      **/
      **/
     @PostMapping("/updateType")
     @PostMapping("/updateType")
-    public HttpResult updateType(@RequestBody SysDictType params) throws Exception {
-        return sysDictService.updateType(params);
+    public HttpResult updateType(@RequestBody SysDictType params) throws SystemException {
+        sysDictService.updateType(params);
+        return HttpResult.ok();
     }
     }
 
 
     /**
     /**
@@ -61,7 +65,7 @@ public class SysDictController {
      * @date 2023/5/30
      * @date 2023/5/30
      **/
      **/
     @PostMapping("/select")
     @PostMapping("/select")
-    public HttpResult findPage(@RequestBody HashMap params) throws Exception {
+    public HttpResult findPage(@RequestBody HashMap params) throws SystemException {
         // 设置分页参数
         // 设置分页参数
         PageHelper.startPage(PageResult.getPage(params), PageResult.getPageSize(params));
         PageHelper.startPage(PageResult.getPage(params), PageResult.getPageSize(params));
         List<SysDict> list = sysDictService.findPage(params);
         List<SysDict> list = sysDictService.findPage(params);
@@ -77,7 +81,7 @@ public class SysDictController {
      * @date 2023/5/30
      * @date 2023/5/30
      **/
      **/
     @GetMapping("/detail")
     @GetMapping("/detail")
-    public HttpResult selectByKey(Long id) throws Exception {
+    public HttpResult selectByKey(Long id) throws SystemException {
         SysDict sysDict = sysDictService.selectByKey(id);
         SysDict sysDict = sysDictService.selectByKey(id);
         return HttpResult.ok(sysDict);
         return HttpResult.ok(sysDict);
     }
     }
@@ -90,9 +94,8 @@ public class SysDictController {
      * @date 2023/5/30
      * @date 2023/5/30
      **/
      **/
     @PostMapping("/findList")
     @PostMapping("/findList")
-    public HttpResult findList(@RequestBody HashMap params) throws Exception {
-        List<Map<String, Object>> list = sysDictService.findList(params);
-        return HttpResult.ok(list);
+    public HttpResult findList(@RequestBody HashMap params) throws SystemException {
+        return HttpResult.ok(sysDictService.findList(params));
     }
     }
 
 
     /**
     /**
@@ -103,8 +106,9 @@ public class SysDictController {
      * @date 2023/5/30
      * @date 2023/5/30
      **/
      **/
     @PostMapping("/add")
     @PostMapping("/add")
-    public HttpResult add(@RequestBody SysDict params) throws Exception {
-        return sysDictService.add(params);
+    public HttpResult add(@RequestBody SysDict params) throws SystemException {
+        sysDictService.add(params);
+        return HttpResult.ok();
     }
     }
 
 
     /**
     /**
@@ -115,8 +119,9 @@ public class SysDictController {
      * @date 2023/5/30
      * @date 2023/5/30
      **/
      **/
     @PostMapping("/update")
     @PostMapping("/update")
-    public HttpResult update(@RequestBody SysDict params) throws Exception {
-        return sysDictService.update(params);
+    public HttpResult update(@RequestBody SysDict params) throws SystemException {
+        sysDictService.update(params);
+        return HttpResult.ok();
     }
     }
 
 
     /**
     /**
@@ -127,8 +132,9 @@ public class SysDictController {
      * @date 2023/5/30
      * @date 2023/5/30
      **/
      **/
     @DeleteMapping("/dels")
     @DeleteMapping("/dels")
-    public HttpResult del(@RequestParam String ids) throws Exception {
-        return sysDictService.deleteByKey(ids);
+    public HttpResult del(@RequestParam String ids) throws SystemException {
+        sysDictService.deleteByKey(ids);
+        return HttpResult.ok();
     }
     }
 
 
     /**
     /**
@@ -138,7 +144,7 @@ public class SysDictController {
      * @date: 2023/7/6
      * @date: 2023/7/6
      */
      */
     @PostMapping("queryDictTypePage")
     @PostMapping("queryDictTypePage")
-    public HttpResult queryDictTypePage (@RequestBody QueryDictTypePageReqVo reqVo) {
+    public HttpResult queryDictTypePage(@RequestBody QueryDictTypePageReqVo reqVo) {
         return HttpResult.ok(sysDictService.queryDictTypePage(reqVo));
         return HttpResult.ok(sysDictService.queryDictTypePage(reqVo));
     }
     }
 
 
@@ -149,7 +155,7 @@ public class SysDictController {
      * @date: 2023/7/6
      * @date: 2023/7/6
      */
      */
     @PostMapping("queryDictType")
     @PostMapping("queryDictType")
-    public HttpResult queryDictType (@RequestBody QueryDictTypePageReqVo reqVo) {
+    public HttpResult queryDictType(@RequestBody QueryDictTypePageReqVo reqVo) {
         return HttpResult.ok(sysDictService.queryDictType(reqVo));
         return HttpResult.ok(sysDictService.queryDictType(reqVo));
     }
     }
 
 

+ 30 - 2
sckw-modules/sckw-system/src/main/java/com/sckw/system/dao/SysDictDao.java

@@ -2,6 +2,8 @@ package com.sckw.system.dao;
 
 
 import com.sckw.system.model.SysDict;
 import com.sckw.system.model.SysDict;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
 
 
@@ -49,11 +51,37 @@ public interface SysDictDao {
     List<Map<String, Object>> findList(Map<String, Object> params);
     List<Map<String, Object>> findList(Map<String, Object> params);
 
 
     /**
     /**
-     * @param typeId 类型id
+     * @param type 类型
      * @return SysDict
      * @return SysDict
      * @desc: 根据类型查
      * @desc: 根据类型查
      * @author: czh
      * @author: czh
      * @date: 2023/7/6
      * @date: 2023/7/6
      */
      */
-    List<SysDict> queryByType(Long typeId);
+    List<SysDict> queryByType(String type);
+
+    /**
+     * @param dictTypeId 字典类型id, value选项值  label
+     * @return SysDict
+     * @desc: 查询唯一的一条字典
+     * @author: czh
+     * @date: 2023/7/7
+     */
+    SysDict queryUnitDict(@Param(value = "dictTypeId") Long dictTypeId, @Param(value = "value") String value, @Param(value = "label") String label);
+
+    /**
+     * @param type 类型 value key
+     * @return SysDict
+     * @desc: 根据类型和key查唯一一条
+     * @author: czh
+     * @date: 2023/7/7
+     */
+    SysDict queryByTypeAndValue(@Param(value = "type") String type, @Param(value = "value") String value);
+
+    /**
+     * @return SysDict
+     * @desc: 查全部
+     * @author: czh
+     * @date: 2023/7/7
+     */
+    List<SysDict> selectAll();
 }
 }

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

@@ -43,4 +43,5 @@ public interface SysDictTypeDao {
      * @date: 2023/7/6
      * @date: 2023/7/6
      */
      */
     List<SysDictType> select(SysDictType sysDictType);
     List<SysDictType> select(SysDictType sysDictType);
+
 }
 }

+ 109 - 0
sckw-modules/sckw-system/src/main/java/com/sckw/system/dubbo/RemoteBaseService.java

@@ -0,0 +1,109 @@
+package com.sckw.system.dubbo;
+
+import com.sckw.core.model.constant.Global;
+import com.sckw.core.utils.BeanUtils;
+import com.sckw.core.utils.CollectionUtils;
+import com.sckw.system.api.model.dto.res.*;
+import com.sckw.system.api.model.pojo.DeptInfoPojo;
+import com.sckw.system.model.*;
+import com.sckw.system.model.vo.res.CertificateResVo;
+import com.sckw.system.model.vo.res.KwsDeptResVo;
+import com.sckw.system.service.KwsDeptService;
+import com.sckw.system.service.KwsEnterpriseService;
+import com.sckw.system.service.KwsRoleService;
+import com.sckw.system.service.KwsUserService;
+import jakarta.annotation.Resource;
+import org.springframework.stereotype.Service;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * @author czh
+ * @desc 提取公共
+ * @date 2023/7/7
+ */
+@Service
+public class RemoteBaseService {
+
+    @Resource
+    private KwsEnterpriseService kwsEnterpriseService;
+
+    @Resource
+    private KwsDeptService kwsDeptService;
+
+    @Resource
+    private KwsUserService kwsUserService;
+
+    @Resource
+    private KwsRoleService kwsRoleService;
+
+
+    public KwsEnterpriseResDto queryEnterpriseById(Long id) {
+        KwsEnterprise kwsEnterprise = kwsEnterpriseService.queryKwsEnterpriseById(id);
+        if (Objects.isNull(kwsEnterprise)) {
+            return null;
+        }
+
+        KwsEnterpriseResDto kwsEnterpriseResDto = new KwsEnterpriseResDto();
+        BeanUtils.copyProperties(kwsEnterprise, kwsEnterpriseResDto);
+        return kwsEnterpriseResDto;
+    }
+
+    public KwsUserResDto getUserByAccount(String username) {
+        return null;
+    }
+
+    public List<KwsUserDeptResDto> queryUserDeptByUserId(Long userId) {
+        List<KwsUserDept> kwsUserDepts = kwsUserService.queryUserDeptByUserId(userId);
+        if (CollectionUtils.isEmpty(kwsUserDepts)) {
+            return Collections.emptyList();
+        }
+        return BeanUtils.copyToList(kwsUserDepts, KwsUserDeptResDto.class);
+    }
+
+    public List<KwsDeptResDto> queryDeptByIds(List<Long> ids) {
+        List<KwsDept> kwsDepts = kwsUserService.queryDeptByIds(ids);
+        if (CollectionUtils.isEmpty(kwsDepts)) {
+            return Collections.emptyList();
+        }
+
+        return BeanUtils.copyToList(kwsDepts, KwsDeptResDto.class);
+    }
+
+    public List<KwsRoleResDto> queryRoleInfoByUserId(Long userId) {
+        List<KwsRole> kwsRoles = kwsRoleService.queryRoleByUserId(userId);
+        if (CollectionUtils.isEmpty(kwsRoles)) {
+            return Collections.emptyList();
+        }
+        return BeanUtils.copyToList(kwsRoles, KwsRoleResDto.class);
+    }
+
+    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);
+    }
+
+    public List<EntCheckTrackResDto> checkTrackByEntId(Long entId) {
+        List<KwsEntCheckTrack> kwsEntCheckTracks = kwsEnterpriseService.entCheck(entId);
+        if (CollectionUtils.isEmpty(kwsEntCheckTracks)) {
+            return Collections.emptyList();
+        }
+        return BeanUtils.copyToList(kwsEntCheckTracks, EntCheckTrackResDto.class);
+    }
+
+    public List<DeptInfoPojo> queryDeftInfoByEntId(long entId) {
+        KwsDept kwsDept = new KwsDept();
+        kwsDept.setEntId(entId);
+        kwsDept.setDelFlag(Global.NO);
+        List<KwsDeptResVo> list = kwsDeptService.findList(kwsDept);
+        if (CollectionUtils.isEmpty(list)) {
+            return Collections.emptyList();
+        }
+        return BeanUtils.copyToList(list, DeptInfoPojo.class);
+    }
+}

+ 155 - 6
sckw-modules/sckw-system/src/main/java/com/sckw/system/dubbo/RemoteSystemServiceImpl.java

@@ -8,15 +8,16 @@ import com.sckw.core.utils.CollectionUtils;
 import com.sckw.core.utils.StringUtils;
 import com.sckw.core.utils.StringUtils;
 import com.sckw.redis.utils.RedissonUtils;
 import com.sckw.redis.utils.RedissonUtils;
 import com.sckw.system.api.RemoteSystemService;
 import com.sckw.system.api.RemoteSystemService;
-import com.sckw.system.api.model.dto.res.SysDictResDto;
+import com.sckw.system.api.model.dto.res.*;
 import com.sckw.system.dao.SysDictDao;
 import com.sckw.system.dao.SysDictDao;
+import com.sckw.system.model.KwsUser;
 import com.sckw.system.model.SysDict;
 import com.sckw.system.model.SysDict;
+import com.sckw.system.service.KwsUserService;
 import org.apache.dubbo.config.annotation.DubboService;
 import org.apache.dubbo.config.annotation.DubboService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
-import java.util.Collections;
-import java.util.List;
+import java.util.*;
 
 
 /**
 /**
  * @author czh
  * @author czh
@@ -30,13 +31,26 @@ public class RemoteSystemServiceImpl implements RemoteSystemService {
     @Autowired
     @Autowired
     private SysDictDao sysDictDao;
     private SysDictDao sysDictDao;
 
 
+    @Autowired
+    private KwsUserService kwsUserService;
+
+    @Autowired
+    private RemoteBaseService remoteBaseService;
+
+    /**
+     * @param type 类型
+     * @return SysDictResDto
+     * @desc: 根据类型id查字典,先查redis,没查到查数据库,查出来了存redis
+     * @author: czh
+     * @date: 2023/7/5
+     */
     @Override
     @Override
-    public List<SysDictResDto> queryDictByTypeId(Long typeId) {
-        String key = Global.REDIS_SYS_DICT_PREFIX + typeId;
+    public List<SysDictResDto> queryDictByType(String type) {
+        String key = Global.REDIS_SYS_DICT_TYPE_PREFIX + type;
         String dictCache = RedissonUtils.getString(key);
         String dictCache = RedissonUtils.getString(key);
         //从redis查,查不到从数据库查,并写入redis
         //从redis查,查不到从数据库查,并写入redis
         if (StringUtils.isBlank(dictCache)) {
         if (StringUtils.isBlank(dictCache)) {
-            List<SysDict> sysDictList = sysDictDao.queryByType(typeId);
+            List<SysDict> sysDictList = sysDictDao.queryByType(type);
             if (CollectionUtils.isEmpty(sysDictList)) {
             if (CollectionUtils.isEmpty(sysDictList)) {
                 return Collections.emptyList();
                 return Collections.emptyList();
             }
             }
@@ -48,4 +62,139 @@ public class RemoteSystemServiceImpl implements RemoteSystemService {
         return JSONObject.parseArray(dictCache, SysDictResDto.class);
         return JSONObject.parseArray(dictCache, SysDictResDto.class);
     }
     }
 
 
+    /**
+     * @param type 字典类型,value key
+     * @return SysDictResDto
+     * @desc: 根据字典类型和key查
+     * @author: czh
+     * @date: 2023/7/7
+     */
+    @Override
+    public SysDictResDto queryDictByTypeAndValue(String type, String value) {
+        String key = Global.REDIS_SYS_DICT_PREFIX + type + "#" + value;
+        String dictCache = RedissonUtils.getString(key);
+        //从redis查,查不到从数据库查,并写入redis
+        if (StringUtils.isBlank(dictCache)) {
+            SysDict sysDict = sysDictDao.queryByTypeAndValue(type, value);
+            if (Objects.isNull(sysDict)) {
+                return null;
+            }
+            SysDictResDto sysDictResDto = new SysDictResDto();
+            BeanUtils.copyProperties(sysDict, sysDictResDto);
+            RedissonUtils.putString(key, JSON.toJSONString(sysDictResDto), Global.COMMON_EXPIRE);
+            return sysDictResDto;
+        }
+        return JSONObject.parseObject(dictCache, SysDictResDto.class);
+    }
+
+    /**
+     * @param  type 字典类型,value key
+     * @return SysDictGroupResDto
+     * @desc: 根据字典类型和key查字典组
+     * @author: czh
+     * @date: 2023/7/7
+     */
+    @Override
+    public SysDictGroupResDto queryDictGroupByTypeAndValue(String type, String value) {
+        String key = Global.REDIS_SYS_DICT_GROUP_PREFIX + type + "#" + value;
+        String dictCache = RedissonUtils.getString(key);
+        //从redis查,查不到从数据库查,并写入redis
+        if (StringUtils.isBlank(dictCache)) {
+            List<SysDict> list = sysDictDao.selectAll();
+            if (CollectionUtils.isEmpty(list)) {
+                return null;
+            }
+            Optional<SysDict> first = list.stream().filter(item -> item.getType().equals(type) && item.getValue().equals(value)).findFirst();
+            if (first.isEmpty()) {
+                return null;
+            }
+
+            SysDictGroupResDto sysDictGroupResDto = new SysDictGroupResDto();
+            BeanUtils.copyProperties(first.get(), sysDictGroupResDto);
+            sysDictGroupResDto.setChild(getChild(sysDictGroupResDto.getId(), list));
+            RedissonUtils.putString(key, JSON.toJSONString(sysDictGroupResDto), Global.COMMON_EXPIRE);
+            return sysDictGroupResDto;
+        }
+        return JSONObject.parseObject(dictCache, SysDictGroupResDto.class);
+    }
+
+
+    /**
+     * @param entId 企业id
+     * @return EntCacheResDto
+     * @desc: 从缓存查企业信息
+     * @author: czh
+     * @date: 2023/7/7
+     */
+    @Override
+    public EntCacheResDto queryEntCacheById(Long entId) {
+        String key = Global.REDIS_ENTERPRISE_PREFIX + entId;
+        String dictCache = RedissonUtils.getString(key);
+        //从redis查,查不到从数据库查,并写入redis
+        if (StringUtils.isBlank(dictCache)) {
+            KwsEnterpriseResDto kwsEnterpriseResDto = remoteBaseService.queryEnterpriseById(entId);
+            if (Objects.isNull(kwsEnterpriseResDto)) {
+                return null;
+            }
+
+            EntCacheResDto entCacheResDto = new EntCacheResDto();
+            BeanUtils.copyProperties(kwsEnterpriseResDto, entCacheResDto);
+            entCacheResDto.setDeptInfo(remoteBaseService.queryDeftInfoByEntId(entId));
+            entCacheResDto.setCertificateInfo(remoteBaseService.queryCertificateByEntId(entId));
+            RedissonUtils.putString(key, JSON.toJSONString(entCacheResDto), Global.COMMON_EXPIRE);
+            return entCacheResDto;
+        }
+
+        return JSONObject.parseObject(dictCache, EntCacheResDto.class);
+    }
+
+    @Override
+    public UserCacheResDto queryUserCacheById(Long userId) {
+        String key = Global.REDIS_USER_PREFIX + userId;
+        String dictCache = RedissonUtils.getString(key);
+        //从redis查,查不到从数据库查,并写入redis
+        if (StringUtils.isBlank(dictCache)) {
+            KwsUser kwsUser = kwsUserService.selectByKey(userId);
+            if (Objects.isNull(kwsUser)) {
+                return null;
+            }
+
+            UserCacheResDto userCacheResDto = new UserCacheResDto();
+            BeanUtils.copyProperties(kwsUser, userCacheResDto);
+            userCacheResDto.setRoleInfo(remoteBaseService.queryRoleInfoByUserId(userId));
+
+            List<KwsUserDeptResDto> kwsUserDeptResDtos = remoteBaseService.queryUserDeptByUserId(userId);
+            if (!CollectionUtils.isEmpty(kwsUserDeptResDtos)) {
+            }
+
+        }
+
+        return null;
+    }
+
+    /**
+     * @param id 父id,需要遍历的list
+     * @return SysDictGroupResDto
+     * @desc: 构建字典组
+     * @author: czh
+     * @date: 2023/7/7
+     */
+    private List<SysDictGroupResDto> getChild(Long id, List<SysDict> list) {
+        List<SysDictGroupResDto> child = new ArrayList<>();
+        for (SysDict sysDict : list) {
+            if (sysDict.getParentId().equals(String.valueOf(id))) {
+                SysDictGroupResDto sysDictGroupResDto = new SysDictGroupResDto();
+                BeanUtils.copyProperties(sysDict, sysDictGroupResDto);
+                child.add(sysDictGroupResDto);
+            }
+        }
+
+        if (!CollectionUtils.isEmpty(child)) {
+            for (SysDictGroupResDto sysDictGroupResDto : child) {
+                sysDictGroupResDto.setChild(getChild(sysDictGroupResDto.getId(), list));
+            }
+        }
+        return child;
+    }
+
 }
 }

+ 22 - 50
sckw-modules/sckw-system/src/main/java/com/sckw/system/dubbo/RemoteUserServiceImpl.java

@@ -13,9 +13,7 @@ import com.sckw.system.dao.KwsUserLoginDao;
 import com.sckw.system.model.*;
 import com.sckw.system.model.*;
 import com.sckw.system.model.pojo.FindMenuTreePojo;
 import com.sckw.system.model.pojo.FindMenuTreePojo;
 import com.sckw.system.model.vo.req.ForgetPasswordReqVo;
 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.model.vo.res.KwsMenuResVo;
-import com.sckw.system.service.KwsEnterpriseService;
 import com.sckw.system.service.KwsMenuService;
 import com.sckw.system.service.KwsMenuService;
 import com.sckw.system.service.KwsRoleService;
 import com.sckw.system.service.KwsRoleService;
 import com.sckw.system.service.KwsUserService;
 import com.sckw.system.service.KwsUserService;
@@ -38,10 +36,10 @@ import java.util.Objects;
 public class RemoteUserServiceImpl implements RemoteUserService {
 public class RemoteUserServiceImpl implements RemoteUserService {
 
 
     @Resource
     @Resource
-    private KwsUserService kwsUserService;
+    private RemoteBaseService remoteBaseService;
 
 
     @Resource
     @Resource
-    private KwsEnterpriseService kwsEnterpriseService;
+    private KwsUserService kwsUserService;
 
 
     @Resource
     @Resource
     private KwsRoleService kwsRoleService;
     private KwsRoleService kwsRoleService;
@@ -52,49 +50,15 @@ public class RemoteUserServiceImpl implements RemoteUserService {
     @Resource
     @Resource
     private KwsUserLoginDao kwsUserLoginDao;
     private KwsUserLoginDao kwsUserLoginDao;
 
 
-    @Override
-    public KwsUserResDto getUserByAccount(String username) {
-        return null;
-    }
-
-    @Override
-    public List<KwsUserDeptResDto> queryUserDeptByUserId(Long userId) {
-        List<KwsUserDept> kwsUserDepts = kwsUserService.queryUserDeptByUserId(userId);
-        if (CollectionUtils.isEmpty(kwsUserDepts)) {
-            return Collections.emptyList();
-        }
-        return BeanUtils.copyToList(kwsUserDepts, KwsUserDeptResDto.class);
-    }
-
-    @Override
-    public List<KwsDeptResDto> queryDeptByIds(List<Long> ids) {
-        List<KwsDept> kwsDepts = kwsUserService.queryDeptByIds(ids);
-        if (CollectionUtils.isEmpty(kwsDepts)) {
-            return Collections.emptyList();
-        }
-
-        return BeanUtils.copyToList(kwsDepts, KwsDeptResDto.class);
-    }
 
 
     @Override
     @Override
     public KwsEnterpriseResDto queryEnterpriseById(Long id) {
     public KwsEnterpriseResDto queryEnterpriseById(Long id) {
-        KwsEnterprise kwsEnterprise = kwsEnterpriseService.queryKwsEnterpriseById(id);
-        if (Objects.isNull(kwsEnterprise)) {
-            return null;
-        }
-
-        KwsEnterpriseResDto kwsEnterpriseResDto = new KwsEnterpriseResDto();
-        BeanUtils.copyProperties(kwsEnterprise, kwsEnterpriseResDto);
-        return kwsEnterpriseResDto;
+        return remoteBaseService.queryEnterpriseById(id);
     }
     }
 
 
     @Override
     @Override
     public List<KwsRoleResDto> queryRoleInfoByUserId(Long userId) {
     public List<KwsRoleResDto> queryRoleInfoByUserId(Long userId) {
-        List<KwsRole> kwsRoles = kwsRoleService.queryRoleByUserId(userId);
-        if (CollectionUtils.isEmpty(kwsRoles)) {
-            return Collections.emptyList();
-        }
-        return BeanUtils.copyToList(kwsRoles, KwsRoleResDto.class);
+        return remoteBaseService.queryRoleInfoByUserId(userId);
     }
     }
 
 
     @Override
     @Override
@@ -141,22 +105,15 @@ public class RemoteUserServiceImpl implements RemoteUserService {
 
 
     @Override
     @Override
     public List<EntCertificateResDto> queryCertificateByEntId(Long entId) {
     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);
+        return remoteBaseService.queryCertificateByEntId(entId);
     }
     }
 
 
     @Override
     @Override
     public List<EntCheckTrackResDto> checkTrackByEntId(Long entId) {
     public List<EntCheckTrackResDto> checkTrackByEntId(Long entId) {
-        List<KwsEntCheckTrack> kwsEntCheckTracks = kwsEnterpriseService.entCheck(entId);
-        if (CollectionUtils.isEmpty(kwsEntCheckTracks)) {
-            return Collections.emptyList();
-        }
-        return BeanUtils.copyToList(kwsEntCheckTracks, EntCheckTrackResDto.class);
+        return remoteBaseService.checkTrackByEntId(entId);
     }
     }
 
 
+
     @Override
     @Override
     public void updatePassword(UpdatePasswordReqDto updatePassword) {
     public void updatePassword(UpdatePasswordReqDto updatePassword) {
         kwsUserService.updatePassword(updatePassword);
         kwsUserService.updatePassword(updatePassword);
@@ -167,6 +124,21 @@ public class RemoteUserServiceImpl implements RemoteUserService {
         kwsUserService.resetPassword(id);
         kwsUserService.resetPassword(id);
     }
     }
 
 
+    @Override
+    public KwsUserResDto getUserByAccount(String username) {
+        return remoteBaseService.getUserByAccount(username);
+    }
+
+    @Override
+    public List<KwsUserDeptResDto> queryUserDeptByUserId(Long userId) {
+        return remoteBaseService.queryUserDeptByUserId(userId);
+    }
+
+    @Override
+    public List<KwsDeptResDto> queryDeptByIds(List<Long> ids) {
+        return remoteBaseService.queryDeptByIds(ids);
+    }
+
     @Override
     @Override
     public void register(RegisterReqDto reqDto) throws SystemException {
     public void register(RegisterReqDto reqDto) throws SystemException {
         kwsUserService.register(reqDto);
         kwsUserService.register(reqDto);

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

@@ -199,7 +199,7 @@ public class KwsRoleService {
         //让涉及到的用户重新登录获取菜单权限
         //让涉及到的用户重新登录获取菜单权限
         for (KwsUserRole kwsUserRole : kwsUserRoleList) {
         for (KwsUserRole kwsUserRole : kwsUserRoleList) {
             Long userId = kwsUserRole.getUserId();
             Long userId = kwsUserRole.getUserId();
-            RedissonUtils.deleteBactch(Global.REDIS_USER_PREFIX + userId + "*");
+            RedissonUtils.deleteBactch(Global.REDIS_USER_LOGIN_PREFIX + userId + "*");
         }
         }
     }
     }
 
 
@@ -309,7 +309,7 @@ public class KwsRoleService {
             }
             }
         }
         }
         RedissonUtils.putSet(Global.getFullUserMenuKey(reqVo.getSystemType(), userId), menus);
         RedissonUtils.putSet(Global.getFullUserMenuKey(reqVo.getSystemType(), userId), menus);
-        RedissonUtils.deleteBactch(Global.REDIS_USER_PREFIX + userId + "*");
+        RedissonUtils.deleteBactch(Global.REDIS_USER_LOGIN_PREFIX + userId + "*");
 
 
     }
     }
 
 

+ 71 - 65
sckw-modules/sckw-system/src/main/java/com/sckw/system/service/SysDictService.java

@@ -10,7 +10,6 @@ import com.sckw.core.utils.BeanUtils;
 import com.sckw.core.utils.CollectionUtils;
 import com.sckw.core.utils.CollectionUtils;
 import com.sckw.core.utils.StringUtils;
 import com.sckw.core.utils.StringUtils;
 import com.sckw.core.web.constant.HttpStatus;
 import com.sckw.core.web.constant.HttpStatus;
-import com.sckw.core.web.response.HttpResult;
 import com.sckw.system.dao.SysDictDao;
 import com.sckw.system.dao.SysDictDao;
 import com.sckw.system.dao.SysDictTypeDao;
 import com.sckw.system.dao.SysDictTypeDao;
 import com.sckw.system.model.SysDict;
 import com.sckw.system.model.SysDict;
@@ -21,6 +20,7 @@ import org.springframework.stereotype.Service;
 
 
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
+import java.util.Objects;
 
 
 /**
 /**
  * 字典service接口
  * 字典service接口
@@ -45,12 +45,17 @@ public class SysDictService {
      */
      */
     public void addType(SysDictType params) throws SystemException {
     public void addType(SysDictType params) throws SystemException {
         checkType(params.getType());
         checkType(params.getType());
-
         if (sysDictTypeDao.insert(params) <= 0) {
         if (sysDictTypeDao.insert(params) <= 0) {
             throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
             throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
         }
         }
     }
     }
 
 
+    /**
+     * @param type 字典类型
+     * @desc: 字典类型查重
+     * @author: czh
+     * @date: 2023/7/7
+     */
     private void checkType(String type) {
     private void checkType(String type) {
         SysDictType sysDictType = new SysDictType();
         SysDictType sysDictType = new SysDictType();
         sysDictType.setType(type);
         sysDictType.setType(type);
@@ -61,111 +66,112 @@ public class SysDictService {
     }
     }
 
 
     /**
     /**
-     * 更新记录
-     *
-     * @param params
-     * @return
-     * @throws Exception
+     * @param params 实体
+     * @desc: 更新记录
+     * @author: czh
+     * @date: 2023/7/7
      */
      */
-    public HttpResult updateType(SysDictType params) throws Exception {
-        int count = sysDictTypeDao.update(params);
-        return count > 0 ? HttpResult.ok("更新成功!") : HttpResult.error();
+    public void updateType(SysDictType params) throws SystemException {
+        checkType(params.getType());
+        if (sysDictTypeDao.update(params) <= 0) {
+            throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
+        }
     }
     }
 
 
     /**
     /**
-     * 分页查询
-     *
-     * @param params
-     * @return
-     * @throws Exception
+     * @param params map
+
+     * @return SysDict
      */
      */
-    public List<SysDict> findPage(Map<String, Object> params) throws Exception {
+    public List<SysDict> findPage(Map<String, Object> params) throws SystemException {
         return sysDictDao.findPage(params);
         return sysDictDao.findPage(params);
     }
     }
 
 
     /**
     /**
-     * 添加新纪录
-     *
-     * @param params
-     * @return
-     * @throws Exception
+     * @param params 实体
+     * @desc: 添加新纪录
      */
      */
-    public HttpResult add(SysDict params) throws Exception {
-        /*params.setId(new IdWorker(1).nextId());
-        params.setStatus(0);
-        params.setCreateBy(0L);
-        params.setCreateTime(new Date());
-        params.setUpdateBy(0L);
-        params.setUpdateTime(new Date());
-        params.setDelFlag(0);*/
-        params.setCreateBy(0L);
-        params.setUpdateBy(0L);
-        int count = sysDictDao.insert(params);
-        return count > 0 ? HttpResult.ok("添加成功!") : HttpResult.error();
+    public void add(SysDict params) throws SystemException {
+        checkDict(params.getDictId(), params.getValue(), params.getLabel());
+        if (sysDictDao.insert(params) <= 0) {
+            throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.INSERT_FAIL);
+        }
     }
     }
 
 
     /**
     /**
-     * 删除记录-根据主键
-     *
-     * @param ids
-     * @return
-     * @throws Exception
+     * @param dictTypeId 字典类型id, value选项值  label
+     * @desc: 字典查重
+     * @author: czh
+     * @date: 2023/7/7
+     */
+    public void checkDict(Long dictTypeId, String value, String label) throws SystemException {
+        SysDict sysDict = sysDictDao.queryUnitDict(dictTypeId, value, label);
+        if (!Objects.isNull(sysDict)) {
+            throw new SystemException(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.DICT_EXISTS);
+        }
+    }
+
+    /**
+     * @param ids 主键
+     * @desc: 删除记录-根据主键
+     * @author: czh
+     * @date: 2023/7/7
      */
      */
-    public HttpResult deleteByKey(String ids) throws Exception {
-        /**1.数据校验**/
+    public void deleteByKey(String ids) throws SystemException {
+        /*1.数据校验*/
         if (StringUtils.isBlank(ids)) {
         if (StringUtils.isBlank(ids)) {
-            return HttpResult.error("请选择您要删除的字典信息!");
+            throw new SystemException(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.ID_MISSING);
         }
         }
 
 
-        int resultCode = 0;
         String[] idArray = ids.split(",");
         String[] idArray = ids.split(",");
-        for (int i = 0; i < idArray.length; i++) {
-            String id = idArray[i];
+        for (String id : idArray) {
             SysDict sysDict = sysDictDao.selectByKey(Long.parseLong(id));
             SysDict sysDict = sysDictDao.selectByKey(Long.parseLong(id));
             if (null != sysDict) {
             if (null != sysDict) {
                 sysDict.setDelFlag(Global.YES);
                 sysDict.setDelFlag(Global.YES);
-                resultCode = sysDictDao.update(sysDict);
+                if (sysDictDao.update(sysDict) <= 0) {
+                    throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.DELETE_FAIL);
+                }
             }
             }
         }
         }
-        return resultCode > 0 ? HttpResult.ok("删除成功!") : HttpResult.error("删除失败!");
     }
     }
 
 
     /**
     /**
-     * 更新记录
-     *
-     * @param params
-     * @return
-     * @throws Exception
+     * @param params 实体
+     * @desc: 更新记录
+     * @author: czh
+     * @date: 2023/7/7
      */
      */
-    public HttpResult update(SysDict params) throws Exception {
-        int count = sysDictDao.update(params);
-        return count > 0 ? HttpResult.ok("更新成功!") : HttpResult.error();
+    public void update(SysDict params) throws SystemException {
+        checkDict(params.getDictId(), params.getValue(), params.getLabel());
+        if (sysDictDao.update(params) <= 0) {
+            throw new SystemException(HttpStatus.CRUD_FAIL_CODE, HttpStatus.UPDATE_FAIL);
+        }
     }
     }
 
 
     /**
     /**
-     * 根据主键查询
      *
      *
-     * @param key
-     * @return
-     * @throws Exception
+     *
+     * @param key 主键
+     * @desc: 根据主键查询
+     * @return SysDict
+     * @author: czh
+     * @date: 2023/7/7
      */
      */
-    public SysDict selectByKey(Long key) throws Exception {
+    public SysDict selectByKey(Long key) throws SystemException {
         return sysDictDao.selectByKey(key);
         return sysDictDao.selectByKey(key);
     }
     }
 
 
     /**
     /**
      * 查询
      * 查询
-     *
-     * @param params
-     * @return
-     * @throws Exception
+     * @param params map
+     * @return List
      */
      */
-    public List<Map<String, Object>> findList(Map<String, Object> params) throws Exception {
+    public List<Map<String, Object>> findList(Map<String, Object> params) throws SystemException {
         return sysDictDao.findList(params);
         return sysDictDao.findList(params);
     }
     }
 
 
     /**
     /**
-     * @param reqVo
+     * @param reqVo 入参
      * @return PageResult
      * @return PageResult
      * @desc: 查字典类型
      * @desc: 查字典类型
      * @author: czh
      * @author: czh

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

@@ -211,9 +211,31 @@
     </if>
     </if>
     ORDER BY sort
     ORDER BY sort
   </select>
   </select>
+
   <select id="queryByType" resultType="com.sckw.system.model.SysDict">
   <select id="queryByType" resultType="com.sckw.system.model.SysDict">
-    select * from sys_dict where del_flag = 0 and dict_id = #{typeId}
+    select * from sys_dict where del_flag = 0 and type = #{type}
+  </select>
+
+  <select id="queryUnitDict" resultType="com.sckw.system.model.SysDict">
+    select *
+      from sys_dict
+     where del_flag = 0
+       and dict_id = #{dictTypeId}
+       and (value = #{value} or label = #{label})
+  </select>
+
+  <select id="queryByTypeAndValue" resultType="com.sckw.system.model.SysDict">
+    select *
+    from sys_dict
+    where del_flag = 0
+      and type = #{type}
+      and value = #{value}
   </select>
   </select>
 
 
+  <select id="selectAll" resultType="com.sckw.system.model.SysDict">
+    select *
+      from sys_dict
+     where del_flag = 0
+  </select>
 
 
 </mapper>
 </mapper>