WindPowerInfo6Service.java 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. package com.gyee.generation.service;//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.model.vo.Location;
  7. import com.gyee.generation.service.auto.IProEconPowerstationInfoDay6Service;
  8. import com.gyee.generation.util.DateUtils;
  9. import com.gyee.generation.util.StringUtils;
  10. import com.gyee.generation.util.realtimesource.IEdosUtil;
  11. import com.gyee.generation.util.statisticcs.Initial;
  12. import org.springframework.beans.factory.annotation.Value;
  13. import org.springframework.stereotype.Service;
  14. import javax.annotation.Resource;
  15. import java.math.BigDecimal;
  16. import java.math.RoundingMode;
  17. import java.util.*;
  18. import java.util.stream.Collectors;
  19. @Service
  20. public class WindPowerInfo6Service {
  21. // private static final Logger logger = LoggerFactory.getLogger(WindPowerInfo1Service.class);
  22. @Resource
  23. private IEdosUtil edosUtil;
  24. @Resource
  25. private IProEconPowerstationInfoDay6Service proEconPowerstationInfoDay6Service;
  26. @Value("${initialcode}")
  27. private String initialcode;
  28. /**
  29. * 计算区域日信息
  30. */
  31. public void calRegionInfoDay(Date recordDate) {
  32. List<ProEconPowerstationInfoDay6> wpinfodayls = proEconPowerstationInfoDay6Service.list().stream()
  33. .filter(i -> i.getRecordDate().compareTo(DateUtils.truncDay(recordDate))==0
  34. // && CacheContext.wpmap.containsKey(i.getWindpowerstationId())
  35. && i.getLocation().equals(Location.cp.getValue()))
  36. .collect(Collectors.toList());
  37. if(!wpinfodayls.isEmpty())
  38. {
  39. Map<String, Map<String, List<ProEconPowerstationInfoDay6>>>rgmap=new HashMap<>();
  40. for(ProEconPowerstationInfoDay6 wpinfo:wpinfodayls)
  41. {
  42. if(rgmap.containsKey(wpinfo.getRegionId()))
  43. {
  44. Map<String, List<ProEconPowerstationInfoDay6>> map=rgmap.get(wpinfo.getRegionId());
  45. List<ProEconPowerstationInfoDay6> qbls=map.get("qb");
  46. List<ProEconPowerstationInfoDay6> gfls=map.get("fd");
  47. List<ProEconPowerstationInfoDay6> fdls=map.get("gf");
  48. if(wpinfo.getForeignKeyId().equals("-1"))
  49. {
  50. fdls.add(wpinfo);
  51. }else if(wpinfo.getForeignKeyId().equals("-2")){
  52. gfls.add(wpinfo);
  53. }
  54. qbls.add(wpinfo);
  55. }else
  56. {
  57. Map<String, List<ProEconPowerstationInfoDay6>> map=new HashMap<>();
  58. List<ProEconPowerstationInfoDay6> qbls=new ArrayList<>();
  59. List<ProEconPowerstationInfoDay6> gfls=new ArrayList<>();
  60. List<ProEconPowerstationInfoDay6> fdls=new ArrayList<>();
  61. if(wpinfo.getForeignKeyId().equals("-1"))
  62. {
  63. fdls.add(wpinfo);
  64. }else if(wpinfo.getForeignKeyId().equals("-2")){
  65. gfls.add(wpinfo);
  66. }
  67. qbls.add(wpinfo);
  68. map.put("qb",qbls);
  69. map.put("fd",fdls);
  70. map.put("gf",gfls);
  71. rgmap.put(wpinfo.getRegionId(),map);
  72. }
  73. }
  74. //判断是否有重复记录,先删除重复记录
  75. List<String> idls = proEconPowerstationInfoDay6Service.list().stream()
  76. .filter(i -> i.getRecordDate().compareTo(DateUtils.truncDay(recordDate))==0
  77. // && CacheContext.wpmap.containsKey(i.getWindpowerstationId())
  78. && i.getLocation().equals(Location.rg.getValue())).map(ProEconPowerstationInfoDay6::getId)
  79. .collect(Collectors.toList());
  80. if (idls.size() > 0) {
  81. proEconPowerstationInfoDay6Service.removeByIds(idls);
  82. }
  83. for(Map.Entry<String, Map<String, List<ProEconPowerstationInfoDay6>>> entry:rgmap.entrySet()){
  84. Map<String, List<ProEconPowerstationInfoDay6>> map=entry.getValue();
  85. List<ProEconPowerstationInfoDay6> qbls=map.get("qb");
  86. List<ProEconPowerstationInfoDay6> gfls=map.get("fd");
  87. List<ProEconPowerstationInfoDay6> fdls=map.get("gf");
  88. // if(CacheContext.cpwpmap.size()==qbls.size())
  89. // {
  90. ProEconPowerstationInfoDay6 qb=new ProEconPowerstationInfoDay6();
  91. ProEconPowerstationInfoDay6 fd=new ProEconPowerstationInfoDay6();
  92. ProEconPowerstationInfoDay6 gf=new ProEconPowerstationInfoDay6();
  93. if(CacheContext.rgmap.containsKey(entry.getKey()))
  94. {
  95. ProBasicRegion cp=CacheContext.rgmap.get(entry.getKey());
  96. gf.setRegionId(cp.getId());
  97. gf.setRecordDate(DateUtils.truncDay(recordDate));
  98. gf.setForeignKeyId("-2");
  99. gf.setLocation(Location.rg.getValue());
  100. fd.setRegionId(cp.getId());
  101. fd.setRecordDate(DateUtils.truncDay(recordDate));
  102. fd.setForeignKeyId("-1");
  103. fd.setLocation(Location.rg.getValue());
  104. qb.setRegionId(cp.getId());
  105. qb.setRecordDate(DateUtils.truncDay(recordDate));
  106. qb.setForeignKeyId("0");
  107. qb.setLocation(Location.rg.getValue());
  108. //计算区域级全部
  109. calCp(qb,qbls);
  110. //计算公司级风电场站
  111. calCp(fd,fdls);
  112. //计算公司级光电场站
  113. calCp(gf,gfls);
  114. proEconPowerstationInfoDay6Service.save(qb);
  115. proEconPowerstationInfoDay6Service.save(fd);
  116. proEconPowerstationInfoDay6Service.save(gf);
  117. }
  118. // }else
  119. // {
  120. // logger.debug("公司所属场站数量与保存的场站日信息数量不一致,未进行{0}统计-------结束", entry.getKey());
  121. //
  122. // }
  123. }
  124. }
  125. }
  126. /**
  127. * 计算公司日信息
  128. */
  129. public void calCompanyInfoDay(Date recordDate) {
  130. List<ProEconPowerstationInfoDay6> wpinfodayls = proEconPowerstationInfoDay6Service.list().stream()
  131. .filter(i -> i.getRecordDate().compareTo(DateUtils.truncDay(recordDate))==0
  132. // && CacheContext.wpmap.containsKey(i.getWindpowerstationId())
  133. && i.getLocation().equals(Location.wp.getValue()))
  134. .collect(Collectors.toList());
  135. if(!wpinfodayls.isEmpty())
  136. {
  137. Map<String, Map<String, List<ProEconPowerstationInfoDay6>>>cpmap=new HashMap<>();
  138. for(ProEconPowerstationInfoDay6 wpinfo:wpinfodayls)
  139. {
  140. if(cpmap.containsKey(wpinfo.getCompanyId()))
  141. {
  142. Map<String, List<ProEconPowerstationInfoDay6>> map=cpmap.get(wpinfo.getCompanyId());
  143. List<ProEconPowerstationInfoDay6> qbls=map.get("qb");
  144. List<ProEconPowerstationInfoDay6> gfls=map.get("fd");
  145. List<ProEconPowerstationInfoDay6> fdls=map.get("gf");
  146. if(wpinfo.getWindpowerstationId().contains("FDC"))
  147. {
  148. fdls.add(wpinfo);
  149. }else {
  150. gfls.add(wpinfo);
  151. }
  152. qbls.add(wpinfo);
  153. }else
  154. {
  155. Map<String, List<ProEconPowerstationInfoDay6>> map=new HashMap<>();
  156. List<ProEconPowerstationInfoDay6> qbls=new ArrayList<>();
  157. List<ProEconPowerstationInfoDay6> gfls=new ArrayList<>();
  158. List<ProEconPowerstationInfoDay6> fdls=new ArrayList<>();
  159. if(wpinfo.getWindpowerstationId().contains("FDC"))
  160. {
  161. fdls.add(wpinfo);
  162. }else {
  163. gfls.add(wpinfo);
  164. }
  165. qbls.add(wpinfo);
  166. map.put("qb",qbls);
  167. map.put("fd",fdls);
  168. map.put("gf",gfls);
  169. cpmap.put(wpinfo.getCompanyId(),map);
  170. }
  171. }
  172. //判断是否有重复记录,先删除重复记录
  173. List<String> idls = proEconPowerstationInfoDay6Service.list().stream()
  174. .filter(i -> i.getRecordDate().compareTo(DateUtils.truncDay(recordDate))==0
  175. // && CacheContext.wpmap.containsKey(i.getWindpowerstationId())
  176. && i.getLocation().equals(Location.cp.getValue())).map(ProEconPowerstationInfoDay6::getId)
  177. .collect(Collectors.toList());
  178. if (idls.size() > 0) {
  179. proEconPowerstationInfoDay6Service.removeByIds(idls);
  180. }
  181. for(Map.Entry<String, Map<String, List<ProEconPowerstationInfoDay6>>> entry:cpmap.entrySet()){
  182. Map<String, List<ProEconPowerstationInfoDay6>> map=entry.getValue();
  183. List<ProEconPowerstationInfoDay6> qbls=map.get("qb");
  184. List<ProEconPowerstationInfoDay6> gfls=map.get("fd");
  185. List<ProEconPowerstationInfoDay6> fdls=map.get("gf");
  186. // if(CacheContext.cpwpmap.size()==qbls.size())
  187. // {
  188. ProEconPowerstationInfoDay6 qb=new ProEconPowerstationInfoDay6();
  189. ProEconPowerstationInfoDay6 fd=new ProEconPowerstationInfoDay6();
  190. ProEconPowerstationInfoDay6 gf=new ProEconPowerstationInfoDay6();
  191. if(CacheContext.cpmap.containsKey(entry.getKey()))
  192. {
  193. ProBasicCompany cp=CacheContext.cpmap.get(entry.getKey());
  194. gf.setRegionId(cp.getRegionId());
  195. gf.setCompanyId(cp.getId());
  196. gf.setRecordDate(DateUtils.truncDay(recordDate));
  197. gf.setForeignKeyId("-2");
  198. gf.setLocation(Location.cp.getValue());
  199. fd.setRegionId(cp.getRegionId());
  200. fd.setCompanyId(cp.getId());
  201. fd.setRecordDate(DateUtils.truncDay(recordDate));
  202. fd.setForeignKeyId("-1");
  203. fd.setLocation(Location.cp.getValue());
  204. qb.setRegionId(cp.getRegionId());
  205. qb.setCompanyId(cp.getId());
  206. qb.setRecordDate(DateUtils.truncDay(recordDate));
  207. qb.setForeignKeyId("0");
  208. qb.setLocation(Location.cp.getValue());
  209. //计算公司级全部场站
  210. calCp(qb,qbls);
  211. //计算公司级风电场站
  212. calCp(fd,fdls);
  213. //计算公司级光电场站
  214. calCp(gf,gfls);
  215. proEconPowerstationInfoDay6Service.save(qb);
  216. proEconPowerstationInfoDay6Service.save(fd);
  217. proEconPowerstationInfoDay6Service.save(gf);
  218. }
  219. // }else
  220. // {
  221. // logger.debug("公司所属场站数量与保存的场站日信息数量不一致,未进行{0}统计-------结束", entry.getKey());
  222. //
  223. // }
  224. }
  225. }
  226. }
  227. private void calCp(ProEconPowerstationInfoDay6 pewp,List<ProEconPowerstationInfoDay6> ls) {
  228. if(!ls.isEmpty())
  229. {
  230. //日发电量
  231. // DoubleSummaryStatistics summaryStatistics=ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getRfdl).summaryStatistics();
  232. // pewp.setRfdl(com.gyee.common.model.StringUtils.round(summaryStatistics.getSum(),2));
  233. //* 日最大风速(测风塔)
  234. DoubleSummaryStatistics summaryStatistics=ls.stream().mapToDouble(ProEconPowerstationInfoDay6::getRzdfscft).summaryStatistics();
  235. pewp.setRzdfscft(com.gyee.common.model.StringUtils.round(summaryStatistics.getMax(),2));
  236. // * 日最小风速(测风塔)
  237. summaryStatistics=ls.stream().mapToDouble(ProEconPowerstationInfoDay6::getRzxfscft).summaryStatistics();
  238. pewp.setRzxfscft(com.gyee.common.model.StringUtils.round(summaryStatistics.getMin(),2));
  239. // * 日最大功率(出线)
  240. summaryStatistics=ls.stream().mapToDouble(ProEconPowerstationInfoDay6::getRzdglcx).summaryStatistics();
  241. pewp.setRzdglcx(com.gyee.common.model.StringUtils.round(summaryStatistics.getMax(),2));
  242. // * 日最小功率(出线)
  243. summaryStatistics=ls.stream().mapToDouble(ProEconPowerstationInfoDay6::getRzxglcx).summaryStatistics();
  244. pewp.setRzxglcx(com.gyee.common.model.StringUtils.round(summaryStatistics.getMin(),2));
  245. // * 日平均功率(出线)
  246. summaryStatistics=ls.stream().mapToDouble(ProEconPowerstationInfoDay6::getRpjglcx).summaryStatistics();
  247. pewp.setRpjglcx(com.gyee.common.model.StringUtils.round(summaryStatistics.getAverage(),2));
  248. // * 日平均风速(测风塔)
  249. summaryStatistics=ls.stream().mapToDouble(ProEconPowerstationInfoDay6::getRpjfscft).summaryStatistics();
  250. pewp.setRpjfscft(com.gyee.common.model.StringUtils.round(summaryStatistics.getAverage(),2));
  251. // * 月最大风速(测风塔)
  252. summaryStatistics=ls.stream().mapToDouble(ProEconPowerstationInfoDay6::getYzdfscft).summaryStatistics();
  253. pewp.setYzdfscft(com.gyee.common.model.StringUtils.round(summaryStatistics.getMax(),2));
  254. // * 月最小风速(测风塔)
  255. summaryStatistics=ls.stream().mapToDouble(ProEconPowerstationInfoDay6::getYzxfscft).summaryStatistics();
  256. pewp.setYzxfscft(com.gyee.common.model.StringUtils.round(summaryStatistics.getMin(),2));
  257. // * 月最大功率(出线)
  258. summaryStatistics=ls.stream().mapToDouble(ProEconPowerstationInfoDay6::getYzdglcx).summaryStatistics();
  259. pewp.setYzdglcx(com.gyee.common.model.StringUtils.round(summaryStatistics.getMax(),2));
  260. // * 月最小功率(出线)
  261. summaryStatistics=ls.stream().mapToDouble(ProEconPowerstationInfoDay6::getYzxglcx).summaryStatistics();
  262. pewp.setYzxglcx(com.gyee.common.model.StringUtils.round(summaryStatistics.getMin(),2));
  263. // * 月平均功率(出线)
  264. summaryStatistics=ls.stream().mapToDouble(ProEconPowerstationInfoDay6::getYpjglcx).summaryStatistics();
  265. pewp.setYpjglcx(com.gyee.common.model.StringUtils.round(summaryStatistics.getAverage(),2));
  266. // * 月平均风速(测风塔)
  267. summaryStatistics=ls.stream().mapToDouble(ProEconPowerstationInfoDay6::getYpjfscft).summaryStatistics();
  268. pewp.setYpjfscft(com.gyee.common.model.StringUtils.round(summaryStatistics.getAverage(),2));
  269. // * 年最大风速(测风塔)
  270. summaryStatistics=ls.stream().mapToDouble(ProEconPowerstationInfoDay6::getNzdfscft).summaryStatistics();
  271. pewp.setNzdfscft(com.gyee.common.model.StringUtils.round(summaryStatistics.getMax(),2));
  272. // * 年最小风速(测风塔)
  273. summaryStatistics=ls.stream().mapToDouble(ProEconPowerstationInfoDay6::getNzxfscft).summaryStatistics();
  274. pewp.setNzxfscft(com.gyee.common.model.StringUtils.round(summaryStatistics.getMin(),2));
  275. // * 年最大功率(出线)
  276. summaryStatistics=ls.stream().mapToDouble(ProEconPowerstationInfoDay6::getNzdglcx).summaryStatistics();
  277. pewp.setNzdglcx(com.gyee.common.model.StringUtils.round(summaryStatistics.getMax(),2));
  278. // * 年最小功率(出线)
  279. summaryStatistics=ls.stream().mapToDouble(ProEconPowerstationInfoDay6::getNzxglcx).summaryStatistics();
  280. pewp.setNzxglcx(com.gyee.common.model.StringUtils.round(summaryStatistics.getMin(),2));
  281. // * 年平均功率(出线)
  282. summaryStatistics=ls.stream().mapToDouble(ProEconPowerstationInfoDay6::getNpjglcx).summaryStatistics();
  283. pewp.setNpjglcx(com.gyee.common.model.StringUtils.round(summaryStatistics.getAverage(),2));
  284. // * 年平均风速(测风塔)
  285. summaryStatistics=ls.stream().mapToDouble(ProEconPowerstationInfoDay6::getNpjfscft).summaryStatistics();
  286. pewp.setNpjfscft(com.gyee.common.model.StringUtils.round(summaryStatistics.getAverage(),2));
  287. }
  288. }
  289. /**
  290. * 计算场站日信息
  291. */
  292. public void calWindpowerInfoDay(Date recordDate) throws Exception {
  293. Calendar c=Calendar.getInstance();
  294. c.setTime(recordDate);
  295. Date end=c.getTime();
  296. Date begin= DateUtils.truncDay(c.getTime());
  297. // List<ProEconPowerstationInfoDay6> wpinfodayls=new ArrayList<>();
  298. //判断是否有重复记录,先删除重复记录
  299. List<String> idls = proEconPowerstationInfoDay6Service.list().stream()
  300. .filter(i -> i.getRecordDate().compareTo(DateUtils.truncDay(recordDate))==0
  301. && CacheContext.wpmap.containsKey(i.getWindpowerstationId())
  302. && i.getLocation().equals(Location.wp.getValue())).map(ProEconPowerstationInfoDay6::getId)
  303. .collect(Collectors.toList());
  304. if (idls.size() > 0) {
  305. proEconPowerstationInfoDay6Service.removeByIds(idls);
  306. }
  307. for(ProBasicPowerstation wp:CacheContext.wpls)
  308. {
  309. if(CacheContext.wppointmap.containsKey(wp.getId()))
  310. {
  311. Map<String, ProBasicPowerstationPoint> pointmap=CacheContext.wppointmap.get(wp.getId());
  312. ProEconPowerstationInfoDay6 pewp=new ProEconPowerstationInfoDay6();
  313. Initial.initial(pewp);
  314. pewp.setRegionId(wp.getRegionId());
  315. pewp.setCompanyId(wp.getCompanyId());
  316. pewp.setRecordDate(DateUtils.truncDay(recordDate));
  317. pewp.setForeignKeyId("0");
  318. pewp.setWindpowerstationId(wp.getId());
  319. pewp.setLocation(Location.wp.getValue());
  320. //昨日的统计结果
  321. List<ProEconPowerstationInfoDay6> pepid1ls =new ArrayList<>();
  322. Calendar cl=Calendar.getInstance();
  323. cl.setTime(recordDate);
  324. if(cl.get(Calendar.DAY_OF_MONTH)!=1)
  325. {
  326. pepid1ls = proEconPowerstationInfoDay6Service.list().stream()
  327. .filter(i -> i.getRecordDate().compareTo(DateUtils.truncDay(cl.getTime())) == 0
  328. && i.getWindpowerstationId().equals(wp.getId())
  329. && i.getLocation().equals(Location.wp.getValue()))
  330. .collect(Collectors.toList());
  331. }
  332. extracted(end, begin, pointmap, pewp,pepid1ls);
  333. //*******************************************年信息统计*********************************************************/
  334. // wpinfodayls.add(pewp);
  335. proEconPowerstationInfoDay6Service.save(pewp);
  336. }
  337. }
  338. }
  339. /**
  340. * 计算项目日信息
  341. */
  342. public void calProjectInfoDay(Date recordDate) throws Exception {
  343. Calendar c=Calendar.getInstance();
  344. c.setTime(recordDate);
  345. Date end=c.getTime();
  346. Date begin= DateUtils.truncDay(c.getTime());
  347. //判断是否有重复记录,先删除重复记录
  348. List<String> idls = proEconPowerstationInfoDay6Service.list().stream()
  349. .filter(i -> i.getRecordDate().compareTo(DateUtils.truncDay(recordDate))==0
  350. && CacheContext.pjmap.containsKey(i.getProjectId())
  351. && i.getLocation().equals(Location.pj.getValue())).map(ProEconPowerstationInfoDay6::getId)
  352. .collect(Collectors.toList());
  353. if (idls.size() > 0) {
  354. proEconPowerstationInfoDay6Service.removeByIds(idls);
  355. }
  356. for(ProBasicProject pj:CacheContext.pjls)
  357. {
  358. if(CacheContext.wppointmap.containsKey(pj.getId()))
  359. {
  360. Map<String, ProBasicPowerstationPoint> pointmap=CacheContext.wppointmap.get(pj.getId());
  361. ProEconPowerstationInfoDay6 pewp=new ProEconPowerstationInfoDay6();
  362. Initial.initial(pewp);
  363. pewp.setForeignKeyId("0");
  364. pewp.setWindpowerstationId(pj.getWindpowerstationId());
  365. pewp.setProjectId(pj.getId());
  366. pewp.setLocation(Location.pj.getValue());
  367. pewp.setRecordDate(DateUtils.truncDay(recordDate));
  368. //昨日的统计结果
  369. List<ProEconPowerstationInfoDay6> pepid1ls =new ArrayList<>();
  370. Calendar cl=Calendar.getInstance();
  371. cl.setTime(recordDate);
  372. if(cl.get(Calendar.DAY_OF_MONTH)!=1)
  373. {
  374. pepid1ls = proEconPowerstationInfoDay6Service.list().stream()
  375. .filter(i -> i.getRecordDate().compareTo(DateUtils.truncDay(cl.getTime())) == 0
  376. && i.getProjectId().equals(pj.getId())
  377. && i.getLocation().equals(Location.pj.getValue()))
  378. .collect(Collectors.toList());
  379. }
  380. extracted(end, begin, pointmap, pewp,pepid1ls);
  381. proEconPowerstationInfoDay6Service.save(pewp);
  382. }
  383. }
  384. }
  385. /**
  386. * 计算线路日信息
  387. */
  388. public void calLineInfoDay(Date recordDate) throws Exception {
  389. Calendar c=Calendar.getInstance();
  390. c.setTime(recordDate);
  391. Date end=c.getTime();
  392. Date begin= DateUtils.truncDay(c.getTime());
  393. //判断是否有重复记录,先删除重复记录
  394. List<String> idls = proEconPowerstationInfoDay6Service.list().stream()
  395. .filter(i -> i.getRecordDate().compareTo(DateUtils.truncDay(recordDate))==0
  396. && CacheContext.lnmap.containsKey(i.getLineId())
  397. && i.getLocation().equals(Location.ln.getValue()) ).map(ProEconPowerstationInfoDay6::getId)
  398. .collect(Collectors.toList());
  399. if (idls.size() > 0) {
  400. proEconPowerstationInfoDay6Service.removeByIds(idls);
  401. }
  402. for(ProBasicLine ln:CacheContext.lnls)
  403. {
  404. if(CacheContext.wppointmap.containsKey(ln.getId()))
  405. {
  406. Map<String, ProBasicPowerstationPoint> pointmap=CacheContext.wppointmap.get(ln.getId());
  407. ProEconPowerstationInfoDay6 pewp=new ProEconPowerstationInfoDay6();
  408. Initial.initial(pewp);
  409. pewp.setForeignKeyId("0");
  410. pewp.setLineId(ln.getId());
  411. pewp.setLocation(Location.ln.getValue());
  412. pewp.setProjectId(ln.getProjectId());
  413. pewp.setRecordDate(DateUtils.truncDay(recordDate));
  414. //昨日的统计结果
  415. List<ProEconPowerstationInfoDay6> pepid1ls =new ArrayList<>();
  416. Calendar cl=Calendar.getInstance();
  417. cl.setTime(recordDate);
  418. if(cl.get(Calendar.DAY_OF_MONTH)!=1)
  419. {
  420. pepid1ls = proEconPowerstationInfoDay6Service.list().stream()
  421. .filter(i -> i.getRecordDate().compareTo(DateUtils.truncDay(cl.getTime())) == 0
  422. && i.getLineId().equals(ln.getId())
  423. && i.getLocation().equals(Location.ln.getValue()))
  424. .collect(Collectors.toList());
  425. }
  426. extracted(end, begin, pointmap, pewp,pepid1ls);
  427. proEconPowerstationInfoDay6Service.save(pewp);
  428. }
  429. }
  430. }
  431. private void extracted(Date end, Date begin, Map<String, ProBasicPowerstationPoint> pointmap, ProEconPowerstationInfoDay6 pewp, List<ProEconPowerstationInfoDay6> pepid1ls) throws Exception {
  432. //*******************************************日信息统计*********************************************************/
  433. if(pointmap.containsKey(ContantXk.FCCFTFS70))
  434. {
  435. ProBasicPowerstationPoint point= pointmap.get(ContantXk.FCCFTFS70);
  436. if(StringUtils.notEmp(point.getNemCode()) && !point.getNemCode().equals(initialcode))
  437. {
  438. List<PointData> pointls=edosUtil.getHistoryDatasSnap(point.getNemCode(), begin.getTime()/1000, end.getTime()/1000);
  439. if(!pointls.isEmpty())
  440. {
  441. DoubleSummaryStatistics summaryStatistics=pointls.stream().mapToDouble(PointData::getPointValueInDouble).summaryStatistics();
  442. //日最大风速
  443. pewp.setRzdfscft(summaryStatistics.getMax());
  444. //日最小风速
  445. pewp.setRzxfscft(summaryStatistics.getMin());
  446. //日平均风速
  447. pewp.setRpjfscft(summaryStatistics.getAverage());
  448. }
  449. }else
  450. {
  451. if(pointmap.containsKey(ContantXk.SSPJFS))
  452. {
  453. point= pointmap.get(ContantXk.SSPJFS);
  454. List<PointData> pointls=edosUtil.getHistoryDatasSnap(point.getNemCode(), begin.getTime()/1000, end.getTime()/1000);
  455. if(!pointls.isEmpty())
  456. {
  457. DoubleSummaryStatistics summaryStatistics=pointls.stream().mapToDouble(PointData::getPointValueInDouble).summaryStatistics();
  458. //日最大风速
  459. pewp.setRzdfscft(summaryStatistics.getMax());
  460. //日最小风速
  461. pewp.setRzxfscft(summaryStatistics.getMin());
  462. //日平均风速
  463. pewp.setRpjfscft(summaryStatistics.getAverage());
  464. }
  465. }
  466. }
  467. }else if(pointmap.containsKey(ContantXk.SSPJFS))
  468. {
  469. ProBasicPowerstationPoint point= pointmap.get(ContantXk.SSPJFS);
  470. List<PointData> pointls=edosUtil.getHistoryDatasSnap(point.getNemCode(), begin.getTime()/1000, end.getTime()/1000);
  471. if(!pointls.isEmpty())
  472. {
  473. DoubleSummaryStatistics summaryStatistics=pointls.stream().mapToDouble(PointData::getPointValueInDouble).summaryStatistics();
  474. //日最大风速
  475. pewp.setRzdfscft(summaryStatistics.getMax());
  476. //日最小风速
  477. pewp.setRzxfscft(summaryStatistics.getMin());
  478. //日平均风速
  479. pewp.setRpjfscft(summaryStatistics.getAverage());
  480. }
  481. }
  482. if(pointmap.containsKey(ContantXk.SSZGL))
  483. {
  484. ProBasicPowerstationPoint point= pointmap.get(ContantXk.SSZGL);
  485. List<PointData> pointls=edosUtil.getHistoryDatasSnap(point.getNemCode(), begin.getTime()/1000, end.getTime()/1000);
  486. if(!pointls.isEmpty())
  487. {
  488. DoubleSummaryStatistics summaryStatistics=pointls.stream().mapToDouble(PointData::getPointValueInDouble).summaryStatistics();
  489. //日最大功率
  490. pewp.setRzdglcx(summaryStatistics.getMax());
  491. //日最小功率
  492. pewp.setRzxglcx(summaryStatistics.getMin());
  493. //日平均功率
  494. pewp.setRpjglcx(summaryStatistics.getAverage());
  495. }
  496. }
  497. //*******************************************日信息统计*********************************************************/
  498. //*******************************************月信息统计*********************************************************/
  499. if(pepid1ls.isEmpty())
  500. {
  501. setPowerandSpeedMonth(pewp);
  502. }else
  503. {
  504. ProEconPowerstationInfoDay6 pepid=pepid1ls.get(0);
  505. //如果昨日大于今日最大功率
  506. if(pepid.getYzdglcx()> pewp.getRzdglcx())
  507. {
  508. pewp.setYzdglcx(pepid.getYzdglcx());
  509. }else {
  510. pewp.setYzdglcx(pewp.getRzdglcx());
  511. }
  512. //如果昨日大于今日最大风速
  513. if(pepid.getYzdfscft()> pewp.getRzdfscft())
  514. {
  515. pewp.setYzdfscft(pepid.getYzdfscft());
  516. }else
  517. {
  518. pewp.setYzdfscft(pewp.getRzdfscft());
  519. }
  520. //如果昨日小于今日最小功率
  521. if(pepid.getYzxglcx()< pewp.getRzxglcx())
  522. {
  523. pewp.setYzxglcx(pepid.getYzxglcx());
  524. }else
  525. {
  526. pewp.setYzxglcx(pewp.getRzxglcx());
  527. }
  528. //如果昨日小于今日最小风速
  529. if(pepid.getYzxfscft()< pewp.getRzxfscft())
  530. {
  531. pewp.setYzxfscft(pepid.getYzxfscft());
  532. }else
  533. {
  534. pewp.setYzxfscft(pewp.getRzxfscft());
  535. }
  536. double pjfs = BigDecimal.valueOf(pewp.getYpjfscft() + pepid.getRpjfscft()).divide(new BigDecimal(2), 4, RoundingMode.HALF_EVEN).doubleValue();
  537. pewp.setYzxfscft(pjfs);
  538. double pjgl = BigDecimal.valueOf(pewp.getYpjglcx() + pepid.getRpjglcx()).divide(new BigDecimal(2), 4, RoundingMode.HALF_EVEN).doubleValue();
  539. pewp.setYzxglcx(pjgl);
  540. }
  541. //*******************************************月信息统计*********************************************************/
  542. //*******************************************年信息统计*********************************************************/
  543. if(pepid1ls.isEmpty())
  544. {
  545. setPowerandSpeedYear(pewp);
  546. }else {
  547. ProEconPowerstationInfoDay6 pepid = pepid1ls.get(0);
  548. //如果昨年大于今年最大功率
  549. if (pepid.getNzdglcx() > pewp.getRzdglcx()) {
  550. pewp.setNzdglcx(pepid.getNzdglcx());
  551. } else {
  552. pewp.setNzdglcx(pewp.getRzdglcx());
  553. }
  554. //如果昨年大于今年最大风速
  555. if (pepid.getNzdfscft() > pewp.getRzdfscft()) {
  556. pewp.setNzdfscft(pepid.getNzdfscft());
  557. } else {
  558. pewp.setNzdfscft(pewp.getRzdfscft());
  559. }
  560. //如果昨年小于今年最小功率
  561. if (pepid.getNzxglcx() < pewp.getRzxglcx()) {
  562. pewp.setNzxglcx(pepid.getNzxglcx());
  563. } else {
  564. pewp.setNzxglcx(pewp.getRzxglcx());
  565. }
  566. //如果昨年小于今年最小风速
  567. if (pepid.getNzxfscft() < pewp.getRzxfscft()) {
  568. pewp.setNzxfscft(pepid.getNzxfscft());
  569. } else {
  570. pewp.setNzxfscft(pewp.getRzxfscft());
  571. }
  572. double pjfs = BigDecimal.valueOf(pewp.getNpjfscft() + pepid.getRpjfscft()).divide(new BigDecimal(2), 4, RoundingMode.HALF_EVEN).doubleValue();
  573. pewp.setNzxfscft(pjfs);
  574. double pjgl = BigDecimal.valueOf(pewp.getNpjglcx() + pepid.getRpjglcx()).divide(new BigDecimal(2), 4, RoundingMode.HALF_EVEN).doubleValue();
  575. pewp.setNzxglcx(pjgl);
  576. }
  577. }
  578. private void setPowerandSpeedYear(ProEconPowerstationInfoDay6 pewp) {
  579. //年最大风速
  580. pewp.setNzdfscft(pewp.getRzdfscft());
  581. //年最小风速
  582. pewp.setNzxfscft(pewp.getRzxfscft());
  583. //年平均风速
  584. pewp.setNpjfscft(pewp.getRpjfscft());
  585. //年最大功率
  586. pewp.setNzdglcx(pewp.getRzdglcx());
  587. //年最小功率
  588. pewp.setNzxglcx(pewp.getRzxglcx());
  589. //年平均功率
  590. pewp.setNpjglcx(pewp.getRpjglcx());
  591. }
  592. private void setPowerandSpeedMonth(ProEconPowerstationInfoDay6 pewp) {
  593. //月最大风速
  594. pewp.setYzdfscft(pewp.getRzdfscft());
  595. //月最小风速
  596. pewp.setYzxfscft(pewp.getRzxfscft());
  597. //月平均风速
  598. pewp.setYpjfscft(pewp.getRpjfscft());
  599. //月最大功率
  600. pewp.setYzdglcx(pewp.getRzdglcx());
  601. //月最小功率
  602. pewp.setYzxglcx(pewp.getRzxglcx());
  603. //月平均功率
  604. pewp.setYpjglcx(pewp.getRpjglcx());
  605. }
  606. }