CacheContext.java 3.4 KB

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