diff --git a/pqs-common/common-redis/src/main/java/com/njcn/redis/pojo/enums/AppRedisKey.java b/pqs-common/common-redis/src/main/java/com/njcn/redis/pojo/enums/AppRedisKey.java index 8db20301b..af1256b18 100644 --- a/pqs-common/common-redis/src/main/java/com/njcn/redis/pojo/enums/AppRedisKey.java +++ b/pqs-common/common-redis/src/main/java/com/njcn/redis/pojo/enums/AppRedisKey.java @@ -95,4 +95,19 @@ public interface AppRedisKey { String DOWNLOAD = "downloadKey:"; String CONTROL = "control:"; + + /** + * 设备池 + */ + String DEVICE_LIST = "deviceListKey"; + + /** + * 字典树 + */ + String DICT_TREE = "dictTreeKey"; + + /** + * 模板 + */ + String DEV_MODEL = "devModelKey:"; } diff --git a/pqs-common/common-redis/src/main/java/com/njcn/redis/utils/RedisUtil.java b/pqs-common/common-redis/src/main/java/com/njcn/redis/utils/RedisUtil.java index d05c422c4..e8d8fed36 100644 --- a/pqs-common/common-redis/src/main/java/com/njcn/redis/utils/RedisUtil.java +++ b/pqs-common/common-redis/src/main/java/com/njcn/redis/utils/RedisUtil.java @@ -3,6 +3,7 @@ package com.njcn.redis.utils; import lombok.RequiredArgsConstructor; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; import java.util.*; @@ -79,6 +80,17 @@ public class RedisUtil { redisTemplate.delete(Arrays.asList(keys)); } + /** + * 指定字符模糊匹配,批量删除keys + */ + public void deleteKeysByString(String str) { + Set keys = redisTemplate.keys(str.concat("*")); + // 删除所有匹配的key + if (keys != null && !keys.isEmpty()) { + redisTemplate.delete(keys); + } + } + /** * 获取key对应的字符数据 diff --git a/pqs-system/system-boot/src/main/java/com/njcn/system/init/InitEpdPqd.java b/pqs-system/system-boot/src/main/java/com/njcn/system/init/InitEpdPqd.java index 187ddbace..c653f3e4b 100644 --- a/pqs-system/system-boot/src/main/java/com/njcn/system/init/InitEpdPqd.java +++ b/pqs-system/system-boot/src/main/java/com/njcn/system/init/InitEpdPqd.java @@ -1,6 +1,7 @@ package com.njcn.system.init; import com.njcn.system.service.IEleEpdPqdService; +import com.njcn.system.service.SysDicTreePOService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.CommandLineRunner; @@ -16,9 +17,11 @@ import org.springframework.stereotype.Component; public class InitEpdPqd implements CommandLineRunner { private final IEleEpdPqdService epdPqdService; + private final SysDicTreePOService sysDicTreePOService; @Override public void run(String... args) { epdPqdService.refreshEpdPqdDataCache(); + sysDicTreePOService.refreshDictTreeCache(); } } diff --git a/pqs-system/system-boot/src/main/java/com/njcn/system/service/SysDicTreePOService.java b/pqs-system/system-boot/src/main/java/com/njcn/system/service/SysDicTreePOService.java index 2665e2095..dd241182c 100644 --- a/pqs-system/system-boot/src/main/java/com/njcn/system/service/SysDicTreePOService.java +++ b/pqs-system/system-boot/src/main/java/com/njcn/system/service/SysDicTreePOService.java @@ -16,6 +16,10 @@ import java.util.List; */ public interface SysDicTreePOService extends IService { + /** + * 初始化缓存设备树 + */ + void refreshDictTreeCache(); boolean addDictTree(DictTreeParam dictTreeParam); diff --git a/pqs-system/system-boot/src/main/java/com/njcn/system/service/impl/SysDicTreePOServiceImpl.java b/pqs-system/system-boot/src/main/java/com/njcn/system/service/impl/SysDicTreePOServiceImpl.java index baf168d5c..b0c8e94a6 100644 --- a/pqs-system/system-boot/src/main/java/com/njcn/system/service/impl/SysDicTreePOServiceImpl.java +++ b/pqs-system/system-boot/src/main/java/com/njcn/system/service/impl/SysDicTreePOServiceImpl.java @@ -5,16 +5,19 @@ import cn.hutool.core.text.StrPool; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.njcn.common.pojo.constant.BizParamConstant; +import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO; +import com.njcn.redis.pojo.enums.AppRedisKey; +import com.njcn.redis.utils.RedisUtil; import com.njcn.system.enums.DicDataTypeEnum; import com.njcn.system.pojo.constant.DicState; +import com.njcn.system.pojo.dto.EpdDTO; import com.njcn.system.pojo.param.DictTreeParam; import com.njcn.system.pojo.vo.DictTreeVO; +import lombok.RequiredArgsConstructor; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -31,11 +34,23 @@ import org.springframework.transaction.annotation.Transactional; * @version V1.0.0 */ @Service +@RequiredArgsConstructor public class SysDicTreePOServiceImpl extends ServiceImpl implements SysDicTreePOService { + private final RedisUtil redisUtil; + + @Override + public void refreshDictTreeCache() { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(SysDicTreePO::getStatus,0); + List list = this.list(queryWrapper); + redisUtil.saveByKey(AppRedisKey.DICT_TREE,list); + } + @Override @Transactional(rollbackFor = {Exception.class}) public boolean addDictTree(DictTreeParam dictTreeParam) { + boolean result; SysDicTreePO sysDicTreePO = new SysDicTreePO(); BeanUtils.copyProperties(dictTreeParam, sysDicTreePO); if (!Objects.equals(sysDicTreePO.getPid(), BizParamConstant.PARENT_ID)) { @@ -51,19 +66,32 @@ public class SysDicTreePOServiceImpl extends ServiceImpl