CacheContext.java 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. /**
  12. * 初始化缓存类
  13. */
  14. @Component
  15. public class CacheContext implements CommandLineRunner {
  16. @Autowired
  17. private IDataDictionaryService dataDictionaryService;
  18. @Autowired
  19. private IIndicatorTypeService iIndicatorTypeService;
  20. @Autowired
  21. private IBinSectionService binSectionService;
  22. @Autowired
  23. private IBinStageService binStageService;
  24. @Autowired
  25. private IOrganizationEvaluationRuleService organizationEvaluationRuleService;
  26. @Autowired
  27. private IMultipleBrandService multipleBrandService;
  28. /**
  29. * 单位营业收入配置列表
  30. */
  31. public static Map<String, MultipleBrand> brandMap = new HashMap<>();
  32. /**
  33. * brandMap列表根据考评周期和具体年月分组
  34. */
  35. public static Map<String, Map<String, MultipleBrand>> groupBrandMap = new HashMap<>();
  36. public static final Map<String, String> childCompanyId = new LinkedHashMap<>();
  37. //初始化字典表
  38. public static List<DataDictionary> ddList = new ArrayList<>();
  39. public static Map<String, DataDictionary> ddMap = new HashMap<>();
  40. public static Map<String, String> ddNameMap = new HashMap<>();
  41. public static Map<String, String> ddValueMap = new HashMap<>();
  42. public static Map<String, List<DataDictionary>> ddSuperKeyMap = new HashMap<>();
  43. //指标分类
  44. public static List<IndicatorType> itList = new ArrayList<>();
  45. //经营阶段分类
  46. public static List<BinStage> bseList = new ArrayList<>();
  47. public static Map<String, String> bseIdMap = new HashMap<>();
  48. public static Map<String, BinStage> bseIdObject = new HashMap<>();
  49. public static Map<String, BinStage> bseCodeObject = new HashMap<>();
  50. //生产经营业务分类
  51. public static List<BinSection> bsnList = new ArrayList<>();
  52. public static Map<String, BinSection> bsnIdObject = new HashMap<>();
  53. public static Map<String, BinSection> bsnCodeObject = new HashMap<>();
  54. public static Map<String, String> bsnIdName = new HashMap<>();
  55. //权重
  56. public static Map<String, List<OrganizationEvaluationRule>> ruleMap = new HashMap();
  57. public static List<OrganizationEvaluationRule> ruleList = new ArrayList<>();
  58. @Override
  59. public void run(String... args) throws Exception {
  60. initDataDictionary();
  61. initIndicatorType();
  62. initBinStage();
  63. initBinSection();
  64. initOrganizationEvaluationRule();
  65. initTree();
  66. initTree2();
  67. }
  68. private void initTree() {
  69. //按照单位营业收入配置
  70. IPage<MultipleBrand> tree = multipleBrandService.getMultipleBranTree(1, 1000, null, null, "", "", "", null);
  71. List<MultipleBrand> records = tree.getRecords();
  72. for (MultipleBrand record : records) {
  73. brandMap.put(record.getOrganizationId(), record);
  74. if (record.getChildren() == null) continue;
  75. for (MultipleBrand child : record.getChildren()) {
  76. brandMap.put(child.getOrganizationId(), child);
  77. }
  78. }
  79. }
  80. private void initTree2() {
  81. //按照单位营业收入配置
  82. IPage<MultipleBrand> tree = multipleBrandService.getMultipleBranTree(1, 1000, null, null, "", "", "", null);
  83. List<MultipleBrand> records = tree.getRecords();
  84. Map<String, List<MultipleBrand>> collect = records.stream().peek(mb -> {
  85. if ("NDKP".equals(mb.getCheckCycle())) {
  86. mb.setCheckCycle(mb.getCheckCycle() + "_" + mb.getYear() + "_" + mb.getMonth());
  87. } else {
  88. mb.setCheckCycle(mb.getCheckCycle() + "_" + mb.getYear() + "_" + mb.getMonth());
  89. }
  90. }).collect(Collectors.groupingBy(MultipleBrand::getCheckCycle));
  91. for (Map.Entry<String, List<MultipleBrand>> entry : collect.entrySet()) {
  92. Map<String, MultipleBrand> aaa = new HashMap<>();
  93. for (MultipleBrand record : entry.getValue()) {
  94. aaa.put(record.getOrganizationId(), record);
  95. if (record.getChildren() == null) {
  96. continue;
  97. }
  98. for (MultipleBrand child : record.getChildren()) {
  99. aaa.put(child.getOrganizationId(), child);
  100. }
  101. }
  102. groupBrandMap.put(entry.getKey(), aaa);
  103. }
  104. }
  105. public static Set<String> getChildList(String id, String orgCode) {
  106. Set<String> zgs = new HashSet<>();
  107. zgs.add(id);
  108. Map<String, MultipleBrand> stringMultipleBrandMap = groupBrandMap.get(orgCode);
  109. if (stringMultipleBrandMap == null) return zgs;
  110. MultipleBrand brand = stringMultipleBrandMap.get(id);
  111. if (brand == null) {
  112. return zgs;
  113. }
  114. Map<String, MultipleBrand> coll = brandMap.values().stream().filter(bm -> bm.getChildren() != null).collect(Collectors.toMap(MultipleBrand::getOrganizationId, Function.identity()));
  115. List<String> parentId = coll.values().stream().filter(bm -> id.equals(bm.getChildren().get(0).getOrganizationId())).map(MultipleBrand::getOrganizationId).collect(Collectors.toList());
  116. zgs.addAll(parentId);
  117. if (brand.getChildren() == null) return zgs;
  118. for (MultipleBrand child : brand.getChildren()) {
  119. zgs.add(child.getOrganizationId());
  120. }
  121. return zgs;
  122. }
  123. /**
  124. * 初始化数据字典表
  125. */
  126. public void initDataDictionary() {
  127. //清理集合中的数据
  128. ddList.clear();
  129. ddMap.clear();
  130. ddNameMap.clear();
  131. ddValueMap.clear();
  132. ddSuperKeyMap.clear();
  133. //重新加载集合数据
  134. ddList = dataDictionaryService.list();
  135. ddList.stream().forEach(d -> {
  136. ddMap.put(d.getDataKey(), d);
  137. ddNameMap.put(d.getDataKey(), d.getKeyName());
  138. ddValueMap.put(d.getDataKey(), d.getKeyValue());
  139. });
  140. ddSuperKeyMap = ddList.stream().collect(Collectors.groupingBy(DataDictionary::getSuperKey));
  141. }
  142. /**
  143. * 初始化指标分类
  144. */
  145. public void initIndicatorType() {
  146. //清理集合中的数据
  147. itList.clear();
  148. itList = iIndicatorTypeService.list().stream().filter(t -> !t.getDelFlag()).collect(Collectors.toList());
  149. itList.sort(Comparator.comparing(IndicatorType::getOrderNum));
  150. }
  151. /**
  152. * 初始化经营阶段分类
  153. */
  154. public void initBinStage() {
  155. //清理集合中的数据
  156. bseList.clear();
  157. bseIdMap.clear();
  158. bseIdObject.clear();
  159. bseCodeObject.clear();
  160. bseList = binStageService.list().stream().filter(t -> !t.getDelFlag()).collect(Collectors.toList());
  161. bseList.sort(Comparator.comparing(BinStage::getOrderNum));
  162. bseList.stream().forEach(d -> {
  163. bseIdMap.put(d.getId(), d.getStageName());
  164. bseIdObject.put(d.getId(), d);
  165. bseCodeObject.put(d.getStageCode(), d);
  166. });
  167. }
  168. /**
  169. * 初始化生产经营业务分类
  170. */
  171. public void initBinSection() {
  172. //清理集合中的数据
  173. bsnList.clear();
  174. bsnIdObject.clear();
  175. bsnCodeObject.clear();
  176. bsnList = binSectionService.list().stream().filter(t -> !t.getDelFlag()).collect(Collectors.toList());
  177. bsnList.sort(Comparator.comparing(BinSection::getOrderNum));
  178. bsnList.stream().forEach(d -> {
  179. bsnIdObject.put(d.getId(), d);
  180. });
  181. bsnList.stream().forEach(d -> {
  182. bsnCodeObject.put(d.getSectionCode(), d);
  183. bsnIdName.put(d.getId(), d.getSectionName());
  184. });
  185. }
  186. public void initOrganizationEvaluationRule() {
  187. ruleList.clear();
  188. ruleMap.clear();
  189. ruleList = organizationEvaluationRuleService.list();
  190. if (ruleList != null) {
  191. ruleList = ruleList.stream().filter(t -> t != null && !t.getDelFlag() && t.getIsCheck()).collect(Collectors.toList());
  192. ruleMap = ruleList.stream().collect(Collectors.groupingBy(OrganizationEvaluationRule::getOrganizationId));
  193. }
  194. }
  195. }