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; /** * 初始化缓存类 */ @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 brandMap = new HashMap<>(); /** * brandMap列表根据考评周期和具体年月分组 */ public static Map> groupBrandMap = new HashMap<>(); public static final Map childCompanyId = new LinkedHashMap<>(); //初始化字典表 public static List ddList = new ArrayList<>(); public static Map ddMap = new HashMap<>(); public static Map ddNameMap = new HashMap<>(); public static Map ddValueMap = new HashMap<>(); public static Map> ddSuperKeyMap = new HashMap<>(); //指标分类 public static List itList = new ArrayList<>(); //经营阶段分类 public static List bseList = new ArrayList<>(); public static Map bseIdMap = new HashMap<>(); public static Map bseIdObject = new HashMap<>(); public static Map bseCodeObject = new HashMap<>(); //生产经营业务分类 public static List bsnList = new ArrayList<>(); public static Map bsnIdObject = new HashMap<>(); public static Map bsnCodeObject = new HashMap<>(); public static Map bsnIdName = new HashMap<>(); //权重 public static Map> ruleMap = new HashMap(); public static List ruleList = new ArrayList<>(); @Override public void run(String... args) throws Exception { initDataDictionary(); initIndicatorType(); initBinStage(); initBinSection(); initOrganizationEvaluationRule(); initTree(); initTree2(); } private void initTree() { //按照单位营业收入配置 IPage tree = multipleBrandService.getMultipleBranTree(1, 1000, null, null, "", "", "", null); List 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); } } } private void initTree2() { //按照单位营业收入配置 IPage tree = multipleBrandService.getMultipleBranTree(1, 1000, null, null, "", "", "", null); List records = tree.getRecords(); Map> collect = records.stream().peek(mb -> { if ("NDKP".equals(mb.getCheckCycle())) { mb.setCheckCycle(mb.getCheckCycle() + "_" + mb.getYear() + "_" + mb.getMonth()); } else { mb.setCheckCycle(mb.getCheckCycle() + "_" + mb.getYear() + "_" + mb.getMonth()); } }).collect(Collectors.groupingBy(MultipleBrand::getCheckCycle)); for (Map.Entry> entry : collect.entrySet()) { Map aaa = new HashMap<>(); for (MultipleBrand record : entry.getValue()) { aaa.put(record.getOrganizationId(), record); if (record.getChildren() == null) { continue; } for (MultipleBrand child : record.getChildren()) { aaa.put(child.getOrganizationId(), child); } } groupBrandMap.put(entry.getKey(), aaa); } } public static Set getChildList(String id, String orgCode) { Set zgs = new HashSet<>(); zgs.add(id); Map stringMultipleBrandMap = groupBrandMap.get(orgCode); if (stringMultipleBrandMap == null) return zgs; MultipleBrand brand = stringMultipleBrandMap.get(id); if (brand == null) { return zgs; } Map coll = brandMap.values().stream().filter(bm -> bm.getChildren() != null).collect(Collectors.toMap(MultipleBrand::getOrganizationId, Function.identity())); List 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()) { zgs.add(child.getOrganizationId()); } return zgs; } /** * 初始化数据字典表 */ 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(); if (ruleList != null) { ruleList = ruleList.stream().filter(t -> t != null && !t.getDelFlag() && t.getIsCheck()).collect(Collectors.toList()); ruleMap = ruleList.stream().collect(Collectors.groupingBy(OrganizationEvaluationRule::getOrganizationId)); } } }