JavaFunctionJobHandler.java 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859
  1. package com.ruoyi;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.date.DateTime;
  4. import cn.hutool.core.date.DateUtil;
  5. import cn.hutool.core.thread.ThreadUtil;
  6. import cn.hutool.core.util.NumberUtil;
  7. import com.alibaba.fastjson2.JSON;
  8. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  9. import com.ruoyi.quartz.handler.IJobHandler;
  10. import com.ruoyi.ucp.entity.*;
  11. import com.ruoyi.ucp.feign.AdapterApi;
  12. import com.ruoyi.ucp.service.*;
  13. import com.ruoyi.ucp.util.CalcCache;
  14. import org.apache.commons.math3.fitting.PolynomialCurveFitter;
  15. import org.apache.commons.math3.fitting.WeightedObservedPoints;
  16. import org.junit.Test;
  17. import org.springframework.data.redis.core.StringRedisTemplate;
  18. import org.springframework.stereotype.Service;
  19. import javax.annotation.Resource;
  20. import java.net.URI;
  21. import java.util.*;
  22. import java.util.concurrent.ConcurrentHashMap;
  23. import java.util.concurrent.atomic.AtomicReference;
  24. import java.util.function.Function;
  25. import java.util.stream.Collectors;
  26. @Service
  27. public class JavaFunctionJobHandler extends IJobHandler {
  28. /* @Resource
  29. private PointInfo pointInfo;*/
  30. @Resource
  31. private AdapterApi adapter;
  32. @Resource
  33. private IPointInfoService pointService;
  34. @Resource
  35. private IStationInfoHourService stationInfoHourService;
  36. @Resource
  37. private IStationInfoDayService stationInfoDayService;
  38. @Resource
  39. private ILineInfoDayService lineInfoDayService;
  40. @Resource
  41. private IStateAiService stateAiService;
  42. @Resource
  43. private StringRedisTemplate stringRedisTemplate;
  44. @Resource
  45. private IEquipmentModelService equipmentModelService;
  46. @Resource
  47. private ITurbineInfoDayService turbineInfoDayService;
  48. @Resource
  49. private IProEconReportIndicatorPoolService reportIndicatorPoolService;
  50. @Override
  51. public void execute() throws Exception {
  52. }
  53. @Override
  54. public IJobHandler getFunctionHandler() {
  55. return null;
  56. }
  57. @Override
  58. public void setFunctionHandler(IJobHandler jobHandler) {
  59. }
  60. public URI taosGoldenUriTest() {
  61. return URI.create("http://127.0.0.1:8011/ts");
  62. }
  63. public String pointInfos2Keys(List<PointInfo> entity) {
  64. return entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
  65. }
  66. public List<StationInfoHour> getStationinfoByHour(Date hour) {
  67. QueryWrapper<StationInfoHour> wrapper = new QueryWrapper<>();
  68. wrapper.eq("record_date", DateUtil.beginOfHour(hour));
  69. return stationInfoHourService.list(wrapper);
  70. }
  71. public List<StationInfoDay> getStationinfoByDate(Date date) {
  72. QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
  73. wrapper.eq("record_date", date);
  74. return stationInfoDayService.list(wrapper);
  75. }
  76. public List<LineInfoDay> getLineinfoByDate(Date date) {
  77. QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
  78. wrapper.eq("record_date", date);
  79. return lineInfoDayService.list(wrapper);
  80. }
  81. public URI taosUri() {
  82. return URI.create("http://172.16.12.101:8012/ts");
  83. }
  84. public URI goldenUri() {
  85. return URI.create("http://172.16.12.103:8011/ts");
  86. }
  87. public Map<String, String> getEntityMap(String uniformCode, String institutionType) {
  88. PointInfo pi = new PointInfo();
  89. pi.setUniformCode(uniformCode);
  90. pi.setInstitutionType(institutionType);
  91. List<PointInfo> entity = pointService.getByEntity(pi);
  92. switch (institutionType) {
  93. case "turbine":
  94. case "state":
  95. return entity.stream().collect(Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointKey));
  96. case "station":
  97. return entity.stream().collect(Collectors.toMap(PointInfo::getStationId, PointInfo::getPointKey));
  98. }
  99. return new HashMap<>();
  100. }
  101. public Map<String, TurbineInfoDay> getTurbineinfoMap(Date date, List<PointInfo> entity) {
  102. QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
  103. wrapper.eq("record_date", date);
  104. List<TurbineInfoDay> list = turbineInfoDayService.list(wrapper);
  105. if (list.isEmpty()) {
  106. entity.forEach(pi -> {
  107. TurbineInfoDay day = new TurbineInfoDay();
  108. day.setStationId(pi.getStationId());
  109. day.setProjectId(pi.getProjectId());
  110. day.setLineId(pi.getLineId());
  111. day.setTurbineId(pi.getTurbineId());
  112. day.setRecordDate(date);
  113. list.add(day);
  114. });
  115. }
  116. return list.stream().collect(Collectors.toMap(TurbineInfoDay::getTurbineId, Function.identity()));
  117. }
  118. public List<PointInfo> getEntity(String uniformCode, String institutionType) {
  119. PointInfo pi = new PointInfo();
  120. pi.setUniformCode(uniformCode);
  121. pi.setInstitutionType(institutionType);
  122. return pointService.getByEntity(pi);
  123. }
  124. public Map<String, Double> getTurbinePowerLoss(double rfdl, PointInfo piZt, List<PointData> fsList, List<PointData> glList) {
  125. String tbId = piZt.getTurbineId();
  126. // Map<Double, Long> collect = piZt.getPointDatas().stream().collect(Collectors.groupingBy(PointData::getValue, Collectors.counting()));
  127. double sum1 = glList.stream().mapToDouble(PointData::getValue).sum();
  128. double xs = rfdl / (sum1 / 240);
  129. // double sum2 = fsList.stream().mapToDouble(pd -> {
  130. // Double v = CalcCache.fitcoef.get(tbId).get(pd.getValue());
  131. // if (v == null) v = 0.0;
  132. // return v;
  133. // }).sum();
  134. // sum2=sum2/240;
  135. List<PointData> collectZt = piZt.getPointDatas();
  136. double jxss = 0, sdtj = 0, gzss = 0, djss = 0, xnss = 0, fdjcl = 0, xdjcl = 0, xdtj = 0;
  137. Map<String, Double> map = new HashMap<>();
  138. if (collectZt.size() == fsList.size() && fsList.size() == glList.size()) {
  139. for (int i = 0; i < collectZt.size(); i++) {
  140. Double v = CalcCache.fitcoef.get(tbId).get(fsList.get(i).getValue());
  141. if (v == null) v = 0.0;
  142. switch ((int) collectZt.get(i).getValue()) {
  143. //计划检修损失:
  144. case 6:
  145. //检修
  146. jxss += v;
  147. break;
  148. case 1:
  149. //手动停机
  150. sdtj += v;
  151. break;
  152. //非计划检修损失:
  153. case 4:
  154. //故障
  155. gzss += v;
  156. break;
  157. case 0:
  158. //待机
  159. djss += v;
  160. break;
  161. //性能损失:
  162. case 2:
  163. //性能
  164. xnss += v - glList.get(i).getValue();
  165. break;
  166. case 3:
  167. //发电降出力
  168. fdjcl += v - glList.get(i).getValue();
  169. break;
  170. //限电损失:
  171. case 8:
  172. //限电降出力
  173. xdjcl += v - glList.get(i).getValue();
  174. break;
  175. case 9:
  176. //限电停机
  177. xdtj += v;
  178. break;
  179. }
  180. }
  181. }
  182. //15秒*60分钟
  183. map.put("jxss", jxss > 0 ? jxss / 240 * xs : 0);
  184. map.put("sdtj", sdtj > 0 ? sdtj / 240 * xs : 0);
  185. map.put("gzss", gzss > 0 ? gzss / 240 * xs : 0);
  186. map.put("djss", djss > 0 ? djss / 240 * xs : 0);
  187. map.put("xnss", xnss > 0 ? xnss / 240 * xs : 0);
  188. map.put("fdjcl", fdjcl > 0 ? fdjcl / 240 * xs : 0);
  189. map.put("xdjcl", xdjcl > 0 ? xdjcl / 240 * xs : 0);
  190. map.put("xdtj", xdtj > 0 ? xdtj / 240 * xs : 0);
  191. return map;
  192. }
  193. public void calcAQTS(Date date) {
  194. QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
  195. wrapper.select("min(record_date) record_date");
  196. StationInfoDay one = stationInfoDayService.getOne(wrapper);
  197. wrapper = new QueryWrapper<>();
  198. wrapper.eq("record_date", one.getRecordDate());
  199. //最早时间的列表
  200. List<StationInfoDay> list = stationInfoDayService.list(wrapper);
  201. List<StationInfoDay> today = getStationinfoByDate(date);
  202. if (today.isEmpty()) {
  203. for (StationInfoDay infoDay : list) {
  204. StationInfoDay day = new StationInfoDay();
  205. day.setStationId(infoDay.getStationId());
  206. day.setRecordDate(date);
  207. day.setAqts(infoDay.getAqts() + (int) DateUtil.betweenDay(infoDay.getRecordDate(), date, true));
  208. today.add(day);
  209. }
  210. } else {
  211. Map<String, StationInfoDay> collect = list.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  212. for (StationInfoDay day : today) {
  213. StationInfoDay day1 = collect.get(day.getStationId());
  214. day.setAqts(day1.getAqts() + (int) DateUtil.betweenDay(day1.getRecordDate(), date, true));
  215. }
  216. }
  217. stationInfoDayService.saveOrUpdateBatch(today);
  218. }
  219. public void calcStationSwGwCyDl(Date date) {
  220. //date当天零点
  221. DateTime time = DateUtil.beginOfDay(date);
  222. //date昨天零点
  223. DateTime time0 = DateUtil.offsetDay(time, -1);
  224. //date当天零点加三分钟
  225. DateTime time2 = DateUtil.offsetMinute(time, 3);
  226. //date昨天零点加三分钟
  227. DateTime time1 = DateUtil.offsetMinute(time0, 3);
  228. PointInfo swdlPi = new PointInfo();
  229. swdlPi.setUniformCode("Z-ZXYG-CX");
  230. PointInfo gwdlPi = new PointInfo();
  231. gwdlPi.setUniformCode("Z-FXYG-CX");
  232. PointInfo cydlPi = new PointInfo();
  233. cydlPi.setUniformCode("Z-ZXYG-ZYB");
  234. List<PointInfo> swdlEt = pointService.getByEntity(swdlPi);
  235. List<PointInfo> gwdlEt = pointService.getByEntity(gwdlPi);
  236. Map<String, PointInfo> gwdlMap = gwdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  237. List<PointInfo> cydlEt = pointService.getByEntity(cydlPi);
  238. Map<String, PointInfo> cydlMap = cydlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  239. String swdlK = pointInfos2Keys(swdlEt);
  240. String gwdlK = pointInfos2Keys(gwdlEt);
  241. String cydlK = pointInfos2Keys(cydlEt);
  242. Map<String, PointData> swdlL2 = adapter.getHistorySection(goldenUri(), swdlK, time2.getTime());
  243. Map<String, PointData> swdlL1 = adapter.getHistorySection(goldenUri(), swdlK, time1.getTime());
  244. Map<String, PointData> gwdlL2 = adapter.getHistorySection(goldenUri(), gwdlK, time2.getTime());
  245. Map<String, PointData> gwdlL1 = adapter.getHistorySection(goldenUri(), gwdlK, time1.getTime());
  246. Map<String, PointData> cydlL2 = adapter.getHistorySection(goldenUri(), cydlK, time2.getTime());
  247. Map<String, PointData> cydlL1 = adapter.getHistorySection(goldenUri(), cydlK, time1.getTime());
  248. List<StationInfoDay> byDate = getStationinfoByDate(time0.toJdkDate());
  249. Map<String, StationInfoDay> collect = new HashMap<>();
  250. if (!byDate.isEmpty()) {
  251. collect = byDate.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  252. }
  253. StationInfoDay infoDay;
  254. String stationId;
  255. PointInfo gwdlKey, cydlKey;
  256. List<StationInfoDay> infoDays = new ArrayList<>();
  257. for (PointInfo info : swdlEt) {
  258. stationId = info.getStationId();
  259. if (byDate.isEmpty()) {
  260. infoDay = new StationInfoDay();
  261. infoDay.setStationId(stationId);
  262. infoDay.setRecordDate(time0.toJdkDate());
  263. } else {
  264. infoDay = collect.get(stationId);
  265. }
  266. infoDay.setSwdl((int) ((swdlL2.get(info.getPointKey()).getValue() -
  267. swdlL1.get(info.getPointKey()).getValue()) * info.getCoef()));
  268. gwdlKey = gwdlMap.get(stationId);
  269. infoDay.setGwdl((int) ((gwdlL2.get(gwdlKey.getPointKey()).getValue() -
  270. gwdlL1.get(gwdlKey.getPointKey()).getValue()) * gwdlKey.getCoef()));
  271. cydlKey = cydlMap.get(stationId);
  272. infoDay.setCydl((int) ((cydlL2.get(cydlKey.getPointKey()).getValue() -
  273. cydlL1.get(cydlKey.getPointKey()).getValue()) * cydlKey.getCoef()));
  274. infoDays.add(infoDay);
  275. }
  276. stationInfoDayService.saveOrUpdateBatch(infoDays);
  277. }
  278. public void calcStationHourRFDL(Date hour) {
  279. PointInfo pointInfo = new PointInfo();
  280. pointInfo.setInstitutionType("station");
  281. pointInfo.setUniformCode("RFDLSYZ");
  282. List<PointInfo> entity = pointService.getByEntity(pointInfo);
  283. Map<String, PointData> section = adapter.getHistorySection(taosUri(), pointInfos2Keys(entity), hour.getTime());
  284. List<StationInfoHour> byHours = getStationinfoByHour(hour);
  285. if (byHours.isEmpty()) {
  286. for (PointInfo point : entity) {
  287. StationInfoHour info = new StationInfoHour();
  288. info.setStationId(point.getStationId());
  289. info.setRecordDate(DateUtil.beginOfHour(hour));
  290. info.setRfdl(section.get(point.getPointKey()).getValue());
  291. byHours.add(info);
  292. }
  293. } else {
  294. Map<String, String> collect = entity.stream().collect(Collectors.toMap(PointInfo::getStationId, PointInfo::getPointKey));
  295. for (StationInfoHour byHour : byHours) {
  296. byHour.setRfdl(section.get(collect.get(byHour.getStationId())).getValue());
  297. }
  298. }
  299. stationInfoHourService.saveOrUpdateBatch(byHours);
  300. }
  301. public void calcLineDjlRfdl(Date date) {
  302. //date当天零点
  303. DateTime time = DateUtil.beginOfDay(date);
  304. //date昨天零点
  305. DateTime time0 = DateUtil.offsetDay(time, -1);
  306. //date当天零点加三分钟
  307. DateTime time2 = DateUtil.offsetMinute(time, 3);
  308. //date昨天零点加三分钟
  309. DateTime time1 = DateUtil.offsetMinute(time0, 3);
  310. PointInfo pi = new PointInfo();
  311. pi.setUniformCode("Z-ZXYG-JX");
  312. pi.setLineId("all");
  313. List<PointInfo> entity = pointService.getByEntity(pi);
  314. // entity = entity.stream().filter(e -> e.getStationId().equals("GJNY_SXGS_ZZ_FDC_STA")).collect(Collectors.toList());
  315. String keys = pointInfos2Keys(entity);
  316. Map<String, PointData> latest2 = adapter.getHistorySection(goldenUri(), keys, time2.getTime());
  317. Map<String, PointData> latest1 = adapter.getHistorySection(goldenUri(), keys, time1.getTime());
  318. List<LineInfoDay> byDate = getLineinfoByDate(time0.toJdkDate());
  319. Map<String, LineInfoDay> collect = new HashMap<>();
  320. if (!byDate.isEmpty()) {
  321. collect = byDate.stream().collect(Collectors.toMap(LineInfoDay::getLineId, Function.identity()));
  322. }
  323. List<LineInfoDay> list = new ArrayList<>();
  324. for (PointInfo info : entity) {
  325. LineInfoDay day;
  326. if (byDate.isEmpty()) {
  327. day = new LineInfoDay();
  328. day.setStationId(info.getStationId());
  329. day.setProjectId(info.getProjectId());
  330. day.setLineId(info.getLineId());
  331. day.setRecordDate(time0.toJdkDate());
  332. } else {
  333. day = collect.get(info.getLineId());
  334. }
  335. day.setRfdl((int) ((latest2.get(info.getPointKey()).getValue() -
  336. latest1.get(info.getPointKey()).getValue()) * info.getCoef()));
  337. if (day.getRfdl() <= 0 || day.getRfdl() > 30000000) {
  338. day.setRfdl(0);
  339. }
  340. list.add(day);
  341. }
  342. lineInfoDayService.saveOrUpdateBatch(list);
  343. }
  344. public void calcStationZhcydl(Date date) {
  345. //date当天零点
  346. DateTime time = DateUtil.beginOfDay(date);
  347. //date昨天零点
  348. DateTime time0 = DateUtil.offsetDay(time, -1);
  349. QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
  350. wrapper.select("sum(rfdl) rfdl,station_id").eq("record_date", time0.toJdkDate())
  351. .groupBy("station_id");
  352. List<LineInfoDay> list = lineInfoDayService.list(wrapper);
  353. List<StationInfoDay> byDate = getStationinfoByDate(time0.toJdkDate());
  354. // list = list.stream().filter(b -> b.getStationId().equals("GJNY_SXGS_ZZ_FDC_STA")).collect(Collectors.toList());
  355. Map<String, StationInfoDay> collect = new HashMap<>();
  356. if (!byDate.isEmpty()) {
  357. collect = byDate.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  358. }
  359. StationInfoDay infoDay;
  360. List<StationInfoDay> infoDays = new ArrayList<>();
  361. for (LineInfoDay day : list) {
  362. if (byDate.isEmpty()) {
  363. infoDay = new StationInfoDay();
  364. infoDay.setStationId(day.getStationId());
  365. infoDay.setRecordDate(time0.toJdkDate());
  366. } else {
  367. infoDay = collect.get(day.getStationId());
  368. }
  369. infoDay.setRfdl(day.getRfdl());
  370. infoDay.setZhcydl(infoDay.getRfdl() + infoDay.getGwdl() - infoDay.getSwdl());
  371. infoDays.add(infoDay);
  372. }
  373. stationInfoDayService.saveOrUpdateBatch(infoDays);
  374. }
  375. public void calcStationHourPJGL(Date hour) {
  376. PointInfo pointInfo = new PointInfo();
  377. pointInfo.setInstitutionType("station");
  378. pointInfo.setUniformCode("SSZGL");
  379. List<PointInfo> entity = pointService.getByEntity(pointInfo);
  380. List<StationInfoHour> byHours = getStationinfoByHour(hour);
  381. Map<String, StationInfoHour> collect = new HashMap<>();
  382. if (!byHours.isEmpty()) {
  383. collect = byHours.stream().collect(
  384. Collectors.toMap(StationInfoHour::getStationId, Function.identity()));
  385. }
  386. DoubleStatData stat;
  387. List<StationInfoHour> byHours2 = new ArrayList<>();
  388. for (PointInfo point : entity) {
  389. stat = adapter.getHistoryStat(taosGoldenUriTest(),
  390. point.getPointKey(), DateUtil.offsetHour(hour, -1).getTime(), hour.getTime());
  391. if (byHours.isEmpty()) {
  392. StationInfoHour info = new StationInfoHour();
  393. info.setStationId(point.getStationId());
  394. info.setRecordDate(DateUtil.beginOfHour(hour));
  395. if (stat == null || stat.getAvg() == null) info.setPjgl(0.0);
  396. info.setPjgl(stat.getAvg().getDoubleValue());
  397. byHours2.add(info);
  398. } else {
  399. collect.get(point.getStationId()).setPjgl(stat.getAvg().getDoubleValue());
  400. }
  401. }
  402. stationInfoHourService.saveOrUpdateBatch(byHours.isEmpty() ? byHours2 : byHours);
  403. }
  404. public void calcStationRfdlFj(Date date) {
  405. //date当天零点
  406. DateTime time = DateUtil.beginOfDay(date);
  407. //date昨天零点
  408. DateTime time0 = DateUtil.offsetDay(time, -1);
  409. QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
  410. wrapper.select("sum(rfdl) rfdl,station_id").eq("record_date", time0.toJdkDate())
  411. .groupBy("station_id");
  412. List<TurbineInfoDay> list = turbineInfoDayService.list(wrapper);
  413. List<StationInfoDay> byDate = getStationinfoByDate(time0.toJdkDate());
  414. Map<String, StationInfoDay> collect = new HashMap<>();
  415. if (!byDate.isEmpty()) {
  416. collect = byDate.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  417. }
  418. StationInfoDay infoDay;
  419. List<StationInfoDay> infoDays = new ArrayList<>();
  420. for (TurbineInfoDay day : list) {
  421. if (byDate.isEmpty()) {
  422. infoDay = new StationInfoDay();
  423. infoDay.setStationId(day.getStationId());
  424. infoDay.setRecordDate(time0.toJdkDate());
  425. } else {
  426. infoDay = collect.get(day.getStationId());
  427. }
  428. infoDay.setRfdlFj(day.getRfdl());
  429. infoDays.add(infoDay);
  430. }
  431. stationInfoDayService.saveOrUpdateBatch(infoDays);
  432. }
  433. public void calcTurbineRFDL(Date date) {
  434. //date当天零点
  435. DateTime time = DateUtil.beginOfDay(date);
  436. //date昨天零点
  437. DateTime time0 = DateUtil.offsetDay(time, -1);
  438. //date当天零点加三分钟
  439. DateTime time2 = DateUtil.offsetMinute(time, 3);
  440. //date昨天零点加三分钟
  441. DateTime time1 = DateUtil.offsetMinute(time0, 3);
  442. PointInfo pi = new PointInfo();
  443. pi.setUniformCode("AI121");
  444. pi.setInstitutionType("turbine");
  445. List<PointInfo> entity = getEntity("AI121", "turbine");
  446. Map<String, String> turMap = entity.stream().collect(Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointKey));
  447. Map<String, String> fsMap = getEntityMap("AI066", "turbine");
  448. String keys = pointInfos2Keys(entity);
  449. Map<String, PointData> swdlL2 = adapter.getHistorySection(goldenUri(), keys, time2.getTime());
  450. Map<String, PointData> swdlL1 = adapter.getHistorySection(goldenUri(), keys, time1.getTime());
  451. Map<String, TurbineInfoDay> byDate = getTurbineinfoMap(time0.toJdkDate(), entity);
  452. TurbineInfoDay infoDay;
  453. String turbineId, key;
  454. List<TurbineInfoDay> infoDays = new ArrayList<>();
  455. DoubleStatData stat;
  456. for (PointInfo info : entity) {
  457. turbineId = info.getTurbineId();
  458. infoDay = byDate.get(turbineId);
  459. key = turMap.get(turbineId);
  460. double v = (swdlL2.get(key).getValue() - swdlL1.get(key).getValue()) * info.getCoef();
  461. if (v < 0 || v > 1000000) {
  462. v = 0;
  463. } else if (v > 30000) {
  464. v = v / (v % 30000 + 3);
  465. }
  466. infoDay.setRfdl(v);
  467. stat = adapter.getHistoryStat(goldenUri(), fsMap.get(turbineId), time1.getTime(), time2.getTime());
  468. if (stat == null) {
  469. infoDay.setPjfs(0.0);
  470. } else {
  471. infoDay.setPjfs(stat.getAvg().getValue());
  472. }
  473. infoDays.add(infoDay);
  474. }
  475. turbineInfoDayService.saveOrUpdateBatch(infoDays);
  476. }
  477. /*public void calcTurbine5s(Date date) {
  478. //date当天零点
  479. DateTime time = DateUtil.beginOfDay(date);
  480. //date昨天零点
  481. DateTime time0 = DateUtil.offsetDay(time, -1);
  482. //状态
  483. List<PointInfo> entityZt = getEntity("MXZT", "turbine");
  484. //功率
  485. Map<String, String> collectGl = getEntityMap("AI114", "turbine");
  486. //风速
  487. Map<String, String> collectFs = getEntityMap("AI066", "turbine");
  488. Map<String, TurbineInfoDay> dayMap = getTurbineinfoMap(time0.toJdkDate(), entityZt);
  489. String tbId;
  490. TurbineInfoDay infoDay;
  491. List<TurbineInfoDay> infoDays = new ArrayList<>();
  492. for (PointInfo info : entityZt) {
  493. tbId = info.getTurbineId();
  494. List<PointData> snapZt = adapter.getHistorySnap(taosUri(), info.getPointKey(), time0.getTime(), time.getTime(), 60);
  495. //0 待机,1 手动停机,2 正常发电,3 发电降出力,4 故障,5 故障受累,6 检修,7 检修受累,8 限电降出力,
  496. // 9 限电停机,10 电网受累,11 环境受累,12 通讯中断,13 设备离线
  497. List<DoubleStatData> statGl = adapter.getHistoryStat2(goldenUri(), collectGl.get(tbId), time0.getTime(), time.getTime(), 60);
  498. List<DoubleStatData> statFs = adapter.getHistoryStat2(goldenUri(), collectFs.get(tbId), time0.getTime(), time.getTime(), 60);
  499. List<PointData> glList = statGl.stream().map(DoubleStatData::getAvg).collect(Collectors.toList());
  500. List<PointData> fsList = statFs.stream().map(DoubleStatData::getAvg)
  501. .peek(fs -> {
  502. if (fs.getValue() < 25) {
  503. fs.setDoubleValue(NumberUtil.round(fs.getValue(), 2).doubleValue());
  504. } else {
  505. fs.setDoubleValue(25.0);
  506. }
  507. }).collect(Collectors.toList());
  508. // Map<String, Double> loss = getTurbinePowerLoss(snapZt, fsList, tbId, glList);
  509. Map<String, Double> loss = new HashMap<>();
  510. infoDay = dayMap.get(tbId);
  511. infoDay.setJhjxss(loss.get("jxss") + loss.get("sdtj"));
  512. infoDay.setFjhjxss(loss.get("gzss") + loss.get("djss") + loss.get("fdjcl"));
  513. infoDay.setXdss(loss.get("xdjcl") + loss.get("xdtj"));
  514. infoDay.setSlss(0.0);
  515. if (infoDay.getRfdl() == 0) {
  516. infoDay.setXnss(0.0);
  517. } else {
  518. infoDay.setXnss(loss.get("xnss") * 0.1);
  519. }
  520. infoDay.setLlfdl(infoDay.getRfdl() + infoDay.getJhjxss() + infoDay.getFjhjxss() +
  521. infoDay.getXdss() + infoDay.getSlss() + infoDay.getXnss());
  522. infoDays.add(infoDay);
  523. }
  524. turbineInfoDayService.saveOrUpdateBatch(infoDays);
  525. }*/
  526. //此处加公式
  527. public void calcStationSspjfs() {
  528. List<PointInfo> fsEntity = getEntity("AI066", "turbine");
  529. String keys = pointInfos2Keys(fsEntity);
  530. Map<String, PointData> latest = adapter.getLatest(goldenUri(), keys);
  531. Map<String, List<String>> listMap = fsEntity.stream().collect(Collectors.groupingBy(PointInfo::getStationId, Collectors.mapping(PointInfo::getPointKey, Collectors.toList())));
  532. Map<String, String> entityMap = getEntityMap("SSPJFS", "station");
  533. List<PointData> tsData = new ArrayList<>();
  534. listMap.forEach((stId, keyList) -> {
  535. double v = keyList.stream().mapToDouble(key -> latest.get(key).getValue()).average().orElse(0.0);
  536. PointData data = new PointData();
  537. data.setTs(System.currentTimeMillis());
  538. data.setTagName(entityMap.get(stId));
  539. data.setDoubleValue(v);
  540. tsData.add(data);
  541. });
  542. adapter.writeHistoryBatch(taosUri(), tsData);
  543. }
  544. public void calcTurbine5s2(Date date) {
  545. //date当天零点
  546. DateTime time = DateUtil.beginOfDay(date);
  547. //date昨天零点
  548. DateTime time0 = DateUtil.offsetDay(time, -1);
  549. //风速
  550. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  551. //功率
  552. List<PointInfo> entityGl = getEntity("AI114", "turbine");
  553. getSnapDataByEntity(entityFs, time0, time, 15);
  554. getSnapDataByEntity(entityGl, time0, time, 15);
  555. List<PointInfo> ztMapMap = calcTurbineZt(time0, time, entityFs, entityGl);
  556. Map<String, Map<String, PointInfo>> ztMapMapInfos = ztMapMap.stream().collect(
  557. Collectors.groupingBy(PointInfo::getStationId, Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
  558. Map<String, TurbineInfoDay> dayMap = getTurbineinfoMap(time0, entityFs);
  559. List<TurbineInfoDay> infoDays = new ArrayList<>();
  560. Map<String, Map<String, List<PointData>>> fsMapMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
  561. Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas)));
  562. Map<String, Map<String, List<PointData>>> glMapMap = entityGl.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
  563. Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas)));
  564. ztMapMapInfos.forEach((stId, ztMapInfo) -> ztMapInfo.forEach((wtId, ztInfo) -> {
  565. //0 待机,1 手动停机,2 正常发电,3 发电降出力,4 故障,5 故障受累,6 检修,7 检修受累,8 限电降出力,
  566. // 9 限电停机,10 电网受累,11 环境受累,12 通讯中断,13 设备离线
  567. TurbineInfoDay infoDay = dayMap.get(wtId);
  568. Map<String, Double> loss = getTurbinePowerLoss(infoDay.getRfdl(), ztMapMapInfos.get(stId).get(wtId), fsMapMap.get(stId).get(wtId), glMapMap.get(stId).get(wtId));
  569. infoDay.setJhjxss(loss.get("jxss") + loss.get("sdtj"));
  570. infoDay.setFjhjxss(loss.get("gzss") + loss.get("djss") + loss.get("fdjcl"));
  571. infoDay.setXdss(loss.get("xdjcl") + loss.get("xdtj"));
  572. infoDay.setSlss(0.0);
  573. if (infoDay.getRfdl() == 0) {
  574. infoDay.setXnss(0.0);
  575. } else {
  576. infoDay.setXnss(loss.get("xnss"));
  577. }
  578. infoDay.setLlfdl(infoDay.getRfdl() + infoDay.getJhjxss() + infoDay.getFjhjxss() +
  579. infoDay.getXdss() + infoDay.getSlss() + infoDay.getXnss());
  580. infoDays.add(infoDay);
  581. }));
  582. turbineInfoDayService.saveOrUpdateBatch(infoDays);
  583. }
  584. public List<PointInfo> calcTurbineZt(Date start, Date end, List<PointInfo> fsInfos, List<PointInfo> glInfos) {
  585. List<PointInfo> turbineZt = calcTurbineDizt(start, end, 15);
  586. List<PointInfo> turbineAizt = calcTurbineAizt(start, end, 15);
  587. turbineZt.addAll(turbineAizt);
  588. Map<String, Map<String, PointInfo>> ztMapMap = turbineZt.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
  589. Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
  590. //AGC
  591. List<PointInfo> entityAgc = getEntity("AGC002", "booster");
  592. getSnapDataByEntity(entityAgc, start, end, 15);
  593. //出线
  594. List<PointInfo> entityCx = getEntity("AGC001", "booster");
  595. getSnapDataByEntity(entityCx, start, end, 15);
  596. //叶轮转速给定
  597. List<PointInfo> entityYlzsgd = getEntity("AI110", "turbine");
  598. getSnapDataByEntity(entityYlzsgd, start, end, 15);
  599. Map<String, PointInfo> collectAgc = entityAgc.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  600. Map<String, PointInfo> collectCx = entityCx.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  601. Map<String, Map<String, List<PointData>>> collectYlzsgd = entityYlzsgd.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
  602. Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas)));
  603. Map<String, Map<String, PointInfo>> fsMapMap = fsInfos.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
  604. Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
  605. Map<String, Map<String, List<PointData>>> glMapMap = glInfos.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
  606. Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas)));
  607. ztMapMap.forEach((stId, ztMap) -> {
  608. PointInfo agcInfo = collectAgc.get(stId);
  609. PointInfo cxInfo = collectCx.get(stId);
  610. Map<String, PointInfo> fsMap = fsMapMap.get(stId);
  611. Map<String, List<PointData>> pdsZsglMap = new HashMap<>();
  612. ztMap.forEach((wtId, zt) -> {
  613. List<PointData> peek = fsMap.get(wtId).getPointDatas().stream().peek(pd -> pd.setDoubleValue(NumberUtil.round(pd.getValue() > 25 ? 25.0
  614. : pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
  615. fsMap.get(wtId).setPointDatas(peek);
  616. List<PointData> zsglSnap = fsMap.get(wtId).getPointDatas().stream().map(pd -> {
  617. Double v = CalcCache.fitcoef.get(wtId).get(pd.getValue());
  618. return new PointData(pd.getTs(), v == null ? 0 : v);
  619. }).collect(Collectors.toList());
  620. pdsZsglMap.put(wtId, zsglSnap);
  621. });
  622. List<PointData> agcc = agcInfo.getPointDatas().stream().peek(agc -> {
  623. agc.setDoubleValue(agc.getValue() * agcInfo.getCoef());
  624. agc.setLongValue(0L);
  625. }).collect(Collectors.toList());
  626. agcInfo.setPointDatas(agcc);
  627. List<PointData> cxc = cxInfo.getPointDatas().stream().peek(cx -> {
  628. cx.setDoubleValue(cx.getValue() * cxInfo.getCoef());
  629. cx.setLongValue(0L);
  630. }).collect(Collectors.toList());
  631. cxInfo.setPointDatas(cxc);
  632. //风机风速、功率->场站风速、功率
  633. // List<PointData> firstFs = new ArrayList<>();
  634. // List<PointData> firstGl = new ArrayList<>();
  635. List<PointData> firstZsgl = new ArrayList<>();
  636. double v1, v2, v3;
  637. for (int i = 0; i < 5760; i++) {
  638. int finalI = i;
  639. long ts = start.getTime() + i * 15000;
  640. // v1 = fsMap.values().stream().mapToDouble(pds -> pds.getPointDatas().get(finalI).getValue()).average().orElse(0.0);
  641. // v2 = glMap.values().stream().mapToDouble(pds -> pds.getPointDatas().get(finalI).getValue()).sum();
  642. v3 = pdsZsglMap.values().stream().mapToDouble(pds -> pds.get(finalI).getValue()).sum();
  643. // firstFs.add(new PointData(ts, v1));
  644. // firstGl.add(new PointData(ts, v2));
  645. firstZsgl.add(new PointData(ts, v3));
  646. }
  647. List<PointData> czxd = calcStationXd2(agcInfo, cxInfo.getPointDatas(), firstZsgl);
  648. ztMap.forEach((wtId, ztInfo) -> {
  649. List<PointData> fss = fsMap.get(wtId).getPointDatas();
  650. List<PointData> gls = glMapMap.get(stId).get(wtId);
  651. //叶轮转速给定
  652. List<PointData> ylzsgds = collectYlzsgd.get(stId).get(wtId);
  653. calcTurbineXd(ztInfo, gls, fss, ylzsgds, czxd);
  654. });
  655. });
  656. return turbineZt;
  657. }
  658. public void calcTurbineXd(PointInfo ztInfo, List<PointData> gls, List<PointData> fss, List<PointData> ylzsgds, List<PointData> czxd) {
  659. Map<String, EquipmentModel> map = equipmentModelService.map();
  660. Double capacity = map.get(ztInfo.getSpare()).getPowerProduction();
  661. List<PointData> zts = ztInfo.getPointDatas();
  662. for (int i = 0; i < 5760; i++) {
  663. double ssgl = gls.get(i).getValue();
  664. double ssfs = fss.get(i).getValue();
  665. double ylzsgd = ylzsgds.get(i).getValue();
  666. if (czxd.get(i).isBooleanValue() && ssgl < capacity * 0.9) {
  667. if (ssfs >= 12) {
  668. zts.get(i).setDoubleValue(8.0);
  669. }
  670. if (ylzsgd != 0 && ylzsgd < 17.3) {//降出力
  671. zts.get(i).setDoubleValue(8.0);
  672. }
  673. }
  674. }
  675. }
  676. //此处加公式
  677. public List<PointData> calcStationXd2(PointInfo agcInfo, List<PointData> cxSnap, List<PointData> zsglSnap) {
  678. String stId = agcInfo.getStationId();
  679. List<PointData> agcSnap = agcInfo.getPointDatas();
  680. List<PointData> zsgl5s = get5Avg(zsglSnap);
  681. List<PointData> agc5s = get5Avg(agcSnap);
  682. List<PointData> cx5s = get5Avg(cxSnap);
  683. //场站限电
  684. List<PointData> czxd = zsglSnap.stream().map(s -> new PointData(s.getTs(), 0.0)).collect(Collectors.toList());
  685. //之前是否限电
  686. boolean iszqxd = false;
  687. for (int i = 0; i < 5760; i++) {
  688. boolean isxd = false;
  689. double zsgl = zsglSnap.get(i).getValue();
  690. double zsgl5 = zsgl5s.get(i).getValue();
  691. double agc = agcSnap.get(i).getValue();
  692. double agc5 = agc5s.get(i).getValue();
  693. double cxgl = cxSnap.get(i).getValue();
  694. double cxgl5 = cx5s.get(i).getValue();
  695. boolean k; //agc一直不变
  696. //第一次初始化复制实时数据到缓存
  697. if (CalcCache.powerCache.get(stId) == null || CalcCache.powerCache.get(stId) != agc) {
  698. CalcCache.powerCache.put(stId, agc);
  699. k = false;
  700. } else {
  701. k = true;
  702. }
  703. if (agc != 0) {
  704. //如果场站限电状态为不限电
  705. if (zsgl5 >= agcInfo.getSpare2() * 40) {
  706. if (agc5 <= cxgl5) {
  707. isxd = true;
  708. } else if (iszqxd) {
  709. if (zsgl / agc > 1.15) {
  710. isxd = true;
  711. } else if (zsgl > agc && agc5 - cxgl5 < 400) {
  712. isxd = true;
  713. }
  714. } else if (zsgl / agc >= 1.2 && agc - cxgl <= 200) {
  715. isxd = true;
  716. }
  717. } else if (k) {
  718. if (zsgl / agc >= 1.1 && agc5 - cxgl5 <= 200) {
  719. isxd = true;
  720. }
  721. }
  722. }
  723. czxd.get(i).setBooleanValue(isxd);
  724. iszqxd = isxd;
  725. }
  726. return czxd;
  727. }
  728. private List<PointData> get5Avg(List<PointData> pointData) {
  729. List<PointData> result = new ArrayList<>();
  730. for (int i = 0; i < pointData.size(); i++) {
  731. PointData data = new PointData();
  732. data.setTs(pointData.get(i).getTs());
  733. double v;
  734. if (i > 4) {
  735. v = (pointData.get(i).getValue() + pointData.get(i - 1).getValue() + pointData.get(i - 2).getValue() + pointData.get(i - 3).getValue() + pointData.get(i - 4).getValue()) / 5;
  736. } else {
  737. v = pointData.get(i).getValue();
  738. }
  739. data.setDoubleValue(v);
  740. result.add(data);
  741. }
  742. return result;
  743. }
  744. public List<PointInfo> calcTurbineAizt(Date start, Date end, int interval) {
  745. List<PointInfo> entityAiZt = getEntity("AI422", "state");
  746. List<StateAi> list = stateAiService.list();
  747. Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(
  748. StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
  749. getSnapDataByEntity(entityAiZt, start, end, interval);
  750. for (PointInfo info : entityAiZt) {
  751. List<PointData> peek = info.getPointDatas().stream().peek(pd -> {
  752. Integer m = collectAi.get(info.getSpare()).get((int) pd.getValue());
  753. if (m == null) m = 2;
  754. pd.setDoubleValue(m);
  755. }).collect(Collectors.toList());
  756. info.setPointDatas(peek);
  757. }
  758. return entityAiZt;
  759. }
  760. public List<PointInfo> calcTurbineDizt(Date start, Date end, int interval) {
  761. List<PointInfo> entity = new ArrayList<>();
  762. List<PointInfo> entity0 = getEntity("MX000", "state");
  763. List<PointInfo> entity1 = getEntity("MX001", "state");
  764. List<PointInfo> entity2 = getEntity("MX002", "state");
  765. List<PointInfo> entity4 = getEntity("MX004", "state");
  766. List<PointInfo> entity6 = getEntity("MX006", "state");
  767. entity.addAll(entity0);
  768. entity.addAll(entity1);
  769. entity.addAll(entity2);
  770. entity.addAll(entity4);
  771. entity.addAll(entity6);
  772. List<String> keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.toList());
  773. Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), String.join(",", keys), start.getTime());
  774. Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
  775. wtUcPis.forEach((wtId, map) -> {
  776. map.forEach((uc, pi) -> {
  777. List<PointData> raw = adapter.getHistoryRaw(goldenUri(), pi.getPointKey(), start.getTime(), end.getTime());
  778. List<PointData> ds = boolPointDatasFull(latest.get(pi.getPointKey()).isBooleanValue(), raw, start.getTime(), end.getTime(), interval);
  779. pi.setPointDatas(ds);
  780. ThreadUtil.sleep(20);
  781. });
  782. List<PointData> mx000 = map.get("MX000").getPointDatas();
  783. PointData data0;
  784. for (int i = 0; i < mx000.size(); i++) {
  785. data0 = mx000.get(i);
  786. if (data0.getValue() == 1.0) {
  787. data0.setDoubleValue(0.0);
  788. data0.setBooleanValue(false);
  789. } else if (map.get("MX001").getPointDatas().get(i).getValue() == 1.0) {
  790. data0.setDoubleValue(1.0);
  791. } else if (map.get("MX002").getPointDatas().get(i).getValue() == 1.0) {
  792. data0.setDoubleValue(2.0);
  793. } else if (map.get("MX004").getPointDatas().get(i).getValue() == 1.0) {
  794. data0.setDoubleValue(4.0);
  795. } else if (map.get("MX006").getPointDatas().get(i).getValue() == 1.0) {
  796. data0.setDoubleValue(6.0);
  797. } else {
  798. // System.out.println(wtId + data0.getTs() + ":di无对应状态!");
  799. data0.setDoubleValue(2.0);
  800. }
  801. }
  802. map.get("MX001").setPointDatas(null);
  803. map.get("MX002").setPointDatas(null);
  804. map.get("MX004").setPointDatas(null);
  805. map.get("MX006").setPointDatas(null);
  806. });
  807. return entity0;
  808. }
  809. public PointInfo calcTurbineAizt2(PointInfo entityAiZt, Map<String, Map<Integer, Integer>> collectAi, Date start, Date end, int interval) {
  810. if (entityAiZt == null) return null;
  811. getSnapDataByEntity(entityAiZt, start, end, interval);
  812. Map<Integer, Integer> integerMap = collectAi.get(entityAiZt.getSpare());
  813. List<PointData> data = entityAiZt.getPointDatas().stream().peek(pd -> {
  814. Integer m = integerMap.get((int) pd.getValue());
  815. if (m == null) m = 2;
  816. pd.setDoubleValue(m);
  817. }).collect(Collectors.toList());
  818. entityAiZt.setPointDatas(data);
  819. return entityAiZt;
  820. }
  821. public PointInfo calcTurbineDizt2(Map<String, PointInfo> wtucpi, Map<String, PointData> latest, Date start, Date end, int interval) {
  822. if (wtucpi == null) return null;
  823. wtucpi.forEach((uc, pi) -> {
  824. List<PointData> raw = adapter.getHistoryRaw(goldenUri(), pi.getPointKey(), start.getTime(), end.getTime());
  825. List<PointData> ds = boolPointDatasFull(latest.get(pi.getPointKey()).isBooleanValue(), raw, start.getTime(), end.getTime(), interval);
  826. pi.setPointDatas(ds);
  827. ThreadUtil.sleep(20);
  828. });
  829. PointInfo mx000 = wtucpi.get("MX000");
  830. PointData data0;
  831. for (int i = 0; i < mx000.getPointDatas().size(); i++) {
  832. data0 = mx000.getPointDatas().get(i);
  833. if (data0.getValue() == 1.0) {
  834. data0.setDoubleValue(0.0);
  835. data0.setBooleanValue(false);
  836. } else if (wtucpi.get("MX001").getPointDatas().get(i).getValue() == 1.0) {
  837. data0.setDoubleValue(1.0);
  838. } else if (wtucpi.get("MX002").getPointDatas().get(i).getValue() == 1.0) {
  839. data0.setDoubleValue(2.0);
  840. } else if (wtucpi.get("MX004").getPointDatas().get(i).getValue() == 1.0) {
  841. data0.setDoubleValue(4.0);
  842. } else if (wtucpi.get("MX006").getPointDatas().get(i).getValue() == 1.0) {
  843. data0.setDoubleValue(6.0);
  844. } else {
  845. System.out.println(mx000.getTurbineId() + data0.getTs() + ":di无对应状态!");
  846. data0.setDoubleValue(2.0);
  847. }
  848. }
  849. wtucpi.get("MX001").setPointDatas(null);
  850. wtucpi.get("MX002").setPointDatas(null);
  851. wtucpi.get("MX004").setPointDatas(null);
  852. wtucpi.get("MX006").setPointDatas(null);
  853. return mx000;
  854. }
  855. public List<PointData> boolPointDatasFull(boolean v, List<PointData> data, long startTime, long endTime, int interval) {
  856. int j = 0, m = 0;
  857. List<PointData> data2 = new ArrayList<>();
  858. for (long i = startTime; i < endTime; i += interval * 1000L) {
  859. PointData dt = new PointData();
  860. dt.setTs(i);
  861. data2.add(dt);
  862. //超出范围
  863. if (j >= data.size() - 1) continue;
  864. if (i < data.get(j).getTs()) {
  865. if (m == 0) {
  866. dt.setBooleanValue(v);
  867. } else {
  868. dt.setBooleanValue(data.get(j - 1).isBooleanValue());
  869. }
  870. } else {
  871. dt.setBooleanValue(data.get(j).isBooleanValue());
  872. j++;
  873. m++;
  874. }
  875. }
  876. return data2;
  877. }
  878. public void calcGlqxnh(Date start, Date end) {
  879. //风速
  880. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  881. //功率
  882. List<PointInfo> entityGl = getEntity("AI114", "turbine");
  883. Map<String, PointInfo> glMap = entityGl.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  884. Map<String, EquipmentModel> map = equipmentModelService.map();
  885. List<PointInfo> entity = new ArrayList<>();
  886. List<PointInfo> entity0 = getEntity("MX000", "state");
  887. List<PointInfo> entity1 = getEntity("MX001", "state");
  888. List<PointInfo> entity2 = getEntity("MX002", "state");
  889. List<PointInfo> entity4 = getEntity("MX004", "state");
  890. List<PointInfo> entity6 = getEntity("MX006", "state");
  891. entity.addAll(entity0);
  892. entity.addAll(entity1);
  893. entity.addAll(entity2);
  894. entity.addAll(entity4);
  895. entity.addAll(entity6);
  896. List<String> keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.toList());
  897. Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), String.join(",", keys), start.getTime());
  898. Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
  899. List<PointInfo> entityAiZt = getEntity("AI422", "state");
  900. Map<String, PointInfo> aiztMap = entityAiZt.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  901. List<StateAi> list = stateAiService.list();
  902. Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(
  903. StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
  904. // Map<String, Map<Double,Double>> fitMap = new HashMap<>();
  905. for (PointInfo ef : entityFs) {
  906. String wtId = ef.getTurbineId();
  907. PointInfo glInfo = glMap.get(wtId);
  908. getSnapDataByEntity(ef, start, end, 60);
  909. getSnapDataByEntity(glInfo, start, end, 60);
  910. List<PointData> peek = ef.getPointDatas().stream().peek(pd -> pd.setDoubleValue(
  911. NumberUtil.round(pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
  912. ef.setPointDatas(peek);
  913. PointInfo turbineZt = calcTurbineDizt2(wtUcPis.get(wtId), latest, start, end, 60);
  914. PointInfo turbineAizt = calcTurbineAizt2(aiztMap.get(wtId), collectAi, start, end, 60);
  915. Map<Double, Double> fit = new TreeMap<>();
  916. if (turbineZt != null) {
  917. double capacity = map.get(turbineZt.getSpare()).getPowerProduction();
  918. fit = dataProcessAndFit(ef, glInfo, turbineZt, CalcCache.bzgl.get(turbineZt.getSpare()), capacity);
  919. // fitMap.put(wtId, fit);
  920. turbineZt.setPointDatas(null);
  921. }
  922. if (turbineAizt != null) {
  923. double capacity = map.get(turbineAizt.getSpare()).getPowerProduction();
  924. fit = dataProcessAndFit(ef, glInfo, turbineAizt, CalcCache.bzgl.get(turbineAizt.getSpare()), capacity);
  925. // fitMap.put(wtId, fit);
  926. turbineAizt.setPointDatas(null);
  927. }
  928. ef.setPointDatas(null);
  929. glInfo.setPointDatas(null);
  930. stringRedisTemplate.opsForValue().set("edfs:" + end.getMonth() + ":" + wtId, JSON.toJSONString(fit));
  931. }
  932. System.out.println("苹果天涯");
  933. // stringRedisTemplate.opsForValue().set("glqxnh", JSON.toJSONString(fitMap));
  934. }
  935. public Map<Double, Double> dataProcessAndFit(PointInfo fsPI, PointInfo glPI, PointInfo ztPI, Map<Double, Double> modelPowerMap, double capacity) {
  936. System.out.println("开始拟合");
  937. List<PointData> fsPds = fsPI.getPointDatas();
  938. List<PointData> glPds = glPI.getPointDatas();
  939. List<PointData> ztPds = ztPI.getPointDatas();
  940. WeightedObservedPoints points = new WeightedObservedPoints();
  941. //数据过滤 0正常,1过滤掉
  942. if (fsPds.size() != glPds.size() || glPds.size() != ztPds.size()) return new HashMap<>();
  943. Double bzv;
  944. for (int i = 0; i < ztPds.size(); i++) {
  945. double fs = fsPds.get(i).getValue();
  946. double gl = glPds.get(i).getValue();
  947. // 过滤非并网值 风机状态不等于2
  948. if (ztPds.get(i).getValue() != 2.0) {
  949. //
  950. } else if (fs < 0 || fs > 25 || gl < 0 || gl > capacity * 1.05) {// 按给定风速功率过滤
  951. //
  952. } else {
  953. bzv = modelPowerMap.get(fs);
  954. if (bzv == null || bzv == 0.0) {
  955. points.add(fs, gl);
  956. continue;
  957. }
  958. double k = gl / bzv; //功率曲线偏差: 保证功率/实际功率 k:偏差百分比
  959. if (k < 0.61 || k > 1.25) {
  960. //
  961. } else {
  962. points.add(fs, gl);
  963. }
  964. }
  965. }
  966. Map<Double, Double> glyc = new TreeMap<>();
  967. PolynomialCurveFitter fitter = PolynomialCurveFitter.create(4);
  968. try {
  969. double[] result = fitter.fit(points.toList());
  970. double min = calcMin(result);
  971. System.out.println(ztPI.getTurbineId());
  972. System.out.println(ztPI.getSpare());
  973. System.out.println(min);
  974. double[] max = calcMax(result);
  975. if (min == 0 || max[0] == 0 || max[1] == 0) {
  976. System.out.println();
  977. }
  978. System.out.println(max[0] + "," + max[1]);
  979. double ru;
  980. for (double i = 0; i < 25; i += 0.01) {
  981. i = NumberUtil.round(i, 2).doubleValue();
  982. if (i < 3) {
  983. ru = 0.0;
  984. } else if (i < min) {
  985. ru = modelPowerMap.get(i);
  986. } else if (i < max[0]) {
  987. ru = calcPoly(i, result);
  988. } else {
  989. ru = max[1];
  990. }
  991. glyc.put(i, NumberUtil.round(ru, 2).doubleValue());
  992. }
  993. } catch (Exception e) {
  994. System.out.println(ztPI.getTurbineId());
  995. System.out.println(ztPI.getSpare());
  996. System.out.println(e.getMessage());
  997. }
  998. System.out.println("拟合完成" + glyc);
  999. return glyc;
  1000. }
  1001. public double calcMin(double[] coef) {
  1002. double minX = 0, minY = 9000;
  1003. for (double x = 0; x < 8; x += 0.01) {
  1004. double y = calcPoly(x, coef);
  1005. if (y < minY) {
  1006. minY = y;
  1007. minX = x;
  1008. }
  1009. }
  1010. return minX;
  1011. }
  1012. public double[] calcMax(double[] coef) {
  1013. double[] a = new double[2];
  1014. for (double x = 8; x < 16; x += 0.01) {
  1015. double y = calcPoly(x, coef);
  1016. if (y > a[1]) {
  1017. a[0] = x;
  1018. a[1] = y;
  1019. }
  1020. }
  1021. return a;
  1022. }
  1023. public void printResult(double[] r, double accuracy) {
  1024. for (double index = 0; index < 25; index += accuracy) {
  1025. System.out.println("[" + index + "," + calcPoly(index, r) + "],");
  1026. }
  1027. }
  1028. public void getSnapDataByEntity(List<PointInfo> entity, URI uri, Date start, Date end, int interval) {
  1029. for (PointInfo info : entity) {
  1030. List<PointData> snap = adapter.getHistorySnap(uri, info.getPointKey(), start.getTime(), end.getTime(), interval);
  1031. ThreadUtil.sleep(20);
  1032. info.setPointDatas(snap);
  1033. }
  1034. }
  1035. public void getSnapDataByEntity(PointInfo entity, URI uri, Date start, Date end, int interval) {
  1036. getSnapDataByEntity(Collections.singletonList(entity), uri, start, end, interval);
  1037. }
  1038. public void getSnapDataByEntity(List<PointInfo> entity, Date start, Date end, int interval) {
  1039. getSnapDataByEntity(entity, goldenUri(), start, end, interval);
  1040. }
  1041. public void getSnapDataByEntity(PointInfo entity, Date start, Date end, int interval) {
  1042. getSnapDataByEntity(entity, goldenUri(), start, end, interval);
  1043. }
  1044. public double calcPoly(String wtId, double value) {
  1045. return CalcCache.fitcoef.get(wtId).get(value);
  1046. }
  1047. public double calcPoly(double x, double[] factor) {
  1048. double y = 0;
  1049. for (int deg = 0; deg < factor.length; deg++) {
  1050. y += Math.pow(x, deg) * factor[deg];
  1051. }
  1052. return y;
  1053. }
  1054. //切入切出风速
  1055. public void cutInWindSpeed() {
  1056. //date当天零点
  1057. DateTime timeNow00 = DateUtil.beginOfDay(new Date());
  1058. //date昨天零点
  1059. DateTime timeBegin00 = DateUtil.offsetDay(timeNow00, -1);
  1060. //上个月
  1061. DateTime timeBegin2 = DateUtil.offsetMonth(timeBegin00, -1);
  1062. //上个月第一天
  1063. DateTime timeBegin1 = DateUtil.beginOfMonth(timeBegin2);
  1064. //上个月最后一天
  1065. DateTime timeEnd2 = DateUtil.endOfMonth(timeBegin2);
  1066. //上个月天数
  1067. int days = (int) DateUtil.betweenDay(timeBegin1, timeEnd2, false);
  1068. //遍历天数
  1069. for (int i = 1; i <= days; i++) {
  1070. DateTime timeNow = DateUtil.offsetDay(timeBegin1, i);
  1071. DateTime timeBegin = DateUtil.offsetDay(timeBegin1, i - 1);
  1072. List<PointInfo> turbineZt = calcTurbineAizt(timeBegin, timeNow, 60);
  1073. List<PointInfo> turbineZtDI = calcTurbineDizt(timeBegin, timeNow, 60);
  1074. turbineZt.addAll(turbineZtDI);
  1075. //所有风机的风速测点
  1076. QueryWrapper<PointInfo> queryWrapper = new QueryWrapper<>();
  1077. queryWrapper.eq("uniform_code", "AI066");
  1078. List<PointInfo> pointInfos = getEntity("AI066", "turbine");
  1079. // List<PointInfo> pointInfos = pointInfo.selectList(queryWrapper);
  1080. //定义切入风速map集合
  1081. ConcurrentHashMap<String, ConcurrentHashMap<String, Double>> mapIn = new ConcurrentHashMap<>();
  1082. //定义切出风速集合
  1083. ConcurrentHashMap<String, ConcurrentHashMap<String, Double>> mapOut = new ConcurrentHashMap<>();
  1084. //插入集合
  1085. List<TurbineInfoDay> interest = new ArrayList<>();
  1086. //更新集合
  1087. List<TurbineInfoDay> update = new ArrayList<>();
  1088. //遍历每台风机,取出每台风机的pointDatas
  1089. for (PointInfo turbine : turbineZt) {
  1090. mapIn.put(turbine.getTurbineId(), new ConcurrentHashMap<>());
  1091. mapOut.put(turbine.getTurbineId(), new ConcurrentHashMap<>());
  1092. List<PointData> pointDatas = turbine.getPointDatas();
  1093. //风速测点key
  1094. String windSpeedKey = null;
  1095. //遍历pointInfos,找出pointData1的id和pointInfos中相等的,取出pointInfo的pointKey
  1096. for (PointInfo info : pointInfos) {
  1097. if (Objects.equals(turbine.getTurbineId(), info.getTurbineId())) {
  1098. windSpeedKey = info.getPointKey();
  1099. }
  1100. }
  1101. //遍历pointDatas,取出当前状态和后一个状态
  1102. for (int k = 1; k < pointDatas.size(); k++) {
  1103. PointData pointData1 = pointDatas.get(k - 1);
  1104. PointData pointData2 = pointDatas.get(k);
  1105. double value1 = pointData1.getValue();
  1106. double value2 = pointData2.getValue();
  1107. //切入时间
  1108. long ts1;
  1109. //切出时间
  1110. long ts2;
  1111. //如果1的值为0,2的值为2,则为切入状态
  1112. if (value1 == 0 && value2 == 2) {
  1113. ts1 = pointData2.getTs();
  1114. // String stringDate = DateUtil.date(ts1).toString("yyyy-MM-dd HH:mm:ss");
  1115. // System.out.println(turbine.getTurbineId() + "切入" + stringDate);
  1116. //切入时间前5分钟
  1117. long ts11 = ts1 - 300000;
  1118. //根据风速key,从适配器取切入前5分钟的所有风速
  1119. List<PointData> pointDatas1 = adapter.getHistorySnap(goldenUri(), windSpeedKey, ts11, ts1, 10);
  1120. //平均所有风速即为平均切入风速
  1121. double avgCutInWindSpeed = pointDatas1.stream().mapToDouble(PointData::getValue).average().orElse(0);
  1122. // System.out.println(turbine.getTurbineId() + "切入风速" + avgCutInWindSpeed);
  1123. //存入map集合,外层key为turbineId,内层key为ts1,value为平均切入风速
  1124. mapIn.get(turbine.getTurbineId()).put(String.valueOf(ts1), avgCutInWindSpeed);
  1125. }
  1126. //切出
  1127. if (value1 == 2 && value2 != 2) {
  1128. ts2 = pointData2.getTs();
  1129. String stringDate = DateUtil.date(ts2).toString("yyyy-MM-dd HH:mm:ss");
  1130. // System.out.println(turbine.getTurbineId() + "切出" + stringDate);
  1131. //切出时间前5分钟
  1132. long ts22 = ts2 - 300000;
  1133. List<PointData> pointDatas2 = adapter.getHistorySnap(goldenUri(), windSpeedKey, ts22, ts2, 10);
  1134. double avgCutOutWindSpeed = pointDatas2.stream().mapToDouble(PointData::getValue).average().orElse(0);
  1135. // System.out.println(turbine.getTurbineId() + "切出风速" + avgCutOutWindSpeed);
  1136. //存入map集合,外层key为turbineId,内层key为ts2,value为平均切出风速
  1137. mapOut.get(turbine.getTurbineId()).put(String.valueOf(ts2), avgCutOutWindSpeed);
  1138. }
  1139. }
  1140. //遍历map集合,取出每个风机的所有切入风速,算一个平均值
  1141. ConcurrentHashMap<String, Double> mapTurbineValues = mapIn.get(turbine.getTurbineId());
  1142. //平均切入风速
  1143. double avgCutInWindSpeed = 0;
  1144. if (mapTurbineValues != null) {
  1145. AtomicReference<Double> sum = new AtomicReference<>(0.0);
  1146. //遍历mapTurbineValues,V大于5的舍弃,剩余算平均值
  1147. for (String key : mapTurbineValues.keySet()) {
  1148. if (mapTurbineValues.get(key) > 5) {
  1149. mapTurbineValues.remove(key);
  1150. }
  1151. }
  1152. mapTurbineValues.forEach((k1, v) -> {
  1153. sum.updateAndGet(v1 -> v1 + v);
  1154. });
  1155. //如果值为空则置0
  1156. if (sum.get() == 0) {
  1157. avgCutInWindSpeed = 0;
  1158. } else {
  1159. avgCutInWindSpeed = sum.get() / mapTurbineValues.size();
  1160. }
  1161. System.out.println(turbine.getTurbineId() + "切入平均风速" + avgCutInWindSpeed + "时间" + timeBegin);
  1162. }
  1163. //遍历map集合,取出每个风机的所有切出风速,算一个平均值
  1164. ConcurrentHashMap<String, Double> mapTurbineValues2 = mapOut.get(turbine.getTurbineId());
  1165. double avgCutOutWindSpeed;
  1166. if (mapTurbineValues2 != null) {
  1167. AtomicReference<Double> sum = new AtomicReference<>(0.0);
  1168. for (String key : mapTurbineValues2.keySet()) {
  1169. if (mapTurbineValues2.get(key) > 5) {
  1170. mapTurbineValues2.remove(key);
  1171. }
  1172. }
  1173. mapTurbineValues2.forEach((k2, v) -> {
  1174. sum.updateAndGet(v1 -> v1 + v);
  1175. });
  1176. if (sum.get() == 0) {
  1177. avgCutOutWindSpeed = 0;
  1178. } else {
  1179. avgCutOutWindSpeed = sum.get() / mapTurbineValues2.size();
  1180. }
  1181. System.out.println(turbine.getTurbineId() + "切出平均风速" + avgCutOutWindSpeed + "时间" + timeBegin);
  1182. }
  1183. //存入数据库
  1184. String turbineId = turbine.getTurbineId();
  1185. Date jdkDate = timeBegin.toJdkDate();
  1186. System.out.println(turbineId + " " + jdkDate);
  1187. QueryWrapper<TurbineInfoDay> turbineInfoDayQueryWrapper = new QueryWrapper<>();
  1188. turbineInfoDayQueryWrapper.eq("turbine_id", turbine.getTurbineId());
  1189. turbineInfoDayQueryWrapper.eq("record_date", timeBegin.toJdkDate());
  1190. TurbineInfoDay one = turbineInfoDayService.getOne(turbineInfoDayQueryWrapper);
  1191. System.out.println(one);
  1192. if (one == null) {
  1193. TurbineInfoDay turbineInfoDay = new TurbineInfoDay();
  1194. turbineInfoDay.setTurbineId(turbine.getTurbineId());
  1195. turbineInfoDay.setRecordDate(timeBegin.toJdkDate());
  1196. turbineInfoDay.setXfqrfs(avgCutInWindSpeed);
  1197. System.out.println(turbineInfoDay);
  1198. interest.add(turbineInfoDay);
  1199. // turbineInfoDayService.save(turbineInfoDay);
  1200. } else {
  1201. one.setXfqrfs(avgCutInWindSpeed);
  1202. System.out.println(one);
  1203. // turbineInfoDayService.updateById(one);
  1204. update.add(one);
  1205. }
  1206. }
  1207. // //批量插入
  1208. // turbineInfoDayService.saveBatch(interest);
  1209. // //批量更新
  1210. // turbineInfoDayService.updateBatchById(update);
  1211. // //批量插入或更新
  1212. turbineInfoDayService.saveOrUpdateBatch(interest);
  1213. turbineInfoDayService.saveOrUpdateBatch(update);
  1214. }
  1215. }
  1216. //算额定风速
  1217. public void calcGlqxnh_edfs() {
  1218. //date当天零点
  1219. DateTime timeNow00 = DateUtil.beginOfDay(new Date());
  1220. //date昨天零点
  1221. DateTime timeBegin00 = DateUtil.offsetDay(timeNow00, -1);
  1222. //上个月
  1223. DateTime timeBegin2 = DateUtil.offsetMonth(timeBegin00, -1);
  1224. //上个月第一天
  1225. DateTime timeBegin1 = DateUtil.beginOfMonth(timeBegin2);
  1226. //上个月最后一天
  1227. DateTime timeEnd2 = DateUtil.endOfMonth(timeBegin2);
  1228. //上个月天数
  1229. int days = (int) DateUtil.betweenDay(timeBegin1, timeEnd2, false);
  1230. //遍历天数
  1231. for (int i = 1; i <= days; i++) {
  1232. DateTime end = DateUtil.offsetDay(timeBegin1, i);
  1233. DateTime start = DateUtil.offsetDay(timeBegin1, i - 1);
  1234. //风速
  1235. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  1236. //功率
  1237. List<PointInfo> entityGl = getEntity("AI114", "turbine");
  1238. Map<String, PointInfo> glMap = entityGl.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  1239. Map<String, EquipmentModel> map = equipmentModelService.map();
  1240. List<PointInfo> entity = new ArrayList<>();
  1241. List<PointInfo> entity0 = getEntity("MX000", "state");
  1242. List<PointInfo> entity1 = getEntity("MX001", "state");
  1243. List<PointInfo> entity2 = getEntity("MX002", "state");
  1244. List<PointInfo> entity4 = getEntity("MX004", "state");
  1245. List<PointInfo> entity6 = getEntity("MX006", "state");
  1246. entity.addAll(entity0);
  1247. entity.addAll(entity1);
  1248. entity.addAll(entity2);
  1249. entity.addAll(entity4);
  1250. entity.addAll(entity6);
  1251. List<String> keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.toList());
  1252. Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), String.join(",", keys), start.getTime());
  1253. Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
  1254. List<PointInfo> entityAiZt = getEntity("AI422", "state");
  1255. Map<String, PointInfo> aiztMap = entityAiZt.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  1256. List<StateAi> list = stateAiService.list();
  1257. Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(
  1258. StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
  1259. // Map<String, Map<Double,Double>> fitMap = new HashMap<>();
  1260. //插入集合
  1261. List<TurbineInfoDay> interest = new ArrayList<>();
  1262. //更新集合
  1263. List<TurbineInfoDay> update = new ArrayList<>();
  1264. for (PointInfo ef : entityFs) {
  1265. String wtId = ef.getTurbineId();
  1266. PointInfo glInfo = glMap.get(wtId);
  1267. getSnapDataByEntity(ef, start, end, 60);
  1268. getSnapDataByEntity(glInfo, start, end, 60);
  1269. List<PointData> peek = ef.getPointDatas().stream().peek(pd -> pd.setDoubleValue(
  1270. NumberUtil.round(pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
  1271. ef.setPointDatas(peek);
  1272. try {
  1273. PointInfo turbineZt = calcTurbineDizt2(wtUcPis.get(wtId), latest, start, end, 60);
  1274. PointInfo turbineAizt = calcTurbineAizt2(aiztMap.get(wtId), collectAi, start, end, 60);
  1275. Map<Double, Double> fit = new TreeMap<>();
  1276. double capacity = 2000;
  1277. if (turbineZt != null) {
  1278. System.out.println("数据处理拟合");
  1279. capacity = map.get(turbineZt.getSpare()).getPowerProduction();
  1280. fit = dataProcessAndFit(ef, glInfo, turbineZt, CalcCache.bzgl.get(turbineZt.getSpare()), capacity);
  1281. // fitMap.put(wtId, fit);
  1282. turbineZt.setPointDatas(null);
  1283. }
  1284. if (turbineAizt != null) {
  1285. System.out.println("数据处理拟合");
  1286. capacity = map.get(turbineAizt.getSpare()).getPowerProduction();
  1287. fit = dataProcessAndFit(ef, glInfo, turbineAizt, CalcCache.bzgl.get(turbineAizt.getSpare()), capacity);
  1288. // fitMap.put(wtId, fit);
  1289. turbineAizt.setPointDatas(null);
  1290. }
  1291. ef.setPointDatas(null);
  1292. glInfo.setPointDatas(null);
  1293. //存redis
  1294. // stringRedisTemplate.opsForValue().set("glqxnh:" + end.getMonth() + ":" + wtId, JSON.toJSONString(fit));
  1295. System.out.println("拟合曲线的大小" + fit.size() + ":" + wtId);
  1296. //符合条件的风速和
  1297. List<Double> listDouble = new ArrayList<>();
  1298. //遍历fit集合,取出值与capacity相等的key
  1299. if (!fit.isEmpty()) {
  1300. for (double key : fit.keySet()) {
  1301. Double v = fit.get(key);
  1302. //如果v-capacity的值小于10大于-10,则把key加入listDouble
  1303. if ((Math.abs(v - capacity) <= 10) && Math.abs(v - capacity) >= -10) {
  1304. listDouble.add(key);
  1305. }
  1306. }
  1307. }
  1308. //取出listDouble的值求平均值
  1309. double agValue = 0;
  1310. if (!listDouble.isEmpty()) {
  1311. for (Double aDouble : listDouble) {
  1312. agValue += aDouble;
  1313. }
  1314. agValue = agValue / listDouble.size();
  1315. }
  1316. System.out.println("wtId:" + wtId + "agValue平均额定风速:" + agValue);
  1317. //存入数据库
  1318. System.out.println(wtId + " " + start);
  1319. QueryWrapper<TurbineInfoDay> turbineInfoDayQueryWrapper = new QueryWrapper<>();
  1320. turbineInfoDayQueryWrapper.eq("turbine_id", wtId);
  1321. turbineInfoDayQueryWrapper.eq("record_date", start);
  1322. TurbineInfoDay one = turbineInfoDayService.getOne(turbineInfoDayQueryWrapper);
  1323. System.out.println(one);
  1324. if (one == null) {
  1325. TurbineInfoDay turbineInfoDay = new TurbineInfoDay();
  1326. turbineInfoDay.setTurbineId(wtId);
  1327. turbineInfoDay.setRecordDate(start);
  1328. turbineInfoDay.setEdfs(agValue);
  1329. System.out.println(turbineInfoDay);
  1330. // turbineInfoDayService.save(turbineInfoDay);
  1331. interest.add(turbineInfoDay);
  1332. } else {
  1333. one.setEdfs(agValue);
  1334. System.out.println(one);
  1335. // turbineInfoDayService.updateById(one);
  1336. update.add(one);
  1337. }
  1338. } catch (Exception e) {
  1339. System.out.println(wtId + " " + start);
  1340. }
  1341. }
  1342. // //批量插入
  1343. // turbineInfoDayService.saveBatch(interest);
  1344. // //批量更新
  1345. // turbineInfoDayService.updateBatchById(update);
  1346. // //批量插入或更新
  1347. turbineInfoDayService.saveOrUpdateBatch(interest);
  1348. turbineInfoDayService.saveOrUpdateBatch(update);
  1349. }
  1350. // stringRedisTemplate.opsForValue().set("glqxnh", JSON.toJSONString(fitMap));
  1351. }
  1352. //环境温度
  1353. public void ambientTemperature() {
  1354. //date当天零点
  1355. DateTime timeNow = DateUtil.beginOfDay(new Date());
  1356. //date昨天零点
  1357. DateTime timeBegin = DateUtil.offsetDay(timeNow, -1);
  1358. //所有风机的温度
  1359. QueryWrapper<PointInfo> queryWrapper = new QueryWrapper<>();
  1360. queryWrapper.eq("uniform_code", "AI072");
  1361. List<PointInfo> pointInfos = getEntity("AI072", "turbine");
  1362. //插入集合
  1363. List<TurbineInfoDay> interest = new ArrayList<>();
  1364. //更新集合
  1365. List<TurbineInfoDay> update = new ArrayList<>();
  1366. //遍历pointInfos
  1367. for (PointInfo turbine : pointInfos) {
  1368. List<PointData> pointDatas = adapter.getHistorySnap(goldenUri(), turbine.getPointKey(), timeBegin.getTime(), timeNow.getTime(), 10);
  1369. //遍历pointDatas,取出数据算平均值
  1370. double avgCutInWindSpeed = 0;
  1371. for (PointData pointData : pointDatas) {
  1372. avgCutInWindSpeed += pointData.getValue();
  1373. }
  1374. avgCutInWindSpeed /= pointDatas.size();
  1375. //存入数据库
  1376. String turbineId = turbine.getTurbineId();
  1377. Date jdkDate = timeBegin.toJdkDate();
  1378. System.out.println(turbineId + " " + jdkDate);
  1379. QueryWrapper<TurbineInfoDay> turbineInfoDayQueryWrapper = new QueryWrapper<>();
  1380. turbineInfoDayQueryWrapper.eq("turbine_id", turbine.getTurbineId());
  1381. turbineInfoDayQueryWrapper.eq("record_date", timeBegin.toJdkDate());
  1382. TurbineInfoDay one = turbineInfoDayService.getOne(turbineInfoDayQueryWrapper);
  1383. System.out.println(one);
  1384. if (one == null) {
  1385. TurbineInfoDay turbineInfoDay = new TurbineInfoDay();
  1386. turbineInfoDay.setTurbineId(turbine.getTurbineId());
  1387. turbineInfoDay.setRecordDate(timeBegin.toJdkDate());
  1388. turbineInfoDay.setHjwd(avgCutInWindSpeed);
  1389. System.out.println(turbineInfoDay);
  1390. interest.add(turbineInfoDay);
  1391. // turbineInfoDayService.save(turbineInfoDay);
  1392. } else {
  1393. one.setHjwd(avgCutInWindSpeed);
  1394. System.out.println(one);
  1395. update.add(one);
  1396. // turbineInfoDayService.updateById(one);
  1397. }
  1398. }
  1399. // //批量插入
  1400. // turbineInfoDayService.saveBatch(interest);
  1401. // //批量更新
  1402. // turbineInfoDayService.updateBatchById(update);
  1403. // //批量插入或更新
  1404. turbineInfoDayService.saveOrUpdateBatch(interest);
  1405. turbineInfoDayService.saveOrUpdateBatch(update);
  1406. }
  1407. public void writeReportPool(Date date) {
  1408. //date当天零点
  1409. DateTime time = DateUtil.beginOfDay(date);
  1410. //date昨天零点
  1411. DateTime time0 = DateUtil.offsetDay(time, -1);
  1412. DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
  1413. DateTime beginOfYear = DateUtil.beginOfYear(time0);
  1414. QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
  1415. wrapper.eq("record_date", time0);
  1416. List<StationInfoDay> days = stationInfoDayService.list(wrapper);
  1417. Map<String, StationInfoDay> dayMap = days.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  1418. wrapper = new QueryWrapper<>();
  1419. wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,sum(zhcydl) zhcydl,station_id")
  1420. .between("record_date", beginOfMonth.toJdkDate(), time0.toJdkDate())
  1421. .groupBy("station_id");
  1422. List<StationInfoDay> monthDays = stationInfoDayService.list(wrapper);
  1423. Map<String, StationInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  1424. wrapper = new QueryWrapper<>();
  1425. wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,sum(zhcydl) zhcydl,station_id")
  1426. .between("record_date", beginOfYear.toJdkDate(), time0.toJdkDate())
  1427. .groupBy("station_id");
  1428. List<StationInfoDay> yearDays = stationInfoDayService.list(wrapper);
  1429. Map<String, StationInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  1430. // QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
  1431. // wrapperrp.eq("record_date", time0).last("and foreign_key_id = windpowerstation_id");
  1432. // List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
  1433. QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
  1434. wrapperrp.eq("record_date", time0)
  1435. .in("foreign_key_id", days.stream().map(StationInfoDay::getStationId).collect(Collectors.toList()));
  1436. List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
  1437. if (!pools.isEmpty()) {
  1438. StationInfoDay day, month, year;
  1439. List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
  1440. for (ProEconReportIndicatorPool pool : pools) {
  1441. String stationId = pool.getForeignKeyId();
  1442. day = dayMap.get(stationId);
  1443. pool.setRfdldb(day.getRfdl().doubleValue());
  1444. pool.setRswdldb(day.getSwdl().doubleValue());
  1445. pool.setRgwgwdldb(day.getGwdl().doubleValue());
  1446. pool.setRfdcydldb(day.getCydl().doubleValue());
  1447. pool.setRzhcydldb(day.getZhcydl().doubleValue());
  1448. month = monthMap.get(stationId);
  1449. pool.setYfdldb(month.getRfdl().doubleValue());
  1450. pool.setYswdldb(month.getSwdl().doubleValue());
  1451. pool.setYgwgwdldb(month.getGwdl().doubleValue());
  1452. pool.setYfdcydldb(month.getCydl().doubleValue());
  1453. pool.setYzhcydldb(month.getZhcydl().doubleValue());
  1454. year = yearMap.get(stationId);
  1455. pool.setNfdldb(year.getRfdl().doubleValue());
  1456. pool.setNswdldb(year.getSwdl().doubleValue());
  1457. pool.setNgwgwdldb(year.getGwdl().doubleValue());
  1458. pool.setNfdcydldb(year.getCydl().doubleValue());
  1459. pool.setNzhcydldb(year.getZhcydl().doubleValue());
  1460. poolList.add(pool);
  1461. }
  1462. reportIndicatorPoolService.saveOrUpdateBatch(poolList);
  1463. } else {
  1464. List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
  1465. for (StationInfoDay day : days) {
  1466. ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
  1467. pool.setRecordDate(time0.toLocalDateTime().toLocalDate());
  1468. pool.setForeignKeyId(day.getStationId());
  1469. poolList.add(pool);
  1470. }
  1471. reportIndicatorPoolService.saveOrUpdateBatch(poolList);
  1472. }
  1473. }
  1474. public void writeReportPoolProject(Date date) {
  1475. //date当天零点
  1476. DateTime time = DateUtil.beginOfDay(date);
  1477. //date昨天零点
  1478. DateTime time0 = DateUtil.offsetDay(time, -1);
  1479. DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
  1480. DateTime beginOfYear = DateUtil.beginOfYear(time0);
  1481. QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
  1482. wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,project_id")
  1483. .eq("record_date", time0)
  1484. .groupBy("project_id");
  1485. List<LineInfoDay> days = lineInfoDayService.list(wrapper);
  1486. Map<String, LineInfoDay> dayMap = days.stream().collect(Collectors.toMap(LineInfoDay::getProjectId, Function.identity()));
  1487. wrapper = new QueryWrapper<>();
  1488. wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,project_id")
  1489. .between("record_date", beginOfMonth, time0)
  1490. .groupBy("project_id");
  1491. List<LineInfoDay> monthDays = lineInfoDayService.list(wrapper);
  1492. Map<String, LineInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(LineInfoDay::getProjectId, Function.identity()));
  1493. wrapper = new QueryWrapper<>();
  1494. wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,project_id")
  1495. .between("record_date", beginOfYear, time0)
  1496. .groupBy("project_id");
  1497. List<LineInfoDay> yearDays = lineInfoDayService.list(wrapper);
  1498. Map<String, LineInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(LineInfoDay::getProjectId, Function.identity()));
  1499. QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
  1500. wrapperrp.eq("record_date", time0).last("and foreign_key_id = project_id");
  1501. List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
  1502. QueryWrapper<ProEconReportIndicatorPool> wrapperrp2 = new QueryWrapper<>();
  1503. wrapperrp2.eq("record_date", time0)
  1504. .in("foreign_key_id", days.stream().map(LineInfoDay::getProjectId).collect(Collectors.toList()));
  1505. List<ProEconReportIndicatorPool> pools2 = reportIndicatorPoolService.list(wrapperrp2);
  1506. if (!pools2.isEmpty()) {
  1507. LineInfoDay day, month, year;
  1508. List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
  1509. String projectId;
  1510. for (ProEconReportIndicatorPool pool : pools2) {
  1511. projectId = pool.getForeignKeyId();
  1512. day = dayMap.get(projectId);
  1513. pool.setRfdldb(day.getRfdl().doubleValue());
  1514. pool.setRswdldb(day.getSwdl());
  1515. pool.setRgwgwdldb(day.getGwdl());
  1516. pool.setRfdcydldb(day.getCydl());
  1517. pool.setRzhcydldb(day.getRfdl().doubleValue() + day.getGwdl() - day.getSwdl());
  1518. month = monthMap.get(projectId);
  1519. pool.setYfdldb(month.getRfdl().doubleValue());
  1520. pool.setYswdldb(month.getSwdl());
  1521. pool.setYgwgwdldb(month.getGwdl());
  1522. pool.setYfdcydldb(month.getCydl());
  1523. pool.setRzhcydldb(month.getRfdl().doubleValue() + month.getGwdl() - month.getSwdl());
  1524. year = yearMap.get(projectId);
  1525. pool.setNfdldb(year.getRfdl().doubleValue());
  1526. pool.setNswdldb(year.getSwdl());
  1527. pool.setNgwgwdldb(year.getGwdl());
  1528. pool.setNfdcydldb(year.getCydl());
  1529. pool.setRzhcydldb(year.getRfdl().doubleValue() + year.getGwdl() - year.getSwdl());
  1530. poolList.add(pool);
  1531. }
  1532. reportIndicatorPoolService.saveOrUpdateBatch(poolList);
  1533. } else {
  1534. List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
  1535. for (LineInfoDay day : days) {
  1536. ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
  1537. pool.setRecordDate(time0.toLocalDateTime().toLocalDate());
  1538. pool.setForeignKeyId(day.getProjectId());
  1539. poolList.add(pool);
  1540. }
  1541. reportIndicatorPoolService.saveOrUpdateBatch(poolList);
  1542. }
  1543. }
  1544. public void writeReportPoolPjfs(Date date) {
  1545. //date当天零点
  1546. DateTime time = DateUtil.beginOfDay(date);
  1547. //date昨天零点
  1548. DateTime time0 = DateUtil.offsetDay(time, -1);
  1549. DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
  1550. DateTime beginOfYear = DateUtil.beginOfYear(time0);
  1551. QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
  1552. wrapper.select("avg(pjfs) pjfs,project_id")
  1553. .eq("record_date", time0)
  1554. .groupBy("project_id");
  1555. List<TurbineInfoDay> days = turbineInfoDayService.list(wrapper);
  1556. Map<String, TurbineInfoDay> dayMap = days.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  1557. wrapper = new QueryWrapper<>();
  1558. wrapper.select("avg(pjfs) pjfs,project_id")
  1559. .between("record_date", beginOfMonth, time0)
  1560. .groupBy("project_id");
  1561. List<TurbineInfoDay> monthDays = turbineInfoDayService.list(wrapper);
  1562. Map<String, TurbineInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  1563. wrapper = new QueryWrapper<>();
  1564. wrapper.select("avg(pjfs) pjfs,project_id")
  1565. .between("record_date", beginOfYear, time0)
  1566. .groupBy("project_id");
  1567. List<TurbineInfoDay> yearDays = turbineInfoDayService.list(wrapper);
  1568. Map<String, TurbineInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  1569. // QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
  1570. // wrapperrp.eq("record_date", time0).last("and foreign_key_id = project_id");
  1571. QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
  1572. wrapperrp.eq("record_date", time0)
  1573. .in("foreign_key_id", days.stream().map(TurbineInfoDay::getProjectId).collect(Collectors.toList()));
  1574. List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
  1575. ProEconReportIndicatorPool GSPJFS = new ProEconReportIndicatorPool();
  1576. GSPJFS.setRecordDate(time0.toLocalDateTime().toLocalDate());
  1577. GSPJFS.setForeignKeyId("GJNY_SXGS_DBXNY_ZGS0");
  1578. GSPJFS.setCompanyId("GJNY_SXGS_DBXNY_ZGS");
  1579. reportIndicatorPoolService.save(GSPJFS);
  1580. wrapperrp = new QueryWrapper<>();
  1581. wrapperrp.eq("record_date", time0).eq("foreign_key_id", "GJNY_SXGS_DBXNY_ZGS0");
  1582. List<ProEconReportIndicatorPool> pools2 = reportIndicatorPoolService.list(wrapperrp);
  1583. TurbineInfoDay day, month, year;
  1584. String projectId;
  1585. if (!pools.isEmpty()) {
  1586. for (ProEconReportIndicatorPool pool : pools) {
  1587. projectId = pool.getForeignKeyId();
  1588. day = dayMap.get(projectId);
  1589. pool.setRpjfs(day.getPjfs());
  1590. month = monthMap.get(projectId);
  1591. pool.setYpjfs(month.getPjfs());
  1592. year = yearMap.get(projectId);
  1593. pool.setNpjfs(year.getPjfs());
  1594. }
  1595. double v1 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getRpjfs).average().orElse(0);
  1596. double v2 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getYpjfs).average().orElse(0);
  1597. double v3 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getNpjfs).average().orElse(0);
  1598. if (CollUtil.isNotEmpty(pools2)) {
  1599. pools2.get(0).setRpjfs(v1);
  1600. pools2.get(0).setYpjfs(v2);
  1601. pools2.get(0).setNpjfs(v3);
  1602. reportIndicatorPoolService.saveOrUpdateBatch(pools2);
  1603. }
  1604. reportIndicatorPoolService.saveOrUpdateBatch(pools);
  1605. } else {
  1606. List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
  1607. for (TurbineInfoDay day2 : days) {
  1608. ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
  1609. pool.setRecordDate(time0.toLocalDateTime().toLocalDate());
  1610. pool.setForeignKeyId(day2.getProjectId());
  1611. poolList.add(pool);
  1612. }
  1613. reportIndicatorPoolService.saveOrUpdateBatch(poolList);
  1614. }
  1615. }
  1616. public void gongsizhibiao() {
  1617. //date当天零点
  1618. DateTime time = DateUtil.beginOfDay(new Date());
  1619. //date昨天零点
  1620. DateTime time0 = DateUtil.offsetDay(time, -1);
  1621. DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
  1622. DateTime beginOfYear = DateUtil.beginOfYear(time0);
  1623. QueryWrapper<ProEconReportIndicatorPool> wrapper = new QueryWrapper<>();
  1624. wrapper.eq("record_date", time0)
  1625. //包含"STA"
  1626. .like("foreign_key_id", "_STA");
  1627. List<ProEconReportIndicatorPool> list = reportIndicatorPoolService.list(wrapper);
  1628. //遍历list,累加指标RFDL
  1629. //公司指标
  1630. double rfdl = 0;
  1631. for (ProEconReportIndicatorPool pool : list) {
  1632. rfdl += pool.getRfdldb();
  1633. }
  1634. }
  1635. }
  1636. }