初始化字典数据至内存
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,10 @@ import java.util.List;
|
||||
*/
|
||||
public interface SysDicTreePOService extends IService<SysDicTreePO> {
|
||||
|
||||
/**
|
||||
* 初始化缓存设备树
|
||||
*/
|
||||
void refreshDictTreeCache();
|
||||
|
||||
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.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<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
|
||||
@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<SysDicTreePOMapper, Sys
|
||||
sysDicTreePO.setPids(BizParamConstant.PARENT_ID);
|
||||
}
|
||||
sysDicTreePO.setStatus(0);
|
||||
return this.save(sysDicTreePO);
|
||||
result = this.save(sysDicTreePO);
|
||||
if (result) {
|
||||
refreshDictTreeCache();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateDictTree(DictTreeParam dictTreeParam) {
|
||||
boolean result;
|
||||
SysDicTreePO sysDicTreePO = new SysDicTreePO();
|
||||
BeanUtils.copyProperties(dictTreeParam, sysDicTreePO);
|
||||
return this.updateById(sysDicTreePO);
|
||||
result = this.updateById(sysDicTreePO);
|
||||
if (result) {
|
||||
refreshDictTreeCache();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user