123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- package com.ims.eval.cache;
- import com.ims.eval.entity.BinSection;
- import com.ims.eval.entity.BinStage;
- import com.ims.eval.entity.DataDictionary;
- import com.ims.eval.entity.IndicatorType;
- import com.ims.eval.service.IBinSectionService;
- import com.ims.eval.service.IBinStageService;
- import com.ims.eval.service.IDataDictionaryService;
- import com.ims.eval.service.IIndicatorTypeService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.boot.CommandLineRunner;
- import org.springframework.stereotype.Component;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * 初始化缓存类
- */
- @Component
- public class CacheContext implements CommandLineRunner {
- @Autowired
- private IDataDictionaryService dataDictionaryService;
- @Autowired
- private IIndicatorTypeService iIndicatorTypeService;
- @Autowired
- private IBinSectionService binSectionService;
- @Autowired
- private IBinStageService binStageService;
- //初始化字典表
- public static List<DataDictionary> ddList = new ArrayList<>();
- public static Map<String, DataDictionary> ddMap = new HashMap<>();
- public static Map<String, String> ddNameMap = new HashMap<>();
- public static Map<String, String> ddValueMap = new HashMap<>();
- public static Map<String, List<DataDictionary>> ddSuperKeyMap = new HashMap<>();
- //指标分类
- public static List<IndicatorType> itList = new ArrayList<>();
- //经营阶段分类
- public static List<BinStage> bseList = new ArrayList<>();
- public static Map<String, String> bseIdMap = new HashMap<>();
- //生产经营业务分类
- public static List<BinSection> bsnList = new ArrayList<>();
- public static Map<String, BinSection> bsnIdObject = new HashMap<>();
- @Override
- public void run(String... args) throws Exception {
- initDataDictionary();
- initIndicatorType();
- initBinStage();
- initBinSection();
- }
- /**
- * 初始化数据字典表
- */
- public void initDataDictionary(){
- //清理集合中的数据
- ddList.clear();
- ddMap.clear();
- ddNameMap.clear();
- ddValueMap.clear();
- ddSuperKeyMap.clear();
- //重新加载集合数据
- ddList = dataDictionaryService.list();
- ddList.stream().forEach(d -> {
- ddMap.put(d.getDataKey(), d);
- ddNameMap.put(d.getDataKey(), d.getKeyName());
- ddValueMap.put(d.getDataKey(), d.getKeyValue());
- });
- ddSuperKeyMap = ddList.stream().collect(Collectors.groupingBy(DataDictionary::getSuperKey));
- }
- /**
- * 初始化指标分类
- */
- public void initIndicatorType(){
- //清理集合中的数据
- itList.clear();
- itList = iIndicatorTypeService.list().stream().filter(t->!t.getDelFlag()).collect(Collectors.toList());
- itList.sort(Comparator.comparing(IndicatorType::getOrderNum));
- }
- /**
- * 初始化经营阶段分类
- */
- public void initBinStage(){
- //清理集合中的数据
- bseList.clear();
- bseIdMap.clear();
- bseList = binStageService.list().stream().filter(t->!t.getDelFlag()).collect(Collectors.toList());
- bseList.sort(Comparator.comparing(BinStage::getOrderNum));
- bseList.stream().forEach(d -> {
- bseIdMap.put(d.getId(), d.getStageName());
- });
- }
- /**
- * 初始化生产经营业务分类
- */
- public void initBinSection(){
- //清理集合中的数据
- bsnList.clear();
- bsnList = binSectionService.list().stream().filter(t->!t.getDelFlag()).collect(Collectors.toList());
- bsnList.sort(Comparator.comparing(BinSection::getOrderNum));
- bsnList.stream().forEach(d -> {
- bsnIdObject.put(d.getId(), d);
- });
- }
- }
|