CacheContext.java 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. package com.ims.eval.cache;
  2. import com.baomidou.mybatisplus.core.metadata.IPage;
  3. import com.ims.eval.entity.*;
  4. import com.ims.eval.service.*;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.boot.CommandLineRunner;
  7. import org.springframework.stereotype.Component;
  8. import java.util.*;
  9. import java.util.function.Function;
  10. import java.util.stream.Collectors;
  11. import java.util.stream.Stream;
  12. /**
  13. * 初始化缓存类
  14. */
  15. @Component
  16. public class CacheContext implements CommandLineRunner {
  17. @Autowired
  18. private IDataDictionaryService dataDictionaryService;
  19. @Autowired
  20. private IIndicatorTypeService iIndicatorTypeService;
  21. @Autowired
  22. private IBinSectionService binSectionService;
  23. @Autowired
  24. private IBinStageService binStageService;
  25. @Autowired
  26. private IOrganizationEvaluationRuleService organizationEvaluationRuleService;
  27. @Autowired
  28. private IMultipleBrandService multipleBrandService;
  29. //按公司
  30. //public static Map<String, OrganizationStructure> brandMap = new HashMap<>();
  31. //按单位营业收入配置
  32. public static Map<String, MultipleBrand> brandMap = new HashMap<>();
  33. // public static final ThreadLocal<List<String>> childCompany = new ThreadLocal<>();
  34. public static final Map<String, String> childCompanyId = new LinkedHashMap<>();
  35. //初始化字典表
  36. public static List<DataDictionary> ddList = new ArrayList<>();
  37. public static Map<String, DataDictionary> ddMap = new HashMap<>();
  38. public static Map<String, String> ddNameMap = new HashMap<>();
  39. public static Map<String, String> ddValueMap = new HashMap<>();
  40. public static Map<String, List<DataDictionary>> ddSuperKeyMap = new HashMap<>();
  41. //指标分类
  42. public static List<IndicatorType> itList = new ArrayList<>();
  43. //经营阶段分类
  44. public static List<BinStage> bseList = new ArrayList<>();
  45. public static Map<String, String> bseIdMap = new HashMap<>();
  46. public static Map<String, BinStage> bseIdObject = new HashMap<>();
  47. public static Map<String, BinStage> bseCodeObject = new HashMap<>();
  48. //生产经营业务分类
  49. public static List<BinSection> bsnList = new ArrayList<>();
  50. public static Map<String, BinSection> bsnIdObject = new HashMap<>();
  51. public static Map<String, BinSection> bsnCodeObject = new HashMap<>();
  52. public static Map<String, String> bsnIdName = new HashMap<>();
  53. //权重
  54. public static Map<String, List<OrganizationEvaluationRule>> ruleMap = new HashMap();
  55. public static List<OrganizationEvaluationRule> ruleList = new ArrayList<>();
  56. @Override
  57. public void run(String... args) throws Exception {
  58. initDataDictionary();
  59. initIndicatorType();
  60. initBinStage();
  61. initBinSection();
  62. initOrganizationEvaluationRule();
  63. initTree();
  64. }
  65. private void initTree() {
  66. //按照单位营业收入配置
  67. IPage<MultipleBrand> tree = multipleBrandService.getMultipleBranTree(1, 1000, null, null, "", "", "", null);
  68. List<MultipleBrand> records = tree.getRecords();
  69. for (MultipleBrand record : records) {
  70. brandMap.put(record.getOrganizationId(), record);
  71. if (record.getChildren()==null) continue;
  72. for (MultipleBrand child : record.getChildren()) {
  73. brandMap.put(child.getOrganizationId(), child);
  74. }
  75. }
  76. /*
  77. //按照公司
  78. List<OrganizationStructure> loss = organizationStructureService.getList2(null, null, null);
  79. brandMap = loss.stream().collect(Collectors.toMap(OrganizationStructure::getId, Function.identity()));*/
  80. }
  81. public static List<String> getChildList(String id) {
  82. MultipleBrand brand = brandMap.get(id);
  83. List<String> zgs = new ArrayList<>();
  84. if (brand==null){
  85. return zgs;
  86. }
  87. zgs.add(brand.getOrganizationId());
  88. Map<String, MultipleBrand> coll = brandMap.values().stream().filter(bm -> bm.getChildren() != null).collect(Collectors.toMap(MultipleBrand::getOrganizationId, Function.identity()));
  89. List<String> parentId = coll.values().stream().filter(bm -> id.equals(bm.getChildren().get(0).getOrganizationId())).map(MultipleBrand::getOrganizationId).collect(Collectors.toList());
  90. zgs.addAll(parentId);
  91. if(brand.getChildren() == null) return zgs;
  92. for (MultipleBrand child : brand.getChildren()) {
  93. List<String> childList = getChildList(child.getOrganizationId());
  94. zgs.addAll(childList);
  95. }
  96. return zgs;
  97. /*
  98. //按公司
  99. List<String> ids = new ArrayList<>();
  100. ids.add(id);
  101. List<String> collects = brandMap.values().stream().filter(i -> id.equals(i.getParentId())).map(OrganizationStructure::getId).collect(Collectors.toList());
  102. ids.addAll(collects);
  103. return ids;*/
  104. }
  105. /**
  106. * 初始化数据字典表
  107. */
  108. public void initDataDictionary() {
  109. //清理集合中的数据
  110. ddList.clear();
  111. ddMap.clear();
  112. ddNameMap.clear();
  113. ddValueMap.clear();
  114. ddSuperKeyMap.clear();
  115. //重新加载集合数据
  116. ddList = dataDictionaryService.list();
  117. ddList.stream().forEach(d -> {
  118. ddMap.put(d.getDataKey(), d);
  119. ddNameMap.put(d.getDataKey(), d.getKeyName());
  120. ddValueMap.put(d.getDataKey(), d.getKeyValue());
  121. });
  122. ddSuperKeyMap = ddList.stream().collect(Collectors.groupingBy(DataDictionary::getSuperKey));
  123. }
  124. /**
  125. * 初始化指标分类
  126. */
  127. public void initIndicatorType() {
  128. //清理集合中的数据
  129. itList.clear();
  130. itList = iIndicatorTypeService.list().stream().filter(t -> !t.getDelFlag()).collect(Collectors.toList());
  131. itList.sort(Comparator.comparing(IndicatorType::getOrderNum));
  132. }
  133. /**
  134. * 初始化经营阶段分类
  135. */
  136. public void initBinStage() {
  137. //清理集合中的数据
  138. bseList.clear();
  139. bseIdMap.clear();
  140. bseIdObject.clear();
  141. bseCodeObject.clear();
  142. bseList = binStageService.list().stream().filter(t -> !t.getDelFlag()).collect(Collectors.toList());
  143. bseList.sort(Comparator.comparing(BinStage::getOrderNum));
  144. bseList.stream().forEach(d -> {
  145. bseIdMap.put(d.getId(), d.getStageName());
  146. bseIdObject.put(d.getId(), d);
  147. bseCodeObject.put(d.getStageCode(), d);
  148. });
  149. }
  150. /**
  151. * 初始化生产经营业务分类
  152. */
  153. public void initBinSection() {
  154. //清理集合中的数据
  155. bsnList.clear();
  156. bsnIdObject.clear();
  157. bsnCodeObject.clear();
  158. bsnList = binSectionService.list().stream().filter(t -> !t.getDelFlag()).collect(Collectors.toList());
  159. bsnList.sort(Comparator.comparing(BinSection::getOrderNum));
  160. bsnList.stream().forEach(d -> {
  161. bsnIdObject.put(d.getId(), d);
  162. });
  163. bsnList.stream().forEach(d -> {
  164. bsnCodeObject.put(d.getSectionCode(), d);
  165. bsnIdName.put(d.getId(), d.getSectionName());
  166. });
  167. }
  168. public void initOrganizationEvaluationRule() {
  169. ruleList.clear();
  170. ruleMap.clear();
  171. ruleList = organizationEvaluationRuleService.list();
  172. ruleList = ruleList.stream().filter(t -> !t.getDelFlag() && t.getIsCheck()).collect(Collectors.toList());
  173. ruleMap = ruleList.stream().collect(Collectors.groupingBy(OrganizationEvaluationRule::getOrganizationId));
  174. }
  175. }