소스 검색

20230308_sun修正行政区划完整名从redis取

15143018065 2 년 전
부모
커밋
822b02dc16

+ 5 - 0
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/CacheConstants.java

@@ -51,4 +51,9 @@ public class CacheConstants
      * 登录账户密码错误次数 redis key
      */
     public static final String PWD_ERR_CNT_KEY = "pwd_err_cnt:";
+
+    /**
+     * 字典管理 cache key
+     */
+    public static final String SYS_DEPT_JL_KEY = "sys_dept_jl:";
 }

+ 77 - 0
ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/utils/SysDeptJlUtils.java

@@ -0,0 +1,77 @@
+package com.ruoyi.common.security.utils;
+
+import com.ruoyi.common.core.constant.CacheConstants;
+import com.ruoyi.common.core.utils.SpringUtils;
+import com.ruoyi.common.core.utils.StringUtils;
+import com.ruoyi.common.redis.configure.RedisKeySerializer;
+import com.ruoyi.common.redis.service.RedisService;
+
+import java.util.Collection;
+import java.util.stream.Collectors;
+
+/**
+ * 吉林省行政区划工具类
+ *
+ * @author sun
+ */
+public class SysDeptJlUtils {
+
+    /**
+     * 设置行政区划缓存
+     *
+     * @param key 参数键
+     * @param fullName 完整行政区划名
+     */
+    public static void setDeptCache(String key, String fullName)
+    {
+        SpringUtils.getBean(RedisService.class).setCacheObject(getCacheKey(key), fullName);
+    }
+
+    /**
+     * 获取行政区划缓存
+     *
+     * @param key 参数键
+     * @return dictDatas 行政区划完整名
+     */
+    public static String getDeptCache(String key)
+    {
+        Object cache = SpringUtils.getBean(RedisService.class).getCacheObject(getCacheKey(key));
+        if (StringUtils.isNotNull(cache))
+        {
+            return cache.toString();
+        }
+        return null;
+    }
+
+    /**
+     * 删除指定行政区划缓存
+     *
+     * @param key 参数键
+     */
+    public static void removeDeptCache(String key)
+    {
+        SpringUtils.getBean(RedisService.class).deleteObject(getCacheKey(key));
+    }
+
+    /**
+     * 清空行政区划缓存
+     */
+    public static void clearDeptCache()
+    {
+        Collection<String> keys = SpringUtils.getBean(RedisService.class).keys(CacheConstants.SYS_DEPT_JL_KEY + "*");
+        Collection<String> keys2 = keys.stream().map(item -> item.replace(RedisKeySerializer.key + ":", "")).collect(Collectors.toSet());
+        SpringUtils.getBean(RedisService.class).deleteObject(keys2);
+    }
+
+    /**
+     * 设置cache key
+     *
+     * @param configKey 参数键
+     * @return 缓存键key
+     */
+    public static String getCacheKey(String configKey)
+    {
+        return CacheConstants.SYS_DEPT_JL_KEY + configKey;
+    }
+
+}

+ 10 - 0
ruoyi-modules/mz-business/src/main/java/com/ruoyi/business/controller/YljgKhJbxxController.java

@@ -122,6 +122,16 @@ public class YljgKhJbxxController extends BaseController
         util.exportExcel(response, list, "养老机构_客户_基本信息数据");
     }
 
+    @RequiresPermissions(value = {"business:rzjg:export", "search:rzjg:export"}, logical = Logical.OR)
+    @Log(title = "养老机构_客户_基本信息", businessType = BusinessType.EXPORT)
+    @PostMapping("/sq/export")
+    public void sqExport(HttpServletResponse response, YljgKhJbxx yljgKhJbxx)
+    {
+        List<YljgKhJbxx> list = yljgKhJbxxService.selectBusinessYljgKhJbxxSqList(yljgKhJbxx);
+        ExcelUtil<YljgKhJbxx> util = new ExcelUtil<YljgKhJbxx>(YljgKhJbxx.class);
+        util.exportExcel(response, list, "养老机构_客户_基本信息数据");
+    }
+
     /**
      * 获取养老机构_客户_基本信息详细信息
      */

+ 10 - 0
ruoyi-modules/mz-system-ext/src/main/java/com/ruoyi/system/domain/SysDeptJl.java

@@ -1,6 +1,7 @@
 package com.ruoyi.system.domain;
 
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.ruoyi.common.core.annotation.Excel;
@@ -13,6 +14,7 @@ import lombok.EqualsAndHashCode;
 import lombok.NoArgsConstructor;
 
 import javax.validation.constraints.Size;
+import java.util.List;
 
 /**
  * 吉林地区管理对象 sys_dept_jl
@@ -67,4 +69,12 @@ public class SysDeptJl extends BaseEntity
 
     private String isPgc;
 
+    @TableField(exist = false)
+    private String fullName;
+
+    @TableField(exist = false)
+    private List<String> codeList;
+
+    @TableField(exist = false)
+    private List<String> idList;
 }

+ 2 - 0
ruoyi-modules/mz-system-ext/src/main/java/com/ruoyi/system/mapper/SysDeptJlMapper.java

@@ -100,4 +100,6 @@ public interface SysDeptJlMapper extends BaseMapperPlus<SysDeptJl>
     public String selectAreaCodeByDeptId(String id);
 
     public List<SysDept> selectSysDeptJl();
+
+    public List<SysDeptJl> selectSysDeptJlUnderJl();
 }

+ 4 - 0
ruoyi-modules/mz-system-ext/src/main/java/com/ruoyi/system/service/ISysDeptJlService.java

@@ -85,4 +85,8 @@ public interface ISysDeptJlService
     public List<SysDeptJl> getLevelListZS(String code, String level);
 
     public String getLocationName(String code);
+
+    public void loadingDeptCache();
+
+    public void clearDeptCache();
 }

+ 42 - 2
ruoyi-modules/mz-system-ext/src/main/java/com/ruoyi/system/service/impl/SysDeptJlServiceImpl.java

@@ -3,16 +3,20 @@ package com.ruoyi.system.service.impl;
 import com.ruoyi.common.core.exception.ServiceException;
 import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.common.core.utils.uuid.IdUtils;
+import com.ruoyi.common.security.utils.SysDeptJlUtils;
 import com.ruoyi.system.domain.SysDeptJl;
 import com.ruoyi.system.mapper.SysDeptJlMapper;
 import com.ruoyi.system.service.ISysDeptJlService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.PostConstruct;
 import java.text.DecimalFormat;
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * 吉林地区管理Service业务层处理
@@ -119,7 +123,10 @@ public class SysDeptJlServiceImpl implements ISysDeptJlService {
         sysDeptJl.setCode(s);
         sysDeptJl.setLevel(Integer.parseInt(sysDeptJl1.getLevel()) + 1 + "");
         sysDeptJl.setId(IdUtils.simpleUUID());
-        return sysDeptJlMapper.insertSysDeptJl(sysDeptJl);
+        sysDeptJl.setFullName(getLocationName(sysDeptJl1.getCode() + " " + sysDeptJl.getName()));
+        int res = sysDeptJlMapper.insertSysDeptJl(sysDeptJl);
+        SysDeptJlUtils.setDeptCache(sysDeptJl.getCode(), sysDeptJl.getFullName());
+        return res;
     }
 
     /**
@@ -130,10 +137,14 @@ public class SysDeptJlServiceImpl implements ISysDeptJlService {
      */
     @Override
     public int updateSysDeptJl(SysDeptJl sysDeptJl) {
+        SysDeptJl old = sysDeptJlMapper.selectById(sysDeptJl.getId());
+        sysDeptJl.setFullName(getLocationName(old.getParentId()) + " " + sysDeptJl.getName());
         sysDeptJl.setParentId(null);
         sysDeptJl.setLevel(null);
         sysDeptJl.setCode(null);
-        return sysDeptJlMapper.updateSysDeptJl(sysDeptJl);
+        int res = sysDeptJlMapper.updateSysDeptJl(sysDeptJl);
+        SysDeptJlUtils.setDeptCache(old.getCode(), sysDeptJl.getFullName());
+        return res;
     }
 
     /**
@@ -144,6 +155,11 @@ public class SysDeptJlServiceImpl implements ISysDeptJlService {
      */
     @Override
     public int deleteSysDeptJlByIds(String[] ids) {
+        List<String> idList = Stream.of(ids).collect(Collectors.toList());
+        idList.forEach(i -> {
+            SysDeptJl delete = sysDeptJlMapper.selectById(i);
+            SysDeptJlUtils.removeDeptCache(delete.getCode());
+        });
         return sysDeptJlMapper.deleteSysDeptJlByIds(ids);
     }
 
@@ -155,6 +171,8 @@ public class SysDeptJlServiceImpl implements ISysDeptJlService {
      */
     @Override
     public int deleteSysDeptJlById(String id) {
+        SysDeptJl delete = sysDeptJlMapper.selectById(id);
+        SysDeptJlUtils.removeDeptCache(delete.getCode());
         return sysDeptJlMapper.deleteSysDeptJlById(id);
     }
 
@@ -243,4 +261,26 @@ public class SysDeptJlServiceImpl implements ISysDeptJlService {
     public String getLocationName(String code) {
         return sysDeptJlMapper.getXzqhNames(code);
     }
+
+    /**
+     * 项目启动时,初始化行政区划到缓存
+     */
+    @PostConstruct
+    public void init()
+    {
+        loadingDeptCache();
+    }
+
+    @Override
+    public void loadingDeptCache()
+    {
+        List<SysDeptJl> sysDeptJlList = sysDeptJlMapper.selectSysDeptJlUnderJl();
+        sysDeptJlList.forEach(s -> SysDeptJlUtils.setDeptCache(s.getCode(), s.getFullName()));
+    }
+
+    @Override
+    public void clearDeptCache()
+    {
+        SysDeptJlUtils.clearDeptCache();
+    }
 }

+ 5 - 0
ruoyi-modules/mz-system-ext/src/main/resources/mapper/system/SysDeptJlMapper.xml

@@ -8,6 +8,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="id"    column="id"    />
         <result property="code"    column="code"    />
         <result property="name"    column="name"    />
+        <result property="fullName"    column="full_name"    />
         <result property="parentId"    column="parent_id"    />
         <result property="ancestors"    column="ancestors"    />
         <result property="level"    column="level"    />
@@ -285,4 +286,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         from sys_dept_jl
         WHERE id = #{id}
     </select>
+
+    <select id="selectSysDeptJlUnderJl" parameterType="String" resultMap="SysDeptJlResult">
+        select id, code, full_name, ancestors from sys_dept_jl where find_in_set('220000000000', ancestors)
+    </select>
 </mapper>