InitialRunner.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. package com.gyee.power.fitting.common.spring;
  2. import com.gyee.power.fitting.common.config.GyeeConfig;
  3. import com.gyee.power.fitting.model.*;
  4. import com.gyee.power.fitting.service.*;
  5. import lombok.extern.slf4j.Slf4j;
  6. import org.apache.commons.lang3.StringUtils;
  7. import org.springframework.boot.CommandLineRunner;
  8. import org.springframework.core.annotation.Order;
  9. import org.springframework.scheduling.annotation.Async;
  10. import org.springframework.stereotype.Component;
  11. import javax.annotation.Resource;
  12. import java.util.ArrayList;
  13. import java.util.HashMap;
  14. import java.util.List;
  15. import java.util.Map;
  16. import java.util.function.Function;
  17. import java.util.stream.Collectors;
  18. /**
  19. * 服务启动前执行,进行全局变量初始化
  20. */
  21. @Slf4j
  22. @Component
  23. @Order(1)
  24. public class InitialRunner implements CommandLineRunner {
  25. @Resource
  26. GyeeConfig config;
  27. @Resource
  28. private WindturbineService windturbineService;
  29. @Resource
  30. private WindpowerstationService windpowerstationService;
  31. @Resource
  32. private Windturbinetestingpointai2Service pointService;
  33. @Resource
  34. private EquipmentmodelService equipmentmodelService;
  35. @Resource
  36. private ModelpowerdetailsService modelpowerdetailsService;
  37. @Resource
  38. private PowermodelService powermodelService;
  39. /**
  40. * 场站所有信息
  41. **/
  42. public static List<Windpowerstation> wpList = new ArrayList<>();
  43. /**
  44. * <MHS_FDC, 麻黄山风电场>
  45. **/
  46. public static Map<String, String> stationMap = new HashMap<>();
  47. /**
  48. * 所有的风机
  49. **/
  50. public static List<Windturbine> wtList = new ArrayList<>();
  51. /**
  52. * key:wtId NG01_01
  53. **/
  54. public static Map<String, Windturbine> wtMap = new HashMap<>();
  55. /**场站的风机 key:NSS_FDC**/
  56. public static Map<String, List<Windturbine>> wpMap = new HashMap<>();
  57. /**
  58. * 光伏
  59. */
  60. public static List<Windpowerstation> gfwpList = new ArrayList<>();
  61. public static Map<String, String> gfstationMap = new HashMap<>();
  62. public static List<Windturbine> gfwtList = new ArrayList<>();
  63. public static Map<String, Windturbine> gfwtMap = new HashMap<>();
  64. public static Map<String, List<Windturbine>> gfwpMap = new HashMap<>();
  65. /**
  66. * 光照强度-场站
  67. */
  68. public static Map<String, Windpowerstationtestingpoint2> zfsMap = new HashMap<>();
  69. /**
  70. * 组件温度-场站
  71. */
  72. public static Map<String, Windpowerstationtestingpoint2> zjwdMap = new HashMap<>();
  73. /**
  74. * 功率-场站
  75. */
  76. public static Map<String, List<Windturbinetestingpointai2>> zglMap = new HashMap<>();
  77. /**
  78. * 所有设备型号
  79. **/
  80. public static List<Equipmentmodel> equipmentList = new ArrayList<>();
  81. /**
  82. * key: NG01_01
  83. **/
  84. public static Map<String, List<Windturbinetestingpointai2>> pointMap = new HashMap<>();
  85. @Resource
  86. private IWindpowerstationtestingpoint2Service windpowerstationtestingpoint2Service;
  87. public static Map<String, Equipmentmodel> equipmentMap = new HashMap<>();
  88. /**
  89. * key: model UP82
  90. **/
  91. public static Map<String, List<Modelpowerdetails>> modelPowerDetailMap = new HashMap<>();
  92. /** key: NG01_01, speed, power**/
  93. public static Map<String, Map<Double, Double>> zsllglMap = new HashMap<>();
  94. //--------------------------------------new-------------------------------------------
  95. @Resource
  96. private ProBasicEquipmentService proBasicEquipmentService;
  97. @Resource
  98. private ProBasicPowerstationService proBasicPowerstationService ;
  99. @Resource
  100. private ProBasicEquipmentPointService proBasicEquipmentPointService;
  101. @Resource
  102. private ProEconEquipmentmodelService proEconEquipmentmodelService;
  103. @Resource
  104. private ProBasicModelPowerService proBasicModelPowerService;
  105. /**
  106. * 场站所有信息
  107. **/
  108. public static List<ProBasicPowerstation> wpNewList = new ArrayList<>();
  109. /**
  110. * <MHS_FDC, 麻黄山风电场>
  111. **/
  112. public static Map<String, String> stationNewMap = new HashMap<>();
  113. /**
  114. * 所有的风机
  115. **/
  116. public static List<ProBasicEquipment> wtNewList = new ArrayList<>();
  117. /**
  118. * key:wtId NG01_01
  119. **/
  120. public static Map<String, ProBasicEquipment> wtNewMap = new HashMap<>();
  121. /**场站的风机 key:NSS_FDC**/
  122. public static Map<String, List<ProBasicEquipment>> wpNewMap = new HashMap<>();
  123. /**
  124. * 光伏
  125. */
  126. public static List<ProBasicPowerstation> gfwpNewList = new ArrayList<>();
  127. public static Map<String, String> gfstationNewMap = new HashMap<>();
  128. public static List<ProBasicEquipment> gfwtNewList = new ArrayList<>();
  129. public static Map<String, ProBasicEquipment> gfwtNewMap = new HashMap<>();
  130. public static Map<String, List<ProBasicEquipment>> gfwpNewMap = new HashMap<>();
  131. /**
  132. * 光照强度-场站
  133. */
  134. public static Map<String, ProBasicPowerstationPoint> zfsNewMap = new HashMap<>();
  135. /**
  136. * 组件温度-场站
  137. */
  138. public static Map<String, ProBasicPowerstationPoint> zjwdNewMap = new HashMap<>();
  139. /**
  140. * 功率-场站
  141. */
  142. public static Map<String, List<ProBasicEquipmentPoint>> zglNewMap = new HashMap<>();
  143. /**
  144. * 所有设备型号
  145. **/
  146. public static List<ProEconEquipmentmodel> equipmentNewList = new ArrayList<>();
  147. /**
  148. * key: NG01_01
  149. **/
  150. public static Map<String, List<ProBasicEquipmentPoint>> pointNewMap = new HashMap<>();
  151. public static Map<String, ProEconEquipmentmodel> equipmentNewMap = new HashMap<>();
  152. /**
  153. * key: model UP82
  154. **/
  155. public static Map<String, List<ProBasicModelPower>> modelPowerDetailNewMap = new HashMap<>();
  156. /** key: NG01_01, speed, power**/
  157. public static Map<String, Map<Double, Double>> zsllglNewMap = new HashMap<>();
  158. //---------------------------------------------------------------------------------
  159. @Override
  160. public void run(String... args) {
  161. System.out.println(">>>>>>>>>>>>>>>服务启动,正在缓存数据<<<<<<<<<<<<<<");
  162. // cacheStation();
  163. // cachePoints();
  164. // cacheEquipment();
  165. // // 耗时缓存
  166. // new Thread(){
  167. // @Override
  168. // public void run() {
  169. // super.run();
  170. // cacheModelPower();
  171. // cacheZSLLGL(null);
  172. // }
  173. // }.start();
  174. cacheNewStation();
  175. cacheNewPoints();
  176. cacheNewEquipment();
  177. cacheNewModelPower();
  178. System.out.println(">>>>>>>>>>>>>>>数据缓存完成<<<<<<<<<<<<<<");
  179. }
  180. /**
  181. * 缓存场站、风机数据
  182. * 数据新增或删除后需要更新,故每次清空
  183. */
  184. public void cacheStation() {
  185. List<Windpowerstation> stations = windpowerstationService.selectList();
  186. wpList = stations.stream().filter(f -> f.getId().contains("FDC")).collect(Collectors.toList());
  187. gfwpList = stations.stream().filter(f -> f.getId().contains("GDC")).collect(Collectors.toList());
  188. wpList.forEach(obj -> {
  189. List<Windturbine> wts = windturbineService.selectList(obj.getId());
  190. stationMap.put(obj.getId(), obj.getName());
  191. wpMap.put(obj.getId(), wts);
  192. wtList.addAll(wts);
  193. wts.forEach(u -> wtMap.put(u.getId(), u));
  194. });
  195. gfwpList.stream().forEach(obj -> {
  196. List<Windturbine> wts = windturbineService.selectList(obj.getId());
  197. gfstationMap.put(obj.getId(), obj.getName());
  198. gfwpMap.put(obj.getId(), wts);
  199. gfwtList.addAll(wts);
  200. wts.stream().forEach(u -> gfwtMap.put(u.getId(), u));
  201. });
  202. log.info("场站数据缓存完成");
  203. }
  204. /**
  205. * 缓存场站、风机数据
  206. * 数据新增或删除后需要更新,故每次清空
  207. */
  208. public void cacheNewStation() {
  209. List<ProBasicPowerstation> stations = proBasicPowerstationService.list();
  210. wpNewList = stations.stream().filter(f -> f.getId().contains("FDC")).collect(Collectors.toList());
  211. wpNewList.forEach(obj -> {
  212. List<ProBasicEquipment> wts =proBasicEquipmentService.list().stream().filter(w -> w.getWindpowerstationId().equals(obj.getId())).collect(Collectors.toList());;
  213. stationNewMap.put(obj.getId(), obj.getName());
  214. wpNewMap.put(obj.getId(), wts);
  215. wtNewList.addAll(wts);
  216. wts.forEach(u -> wtNewMap.put(u.getId(), u));
  217. });
  218. log.info("场站数据缓存完成");
  219. }
  220. /**
  221. * 缓存测点数据
  222. */
  223. private void cachePoints() {
  224. List<Windturbinetestingpointai2> list = new ArrayList<>();
  225. wpList.stream().forEach(d -> list.addAll(pointService.selectList(d.getId(), config.getPoints())));
  226. pointMap.putAll(list.stream().collect(Collectors.groupingBy(u -> u.getWindturbineid())));
  227. log.info("cachePoints: " + pointMap.size());
  228. if (pointMap.size() == 0)
  229. log.error("cachePoints", "测点数据缓存失败");
  230. }
  231. /**
  232. * 缓存测点数据
  233. */
  234. private void cacheNewPoints() {
  235. List<ProBasicEquipmentPoint> list = new ArrayList<>();
  236. wpNewList.stream().forEach(d -> list.addAll(proBasicEquipmentPointService.selectList(d.getId(), config.getPoints())));
  237. pointNewMap.putAll(list.stream().collect(Collectors.groupingBy(u -> u.getWindturbineId())));
  238. log.info("cachePoints: " + pointNewMap.size());
  239. if (pointNewMap.size() == 0)
  240. log.error("cachePoints", "测点数据缓存失败");
  241. }
  242. /**
  243. * 缓存设备型号
  244. */
  245. private void cacheEquipment() {
  246. equipmentList.addAll(equipmentmodelService.selectList());
  247. for (Equipmentmodel eq : equipmentList)
  248. equipmentMap.put(eq.getId(), eq);
  249. log.info("设备型号数据缓存完成");
  250. }
  251. /**
  252. * 缓存设备型号
  253. */
  254. private void cacheNewEquipment() {
  255. equipmentNewList.addAll(proEconEquipmentmodelService.list());
  256. for (ProEconEquipmentmodel eq : equipmentNewList)
  257. equipmentNewMap.put(eq.getId(), eq);
  258. log.info("设备型号数据缓存完成");
  259. }
  260. private void cacheModelPower() {
  261. List<Modelpowerdetails> lsMPD = modelpowerdetailsService.selectList();
  262. modelPowerDetailMap.putAll(lsMPD.stream().collect(Collectors.groupingBy(u -> u.getModelid())));
  263. log.info("保证功率数据缓存完成");
  264. }
  265. private void cacheNewModelPower() {
  266. List<ProBasicModelPower> lsMPD = proBasicModelPowerService.list();
  267. modelPowerDetailNewMap.putAll(lsMPD.stream().collect(Collectors.groupingBy(u -> u.getModelId())));
  268. log.info("保证功率数据缓存完成");
  269. }
  270. /**
  271. * 自算理论功率
  272. */
  273. public void cacheZSLLGL(String wtId){
  274. if (StringUtils.isEmpty(wtId)){
  275. zsllglMap = powermodelService.selectList().stream()
  276. .collect(Collectors.groupingBy(Powermodel::getWindturbineid,
  277. Collectors.toMap(Powermodel::getSpeed, Powermodel::getPower)));
  278. }else{
  279. List<Powermodel> list = powermodelService.selectByWtId(wtId);
  280. Map<Double, Double> collect = list.stream().collect(Collectors.toMap(Powermodel::getSpeed, Powermodel::getPower));
  281. zsllglMap.replace(wtId, collect);
  282. }
  283. log.info("自算功率数据缓存完成");
  284. }
  285. }