InitialRunner.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. package com.gyee.impala.common.spring;
  2. import com.gyee.impala.model.master.*;
  3. import com.gyee.impala.model.master.diagnose.Diagnosepoint;
  4. import com.gyee.impala.model.master.diagnose.Diagnosetrainhistory;
  5. import com.gyee.impala.service.master.*;
  6. import com.gyee.impala.service.master.diagnose.DiagnosepointService;
  7. import com.gyee.impala.service.master.diagnose.DiagnosetrainhistoryService;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.boot.CommandLineRunner;
  10. import org.springframework.core.annotation.Order;
  11. import org.springframework.stereotype.Component;
  12. import javax.annotation.Resource;
  13. import java.util.*;
  14. import java.util.stream.Collectors;
  15. /**
  16. * 服务启动前执行,进行全局变量初始化
  17. */
  18. @Component
  19. @Order(2)
  20. public class InitialRunner implements CommandLineRunner {
  21. @Resource
  22. private WindturbineService windturbineService;
  23. @Resource
  24. private WindpowerstationService windpowerstationService;
  25. @Autowired
  26. private KnowcategoryService faulttypeService;
  27. @Autowired
  28. private EquipmentmodelService modelService;
  29. @Autowired
  30. private DiagnosepointService diagnosepointService;
  31. @Autowired
  32. private DiagnosetrainhistoryService diagnosetrainhistoryService;
  33. /**场站所有信息**/
  34. public static List<Windpowerstation> wpList = new ArrayList<>();
  35. /**场站的风机**/
  36. public static Map<String, List<Windturbine>> wpMap = new HashMap<>();
  37. /** <MHS_FDC, 麻黄山风电场> **/
  38. public static Map<String, String> stationMap = new HashMap<>();
  39. /**所有的风机**/
  40. public static List<Windturbine> wtList = new ArrayList<>();
  41. /** <NG01_01, Windturbine> **/
  42. public static Map<String, Windturbine> wtMap = new HashMap<>();
  43. /**功率曲线预处理数据表格数据 key:time+wtId value:当前风机的总条数 **/
  44. public static Map<String, Integer> scatterMap = new HashMap<>();
  45. /***故障 <FDJ,发电机故障> 类型*/
  46. public static Map<String, String> faultTypeMap = new HashMap<>();
  47. public static List<Knowcategory> faultTypeList = new ArrayList<>();
  48. /***scada预警 <FDJ,发电机> 类型*/
  49. public static Map<String, String> scadaWarnMap = new HashMap<>();
  50. public static List<Knowcategory> scadaWarnList = new ArrayList<>();
  51. /***自定义预警 <FDJ,发电机> 类型*/
  52. public static Map<String, String> customWarnMap = new HashMap<>();
  53. public static List<Knowcategory> customWarnList = new ArrayList<>();
  54. /** 设备型号配置 <UP82, Equipmentmodel> **/
  55. public static Map<String, Equipmentmodel> modelMap = new HashMap<>();
  56. /** 故障诊断 训练需要的测点**/
  57. public static Map<String, Map<String, List<Diagnosepoint>>> mapPoint = new HashMap<>();
  58. /*** 故障训练历史模型 */
  59. public static Map<String, List<Diagnosetrainhistory>> historyModelMap = new HashMap<>();
  60. public static List<Diagnosetrainhistory> historyList = new ArrayList<>();
  61. @Override
  62. public void run(String... args){
  63. System.out.println(">>>>>>>>>>>>>>>服务启动,正在缓存数据<<<<<<<<<<<<<<");
  64. cacheStation();
  65. cacheKnowCategory();
  66. cacheEquipmentModel();
  67. cacheDiagnosePoint();
  68. cacheHistory();
  69. System.out.println(">>>>>>>>>>>>>>>数据缓存完成<<<<<<<<<<<<<<");
  70. }
  71. /**
  72. * 缓存场站数据
  73. * 数据新增或删除后需要更新,故每次清空
  74. */
  75. public void cacheStation(){
  76. wpList.clear();
  77. wtList.clear();
  78. stationMap.clear();
  79. wpMap.clear();
  80. wtMap.clear();
  81. List<Windpowerstation> stations = windpowerstationService.getAll();
  82. wpList = stations;
  83. stations.stream().forEach(obj -> {
  84. List<Windturbine> wts = windturbineService.getWindTurbineId(obj.getId());
  85. stationMap.put(obj.getId(), obj.getName());
  86. wpMap.put(obj.getId(), wts);
  87. wtList.addAll(wts);
  88. wts.stream().forEach(o -> wtMap.put(o.getId(), o));
  89. });
  90. }
  91. /**
  92. * 缓存故障知识数据
  93. */
  94. public void cacheKnowCategory() {
  95. faultTypeList.clear();
  96. scadaWarnList.clear();
  97. customWarnList.clear();
  98. faultTypeMap.clear();
  99. scadaWarnMap.clear();
  100. customWarnMap.clear();
  101. List<Knowcategory> faultType = faulttypeService.getAll();
  102. faultType.stream().forEach(obj -> {
  103. if (obj.getCategory().equals("GZ")) {
  104. faultTypeList.add(obj);
  105. faultTypeMap.put(obj.getCode(), obj.getName().toUpperCase());
  106. }
  107. else if (obj.getCategory().equals("SCADABJ")) {
  108. scadaWarnList.add(obj);
  109. scadaWarnMap.put(obj.getCode(), obj.getName().toUpperCase());
  110. }
  111. else if (obj.getCategory().equals("CUSTOMBJ")) {
  112. customWarnList.add(obj);
  113. customWarnMap.put(obj.getCode(), obj.getName().toUpperCase());
  114. }
  115. });
  116. }
  117. public void cacheEquipmentModel() {
  118. modelMap.clear();
  119. List<Equipmentmodel> models = modelService.getAll();
  120. models.stream().forEach(obj -> modelMap.put(obj.getId(), obj));
  121. }
  122. public void cacheDiagnosePoint(){
  123. mapPoint.clear();
  124. List<Diagnosepoint> points = diagnosepointService.getDiagnosepointList();
  125. mapPoint = points.stream().collect(Collectors.groupingBy(Diagnosepoint::getStationen, Collectors.groupingBy(Diagnosepoint::getModel)));
  126. }
  127. public void cacheHistory(){
  128. historyModelMap.clear();
  129. historyList.clear();
  130. historyList = diagnosetrainhistoryService.getListAll();
  131. historyModelMap = historyList.stream().collect(Collectors.groupingBy(Diagnosetrainhistory::getModel));
  132. }
  133. }