123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- package com.ims.eval.cache;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.ims.eval.entity.*;
- import com.ims.eval.service.*;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.boot.CommandLineRunner;
- import org.springframework.stereotype.Component;
- import java.util.*;
- import java.util.function.Function;
- import java.util.stream.Collectors;
- import java.util.stream.Stream;
- /**
- * 初始化缓存类
- */
- @Component
- public class CacheContext implements CommandLineRunner {
- @Autowired
- private IDataDictionaryService dataDictionaryService;
- @Autowired
- private IIndicatorTypeService iIndicatorTypeService;
- @Autowired
- private IBinSectionService binSectionService;
- @Autowired
- private IBinStageService binStageService;
- @Autowired
- private IOrganizationEvaluationRuleService organizationEvaluationRuleService;
- @Autowired
- private IMultipleBrandService multipleBrandService;
- //按公司
- //public static Map<String, OrganizationStructure> brandMap = new HashMap<>();
- //按单位营业收入配置
- public static Map<String, MultipleBrand> brandMap = new HashMap<>();
- // public static final ThreadLocal<List<String>> childCompany = new ThreadLocal<>();
- public static final Map<String, String> childCompanyId = new LinkedHashMap<>();
- //初始化字典表
- 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 Map<String, BinStage> bseIdObject = new HashMap<>();
- public static Map<String, BinStage> bseCodeObject = new HashMap<>();
- //生产经营业务分类
- public static List<BinSection> bsnList = new ArrayList<>();
- public static Map<String, BinSection> bsnIdObject = new HashMap<>();
- public static Map<String, BinSection> bsnCodeObject = new HashMap<>();
- public static Map<String, String> bsnIdName = new HashMap<>();
- //权重
- public static Map<String, List<OrganizationEvaluationRule>> ruleMap = new HashMap();
- public static List<OrganizationEvaluationRule> ruleList = new ArrayList<>();
- @Override
- public void run(String... args) throws Exception {
- initDataDictionary();
- initIndicatorType();
- initBinStage();
- initBinSection();
- initOrganizationEvaluationRule();
- initTree();
- }
- private void initTree() {
- //按照单位营业收入配置
- IPage<MultipleBrand> tree = multipleBrandService.getMultipleBranTree(1, 1000, null, null, "", "", "", null);
- List<MultipleBrand> records = tree.getRecords();
- for (MultipleBrand record : records) {
- brandMap.put(record.getOrganizationId(), record);
- if (record.getChildren()==null) continue;
- for (MultipleBrand child : record.getChildren()) {
- brandMap.put(child.getOrganizationId(), child);
- }
- }
- /*
- //按照公司
- List<OrganizationStructure> loss = organizationStructureService.getList2(null, null, null);
- brandMap = loss.stream().collect(Collectors.toMap(OrganizationStructure::getId, Function.identity()));*/
- }
- public static List<String> getChildList(String id) {
- MultipleBrand brand = brandMap.get(id);
- List<String> zgs = new ArrayList<>();
- if (brand==null){
- return zgs;
- }
- zgs.add(brand.getOrganizationId());
- Map<String, MultipleBrand> coll = brandMap.values().stream().filter(bm -> bm.getChildren() != null).collect(Collectors.toMap(MultipleBrand::getOrganizationId, Function.identity()));
- List<String> parentId = coll.values().stream().filter(bm -> id.equals(bm.getChildren().get(0).getOrganizationId())).map(MultipleBrand::getOrganizationId).collect(Collectors.toList());
- zgs.addAll(parentId);
- if(brand.getChildren() == null) return zgs;
- for (MultipleBrand child : brand.getChildren()) {
- List<String> childList = getChildList(child.getOrganizationId());
- zgs.addAll(childList);
- }
- return zgs;
- /*
- //按公司
- List<String> ids = new ArrayList<>();
- ids.add(id);
- List<String> collects = brandMap.values().stream().filter(i -> id.equals(i.getParentId())).map(OrganizationStructure::getId).collect(Collectors.toList());
- ids.addAll(collects);
- return ids;*/
- }
- /**
- * 初始化数据字典表
- */
- 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();
- bseIdObject.clear();
- bseCodeObject.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());
- bseIdObject.put(d.getId(), d);
- bseCodeObject.put(d.getStageCode(), d);
- });
- }
- /**
- * 初始化生产经营业务分类
- */
- public void initBinSection() {
- //清理集合中的数据
- bsnList.clear();
- bsnIdObject.clear();
- bsnCodeObject.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);
- });
- bsnList.stream().forEach(d -> {
- bsnCodeObject.put(d.getSectionCode(), d);
- bsnIdName.put(d.getId(), d.getSectionName());
- });
- }
- public void initOrganizationEvaluationRule() {
- ruleList.clear();
- ruleMap.clear();
- ruleList = organizationEvaluationRuleService.list();
- ruleList = ruleList.stream().filter(t -> !t.getDelFlag() && t.getIsCheck()).collect(Collectors.toList());
- ruleMap = ruleList.stream().collect(Collectors.groupingBy(OrganizationEvaluationRule::getOrganizationId));
- }
- }
|