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 brandMap = new HashMap<>(); //按单位营业收入配置 public static Map brandMap = new HashMap<>(); // public static final ThreadLocal> childCompany = new ThreadLocal<>(); 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(); } 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); } } /* //按照公司 List loss = organizationStructureService.getList2(null, null, null); brandMap = loss.stream().collect(Collectors.toMap(OrganizationStructure::getId, Function.identity()));*/ } public static List getChildList(String id) { MultipleBrand brand = brandMap.get(id); List zgs = new ArrayList<>(); if (brand==null){ return zgs; } zgs.add(brand.getOrganizationId()); 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()) { List childList = getChildList(child.getOrganizationId()); zgs.addAll(childList); } return zgs; /* //按公司 List ids = new ArrayList<>(); ids.add(id); List 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)); } }