CacheContext.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. package com.ims.eval.cache;
  2. import com.ims.eval.entity.*;
  3. import com.ims.eval.service.*;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.boot.CommandLineRunner;
  6. import org.springframework.stereotype.Component;
  7. import java.util.*;
  8. import java.util.stream.Collectors;
  9. /**
  10. * 初始化缓存类
  11. */
  12. @Component
  13. public class CacheContext implements CommandLineRunner {
  14. @Autowired
  15. private IDataDictionaryService dataDictionaryService;
  16. @Autowired
  17. private IIndicatorTypeService iIndicatorTypeService;
  18. @Autowired
  19. private IBinSectionService binSectionService;
  20. @Autowired
  21. private IBinStageService binStageService;
  22. @Autowired
  23. private IOrganizationEvaluationRuleService organizationEvaluationRuleService;
  24. //初始化字典表
  25. public static List<DataDictionary> ddList = new ArrayList<>();
  26. public static Map<String, DataDictionary> ddMap = new HashMap<>();
  27. public static Map<String, String> ddNameMap = new HashMap<>();
  28. public static Map<String, String> ddValueMap = new HashMap<>();
  29. public static Map<String, List<DataDictionary>> ddSuperKeyMap = new HashMap<>();
  30. //指标分类
  31. public static List<IndicatorType> itList = new ArrayList<>();
  32. //经营阶段分类
  33. public static List<BinStage> bseList = new ArrayList<>();
  34. public static Map<String, String> bseIdMap = new HashMap<>();
  35. public static Map<String, BinStage> bseIdObject = new HashMap<>();
  36. public static Map<String, BinStage> bseCodeObject = new HashMap<>();
  37. //生产经营业务分类
  38. public static List<BinSection> bsnList = new ArrayList<>();
  39. public static Map<String, BinSection> bsnIdObject = new HashMap<>();
  40. public static Map<String, BinSection> bsnCodeObject = new HashMap<>();
  41. public static Map<String, String> bsnIdName = new HashMap<>();
  42. //权重
  43. public static Map<String, List<OrganizationEvaluationRule>> ruleMap = new HashMap();
  44. public static List<OrganizationEvaluationRule> ruleList = new ArrayList<>();
  45. @Override
  46. public void run(String... args) throws Exception {
  47. initDataDictionary();
  48. initIndicatorType();
  49. initBinStage();
  50. initBinSection();
  51. initOrganizationEvaluationRule();
  52. }
  53. /**
  54. * 初始化数据字典表
  55. */
  56. public void initDataDictionary(){
  57. //清理集合中的数据
  58. ddList.clear();
  59. ddMap.clear();
  60. ddNameMap.clear();
  61. ddValueMap.clear();
  62. ddSuperKeyMap.clear();
  63. //重新加载集合数据
  64. ddList = dataDictionaryService.list();
  65. ddList.stream().forEach(d -> {
  66. ddMap.put(d.getDataKey(), d);
  67. ddNameMap.put(d.getDataKey(), d.getKeyName());
  68. ddValueMap.put(d.getDataKey(), d.getKeyValue());
  69. });
  70. ddSuperKeyMap = ddList.stream().collect(Collectors.groupingBy(DataDictionary::getSuperKey));
  71. }
  72. /**
  73. * 初始化指标分类
  74. */
  75. public void initIndicatorType(){
  76. //清理集合中的数据
  77. itList.clear();
  78. itList = iIndicatorTypeService.list().stream().filter(t->!t.getDelFlag()).collect(Collectors.toList());
  79. itList.sort(Comparator.comparing(IndicatorType::getOrderNum));
  80. }
  81. /**
  82. * 初始化经营阶段分类
  83. */
  84. public void initBinStage(){
  85. //清理集合中的数据
  86. bseList.clear();
  87. bseIdMap.clear();
  88. bseIdObject.clear();
  89. bseCodeObject.clear();
  90. bseList = binStageService.list().stream().filter(t->!t.getDelFlag()).collect(Collectors.toList());
  91. bseList.sort(Comparator.comparing(BinStage::getOrderNum));
  92. bseList.stream().forEach(d -> {
  93. bseIdMap.put(d.getId(), d.getStageName());
  94. bseIdObject.put(d.getId(), d);
  95. bseCodeObject.put(d.getStageCode(), d);
  96. });
  97. }
  98. /**
  99. * 初始化生产经营业务分类
  100. */
  101. public void initBinSection(){
  102. //清理集合中的数据
  103. bsnList.clear();
  104. bsnIdObject.clear();
  105. bsnCodeObject.clear();
  106. bsnList = binSectionService.list().stream().filter(t->!t.getDelFlag()).collect(Collectors.toList());
  107. bsnList.sort(Comparator.comparing(BinSection::getOrderNum));
  108. bsnList.stream().forEach(d -> {
  109. bsnIdObject.put(d.getId(), d);
  110. });
  111. bsnList.stream().forEach(d -> {
  112. bsnCodeObject.put(d.getSectionCode(), d);
  113. bsnIdName.put(d.getId(), d.getSectionName());
  114. });
  115. }
  116. public void initOrganizationEvaluationRule(){
  117. ruleList.clear();
  118. ruleMap.clear();
  119. ruleList = organizationEvaluationRuleService.list();
  120. ruleList = ruleList.stream().filter(t->!t.getDelFlag() && t.getIsCheck()).collect(Collectors.toList());
  121. ruleMap = ruleList.stream().collect(Collectors.groupingBy(OrganizationEvaluationRule::getOrganizationId));
  122. }
  123. }