InitialRunner.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. package com.gyee.power.fitting.common.spring;
  2. import com.alibaba.fastjson.JSON;
  3. import com.gyee.power.fitting.common.config.GyeeConfig;
  4. import com.gyee.power.fitting.common.util.FileUtil;
  5. import com.gyee.power.fitting.model.*;
  6. import com.gyee.power.fitting.model.agc.AgcDeviateConfig;
  7. import com.gyee.power.fitting.service.*;
  8. import com.gyee.power.fitting.service.impl.NewIvPvCurveFittingService;
  9. import lombok.extern.slf4j.Slf4j;
  10. import org.apache.commons.lang3.StringUtils;
  11. import org.springframework.boot.CommandLineRunner;
  12. import org.springframework.core.annotation.Order;
  13. import org.springframework.stereotype.Component;
  14. import javax.annotation.Resource;
  15. import java.util.ArrayList;
  16. import java.util.HashMap;
  17. import java.util.List;
  18. import java.util.Map;
  19. import java.util.function.Function;
  20. import java.util.stream.Collectors;
  21. /**
  22. * 服务启动前执行,进行全局变量初始化
  23. */
  24. @Slf4j
  25. @Component
  26. @Order(1)
  27. public class InitialRunner implements CommandLineRunner {
  28. @Resource
  29. GyeeConfig config;
  30. @Resource
  31. private WindturbineService windturbineService;
  32. @Resource
  33. private WindpowerstationService windpowerstationService;
  34. @Resource
  35. private Windturbinetestingpointai2Service pointService;
  36. @Resource
  37. private ProBasicEquipmentPointService pointService1;
  38. @Resource
  39. private EquipmentmodelService equipmentmodelService;
  40. @Resource
  41. private ModelpowerdetailsService modelpowerdetailsService;
  42. @Resource
  43. private PowermodelService powermodelService;
  44. @Resource
  45. private ProEconPowerModelService proEconPowerModelService;
  46. @Resource
  47. private NewIvPvCurveFittingService ipcfService;
  48. /**
  49. * 场站所有信息
  50. **/
  51. public static List<Windpowerstation> wpList = new ArrayList<>();
  52. /**
  53. * <MHS_FDC, 麻黄山风电场>
  54. **/
  55. public static Map<String, String> stationMap = new HashMap<>();
  56. /**
  57. * 所有的风机
  58. **/
  59. public static List<Windturbine> wtList = new ArrayList<>();
  60. /**
  61. * key:wtId NG01_01
  62. **/
  63. public static Map<String, Windturbine> wtMap = new HashMap<>();
  64. /**场站的风机 key:NSS_FDC**/
  65. public static Map<String, List<Windturbine>> wpMap = new HashMap<>();
  66. /**
  67. * 光伏
  68. */
  69. public static List<Windpowerstation> gfwpList = new ArrayList<>();
  70. public static Map<String, String> gfstationMap = new HashMap<>();
  71. public static List<Windturbine> gfwtList = new ArrayList<>();
  72. public static Map<String, Windturbine> gfwtMap = new HashMap<>();
  73. public static Map<String, List<Windturbine>> gfwpMap = new HashMap<>();
  74. /**
  75. * 光照强度-场站
  76. */
  77. public static Map<String, Windpowerstationtestingpoint2> zfsMap = new HashMap<>();
  78. /**
  79. * 组件温度-场站
  80. */
  81. public static Map<String, Windpowerstationtestingpoint2> zjwdMap = new HashMap<>();
  82. /**
  83. * 功率-场站
  84. */
  85. public static Map<String, List<Windturbinetestingpointai2>> zglMap = new HashMap<>();
  86. /**
  87. * 所有设备型号
  88. **/
  89. public static List<Equipmentmodel> equipmentList = new ArrayList<>();
  90. /**
  91. * key: NG01_01
  92. **/
  93. public static Map<String, List<Windturbinetestingpointai2>> pointMap = new HashMap<>();
  94. @Resource
  95. private IWindpowerstationtestingpoint2Service windpowerstationtestingpoint2Service;
  96. public static Map<String, Equipmentmodel> equipmentMap = new HashMap<>();
  97. /**
  98. * key: model UP82
  99. **/
  100. public static Map<String, List<Modelpowerdetails>> modelPowerDetailMap = new HashMap<>();
  101. /** key: NG01_01, speed, power**/
  102. public static Map<String, Map<Double, Double>> zsllglMap = new HashMap<>();
  103. public static Map<String, AgcDeviateConfig> powerPreMap = new HashMap<>();
  104. //--------------------------------------new-------------------------------------------
  105. @Resource
  106. private ProBasicEquipmentService proBasicEquipmentService;
  107. @Resource
  108. private ProBasicPowerstationService proBasicPowerstationService ;
  109. @Resource
  110. private ProBasicEquipmentPointService proBasicEquipmentPointService;
  111. @Resource
  112. private ProBasicPowerstationPointService proBasicPowerstationPointService;
  113. @Resource
  114. private ProEconEquipmentmodelService proEconEquipmentmodelService;
  115. @Resource
  116. private ProBasicModelPowerService proBasicModelPowerService;
  117. /**
  118. * 场站所有信息
  119. **/
  120. public static List<ProBasicPowerstation> wpNewList = new ArrayList<>();
  121. /**
  122. * <MHS_FDC, 麻黄山风电场>
  123. **/
  124. public static Map<String, String> stationNewMap = new HashMap<>();
  125. /**
  126. * 所有的风机
  127. **/
  128. public static List<ProBasicEquipment> wtNewList = new ArrayList<>();
  129. /**
  130. * key:wtId NG01_01
  131. **/
  132. public static Map<String, ProBasicEquipment> wtNewMap = new HashMap<>();
  133. /**场站的风机 key:NSS_FDC**/
  134. public static Map<String, List<ProBasicEquipment>> wpNewMap = new HashMap<>();
  135. /**
  136. * 光伏
  137. */
  138. public static List<ProBasicPowerstation> gfwpNewList = new ArrayList<>();
  139. public static Map<String, String> gfstationNewMap = new HashMap<>();
  140. public static List<ProBasicEquipment> gfwtNewList = new ArrayList<>();
  141. public static Map<String, ProBasicEquipment> gfwtNewMap = new HashMap<>();
  142. public static Map<String, List<ProBasicEquipment>> gfwpNewMap = new HashMap<>();
  143. /**
  144. * 光照强度-场站
  145. */
  146. public static Map<String, ProBasicPowerstationPoint> zfsNewMap = new HashMap<>();
  147. /**
  148. * 组件温度-场站
  149. */
  150. public static Map<String, ProBasicPowerstationPoint> zjwdNewMap = new HashMap<>();
  151. /**
  152. * 功率-场站
  153. */
  154. public static Map<String, List<ProBasicEquipmentPoint>> zglNewMap = new HashMap<>();
  155. /**
  156. * 所有设备型号
  157. **/
  158. public static List<ProEconEquipmentmodel> equipmentNewList = new ArrayList<>();
  159. /**
  160. * key: NG01_01
  161. **/
  162. public static Map<String, List<ProBasicEquipmentPoint>> pointNewMap = new HashMap<>();
  163. public static Map<String, ProEconEquipmentmodel> equipmentNewMap = new HashMap<>();
  164. /**
  165. * key: model UP82
  166. **/
  167. public static Map<String, List<ProBasicModelPower>> modelPowerDetailNewMap = new HashMap<>();
  168. /** key: NG01_01, speed, power**/
  169. public static Map<String, Map<Double, Double>> zsllglNewMap = new HashMap<>();
  170. /**
  171. * 功率-场站
  172. */
  173. public static Map<String, List<ProBasicEquipmentPoint>> newzglMap = new HashMap<>();
  174. public static Map<String, List<ProBasicEquipmentPoint>> newllglMap = new HashMap<>();
  175. public static Map<String, ProBasicPowerstationPoint> newzjwdMap = new HashMap<>();
  176. public static Map<String, ProBasicPowerstationPoint> newzfsMap = new HashMap<>();
  177. public static Map<String, ProBasicEquipment> newwtMap = new HashMap<>();
  178. public static List<ProBasicPowerstation> newwpList = new ArrayList<>();
  179. public static List<ProBasicEquipment> newwtList = new ArrayList<>();
  180. public static Map<String, List<ProBasicEquipment>> newwpMap = new HashMap<>();
  181. public static List<ProBasicPowerstation> newgfwpList = new ArrayList<>();
  182. public static Map<String, String> newstationMap = new HashMap<>();
  183. public static Map<String, String> newgfstationMap = new HashMap<>();
  184. public static Map<String, List<ProBasicEquipment>> newgfwpMap = new HashMap<>();
  185. public static List<ProBasicEquipment> newgfwtList = new ArrayList<>();
  186. public static Map<String, ProBasicEquipment> newgfwtMap = new HashMap<>();
  187. //---------------------------------------------------------------------------------
  188. @Override
  189. public void run(String... args) {
  190. System.out.println(">>>>>>>>>>>>>>>服务启动,正在缓存数据<<<<<<<<<<<<<<");
  191. // cacheStation();
  192. // cachePoints();
  193. // cacheEquipment();
  194. // // 耗时缓存
  195. // new Thread(){
  196. // @Override
  197. // public void run() {
  198. // super.run();
  199. // cacheModelPower();
  200. // cacheZSLLGL(null);
  201. // }
  202. // }.start();
  203. newcacheStation();
  204. cachePhotovoltaicInfo();
  205. cacheNewStation();
  206. cacheNewPoints();
  207. cacheNewEquipment();
  208. new Thread(){
  209. @Override
  210. public void run() {
  211. super.run();
  212. cacheNewModelPower();
  213. cacheZSLLGL(null);
  214. }
  215. }.start();
  216. System.out.println(">>>>>>>>>>>>>>>数据缓存完成<<<<<<<<<<<<<<");
  217. }
  218. /**
  219. * 缓存场站、风机数据
  220. * 数据新增或删除后需要更新,故每次清空
  221. */
  222. public void newcacheStation() {
  223. List<ProBasicPowerstation> stations = proBasicPowerstationService.selectList();
  224. newwpList = stations.stream().filter(f -> f.getId().contains("FDC_STA")).collect(Collectors.toList());
  225. newgfwpList = stations.stream().filter(f -> f.getId().contains("GDC_STA")).collect(Collectors.toList());
  226. newwpList.forEach(obj -> {
  227. List<ProBasicEquipment> wts = proBasicEquipmentService.selectList(obj.getId());
  228. newstationMap.put(obj.getId(), obj.getName());
  229. newwpMap.put(obj.getId(), wts);
  230. newwtList.addAll(wts);
  231. wts.forEach(u -> newwtMap.put(u.getId(), u));
  232. });
  233. newgfwpList.stream().forEach(obj -> {
  234. List<ProBasicEquipment> wts = proBasicEquipmentService.selectList(obj.getId());
  235. newgfstationMap.put(obj.getId(), obj.getName());
  236. newgfwpMap.put(obj.getId(), wts);
  237. newgfwtList.addAll(wts);
  238. wts.stream().forEach(u -> newgfwtMap.put(u.getId(), u));
  239. });
  240. log.info("场站数据缓存完成");
  241. }
  242. public void cacheStation() {
  243. List<Windpowerstation> stations = windpowerstationService.selectList();
  244. wpList = stations.stream().filter(f -> f.getId().contains("FDC")).collect(Collectors.toList());
  245. gfwpList = stations.stream().filter(f -> f.getId().contains("GDC")).collect(Collectors.toList());
  246. wpList.forEach(obj -> {
  247. List<Windturbine> wts = windturbineService.selectList(obj.getId());
  248. stationMap.put(obj.getId(), obj.getName());
  249. wpMap.put(obj.getId(), wts);
  250. wtList.addAll(wts);
  251. wts.forEach(u -> wtMap.put(u.getId(), u));
  252. });
  253. gfwpList.stream().forEach(obj -> {
  254. List<Windturbine> wts = windturbineService.selectList(obj.getId());
  255. gfstationMap.put(obj.getId(), obj.getName());
  256. gfwpMap.put(obj.getId(), wts);
  257. gfwtList.addAll(wts);
  258. wts.stream().forEach(u -> gfwtMap.put(u.getId(), u));
  259. });
  260. log.info("场站数据缓存完成");
  261. }
  262. /**
  263. * 缓存场站、风机数据
  264. * 数据新增或删除后需要更新,故每次清空
  265. */
  266. public void cacheNewStation() {
  267. List<ProBasicPowerstation> stations = proBasicPowerstationService.list();
  268. wpNewList = stations.stream().filter(f -> f.getId().contains("FDC")).collect(Collectors.toList());
  269. gfwpNewList = stations.stream().filter(f -> f.getId().contains("GDC")).collect(Collectors.toList());
  270. wpNewList.forEach(obj -> {
  271. List<ProBasicEquipment> wts =proBasicEquipmentService.list().stream().filter(w -> w.getWindpowerstationId().equals(obj.getId())).collect(Collectors.toList());;
  272. stationNewMap.put(obj.getId(), obj.getName());
  273. wpNewMap.put(obj.getId(), wts);
  274. wtNewList.addAll(wts);
  275. wts.forEach(u -> wtNewMap.put(u.getId(), u));
  276. });
  277. gfwpNewList.stream().forEach(obj -> {
  278. List<ProBasicEquipment> wts = proBasicEquipmentService.selectList(obj.getId());
  279. gfstationNewMap.put(obj.getId(), obj.getName());
  280. gfwpNewMap.put(obj.getId(), wts);
  281. gfwtNewList.addAll(wts);
  282. wts.stream().forEach(u -> gfwtNewMap.put(u.getId(), u));
  283. });
  284. log.info("场站数据缓存完成");
  285. }
  286. private void cachePhotovoltaicInfo() {
  287. List<ProBasicPowerstationPoint> zfsPoints = proBasicPowerstationPointService.getzfsPoints("GDC", ipcfService.getUniforcodes().get("光照强度"));
  288. List<ProBasicPowerstationPoint> zjwdPoints = proBasicPowerstationPointService.getzjwdPoints("GDC", ipcfService.getUniforcodes().get("组件温度"));
  289. newzfsMap = zfsPoints.stream().collect(Collectors.toMap(ProBasicPowerstationPoint::getWindpowerstationId, Function.identity()));
  290. newzjwdMap = zjwdPoints.stream().collect(Collectors.toMap(ProBasicPowerstationPoint::getWindpowerstationId, Function.identity()));
  291. List<ProBasicEquipmentPoint> zglPoints = pointService1.getPoints("GDC", null, ipcfService.getUniforcodes().get("功率"));
  292. newzglMap = zglPoints.stream().collect(Collectors.groupingBy(ProBasicEquipmentPoint::getWindpowerstationId));
  293. List<ProBasicEquipmentPoint> llglPoints = pointService1.getPoints("GDC", null, ipcfService.getUniforcodes().get("理论功率"));
  294. newllglMap = llglPoints.stream().collect(Collectors.groupingBy(ProBasicEquipmentPoint::getWindpowerstationId));
  295. }
  296. /**
  297. * 缓存测点数据
  298. */
  299. private void cachePoints() {
  300. List<Windturbinetestingpointai2> list = new ArrayList<>();
  301. wpList.stream().forEach(d -> list.addAll(pointService.selectList(d.getId(), config.getPoints())));
  302. pointMap.putAll(list.stream().collect(Collectors.groupingBy(u -> u.getWindturbineid())));
  303. log.info("cachePoints: " + pointMap.size());
  304. if (pointMap.size() == 0)
  305. log.error("cachePoints", "测点数据缓存失败");
  306. }
  307. /**
  308. * 缓存测点数据
  309. */
  310. private void cacheNewPoints() {
  311. List<ProBasicEquipmentPoint> list = new ArrayList<>();
  312. wpNewList.stream().forEach(d -> list.addAll(proBasicEquipmentPointService.selectList(d.getId(), config.getPoints())));
  313. pointNewMap.putAll(list.stream().collect(Collectors.groupingBy(u -> u.getWindturbineId())));
  314. log.info("cachePoints: " + pointNewMap.size());
  315. if (pointNewMap.size() == 0)
  316. log.error("cachePoints", "测点数据缓存失败");
  317. }
  318. /**
  319. * 缓存设备型号
  320. */
  321. private void cacheEquipment() {
  322. equipmentList.addAll(equipmentmodelService.selectList());
  323. for (Equipmentmodel eq : equipmentList)
  324. equipmentMap.put(eq.getId(), eq);
  325. log.info("设备型号数据缓存完成");
  326. }
  327. /**
  328. * 缓存设备型号
  329. */
  330. private void cacheNewEquipment() {
  331. equipmentNewList.addAll(proEconEquipmentmodelService.list());
  332. for (ProEconEquipmentmodel eq : equipmentNewList)
  333. equipmentNewMap.put(eq.getId(), eq);
  334. log.info("设备型号数据缓存完成");
  335. }
  336. private void cacheModelPower() {
  337. List<Modelpowerdetails> lsMPD = modelpowerdetailsService.selectList();
  338. modelPowerDetailMap.putAll(lsMPD.stream().collect(Collectors.groupingBy(u -> u.getModelid())));
  339. log.info("保证功率数据缓存完成");
  340. }
  341. private void cacheNewModelPower() {
  342. List<ProBasicModelPower> lsMPD = proBasicModelPowerService.list();
  343. modelPowerDetailNewMap.putAll(lsMPD.stream().collect(Collectors.groupingBy(u -> u.getModelId())));
  344. log.info("保证功率数据缓存完成");
  345. }
  346. /**
  347. * 自算理论功率
  348. */
  349. public void cacheZSLLGL(String wtId){
  350. if (StringUtils.isEmpty(wtId)){
  351. zsllglNewMap = proEconPowerModelService.selectList().stream()
  352. .collect(Collectors.groupingBy(ProEconPowerModel::getWindturbineId,
  353. Collectors.toMap(ProEconPowerModel::getSpeed, ProEconPowerModel::getPower)));
  354. }else{
  355. List<ProEconPowerModel> list = proEconPowerModelService.selectByWtId(wtId);
  356. Map<Double, Double> collect = list.stream().collect(Collectors.toMap(ProEconPowerModel::getSpeed, ProEconPowerModel::getPower));
  357. zsllglNewMap.replace(wtId, collect);
  358. }
  359. log.info("自算功率数据缓存完成");
  360. }
  361. /**
  362. * 功率预测相关测点
  363. */
  364. private void cacheFGL(){
  365. String str = FileUtil.getStringFromFile(config.getFilePathPower() + "fgl_info.json");
  366. AgcDeviateConfig[] object = JSON.parseObject(str, AgcDeviateConfig[].class);
  367. for (AgcDeviateConfig conf : object){
  368. powerPreMap.put(conf.getId(), conf);
  369. }
  370. log.info("自功率预测相关测点数据缓存完成");
  371. }
  372. }