ShutdownService.java 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  1. package com.gyee.generation.service;
  2. import com.gyee.common.contant.ContantXk;
  3. import com.gyee.common.model.PointData;
  4. import com.gyee.generation.init.CacheContext;
  5. import com.gyee.generation.model.auto.*;
  6. import com.gyee.generation.service.auto.*;
  7. import com.gyee.generation.util.DateUtils;
  8. import com.gyee.generation.util.StringUtils;
  9. import com.gyee.generation.util.realtimesource.IEdosUtil;
  10. import org.slf4j.Logger;
  11. import org.slf4j.LoggerFactory;
  12. import org.springframework.stereotype.Service;
  13. import javax.annotation.Resource;
  14. import java.util.*;
  15. import java.util.stream.Collectors;
  16. @Service
  17. public class ShutdownService {
  18. @Resource
  19. private IEdosUtil edosUtil;
  20. @Resource
  21. private IProEconWindturbineStatusService proEconWindturbineStatusService;
  22. @Resource
  23. private IProEconShutdownEventService proEconShutdownEventService;
  24. @Resource
  25. private IProEconShutdownEvent2Service proEconShutdownEvent2Service;
  26. @Resource
  27. private IProEconInterruptionService proEconInterruptionService;
  28. @Resource
  29. private IProEconInputOrOutputSpeedService proEconInputOrOutputSpeedService;
  30. public static Logger logger = LoggerFactory.getLogger(ShutdownService.class);
  31. /// <summary>
  32. /// 风机状态测点,key为风机编号
  33. /// </summary>
  34. public Map<String, ProBasicEquipmentPoint> statusPoints = new HashMap<>();
  35. /// <summary>
  36. /// 风机功率测点,key为风机编号
  37. /// </summary>
  38. public Map<String, ProBasicEquipmentPoint> powerPoints = new HashMap<>();
  39. /// <summary>
  40. /// 风机当前状态,key为风机编号
  41. /// </summary>
  42. public Map<String, Integer> status = new HashMap<>();
  43. /// <summary>
  44. /// 保存风机信息,key为风机编号
  45. /// </summary>
  46. public Map<String, ProBasicEquipment> windTurbines = new HashMap<>();
  47. /// <summary>
  48. /// 风机状态说明,key为状态码,value为状态说明
  49. /// </summary>
  50. public Map<Integer, String> statusDescription = new HashMap<>();
  51. public Date date = new Date();
  52. Map<String, ProEconWindturbineStatus> oldStatusMap = new HashMap<>();
  53. Map<String, ProEconShutdownEvent> oldShutdownEvent = new HashMap<>();
  54. Map<String, ProEconInterruption> oldInterrup = new HashMap<>();
  55. //新增shutdownevent2 实时
  56. Map<String, ProEconShutdownEvent2> oldShutdownEvent2 = new HashMap<>();
  57. /// <summary>
  58. /// 风机功率 key为风机编号
  59. /// </summary>
  60. Map<String, ProBasicEquipmentPoint> powerpointMap = new HashMap<>();//功率
  61. /// <summary>
  62. /// 风机风速 key为风机编号
  63. /// </summary>
  64. Map<String, ProBasicEquipmentPoint> speedpointMap = new HashMap<>();//风速
  65. /// <summary>
  66. /// 测风塔风速 key为风场编号
  67. /// </summary>
  68. Map<String, ProBasicPowerstationPoint> gzdpointMap = new HashMap<>();//测风塔风速
  69. Map<String, ProBasicPowerstation> windpowerMap;//风场
  70. public void init()
  71. {
  72. // statusDescription.put(0, "待机");
  73. // statusDescription.put(1, "并网");
  74. // statusDescription.put(2, "停机");
  75. // statusDescription.put(3, "通讯中断");
  76. // statusDescription.put(4, "维护");
  77. // statusDescription.put(5, "限电");
  78. statusDescription.put(0, "待机");
  79. statusDescription.put(1, "手动停机");
  80. statusDescription.put(2, "正常发电");
  81. statusDescription.put(3, "缺陷降出力");
  82. statusDescription.put(4, "故障停机");
  83. statusDescription.put(5, "故障受累");
  84. statusDescription.put(6, "检修停机");
  85. statusDescription.put(7, "检修受累");
  86. statusDescription.put(8, "限电降出力");
  87. statusDescription.put(9, "限电停机");
  88. statusDescription.put(10, "电网受累");
  89. statusDescription.put(11, "环境受累");
  90. statusDescription.put(12, "通讯中断");
  91. statusDescription.put(13, "设备离线");
  92. windpowerMap = CacheContext.wpmap;
  93. List<ProBasicEquipmentPoint> items=new ArrayList<>();
  94. List<ProBasicEquipmentPoint> powerpointList = new ArrayList<>();
  95. List<ProBasicEquipmentPoint> speedpointList = new ArrayList<>();
  96. List<ProBasicEquipment> wtls= CacheContext.wtls;
  97. Map<String, Map<String, ProBasicEquipmentPoint>> wtpAimap=CacheContext.wtpAimap;
  98. //筛选风机对应测点
  99. wtls.forEach(wt->{
  100. Map<String, ProBasicEquipmentPoint> windturbinetestingpointnewMap = wtpAimap.get(wt.getId());
  101. if(windturbinetestingpointnewMap.containsKey(ContantXk.MXZT))
  102. {
  103. ProBasicEquipmentPoint mxztPoint = windturbinetestingpointnewMap.get(ContantXk.MXZT);
  104. items.add(mxztPoint);
  105. }
  106. if(windturbinetestingpointnewMap.containsKey(ContantXk.CJ_SSGL))
  107. {
  108. ProBasicEquipmentPoint ssglPoint = windturbinetestingpointnewMap.get(ContantXk.CJ_SSGL);
  109. powerPoints.put(ssglPoint.getNemCode(),ssglPoint);
  110. powerpointList.add(ssglPoint);
  111. }
  112. if(windturbinetestingpointnewMap.containsKey(ContantXk.CJ_SSFS))
  113. {
  114. ProBasicEquipmentPoint ssfsPoint = windturbinetestingpointnewMap.get(ContantXk.CJ_SSFS);
  115. speedpointList.add(ssfsPoint);
  116. }
  117. });
  118. //进行测点排序
  119. powerpointList.sort(Comparator.comparing(ProBasicEquipmentPoint::getWindturbineId));
  120. speedpointList.sort(Comparator.comparing(ProBasicEquipmentPoint::getWindturbineId));
  121. for (ProBasicEquipmentPoint item : items)
  122. {
  123. statusPoints.put(item.getWindturbineId(), item);
  124. status.put(item.getWindturbineId(), -1);
  125. }
  126. windTurbines=CacheContext.wtmap;
  127. List<ProBasicPowerstationPoint> gzdpointList =new ArrayList<>();
  128. CacheContext.wpls.forEach(wp->{
  129. Map<String, ProBasicPowerstationPoint> wppointsmap = CacheContext.wppointmap.get(wp.getId());
  130. if(wppointsmap.containsKey(ContantXk.FCCFTFS70))
  131. {
  132. ProBasicPowerstationPoint mxztPoint = wppointsmap.get(ContantXk.FCCFTFS70);
  133. gzdpointList.add(mxztPoint);
  134. }
  135. });
  136. for (ProBasicEquipmentPoint proBasicEquipmentPoint : powerpointList) {
  137. if (!powerpointMap.containsKey(proBasicEquipmentPoint.getWindturbineId())) {
  138. powerpointMap.put(proBasicEquipmentPoint.getWindturbineId(), proBasicEquipmentPoint);
  139. }
  140. }
  141. for (ProBasicEquipmentPoint proBasicEquipmentPoint : speedpointList) {
  142. if (!speedpointMap.containsKey(proBasicEquipmentPoint.getWindturbineId())) {
  143. speedpointMap.put(proBasicEquipmentPoint.getWindturbineId(), proBasicEquipmentPoint);
  144. }
  145. }
  146. for (ProBasicPowerstationPoint proBasicPowerstationPoint : gzdpointList) {
  147. if (!gzdpointMap.containsKey(proBasicPowerstationPoint.getWindpowerstationId())) {
  148. gzdpointMap.put(proBasicPowerstationPoint.getWindpowerstationId(), proBasicPowerstationPoint);
  149. }
  150. }
  151. // List<ProBasicModelPowerRd> pbmprls=proBasicModelPowerRdService.list().stream()
  152. //
  153. // .sorted(Comparator.comparing(ProBasicModelPowerRd::getSpeed)).collect(Collectors.toList());
  154. //
  155. //
  156. // if(!pbmprls.isEmpty())
  157. // {
  158. // for(ProBasicModelPowerRd pwpcf:pbmprls)
  159. // {
  160. //
  161. // if(modelPowerMap.containsKey(pwpcf.getId()))
  162. // {
  163. // Map<Double, ProBasicModelPowerRd> map =modelPowerMap.get(pwpcf.getId());
  164. // map.put(pwpcf.getSpeed(),pwpcf);
  165. // modelPowerMap.put(pwpcf.getId(),map);
  166. // }else
  167. // {
  168. // Map<Double, ProBasicModelPowerRd> map = new HashMap<Double, ProBasicModelPowerRd>();
  169. // map.put(pwpcf.getSpeed(),pwpcf);
  170. // modelPowerMap.put(pwpcf.getId(),map);
  171. // }
  172. //
  173. // }
  174. // }
  175. }
  176. public void execShutdown() throws Exception {
  177. init();
  178. oldStatusMap.clear();
  179. oldShutdownEvent.clear();
  180. oldInterrup.clear();
  181. oldShutdownEvent2.clear();
  182. logger.debug("{0}开始", date);
  183. //循环读取所有风机的当前状态,并且给几个缓存字典初始化
  184. for (String key : statusPoints.keySet())
  185. {
  186. //取实时状态数据 赋值给status
  187. double power = 0;
  188. if (powerPoints.containsKey(key))
  189. {
  190. power = StringUtils.round(edosUtil.getRealData(powerPoints.get(key).getNemCode()).getPointValueInDouble(),4);
  191. }
  192. double value = StringUtils.round(edosUtil.getRealData(statusPoints.get(key).getNemCode()).getPointValueInDouble(),4);
  193. if (power > 1)
  194. {
  195. status.put(key,value == 9 ? 1 : (int) value);
  196. }
  197. else
  198. {
  199. status.put(key,value == 9 ? 0 : (int) value);
  200. }
  201. oldStatusMap.put(key, null);
  202. oldShutdownEvent.put(key, null);
  203. oldInterrup.put(key, null);
  204. // 新增 shutdownevent2 实时
  205. oldShutdownEvent2.put(key, null);
  206. }
  207. //读取oracle中 五种小时数、停机记录、中断记录
  208. //读取数据库存在的恢复时间为NULL的数据
  209. List<ProEconWindturbineStatus> oldStatusQuery=proEconWindturbineStatusService.list().stream()
  210. .filter(i->StringUtils.empty(i.getStartTime()))
  211. .sorted(Comparator.comparing(ProEconWindturbineStatus::getStopTime)).collect(Collectors.toList());
  212. for (ProEconWindturbineStatus oldStatus : oldStatusQuery)
  213. {
  214. if (oldStatusMap.containsKey(oldStatus.getWindturbineId()))
  215. {
  216. oldStatusMap.put(oldStatus.getWindturbineId(),oldStatus);
  217. }
  218. }
  219. List<ProEconShutdownEvent> oldShutdwonQuery=proEconShutdownEventService.list().stream()
  220. .filter(i->StringUtils.empty(i.getStartTime()))
  221. .sorted(Comparator.comparing(ProEconShutdownEvent::getStopTime)).collect(Collectors.toList());
  222. for (ProEconShutdownEvent shutdown : oldShutdwonQuery)
  223. {
  224. if (oldShutdownEvent.containsKey(shutdown.getWindturbineId()))
  225. {
  226. oldShutdownEvent.put(shutdown.getWindturbineId(),shutdown);
  227. }
  228. }
  229. List<ProEconInterruption> oldInterrupQuery=proEconInterruptionService.list().stream()
  230. .filter(i->StringUtils.empty(i.getStartTime()))
  231. .sorted(Comparator.comparing(ProEconInterruption::getStopTime)).collect(Collectors.toList());
  232. for (ProEconInterruption interrup : oldInterrupQuery)
  233. {
  234. if (oldInterrup.containsKey(interrup.getWindturbineId()))
  235. {
  236. oldInterrup.put(interrup.getWindturbineId(),interrup);
  237. }
  238. }
  239. // 新增 shutdownevent2 实时
  240. List<ProEconShutdownEvent2> oldShutdwonQuery2=proEconShutdownEvent2Service.list().stream()
  241. .filter(i->StringUtils.empty(i.getStartTime()))
  242. .sorted(Comparator.comparing(ProEconShutdownEvent2::getStopTime)).collect(Collectors.toList());
  243. for (ProEconShutdownEvent2 shutdown : oldShutdwonQuery2)
  244. {
  245. if (oldShutdownEvent2.containsKey(shutdown.getWindturbineId()))
  246. {
  247. oldShutdownEvent2.put(shutdown.getWindturbineId(),shutdown);
  248. }
  249. }
  250. for (String s : oldStatusMap.keySet())
  251. {
  252. ProEconWindturbineStatus item = oldStatusMap.get(s);
  253. if (item == null)
  254. {
  255. //logger.debug("{0}重复加入 风机编号{1}", date,s);
  256. ProEconShutdownEvent shutdwonEvent=new ProEconShutdownEvent();
  257. ProEconInterruption interrup=new ProEconInterruption();
  258. //新增 shutdownevent2 实时
  259. ProEconShutdownEvent2 shutdwonEvent2=new ProEconShutdownEvent2();
  260. item = buildWindturbineStatus(s, date, shutdwonEvent, interrup, shutdwonEvent2);
  261. proEconWindturbineStatusService.save(item);
  262. proEconShutdownEventService.save(shutdwonEvent);
  263. proEconInterruptionService.save(interrup);
  264. // 新增 shutdownevent2 实时
  265. //20分钟以内的报警数据
  266. Date dtbegin = DateUtils.addMinutes(shutdwonEvent2.getStopTime(),-15);
  267. Date dtend = shutdwonEvent2.getStopTime();
  268. Optional<ProEconShutdownEvent2> olditemo= proEconShutdownEvent2Service.list().stream()
  269. .filter(i -> i.getWindturbineId().equals(s)
  270. && (i.getStartTime().compareTo(dtbegin) == 0 || i.getStartTime().after(dtbegin))
  271. && (i.getStartTime().compareTo(dtend) == 0 || i.getStartTime().before(dtend))
  272. ).min(Comparator.comparing(ProEconShutdownEvent2::getStartTime));
  273. ProEconShutdownEvent2 lditem;
  274. if (!olditemo.isPresent())
  275. {
  276. proEconShutdownEvent2Service.save(shutdwonEvent2);
  277. }
  278. else
  279. {
  280. lditem=olditemo.get();
  281. lditem.setStartTime(null);
  282. if (!oldShutdownEvent2.containsKey(lditem.getWindturbineId()))
  283. oldShutdownEvent2.put(lditem.getWindturbineId(), lditem);
  284. }
  285. continue;
  286. }
  287. Calendar c=Calendar.getInstance();
  288. c.setTime(date);
  289. if (c.get(Calendar.HOUR_OF_DAY) == 0 &&c.get(Calendar.MINUTE) == 0)
  290. {
  291. logger.debug("{0}--整点操作--{1}", s, date);
  292. updateAndAddStatus( item);
  293. }
  294. else if (!Objects.equals(item.getSatusCode(), status.get(s)))
  295. {
  296. updateAndAddStatus(item);
  297. // #region 切入切出风速
  298. if (item.getSatusCode() == 0 && status.get(s) == 2)
  299. {
  300. ProEconInputOrOutputSpeed input = new ProEconInputOrOutputSpeed();
  301. input.setWindturbineId(s);
  302. input.setWindpowerstationId(windTurbines.get(s).getWindpowerstationId());
  303. input.setProjectId(windTurbines.get(s).getProjectId());
  304. input.setLineId(windTurbines.get(s).getLineId());
  305. input.setRecordDate(date);
  306. input.setInputOrOutput(1);
  307. if (speedpointMap.containsKey(s))
  308. {
  309. double value =edosUtil.getRealData(speedpointMap.get(s).getNemCode()).getPointValueInDouble();
  310. input.setSpeed(value);
  311. }
  312. proEconInputOrOutputSpeedService.save(input);
  313. }
  314. else if (item.getSatusCode() == 1 && status.get(s)== 0)
  315. {
  316. ProEconInputOrOutputSpeed input = new ProEconInputOrOutputSpeed();
  317. input.setWindturbineId(s);
  318. input.setWindpowerstationId(windTurbines.get(s).getWindpowerstationId());
  319. input.setProjectId(windTurbines.get(s).getProjectId());
  320. input.setLineId(windTurbines.get(s).getLineId());
  321. input.setRecordDate(date);
  322. input.setInputOrOutput(0);
  323. if (speedpointMap.containsKey(s))
  324. {
  325. double value =edosUtil.getRealData(speedpointMap.get(s).getNemCode()).getPointValueInDouble();
  326. input.setSpeed(value);
  327. }
  328. proEconInputOrOutputSpeedService.save(input);
  329. }
  330. }
  331. updateAndAddStatus2(item);
  332. }
  333. logger.debug("{0}-------结束", date);
  334. }
  335. /// <summary>
  336. /// 计算损失电量
  337. /// </summary>
  338. /// <param name="entities"></param>
  339. /// <param name="status"></param>
  340. private void updateAndAddStatus2(ProEconWindturbineStatus status) throws Exception {
  341. Integer oldStatus = status.getSatusCode();
  342. if (oldStatus == 4 || oldStatus == 6)
  343. {
  344. ProEconShutdownEvent ose = oldShutdownEvent.get(status.getWindturbineId());
  345. if (ose != null)
  346. {
  347. Double gc = calcLossPower(ose.getWindturbineId(), ose.getStopTime(), date);
  348. ose.setLossPower(gc);
  349. }
  350. // 新增 shutdownevent2 实时
  351. ProEconShutdownEvent2 ose2 = oldShutdownEvent2.get(status.getWindturbineId());
  352. if (ose2 != null)
  353. {
  354. Double gc = calcLossPower(ose2.getWindturbineId(), ose2.getStopTime(), date);
  355. ose2.setLossPower(gc);
  356. }
  357. }
  358. }
  359. private void updateAndAddStatus( ProEconWindturbineStatus status) throws Exception {
  360. status.setStartTime(date);
  361. List<PointData> speedDataList1;
  362. if (windTurbines.get(status.getWindturbineId()).getWindpowerstationId().contains("GDC"))
  363. {
  364. String point=gzdpointMap.get(windTurbines.get(status.getWindturbineId()).getWindpowerstationId()).getNemCode();
  365. speedDataList1 =edosUtil.getHistoryDatasSnap(point,status.getStopTime().getTime()/1000,status.getStartTime().getTime()/1000);
  366. }
  367. else
  368. {
  369. String point=speedpointMap.get(status.getWindturbineId()).getNemCode();
  370. speedDataList1 =edosUtil.getHistoryDatasSnap(point,status.getStopTime().getTime()/1000,status.getStartTime().getTime()/1000);
  371. }
  372. if (speedDataList1 != null && speedDataList1.size() > 0)
  373. {
  374. status.setSpeed(speedDataList1.get(0).getPointValueInDouble());
  375. DoubleSummaryStatistics summaryStatistics=speedDataList1.stream().mapToDouble(PointData::getPointValueInDouble).summaryStatistics();
  376. status.setAvgSpeed(summaryStatistics.getAverage());
  377. }
  378. else
  379. {
  380. status.setSpeed(0.0);
  381. status.setAvgSpeed(0.0);
  382. }
  383. double timehour=DateUtils.hoursDiff2(date,status.getStopTime());
  384. status.setStopHours(timehour);
  385. ProEconShutdownEvent shutdwonEvent = new ProEconShutdownEvent();
  386. ProEconInterruption interrup = new ProEconInterruption();
  387. // #region 新增 shutdownevent2 实时
  388. ProEconShutdownEvent2 shutdwonEvent2 = new ProEconShutdownEvent2();
  389. ProEconWindturbineStatus newStatusItem = buildWindturbineStatus(status.getWindturbineId(), date, shutdwonEvent, interrup, shutdwonEvent2);
  390. proEconWindturbineStatusService.save(newStatusItem);
  391. Integer oldStatus = status.getSatusCode();
  392. Integer currentStatus = this.status.get(status.getWindturbineId());
  393. if (currentStatus == 4 || currentStatus == 6)
  394. {
  395. if (oldStatus == 0 || oldStatus == 1 || oldStatus == 12)
  396. {
  397. proEconShutdownEventService.save(shutdwonEvent);
  398. }
  399. }
  400. if (currentStatus == 12 && oldStatus != 12)
  401. {
  402. proEconInterruptionService.save(interrup);
  403. }
  404. // 新增 shutdownevent2 实时
  405. if (currentStatus == 4 || currentStatus == 6)
  406. {
  407. if (oldStatus == 0 || oldStatus == 1 || oldStatus == 12)
  408. {
  409. Date dtbegin = DateUtils.addMinutes(shutdwonEvent2.getStopTime(),-30);
  410. Date dtend = shutdwonEvent2.getStopTime();
  411. String windTurbineId = shutdwonEvent2.getWindturbineId();
  412. Optional<ProEconShutdownEvent2> olditem= proEconShutdownEvent2Service.list().stream()
  413. .filter(i -> i.getWindturbineId().equals(windTurbineId)
  414. && (i.getStartTime().compareTo(dtbegin) == 0 || i.getStartTime().after(dtbegin))
  415. && (i.getStartTime().compareTo(dtend) == 0 || i.getStartTime().before(dtend))
  416. ).min(Comparator.comparing(ProEconShutdownEvent2::getStartTime));
  417. ProEconShutdownEvent2 temp;
  418. if (!olditem.isPresent())
  419. {
  420. proEconShutdownEvent2Service.save(shutdwonEvent2);
  421. }
  422. else
  423. {
  424. temp=olditem.get();
  425. temp.setStartTime(null);
  426. if (!oldShutdownEvent2.containsKey(temp.getWindturbineId()))
  427. oldShutdownEvent2.put(temp.getWindturbineId(), temp);
  428. }
  429. }
  430. }
  431. if (oldStatus == 4 || oldStatus == 6)
  432. {
  433. if (currentStatus == 0 || currentStatus == 1 || currentStatus == 12)
  434. {
  435. ProEconShutdownEvent ose = oldShutdownEvent.get(status.getWindturbineId());
  436. if (ose != null)
  437. {
  438. ose.setStartTime(date);
  439. timehour=DateUtils.hoursDiff2(date,ose.getStopTime());
  440. ose.setStopHours(timehour);
  441. if (!ose.getStoptypeId().equals("wh"))
  442. {
  443. String s =newMethod( status.getWindturbineId(), DateUtils.addMinutes(ose.getStopTime(),-5), date);
  444. if (StringUtils.notEmp(s))
  445. {
  446. ose.setStoptypeId(s);
  447. }
  448. }
  449. //Double gc = calcLossPower(ose.WINDTURBINEID, ose.STOPTIME.Value, ose.STARTTIME.Value, ose.STOPHOURS.Value, entities);
  450. //ose.LOSSPOWER = gc;
  451. }
  452. // 新增 shutdownevent2 实时
  453. ProEconShutdownEvent2 ose2 = oldShutdownEvent2.get(status.getWindturbineId());
  454. if (ose2 != null )
  455. {
  456. ose2.setStartTime(date);
  457. timehour=DateUtils.hoursDiff2(date,ose2.getStopTime());
  458. ose2.setStopHours(timehour);
  459. if (ose!=null && !ose.getStoptypeId().equals("wh"))
  460. {
  461. ose2.setStopTypeId(ose.getStoptypeId());
  462. }
  463. }
  464. }
  465. }
  466. if (oldStatus == 12 && currentStatus != 12)
  467. {
  468. ProEconInterruption item = oldInterrup.get(status.getWindturbineId());
  469. if (item != null)
  470. {
  471. item.setStartTime(date);
  472. timehour=DateUtils.hoursDiff2(date,item.getStopTime());
  473. item.setStopHours(timehour);
  474. }
  475. }
  476. }
  477. private Double calcLossPower(String windturbineId, Date startDate, Date endDate) throws Exception {
  478. double result = 0.0;
  479. Map<String, Map<String, ProBasicEquipmentPoint>> wtpAimap = CacheContext.wtpAimap;
  480. Map<String, ProBasicEquipmentPoint> wtpointmap=wtpAimap.get(windturbineId);
  481. Calendar c1=Calendar.getInstance();
  482. c1.setTime(startDate);
  483. Calendar c2=Calendar.getInstance();
  484. c2.setTime(endDate);
  485. //判定限电是否跨年
  486. if(endDate.after(startDate) && c1.get(Calendar.YEAR)==c2.get(Calendar.YEAR))
  487. {
  488. //年故障损失电量
  489. if(wtpointmap.containsKey(ContantXk.NGZSSDL) )
  490. {
  491. double beginvalue;
  492. double endvalue;
  493. List<String> pointid=new ArrayList<>();
  494. pointid.add(wtpointmap.get(ContantXk.NGZSSDL).getNemCode());
  495. List<PointData> xdbegin=edosUtil.getHistMatrix(pointid,startDate.getTime()/1000);
  496. List<PointData> xdend=edosUtil.getHistMatrix(pointid,endDate.getTime()/1000);
  497. if(xdbegin.size()==1 && xdend.size()==1)
  498. {
  499. beginvalue=xdbegin.get(0).getPointValueInDouble();
  500. endvalue=xdend.get(0).getPointValueInDouble();
  501. if (endvalue > beginvalue) {
  502. result =result+(endvalue - beginvalue);
  503. }
  504. }
  505. }
  506. }else
  507. {
  508. Calendar c=Calendar.getInstance();
  509. c.setTime(DateUtils.truncDay(startDate));
  510. c.add(Calendar.DAY_OF_MONTH,1);
  511. //获得1月1日零点值
  512. Date endtime=c.getTime();
  513. //年故障损失电量
  514. if(wtpointmap.containsKey(ContantXk.NGZSSDL) )
  515. {
  516. double beginvalue;
  517. double endvalue;
  518. List<String> pointid=new ArrayList<>();
  519. pointid.add(wtpointmap.get(ContantXk.NGZSSDL).getNemCode());
  520. List<PointData> xdbegin=edosUtil.getHistMatrix(pointid,startDate.getTime()/1000);
  521. List<PointData> xdend=edosUtil.getHistMatrix(pointid,endtime.getTime()/1000);
  522. if(xdbegin.size()==1 && xdend.size()==1)
  523. {
  524. beginvalue=xdbegin.get(0).getPointValueInDouble();
  525. endvalue=xdend.get(0).getPointValueInDouble();
  526. if (endvalue > beginvalue) {
  527. result =result+(endvalue - beginvalue);
  528. }
  529. }
  530. }
  531. //日故障损失电量
  532. if(wtpointmap.containsKey(ContantXk.NGZSSDL) )
  533. {
  534. double endvalue;
  535. List<String> pointid=new ArrayList<>();
  536. pointid.add(wtpointmap.get(ContantXk.NGZSSDL).getNemCode());
  537. List<PointData> xdend=edosUtil.getHistMatrix(pointid,startDate.getTime()/1000);
  538. if(xdend.size()==1)
  539. {
  540. endvalue=xdend.get(0).getPointValueInDouble();
  541. if (endvalue > 0) {
  542. result =result+endvalue;
  543. }
  544. }
  545. }
  546. }
  547. return result;
  548. }
  549. // 新增 shutdownevent2 实时
  550. private ProEconWindturbineStatus buildWindturbineStatus(String windturbineId, Date date, ProEconShutdownEvent shutdwonEvent,
  551. ProEconInterruption interrup, ProEconShutdownEvent2 shutdwonEvent2)
  552. {
  553. ProEconWindturbineStatus retValue = new ProEconWindturbineStatus();
  554. retValue.setProjectId(windTurbines.get(windturbineId).getProjectId());
  555. retValue.setSatusCode(status.get(windturbineId));
  556. retValue.setStatusDesc(statusDescription.get(status.get(windturbineId)));
  557. retValue.setStopTime(date);
  558. retValue.setWindpowerstationId(windTurbines.get(windturbineId).getWindpowerstationId());
  559. retValue.setWindturbineId(windturbineId);
  560. Integer currentStatus = status.get(windturbineId);
  561. if (currentStatus == 4 || currentStatus == 6)
  562. {
  563. shutdwonEvent.setId(StringUtils.getUUID());
  564. shutdwonEvent.setProjectId(retValue.getProjectId());
  565. shutdwonEvent.setStatusCode(currentStatus);
  566. shutdwonEvent.setStopTime(date);
  567. shutdwonEvent.setWindpowerstationId(retValue.getWindpowerstationId());
  568. shutdwonEvent.setWindturbineId(windturbineId);
  569. shutdwonEvent2.setId(StringUtils.getUUID());
  570. shutdwonEvent2.setProjectId(retValue.getProjectId());
  571. shutdwonEvent2.setStatusCode(currentStatus);
  572. shutdwonEvent2.setStopTime(date);
  573. shutdwonEvent2.setWinpowerstationId(retValue.getWindpowerstationId());
  574. shutdwonEvent2.setWindturbineId(windturbineId);
  575. if (currentStatus == 4)
  576. {
  577. Date begin =DateUtils.addMinutes(date,-5);
  578. Date end = DateUtils.addMinutes(date,5);
  579. shutdwonEvent.setStoptypeId("gzbmq");
  580. shutdwonEvent2.setStopTypeId("gzbmq");
  581. //读取报警记录表前后五分钟数据,选取第一个报警报警类型
  582. String s =newMethod( windturbineId, begin, end);
  583. if (StringUtils.notEmp(s))
  584. {
  585. shutdwonEvent.setStoptypeId(s);
  586. shutdwonEvent2.setStopTypeId(s);
  587. }
  588. }
  589. else
  590. {
  591. shutdwonEvent.setStoptypeId("wh");
  592. shutdwonEvent2.setStopTypeId("wh");
  593. }
  594. retValue.setShutdownEventId(shutdwonEvent.getId());
  595. }
  596. if (currentStatus == 12)
  597. {
  598. interrup.setProjectId(retValue.getProjectId());
  599. interrup.setStopTime(date);
  600. interrup.setWindpowerstationId(retValue.getWindpowerstationId());
  601. interrup.setWindturbineId(windturbineId);
  602. }
  603. return retValue;
  604. }
  605. //TODO-SL 需要添加报警记录关联停机事件方法
  606. /**
  607. *
  608. */
  609. private String newMethod( String windturbineId, Date begin, Date end)
  610. {
  611. String result = "";
  612. return result;
  613. }
  614. }