WindPowerInfo6Service.java 36 KB

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