123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- 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<String, MultipleBrand> brandMap = new HashMap<>();
- /**
- * brandMap列表根据考评周期和具体年月分组
- */
- public static Map<String, Map<String, MultipleBrand>> groupBrandMap = new HashMap<>();
- 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();
- initTree2();
- }
- 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);
- }
- }
- }
- private void initTree2() {
- //按照单位营业收入配置
- IPage<MultipleBrand> tree = multipleBrandService.getMultipleBranTree(1, 1000, null, null, "", "", "", null);
- List<MultipleBrand> records = tree.getRecords();
- Map<String, List<MultipleBrand>> 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<String, List<MultipleBrand>> entry : collect.entrySet()) {
- Map<String, MultipleBrand> 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<String> getChildList(String id, String orgCode) {
- Set<String> zgs = new HashSet<>();
- zgs.add(id);
- Map<String, MultipleBrand> stringMultipleBrandMap = groupBrandMap.get(orgCode);
- if (stringMultipleBrandMap == null) return zgs;
- MultipleBrand brand = stringMultipleBrandMap.get(id);
- if (brand == null) {
- return zgs;
- }
- 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()) {
- 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));
- }
- }
- }
|