代码合并终
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
package com.njcn.system.component;
|
||||
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.enums.DicDataTypeEnum;
|
||||
import com.njcn.system.pojo.po.DictData;
|
||||
import com.njcn.system.service.IDictDataService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.njcn.system.pojo.constant.DicDataConstant.NAME_KEY;
|
||||
import static com.njcn.system.pojo.constant.DicDataConstant.SPLIT_SIGN;
|
||||
|
||||
/**
|
||||
* pqs
|
||||
*
|
||||
* @author cdf
|
||||
* @date 2023/2/6
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DictCacheRedis {
|
||||
|
||||
|
||||
|
||||
private @Autowired
|
||||
IDictDataService dictDataService;
|
||||
|
||||
private @Autowired
|
||||
RedisUtil redisUtil;
|
||||
private @Autowired
|
||||
RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
@PostConstruct
|
||||
public void init(){
|
||||
log.info("系统启动中。。。加载dictDataMap");
|
||||
/*todo 后续将字典表全部加载*/
|
||||
List<DictData> data = dictDataService.getDicDataByTypeCode (DicDataTypeEnum.LINE_STATE.getCode ( ));
|
||||
List<DictData> data2 = dictDataService.getDicDataByTypeCode (DicDataTypeEnum.DEV_STATUS.getCode ( ));
|
||||
List<DictData> data3 = dictDataService.getDicDataByTypeCode (DicDataTypeEnum.LINE_SORT.getCode ( ));
|
||||
|
||||
/*
|
||||
* key:NAME_KEY前缀(清缓存使用)+SPLIT_SIGN(拼接符号)+DicDataTypeEnum+SPLIT_SIGN(拼接符号)+Code
|
||||
* Value:id
|
||||
* */
|
||||
data.forEach (temp->{
|
||||
redisUtil.saveByKey (NAME_KEY+ SPLIT_SIGN+DicDataTypeEnum.LINE_STATE.getCode ( )+SPLIT_SIGN+temp.getCode (),temp.getId ());
|
||||
});
|
||||
|
||||
data2.forEach (temp->{
|
||||
redisUtil.saveByKey (NAME_KEY+SPLIT_SIGN+DicDataTypeEnum.DEV_STATUS.getCode ( )+SPLIT_SIGN+temp.getCode (),temp.getId ());
|
||||
});
|
||||
|
||||
data3.forEach (temp->{
|
||||
redisUtil.saveByKey (NAME_KEY+SPLIT_SIGN+DicDataTypeEnum.LINE_SORT.getCode ( )+SPLIT_SIGN+temp.getCode (),temp.getId ());
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void destroy(){
|
||||
log.info("系统运行结束");
|
||||
Set<String> keys = redisTemplate.keys(NAME_KEY + "*");
|
||||
|
||||
redisTemplate.delete(keys);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user