CacheContext.java 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. package com.gyee.failurestatistics.init;
  2. import com.gyee.failurestatistics.model.auto.*;
  3. import com.gyee.failurestatistics.service.HealthpointsService;
  4. import com.gyee.failurestatistics.service.auto.*;
  5. import org.slf4j.Logger;
  6. import org.slf4j.LoggerFactory;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.boot.CommandLineRunner;
  9. import org.springframework.stereotype.Component;
  10. import javax.annotation.Resource;
  11. import java.util.ArrayList;
  12. import java.util.HashMap;
  13. import java.util.List;
  14. import java.util.Map;
  15. /**
  16. * @ClassName : CacheContext
  17. * @Author : xieshengjie
  18. * @Date: 2021/9/29 17:33
  19. * @Description : 初始化
  20. */
  21. @Component
  22. public class CacheContext implements CommandLineRunner {
  23. private static final Logger log = LoggerFactory.getLogger(CacheContext.class);
  24. @Autowired
  25. private IWindturbineService windturbineService;
  26. @Autowired
  27. private IWindpowerstationService windpowerstationService;
  28. @Autowired
  29. private IProjectService projectService;
  30. @Autowired
  31. private ILineService lineService;
  32. @Autowired
  33. private IEquipmentmodelService equipmentmodelService;
  34. @Autowired
  35. private IWindturbinetestingpointnewService windturbinetestingpointnewService;
  36. @Autowired
  37. private IWindpowerstationpointnewService windpowerstationpointnewService;
  38. @Resource
  39. private HealthpointsService healthpointsService;
  40. public static Map<String, Windturbine> wtmap = new HashMap<String, Windturbine>(); // 风电机MAP
  41. public static Map<String, Healthpoint> hpmap = new HashMap<>();
  42. public static Map<String, Windpowerstation> wpmap = new HashMap<>();
  43. public static List<Windpowerstation> wpls = new ArrayList<Windpowerstation>(); // 风电场LIST集合
  44. public static List<Windturbine> wtls = new ArrayList<Windturbine>(); // 风电机LIST集合
  45. public static Map<String, Map<String, Windturbinetestingpointnew>> wtpAimap = new HashMap<>();// 风电机测点AI表
  46. public static Map<String,Map<String, Windpowerstationpointnew>> wppointmap =new HashMap<>();
  47. public static List<Project> projects = new ArrayList<>();
  48. public static List<Line> lines = new ArrayList<>();
  49. public static Map<String, List<Windturbine>> wtsmap = new HashMap<String, List<Windturbine>>(); // 风电场MAP风电机LIST集合
  50. public static List<Equipmentmodel> mlls = new ArrayList<Equipmentmodel>();// 风电机模型LIST集合
  51. public static Map<String, Equipmentmodel> mlmap = new HashMap<String, Equipmentmodel>();// 风电机模型
  52. @Override
  53. public void run(String... args) throws Exception {
  54. log.info("-------------------------------缓存开始--------------------------------------");
  55. hpmap=healthpointsService.findAllMap();
  56. wpls = windpowerstationService.list();
  57. wpls.stream().filter(i->i.getId().endsWith("FDC")).forEach(i->{
  58. wpmap.put(i.getId(),i);
  59. });
  60. projects = projectService.list();
  61. lines = lineService.list();
  62. wtls = windturbineService.list();
  63. mlls = equipmentmodelService.list();
  64. if (!mlls.isEmpty()) {
  65. for (Equipmentmodel model : mlls) {
  66. mlmap.put(model.getId(), model);
  67. }
  68. }
  69. if (!wtls.isEmpty()) {
  70. List<Windturbine> list = null;
  71. for (Windturbine wt : wtls) {
  72. wtmap.put(wt.getId(), wt);
  73. if (wtsmap.containsKey(wt.getWindpowerstationid())) {
  74. list = wtsmap.get(wt.getWindpowerstationid());
  75. list.add(wt);
  76. } else {
  77. list = new ArrayList<Windturbine>();
  78. list.add(wt);
  79. wtsmap.put(wt.getWindpowerstationid(), list);
  80. }
  81. }
  82. }
  83. List<Windturbinetestingpointnew> WindturbinetestingpointaiList = windturbinetestingpointnewService.list();
  84. Map<String, Windturbinetestingpointnew> map = null;
  85. if(WindturbinetestingpointaiList != null && !WindturbinetestingpointaiList.isEmpty()){
  86. for(Windturbinetestingpointnew mp : WindturbinetestingpointaiList){
  87. if(wtpAimap.containsKey(mp.getWindturbineid())){
  88. map = wtpAimap.get(mp.getWindturbineid());
  89. map.put(mp.getUniformcode(), mp);
  90. }else{
  91. map = new HashMap<String, Windturbinetestingpointnew>();
  92. map.put(mp.getUniformcode(), mp);
  93. wtpAimap.put(mp.getWindturbineid(), map);
  94. }
  95. }
  96. }
  97. List<Windpowerstationpointnew> wplist = windpowerstationpointnewService.list();
  98. for (Windpowerstationpointnew Windpowerstationpointnew : wplist) {
  99. if (wppointmap.containsKey(Windpowerstationpointnew.getWindpowerstationid())){
  100. wppointmap.get(Windpowerstationpointnew.getWindpowerstationid()).put(Windpowerstationpointnew.getUniformcode(),Windpowerstationpointnew);
  101. }else{
  102. Map<String,Windpowerstationpointnew> wpmap = new HashMap<>();
  103. wpmap.put(Windpowerstationpointnew.getUniformcode(),Windpowerstationpointnew);
  104. wppointmap.put(Windpowerstationpointnew.getWindpowerstationid(),wpmap);
  105. }
  106. }
  107. log.info("-------------------------------缓存结束--------------------------------------");
  108. }
  109. // 取redis
  110. // private Logger logger = LoggerFactory.getLogger(CacheContext.class);
  111. // @Resource
  112. // private IWindturbinetestingpointService windturbinetestingpointService;
  113. // @Resource
  114. // private RedisService redisService;
  115. //
  116. // public static Map<String, Map<String, Windturbinetestingpoint>> wtpAimap = new HashMap<>();// 风电机测点表
  117. //
  118. // @Override
  119. // public void run(String... args) {
  120. // logger.info("--------------------------------缓存开始--------------------------------");
  121. // if (redisService.hasKey("WT")){
  122. // String wt = redisService.get("WT");
  123. // wtpAimap = (Map<String, Map<String, Windturbinetestingpoint>>) JSONUtils.parse(wt);
  124. // }else {
  125. // List<Windturbinetestingpoint> windturbinetestingpointList = windturbinetestingpointService.list();
  126. // Map<String, Windturbinetestingpoint> map = null;
  127. //
  128. // if(windturbinetestingpointList != null && !windturbinetestingpointList.isEmpty()){
  129. // for(Windturbinetestingpoint mp : windturbinetestingpointList){
  130. // if(wtpAimap.containsKey(mp.getWindturbineid())){
  131. // map = wtpAimap.get(mp.getWindturbineid());
  132. // map.put(mp.getUniformcode(), mp);
  133. // }else{
  134. // map = new HashMap<String, Windturbinetestingpoint>();
  135. // map.put(mp.getUniformcode(), mp);
  136. // wtpAimap.put(mp.getWindturbineid(), map);
  137. // }
  138. // }
  139. // }
  140. // }
  141. // logger.info("--------------------------------缓存结束--------------------------------");
  142. // }
  143. }