初始化字典数据至内存
This commit is contained in:
@@ -95,4 +95,19 @@ public interface AppRedisKey {
|
|||||||
String DOWNLOAD = "downloadKey:";
|
String DOWNLOAD = "downloadKey:";
|
||||||
|
|
||||||
String CONTROL = "control:";
|
String CONTROL = "control:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备池
|
||||||
|
*/
|
||||||
|
String DEVICE_LIST = "deviceListKey";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字典树
|
||||||
|
*/
|
||||||
|
String DICT_TREE = "dictTreeKey";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模板
|
||||||
|
*/
|
||||||
|
String DEV_MODEL = "devModelKey:";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.njcn.redis.utils;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -79,6 +80,17 @@ public class RedisUtil {
|
|||||||
redisTemplate.delete(Arrays.asList(keys));
|
redisTemplate.delete(Arrays.asList(keys));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定字符模糊匹配,批量删除keys
|
||||||
|
*/
|
||||||
|
public void deleteKeysByString(String str) {
|
||||||
|
Set<String> keys = redisTemplate.keys(str.concat("*"));
|
||||||
|
// 删除所有匹配的key
|
||||||
|
if (keys != null && !keys.isEmpty()) {
|
||||||
|
redisTemplate.delete(keys);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取key对应的字符数据
|
* 获取key对应的字符数据
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.njcn.system.init;
|
package com.njcn.system.init;
|
||||||
|
|
||||||
import com.njcn.system.service.IEleEpdPqdService;
|
import com.njcn.system.service.IEleEpdPqdService;
|
||||||
|
import com.njcn.system.service.SysDicTreePOService;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.boot.CommandLineRunner;
|
import org.springframework.boot.CommandLineRunner;
|
||||||
@@ -16,9 +17,11 @@ import org.springframework.stereotype.Component;
|
|||||||
public class InitEpdPqd implements CommandLineRunner {
|
public class InitEpdPqd implements CommandLineRunner {
|
||||||
|
|
||||||
private final IEleEpdPqdService epdPqdService;
|
private final IEleEpdPqdService epdPqdService;
|
||||||
|
private final SysDicTreePOService sysDicTreePOService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(String... args) {
|
public void run(String... args) {
|
||||||
epdPqdService.refreshEpdPqdDataCache();
|
epdPqdService.refreshEpdPqdDataCache();
|
||||||
|
sysDicTreePOService.refreshDictTreeCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public interface SysDicTreePOService extends IService<SysDicTreePO> {
|
public interface SysDicTreePOService extends IService<SysDicTreePO> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化缓存设备树
|
||||||
|
*/
|
||||||
|
void refreshDictTreeCache();
|
||||||
|
|
||||||
boolean addDictTree(DictTreeParam dictTreeParam);
|
boolean addDictTree(DictTreeParam dictTreeParam);
|
||||||
|
|
||||||
|
|||||||
@@ -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.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.njcn.common.pojo.constant.BizParamConstant;
|
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.enums.DicDataTypeEnum;
|
||||||
import com.njcn.system.pojo.constant.DicState;
|
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.param.DictTreeParam;
|
||||||
import com.njcn.system.pojo.vo.DictTreeVO;
|
import com.njcn.system.pojo.vo.DictTreeVO;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
@@ -31,11 +34,23 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
* @version V1.0.0
|
* @version V1.0.0
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class SysDicTreePOServiceImpl extends ServiceImpl<SysDicTreePOMapper, SysDicTreePO> implements SysDicTreePOService {
|
public class SysDicTreePOServiceImpl extends ServiceImpl<SysDicTreePOMapper, SysDicTreePO> implements SysDicTreePOService {
|
||||||
|
|
||||||
|
private final RedisUtil redisUtil;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refreshDictTreeCache() {
|
||||||
|
LambdaQueryWrapper<SysDicTreePO> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(SysDicTreePO::getStatus,0);
|
||||||
|
List<SysDicTreePO> list = this.list(queryWrapper);
|
||||||
|
redisUtil.saveByKey(AppRedisKey.DICT_TREE,list);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = {Exception.class})
|
@Transactional(rollbackFor = {Exception.class})
|
||||||
public boolean addDictTree(DictTreeParam dictTreeParam) {
|
public boolean addDictTree(DictTreeParam dictTreeParam) {
|
||||||
|
boolean result;
|
||||||
SysDicTreePO sysDicTreePO = new SysDicTreePO();
|
SysDicTreePO sysDicTreePO = new SysDicTreePO();
|
||||||
BeanUtils.copyProperties(dictTreeParam, sysDicTreePO);
|
BeanUtils.copyProperties(dictTreeParam, sysDicTreePO);
|
||||||
if (!Objects.equals(sysDicTreePO.getPid(), BizParamConstant.PARENT_ID)) {
|
if (!Objects.equals(sysDicTreePO.getPid(), BizParamConstant.PARENT_ID)) {
|
||||||
@@ -51,19 +66,32 @@ public class SysDicTreePOServiceImpl extends ServiceImpl<SysDicTreePOMapper, Sys
|
|||||||
sysDicTreePO.setPids(BizParamConstant.PARENT_ID);
|
sysDicTreePO.setPids(BizParamConstant.PARENT_ID);
|
||||||
}
|
}
|
||||||
sysDicTreePO.setStatus(0);
|
sysDicTreePO.setStatus(0);
|
||||||
return this.save(sysDicTreePO);
|
result = this.save(sysDicTreePO);
|
||||||
|
if (result) {
|
||||||
|
refreshDictTreeCache();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateDictTree(DictTreeParam dictTreeParam) {
|
public boolean updateDictTree(DictTreeParam dictTreeParam) {
|
||||||
|
boolean result;
|
||||||
SysDicTreePO sysDicTreePO = new SysDicTreePO();
|
SysDicTreePO sysDicTreePO = new SysDicTreePO();
|
||||||
BeanUtils.copyProperties(dictTreeParam, sysDicTreePO);
|
BeanUtils.copyProperties(dictTreeParam, sysDicTreePO);
|
||||||
return this.updateById(sysDicTreePO);
|
result = this.updateById(sysDicTreePO);
|
||||||
|
if (result) {
|
||||||
|
refreshDictTreeCache();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteDictTree(String id) {
|
public boolean deleteDictTree(String id) {
|
||||||
return this.lambdaUpdate().set(SysDicTreePO::getStatus, DicState.DELETE).in(SysDicTreePO::getId,id).update();
|
boolean result = this.lambdaUpdate().set(SysDicTreePO::getStatus, DicState.DELETE).in(SysDicTreePO::getId,id).update();
|
||||||
|
if (result) {
|
||||||
|
refreshDictTreeCache();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user