ShutdownnewService.java 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. package com.gyee.generation.service;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  4. import com.gyee.common.contant.ContantXk;
  5. import com.gyee.common.model.PointData;
  6. import com.gyee.generation.feign.AdapterApi;
  7. import com.gyee.generation.init.CacheContext;
  8. import com.gyee.generation.mapper.auto.AlarmTsMapper;
  9. import com.gyee.generation.model.PointData2;
  10. import com.gyee.generation.model.auto.*;
  11. import com.gyee.generation.model.vo.AlarmSuperTalbeType;
  12. import com.gyee.generation.model.vo.AlarmVo;
  13. import com.gyee.generation.model.vo.StatusDetailValue;
  14. import com.gyee.generation.service.auto.IProEconInterruptionService;
  15. import com.gyee.generation.service.auto.IProEconShutdownEvent2Service;
  16. import com.gyee.generation.service.auto.IProEconShutdownEventService;
  17. import com.gyee.generation.service.auto.IProEconWindturbineStatusService;
  18. import com.gyee.generation.util.DateUtils;
  19. import com.gyee.generation.util.StringUtils;
  20. import com.gyee.generation.util.realtimesource.IEdosUtil;
  21. import com.gyee.generation.util.realtimesource.StringUtil;
  22. import org.slf4j.Logger;
  23. import org.slf4j.LoggerFactory;
  24. import org.springframework.stereotype.Service;
  25. import javax.annotation.Resource;
  26. import java.net.URI;
  27. import java.util.*;
  28. import java.util.concurrent.Executor;
  29. import java.util.stream.Collectors;
  30. @Service
  31. public class ShutdownnewService {
  32. @Resource
  33. private IEdosUtil edosUtil;
  34. @Resource
  35. private IProEconWindturbineStatusService proEconWindturbineStatusService;
  36. @Resource
  37. private IProEconShutdownEventService proEconShutdownEventService;
  38. @Resource
  39. private IProEconShutdownEvent2Service proEconShutdownEvent2Service;
  40. @Resource
  41. private IProEconInterruptionService proEconInterruptionService;
  42. @Resource
  43. private AlarmTsMapper alarmTsMapper;
  44. public static Logger logger = LoggerFactory.getLogger(ShutdownnewService.class);
  45. @Resource
  46. private AdapterApi adapter;
  47. public URI goldenUri() {
  48. return URI.create("http://10.220.1.8:8011/ts");
  49. }
  50. // public URI goldenUri() {
  51. // return URI.create("http://10.220.1.241:8011/ts");
  52. // }
  53. public void execShutdown(Date recordDate) throws Exception {
  54. List<String> wtStatusIdLs = new ArrayList<>();
  55. Map<String, PointData2> wtStatusMap = new HashMap<>();
  56. Map<String, ProEconWindturbineStatus> oldStatusMap = new HashMap<>();
  57. Map<String, ProEconShutdownEvent> oldShutdownEvent = new HashMap<>();
  58. Map<String, ProEconInterruption> oldInterrup = new HashMap<>();
  59. Map<String, ProEconShutdownEvent2> oldShutdownEvent2 = new HashMap<>();
  60. List<ProBasicEquipment> wtls = new ArrayList<>();
  61. wtls.addAll(CacheContext.wtls);
  62. for (ProBasicEquipment wt : wtls) {
  63. Map<String, ProBasicEquipmentPoint> windturbinetestingpointnewMap = CacheContext.wtpAimap.get(wt.getId());
  64. //取实时状态数据 赋值给status
  65. if (windturbinetestingpointnewMap.containsKey(ContantXk.MXZT)) {
  66. ProBasicEquipmentPoint mxztPoint = windturbinetestingpointnewMap.get(ContantXk.MXZT);
  67. wtStatusIdLs.add(mxztPoint.getNemCode());
  68. }
  69. //初始化将所有风机编号作为key,value全部赋值为null
  70. oldStatusMap.put(wt.getId(), null);
  71. oldShutdownEvent.put(wt.getId(), null);
  72. oldInterrup.put(wt.getId(), null);
  73. oldShutdownEvent2.put(wt.getId(), null);
  74. }
  75. // List<PointData> wtStatusLs = edosUtil.getHistMatrix(wtStatusIdLs, recordDate.getTime() / 1000);
  76. String tagNameString = StringUtil.join(wtStatusIdLs, ",");
  77. Map<String, PointData2> wtStatusLs = adapter.getHistorySection(goldenUri(), tagNameString, recordDate.getTime());
  78. if (wtStatusLs.values().size() == wtls.size()) {
  79. for (int i = 0; i < wtls.size(); i++) {
  80. ProBasicEquipment wt = wtls.get(i);
  81. wtStatusMap.put(wt.getId(), wtStatusLs.get(wtStatusIdLs.get(i)));
  82. }
  83. }
  84. //******************************************************************************************************/
  85. //读取数据库存在的恢复时间为NULL的数据,并通过风机编号把数据遍历到对应的map
  86. QueryWrapper<ProEconWindturbineStatus> queryWrapper = new QueryWrapper<>();
  87. queryWrapper.isNull("start_Time");
  88. queryWrapper.orderByDesc("stop_Time");
  89. List<ProEconWindturbineStatus> oldStatusQuery = proEconWindturbineStatusService.list(queryWrapper).stream().collect(Collectors.toList());
  90. for (ProEconWindturbineStatus oldStatus : oldStatusQuery) {
  91. if (oldStatusMap.containsKey(oldStatus.getWindturbineId())) {
  92. oldStatusMap.put(oldStatus.getWindturbineId(), oldStatus);
  93. }
  94. }
  95. QueryWrapper<ProEconShutdownEvent> queryWrapper2 = new QueryWrapper<>();
  96. queryWrapper2.isNull("start_Time");
  97. queryWrapper2.orderByDesc("stop_Time");
  98. List<ProEconShutdownEvent> oldShutdwonQuery = proEconShutdownEventService.list(queryWrapper2).stream().collect(Collectors.toList());
  99. for (ProEconShutdownEvent shutdown : oldShutdwonQuery) {
  100. if (oldShutdownEvent.containsKey(shutdown.getWindturbineId())) {
  101. oldShutdownEvent.put(shutdown.getWindturbineId(), shutdown);
  102. }
  103. }
  104. QueryWrapper<ProEconInterruption> queryWrapper3 = new QueryWrapper<>();
  105. queryWrapper3.isNull("start_Time");
  106. queryWrapper3.orderByDesc("stop_Time");
  107. List<ProEconInterruption> oldInterrupQuery = proEconInterruptionService.list(queryWrapper3).stream().collect(Collectors.toList());
  108. for (ProEconInterruption interrup : oldInterrupQuery) {
  109. if (oldInterrup.containsKey(interrup.getWindturbineId())) {
  110. oldInterrup.put(interrup.getWindturbineId(), interrup);
  111. }
  112. }
  113. QueryWrapper<ProEconShutdownEvent2> queryWrapper4 = new QueryWrapper<>();
  114. queryWrapper4.isNull("start_Time");
  115. queryWrapper4.orderByDesc("stop_Time");
  116. List<ProEconShutdownEvent2> oldShutdwonQuery2 = proEconShutdownEvent2Service.list(queryWrapper4).stream().collect(Collectors.toList());
  117. for (ProEconShutdownEvent2 shutdown : oldShutdwonQuery2) {
  118. if (oldShutdownEvent2.containsKey(shutdown.getWindturbineId())) {
  119. oldShutdownEvent2.put(shutdown.getWindturbineId(), shutdown);
  120. }
  121. }
  122. //******************************************************************************************************/
  123. List<ProEconShutdownEvent> updateProEconShutdownEventls = new ArrayList<>();
  124. List<ProEconShutdownEvent2> updateProEconShutdownEvent2ls = new ArrayList<>();
  125. List<ProEconInterruption> updateProEconInterruptionls = new ArrayList<>();
  126. List<ProEconWindturbineStatus> updateProEconWindturbineStatusls = new ArrayList<>();
  127. List<ProEconShutdownEvent> insertProEconShutdownEventls = new ArrayList<>();
  128. List<ProEconShutdownEvent2> insertProEconShutdownEvent2ls = new ArrayList<>();
  129. List<ProEconInterruption> insertProEconInterruptionls = new ArrayList<>();
  130. List<ProEconWindturbineStatus> insertProEconWindturbineStatusls = new ArrayList<>();
  131. //遍历PG数据库中存在的记录,恢复时间为空的集合
  132. for (String wtId : oldStatusMap.keySet()) {
  133. ProEconShutdownEvent shutdwonEvent = null;
  134. ProEconInterruption interrup = null;
  135. ProEconShutdownEvent2 shutdwonEvent2 = null;
  136. ProEconWindturbineStatus item = null;
  137. if (oldStatusMap.containsKey(wtId)) {
  138. item = oldStatusMap.get(wtId);
  139. }
  140. if (oldShutdownEvent.containsKey(wtId)) {
  141. // if(wtId.equals("SXJ_KGDL_HSM_F_WT_0021_EQ"))
  142. // {
  143. // System.out.println("");
  144. // }
  145. shutdwonEvent = oldShutdownEvent.get(wtId);
  146. }
  147. if (oldShutdownEvent2.containsKey(wtId)) {
  148. shutdwonEvent2 = oldShutdownEvent2.get(wtId);
  149. }
  150. if (oldInterrup.containsKey(wtId)) {
  151. interrup = oldInterrup.get(wtId);
  152. }
  153. if (wtStatusMap.containsKey(wtId)) {
  154. // if(wtId.equals("SXJ_KGDL_YF_F_WT_0043_EQ"))
  155. // {
  156. // System.out.println("");
  157. // }
  158. PointData2 wtPoint = wtStatusMap.get(wtId);
  159. //获取当前时间
  160. Date currentTime = recordDate;
  161. if (StringUtils.empty(item)) {
  162. item = new ProEconWindturbineStatus();
  163. initalWindturbineStatus(insertProEconWindturbineStatusls, wtId, wtStatusMap, currentTime, item);
  164. } else if (StringUtils.notEmp(item) && wtPoint.getValue() != item.getSatusCode()) {
  165. finishWindturbineStatus(updateProEconWindturbineStatusls, wtId, currentTime, item);
  166. }
  167. if (wtPoint.getValue() == StatusDetailValue.TXZD.getCode()) {
  168. if (StringUtils.empty(interrup)) {
  169. interrup = new ProEconInterruption();
  170. initalInterruption(insertProEconInterruptionls, wtId, currentTime, interrup);
  171. }
  172. } else if (StringUtils.notEmp(interrup)) {
  173. finishInterruption(updateProEconInterruptionls, wtId, currentTime, interrup);
  174. }
  175. if (wtPoint.getValue() == StatusDetailValue.GZ.getCode()) {
  176. if (StringUtils.empty(shutdwonEvent)) {
  177. shutdwonEvent = new ProEconShutdownEvent();
  178. initalShutdownEvent(insertProEconShutdownEventls, wtId, wtStatusMap, currentTime, shutdwonEvent);
  179. }
  180. if (StringUtils.empty(shutdwonEvent2)) {
  181. shutdwonEvent2 = new ProEconShutdownEvent2();
  182. initalShutdownEvent2(insertProEconShutdownEvent2ls, wtId, wtStatusMap, currentTime, shutdwonEvent2);
  183. }
  184. } else {
  185. if (StringUtils.notEmp(shutdwonEvent) && shutdwonEvent.getStatusCode() != wtPoint.getValue()) {
  186. finishShutdownEvent(updateProEconShutdownEventls, wtId, wtStatusMap, currentTime, shutdwonEvent);
  187. }
  188. if (StringUtils.notEmp(shutdwonEvent2) && shutdwonEvent2.getStatusCode() != wtPoint.getValue()) {
  189. finishShutdownEvent2(updateProEconShutdownEvent2ls, wtId, wtStatusMap, currentTime, shutdwonEvent2);
  190. }
  191. }
  192. if (wtPoint.getValue() == StatusDetailValue.JX.getCode()) {
  193. if (StringUtils.empty(shutdwonEvent)) {
  194. shutdwonEvent = new ProEconShutdownEvent();
  195. initalShutdownEvent(insertProEconShutdownEventls, wtId, wtStatusMap, currentTime, shutdwonEvent);
  196. }
  197. if (StringUtils.empty(shutdwonEvent2)) {
  198. shutdwonEvent2 = new ProEconShutdownEvent2();
  199. initalShutdownEvent2(insertProEconShutdownEvent2ls, wtId, wtStatusMap, currentTime, shutdwonEvent2);
  200. }
  201. } else {
  202. if (StringUtils.notEmp(shutdwonEvent) && shutdwonEvent.getStatusCode() != wtPoint.getValue()) {
  203. finishShutdownEvent(updateProEconShutdownEventls, wtId, wtStatusMap, currentTime, shutdwonEvent);
  204. }
  205. if (StringUtils.notEmp(shutdwonEvent2) && shutdwonEvent2.getStatusCode() != wtPoint.getValue()) {
  206. finishShutdownEvent2(updateProEconShutdownEvent2ls, wtId, wtStatusMap, currentTime, shutdwonEvent2);
  207. }
  208. }
  209. }
  210. }
  211. for (ProEconShutdownEvent vo : updateProEconShutdownEventls) {
  212. UpdateWrapper<ProEconShutdownEvent> updateWrapper = new UpdateWrapper<>();
  213. // updateWrapper.set("start_time", vo.getStartTime());
  214. // updateWrapper.set("loss_power", vo.getLossPower());
  215. // updateWrapper.set("stop_hours", vo.getStopHours());
  216. // proEconShutdownEventService.update(vo, updateWrapper);
  217. proEconShutdownEventService.updateShutdownevent(vo.getStartTime(), vo.getLossPower(), vo.getStopHours(), vo.getId());
  218. }
  219. for (ProEconShutdownEvent2 vo : updateProEconShutdownEvent2ls) {
  220. UpdateWrapper<ProEconShutdownEvent2> updateWrapper = new UpdateWrapper<>();
  221. // updateWrapper.set("start_time", vo.getStartTime());
  222. // updateWrapper.set("loss_power", vo.getLossPower());
  223. // updateWrapper.set("stop_hours", vo.getStopHours());
  224. // proEconShutdownEvent2Service.update(vo, updateWrapper);
  225. proEconShutdownEvent2Service.updateShutdownevent2(vo.getStartTime(), vo.getLossPower(), vo.getStopHours(), vo.getId());
  226. }
  227. for (ProEconWindturbineStatus vo : updateProEconWindturbineStatusls) {
  228. UpdateWrapper<ProEconWindturbineStatus> updateWrapper = new UpdateWrapper<>();
  229. // updateWrapper.set("start_time", vo.getStartTime());
  230. // updateWrapper.set("loss_power", vo.getLossPower());
  231. // updateWrapper.set("stop_hours", vo.getStopHours());
  232. // proEconWindturbineStatusService.update(vo, updateWrapper);
  233. proEconWindturbineStatusService.updateWindturbineStatus(vo.getStartTime(), vo.getLossPower(), vo.getStopHours(), vo.getId());
  234. }
  235. for (ProEconInterruption vo : updateProEconInterruptionls) {
  236. UpdateWrapper<ProEconInterruption> updateWrapper = new UpdateWrapper<>();
  237. // updateWrapper.set("start_time", vo.getStartTime());
  238. // updateWrapper.set("stop_hours", vo.getStopHours());
  239. // proEconInterruptionService.update(vo, updateWrapper);
  240. proEconInterruptionService.updateInterruption(vo.getStartTime(), vo.getStopHours(), vo.getId());
  241. }
  242. List<ProEconWindturbineStatus> temp1ls = new ArrayList<>();
  243. for (ProEconWindturbineStatus vo : insertProEconWindturbineStatusls) {
  244. temp1ls.add(vo);
  245. if (temp1ls.size() == 100) {
  246. proEconWindturbineStatusService.saveBatch(temp1ls);
  247. temp1ls = new ArrayList<>();
  248. }
  249. }
  250. if (!temp1ls.isEmpty()) {
  251. proEconWindturbineStatusService.saveBatch(temp1ls);
  252. }
  253. List<ProEconInterruption> temp2ls = new ArrayList<>();
  254. for (ProEconInterruption vo : insertProEconInterruptionls) {
  255. temp2ls.add(vo);
  256. if (temp2ls.size() == 100) {
  257. proEconInterruptionService.saveBatch(temp2ls);
  258. temp2ls = new ArrayList<>();
  259. }
  260. }
  261. if (!temp2ls.isEmpty()) {
  262. proEconInterruptionService.saveBatch(temp2ls);
  263. }
  264. List<ProEconShutdownEvent> temp3ls = new ArrayList<>();
  265. for (ProEconShutdownEvent vo : insertProEconShutdownEventls) {
  266. temp3ls.add(vo);
  267. if (temp3ls.size() == 100) {
  268. proEconShutdownEventService.saveBatch(temp3ls);
  269. temp3ls = new ArrayList<>();
  270. }
  271. }
  272. if (!temp3ls.isEmpty()) {
  273. proEconShutdownEventService.saveBatch(temp3ls);
  274. }
  275. List<ProEconShutdownEvent2> temp4ls = new ArrayList<>();
  276. for (ProEconShutdownEvent2 vo : insertProEconShutdownEvent2ls) {
  277. temp4ls.add(vo);
  278. if (temp4ls.size() == 100) {
  279. proEconShutdownEvent2Service.saveBatch(temp4ls);
  280. temp4ls = new ArrayList<>();
  281. }
  282. }
  283. if (!temp4ls.isEmpty()) {
  284. proEconShutdownEvent2Service.saveBatch(temp4ls);
  285. }
  286. //******************************************************************************************************/
  287. }
  288. private void finishShutdownEvent(List<ProEconShutdownEvent> updateProEconShutdownEventls,
  289. String wtId, Map<String, PointData2> wtStatusMap, Date currentTime, ProEconShutdownEvent item) throws Exception {
  290. if (item.getStatusCode() != wtStatusMap.get(wtId).getValue()) {
  291. item.setStartTime(currentTime);
  292. double timehour = DateUtils.hoursDiff2(item.getStartTime(), item.getStopTime());
  293. item.setStopHours(timehour);
  294. double losspower = calLossPower(wtId, item.getStartTime(), item.getStopTime());
  295. item.setLossPower(losspower);
  296. updateProEconShutdownEventls.add(item);
  297. }
  298. }
  299. private void finishShutdownEvent2(List<ProEconShutdownEvent2> insertProEconShutdownEvent2ls,
  300. String wtId, Map<String, PointData2> wtStatusMap, Date currentTime, ProEconShutdownEvent2 item) throws Exception {
  301. if (item.getStatusCode() != wtStatusMap.get(wtId).getValue()) {
  302. item.setStartTime(currentTime);
  303. double timehour = DateUtils.hoursDiff2(item.getStartTime(), item.getStopTime());
  304. item.setStopHours(timehour);
  305. double losspower = calLossPower(wtId, item.getStartTime(), item.getStopTime());
  306. item.setLossPower(losspower);
  307. if (timehour <= 24) {
  308. insertProEconShutdownEvent2ls.add(item);
  309. } else {
  310. int days = DateUtils.daysDiff1(item.getStartTime(), item.getStopTime());
  311. Calendar c = Calendar.getInstance();
  312. Date startTime = item.getStartTime();
  313. c.setTime(item.getStopTime());
  314. c.set(Calendar.HOUR_OF_DAY, 23);
  315. c.set(Calendar.MINUTE, 59);
  316. c.set(Calendar.SECOND, 59);
  317. for (int i = 0; i < days; i++) {
  318. if (i == 0) {
  319. item.setStartTime(c.getTime());
  320. losspower = calLossPower(wtId, item.getStartTime(), item.getStopTime());
  321. item.setLossPower(losspower);
  322. insertProEconShutdownEvent2ls.add(item);
  323. } else {
  324. ProEconShutdownEvent2 newto = initalShutdownEventnew2(wtId, wtStatusMap, DateUtils.truncate(c.getTime()));
  325. if (i == days - 1) {
  326. newto.setStartTime(startTime);
  327. } else {
  328. newto.setStartTime(c.getTime());
  329. }
  330. losspower = calLossPower(wtId, newto.getStartTime(), newto.getStopTime());
  331. newto.setLossPower(losspower);
  332. insertProEconShutdownEvent2ls.add(newto);
  333. }
  334. c.add(Calendar.DAY_OF_MONTH, 1);
  335. }
  336. }
  337. }
  338. }
  339. private void initalShutdownEvent2(List<ProEconShutdownEvent2> insertProEconShutdownEvent2ls,
  340. String wtId, Map<String, PointData2> wtStatusMap, Date currentTime, ProEconShutdownEvent2 item) {
  341. item.setId(StringUtils.getUUID());
  342. item.setProjectId(CacheContext.wtmap.get(wtId).getProjectId());
  343. item.setStatusCode((int) wtStatusMap.get(wtId).getValue());
  344. item.setStopTime(currentTime);
  345. item.setWinpowerstationId(CacheContext.wtmap.get(wtId).getWindpowerstationId());
  346. item.setWindturbineId(wtId);
  347. if (wtStatusMap.get(wtId).getValue() == StatusDetailValue.GZ.getCode()) {
  348. item.setStopTypeId("gz");
  349. //读取报警记录表前后五分钟数据,选取第一个报警报警类型
  350. List<AlarmVo> vos = alarmTsMapper.selectLastRowByDeviceid(AlarmSuperTalbeType.WT.getCode(), wtId);
  351. if (!vos.isEmpty()) {
  352. AlarmVo vo = vos.get(0);
  353. if (StringUtils.notEmp(vo.getAlarmid())) {
  354. item.setWarningId(vo.getAlarmid());
  355. }
  356. if (StringUtils.notEmp(vo.getDescription())) {
  357. item.setFaultView(vo.getDescription());
  358. }
  359. if (StringUtils.notEmp(vo.getFaultCause())) {
  360. item.setFaultView(vo.getFaultCause());
  361. }
  362. if (StringUtils.notEmp(vo.getResolvent())) {
  363. item.setHandleWay(vo.getResolvent());
  364. }
  365. }
  366. } else if (wtStatusMap.get(wtId).getValue() == StatusDetailValue.JX.getCode()) {
  367. item.setStopTypeId("wh");
  368. }
  369. insertProEconShutdownEvent2ls.add(item);
  370. }
  371. private ProEconShutdownEvent2 initalShutdownEventnew2(String wtId, Map<String, PointData2> wtStatusMap, Date currentTime) {
  372. ProEconShutdownEvent2 item = new ProEconShutdownEvent2();
  373. item.setId(StringUtils.getUUID());
  374. item.setProjectId(CacheContext.wtmap.get(wtId).getProjectId());
  375. item.setStatusCode((int) wtStatusMap.get(wtId).getValue());
  376. item.setStopTime(currentTime);
  377. item.setWinpowerstationId(CacheContext.wtmap.get(wtId).getWindpowerstationId());
  378. item.setWindturbineId(wtId);
  379. if (wtStatusMap.get(wtId).getValue() == StatusDetailValue.GZ.getCode()) {
  380. item.setStopTypeId("gz");
  381. //读取报警记录表前后五分钟数据,选取第一个报警报警类型
  382. List<AlarmVo> vos = alarmTsMapper.selectLastRowByDeviceid(AlarmSuperTalbeType.WT.getCode(), wtId);
  383. if (!vos.isEmpty()) {
  384. AlarmVo vo = vos.get(0);
  385. if (StringUtils.notEmp(vo.getAlarmid())) {
  386. item.setWarningId(vo.getAlarmid());
  387. }
  388. if (StringUtils.notEmp(vo.getDescription())) {
  389. item.setFaultView(vo.getDescription());
  390. }
  391. if (StringUtils.notEmp(vo.getFaultCause())) {
  392. item.setFaultView(vo.getFaultCause());
  393. }
  394. if (StringUtils.notEmp(vo.getResolvent())) {
  395. item.setHandleWay(vo.getResolvent());
  396. }
  397. }
  398. } else if (wtStatusMap.get(wtId).getValue() == StatusDetailValue.JX.getCode()) {
  399. item.setStopTypeId("wh");
  400. }
  401. return item;
  402. }
  403. private void initalShutdownEvent(List<ProEconShutdownEvent> insertProEconShutdownEventls,
  404. String wtId, Map<String, PointData2> wtStatusMap, Date currentTime, ProEconShutdownEvent item) {
  405. item.setId(StringUtils.getUUID());
  406. item.setProjectId(CacheContext.wtmap.get(wtId).getProjectId());
  407. item.setStatusCode((int) wtStatusMap.get(wtId).getValue());
  408. item.setStopTime(currentTime);
  409. item.setWindpowerstationId(CacheContext.wtmap.get(wtId).getWindpowerstationId());
  410. item.setWindturbineId(wtId);
  411. if (wtStatusMap.get(wtId).getValue() == StatusDetailValue.GZ.getCode()) {
  412. item.setStoptypeId("gz");
  413. //读取报警记录表前后五分钟数据,选取第一个报警报警类型
  414. List<AlarmVo> vos = alarmTsMapper.selectLastRowByDeviceid(AlarmSuperTalbeType.WT.getCode(), wtId);
  415. if (!vos.isEmpty()) {
  416. AlarmVo vo = vos.get(0);
  417. if (StringUtils.notEmp(vo.getAlarmid())) {
  418. item.setWarningId(vo.getAlarmid());
  419. }
  420. if (StringUtils.notEmp(vo.getDescription())) {
  421. item.setFaultView(vo.getDescription());
  422. }
  423. if (StringUtils.notEmp(vo.getFaultCause())) {
  424. item.setFaultView(vo.getFaultCause());
  425. }
  426. if (StringUtils.notEmp(vo.getResolvent())) {
  427. item.setHandleWay(vo.getResolvent());
  428. }
  429. }
  430. } else if (wtStatusMap.get(wtId).getValue() == StatusDetailValue.JX.getCode()) {
  431. item.setStoptypeId("wh");
  432. }
  433. insertProEconShutdownEventls.add(item);
  434. }
  435. private void initalWindturbineStatus(List<ProEconWindturbineStatus> insertProEconWindturbineStatusls,
  436. String wtId, Map<String, PointData2> wtStatusMap, Date currentTime, ProEconWindturbineStatus item) {
  437. item.setProjectId(CacheContext.wtmap.get(wtId).getProjectId());
  438. item.setSatusCode((int) wtStatusMap.get(wtId).getValue());
  439. item.setStatusDesc(StatusDetailValue.getNmaeByCode(wtStatusMap.get(wtId).getValue()));
  440. item.setStopTime(currentTime);
  441. item.setWindpowerstationId(CacheContext.wtmap.get(wtId).getWindpowerstationId());
  442. item.setWindturbineId(wtId);
  443. insertProEconWindturbineStatusls.add(item);
  444. }
  445. private void finishWindturbineStatus(List<ProEconWindturbineStatus> updateProEconWindturbineStatusls,
  446. String wtId, Date currentTime, ProEconWindturbineStatus item) throws Exception {
  447. item.setStartTime(currentTime);
  448. double timehour = DateUtils.hoursDiff2(item.getStartTime(), item.getStopTime());
  449. item.setStopHours(timehour);
  450. double losspower = calLossPower(wtId, item.getStartTime(), item.getStopTime());
  451. item.setLossPower(losspower);
  452. updateProEconWindturbineStatusls.add(item);
  453. }
  454. private void initalInterruption(List<ProEconInterruption> insertProEconWindturbineStatusls,
  455. String wtId, Date currentTime, ProEconInterruption item) {
  456. item.setProjectId(CacheContext.wtmap.get(wtId).getProjectId());
  457. item.setStopTime(currentTime);
  458. item.setWindpowerstationId(CacheContext.wtmap.get(wtId).getWindpowerstationId());
  459. item.setWindturbineId(wtId);
  460. insertProEconWindturbineStatusls.add(item);
  461. }
  462. private void finishInterruption(List<ProEconInterruption> updateProEconWindturbineStatusls,
  463. String wtId, Date currentTime, ProEconInterruption item) {
  464. item.setStartTime(currentTime);
  465. double timehour = DateUtils.hoursDiff2(item.getStartTime(), item.getStopTime());
  466. item.setStopHours(timehour);
  467. updateProEconWindturbineStatusls.add(item);
  468. }
  469. private Double calLossPower(String windturbineId, Date startDate, Date endDate) throws Exception {
  470. double result = 0.0;
  471. Map<String, Map<String, ProBasicEquipmentPoint>> wtpAimap = CacheContext.wtpAimap;
  472. Map<String, ProBasicEquipmentPoint> wtpointmap = wtpAimap.get(windturbineId);
  473. Calendar c1 = Calendar.getInstance();
  474. c1.setTime(startDate);
  475. Calendar c2 = Calendar.getInstance();
  476. c2.setTime(endDate);
  477. //判定限电是否跨年
  478. if (endDate.after(startDate) && c1.get(Calendar.YEAR) == c2.get(Calendar.YEAR)) {
  479. //年故障损失电量
  480. if (wtpointmap.containsKey(ContantXk.NGZSSDL)) {
  481. double beginvalue;
  482. double endvalue;
  483. List<String> pointid = new ArrayList<>();
  484. pointid.add(wtpointmap.get(ContantXk.NGZSSDL).getNemCode());
  485. List<PointData> xdbegin = edosUtil.getHistMatrix(pointid, startDate.getTime() / 1000);
  486. List<PointData> xdend = edosUtil.getHistMatrix(pointid, endDate.getTime() / 1000);
  487. if (xdbegin.size() == 1 && xdend.size() == 1) {
  488. beginvalue = xdbegin.get(0).getPointValueInDouble();
  489. endvalue = xdend.get(0).getPointValueInDouble();
  490. if (endvalue > beginvalue) {
  491. result = result + (endvalue - beginvalue);
  492. }
  493. }
  494. }
  495. } else {
  496. Calendar c = Calendar.getInstance();
  497. c.setTime(DateUtils.truncate(startDate));
  498. c.add(Calendar.DAY_OF_MONTH, 1);
  499. //获得1月1日零点值
  500. Date endtime = c.getTime();
  501. //年故障损失电量
  502. if (wtpointmap.containsKey(ContantXk.NGZSSDL)) {
  503. double beginvalue;
  504. double endvalue;
  505. List<String> pointid = new ArrayList<>();
  506. pointid.add(wtpointmap.get(ContantXk.NGZSSDL).getNemCode());
  507. List<PointData> xdbegin = edosUtil.getHistMatrix(pointid, startDate.getTime() / 1000);
  508. List<PointData> xdend = edosUtil.getHistMatrix(pointid, endtime.getTime() / 1000);
  509. if (xdbegin.size() == 1 && xdend.size() == 1) {
  510. beginvalue = xdbegin.get(0).getPointValueInDouble();
  511. endvalue = xdend.get(0).getPointValueInDouble();
  512. if (endvalue > beginvalue) {
  513. result = result + (endvalue - beginvalue);
  514. }
  515. }
  516. }
  517. //日故障损失电量
  518. if (wtpointmap.containsKey(ContantXk.NGZSSDL)) {
  519. double endvalue;
  520. List<String> pointid = new ArrayList<>();
  521. pointid.add(wtpointmap.get(ContantXk.NGZSSDL).getNemCode());
  522. List<PointData> xdend = edosUtil.getHistMatrix(pointid, startDate.getTime() / 1000);
  523. if (xdend.size() == 1) {
  524. endvalue = xdend.get(0).getPointValueInDouble();
  525. if (endvalue > 0) {
  526. result = result + endvalue;
  527. }
  528. }
  529. }
  530. }
  531. return result;
  532. }
  533. }