JavaFunctionJobHandler.java 205 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248
  1. package com.ruoyi.web.controller;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.date.DateField;
  4. import cn.hutool.core.date.DateTime;
  5. import cn.hutool.core.date.DateUtil;
  6. import cn.hutool.core.text.StrBuilder;
  7. import cn.hutool.core.thread.ThreadUtil;
  8. import cn.hutool.core.util.NumberUtil;
  9. import cn.hutool.core.util.StrUtil;
  10. import com.alibaba.fastjson2.JSON;
  11. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  12. import com.ruoyi.quartz.handler.IJobHandler;
  13. import com.ruoyi.ucp.entity.*;
  14. import com.ruoyi.ucp.feign.AdapterApi;
  15. import com.ruoyi.ucp.service.*;
  16. import com.ruoyi.ucp.util.CalcCache;
  17. import org.apache.commons.math3.fitting.PolynomialCurveFitter;
  18. import org.apache.commons.math3.fitting.WeightedObservedPoints;
  19. import org.springframework.data.redis.core.StringRedisTemplate;
  20. import org.springframework.stereotype.Service;
  21. import javax.annotation.Resource;
  22. import java.lang.reflect.Field;
  23. import java.net.URI;
  24. import java.util.*;
  25. import java.util.concurrent.ConcurrentHashMap;
  26. import java.util.concurrent.atomic.AtomicReference;
  27. import java.util.function.Function;
  28. import java.util.stream.Collectors;
  29. @Service
  30. public class JavaFunctionJobHandler extends IJobHandler {
  31. @Resource
  32. private AdapterApi adapter;
  33. @Resource
  34. private IPointInfoService pointService;
  35. @Resource
  36. private IStationInfoHourService stationInfoHourService;
  37. @Resource
  38. private IStationInfoDayService stationInfoDayService;
  39. @Resource
  40. private ILineInfoDayService lineInfoDayService;
  41. @Resource
  42. private IStateAiService stateAiService;
  43. @Resource
  44. private StringRedisTemplate stringRedisTemplate;
  45. @Resource
  46. private IEquipmentModelService equipmentModelService;
  47. @Resource
  48. private ITurbineInfoDayService turbineInfoDayService;
  49. @Resource
  50. private IProEconReportIndicatorPoolService reportIndicatorPoolService;
  51. @Resource
  52. private ITurbineInfoMinService turbineInfoMinService;
  53. @Resource
  54. private IStationInfoMinService stationInfoMinService;
  55. @Resource
  56. private IProBasicProjectPlanService proBasicProjectPlanService;
  57. @Resource
  58. private IHistoryPredictService historyPredictService;
  59. @Resource
  60. private IPredictExaminService predictExaminService;
  61. @Override
  62. public void execute() throws Exception {
  63. }
  64. @Override
  65. public IJobHandler getFunctionHandler() {
  66. return null;
  67. }
  68. @Override
  69. public void setFunctionHandler(IJobHandler jobHandler) {
  70. }
  71. public URI taosGoldenUriTest() {
  72. return URI.create("http://127.0.0.1:8011/ts");
  73. }
  74. public String pointInfos2Keys(List<PointInfo> entity) {
  75. return entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
  76. }
  77. public List<StationInfoHour> getStationinfoByHour(Date hour) {
  78. QueryWrapper<StationInfoHour> wrapper = new QueryWrapper<>();
  79. wrapper.eq("record_date", hour);
  80. return stationInfoHourService.list(wrapper);
  81. }
  82. public List<StationInfoHour> getStationinfoByHour(Date hour, List<PointInfo> entity) {
  83. List<StationInfoHour> byDate = getStationinfoByHour(hour);
  84. if (CollUtil.isEmpty(byDate)) {
  85. entity.forEach(pi -> {
  86. StationInfoHour day = new StationInfoHour();
  87. day.setStationId(pi.getStationId());
  88. day.setRecordDate(hour);
  89. byDate.add(day);
  90. });
  91. }
  92. return byDate;
  93. }
  94. public List<StationInfoDay> getStationinfoByDate(Date date) {
  95. QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
  96. wrapper.eq("record_date", date);
  97. return stationInfoDayService.list(wrapper);
  98. }
  99. public List<StationInfoMin> getStationinfoByMin(Date date) {
  100. QueryWrapper<StationInfoMin> wrapper = new QueryWrapper<>();
  101. wrapper.eq("record_date", date);
  102. return stationInfoMinService.list(wrapper);
  103. }
  104. public List<StationInfoMin> getStationinfoByMin(Date date, List<PointInfo> entity) {
  105. List<StationInfoMin> byDate = getStationinfoByMin(date);
  106. if (CollUtil.isEmpty(byDate)) {
  107. entity.forEach(pi -> {
  108. StationInfoMin day = new StationInfoMin();
  109. day.setStationId(pi.getStationId());
  110. day.setRecordDate(date);
  111. byDate.add(day);
  112. });
  113. }
  114. return byDate;
  115. }
  116. public StationInfoDay getStationinfoByDate(Date date, String stId) {
  117. QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
  118. wrapper.eq("record_date", date).eq("station_id", stId);
  119. List<StationInfoDay> list = stationInfoDayService.list(wrapper);
  120. StationInfoDay day;
  121. if (CollUtil.isEmpty(list)) {
  122. day = new StationInfoDay();
  123. day.setStationId(stId);
  124. day.setRecordDate(date);
  125. } else {
  126. day = list.get(0);
  127. }
  128. return day;
  129. }
  130. public List<StationInfoDay> getStationinfoByDate(Date date, List<PointInfo> entity) {
  131. QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
  132. wrapper.eq("record_date", date);
  133. List<StationInfoDay> list = stationInfoDayService.list(wrapper);
  134. if (CollUtil.isEmpty(list)) {
  135. entity.forEach(pi -> {
  136. StationInfoDay day = new StationInfoDay();
  137. day.setStationId(pi.getStationId());
  138. day.setRecordDate(date);
  139. list.add(day);
  140. });
  141. }
  142. return list;
  143. }
  144. public List<StationInfoDay> getStationinfoByDate2(Date date, List<PointInfo> entity) {
  145. QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
  146. List<String> sts = entity.stream().map(PointInfo::getStationId).collect(Collectors.toList());
  147. wrapper.eq("record_date", date).in("station_id", sts);
  148. List<StationInfoDay> list = stationInfoDayService.list(wrapper);
  149. if (CollUtil.isEmpty(list)) {
  150. entity.forEach(pi -> {
  151. StationInfoDay day = new StationInfoDay();
  152. day.setStationId(pi.getStationId());
  153. day.setRecordDate(date);
  154. list.add(day);
  155. });
  156. }
  157. return list;
  158. }
  159. public List<LineInfoDay> getLineinfoByDate(Date date) {
  160. QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
  161. wrapper.eq("record_date", date);
  162. return lineInfoDayService.list(wrapper);
  163. }
  164. public List<LineInfoDay> getLineinfoByDate(Date date, String stId) {
  165. QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
  166. wrapper.eq("record_date", date).eq("station_id", stId);
  167. return lineInfoDayService.list(wrapper);
  168. }
  169. public List<LineInfoDay> getLineinfoByDate(Date date, List<PointInfo> entity) {
  170. QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
  171. wrapper.eq("record_date", date);
  172. List<LineInfoDay> list = lineInfoDayService.list(wrapper);
  173. if (CollUtil.isEmpty(list)) {
  174. entity.forEach(pi -> {
  175. LineInfoDay day = new LineInfoDay();
  176. day.setStationId(pi.getStationId());
  177. day.setProjectId(pi.getProjectId());
  178. day.setLineId(pi.getLineId());
  179. day.setRecordDate(date);
  180. list.add(day);
  181. });
  182. }
  183. return list;
  184. }
  185. public List<LineInfoDay> getLineinfoByDate2(Date date, List<PointInfo> entity) {
  186. QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
  187. List<String> lines = entity.stream().map(PointInfo::getLineId).collect(Collectors.toList());
  188. wrapper.eq("record_date", date).in("line_id", lines);
  189. List<LineInfoDay> list = lineInfoDayService.list(wrapper);
  190. if (CollUtil.isEmpty(list)) {
  191. entity.forEach(pi -> {
  192. LineInfoDay day = new LineInfoDay();
  193. day.setStationId(pi.getStationId());
  194. day.setProjectId(pi.getProjectId());
  195. day.setLineId(pi.getLineId());
  196. day.setRecordDate(date);
  197. list.add(day);
  198. });
  199. }
  200. return list;
  201. }
  202. public URI taosUri() {
  203. return URI.create("http://172.16.12.101:8012/ts");
  204. }
  205. public URI goldenUri() {
  206. return URI.create("http://172.16.12.103:8011/ts");
  207. }
  208. public Map<String, String> getEntityMap(String uniformCode, String institutionType) {
  209. PointInfo pi = new PointInfo();
  210. pi.setUniformCode(uniformCode);
  211. pi.setInstitutionType(institutionType);
  212. List<PointInfo> entity = pointService.getByEntity(pi);
  213. switch (institutionType) {
  214. case "turbine":
  215. case "state":
  216. return entity.stream().collect(Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointKey));
  217. case "station":
  218. return entity.stream().collect(Collectors.toMap(PointInfo::getStationId, PointInfo::getPointKey));
  219. }
  220. return new HashMap<>();
  221. }
  222. public Map<String, TurbineInfoDay> getTurbineinfoMap(Date date, List<PointInfo> entity) {
  223. QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
  224. wrapper.eq("record_date", date);
  225. List<TurbineInfoDay> list = turbineInfoDayService.list(wrapper);
  226. if (list.isEmpty()) {
  227. entity.forEach(pi -> {
  228. TurbineInfoDay day = new TurbineInfoDay();
  229. day.setStationId(pi.getStationId());
  230. day.setProjectId(pi.getProjectId());
  231. day.setLineId(pi.getLineId());
  232. day.setTurbineId(pi.getTurbineId());
  233. day.setRecordDate(date);
  234. list.add(day);
  235. });
  236. }
  237. return list.stream().collect(Collectors.toMap(TurbineInfoDay::getTurbineId, Function.identity()));
  238. }
  239. public List<PointInfo> getEntity(String uniformCode, String institutionType) {
  240. PointInfo pi = new PointInfo();
  241. pi.setUniformCode(uniformCode);
  242. pi.setInstitutionType(institutionType);
  243. return pointService.getByEntity(pi);
  244. }
  245. public List<PointInfo> getEntityByUis(String uniformCode, String institutionType, String stId) {
  246. PointInfo pi = new PointInfo();
  247. pi.setUniformCode(uniformCode);
  248. pi.setInstitutionType(institutionType);
  249. pi.setStationId(stId);
  250. return pointService.getByEntity(pi);
  251. }
  252. public Map<String, Double> getTurbinePowerLoss(Double rfdl, PointInfo piZt, List<PointData> fsList, List<PointData> glList) {
  253. if (rfdl == null) rfdl = 0.0;
  254. String tbId = piZt.getTurbineId();
  255. // Map<Double, Long> collect = piZt.getPointDatas().stream().collect(Collectors.groupingBy(PointData::getValue, Collectors.counting()));
  256. double sumfs = fsList.stream().mapToDouble(PointData::getValue).sum();
  257. // double xs = 1;
  258. // if (rfdl > 0 && sum1 > 0) {
  259. // xs = rfdl / (sum1 / 240);
  260. // }
  261. // double sum2 = fsList.stream().mapToDouble(pd -> {
  262. // Double v = CalcCache.fitcoef.get(tbId).get(pd.getValue());
  263. // if (v == null) v = 0.0;
  264. // return v;
  265. // }).sum();
  266. // sum2=sum2/240;
  267. List<PointData> collectZt = piZt.getPointDatas();
  268. double jxss = 0, sdtj = 0, gzss = 0, djss = 0, xnss = 0, fdjcl = 0, xdjcl = 0, xdtj = 0;
  269. Map<String, Double> map = new HashMap<>();
  270. if (Math.abs(collectZt.size() - fsList.size()) < 9 && Math.abs(fsList.size() - glList.size()) < 9) {
  271. int min = Math.min(collectZt.size(), Math.min(fsList.size(), glList.size()));
  272. for (int i = 0; i < min; i++) {
  273. Double v = CalcCache.fitcoef.get(tbId).get(fsList.get(i).getValue());
  274. if (v == null) v = 0.0;
  275. v = v - glList.get(i).getValue();
  276. switch ((int) collectZt.get(i).getValue()) {
  277. //计划检修损失:
  278. case 6:
  279. //检修
  280. jxss += v;
  281. break;
  282. case 1:
  283. //手动停机
  284. sdtj += v;
  285. break;
  286. //非计划检修损失:
  287. case 4:
  288. //故障
  289. gzss += v;
  290. break;
  291. case 0:
  292. //待机
  293. djss += v;
  294. break;
  295. //性能损失:
  296. case 2:
  297. //性能
  298. xnss += v;
  299. break;
  300. case 3:
  301. //发电降出力
  302. fdjcl += v;
  303. break;
  304. //限电损失:
  305. case 8:
  306. //限电降出力
  307. xdjcl += v;
  308. break;
  309. case 9:
  310. //限电停机
  311. xdtj += v;
  312. break;
  313. }
  314. }
  315. }
  316. if (jxss > 30000) jxss = 0;
  317. if (sdtj > 30000) sdtj = 0;
  318. if (gzss > 30000) gzss = 0;
  319. if (djss > 30000) djss = 0;
  320. if (xnss > 30000) xnss = 0;
  321. if (fdjcl > 30000) fdjcl = 0;
  322. if (xdjcl > 30000) xdjcl = 0;
  323. if (xdtj > 30000) xdtj = 0;
  324. //15秒*60分钟
  325. map.put("jxss", jxss > 0 ? jxss / 240 : 0);
  326. map.put("sdtj", sdtj > 0 ? sdtj / 240 : 0);
  327. map.put("gzss", gzss > 0 ? gzss / 240 : 0);
  328. map.put("djss", djss > 0 ? djss / 240 : 0);
  329. map.put("xnss", xnss > 0 ? xnss / 240 : 0);
  330. map.put("fdjcl", fdjcl > 0 ? fdjcl / 240 : 0);
  331. map.put("xdjcl", xdjcl > 0 ? xdjcl / 240 : 0);
  332. map.put("xdtj", xdtj > 0 ? xdtj / 240 : 0);
  333. double v = map.get("jxss") + map.get("sdtj") + map.get("gzss") + map.get("djss") + map.get("xnss") + map.get("fdjcl") + map.get("xdjcl") + map.get("xdtj");
  334. System.out.println(piZt.getTurbineId() + ",日发" + rfdl + ",损失" + v + ",风速和" + sumfs / 240);
  335. return map;
  336. }
  337. public void calcAQTS(Date date) {
  338. QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
  339. wrapper.select("min(record_date) record_date");
  340. StationInfoDay one = stationInfoDayService.getOne(wrapper);
  341. wrapper = new QueryWrapper<>();
  342. wrapper.eq("record_date", one.getRecordDate());
  343. //最早时间的列表
  344. List<StationInfoDay> list = stationInfoDayService.list(wrapper);
  345. List<StationInfoDay> today = getStationinfoByDate(date);
  346. if (today.isEmpty()) {
  347. for (StationInfoDay infoDay : list) {
  348. StationInfoDay day = new StationInfoDay();
  349. day.setStationId(infoDay.getStationId());
  350. day.setRecordDate(date);
  351. day.setAqts(infoDay.getAqts() + (int) DateUtil.betweenDay(infoDay.getRecordDate(), date, true));
  352. today.add(day);
  353. }
  354. } else {
  355. Map<String, StationInfoDay> collect = list.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  356. for (StationInfoDay day : today) {
  357. StationInfoDay day1 = collect.get(day.getStationId());
  358. day.setAqts(day1.getAqts() + (int) DateUtil.betweenDay(day1.getRecordDate(), date, true));
  359. }
  360. }
  361. stationInfoDayService.saveOrUpdateBatch(today);
  362. }
  363. public void calcLineSwGWCyDl(Date date) {
  364. //date当天零点
  365. DateTime time = DateUtil.beginOfDay(date);
  366. //date昨天零点
  367. DateTime time0 = DateUtil.offsetDay(time, -1);
  368. List<StationInfoDay> stationInfos = getStationinfoByDate(time0);
  369. Map<String, StationInfoDay> stationMap = stationInfos.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  370. List<LineInfoDay> lineInfos = getLineinfoByDate(time0);
  371. StationInfoDay stationInfo;
  372. for (LineInfoDay lineInfo : lineInfos) {
  373. stationInfo = stationMap.get(lineInfo.getStationId());
  374. double xs = (double) lineInfo.getRfdl() / stationInfo.getRfdl();
  375. lineInfo.setSwdl(xs * stationInfo.getSwdl());
  376. lineInfo.setGwdl(xs * stationInfo.getGwdl());
  377. lineInfo.setCydl(xs * stationInfo.getCydl());
  378. lineInfo.setZyb(xs * stationInfo.getZyb());
  379. }
  380. lineInfoDayService.saveOrUpdateBatch(lineInfos);
  381. }
  382. public void calcLineSwGWCyDlSameDay() {
  383. //date当天零点
  384. DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
  385. List<StationInfoDay> stationInfos = getStationinfoByDate(time0);
  386. Map<String, StationInfoDay> stationMap = stationInfos.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  387. List<LineInfoDay> lineInfos = getLineinfoByDate(time0);
  388. StationInfoDay stationInfo;
  389. for (LineInfoDay lineInfo : lineInfos) {
  390. stationInfo = stationMap.get(lineInfo.getStationId());
  391. double xs = (double) lineInfo.getRfdl() / stationInfo.getRfdl();
  392. lineInfo.setSwdl(xs * stationInfo.getSwdl());
  393. lineInfo.setGwdl(xs * stationInfo.getGwdl());
  394. lineInfo.setCydl(xs * stationInfo.getCydl());
  395. lineInfo.setZyb(xs * stationInfo.getZyb());
  396. }
  397. lineInfoDayService.saveOrUpdateBatch(lineInfos);
  398. }
  399. public void calcLineSwGWCyDl(Date date, String stId) {
  400. //date当天零点
  401. DateTime time = DateUtil.beginOfDay(date);
  402. //date昨天零点
  403. DateTime time0 = DateUtil.offsetDay(time, -1);
  404. StationInfoDay sti = getStationinfoByDate(time0, stId);
  405. List<LineInfoDay> lineInfos = getLineinfoByDate(time0, stId);
  406. for (LineInfoDay lineInfo : lineInfos) {
  407. double xs = (double) lineInfo.getRfdl() / sti.getRfdl();
  408. lineInfo.setSwdl(xs * sti.getSwdl());
  409. lineInfo.setGwdl(xs * sti.getGwdl());
  410. lineInfo.setCydl(xs * sti.getCydl());
  411. lineInfo.setZyb(xs * sti.getZyb());
  412. }
  413. lineInfoDayService.saveOrUpdateBatch(lineInfos);
  414. }
  415. public void calcStationZhcyRfDl(Date date) {
  416. //date当天零点
  417. DateTime time = DateUtil.beginOfDay(date);
  418. //date昨天零点
  419. DateTime time0 = DateUtil.offsetDay(time, -1);
  420. QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
  421. wrapper.select("sum(rfdl) rfdl,station_id").eq("record_date", time0).groupBy("station_id");
  422. List<LineInfoDay> list = lineInfoDayService.list(wrapper);
  423. Map<String, Integer> rfdlMap = list.stream().collect(Collectors.toMap(LineInfoDay::getStationId, LineInfoDay::getRfdl));
  424. List<StationInfoDay> byDate = getStationinfoByDate(time0);
  425. for (StationInfoDay day : byDate) {
  426. day.setRfdl(rfdlMap.get(day.getStationId()));
  427. day.setZhcydl(day.getRfdl() + day.getGwdl() - day.getSwdl());
  428. day.setCydl(day.getZhcydl() - day.getZyb());
  429. }
  430. stationInfoDayService.saveOrUpdateBatch(byDate);
  431. }
  432. public void calcStationRjhfdl(Date month) {
  433. DateTime begin = DateUtil.beginOfMonth(month);
  434. DateTime end = DateUtil.endOfMonth(month);
  435. DateTime beginTq = DateUtil.offset(begin, DateField.YEAR, -1);
  436. DateTime endTq = DateUtil.offset(end, DateField.YEAR, -1);
  437. QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
  438. wrapper.lambda().between(StationInfoDay::getRecordDate, begin, end);
  439. List<StationInfoDay> days = stationInfoDayService.list(wrapper);
  440. Map<String, Map<String, StationInfoDay>> dayMap = new HashMap<>();
  441. if (CollUtil.isNotEmpty(days)) {
  442. dayMap = days.stream().collect(Collectors.groupingBy(StationInfoDay::getStationId,
  443. Collectors.toMap(sid -> DateUtil.date(sid.getRecordDate()).toString(), Function.identity())));
  444. }
  445. wrapper.clear();
  446. wrapper.lambda().between(StationInfoDay::getRecordDate, beginTq, endTq);
  447. List<StationInfoDay> sids = stationInfoDayService.list(wrapper);
  448. Map<String, List<StationInfoDay>> sidMap;
  449. if (CollUtil.isNotEmpty(sids)) {
  450. sidMap = sids.stream().collect(Collectors.groupingBy(StationInfoDay::getStationId));
  451. } else {
  452. sidMap = null;
  453. }
  454. QueryWrapper<ProBasicProjectPlan> wrapperPlan = new QueryWrapper<>();
  455. wrapperPlan.lambda().eq(ProBasicProjectPlan::getYear, String.valueOf(begin.year()))
  456. .eq(ProBasicProjectPlan::getMonth, String.valueOf(begin.month() + 1));
  457. List<ProBasicProjectPlan> plantList = proBasicProjectPlanService.list(wrapperPlan);
  458. for (ProBasicProjectPlan plan : plantList) {
  459. String stId = plan.getWindpowerstationId();
  460. Map<String, StationInfoDay> daym = dayMap.get(stId);
  461. if (daym == null) daym = new HashMap<>();
  462. if (sidMap == null) {
  463. for (StationInfoDay day : daym.values()) {
  464. day.setJhfdl(plan.getGeneratingCapacity() / daym.size());
  465. }
  466. } else {
  467. //去年月发电量
  468. List<StationInfoDay> sidList = sidMap.get(stId);
  469. double rfdlSum = sidList.stream().mapToDouble(StationInfoDay::getRfdl).sum();
  470. double v = plan.getGeneratingCapacity() / rfdlSum;
  471. for (StationInfoDay sid : sidList) {
  472. DateTime time = DateUtil.offset(sid.getRecordDate(), DateField.YEAR, 1);
  473. StationInfoDay day = daym.get(time.toString());
  474. if (day == null) {
  475. day = new StationInfoDay();
  476. day.setStationId(stId);
  477. day.setRecordDate(time);
  478. days.add(day);
  479. }
  480. day.setJhfdl(v * sid.getRfdl());
  481. }
  482. }
  483. }
  484. stationInfoDayService.saveOrUpdateBatch(days);
  485. }
  486. public void calcStationZhcyRfDlSameDay() {
  487. //date当天零点
  488. DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
  489. QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
  490. wrapper.select("sum(rfdl) rfdl,station_id").eq("record_date", time0).groupBy("station_id");
  491. List<LineInfoDay> list = lineInfoDayService.list(wrapper);
  492. Map<String, Integer> rfdlMap = list.stream().collect(Collectors.toMap(LineInfoDay::getStationId, LineInfoDay::getRfdl));
  493. List<StationInfoDay> byDate = getStationinfoByDate(time0);
  494. for (StationInfoDay day : byDate) {
  495. day.setRfdl(rfdlMap.get(day.getStationId()));
  496. day.setZhcydl(day.getRfdl() + day.getGwdl() - day.getSwdl());
  497. day.setCydl(day.getZhcydl() - day.getZyb());
  498. }
  499. stationInfoDayService.saveOrUpdateBatch(byDate);
  500. }
  501. public void calcStationZhcyRfDl(Date date, String stId) {
  502. //date当天零点
  503. DateTime time = DateUtil.beginOfDay(date);
  504. //date昨天零点
  505. DateTime time0 = DateUtil.offsetDay(time, -1);
  506. QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
  507. wrapper.select("sum(rfdl) rfdl,station_id").eq("record_date", time0)
  508. .eq("station_id", stId).groupBy("station_id");
  509. List<LineInfoDay> list = lineInfoDayService.list(wrapper);
  510. Map<String, Integer> rfdlMap = list.stream().collect(Collectors.toMap(LineInfoDay::getStationId, LineInfoDay::getRfdl));
  511. StationInfoDay day = getStationinfoByDate(time0, stId);
  512. day.setRfdl(rfdlMap.get(day.getStationId()));
  513. day.setZhcydl(day.getRfdl() + day.getGwdl() - day.getSwdl());
  514. day.setCydl(day.getZhcydl() - day.getZyb());
  515. stationInfoDayService.saveOrUpdateBatch(Collections.singleton(day));
  516. }
  517. public void calcStationSwGwCyRdl(Date date) {
  518. //date当天零点
  519. DateTime time = DateUtil.beginOfDay(date);
  520. //date昨天零点
  521. DateTime time0 = DateUtil.offsetDay(time, -1);
  522. List<PointInfo> swdlEt = getEntity("Z-ZXYG-CX", "meter");
  523. List<PointInfo> gwdlEt = getEntity("Z-FXYG-CX", "meter");
  524. List<PointInfo> cydlEt = getEntity("Z-ZXYG-ZYB", "meter");
  525. getZeroNextData(swdlEt, time0, time);
  526. getZeroNextData(gwdlEt, time0, time);
  527. getZeroNextData(cydlEt, time0, time);
  528. Map<String, PointInfo> swdlMap = swdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  529. Map<String, PointInfo> gwdlMap = gwdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  530. Map<String, PointInfo> cydlMap = cydlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  531. List<StationInfoDay> byDate = getStationinfoByDate(time0, swdlEt);
  532. String stId;
  533. PointInfo swdlPi, gwdlPi, cydlPi;
  534. for (StationInfoDay info : byDate) {
  535. stId = info.getStationId();
  536. swdlPi = swdlMap.get(stId);
  537. gwdlPi = gwdlMap.get(stId);
  538. cydlPi = cydlMap.get(stId);
  539. int swdl = (int) ((swdlPi.getPointDatas().get(1).getValue() - swdlPi.getPointDatas().get(0).getValue()) * swdlPi.getCoef());
  540. int gwdl = (int) ((gwdlPi.getPointDatas().get(1).getValue() - gwdlPi.getPointDatas().get(0).getValue()) * gwdlPi.getCoef());
  541. int cydl = (int) ((cydlPi.getPointDatas().get(1).getValue() - cydlPi.getPointDatas().get(0).getValue()) * cydlPi.getCoef());
  542. if (swdl < 0 || swdl > 6000000) swdl = 0;
  543. if (gwdl < 0 || gwdl > 6000000) gwdl = 0;
  544. if (cydl < 0 || cydl > 6000000) cydl = 0;
  545. info.setSwdl(swdl);
  546. info.setGwdl(gwdl);
  547. info.setZyb(cydl);
  548. }
  549. stationInfoDayService.saveOrUpdateBatch(byDate);
  550. }
  551. public void calcStationSwGwCyDlSameDay() {
  552. //date当天零点
  553. DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
  554. List<PointInfo> swdlEt = getEntity("Z-ZXYG-CX", "meter");
  555. List<PointInfo> gwdlEt = getEntity("Z-FXYG-CX", "meter");
  556. List<PointInfo> cydlEt = getEntity("Z-ZXYG-ZYB", "meter");
  557. getZeroNextData(swdlEt, time0);
  558. getZeroNextData(gwdlEt, time0);
  559. getZeroNextData(cydlEt, time0);
  560. Map<String, PointInfo> swdlMap = swdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  561. Map<String, PointInfo> gwdlMap = gwdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  562. Map<String, PointInfo> cydlMap = cydlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  563. List<StationInfoDay> byDate = getStationinfoByDate(time0, swdlEt);
  564. String stId;
  565. PointInfo swdlPi, gwdlPi, cydlPi;
  566. for (StationInfoDay info : byDate) {
  567. stId = info.getStationId();
  568. swdlPi = swdlMap.get(stId);
  569. gwdlPi = gwdlMap.get(stId);
  570. cydlPi = cydlMap.get(stId);
  571. int swdl = (int) ((swdlPi.getPointDatas().get(1).getValue() - swdlPi.getPointDatas().get(0).getValue()) * swdlPi.getCoef());
  572. int gwdl = (int) ((gwdlPi.getPointDatas().get(1).getValue() - gwdlPi.getPointDatas().get(0).getValue()) * gwdlPi.getCoef());
  573. int cydl = (int) ((cydlPi.getPointDatas().get(1).getValue() - cydlPi.getPointDatas().get(0).getValue()) * cydlPi.getCoef());
  574. if (swdl < 0 || swdl > 6000000) swdl = 0;
  575. if (gwdl < 0 || gwdl > 6000000) gwdl = 0;
  576. if (cydl < 0 || cydl > 6000000) cydl = 0;
  577. info.setSwdl(swdl);
  578. info.setGwdl(gwdl);
  579. info.setZyb(cydl);
  580. }
  581. stationInfoDayService.saveOrUpdateBatch(byDate);
  582. }
  583. public void calcStationSwGwCyRdl(Date date, String stId) {
  584. //date当天零点
  585. DateTime time = DateUtil.beginOfDay(date);
  586. //date昨天零点
  587. DateTime time0 = DateUtil.offsetDay(time, -1);
  588. List<PointInfo> swdlEt = getEntityByUis("Z-ZXYG-CX", "meter", stId);
  589. List<PointInfo> gwdlEt = getEntityByUis("Z-FXYG-CX", "meter", stId);
  590. List<PointInfo> cydlEt = getEntityByUis("Z-ZXYG-ZYB", "meter", stId);
  591. getZeroNextData(swdlEt, time0, time);
  592. getZeroNextData(gwdlEt, time0, time);
  593. getZeroNextData(cydlEt, time0, time);
  594. List<StationInfoDay> byDate = getStationinfoByDate2(time0, swdlEt);
  595. StationInfoDay info = byDate.get(0);
  596. PointInfo swdlPi = swdlEt.get(0);
  597. PointInfo gwdlPi = gwdlEt.get(0);
  598. PointInfo cydlPi = cydlEt.get(0);
  599. int swdl = (int) ((swdlPi.getPointDatas().get(1).getValue() - swdlPi.getPointDatas().get(0).getValue()) * swdlPi.getCoef());
  600. int gwdl = (int) ((gwdlPi.getPointDatas().get(1).getValue() - gwdlPi.getPointDatas().get(0).getValue()) * gwdlPi.getCoef());
  601. int cydl = (int) ((cydlPi.getPointDatas().get(1).getValue() - cydlPi.getPointDatas().get(0).getValue()) * cydlPi.getCoef());
  602. if (stId.equals("GJNY_SXGS_JSL_FDC_STA") && time0.before(DateUtil.parse("2024-07-08"))) {
  603. swdl = swdl * 100;
  604. gwdl = gwdl * 100;
  605. }
  606. if (swdl < 0 || swdl > 6000000) swdl = 0;
  607. if (gwdl < 0 || gwdl > 6000000) gwdl = 0;
  608. if (cydl < 0 || cydl > 6000000) cydl = 0;
  609. info.setSwdl(swdl);
  610. info.setGwdl(gwdl);
  611. info.setZyb(cydl);
  612. stationInfoDayService.saveOrUpdateBatch(byDate);
  613. }
  614. public void SwdlRepair(Date date) {
  615. //date当天零点
  616. DateTime time = DateUtil.beginOfDay(date);
  617. //date昨天零点
  618. DateTime time0 = DateUtil.offsetDay(time, -1);
  619. List<PointInfo> swdlEt = getEntity("Z-ZXYG-CX", "meter");
  620. Map<String, PointInfo> map = swdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  621. List<StationInfoDay> list = getStationinfoByDate(time0);
  622. Map<String, StationInfoDay> dayMap = list.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  623. CalcCache.swdlTime.forEach((key, ts) -> {
  624. int swdl = 0;
  625. PointData data1, data0;
  626. double ll = (double) (time.getTime() - ts) / 23 * 60 * 60 * 1000;
  627. if (ts > 0 && (ll > 23 && ll < 25)) {
  628. StationInfoDay day = dayMap.get(key);
  629. PointInfo info = map.get(key);
  630. List<PointData> raw1 = adapter.getHistoryRaw(goldenUri(), key, time.getTime(), DateUtil.offsetMinute(time, 6).getTime());
  631. if (CollUtil.isEmpty(raw1)) {
  632. Map<String, PointData> section = adapter.getHistorySection(goldenUri(), key, time.getTime() + 1000);
  633. data1 = section.get(key);
  634. } else {
  635. data1 = raw1.get(0);
  636. }
  637. Map<String, PointData> section = adapter.getHistorySection(goldenUri(), key, ts + 1000);
  638. data0 = section.get(key);
  639. swdl = (int) ((data1.getValue() - data0.getValue()) * info.getCoef());
  640. if (swdl > day.getRfdl()) {
  641. List<PointData> rawl1 = adapter.getHistoryRaw(goldenUri(), key, DateUtil.offsetMinute(time, -60).getTime(), time.getTime());
  642. for (int i = rawl1.size() - 1; i >= 0; i--) {
  643. swdl = (int) ((rawl1.get(i).getValue() - data0.getValue()) * info.getCoef());
  644. if (swdl <= day.getRfdl()) {
  645. day.setSwdl(swdl);
  646. day.setZhcydl(day.getRfdl() + day.getGwdl() - day.getSwdl());
  647. day.setCydl(day.getZhcydl() - day.getZyb());
  648. CalcCache.swdlTime.put(info.getPointKey(), rawl1.get(i).getTs());
  649. break;
  650. }
  651. }
  652. } else {
  653. day.setSwdl(swdl);
  654. day.setZhcydl(day.getRfdl() + day.getGwdl() - day.getSwdl());
  655. day.setCydl(day.getZhcydl() - day.getZyb());
  656. }
  657. }
  658. });
  659. for (StationInfoDay day : list) {
  660. int swdl = 0;
  661. if (day.getSwdl() > day.getRfdl()) {
  662. PointInfo info = map.get(day.getStationId());
  663. Long l = CalcCache.swdlTime.get(info.getPointKey());
  664. PointData data0;
  665. if (l == null || l == 0) {
  666. List<PointData> raw0 = adapter.getHistoryRaw(goldenUri(), info.getPointKey(), time0.getTime(), DateUtil.offsetMinute(time0, 6).getTime());
  667. if (CollUtil.isEmpty(raw0)) {
  668. Map<String, PointData> section = adapter.getHistorySection(goldenUri(), info.getPointKey(), time0.getTime() + 1000);
  669. data0 = section.get(info.getPointKey());
  670. } else {
  671. data0 = raw0.get(0);
  672. }
  673. } else {
  674. double ll = (double) (time.getTime() - l) / 23 * 60 * 60 * 1000;
  675. if (ll > 23 && ll < 25) {
  676. Map<String, PointData> section = adapter.getHistorySection(goldenUri(), info.getPointKey(), l + 1000);
  677. data0 = section.get(info.getPointKey());
  678. } else {
  679. continue;
  680. }
  681. }
  682. List<PointData> raw1 = adapter.getHistoryRaw(goldenUri(), info.getPointKey(), DateUtil.offsetMinute(time, -60).getTime(), time.getTime());
  683. for (int i = raw1.size() - 1; i >= 0; i--) {
  684. swdl = (int) ((raw1.get(i).getValue() - data0.getValue()) * info.getCoef());
  685. if (swdl <= day.getRfdl()) {
  686. day.setSwdl(swdl);
  687. day.setZhcydl(day.getRfdl() + day.getGwdl() - day.getSwdl());
  688. day.setCydl(day.getZhcydl() - day.getZyb());
  689. CalcCache.swdlTime.put(info.getPointKey(), raw1.get(i).getTs());
  690. break;
  691. }
  692. }
  693. }
  694. }
  695. stationInfoDayService.saveOrUpdateBatch(list);
  696. stringRedisTemplate.opsForValue().set("swdlTime", JSON.toJSONString(CalcCache.swdlTime));
  697. }
  698. public void getZeroNextData(List<PointInfo> entity, Date start0, Date start) {
  699. List<PointData> snap0, snap;
  700. for (PointInfo info : entity) {
  701. PointData data0, data;
  702. List<PointData> datas = new ArrayList<>();
  703. snap0 = adapter.getHistoryRaw(goldenUri(), info.getPointKey(), start0.getTime(), DateUtil.offsetMinute(start0, 6).getTime());
  704. if (CollUtil.isEmpty(snap0)) {
  705. Map<String, PointData> section = adapter.getHistorySection(goldenUri(), info.getPointKey(), start0.getTime());
  706. snap0 = new ArrayList<>(section.values());
  707. }
  708. snap = adapter.getHistoryRaw(goldenUri(), info.getPointKey(), start.getTime(), DateUtil.offsetMinute(start, 6).getTime());
  709. if (CollUtil.isEmpty(snap)) {
  710. Map<String, PointData> section = adapter.getHistorySection(goldenUri(), info.getPointKey(), start.getTime());
  711. snap = new ArrayList<>(section.values());
  712. }
  713. if (CollUtil.isEmpty(snap0) || CollUtil.isEmpty(snap)) {
  714. data0 = new PointData();
  715. data = new PointData();
  716. } else {
  717. data0 = snap0.get(0);
  718. data = snap.get(0);
  719. }
  720. datas.add(data0);
  721. datas.add(data);
  722. info.setPointDatas(datas);
  723. }
  724. }
  725. public void getZeroNextData(List<PointInfo> entity, Date start0) {
  726. String keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
  727. Map<String, PointData> latest = adapter.getLatest(goldenUri(), keys);
  728. List<PointData> snap0;
  729. for (PointInfo info : entity) {
  730. PointData data0, data;
  731. List<PointData> datas = new ArrayList<>();
  732. snap0 = adapter.getHistoryRaw(goldenUri(), info.getPointKey(), start0.getTime(), DateUtil.offsetMinute(start0, 90).getTime());
  733. if (CollUtil.isEmpty(snap0)) {
  734. Map<String, PointData> section = adapter.getHistorySection(goldenUri(), info.getPointKey(), start0.getTime());
  735. snap0 = new ArrayList<>(section.values());
  736. }
  737. data = latest.get(info.getPointKey());
  738. if (CollUtil.isEmpty(snap0) || data == null) {
  739. data0 = new PointData();
  740. data = new PointData();
  741. } else {
  742. data0 = snap0.get(0);
  743. }
  744. datas.add(data0);
  745. datas.add(data);
  746. info.setPointDatas(datas);
  747. }
  748. }
  749. public void calcStationHourRFDL(Date hour) {
  750. PointInfo pointInfo = new PointInfo();
  751. pointInfo.setInstitutionType("station");
  752. pointInfo.setUniformCode("RFDLSYZ");
  753. List<PointInfo> entity = pointService.getByEntity(pointInfo);
  754. Map<String, PointData> section = adapter.getHistorySection(taosUri(), pointInfos2Keys(entity), hour.getTime());
  755. List<StationInfoHour> byHours = getStationinfoByHour(hour);
  756. if (byHours.isEmpty()) {
  757. for (PointInfo point : entity) {
  758. StationInfoHour info = new StationInfoHour();
  759. info.setStationId(point.getStationId());
  760. info.setRecordDate(DateUtil.beginOfHour(hour));
  761. info.setRfdl(section.get(point.getPointKey()).getValue());
  762. byHours.add(info);
  763. }
  764. } else {
  765. Map<String, String> collect = entity.stream().collect(Collectors.toMap(PointInfo::getStationId, PointInfo::getPointKey));
  766. for (StationInfoHour byHour : byHours) {
  767. byHour.setRfdl(section.get(collect.get(byHour.getStationId())).getValue());
  768. }
  769. }
  770. stationInfoHourService.saveOrUpdateBatch(byHours);
  771. }
  772. public void calcLineRfdl(Date date) {
  773. //date当天零点
  774. DateTime time = DateUtil.beginOfDay(date);
  775. //date昨天零点
  776. DateTime time0 = DateUtil.offsetDay(time, -1);
  777. List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
  778. entity = entity.stream().filter(e -> !"".equals(e.getProjectId())).collect(Collectors.toList());
  779. getZeroNextData(entity, time0, time);
  780. Map<String, PointInfo> swdlMap = entity.stream().collect(Collectors.toMap(PointInfo::getLineId, Function.identity()));
  781. List<LineInfoDay> byDate = getLineinfoByDate(time0, entity);
  782. String lineId;
  783. PointInfo swdlPi;
  784. int v = 0;
  785. for (LineInfoDay day : byDate) {
  786. lineId = day.getLineId();
  787. swdlPi = swdlMap.get(lineId);
  788. v = (int) ((swdlPi.getPointDatas().get(1).getValue() - swdlPi.getPointDatas().get(0).getValue()) * swdlPi.getCoef());
  789. if (v < 0 || v > 30000000) v = 0;
  790. day.setRfdl(v);
  791. }
  792. lineInfoDayService.saveOrUpdateBatch(byDate);
  793. }
  794. public void calcTurbineRFDLSameDay() {
  795. DateTime time = DateUtil.date();
  796. //date当天零点
  797. DateTime time0 = DateUtil.beginOfDay(time);
  798. List<PointInfo> entity = getEntity("AI121", "turbine");
  799. getZeroNextData(entity, time0, time);
  800. Map<String, PointInfo> turMap = entity.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  801. Map<String, String> fsMap = getEntityMap("AI066", "turbine");
  802. Map<String, TurbineInfoDay> byDate = getTurbineinfoMap(time0, entity);
  803. TurbineInfoDay infoDay;
  804. PointInfo rfdlPi;
  805. String turbineId;
  806. List<TurbineInfoDay> infoDays = new ArrayList<>();
  807. DoubleStatData stat;
  808. for (PointInfo info : entity) {
  809. turbineId = info.getTurbineId();
  810. infoDay = byDate.get(turbineId);
  811. rfdlPi = turMap.get(turbineId);
  812. double v = (rfdlPi.getPointDatas().get(1).getValue() - rfdlPi.getPointDatas().get(0).getValue()) * rfdlPi.getCoef();
  813. if (v < 0 || v > 1000000) {
  814. v = 0;
  815. } else if (v > 30000) {
  816. v = v / (v % 30000 + 3);
  817. }
  818. infoDay.setRfdl(v);
  819. stat = adapter.getHistoryStat(goldenUri(), fsMap.get(turbineId), time0.getTime(), time.getTime());
  820. if (stat == null) {
  821. infoDay.setPjfs(0.0);
  822. } else {
  823. infoDay.setPjfs(stat.getAvg().getValue());
  824. }
  825. infoDays.add(infoDay);
  826. }
  827. turbineInfoDayService.saveOrUpdateBatch(infoDays);
  828. }
  829. public void calcTurbine5s2SameDay() {
  830. DateTime time = DateUtil.date();
  831. //date当天零点
  832. DateTime time0 = DateUtil.beginOfDay(time);
  833. //风速
  834. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  835. //功率
  836. List<PointInfo> entityGl = getEntity("AI114", "turbine");
  837. //状态
  838. List<PointInfo> entityZT = getEntity("MXZT", "turbine");
  839. Map<String, Map<String, PointInfo>> ztMapMapInfos = entityZT.stream().collect(Collectors.groupingBy(PointInfo::getStationId, Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
  840. Map<String, TurbineInfoDay> dayMap = getTurbineinfoMap(time0, entityFs);
  841. List<TurbineInfoDay> infoDays = new ArrayList<>();
  842. Map<String, Map<String, PointInfo>> fsMapMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId, Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
  843. Map<String, Map<String, PointInfo>> glMapMap = entityGl.stream().collect(Collectors.groupingBy(PointInfo::getStationId, Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
  844. ztMapMapInfos.forEach((stId, ztMapInfo) -> ztMapInfo.forEach((wtId, ztInfo) -> {
  845. //0 待机,1 手动停机,2 正常发电,3 发电降出力,4 故障,5 故障受累,6 检修,7 检修受累,8 限电降出力,
  846. // 9 限电停机,10 电网受累,11 环境受累,12 通讯中断,13 设备离线
  847. TurbineInfoDay infoDay = dayMap.get(wtId);
  848. PointInfo fspi = fsMapMap.get(stId).get(wtId);
  849. PointInfo glpi = glMapMap.get(stId).get(wtId);
  850. getSnapDataByEntity(fspi, time0, time, 15);
  851. getSnapDataByEntity(glpi, time0, time, 15);
  852. getSnapDataByEntity(ztInfo, taosUri(), time0, time, 15);
  853. List<PointData> fsData = fspi.getPointDatas();
  854. fsData = fsData.stream().peek(pd -> pd.setDoubleValue(NumberUtil.round(pd.getValue() > 25 ? 25.0 : pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
  855. Map<String, Double> loss = getTurbinePowerLoss(infoDay.getRfdl(), ztInfo, fsData, glpi.getPointDatas());
  856. infoDay.setJhjxss(loss.get("jxss") + loss.get("sdtj"));
  857. infoDay.setFjhjxss(loss.get("gzss") + loss.get("djss") + loss.get("fdjcl"));
  858. infoDay.setXdss(loss.get("xdjcl") + loss.get("xdtj"));
  859. infoDay.setSlss(0.0);
  860. infoDay.setDjss(loss.get("djss"));
  861. infoDay.setGzss(loss.get("gzss"));
  862. if (infoDay.getRfdl() == 0) {
  863. infoDay.setXnss(0.0);
  864. } else {
  865. infoDay.setXnss(loss.get("xnss"));
  866. }
  867. infoDay.setLlfdl(infoDay.getRfdl() + infoDay.getJhjxss() + infoDay.getFjhjxss() + infoDay.getXdss() + infoDay.getSlss() + infoDay.getXnss());
  868. infoDays.add(infoDay);
  869. }));
  870. turbineInfoDayService.saveOrUpdateBatch(infoDays);
  871. }
  872. public void calcLineRfdlSameDay() {
  873. //date当天零点
  874. DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
  875. List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
  876. entity = entity.stream().filter(e -> !"".equals(e.getProjectId())).collect(Collectors.toList());
  877. getZeroNextData(entity, time0);
  878. Map<String, PointInfo> rfdlMap = entity.stream().collect(Collectors.toMap(PointInfo::getLineId, Function.identity()));
  879. List<LineInfoDay> byDate = getLineinfoByDate(time0, entity);
  880. PointInfo rfdlPi;
  881. int v;
  882. for (LineInfoDay day : byDate) {
  883. rfdlPi = rfdlMap.get(day.getLineId());
  884. v = (int) ((rfdlPi.getPointDatas().get(1).getValue() - rfdlPi.getPointDatas().get(0).getValue()) * rfdlPi.getCoef());
  885. if (v < 0 || v > 30000000) v = 0;
  886. day.setRfdl(v);
  887. }
  888. lineInfoDayService.saveOrUpdateBatch(byDate);
  889. }
  890. public void calcLineRfdl(Date date, String stId) {
  891. //date当天零点
  892. DateTime time = DateUtil.beginOfDay(date);
  893. //date昨天零点
  894. DateTime time0 = DateUtil.offsetDay(time, -1);
  895. List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
  896. entity = entity.stream().filter(e -> StrUtil.isNotEmpty(e.getProjectId()) && Objects.equals(stId, e.getStationId())).collect(Collectors.toList());
  897. getZeroNextData(entity, time0, time);
  898. Map<String, PointInfo> swdlMap = entity.stream().collect(Collectors.toMap(PointInfo::getLineId, Function.identity()));
  899. List<LineInfoDay> byDate = getLineinfoByDate2(time0, entity);
  900. String lineId;
  901. PointInfo swdlPi;
  902. int v = 0;
  903. for (LineInfoDay day : byDate) {
  904. lineId = day.getLineId();
  905. swdlPi = swdlMap.get(lineId);
  906. v = (int) ((swdlPi.getPointDatas().get(1).getValue() - swdlPi.getPointDatas().get(0).getValue()) * swdlPi.getCoef());
  907. if (v < 0 || v > 30000000) v = 0;
  908. day.setRfdl(v);
  909. }
  910. lineInfoDayService.saveOrUpdateBatch(byDate);
  911. }
  912. public void calcLineDjlRfdl(Date date) {
  913. //date当天零点
  914. DateTime time = DateUtil.beginOfDay(date);
  915. //date昨天零点
  916. DateTime time0 = DateUtil.offsetDay(time, -1);
  917. //date当天零点加三分钟
  918. DateTime time2 = DateUtil.offsetMinute(time, 3);
  919. //date昨天零点加三分钟
  920. DateTime time1 = DateUtil.offsetMinute(time0, 3);
  921. PointInfo pi = new PointInfo();
  922. pi.setUniformCode("Z-ZXYG-JX");
  923. pi.setLineId("all");
  924. List<PointInfo> entity = pointService.getByEntity(pi);
  925. // entity = entity.stream().filter(e -> e.getStationId().equals("GJNY_SXGS_ZZ_FDC_STA")).collect(Collectors.toList());
  926. String keys = pointInfos2Keys(entity);
  927. Map<String, PointData> latest2 = adapter.getHistorySection(goldenUri(), keys, time2.getTime());
  928. Map<String, PointData> latest1 = adapter.getHistorySection(goldenUri(), keys, time1.getTime());
  929. List<LineInfoDay> byDate = getLineinfoByDate(time0);
  930. Map<String, LineInfoDay> collect = new HashMap<>();
  931. if (!byDate.isEmpty()) {
  932. collect = byDate.stream().collect(Collectors.toMap(LineInfoDay::getLineId, Function.identity()));
  933. }
  934. List<LineInfoDay> list = new ArrayList<>();
  935. for (PointInfo info : entity) {
  936. LineInfoDay day;
  937. if (byDate.isEmpty()) {
  938. day = new LineInfoDay();
  939. day.setStationId(info.getStationId());
  940. day.setProjectId(info.getProjectId());
  941. day.setLineId(info.getLineId());
  942. day.setRecordDate(time0);
  943. } else {
  944. day = collect.get(info.getLineId());
  945. }
  946. day.setRfdl((int) ((latest2.get(info.getPointKey()).getValue() - latest1.get(info.getPointKey()).getValue()) * info.getCoef()));
  947. if (day.getRfdl() <= 0 || day.getRfdl() > 30000000) {
  948. day.setRfdl(0);
  949. }
  950. list.add(day);
  951. }
  952. lineInfoDayService.saveOrUpdateBatch(list);
  953. }
  954. public int test(Date date, String key, int coef) {
  955. //date当天零点
  956. DateTime time = DateUtil.beginOfDay(date);
  957. //date昨天零点
  958. DateTime time0 = DateUtil.offsetDay(time, -1);
  959. PointInfo info = new PointInfo();
  960. info.setPointKey(key);
  961. getZeroNextData(Collections.singletonList(info), time0, time);
  962. int swdl = (int) ((info.getPointDatas().get(1).getValue() - info.getPointDatas().get(0).getValue()) * coef);
  963. return swdl;
  964. }
  965. public void calcStationZhcydl(Date date) {
  966. //date当天零点
  967. DateTime time = DateUtil.beginOfDay(date);
  968. //date昨天零点
  969. DateTime time0 = DateUtil.offsetDay(time, -1);
  970. QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
  971. wrapper.select("sum(rfdl) rfdl,station_id").eq("record_date", time0).groupBy("station_id");
  972. List<LineInfoDay> list = lineInfoDayService.list(wrapper);
  973. List<StationInfoDay> byDate = getStationinfoByDate(time0);
  974. // list = list.stream().filter(b -> b.getStationId().equals("GJNY_SXGS_ZZ_FDC_STA")).collect(Collectors.toList());
  975. Map<String, StationInfoDay> collect = new HashMap<>();
  976. if (!byDate.isEmpty()) {
  977. collect = byDate.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  978. }
  979. StationInfoDay infoDay;
  980. List<StationInfoDay> infoDays = new ArrayList<>();
  981. for (LineInfoDay day : list) {
  982. if (byDate.isEmpty()) {
  983. infoDay = new StationInfoDay();
  984. infoDay.setStationId(day.getStationId());
  985. infoDay.setRecordDate(time0);
  986. } else {
  987. infoDay = collect.get(day.getStationId());
  988. }
  989. infoDay.setRfdl(day.getRfdl());
  990. infoDay.setZhcydl(infoDay.getRfdl() + infoDay.getGwdl() - infoDay.getSwdl());
  991. infoDays.add(infoDay);
  992. }
  993. stationInfoDayService.saveOrUpdateBatch(infoDays);
  994. }
  995. public void calcStationHourPjglRfdl(Date hour) {
  996. //hour整点
  997. DateTime time = DateUtil.beginOfHour(hour);
  998. //1小时前
  999. DateTime time0 = DateUtil.offsetHour(time, -1);
  1000. //当天零点
  1001. DateTime rft = DateUtil.beginOfDay(time);
  1002. List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
  1003. //出线
  1004. List<PointInfo> entityCx = getEntity("AGC001", "booster");
  1005. Map<String, PointInfo> statMapCx = getStatDataByEntity(entityCx, goldenUri(), time0, time, PointInfo::getStationId);
  1006. List<StationInfoHour> byHours = getStationinfoByHour(time, entityCx);
  1007. entity = entity.stream().filter(e -> !"".equals(e.getProjectId())).collect(Collectors.toList());
  1008. if (time.getHours() == 0) {
  1009. getSectionDataByEntity(entity, goldenUri(), DateUtil.offsetDay(rft, -1), time);
  1010. } else {
  1011. getSectionDataByEntity(entity, goldenUri(), rft, time);
  1012. }
  1013. Map<String, List<PointInfo>> stMap = entity.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  1014. for (StationInfoHour byHour : byHours) {
  1015. List<PointInfo> pis = stMap.get(byHour.getStationId());
  1016. double dl = 0, v = 0;
  1017. List<PointData> pds;
  1018. for (PointInfo pi : pis) {
  1019. pds = pi.getPointDatas();
  1020. if (pds.size() > 1) v = (pds.get(1).getValue() - pds.get(0).getValue()) * pi.getCoef();
  1021. dl += (v < 0 || v > 30000000) ? 0 : v;
  1022. }
  1023. byHour.setRfdl(dl);
  1024. PointInfo info = statMapCx.get(byHour.getStationId());
  1025. double v1 = info.getPointDatas().get(0).getValue();
  1026. byHour.setPjgl(v1 <= 0 ? 0 : v1 * info.getCoef());
  1027. }
  1028. stationInfoHourService.saveOrUpdateBatch(byHours);
  1029. }
  1030. public void calcStationMinRfdl(Date hour) {
  1031. //hour整分钟
  1032. DateTime time = DateUtil.beginOfMinute(hour);
  1033. //当天零点
  1034. DateTime rft = DateUtil.beginOfDay(time);
  1035. List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
  1036. entity = entity.stream().filter(e -> !"".equals(e.getProjectId())).collect(Collectors.toList());
  1037. List<StationInfoMin> byHours = getStationinfoByMin(time, entity);
  1038. getSectionDataByEntity(entity, goldenUri(), rft, time);
  1039. Map<String, List<PointInfo>> stMap = entity.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  1040. for (StationInfoMin byHour : byHours) {
  1041. List<PointInfo> pis = stMap.get(byHour.getStationId());
  1042. double dl = 0, v = 0;
  1043. List<PointData> pds;
  1044. for (PointInfo pi : pis) {
  1045. pds = pi.getPointDatas();
  1046. if (pds.size() > 1) v = (pds.get(1).getValue() - pds.get(0).getValue()) * pi.getCoef();
  1047. dl += (v < 0 || v > 30000000) ? 0 : v;
  1048. }
  1049. byHour.setRfdl(dl);
  1050. }
  1051. stationInfoMinService.saveOrUpdateBatch(byHours);
  1052. }
  1053. public void calcStationHourPJGL(Date hour) {
  1054. hour = DateUtil.beginOfHour(hour);
  1055. DateTime start = DateUtil.offsetHour(hour, -1);
  1056. //出线
  1057. List<PointInfo> entityCx = getEntity("AGC001", "booster");
  1058. Map<String, PointInfo> statMapCx = getStatDataByEntity(entityCx, goldenUri(), start, hour, PointInfo::getStationId);
  1059. List<StationInfoHour> byHours = getStationinfoByHour(hour, entityCx);
  1060. for (StationInfoHour byHour : byHours) {
  1061. PointInfo info = statMapCx.get(byHour.getStationId());
  1062. double v = info.getPointDatas().get(0).getValue();
  1063. if (v < 0) {
  1064. v = 0;
  1065. } else {
  1066. v = v * info.getCoef();
  1067. }
  1068. byHour.setPjgl(v);
  1069. }
  1070. stationInfoHourService.saveOrUpdateBatch(byHours);
  1071. }
  1072. public void calcStationRfdlFj(Date date) {
  1073. //date当天零点
  1074. DateTime time = DateUtil.beginOfDay(date);
  1075. //date昨天零点
  1076. DateTime time0 = DateUtil.offsetDay(time, -1);
  1077. QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
  1078. wrapper.select("sum(rfdl) rfdl,station_id").eq("record_date", time0).groupBy("station_id");
  1079. List<TurbineInfoDay> list = turbineInfoDayService.list(wrapper);
  1080. Map<String, TurbineInfoDay> dayMap = list.stream().collect(Collectors.toMap(TurbineInfoDay::getStationId, Function.identity()));
  1081. List<StationInfoDay> byDate = getStationinfoByDate(time0);
  1082. TurbineInfoDay tDay;
  1083. for (StationInfoDay day : byDate) {
  1084. tDay = dayMap.get(day.getStationId());
  1085. day.setRfdlFj(tDay.getRfdl());
  1086. }
  1087. stationInfoDayService.saveOrUpdateBatch(byDate);
  1088. }
  1089. public void calcTurbineRFDL(Date date) {
  1090. //date当天零点
  1091. DateTime time = DateUtil.beginOfDay(date);
  1092. //date昨天零点
  1093. DateTime time0 = DateUtil.offsetDay(time, -1);
  1094. List<PointInfo> entity = getEntity("AI121", "turbine");
  1095. getZeroNextData(entity, time0, time);
  1096. Map<String, PointInfo> turMap = entity.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  1097. Map<String, String> fsMap = getEntityMap("AI066", "turbine");
  1098. Map<String, TurbineInfoDay> byDate = getTurbineinfoMap(time0, entity);
  1099. TurbineInfoDay infoDay;
  1100. PointInfo rfdlPi;
  1101. String turbineId;
  1102. List<TurbineInfoDay> infoDays = new ArrayList<>();
  1103. DoubleStatData stat;
  1104. for (PointInfo info : entity) {
  1105. turbineId = info.getTurbineId();
  1106. infoDay = byDate.get(turbineId);
  1107. rfdlPi = turMap.get(turbineId);
  1108. double v = (rfdlPi.getPointDatas().get(1).getValue() - rfdlPi.getPointDatas().get(0).getValue()) * rfdlPi.getCoef();
  1109. if (v < 0 || v > 1000000) {
  1110. v = 0;
  1111. } else if (v > 30000) {
  1112. v = v / (v % 30000 + 3);
  1113. }
  1114. infoDay.setRfdl(v);
  1115. stat = adapter.getHistoryStat(goldenUri(), fsMap.get(turbineId), time0.getTime(), time.getTime());
  1116. if (stat == null) {
  1117. infoDay.setPjfs(0.0);
  1118. } else {
  1119. infoDay.setPjfs(stat.getAvg().getValue());
  1120. }
  1121. infoDays.add(infoDay);
  1122. }
  1123. turbineInfoDayService.saveOrUpdateBatch(infoDays);
  1124. }
  1125. /*public void calcTurbine5s(Date date) {
  1126. //date当天零点
  1127. DateTime time = DateUtil.beginOfDay(date);
  1128. //date昨天零点
  1129. DateTime time0 = DateUtil.offsetDay(time, -1);
  1130. //状态
  1131. List<PointInfo> entityZt = getEntity("MXZT", "turbine");
  1132. //功率
  1133. Map<String, String> collectGl = getEntityMap("AI114", "turbine");
  1134. //风速
  1135. Map<String, String> collectFs = getEntityMap("AI066", "turbine");
  1136. Map<String, TurbineInfoDay> dayMap = getTurbineinfoMap(time0, entityZt);
  1137. String tbId;
  1138. TurbineInfoDay infoDay;
  1139. List<TurbineInfoDay> infoDays = new ArrayList<>();
  1140. for (PointInfo info : entityZt) {
  1141. tbId = info.getTurbineId();
  1142. List<PointData> snapZt = adapter.getHistorySnap(taosUri(), info.getPointKey(), time0.getTime(), time.getTime(), 60);
  1143. //0 待机,1 手动停机,2 正常发电,3 发电降出力,4 故障,5 故障受累,6 检修,7 检修受累,8 限电降出力,
  1144. // 9 限电停机,10 电网受累,11 环境受累,12 通讯中断,13 设备离线
  1145. List<DoubleStatData> statGl = adapter.getHistoryStat2(goldenUri(), collectGl.get(tbId), time0.getTime(), time.getTime(), 60);
  1146. List<DoubleStatData> statFs = adapter.getHistoryStat2(goldenUri(), collectFs.get(tbId), time0.getTime(), time.getTime(), 60);
  1147. List<PointData> glList = statGl.stream().map(DoubleStatData::getAvg).collect(Collectors.toList());
  1148. List<PointData> fsList = statFs.stream().map(DoubleStatData::getAvg)
  1149. .peek(fs -> {
  1150. if (fs.getValue() < 25) {
  1151. fs.setDoubleValue(NumberUtil.round(fs.getValue(), 2).doubleValue());
  1152. } else {
  1153. fs.setDoubleValue(25.0);
  1154. }
  1155. }).collect(Collectors.toList());
  1156. // Map<String, Double> loss = getTurbinePowerLoss(snapZt, fsList, tbId, glList);
  1157. Map<String, Double> loss = new HashMap<>();
  1158. infoDay = dayMap.get(tbId);
  1159. infoDay.setJhjxss(loss.get("jxss") + loss.get("sdtj"));
  1160. infoDay.setFjhjxss(loss.get("gzss") + loss.get("djss") + loss.get("fdjcl"));
  1161. infoDay.setXdss(loss.get("xdjcl") + loss.get("xdtj"));
  1162. infoDay.setSlss(0.0);
  1163. if (infoDay.getRfdl() == 0) {
  1164. infoDay.setXnss(0.0);
  1165. } else {
  1166. infoDay.setXnss(loss.get("xnss") * 0.1);
  1167. }
  1168. infoDay.setLlfdl(infoDay.getRfdl() + infoDay.getJhjxss() + infoDay.getFjhjxss() +
  1169. infoDay.getXdss() + infoDay.getSlss() + infoDay.getXnss());
  1170. infoDays.add(infoDay);
  1171. }
  1172. turbineInfoDayService.saveOrUpdateBatch(infoDays);
  1173. }*/
  1174. //此处加公式
  1175. public void calcStationSspjfs() {
  1176. List<PointInfo> fsEntity = getEntity("AI066", "turbine");
  1177. String keys = pointInfos2Keys(fsEntity);
  1178. Map<String, PointData> latest = adapter.getLatest(goldenUri(), keys);
  1179. Map<String, List<String>> listMap = fsEntity.stream().collect(Collectors.groupingBy(PointInfo::getStationId, Collectors.mapping(PointInfo::getPointKey, Collectors.toList())));
  1180. Map<String, String> entityMap = getEntityMap("SSPJFS", "station");
  1181. List<PointData> tsData = new ArrayList<>();
  1182. listMap.forEach((stId, keyList) -> {
  1183. double v = keyList.stream().mapToDouble(key -> latest.get(key).getValue()).average().orElse(0.0);
  1184. PointData data = new PointData();
  1185. data.setTs(System.currentTimeMillis());
  1186. data.setTagName(entityMap.get(stId));
  1187. data.setDoubleValue(v);
  1188. tsData.add(data);
  1189. });
  1190. adapter.writeHistoryBatch(taosUri(), tsData);
  1191. }
  1192. public void calcTurbine5s2(Date date) {
  1193. //date当天零点
  1194. DateTime time = DateUtil.beginOfDay(date);
  1195. //date昨天零点
  1196. DateTime time0 = DateUtil.offsetDay(time, -1);
  1197. //风速
  1198. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  1199. //功率
  1200. List<PointInfo> entityGl = getEntity("AI114", "turbine");
  1201. getSnapDataByEntity(entityFs, time0, time, 15);
  1202. getSnapDataByEntity(entityGl, time0, time, 15);
  1203. List<PointInfo> ztMapMap = calcTurbineZt(time0, time, entityFs, entityGl);
  1204. Map<String, Map<String, PointInfo>> ztMapMapInfos = ztMapMap.stream().collect(
  1205. Collectors.groupingBy(PointInfo::getStationId, Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
  1206. Map<String, TurbineInfoDay> dayMap = getTurbineinfoMap(time0, entityFs);
  1207. List<TurbineInfoDay> infoDays = new ArrayList<>();
  1208. Map<String, Map<String, List<PointData>>> fsMapMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
  1209. Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas)));
  1210. Map<String, Map<String, List<PointData>>> glMapMap = entityGl.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
  1211. Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas)));
  1212. ztMapMapInfos.forEach((stId, ztMapInfo) -> ztMapInfo.forEach((wtId, ztInfo) -> {
  1213. //0 待机,1 手动停机,2 正常发电,3 发电降出力,4 故障,5 故障受累,6 检修,7 检修受累,8 限电降出力,
  1214. // 9 限电停机,10 电网受累,11 环境受累,12 通讯中断,13 设备离线
  1215. TurbineInfoDay infoDay = dayMap.get(wtId);
  1216. Map<String, Double> loss = getTurbinePowerLoss(infoDay.getRfdl(), ztMapMapInfos.get(stId).get(wtId), fsMapMap.get(stId).get(wtId), glMapMap.get(stId).get(wtId));
  1217. infoDay.setJhjxss(loss.get("jxss") + loss.get("sdtj"));
  1218. infoDay.setFjhjxss(loss.get("gzss") + loss.get("djss") + loss.get("fdjcl"));
  1219. infoDay.setXdss(loss.get("xdjcl") + loss.get("xdtj"));
  1220. infoDay.setSlss(0.0);
  1221. infoDay.setDjss(loss.get("djss"));
  1222. infoDay.setGzss(loss.get("gzss"));
  1223. if (infoDay.getRfdl() == 0) {
  1224. infoDay.setXnss(0.0);
  1225. } else {
  1226. infoDay.setXnss(loss.get("xnss"));
  1227. }
  1228. infoDay.setLlfdl(infoDay.getRfdl() + infoDay.getJhjxss() + infoDay.getFjhjxss() +
  1229. infoDay.getXdss() + infoDay.getSlss() + infoDay.getXnss());
  1230. infoDays.add(infoDay);
  1231. }));
  1232. turbineInfoDayService.saveOrUpdateBatch(infoDays);
  1233. }
  1234. public List<PointInfo> calcTurbineZt(Date start, Date end, List<PointInfo> fsInfos, List<PointInfo> glInfos) {
  1235. List<PointInfo> turbineZt = calcTurbineDizt(start, end, 15);
  1236. List<PointInfo> turbineAizt = calcTurbineAizt(start, end, 15);
  1237. turbineZt.addAll(turbineAizt);
  1238. Map<String, Map<String, PointInfo>> ztMapMap = turbineZt.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
  1239. Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
  1240. //AGC
  1241. List<PointInfo> entityAgc = getEntity("AGC002", "booster");
  1242. getSnapDataByEntity(entityAgc, start, end, 15);
  1243. //出线
  1244. List<PointInfo> entityCx = getEntity("AGC001", "booster");
  1245. getSnapDataByEntity(entityCx, start, end, 15);
  1246. //叶轮转速给定
  1247. List<PointInfo> entityYlzsgd = getEntity("AI110", "turbine");
  1248. getSnapDataByEntity(entityYlzsgd, start, end, 15);
  1249. Map<String, PointInfo> collectAgc = entityAgc.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  1250. Map<String, PointInfo> collectCx = entityCx.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  1251. Map<String, Map<String, List<PointData>>> collectYlzsgd = entityYlzsgd.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
  1252. Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas)));
  1253. Map<String, Map<String, PointInfo>> fsMapMap = fsInfos.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
  1254. Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
  1255. Map<String, Map<String, List<PointData>>> glMapMap = glInfos.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
  1256. Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas)));
  1257. ztMapMap.forEach((stId, ztMap) -> {
  1258. PointInfo agcInfo = collectAgc.get(stId);
  1259. PointInfo cxInfo = collectCx.get(stId);
  1260. Map<String, PointInfo> fsMap = fsMapMap.get(stId);
  1261. Map<String, List<PointData>> pdsZsglMap = new HashMap<>();
  1262. ztMap.forEach((wtId, zt) -> {
  1263. List<PointData> peek = fsMap.get(wtId).getPointDatas().stream().peek(pd -> pd.setDoubleValue(NumberUtil.round(pd.getValue() > 25 ? 25.0
  1264. : pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
  1265. fsMap.get(wtId).setPointDatas(peek);
  1266. List<PointData> zsglSnap = fsMap.get(wtId).getPointDatas().stream().map(pd -> {
  1267. Double v = CalcCache.fitcoef.get(wtId).get(pd.getValue());
  1268. return new PointData(pd.getTs(), v == null ? 0 : v);
  1269. }).collect(Collectors.toList());
  1270. pdsZsglMap.put(wtId, zsglSnap);
  1271. });
  1272. List<PointData> agcc = agcInfo.getPointDatas().stream().peek(agc -> {
  1273. agc.setDoubleValue(agc.getValue() * agcInfo.getCoef());
  1274. agc.setLongValue(0L);
  1275. }).collect(Collectors.toList());
  1276. agcInfo.setPointDatas(agcc);
  1277. List<PointData> cxc = cxInfo.getPointDatas().stream().peek(cx -> {
  1278. cx.setDoubleValue(cx.getValue() * cxInfo.getCoef());
  1279. cx.setLongValue(0L);
  1280. }).collect(Collectors.toList());
  1281. cxInfo.setPointDatas(cxc);
  1282. //风机风速、功率->场站风速、功率
  1283. // List<PointData> firstFs = new ArrayList<>();
  1284. // List<PointData> firstGl = new ArrayList<>();
  1285. List<PointData> firstZsgl = new ArrayList<>();
  1286. double v1, v2, v3;
  1287. for (int i = 0; i < agcInfo.getPointDatas().size(); i++) {
  1288. int finalI = i;
  1289. long ts = start.getTime() + i * 15000L;
  1290. // v1 = fsMap.values().stream().mapToDouble(pds -> pds.getPointDatas().get(finalI).getValue()).average().orElse(0.0);
  1291. // v2 = glMap.values().stream().mapToDouble(pds -> pds.getPointDatas().get(finalI).getValue()).sum();
  1292. v3 = pdsZsglMap.values().stream().mapToDouble(pds -> pds.get(finalI).getValue()).sum();
  1293. // firstFs.add(new PointData(ts, v1));
  1294. // firstGl.add(new PointData(ts, v2));
  1295. firstZsgl.add(new PointData(ts, v3));
  1296. }
  1297. List<PointData> czxd = calcStationXd2(agcInfo, cxInfo.getPointDatas(), firstZsgl);
  1298. String ybj = "GJNY_SXGS_XZ_F_WT_0013_EQ,GJNY_SXGS_XZ_F_WT_0023_EQ,GJNY_SXGS_XZ_F_WT_0027_EQ,GJNY_SXGS_XZ_F_WT_0034_EQ,GJNY_SXGS_XZ_F_WT_0044_EQ,GJNY_SXGS_XZ_F_WT_0060_EQ,GJNY_SXGS_XZ_F_WT_0062_EQ,GJNY_SXGS_FSG_F_WT_0005_EQ,GJNY_SXGS_FSG_F_WT_0006_EQ,GJNY_SXGS_FSG_F_WT_0038_EQ,GJNY_SXGS_FSG_F_WT_0039_EQ,GJNY_SXGS_ZZ_F_WT_0008_EQ,GJNY_SXGS_ZZ_F_WT_0015_EQ,GJNY_SXGS_ZZ_F_WT_0022_EQ,GJNY_SXGS_ZZ_F_WT_0046_EQ,GJNY_SXGS_ZZ_F_WT_0049_EQ,GJNY_SXGS_CSL_F_WT_0003_EQ,GJNY_SXGS_CSL_F_WT_0012_EQ,GJNY_SXGS_CSL_F_WT_0023_EQ,GJNY_SXGS_JSL_F_WT_0002_EQ,GJNY_SXGS_JSL_F_WT_0003_EQ,GJNY_SXGS_JSL_F_WT_0028_EQ,GJNY_SXGS_JSL_F_WT_0047_EQ,GJNY_SXGS_JSL_F_WT_0070_EQ,GJNY_SXGS_JSL_F_WT_0094_EQ,GJNY_SXGS_LJS_F_WT_0002_EQ,GJNY_SXGS_LJS_F_WT_0011_EQ,GJNY_SXGS_LJS_F_WT_0030_EQ,GJNY_SXGS_LJS_F_WT_0033_EQ";
  1299. ztMap.forEach((wtId, ztInfo) -> {
  1300. if (ybj.contains(wtId)) return;
  1301. List<PointData> fss = fsMap.get(wtId).getPointDatas();
  1302. List<PointData> gls = glMapMap.get(stId).get(wtId);
  1303. //叶轮转速给定
  1304. List<PointData> ylzsgds = collectYlzsgd.get(stId).get(wtId);
  1305. calcTurbineXd(ztInfo, gls, fss, ylzsgds, czxd);
  1306. });
  1307. });
  1308. return turbineZt;
  1309. }
  1310. public List<PointData> calcTurbineSimpleZt(Date start, Date end, Integer interval, String tbId) {
  1311. List<PointInfo> turbineZt = calcTurbineDizt(start, end, interval, tbId);
  1312. List<PointInfo> turbineAizt = calcTurbineAizt(start, end, interval, tbId);
  1313. turbineZt.addAll(turbineAizt);
  1314. Map<String, List<PointData>> collect = turbineZt.stream().collect(Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas));
  1315. return collect.get(tbId);//.stream().map(PointData::getValue).collect(Collectors.toList());
  1316. }
  1317. public void calcTurbineXd(PointInfo ztInfo, List<PointData> gls, List<PointData> fss, List<PointData> ylzsgds, List<PointData> czxd) {
  1318. Map<String, EquipmentModel> map = equipmentModelService.map();
  1319. Double capacity = map.get(ztInfo.getSpare()).getPowerProduction();
  1320. List<PointData> zts = ztInfo.getPointDatas();
  1321. for (int i = 0; i < fss.size(); i++) {
  1322. double ssgl = gls.get(i).getValue();
  1323. double ssfs = fss.get(i).getValue();
  1324. double ylzsgd = ylzsgds.get(i).getValue();
  1325. if (czxd.get(i).isBooleanValue() && ssgl < capacity * 0.9) {
  1326. if (ssfs >= 12) {
  1327. zts.get(i).setDoubleValue(8.0);
  1328. }
  1329. if (ylzsgd != 0 && ylzsgd < 17.3) {//降出力
  1330. zts.get(i).setDoubleValue(8.0);
  1331. }
  1332. }
  1333. }
  1334. }
  1335. //此处加公式
  1336. public List<PointData> calcStationXd2(PointInfo agcInfo, List<PointData> cxSnap, List<PointData> zsglSnap) {
  1337. String stId = agcInfo.getStationId();
  1338. List<PointData> agcSnap = agcInfo.getPointDatas();
  1339. List<PointData> zsgl5s = get5Avg(zsglSnap);
  1340. List<PointData> agc5s = get5Avg(agcSnap);
  1341. List<PointData> cx5s = get5Avg(cxSnap);
  1342. //场站限电
  1343. List<PointData> czxd = zsglSnap.stream().map(s -> new PointData(s.getTs(), 0.0)).collect(Collectors.toList());
  1344. //之前是否限电
  1345. boolean iszqxd = false;
  1346. for (int i = 0; i < zsglSnap.size(); i++) {
  1347. boolean isxd = false;
  1348. double zsgl = zsglSnap.get(i).getValue();
  1349. double zsgl5 = zsgl5s.get(i).getValue();
  1350. double agc = agcSnap.get(i).getValue();
  1351. double agc5 = agc5s.get(i).getValue();
  1352. double cxgl = cxSnap.get(i).getValue();
  1353. double cxgl5 = cx5s.get(i).getValue();
  1354. boolean k; //agc一直不变
  1355. //第一次初始化复制实时数据到缓存
  1356. if (CalcCache.powerCache.get(stId) == null || CalcCache.powerCache.get(stId) != agc) {
  1357. CalcCache.powerCache.put(stId, agc);
  1358. k = false;
  1359. } else {
  1360. k = true;
  1361. }
  1362. if (agc != 0) {
  1363. //如果场站限电状态为不限电
  1364. if (zsgl5 >= agcInfo.getSpare2() * 40) {
  1365. if (agc5 <= cxgl5) {
  1366. isxd = true;
  1367. } else if (iszqxd) {
  1368. if (zsgl / agc > 1.15) {
  1369. isxd = true;
  1370. } else if (zsgl > agc && agc5 - cxgl5 < 400) {
  1371. isxd = true;
  1372. }
  1373. } else if (zsgl / agc >= 1.2 && agc - cxgl <= 200) {
  1374. isxd = true;
  1375. }
  1376. } else if (k) {
  1377. if (zsgl / agc >= 1.1 && agc5 - cxgl5 <= 200) {
  1378. isxd = true;
  1379. }
  1380. }
  1381. }
  1382. czxd.get(i).setBooleanValue(isxd);
  1383. iszqxd = isxd;
  1384. }
  1385. return czxd;
  1386. }
  1387. private List<PointData> get5Avg(List<PointData> pointData) {
  1388. List<PointData> result = new ArrayList<>();
  1389. for (int i = 0; i < pointData.size(); i++) {
  1390. PointData data = new PointData();
  1391. data.setTs(pointData.get(i).getTs());
  1392. double v;
  1393. if (i > 4) {
  1394. 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;
  1395. } else {
  1396. v = pointData.get(i).getValue();
  1397. }
  1398. data.setDoubleValue(v);
  1399. result.add(data);
  1400. }
  1401. return result;
  1402. }
  1403. public List<PointInfo> calcTurbineAizt(Date start, Date end, int interval) {
  1404. List<PointInfo> entityAiZt = getEntity("AI422", "state");
  1405. List<StateAi> list = stateAiService.list();
  1406. Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
  1407. getSnapDataByEntity(entityAiZt, start, end, interval);
  1408. for (PointInfo info : entityAiZt) {
  1409. List<PointData> peek = info.getPointDatas().stream().peek(pd -> {
  1410. Integer m = collectAi.get(info.getSpare()).get((int) pd.getValue());
  1411. if (m == null) m = 2;
  1412. pd.setDoubleValue(m);
  1413. }).collect(Collectors.toList());
  1414. info.setPointDatas(peek);
  1415. }
  1416. return entityAiZt;
  1417. }
  1418. public List<PointInfo> calcTurbineAizt(Date start, Date end, int interval, String tbId) {
  1419. List<PointInfo> entityAiZt = getEntity("AI422", "state");
  1420. entityAiZt = entityAiZt.stream().filter(e -> tbId.equals(e.getTurbineId())).collect(Collectors.toList());
  1421. List<StateAi> list = stateAiService.list();
  1422. Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
  1423. getSnapDataByEntity(entityAiZt, start, end, interval);
  1424. for (PointInfo info : entityAiZt) {
  1425. List<PointData> peek = info.getPointDatas().stream().peek(pd -> {
  1426. Integer m = collectAi.get(info.getSpare()).get((int) pd.getValue());
  1427. if (m == null) m = 2;
  1428. pd.setDoubleValue(m);
  1429. }).collect(Collectors.toList());
  1430. info.setPointDatas(peek);
  1431. }
  1432. return entityAiZt;
  1433. }
  1434. public List<PointInfo> calcTurbineDizt(Date start, Date end, int interval) {
  1435. List<PointInfo> entity = new ArrayList<>();
  1436. List<PointInfo> entity0 = getEntity("MX000", "state");
  1437. List<PointInfo> entity1 = getEntity("MX001", "state");
  1438. List<PointInfo> entity2 = getEntity("MX002", "state");
  1439. List<PointInfo> entity4 = getEntity("MX004", "state");
  1440. List<PointInfo> entity6 = getEntity("MX006", "state");
  1441. entity.addAll(entity0);
  1442. entity.addAll(entity1);
  1443. entity.addAll(entity2);
  1444. entity.addAll(entity4);
  1445. entity.addAll(entity6);
  1446. List<String> keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.toList());
  1447. Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), String.join(",", keys), start.getTime());
  1448. Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
  1449. wtUcPis.forEach((wtId, map) -> {
  1450. map.forEach((uc, pi) -> {
  1451. List<PointData> raw = adapter.getHistoryRaw(goldenUri(), pi.getPointKey(), start.getTime(), end.getTime());
  1452. List<PointData> ds = boolPointDatasFull(latest.get(pi.getPointKey()).isBooleanValue(), raw, start.getTime(), end.getTime(), interval);
  1453. pi.setPointDatas(ds);
  1454. ThreadUtil.sleep(5);
  1455. });
  1456. List<PointData> mx000 = map.get("MX000").getPointDatas();
  1457. PointData data0;
  1458. for (int i = 0; i < mx000.size(); i++) {
  1459. data0 = mx000.get(i);
  1460. if (data0.getValue() == 1.0) {
  1461. data0.setDoubleValue(0.0);
  1462. data0.setBooleanValue(false);
  1463. } else if (map.get("MX001").getPointDatas().get(i).getValue() == 1.0) {
  1464. data0.setDoubleValue(1.0);
  1465. } else if (map.get("MX002").getPointDatas().get(i).getValue() == 1.0) {
  1466. data0.setDoubleValue(2.0);
  1467. } else if (map.get("MX004").getPointDatas().get(i).getValue() == 1.0) {
  1468. data0.setDoubleValue(4.0);
  1469. } else if (map.get("MX006").getPointDatas().get(i).getValue() == 1.0) {
  1470. data0.setDoubleValue(6.0);
  1471. } else {
  1472. // System.out.println(wtId + data0.getTs() + ":di无对应状态!");
  1473. data0.setDoubleValue(2.0);
  1474. }
  1475. }
  1476. map.get("MX001").setPointDatas(null);
  1477. map.get("MX002").setPointDatas(null);
  1478. map.get("MX004").setPointDatas(null);
  1479. map.get("MX006").setPointDatas(null);
  1480. });
  1481. return entity0;
  1482. }
  1483. public List<PointInfo> calcTurbineDizt(Date start, Date end, int interval, String tbId) {
  1484. List<PointInfo> entity = new ArrayList<>();
  1485. List<PointInfo> entity0 = getEntity("MX000", "state");
  1486. List<PointInfo> entity1 = getEntity("MX001", "state");
  1487. List<PointInfo> entity2 = getEntity("MX002", "state");
  1488. List<PointInfo> entity4 = getEntity("MX004", "state");
  1489. List<PointInfo> entity6 = getEntity("MX006", "state");
  1490. entity0 = entity0.stream().filter(e -> tbId.equals(e.getTurbineId())).collect(Collectors.toList());
  1491. entity1 = entity1.stream().filter(e -> tbId.equals(e.getTurbineId())).collect(Collectors.toList());
  1492. entity2 = entity2.stream().filter(e -> tbId.equals(e.getTurbineId())).collect(Collectors.toList());
  1493. entity4 = entity4.stream().filter(e -> tbId.equals(e.getTurbineId())).collect(Collectors.toList());
  1494. entity6 = entity6.stream().filter(e -> tbId.equals(e.getTurbineId())).collect(Collectors.toList());
  1495. entity.addAll(entity0);
  1496. entity.addAll(entity1);
  1497. entity.addAll(entity2);
  1498. entity.addAll(entity4);
  1499. entity.addAll(entity6);
  1500. List<String> keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.toList());
  1501. Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), String.join(",", keys), start.getTime());
  1502. Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
  1503. wtUcPis.forEach((wtId, map) -> {
  1504. map.forEach((uc, pi) -> {
  1505. List<PointData> raw = adapter.getHistoryRaw(goldenUri(), pi.getPointKey(), start.getTime(), end.getTime());
  1506. List<PointData> ds = boolPointDatasFull(latest.get(pi.getPointKey()).isBooleanValue(), raw, start.getTime(), end.getTime(), interval);
  1507. pi.setPointDatas(ds);
  1508. ThreadUtil.sleep(5);
  1509. });
  1510. List<PointData> mx000 = map.get("MX000").getPointDatas();
  1511. PointData data0;
  1512. for (int i = 0; i < mx000.size(); i++) {
  1513. data0 = mx000.get(i);
  1514. if (data0.getValue() == 1.0) {
  1515. data0.setDoubleValue(0.0);
  1516. data0.setBooleanValue(false);
  1517. } else if (map.get("MX001").getPointDatas().get(i).getValue() == 1.0) {
  1518. data0.setDoubleValue(1.0);
  1519. } else if (map.get("MX002").getPointDatas().get(i).getValue() == 1.0) {
  1520. data0.setDoubleValue(2.0);
  1521. } else if (map.get("MX004").getPointDatas().get(i).getValue() == 1.0) {
  1522. data0.setDoubleValue(4.0);
  1523. } else if (map.get("MX006").getPointDatas().get(i).getValue() == 1.0) {
  1524. data0.setDoubleValue(6.0);
  1525. } else {
  1526. // System.out.println(wtId + data0.getTs() + ":di无对应状态!");
  1527. data0.setDoubleValue(2.0);
  1528. }
  1529. }
  1530. map.get("MX001").setPointDatas(null);
  1531. map.get("MX002").setPointDatas(null);
  1532. map.get("MX004").setPointDatas(null);
  1533. map.get("MX006").setPointDatas(null);
  1534. });
  1535. return entity0;
  1536. }
  1537. public PointInfo calcTurbineAizt2(PointInfo entityAiZt, Map<String, Map<Integer, Integer>> collectAi, Date start, Date end, int interval) {
  1538. if (entityAiZt == null) return null;
  1539. getSnapDataByEntity(entityAiZt, start, end, interval);
  1540. Map<Integer, Integer> integerMap = collectAi.get(entityAiZt.getSpare());
  1541. List<PointData> data = entityAiZt.getPointDatas().stream().peek(pd -> {
  1542. Integer m = integerMap.get((int) pd.getValue());
  1543. if (m == null) m = 2;
  1544. pd.setDoubleValue(m);
  1545. }).collect(Collectors.toList());
  1546. entityAiZt.setPointDatas(data);
  1547. return entityAiZt;
  1548. }
  1549. public PointInfo calcTurbineDizt2(Map<String, PointInfo> wtucpi, Map<String, PointData> latest, Date start, Date end, int interval) {
  1550. if (wtucpi == null) return null;
  1551. wtucpi.forEach((uc, pi) -> {
  1552. List<PointData> raw = adapter.getHistoryRaw(goldenUri(), pi.getPointKey(), start.getTime(), end.getTime());
  1553. List<PointData> ds = boolPointDatasFull(latest.get(pi.getPointKey()).isBooleanValue(), raw, start.getTime(), end.getTime(), interval);
  1554. pi.setPointDatas(ds);
  1555. ThreadUtil.sleep(5);
  1556. });
  1557. PointInfo mx000 = wtucpi.get("MX000");
  1558. PointData data0;
  1559. for (int i = 0; i < mx000.getPointDatas().size(); i++) {
  1560. data0 = mx000.getPointDatas().get(i);
  1561. if (data0.getValue() == 1.0) {
  1562. data0.setDoubleValue(0.0);
  1563. data0.setBooleanValue(false);
  1564. } else if (wtucpi.get("MX001").getPointDatas().get(i).getValue() == 1.0) {
  1565. data0.setDoubleValue(1.0);
  1566. } else if (wtucpi.get("MX002").getPointDatas().get(i).getValue() == 1.0) {
  1567. data0.setDoubleValue(2.0);
  1568. } else if (wtucpi.get("MX004").getPointDatas().get(i).getValue() == 1.0) {
  1569. data0.setDoubleValue(4.0);
  1570. } else if (wtucpi.get("MX006").getPointDatas().get(i).getValue() == 1.0) {
  1571. data0.setDoubleValue(6.0);
  1572. } else {
  1573. System.out.println(mx000.getTurbineId() + data0.getTs() + ":di无对应状态!");
  1574. data0.setDoubleValue(2.0);
  1575. }
  1576. }
  1577. wtucpi.get("MX001").setPointDatas(null);
  1578. wtucpi.get("MX002").setPointDatas(null);
  1579. wtucpi.get("MX004").setPointDatas(null);
  1580. wtucpi.get("MX006").setPointDatas(null);
  1581. return mx000;
  1582. }
  1583. public List<PointData> boolPointDatasFull(boolean v, List<PointData> data, long startTime, long endTime, int interval) {
  1584. int j = 0, m = 0;
  1585. List<PointData> data2 = new ArrayList<>();
  1586. for (long i = startTime; i <= endTime; i += interval * 1000L) {
  1587. PointData dt = new PointData();
  1588. dt.setTs(i);
  1589. data2.add(dt);
  1590. //超出范围
  1591. if (j >= data.size() - 1) continue;
  1592. if (i < data.get(j).getTs()) {
  1593. if (m == 0) {
  1594. dt.setBooleanValue(v);
  1595. } else {
  1596. dt.setBooleanValue(data.get(j - 1).isBooleanValue());
  1597. }
  1598. } else {
  1599. dt.setBooleanValue(data.get(j).isBooleanValue());
  1600. j++;
  1601. m++;
  1602. }
  1603. }
  1604. return data2;
  1605. }
  1606. public List<PointData> doublePointDatasFull(double v, List<PointData> data, long startTime, long endTime, int interval) {
  1607. int j = 0, m = 0;
  1608. List<PointData> data2 = new ArrayList<>();
  1609. for (long i = startTime; i <= endTime; i += interval * 1000L) {
  1610. PointData dt = new PointData();
  1611. dt.setTs(i);
  1612. data2.add(dt);
  1613. //超出范围
  1614. if (j >= data.size() - 1) continue;
  1615. if (i < data.get(j).getTs()) {
  1616. if (m == 0) {
  1617. dt.setDoubleValue(v);
  1618. } else {
  1619. dt.setDoubleValue(data.get(j - 1).getValue());
  1620. }
  1621. } else {
  1622. dt.setDoubleValue(data.get(j).getValue());
  1623. j++;
  1624. m++;
  1625. }
  1626. }
  1627. return data2;
  1628. }
  1629. public void calcGlqxnh(Date start, Date end) {
  1630. //风速
  1631. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  1632. //功率
  1633. List<PointInfo> entityGl = getEntity("AI114", "turbine");
  1634. Map<String, PointInfo> glMap = entityGl.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  1635. Map<String, EquipmentModel> map = equipmentModelService.map();
  1636. List<PointInfo> entity = new ArrayList<>();
  1637. List<PointInfo> entity0 = getEntity("MX000", "state");
  1638. List<PointInfo> entity1 = getEntity("MX001", "state");
  1639. List<PointInfo> entity2 = getEntity("MX002", "state");
  1640. List<PointInfo> entity4 = getEntity("MX004", "state");
  1641. List<PointInfo> entity6 = getEntity("MX006", "state");
  1642. entity.addAll(entity0);
  1643. entity.addAll(entity1);
  1644. entity.addAll(entity2);
  1645. entity.addAll(entity4);
  1646. entity.addAll(entity6);
  1647. List<String> keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.toList());
  1648. Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), String.join(",", keys), start.getTime());
  1649. Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
  1650. List<PointInfo> entityAiZt = getEntity("AI422", "state");
  1651. Map<String, PointInfo> aiztMap = entityAiZt.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  1652. List<StateAi> list = stateAiService.list();
  1653. Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
  1654. // Map<String, Map<Double,Double>> fitMap = new HashMap<>();
  1655. // entityFs = entityFs.stream().filter(ef -> !CalcCache.keys.contains(ef.getTurbineId())).collect(Collectors.toList());
  1656. for (PointInfo ef : entityFs) {
  1657. String wtId = ef.getTurbineId();
  1658. PointInfo glInfo = glMap.get(wtId);
  1659. getSnapDataByEntity(ef, start, end, 60);
  1660. getSnapDataByEntity(glInfo, start, end, 60);
  1661. List<PointData> peek = ef.getPointDatas().stream().peek(pd -> pd.setDoubleValue(NumberUtil.round(pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
  1662. ef.setPointDatas(peek);
  1663. PointInfo turbineZt = calcTurbineDizt2(wtUcPis.get(wtId), latest, start, end, 60);
  1664. PointInfo turbineAizt = calcTurbineAizt2(aiztMap.get(wtId), collectAi, start, end, 60);
  1665. Map<Double, Double> fit = new TreeMap<>();
  1666. if (turbineZt != null) {
  1667. double capacity = map.get(turbineZt.getSpare()).getPowerProduction();
  1668. fit = dataProcessAndFit(ef, glInfo, turbineZt, CalcCache.bzgl.get(turbineZt.getSpare()), capacity);
  1669. // fitMap.put(wtId, fit);
  1670. turbineZt.setPointDatas(null);
  1671. }
  1672. if (turbineAizt != null) {
  1673. double capacity = map.get(turbineAizt.getSpare()).getPowerProduction();
  1674. fit = dataProcessAndFit(ef, glInfo, turbineAizt, CalcCache.bzgl.get(turbineAizt.getSpare()), capacity);
  1675. // fitMap.put(wtId, fit);
  1676. turbineAizt.setPointDatas(null);
  1677. }
  1678. ef.setPointDatas(null);
  1679. glInfo.setPointDatas(null);
  1680. String key = "glqxnh:" + (end.getMonth() + 1) + ":" + wtId;
  1681. stringRedisTemplate.opsForValue().set(key, JSON.toJSONString(fit));
  1682. CalcCache.fitcoef.put(key, new ConcurrentHashMap<>(fit));
  1683. }
  1684. System.out.println("苹果天涯");
  1685. // stringRedisTemplate.opsForValue().set("glqxnh", JSON.toJSONString(fitMap));
  1686. }
  1687. public void calcGlqxnhSurplus(Date start, Date end) {
  1688. //风速
  1689. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  1690. //功率
  1691. List<PointInfo> entityGl = getEntity("AI114", "turbine");
  1692. Map<String, PointInfo> glMap = entityGl.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  1693. Map<String, EquipmentModel> map = equipmentModelService.map();
  1694. List<PointInfo> entity = new ArrayList<>();
  1695. List<PointInfo> entity0 = getEntity("MX000", "state");
  1696. List<PointInfo> entity1 = getEntity("MX001", "state");
  1697. List<PointInfo> entity2 = getEntity("MX002", "state");
  1698. List<PointInfo> entity4 = getEntity("MX004", "state");
  1699. List<PointInfo> entity6 = getEntity("MX006", "state");
  1700. entity.addAll(entity0);
  1701. entity.addAll(entity1);
  1702. entity.addAll(entity2);
  1703. entity.addAll(entity4);
  1704. entity.addAll(entity6);
  1705. List<String> keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.toList());
  1706. Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), String.join(",", keys), start.getTime());
  1707. Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
  1708. List<PointInfo> entityAiZt = getEntity("AI422", "state");
  1709. Map<String, PointInfo> aiztMap = entityAiZt.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  1710. List<StateAi> list = stateAiService.list();
  1711. Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
  1712. // Map<String, Map<Double,Double>> fitMap = new HashMap<>();
  1713. entityFs = entityFs.stream().filter(ef -> !CalcCache.already.contains(ef.getTurbineId())).collect(Collectors.toList());
  1714. for (PointInfo ef : entityFs) {
  1715. String wtId = ef.getTurbineId();
  1716. PointInfo glInfo = glMap.get(wtId);
  1717. getSnapDataByEntity(ef, start, end, 60);
  1718. getSnapDataByEntity(glInfo, start, end, 60);
  1719. List<PointData> peek = ef.getPointDatas().stream().peek(pd -> pd.setDoubleValue(NumberUtil.round(pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
  1720. ef.setPointDatas(peek);
  1721. PointInfo turbineZt = calcTurbineDizt2(wtUcPis.get(wtId), latest, start, end, 60);
  1722. PointInfo turbineAizt = calcTurbineAizt2(aiztMap.get(wtId), collectAi, start, end, 60);
  1723. Map<Double, Double> fit = new TreeMap<>();
  1724. if (turbineZt != null) {
  1725. double capacity = map.get(turbineZt.getSpare()).getPowerProduction();
  1726. fit = dataProcessAndFit(ef, glInfo, turbineZt, CalcCache.bzgl.get(turbineZt.getSpare()), capacity);
  1727. // fitMap.put(wtId, fit);
  1728. turbineZt.setPointDatas(null);
  1729. }
  1730. if (turbineAizt != null) {
  1731. double capacity = map.get(turbineAizt.getSpare()).getPowerProduction();
  1732. fit = dataProcessAndFit(ef, glInfo, turbineAizt, CalcCache.bzgl.get(turbineAizt.getSpare()), capacity);
  1733. // fitMap.put(wtId, fit);
  1734. turbineAizt.setPointDatas(null);
  1735. }
  1736. ef.setPointDatas(null);
  1737. glInfo.setPointDatas(null);
  1738. String key = "glqxnh:" + (end.getMonth() + 1) + ":" + wtId;
  1739. stringRedisTemplate.opsForValue().set(key, JSON.toJSONString(fit));
  1740. CalcCache.fitcoef.put(key, new ConcurrentHashMap<>(fit));
  1741. }
  1742. System.out.println("苹果天涯");
  1743. // stringRedisTemplate.opsForValue().set("glqxnh", JSON.toJSONString(fitMap));
  1744. }
  1745. public Map<Double, Double> dataProcessAndFit(PointInfo fsPI, PointInfo glPI, PointInfo ztPI, Map<Double, Double> modelPowerMap, double capacity) {
  1746. System.out.println("开始拟合");
  1747. List<PointData> fsPds = fsPI.getPointDatas();
  1748. List<PointData> glPds = glPI.getPointDatas();
  1749. List<PointData> ztPds = ztPI.getPointDatas();
  1750. WeightedObservedPoints points = new WeightedObservedPoints();
  1751. if (ztPds.size() - glPds.size() == 1) ztPds.remove(glPds.size());
  1752. //数据过滤 0正常,1过滤掉
  1753. if (fsPds.size() != glPds.size() || glPds.size() != ztPds.size()) return new HashMap<>();
  1754. Double bzv;
  1755. for (int i = 0; i < ztPds.size(); i++) {
  1756. double fs = fsPds.get(i).getValue();
  1757. double gl = glPds.get(i).getValue();
  1758. // 过滤非并网值 风机状态不等于2
  1759. if (ztPds.get(i).getValue() != 2.0) {
  1760. //
  1761. } else if (fs < 0 || fs > 25 || gl < 0 || gl > capacity * 1.05) {// 按给定风速功率过滤
  1762. //
  1763. } else {
  1764. bzv = modelPowerMap.get(fs);
  1765. if (bzv == null || bzv == 0.0) {
  1766. points.add(fs, gl);
  1767. continue;
  1768. }
  1769. double k = gl / bzv; //功率曲线偏差: 保证功率/实际功率 k:偏差百分比
  1770. if (k < 0.61 || k > 1.25) {
  1771. //
  1772. } else {
  1773. points.add(fs, gl);
  1774. }
  1775. }
  1776. }
  1777. Map<Double, Double> glyc = new TreeMap<>();
  1778. PolynomialCurveFitter fitter = PolynomialCurveFitter.create(4);
  1779. try {
  1780. double[] result = fitter.fit(points.toList());
  1781. double min = calcMin(result);
  1782. System.out.println(ztPI.getTurbineId());
  1783. System.out.println(ztPI.getSpare());
  1784. System.out.println(min);
  1785. double[] max = calcMax(result);
  1786. if (min == 0 || max[0] == 0 || max[1] == 0) {
  1787. System.out.println();
  1788. }
  1789. System.out.println(max[0] + "," + max[1]);
  1790. double ru;
  1791. for (double i = 0; i < 25; i += 0.01) {
  1792. i = NumberUtil.round(i, 2).doubleValue();
  1793. if (i < 3) {
  1794. ru = 0.0;
  1795. } else if (i < min) {
  1796. ru = modelPowerMap.get(i);
  1797. } else if (i < max[0]) {
  1798. ru = calcPoly(i, result);
  1799. } else {
  1800. ru = max[1];
  1801. }
  1802. glyc.put(i, NumberUtil.round(ru, 2).doubleValue());
  1803. }
  1804. } catch (Exception e) {
  1805. System.out.println(ztPI.getTurbineId());
  1806. System.out.println(ztPI.getSpare());
  1807. System.out.println(e.getMessage());
  1808. }
  1809. System.out.println("拟合完成" + glyc);
  1810. return glyc;
  1811. }
  1812. public double calcMin(double[] coef) {
  1813. double minX = 0, minY = 9000;
  1814. for (double x = 0; x < 8; x += 0.01) {
  1815. double y = calcPoly(x, coef);
  1816. if (y < minY) {
  1817. minY = y;
  1818. minX = x;
  1819. }
  1820. }
  1821. return minX;
  1822. }
  1823. public double[] calcMax(double[] coef) {
  1824. double[] a = new double[2];
  1825. for (double x = 8; x < 16; x += 0.01) {
  1826. double y = calcPoly(x, coef);
  1827. if (y > a[1]) {
  1828. a[0] = x;
  1829. a[1] = y;
  1830. }
  1831. }
  1832. return a;
  1833. }
  1834. public void printResult(double[] r, double accuracy) {
  1835. for (double index = 0; index < 25; index += accuracy) {
  1836. System.out.println("[" + index + "," + calcPoly(index, r) + "],");
  1837. }
  1838. }
  1839. public void getSectionDataByEntity(List<PointInfo> entitys, URI uri, Date start, Date end) {
  1840. String collect = entitys.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
  1841. Map<String, PointData> section0 = adapter.getHistorySection(uri, collect, start.getTime());
  1842. Map<String, PointData> section1 = adapter.getHistorySection(uri, collect, end.getTime());
  1843. for (PointInfo entity : entitys) {
  1844. entity.setPointDatas(new ArrayList<>());
  1845. entity.getPointDatas().add(section0.get(entity.getPointKey()));
  1846. entity.getPointDatas().add(section1.get(entity.getPointKey()));
  1847. }
  1848. }
  1849. public void getSnapDataByEntity(List<PointInfo> entity, URI uri, Date start, Date end, int interval) {
  1850. for (PointInfo info : entity) {
  1851. getSnapDataByEntity(info, uri, start, end, interval);
  1852. ThreadUtil.sleep(5);
  1853. }
  1854. }
  1855. public void getSnapDataByEntity(PointInfo entity, URI uri, Date start, Date end, int interval) {
  1856. List<PointData> snap = adapter.getHistorySnap(uri, entity.getPointKey(), start.getTime(), end.getTime(), interval);
  1857. entity.setPointDatas(snap);
  1858. }
  1859. public void getSnapDataByEntity(List<PointInfo> entity, Date start, Date end, int interval) {
  1860. getSnapDataByEntity(entity, goldenUri(), start, end, interval);
  1861. }
  1862. public void getSnapDataByEntity(PointInfo entity, Date start, Date end, int interval) {
  1863. getSnapDataByEntity(entity, goldenUri(), start, end, interval);
  1864. }
  1865. public double calcPoly(String wtId, double value) {
  1866. return CalcCache.fitcoef.get(wtId).get(value);
  1867. }
  1868. public double calcPoly(double x, double[] factor) {
  1869. double y = 0;
  1870. for (int deg = 0; deg < factor.length; deg++) {
  1871. y += Math.pow(x, deg) * factor[deg];
  1872. }
  1873. return y;
  1874. }
  1875. //切入切出风速
  1876. public void cutInWindSpeed() {
  1877. //date当天零点
  1878. DateTime timeNow00 = DateUtil.beginOfDay(new Date());
  1879. //date昨天零点
  1880. DateTime timeBegin00 = DateUtil.offsetDay(timeNow00, -1);
  1881. //上个月
  1882. DateTime timeBegin2 = DateUtil.offsetMonth(timeBegin00, -1);
  1883. //上个月第一天
  1884. DateTime timeBegin1 = DateUtil.beginOfMonth(timeBegin2);
  1885. //上个月最后一天
  1886. DateTime timeEnd2 = DateUtil.endOfMonth(timeBegin2);
  1887. //上个月天数
  1888. int days = (int) DateUtil.betweenDay(timeBegin1, timeEnd2, false);
  1889. //遍历天数
  1890. for (int i = 1; i <= days; i++) {
  1891. DateTime timeNow = DateUtil.offsetDay(timeBegin1, i);
  1892. DateTime timeBegin = DateUtil.offsetDay(timeBegin1, i - 1);
  1893. List<PointInfo> turbineZt = calcTurbineAizt(timeBegin, timeNow, 60);
  1894. List<PointInfo> turbineZtDI = calcTurbineDizt(timeBegin, timeNow, 60);
  1895. turbineZt.addAll(turbineZtDI);
  1896. //所有风机的风速测点
  1897. QueryWrapper<PointInfo> queryWrapper = new QueryWrapper<>();
  1898. queryWrapper.eq("uniform_code", "AI066");
  1899. List<PointInfo> pointInfos = getEntity("AI066", "turbine");
  1900. // List<PointInfo> pointInfos = pointInfo.selectList(queryWrapper);
  1901. //定义切入风速map集合
  1902. ConcurrentHashMap<String, ConcurrentHashMap<String, Double>> mapIn = new ConcurrentHashMap<>();
  1903. //定义切出风速集合
  1904. ConcurrentHashMap<String, ConcurrentHashMap<String, Double>> mapOut = new ConcurrentHashMap<>();
  1905. //插入集合
  1906. List<TurbineInfoDay> interest = new ArrayList<>();
  1907. //更新集合
  1908. List<TurbineInfoDay> update = new ArrayList<>();
  1909. //遍历每台风机,取出每台风机的pointDatas
  1910. for (PointInfo turbine : turbineZt) {
  1911. mapIn.put(turbine.getTurbineId(), new ConcurrentHashMap<>());
  1912. mapOut.put(turbine.getTurbineId(), new ConcurrentHashMap<>());
  1913. List<PointData> pointDatas = turbine.getPointDatas();
  1914. //风速测点key
  1915. String windSpeedKey = null;
  1916. //遍历pointInfos,找出pointData1的id和pointInfos中相等的,取出pointInfo的pointKey
  1917. for (PointInfo info : pointInfos) {
  1918. if (Objects.equals(turbine.getTurbineId(), info.getTurbineId())) {
  1919. windSpeedKey = info.getPointKey();
  1920. }
  1921. }
  1922. //遍历pointDatas,取出当前状态和后一个状态
  1923. for (int k = 1; k < pointDatas.size(); k++) {
  1924. PointData pointData1 = pointDatas.get(k - 1);
  1925. PointData pointData2 = pointDatas.get(k);
  1926. double value1 = pointData1.getValue();
  1927. double value2 = pointData2.getValue();
  1928. //切入时间
  1929. long ts1;
  1930. //切出时间
  1931. long ts2;
  1932. //如果1的值为0,2的值为2,则为切入状态
  1933. if (value1 == 0 && value2 == 2) {
  1934. ts1 = pointData2.getTs();
  1935. // String stringDate = DateUtil.date(ts1).toString("yyyy-MM-dd HH:mm:ss");
  1936. // System.out.println(turbine.getTurbineId() + "切入" + stringDate);
  1937. //切入时间前5分钟
  1938. long ts11 = ts1 - 300000;
  1939. //根据风速key,从适配器取切入前5分钟的所有风速
  1940. List<PointData> pointDatas1 = adapter.getHistorySnap(goldenUri(), windSpeedKey, ts11, ts1, 10);
  1941. //平均所有风速即为平均切入风速
  1942. double avgCutInWindSpeed = pointDatas1.stream().mapToDouble(PointData::getValue).average().orElse(0);
  1943. // System.out.println(turbine.getTurbineId() + "切入风速" + avgCutInWindSpeed);
  1944. //存入map集合,外层key为turbineId,内层key为ts1,value为平均切入风速
  1945. mapIn.get(turbine.getTurbineId()).put(String.valueOf(ts1), avgCutInWindSpeed);
  1946. }
  1947. //切出
  1948. if (value1 == 2 && value2 != 2) {
  1949. ts2 = pointData2.getTs();
  1950. String stringDate = DateUtil.date(ts2).toString("yyyy-MM-dd HH:mm:ss");
  1951. // System.out.println(turbine.getTurbineId() + "切出" + stringDate);
  1952. //切出时间前5分钟
  1953. long ts22 = ts2 - 300000;
  1954. List<PointData> pointDatas2 = adapter.getHistorySnap(goldenUri(), windSpeedKey, ts22, ts2, 10);
  1955. double avgCutOutWindSpeed = pointDatas2.stream().mapToDouble(PointData::getValue).average().orElse(0);
  1956. // System.out.println(turbine.getTurbineId() + "切出风速" + avgCutOutWindSpeed);
  1957. //存入map集合,外层key为turbineId,内层key为ts2,value为平均切出风速
  1958. mapOut.get(turbine.getTurbineId()).put(String.valueOf(ts2), avgCutOutWindSpeed);
  1959. }
  1960. }
  1961. //遍历map集合,取出每个风机的所有切入风速,算一个平均值
  1962. ConcurrentHashMap<String, Double> mapTurbineValues = mapIn.get(turbine.getTurbineId());
  1963. //平均切入风速
  1964. double avgCutInWindSpeed = 0;
  1965. if (mapTurbineValues != null) {
  1966. AtomicReference<Double> sum = new AtomicReference<>(0.0);
  1967. //遍历mapTurbineValues,V大于5的舍弃,剩余算平均值
  1968. for (String key : mapTurbineValues.keySet()) {
  1969. if (mapTurbineValues.get(key) > 5) {
  1970. mapTurbineValues.remove(key);
  1971. }
  1972. }
  1973. mapTurbineValues.forEach((k1, v) -> {
  1974. sum.updateAndGet(v1 -> v1 + v);
  1975. });
  1976. //如果值为空则置0
  1977. if (sum.get() == 0) {
  1978. avgCutInWindSpeed = 0;
  1979. } else {
  1980. avgCutInWindSpeed = sum.get() / mapTurbineValues.size();
  1981. }
  1982. System.out.println(turbine.getTurbineId() + "切入平均风速" + avgCutInWindSpeed + "时间" + timeBegin);
  1983. }
  1984. //遍历map集合,取出每个风机的所有切出风速,算一个平均值
  1985. ConcurrentHashMap<String, Double> mapTurbineValues2 = mapOut.get(turbine.getTurbineId());
  1986. double avgCutOutWindSpeed;
  1987. if (mapTurbineValues2 != null) {
  1988. AtomicReference<Double> sum = new AtomicReference<>(0.0);
  1989. for (String key : mapTurbineValues2.keySet()) {
  1990. if (mapTurbineValues2.get(key) > 5) {
  1991. mapTurbineValues2.remove(key);
  1992. }
  1993. }
  1994. mapTurbineValues2.forEach((k2, v) -> {
  1995. sum.updateAndGet(v1 -> v1 + v);
  1996. });
  1997. if (sum.get() == 0) {
  1998. avgCutOutWindSpeed = 0;
  1999. } else {
  2000. avgCutOutWindSpeed = sum.get() / mapTurbineValues2.size();
  2001. }
  2002. System.out.println(turbine.getTurbineId() + "切出平均风速" + avgCutOutWindSpeed + "时间" + timeBegin);
  2003. }
  2004. //存入数据库
  2005. String turbineId = turbine.getTurbineId();
  2006. Date jdkDate = timeBegin;
  2007. System.out.println(turbineId + " " + jdkDate);
  2008. QueryWrapper<TurbineInfoDay> turbineInfoDayQueryWrapper = new QueryWrapper<>();
  2009. turbineInfoDayQueryWrapper.eq("turbine_id", turbine.getTurbineId());
  2010. turbineInfoDayQueryWrapper.eq("record_date", timeBegin);
  2011. TurbineInfoDay one = turbineInfoDayService.getOne(turbineInfoDayQueryWrapper);
  2012. System.out.println(one);
  2013. if (one == null) {
  2014. TurbineInfoDay turbineInfoDay = new TurbineInfoDay();
  2015. turbineInfoDay.setTurbineId(turbine.getTurbineId());
  2016. turbineInfoDay.setRecordDate(timeBegin);
  2017. turbineInfoDay.setXfqrfs(avgCutInWindSpeed);
  2018. System.out.println(turbineInfoDay);
  2019. interest.add(turbineInfoDay);
  2020. // turbineInfoDayService.save(turbineInfoDay);
  2021. } else {
  2022. one.setXfqrfs(avgCutInWindSpeed);
  2023. System.out.println(one);
  2024. // turbineInfoDayService.updateById(one);
  2025. update.add(one);
  2026. }
  2027. }
  2028. // //批量插入
  2029. // turbineInfoDayService.saveBatch(interest);
  2030. // //批量更新
  2031. // turbineInfoDayService.updateBatchById(update);
  2032. // //批量插入或更新
  2033. turbineInfoDayService.saveOrUpdateBatch(interest);
  2034. turbineInfoDayService.saveOrUpdateBatch(update);
  2035. }
  2036. }
  2037. //算额定风速
  2038. public void calcGlqxnh_edfs() {
  2039. //date当天零点
  2040. DateTime timeNow00 = DateUtil.beginOfDay(new Date());
  2041. //date昨天零点
  2042. DateTime timeBegin00 = DateUtil.offsetDay(timeNow00, -1);
  2043. //上个月
  2044. DateTime timeBegin2 = DateUtil.offsetMonth(timeBegin00, -1);
  2045. //上个月第一天
  2046. DateTime timeBegin1 = DateUtil.beginOfMonth(timeBegin2);
  2047. //上个月最后一天
  2048. DateTime timeEnd2 = DateUtil.endOfMonth(timeBegin2);
  2049. //上个月天数
  2050. int days = (int) DateUtil.betweenDay(timeBegin1, timeEnd2, false);
  2051. //遍历天数
  2052. for (int i = 1; i <= days; i++) {
  2053. DateTime end = DateUtil.offsetDay(timeBegin1, i);
  2054. DateTime start = DateUtil.offsetDay(timeBegin1, i - 1);
  2055. //风速
  2056. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  2057. //功率
  2058. List<PointInfo> entityGl = getEntity("AI114", "turbine");
  2059. Map<String, PointInfo> glMap = entityGl.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  2060. Map<String, EquipmentModel> map = equipmentModelService.map();
  2061. List<PointInfo> entity = new ArrayList<>();
  2062. List<PointInfo> entity0 = getEntity("MX000", "state");
  2063. List<PointInfo> entity1 = getEntity("MX001", "state");
  2064. List<PointInfo> entity2 = getEntity("MX002", "state");
  2065. List<PointInfo> entity4 = getEntity("MX004", "state");
  2066. List<PointInfo> entity6 = getEntity("MX006", "state");
  2067. entity.addAll(entity0);
  2068. entity.addAll(entity1);
  2069. entity.addAll(entity2);
  2070. entity.addAll(entity4);
  2071. entity.addAll(entity6);
  2072. List<String> keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.toList());
  2073. Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), String.join(",", keys), start.getTime());
  2074. Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
  2075. List<PointInfo> entityAiZt = getEntity("AI422", "state");
  2076. Map<String, PointInfo> aiztMap = entityAiZt.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  2077. List<StateAi> list = stateAiService.list();
  2078. Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
  2079. // Map<String, Map<Double,Double>> fitMap = new HashMap<>();
  2080. //插入集合
  2081. List<TurbineInfoDay> interest = new ArrayList<>();
  2082. //更新集合
  2083. List<TurbineInfoDay> update = new ArrayList<>();
  2084. for (PointInfo ef : entityFs) {
  2085. String wtId = ef.getTurbineId();
  2086. PointInfo glInfo = glMap.get(wtId);
  2087. getSnapDataByEntity(ef, start, end, 60);
  2088. getSnapDataByEntity(glInfo, start, end, 60);
  2089. List<PointData> peek = ef.getPointDatas().stream().peek(pd -> pd.setDoubleValue(NumberUtil.round(pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
  2090. ef.setPointDatas(peek);
  2091. try {
  2092. PointInfo turbineZt = calcTurbineDizt2(wtUcPis.get(wtId), latest, start, end, 60);
  2093. PointInfo turbineAizt = calcTurbineAizt2(aiztMap.get(wtId), collectAi, start, end, 60);
  2094. Map<Double, Double> fit = new TreeMap<>();
  2095. double capacity = 2000;
  2096. if (turbineZt != null) {
  2097. System.out.println("数据处理拟合");
  2098. capacity = map.get(turbineZt.getSpare()).getPowerProduction();
  2099. fit = dataProcessAndFit(ef, glInfo, turbineZt, CalcCache.bzgl.get(turbineZt.getSpare()), capacity);
  2100. // fitMap.put(wtId, fit);
  2101. turbineZt.setPointDatas(null);
  2102. }
  2103. if (turbineAizt != null) {
  2104. System.out.println("数据处理拟合");
  2105. capacity = map.get(turbineAizt.getSpare()).getPowerProduction();
  2106. fit = dataProcessAndFit(ef, glInfo, turbineAizt, CalcCache.bzgl.get(turbineAizt.getSpare()), capacity);
  2107. // fitMap.put(wtId, fit);
  2108. turbineAizt.setPointDatas(null);
  2109. }
  2110. ef.setPointDatas(null);
  2111. glInfo.setPointDatas(null);
  2112. //存redis
  2113. // stringRedisTemplate.opsForValue().set("glqxnh:" + end.getMonth() + ":" + wtId, JSON.toJSONString(fit));
  2114. System.out.println("拟合曲线的大小" + fit.size() + ":" + wtId);
  2115. //符合条件的风速和
  2116. List<Double> listDouble = new ArrayList<>();
  2117. //遍历fit集合,取出值与capacity相等的key
  2118. if (!fit.isEmpty()) {
  2119. for (double key : fit.keySet()) {
  2120. Double v = fit.get(key);
  2121. //如果v-capacity的值小于10大于-10,则把key加入listDouble
  2122. if ((Math.abs(v - capacity) <= 10) && Math.abs(v - capacity) >= -10) {
  2123. listDouble.add(key);
  2124. }
  2125. }
  2126. }
  2127. //取出listDouble的值求平均值
  2128. double agValue = 0;
  2129. if (!listDouble.isEmpty()) {
  2130. for (Double aDouble : listDouble) {
  2131. agValue += aDouble;
  2132. }
  2133. agValue = agValue / listDouble.size();
  2134. }
  2135. System.out.println("wtId:" + wtId + "agValue平均额定风速:" + agValue);
  2136. //存入数据库
  2137. System.out.println(wtId + " " + start);
  2138. QueryWrapper<TurbineInfoDay> turbineInfoDayQueryWrapper = new QueryWrapper<>();
  2139. turbineInfoDayQueryWrapper.eq("turbine_id", wtId);
  2140. turbineInfoDayQueryWrapper.eq("record_date", start);
  2141. TurbineInfoDay one = turbineInfoDayService.getOne(turbineInfoDayQueryWrapper);
  2142. System.out.println(one);
  2143. if (one == null) {
  2144. TurbineInfoDay turbineInfoDay = new TurbineInfoDay();
  2145. turbineInfoDay.setTurbineId(wtId);
  2146. turbineInfoDay.setRecordDate(start);
  2147. turbineInfoDay.setEdfs(agValue);
  2148. System.out.println(turbineInfoDay);
  2149. // turbineInfoDayService.save(turbineInfoDay);
  2150. interest.add(turbineInfoDay);
  2151. } else {
  2152. one.setEdfs(agValue);
  2153. System.out.println(one);
  2154. // turbineInfoDayService.updateById(one);
  2155. update.add(one);
  2156. }
  2157. } catch (Exception e) {
  2158. System.out.println(wtId + " " + start);
  2159. }
  2160. }
  2161. // //批量插入
  2162. // turbineInfoDayService.saveBatch(interest);
  2163. // //批量更新
  2164. // turbineInfoDayService.updateBatchById(update);
  2165. // //批量插入或更新
  2166. turbineInfoDayService.saveOrUpdateBatch(interest);
  2167. turbineInfoDayService.saveOrUpdateBatch(update);
  2168. }
  2169. // stringRedisTemplate.opsForValue().set("glqxnh", JSON.toJSONString(fitMap));
  2170. }
  2171. //环境温度
  2172. public void ambientTemperature() {
  2173. //date当天零点
  2174. DateTime timeNow = DateUtil.beginOfDay(new Date());
  2175. //date昨天零点
  2176. DateTime timeBegin = DateUtil.offsetDay(timeNow, -1);
  2177. //所有风机的温度
  2178. QueryWrapper<PointInfo> queryWrapper = new QueryWrapper<>();
  2179. queryWrapper.eq("uniform_code", "AI072");
  2180. List<PointInfo> pointInfos = getEntity("AI072", "turbine");
  2181. //插入集合
  2182. List<TurbineInfoDay> interest = new ArrayList<>();
  2183. //更新集合
  2184. List<TurbineInfoDay> update = new ArrayList<>();
  2185. //遍历pointInfos
  2186. for (PointInfo turbine : pointInfos) {
  2187. List<PointData> pointDatas = adapter.getHistorySnap(goldenUri(), turbine.getPointKey(), timeBegin.getTime(), timeNow.getTime(), 10);
  2188. //遍历pointDatas,取出数据算平均值
  2189. double avgCutInWindSpeed = 0;
  2190. for (PointData pointData : pointDatas) {
  2191. avgCutInWindSpeed += pointData.getValue();
  2192. }
  2193. avgCutInWindSpeed /= pointDatas.size();
  2194. //存入数据库
  2195. String turbineId = turbine.getTurbineId();
  2196. Date jdkDate = timeBegin;
  2197. System.out.println(turbineId + " " + jdkDate);
  2198. QueryWrapper<TurbineInfoDay> turbineInfoDayQueryWrapper = new QueryWrapper<>();
  2199. turbineInfoDayQueryWrapper.eq("turbine_id", turbine.getTurbineId());
  2200. turbineInfoDayQueryWrapper.eq("record_date", timeBegin);
  2201. TurbineInfoDay one = turbineInfoDayService.getOne(turbineInfoDayQueryWrapper);
  2202. System.out.println(one);
  2203. if (one == null) {
  2204. TurbineInfoDay turbineInfoDay = new TurbineInfoDay();
  2205. turbineInfoDay.setTurbineId(turbine.getTurbineId());
  2206. turbineInfoDay.setRecordDate(timeBegin);
  2207. turbineInfoDay.setHjwd(avgCutInWindSpeed);
  2208. System.out.println(turbineInfoDay);
  2209. interest.add(turbineInfoDay);
  2210. // turbineInfoDayService.save(turbineInfoDay);
  2211. } else {
  2212. one.setHjwd(avgCutInWindSpeed);
  2213. System.out.println(one);
  2214. update.add(one);
  2215. // turbineInfoDayService.updateById(one);
  2216. }
  2217. }
  2218. // //批量插入
  2219. // turbineInfoDayService.saveBatch(interest);
  2220. // //批量更新
  2221. // turbineInfoDayService.updateBatchById(update);
  2222. // //批量插入或更新
  2223. turbineInfoDayService.saveOrUpdateBatch(interest);
  2224. turbineInfoDayService.saveOrUpdateBatch(update);
  2225. }
  2226. public void writeReportPool(Date date) {
  2227. //date当天零点
  2228. DateTime time = DateUtil.beginOfDay(date);
  2229. //date昨天零点
  2230. DateTime time0 = DateUtil.offsetDay(time, -1);
  2231. DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
  2232. DateTime beginOfYear = DateUtil.beginOfYear(time0);
  2233. QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
  2234. wrapper.eq("record_date", time0);
  2235. List<StationInfoDay> days = stationInfoDayService.list(wrapper);
  2236. Map<String, StationInfoDay> dayMap = days.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  2237. wrapper = new QueryWrapper<>();
  2238. wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,sum(zhcydl) zhcydl,station_id").between("record_date", beginOfMonth, time0).groupBy("station_id");
  2239. List<StationInfoDay> monthDays = stationInfoDayService.list(wrapper);
  2240. Map<String, StationInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  2241. wrapper = new QueryWrapper<>();
  2242. wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,sum(zhcydl) zhcydl,station_id").between("record_date", beginOfYear, time0).groupBy("station_id");
  2243. List<StationInfoDay> yearDays = stationInfoDayService.list(wrapper);
  2244. Map<String, StationInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  2245. // QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
  2246. // wrapperrp.eq("record_date", time0).last("and foreign_key_id = windpowerstation_id");
  2247. // List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
  2248. QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
  2249. wrapperrp.eq("record_date", time0).in("foreign_key_id", days.stream().map(StationInfoDay::getStationId).collect(Collectors.toList()));
  2250. List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
  2251. if (!pools.isEmpty()) {
  2252. StationInfoDay day, month, year;
  2253. List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
  2254. for (ProEconReportIndicatorPool pool : pools) {
  2255. String stationId = pool.getForeignKeyId();
  2256. day = dayMap.get(stationId);
  2257. pool.setRfdldb(day.getRfdl().doubleValue());
  2258. pool.setRswdldb(day.getSwdl().doubleValue());
  2259. pool.setRgwgwdldb(day.getGwdl().doubleValue());
  2260. pool.setRfdcydldb(day.getCydl().doubleValue());
  2261. pool.setRzhcydldb(day.getZhcydl().doubleValue());
  2262. month = monthMap.get(stationId);
  2263. pool.setYfdldb(month.getRfdl().doubleValue());
  2264. pool.setYswdldb(month.getSwdl().doubleValue());
  2265. pool.setYgwgwdldb(month.getGwdl().doubleValue());
  2266. pool.setYfdcydldb(month.getCydl().doubleValue());
  2267. pool.setYzhcydldb(month.getZhcydl().doubleValue());
  2268. year = yearMap.get(stationId);
  2269. pool.setNfdldb(year.getRfdl().doubleValue());
  2270. pool.setNswdldb(year.getSwdl().doubleValue());
  2271. pool.setNgwgwdldb(year.getGwdl().doubleValue());
  2272. pool.setNfdcydldb(year.getCydl().doubleValue());
  2273. pool.setNzhcydldb(year.getZhcydl().doubleValue());
  2274. poolList.add(pool);
  2275. }
  2276. reportIndicatorPoolService.saveOrUpdateBatch(poolList);
  2277. } else {
  2278. List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
  2279. for (StationInfoDay day : days) {
  2280. ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
  2281. pool.setRecordDate(time0);
  2282. pool.setForeignKeyId(day.getStationId());
  2283. poolList.add(pool);
  2284. }
  2285. reportIndicatorPoolService.saveOrUpdateBatch(poolList);
  2286. }
  2287. }
  2288. public void writeReportPoolSameDay() {
  2289. //date当天零点
  2290. DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
  2291. DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
  2292. DateTime beginOfYear = DateUtil.beginOfYear(time0);
  2293. QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
  2294. wrapper.eq("record_date", time0);
  2295. List<StationInfoDay> days = stationInfoDayService.list(wrapper);
  2296. Map<String, StationInfoDay> dayMap = days.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  2297. wrapper = new QueryWrapper<>();
  2298. wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,sum(zhcydl) zhcydl,station_id").between("record_date", beginOfMonth, time0).groupBy("station_id");
  2299. List<StationInfoDay> monthDays = stationInfoDayService.list(wrapper);
  2300. Map<String, StationInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  2301. wrapper = new QueryWrapper<>();
  2302. wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,sum(zhcydl) zhcydl,station_id").between("record_date", beginOfYear, time0).groupBy("station_id");
  2303. List<StationInfoDay> yearDays = stationInfoDayService.list(wrapper);
  2304. Map<String, StationInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  2305. QueryWrapper<ProEconReportIndicatorPool> wrapperRp = new QueryWrapper<>();
  2306. wrapperRp.eq("record_date", time0).last("and foreign_key_id = windpowerstation_id");
  2307. List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperRp);
  2308. wrapperRp = new QueryWrapper<>();
  2309. wrapperRp.eq("record_date", time0).eq("foreign_key_id", "GJNY_SXGS_DBXNY_ZGS0");
  2310. ProEconReportIndicatorPool poolsCompany = reportIndicatorPoolService.getOne(wrapperRp);
  2311. StationInfoDay day, month, year;
  2312. if (pools.isEmpty()) {
  2313. pools = new ArrayList<>();
  2314. for (StationInfoDay infoDay : days) {
  2315. String stationId = infoDay.getStationId();
  2316. ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
  2317. pool.setRecordDate(time0);
  2318. pool.setForeignKeyId(stationId);
  2319. pool.setWindpowerstationId(stationId);
  2320. month = monthMap.get(stationId);
  2321. year = yearMap.get(stationId);
  2322. poolSetValueDl1(pool, infoDay, month, year);
  2323. pools.add(pool);
  2324. }
  2325. } else {
  2326. for (ProEconReportIndicatorPool pool : pools) {
  2327. String stationId = pool.getWindpowerstationId();
  2328. day = dayMap.get(stationId);
  2329. month = monthMap.get(stationId);
  2330. year = yearMap.get(stationId);
  2331. poolSetValueDl1(pool, day, month, year);
  2332. }
  2333. }
  2334. reportIndicatorPoolService.saveOrUpdateBatch(pools);
  2335. if (poolsCompany == null) {
  2336. poolsCompany = new ProEconReportIndicatorPool();
  2337. poolsCompany.setRecordDate(time0);
  2338. poolsCompany.setForeignKeyId("GJNY_SXGS_DBXNY_ZGS0");
  2339. poolsCompany.setCompanyId("GJNY_SXGS_DBXNY_ZGS");
  2340. poolSetValueDl(poolsCompany, pools);
  2341. } else {
  2342. poolSetValueDl(poolsCompany, pools);
  2343. }
  2344. reportIndicatorPoolService.saveOrUpdate(poolsCompany);
  2345. }
  2346. public void poolSetValueDl1(ProEconReportIndicatorPool pool, StationInfoDay day, StationInfoDay month, StationInfoDay year) {
  2347. pool.setRfdldb(day.getRfdl().doubleValue());
  2348. pool.setRswdldb(day.getSwdl().doubleValue());
  2349. pool.setRgwgwdldb(day.getGwdl().doubleValue());
  2350. pool.setRfdcydldb(day.getCydl().doubleValue());
  2351. pool.setRzhcydldb(day.getZhcydl().doubleValue());
  2352. pool.setYfdldb(month.getRfdl().doubleValue());
  2353. pool.setYswdldb(month.getSwdl().doubleValue());
  2354. pool.setYgwgwdldb(month.getGwdl().doubleValue());
  2355. pool.setYfdcydldb(month.getCydl().doubleValue());
  2356. pool.setYzhcydldb(month.getZhcydl().doubleValue());
  2357. pool.setNfdldb(year.getRfdl().doubleValue());
  2358. pool.setNswdldb(year.getSwdl().doubleValue());
  2359. pool.setNgwgwdldb(year.getGwdl().doubleValue());
  2360. pool.setNfdcydldb(year.getCydl().doubleValue());
  2361. pool.setNzhcydldb(year.getZhcydl().doubleValue());
  2362. }
  2363. public void poolSetValueDl(ProEconReportIndicatorPool pool, LineInfoDay day, LineInfoDay month, LineInfoDay year) {
  2364. pool.setRfdldb(day.getRfdl().doubleValue());
  2365. pool.setRswdldb(day.getSwdl());
  2366. pool.setRgwgwdldb(day.getGwdl());
  2367. pool.setRfdcydldb(day.getCydl());
  2368. pool.setRzhcydldb(day.getRfdl().doubleValue() + day.getGwdl() - day.getSwdl());
  2369. pool.setYfdldb(month.getRfdl().doubleValue());
  2370. pool.setYswdldb(month.getSwdl());
  2371. pool.setYgwgwdldb(month.getGwdl());
  2372. pool.setYfdcydldb(month.getCydl());
  2373. pool.setYzhcydldb(month.getRfdl().doubleValue() + month.getGwdl() - month.getSwdl());
  2374. pool.setNfdldb(year.getRfdl().doubleValue());
  2375. pool.setNswdldb(year.getSwdl());
  2376. pool.setNgwgwdldb(year.getGwdl());
  2377. pool.setNfdcydldb(year.getCydl());
  2378. pool.setNzhcydldb(year.getRfdl().doubleValue() + year.getGwdl() - year.getSwdl());
  2379. }
  2380. public void poolSetValueDl(ProEconReportIndicatorPool pool, List<ProEconReportIndicatorPool> pools) {
  2381. ProEconReportIndicatorPool p = sumProperties(pools, ProEconReportIndicatorPool.class);
  2382. pool.setRfdldb(p.getRfdldb());
  2383. pool.setRswdldb(p.getRswdldb());
  2384. pool.setRgwgwdldb(p.getRgwgwdldb());
  2385. pool.setRfdcydldb(p.getRfdcydldb());
  2386. pool.setRzhcydldb(p.getRzhcydldb());
  2387. pool.setYfdldb(p.getYfdldb());
  2388. pool.setYswdldb(p.getYswdldb());
  2389. pool.setYgwgwdldb(p.getYgwgwdldb());
  2390. pool.setYfdcydldb(p.getYfdcydldb());
  2391. pool.setYzhcydldb(p.getYzhcydldb());
  2392. pool.setNfdldb(p.getNfdldb());
  2393. pool.setNswdldb(p.getNswdldb());
  2394. pool.setNgwgwdldb(p.getNgwgwdldb());
  2395. pool.setNfdcydldb(p.getNfdcydldb());
  2396. pool.setNzhcydldb(p.getNzhcydldb());
  2397. }
  2398. public void writeReportPoolProject(Date date) {
  2399. //date当天零点
  2400. DateTime time = DateUtil.beginOfDay(date);
  2401. //date昨天零点
  2402. DateTime time0 = DateUtil.offsetDay(time, -1);
  2403. DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
  2404. DateTime beginOfYear = DateUtil.beginOfYear(time0);
  2405. QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
  2406. wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,project_id").eq("record_date", time0).groupBy("project_id");
  2407. List<LineInfoDay> days = lineInfoDayService.list(wrapper);
  2408. Map<String, LineInfoDay> dayMap = days.stream().collect(Collectors.toMap(LineInfoDay::getProjectId, Function.identity()));
  2409. wrapper = new QueryWrapper<>();
  2410. wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,project_id").between("record_date", beginOfMonth, time0).groupBy("project_id");
  2411. List<LineInfoDay> monthDays = lineInfoDayService.list(wrapper);
  2412. Map<String, LineInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(LineInfoDay::getProjectId, Function.identity()));
  2413. wrapper = new QueryWrapper<>();
  2414. wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,project_id").between("record_date", beginOfYear, time0).groupBy("project_id");
  2415. List<LineInfoDay> yearDays = lineInfoDayService.list(wrapper);
  2416. Map<String, LineInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(LineInfoDay::getProjectId, Function.identity()));
  2417. // QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
  2418. // wrapperrp.eq("record_date", time0).last("and foreign_key_id = project_id");
  2419. // List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
  2420. QueryWrapper<ProEconReportIndicatorPool> wrapperrp2 = new QueryWrapper<>();
  2421. wrapperrp2.eq("record_date", time0).in("foreign_key_id", days.stream().map(LineInfoDay::getProjectId).collect(Collectors.toList()));
  2422. List<ProEconReportIndicatorPool> pools2 = reportIndicatorPoolService.list(wrapperrp2);
  2423. if (!pools2.isEmpty()) {
  2424. LineInfoDay day, month, year;
  2425. List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
  2426. String projectId;
  2427. for (ProEconReportIndicatorPool pool : pools2) {
  2428. projectId = pool.getForeignKeyId();
  2429. day = dayMap.get(projectId);
  2430. pool.setRfdldb(day.getRfdl().doubleValue());
  2431. pool.setRswdldb(day.getSwdl());
  2432. pool.setRgwgwdldb(day.getGwdl());
  2433. pool.setRfdcydldb(day.getCydl());
  2434. pool.setRzhcydldb(day.getRfdl().doubleValue() + day.getGwdl() - day.getSwdl());
  2435. month = monthMap.get(projectId);
  2436. pool.setYfdldb(month.getRfdl().doubleValue());
  2437. pool.setYswdldb(month.getSwdl());
  2438. pool.setYgwgwdldb(month.getGwdl());
  2439. pool.setYfdcydldb(month.getCydl());
  2440. pool.setRzhcydldb(month.getRfdl().doubleValue() + month.getGwdl() - month.getSwdl());
  2441. year = yearMap.get(projectId);
  2442. pool.setNfdldb(year.getRfdl().doubleValue());
  2443. pool.setNswdldb(year.getSwdl());
  2444. pool.setNgwgwdldb(year.getGwdl());
  2445. pool.setNfdcydldb(year.getCydl());
  2446. pool.setRzhcydldb(year.getRfdl().doubleValue() + year.getGwdl() - year.getSwdl());
  2447. poolList.add(pool);
  2448. }
  2449. reportIndicatorPoolService.saveOrUpdateBatch(poolList);
  2450. } else {
  2451. List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
  2452. for (LineInfoDay day : days) {
  2453. ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
  2454. pool.setRecordDate(time0);
  2455. pool.setForeignKeyId(day.getProjectId());
  2456. poolList.add(pool);
  2457. }
  2458. reportIndicatorPoolService.saveOrUpdateBatch(poolList);
  2459. }
  2460. }
  2461. public void writeReportPoolProjectSameDay() {
  2462. //date当天零点
  2463. DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
  2464. DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
  2465. DateTime beginOfYear = DateUtil.beginOfYear(time0);
  2466. QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
  2467. wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,project_id,station_id").eq("record_date", time0).groupBy("project_id,station_id");
  2468. List<LineInfoDay> days = lineInfoDayService.list(wrapper);
  2469. Map<String, LineInfoDay> dayMap = days.stream().collect(Collectors.toMap(LineInfoDay::getProjectId, Function.identity()));
  2470. wrapper = new QueryWrapper<>();
  2471. wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,project_id,station_id").between("record_date", beginOfMonth, time0).groupBy("project_id,station_id");
  2472. List<LineInfoDay> monthDays = lineInfoDayService.list(wrapper);
  2473. Map<String, LineInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(LineInfoDay::getProjectId, Function.identity()));
  2474. wrapper = new QueryWrapper<>();
  2475. wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,project_id,station_id").between("record_date", beginOfYear, time0).groupBy("project_id,station_id");
  2476. List<LineInfoDay> yearDays = lineInfoDayService.list(wrapper);
  2477. Map<String, LineInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(LineInfoDay::getProjectId, Function.identity()));
  2478. QueryWrapper<ProEconReportIndicatorPool> wrapperRp = new QueryWrapper<>();
  2479. wrapperRp.eq("record_date", time0).last("and foreign_key_id = project_id");
  2480. List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperRp);
  2481. LineInfoDay day, month, year;
  2482. if (pools.isEmpty()) {
  2483. pools = new ArrayList<>();
  2484. for (LineInfoDay infoDay : days) {
  2485. String projectId = infoDay.getProjectId();
  2486. ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
  2487. pool.setRecordDate(time0);
  2488. pool.setForeignKeyId(projectId);
  2489. pool.setWindpowerstationId(infoDay.getStationId());
  2490. pool.setProjectId(projectId);
  2491. month = monthMap.get(projectId);
  2492. year = yearMap.get(projectId);
  2493. poolSetValueDl(pool, infoDay, month, year);
  2494. pools.add(pool);
  2495. }
  2496. } else {
  2497. for (ProEconReportIndicatorPool pool : pools) {
  2498. String projectId = pool.getProjectId();
  2499. day = dayMap.get(projectId);
  2500. month = monthMap.get(projectId);
  2501. year = yearMap.get(projectId);
  2502. poolSetValueDl(pool, day, month, year);
  2503. }
  2504. }
  2505. reportIndicatorPoolService.saveOrUpdateBatch(pools);
  2506. }
  2507. public void writeReportPoolPjfs(Date date) {
  2508. //date当天零点
  2509. DateTime time = DateUtil.beginOfDay(date);
  2510. //date昨天零点
  2511. DateTime time0 = DateUtil.offsetDay(time, -1);
  2512. DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
  2513. DateTime beginOfYear = DateUtil.beginOfYear(time0);
  2514. QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
  2515. wrapper.select("avg(pjfs) pjfs,project_id").eq("record_date", time0).groupBy("project_id");
  2516. List<TurbineInfoDay> days = turbineInfoDayService.list(wrapper);
  2517. Map<String, TurbineInfoDay> dayMap = days.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  2518. wrapper = new QueryWrapper<>();
  2519. wrapper.select("avg(pjfs) pjfs,project_id").between("record_date", beginOfMonth, time0).groupBy("project_id");
  2520. List<TurbineInfoDay> monthDays = turbineInfoDayService.list(wrapper);
  2521. Map<String, TurbineInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  2522. wrapper = new QueryWrapper<>();
  2523. wrapper.select("avg(pjfs) pjfs,project_id").between("record_date", beginOfYear, time0).groupBy("project_id");
  2524. List<TurbineInfoDay> yearDays = turbineInfoDayService.list(wrapper);
  2525. Map<String, TurbineInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  2526. // QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
  2527. // wrapperrp.eq("record_date", time0).last("and foreign_key_id = project_id");
  2528. QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
  2529. wrapperrp.eq("record_date", time0).in("foreign_key_id", days.stream().map(TurbineInfoDay::getProjectId).collect(Collectors.toList()));
  2530. List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
  2531. QueryWrapper<ProEconReportIndicatorPool> wrapperrp2 = new QueryWrapper<>();
  2532. wrapperrp2.eq("record_date", time0).eq("foreign_key_id", "GJNY_SXGS_DBXNY_ZGS0");
  2533. ProEconReportIndicatorPool pools2 = reportIndicatorPoolService.getOne(wrapperrp2);
  2534. if (pools2 == null) {
  2535. ProEconReportIndicatorPool GSPJFS = new ProEconReportIndicatorPool();
  2536. GSPJFS.setRecordDate(time0);
  2537. GSPJFS.setForeignKeyId("GJNY_SXGS_DBXNY_ZGS0");
  2538. GSPJFS.setCompanyId("GJNY_SXGS_DBXNY_ZGS");
  2539. reportIndicatorPoolService.saveOrUpdate(GSPJFS);
  2540. }
  2541. TurbineInfoDay day, month, year;
  2542. String projectId;
  2543. if (!pools.isEmpty()) {
  2544. for (ProEconReportIndicatorPool pool : pools) {
  2545. projectId = pool.getForeignKeyId();
  2546. day = dayMap.get(projectId);
  2547. pool.setRpjfs(day.getPjfs());
  2548. month = monthMap.get(projectId);
  2549. pool.setYpjfs(month.getPjfs());
  2550. year = yearMap.get(projectId);
  2551. pool.setNpjfs(year.getPjfs());
  2552. }
  2553. double v1 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getRpjfs).average().orElse(0);
  2554. double v2 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getYpjfs).average().orElse(0);
  2555. double v3 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getNpjfs).average().orElse(0);
  2556. if (!(pools2 == null)) {
  2557. pools2.setRpjfs(v1);
  2558. pools2.setYpjfs(v2);
  2559. pools2.setNpjfs(v3);
  2560. reportIndicatorPoolService.saveOrUpdate(pools2);
  2561. }
  2562. reportIndicatorPoolService.saveOrUpdateBatch(pools);
  2563. } else {
  2564. List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
  2565. for (TurbineInfoDay day2 : days) {
  2566. ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
  2567. pool.setRecordDate(time0);
  2568. pool.setForeignKeyId(day2.getProjectId());
  2569. poolList.add(pool);
  2570. }
  2571. reportIndicatorPoolService.saveOrUpdateBatch(poolList);
  2572. }
  2573. }
  2574. public void gongsizhibiao(Date date) {
  2575. //date当天零点
  2576. DateTime time = DateUtil.beginOfDay(date);
  2577. //date昨天零点
  2578. DateTime time0 = DateUtil.offsetDay(time, -1);
  2579. DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
  2580. DateTime beginOfYear = DateUtil.beginOfYear(time0);
  2581. QueryWrapper<ProEconReportIndicatorPool> wrapper = new QueryWrapper<>();
  2582. wrapper.eq("record_date", time0)
  2583. //包含"STA"
  2584. .like("foreign_key_id", "_STA");
  2585. List<ProEconReportIndicatorPool> list = reportIndicatorPoolService.list(wrapper);
  2586. //遍历list,累加指标RFDL
  2587. //公司指标,日发电量
  2588. double rfdl = 0;
  2589. //公司指标,日上网电量
  2590. double swdl = 0;
  2591. //公司指标,日购网电量
  2592. double gwdl = 0;
  2593. //公司指标,日综合厂用电量
  2594. double zhcydl = 0;
  2595. //公司指标,月发电量
  2596. double yfdl = 0;
  2597. //公司指标,月上网电量
  2598. double yswdl = 0;
  2599. //公司指标,月购网电量
  2600. double ygwdl = 0;
  2601. //公司指标,月综合厂用电量
  2602. double yzhcydl = 0;
  2603. //公司指标,年发电量
  2604. double nfdl = 0;
  2605. //公司指标,年上网电量
  2606. double nswdl = 0;
  2607. //公司指标,年购网电量
  2608. double ngwdl = 0;
  2609. //公司指标,年综合厂用电量
  2610. double nzhcydl = 0;
  2611. for (ProEconReportIndicatorPool pool : list) {
  2612. rfdl += pool.getRfdldb();
  2613. swdl += pool.getRswdldb();
  2614. gwdl += pool.getRgwgwdldb();
  2615. zhcydl += pool.getRzhcydldb();
  2616. yfdl += pool.getYfdldb();
  2617. yswdl += pool.getYswdldb();
  2618. ygwdl += pool.getYgwgwdldb();
  2619. yzhcydl += pool.getYzhcydldb();
  2620. nfdl += pool.getNfdldb();
  2621. nswdl += pool.getNswdldb();
  2622. ngwdl += pool.getNgwgwdldb();
  2623. nzhcydl += pool.getNzhcydldb();
  2624. }
  2625. QueryWrapper<ProEconReportIndicatorPool> wrapperrp2 = new QueryWrapper<>();
  2626. wrapperrp2.eq("record_date", time0).eq("foreign_key_id", "GJNY_SXGS_DBXNY_ZGS0");
  2627. ProEconReportIndicatorPool GSZB = reportIndicatorPoolService.getOne(wrapperrp2);
  2628. //公司指标集合
  2629. GSZB.setRfdldb(rfdl);
  2630. GSZB.setRswdldb(swdl);
  2631. GSZB.setRgwgwdldb(gwdl);
  2632. GSZB.setRzhcydldb(zhcydl);
  2633. GSZB.setYfdldb(yfdl);
  2634. GSZB.setYswdldb(yswdl);
  2635. GSZB.setYgwgwdldb(ygwdl);
  2636. GSZB.setYzhcydldb(yzhcydl);
  2637. GSZB.setNfdldb(nfdl);
  2638. GSZB.setNswdldb(nswdl);
  2639. GSZB.setNgwgwdldb(ngwdl);
  2640. GSZB.setNzhcydldb(nzhcydl);
  2641. reportIndicatorPoolService.saveOrUpdate(GSZB);
  2642. }
  2643. //公司指标,累加风机理论发电量
  2644. public void writeReportPoolLLFDL(Date date) {
  2645. //date当天零点
  2646. DateTime time = DateUtil.beginOfDay(date);
  2647. //date昨天零点
  2648. DateTime time0 = DateUtil.offsetDay(time, -1);
  2649. DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
  2650. DateTime beginOfYear = DateUtil.beginOfYear(time0);
  2651. QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
  2652. wrapper.select("avg(llfdl) llfdl,project_id").eq("record_date", time0).groupBy("project_id");
  2653. List<TurbineInfoDay> days = turbineInfoDayService.list(wrapper);
  2654. Map<String, TurbineInfoDay> dayMap = days.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  2655. wrapper = new QueryWrapper<>();
  2656. wrapper.select("avg(llfdl) llfdl,project_id").between("record_date", beginOfMonth, time0).groupBy("project_id");
  2657. List<TurbineInfoDay> monthDays = turbineInfoDayService.list(wrapper);
  2658. Map<String, TurbineInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  2659. wrapper = new QueryWrapper<>();
  2660. wrapper.select("avg(llfdl) llfdl,project_id").between("record_date", beginOfYear, time0).groupBy("project_id");
  2661. List<TurbineInfoDay> yearDays = turbineInfoDayService.list(wrapper);
  2662. Map<String, TurbineInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  2663. QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
  2664. wrapperrp.eq("record_date", time0).in("foreign_key_id", days.stream().map(TurbineInfoDay::getProjectId).collect(Collectors.toList()));
  2665. List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
  2666. QueryWrapper<ProEconReportIndicatorPool> wrapperrp2 = new QueryWrapper<>();
  2667. wrapperrp2.eq("record_date", time0).eq("foreign_key_id", "GJNY_SXGS_DBXNY_ZGS0");
  2668. ProEconReportIndicatorPool pools2 = reportIndicatorPoolService.getOne(wrapperrp2);
  2669. if (pools2 == null) {
  2670. ProEconReportIndicatorPool GSPJFS = new ProEconReportIndicatorPool();
  2671. GSPJFS.setRecordDate(time0);
  2672. GSPJFS.setForeignKeyId("GJNY_SXGS_DBXNY_ZGS0");
  2673. GSPJFS.setCompanyId("GJNY_SXGS_DBXNY_ZGS");
  2674. reportIndicatorPoolService.saveOrUpdate(GSPJFS);
  2675. }
  2676. TurbineInfoDay day, month, year;
  2677. String projectId;
  2678. if (!pools.isEmpty()) {
  2679. for (ProEconReportIndicatorPool pool : pools) {
  2680. projectId = pool.getForeignKeyId();
  2681. day = dayMap.get(projectId);
  2682. pool.setRllfdl(day.getLlfdl());
  2683. month = monthMap.get(projectId);
  2684. pool.setYllfdl(month.getLlfdl());
  2685. year = yearMap.get(projectId);
  2686. pool.setNllfdl(year.getLlfdl());
  2687. }
  2688. double v1 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getRllfdl).sum();
  2689. double v2 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getYllfdl).sum();
  2690. double v3 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getNllfdl).sum();
  2691. //pools.stream().mapToDouble(ProEconReportIndicatorPool::getRllfdl),求和
  2692. if (pools2 != null) {
  2693. pools2.setRllfdl(v1);
  2694. pools2.setYllfdl(v2);
  2695. pools2.setNllfdl(v3);
  2696. reportIndicatorPoolService.saveOrUpdate(pools2);
  2697. }
  2698. reportIndicatorPoolService.saveOrUpdateBatch(pools);
  2699. } else {
  2700. List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
  2701. for (TurbineInfoDay day2 : days) {
  2702. ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
  2703. pool.setRecordDate(time0);
  2704. pool.setForeignKeyId(day2.getProjectId());
  2705. poolList.add(pool);
  2706. }
  2707. reportIndicatorPoolService.saveOrUpdateBatch(poolList);
  2708. }
  2709. }
  2710. public void calcRealtimeTurbineZt() {
  2711. DateTime date0 = DateUtil.date();
  2712. boolean isOnMin = false;
  2713. //分钟变化
  2714. if (CalcCache.minuteNow.minute() != date0.minute()) {
  2715. date0 = DateUtil.beginOfMinute(date0);
  2716. CalcCache.minuteNow = date0;
  2717. isOnMin = true;
  2718. }
  2719. DateTime date = date0;
  2720. List<PointInfo> turbineZt = calcRealtimeTurbineDizt();
  2721. List<PointInfo> turbineAizt = calcRealtimeTurbineAizt();
  2722. turbineZt.addAll(turbineAizt);
  2723. turbineZt = turbineZt.stream().peek(t -> {
  2724. if (t.getPointDatas().get(0).getTs() + 35 * 60 * 1000 <= date.getTime()) {
  2725. t.getPointDatas().get(0).setDoubleValue(12.0);
  2726. }
  2727. }).collect(Collectors.toList());
  2728. Map<String, Map<String, PointInfo>> ztMapMap = turbineZt.stream().collect(Collectors.groupingBy(PointInfo::getStationId, Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
  2729. //AGC
  2730. List<PointInfo> entityAgc = getEntity("AGC002", "booster");
  2731. getSnapDataByEntity(entityAgc, DateUtil.offsetMinute(date, -5), date, 15);
  2732. //出线
  2733. List<PointInfo> entityCx = getEntity("AGC001", "booster");
  2734. getSnapDataByEntity(entityCx, DateUtil.offsetMinute(date, -5), date, 15);
  2735. //风速
  2736. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  2737. getSnapDataByEntity(entityFs, DateUtil.offsetMinute(date, -5), date, 15);
  2738. Map<String, PointInfo> collectAgc = entityAgc.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  2739. Map<String, PointInfo> collectCx = entityCx.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  2740. Map<String, Map<String, PointInfo>> fsMapMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId, Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
  2741. //功率
  2742. List<PointInfo> entityGl = getEntity("AI114", "turbine");
  2743. getLatestByEntity(entityGl);
  2744. Map<String, List<PointData>> glMap = entityGl.stream().collect(Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas));
  2745. ztMapMap.forEach((stId, ztMap) -> {
  2746. PointInfo agcInfo = collectAgc.get(stId);
  2747. PointInfo cxInfo = collectCx.get(stId);
  2748. Map<String, PointInfo> fsMap = fsMapMap.get(stId);
  2749. Map<String, List<PointData>> pdsZsglMap = new HashMap<>();
  2750. ztMap.forEach((wtId, zt) -> {
  2751. List<PointData> peek = fsMap.get(wtId).getPointDatas().stream().peek(pd -> pd.setDoubleValue(NumberUtil.round(pd.getValue() > 25 ? 25.0 : pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
  2752. fsMap.get(wtId).setPointDatas(peek);
  2753. List<PointData> zsglSnap = fsMap.get(wtId).getPointDatas().stream().map(pd -> {
  2754. Double v = CalcCache.fitcoef.get(wtId).get(pd.getValue());
  2755. return new PointData(pd.getTs(), v == null ? 0 : v);
  2756. }).collect(Collectors.toList());
  2757. pdsZsglMap.put(wtId, zsglSnap);
  2758. });
  2759. List<PointData> agcc = agcInfo.getPointDatas().stream().peek(agc -> {
  2760. agc.setDoubleValue(agc.getValue() * agcInfo.getCoef());
  2761. agc.setLongValue(0L);
  2762. }).collect(Collectors.toList());
  2763. agcInfo.setPointDatas(agcc);
  2764. List<PointData> cxc = cxInfo.getPointDatas().stream().peek(cx -> {
  2765. cx.setDoubleValue(cx.getValue() * cxInfo.getCoef());
  2766. cx.setLongValue(0L);
  2767. }).collect(Collectors.toList());
  2768. cxInfo.setPointDatas(cxc);
  2769. //风机风速、功率->场站风速、功率
  2770. List<PointData> firstZsgl = new ArrayList<>();
  2771. double v3;
  2772. for (int i = 0; i < 20; i++) {
  2773. int finalI = i;
  2774. long ts = date.getTime() + i * 15000;
  2775. v3 = pdsZsglMap.values().stream().mapToDouble(pds -> pds.get(finalI).getValue()).sum();
  2776. firstZsgl.add(new PointData(ts, v3));
  2777. }
  2778. boolean czxd = calcRealtimeStationXd(agcInfo, cxInfo.getPointDatas(), firstZsgl);
  2779. if (czxd) {
  2780. //叶轮转速给定
  2781. List<PointInfo> entityYlzsgd = getEntity("AI110", "turbine");
  2782. getLatestByEntity(entityYlzsgd);
  2783. Map<String, List<PointData>> collectYlzsgd = entityYlzsgd.stream().collect(Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas));
  2784. ztMap.forEach((wtId, ztInfo) -> {
  2785. List<PointData> fss = fsMap.get(wtId).getPointDatas();
  2786. List<PointData> gls = glMap.get(wtId);
  2787. //叶轮转速给定
  2788. List<PointData> ylzsgds = collectYlzsgd.get(wtId);
  2789. calcRealtimeTurbineXd(ztInfo, gls.get(0), fss.get(fss.size() - 1), ylzsgds.get(0));
  2790. });
  2791. }
  2792. });
  2793. Map<String, String> entityMxzt = getEntityMap("MXZT", "turbine");
  2794. Map<String, String> entityQfzt = getEntityMap("SSQFZT", "turbine");
  2795. //Map<String, String> entityKygl = getEntityMap("KYGL", "turbine");
  2796. List<PointInfo> fsEntity = entityFs.stream().peek(fs -> {
  2797. PointData data = fs.getPointDatas().get(fs.getPointDatas().size() - 1);
  2798. if (data != null) {
  2799. fs.setPointDatas(Collections.singletonList(data));
  2800. } else {
  2801. fs.setPointDatas(Collections.singletonList(new PointData()));
  2802. }
  2803. }).collect(Collectors.toList());
  2804. List<PointData> qfztDataList = fsEntity.stream().map(fs -> {
  2805. String wtId = fs.getTurbineId();
  2806. PointData data = fs.getPointDatas().get(0);
  2807. data.setTs(date.getTime());
  2808. data.setTagName(entityQfzt.get(wtId));
  2809. data.setDoubleValue(calcQfzt(glMap.get(wtId).get(0).getValue(), CalcCache.fitcoef.get(wtId).get(data.getValue())));
  2810. return data;
  2811. }).collect(Collectors.toList());
  2812. //风机状态转换为写适配器的测点与值
  2813. List<PointData> dataList = turbineZt.stream().map(zt -> {
  2814. PointData data = zt.getPointDatas().get(0);
  2815. data.setTs(date.getTime());
  2816. data.setTagName(entityMxzt.get(zt.getTurbineId()));
  2817. return data;
  2818. }).collect(Collectors.toList());
  2819. if (isOnMin) {
  2820. adapter.writeHistoryBatch(taosUri(), dataList);
  2821. adapter.writeHistoryBatch(taosUri(), qfztDataList);
  2822. } else {
  2823. List<PointData> collect = dataList.stream().filter(d -> {
  2824. if (Objects.equals(CalcCache.statusCache.get(d.getTagName()), d.getValue())) {
  2825. return false;
  2826. } else {
  2827. CalcCache.statusCache.put(d.getTagName(), d.getValue());
  2828. return true;
  2829. }
  2830. }).collect(Collectors.toList());
  2831. List<PointData> qfztDatas = qfztDataList.stream().filter(d -> {
  2832. if (Objects.equals(CalcCache.qfztCache.get(d.getTagName()), d.getValue())) {
  2833. return false;
  2834. } else {
  2835. CalcCache.qfztCache.put(d.getTagName(), d.getValue());
  2836. return true;
  2837. }
  2838. }).collect(Collectors.toList());
  2839. adapter.writeHistoryBatch(taosUri(), collect);
  2840. adapter.writeHistoryBatch(taosUri(), qfztDatas);
  2841. }
  2842. }
  2843. //此处加公式
  2844. public Map<String, Double> calcRealtimeTurbineZt(String stId) {
  2845. List<PointInfo> turbineZt = calcRealtimeTurbineDizt();
  2846. List<PointInfo> turbineAizt = calcRealtimeTurbineAizt();
  2847. turbineZt.addAll(turbineAizt);
  2848. Map<String, Double> collect = turbineZt.stream().filter(zt -> zt.getStationId().equals(stId)).peek(t -> {
  2849. if (t.getPointDatas().get(0).getTs() + 35 * 60 * 1000 <= DateUtil.date().getTime()) {
  2850. t.getPointDatas().get(0).setDoubleValue(12.0);
  2851. }
  2852. }).collect(Collectors.toMap(PointInfo::getTurbineId, pi -> pi.getPointDatas().get(0).getValue()));
  2853. return collect;
  2854. }
  2855. // 计算每种状态的总持续时间
  2856. public void calcTurbineStateMin(Date date) {
  2857. //date当天零点
  2858. DateTime time = DateUtil.beginOfDay(date);
  2859. //date昨天零点
  2860. DateTime time0 = DateUtil.offsetDay(time, -1);
  2861. List<PointInfo> entityMxzt = getEntity("MXZT", "turbine");
  2862. getRawDataByEntity(entityMxzt, taosUri(), time0, time);
  2863. Map<String, TurbineInfoDay> byDate = getTurbineinfoMap(time0, entityMxzt);
  2864. for (PointInfo info : entityMxzt) {
  2865. TurbineInfoDay infoDay = byDate.get(info.getTurbineId());
  2866. Map<Double, Long> durations = calculateStateDurations(info.getPointDatas());
  2867. infoDay.setDjMin(durations.getOrDefault(0.0, 0L) / 60000.0);
  2868. infoDay.setTjMin(durations.getOrDefault(1.0, 0L) / 60000.0);
  2869. infoDay.setYxMin(durations.getOrDefault(2.0, 0L) / 60000.0);
  2870. infoDay.setGzMin(durations.getOrDefault(4.0, 0L) / 60000.0);
  2871. infoDay.setJxMin(durations.getOrDefault(6.0, 0L) / 60000.0);
  2872. infoDay.setXdMin(durations.getOrDefault(8.0, 0L) / 60000.0);
  2873. infoDay.setLxMin(durations.getOrDefault(12.0, 0L) / 60000.0);
  2874. }
  2875. turbineInfoDayService.saveOrUpdateBatch(byDate.values());
  2876. }
  2877. public Map<Double, Long> calculateStateDurations(List<PointData> datas) {
  2878. if (CollUtil.isEmpty(datas)) return Collections.emptyMap();
  2879. Map<Double, Long> durations = new HashMap<>();
  2880. double prevState = datas.get(0).getValue(); // 初始状态
  2881. long prevTs = datas.get(0).getTs(); // 初始时间戳
  2882. PointData current;
  2883. double currentState;
  2884. long currentTs;
  2885. for (int i = 1; i < datas.size(); i++) {
  2886. current = datas.get(i);
  2887. currentState = current.getValue();
  2888. currentTs = current.getTs();
  2889. if (currentState != prevState) {
  2890. // 当状态变化时,计算前一个状态的持续时间并更新map
  2891. durations.put(prevState, durations.getOrDefault(prevState, 0L) + (currentTs - prevTs));
  2892. prevState = currentState;
  2893. prevTs = currentTs;
  2894. }
  2895. }
  2896. // 不要忘记计算列表中最后一个状态的持续时间(如果列表没有以状态变化结束)
  2897. durations.put(prevState, durations.getOrDefault(prevState, 0L) + (datas.get(datas.size() - 1).getTs() - prevTs));
  2898. return durations;
  2899. }
  2900. public void getRawDataByEntity(List<PointInfo> entity, URI uri, Date start, Date end) {
  2901. for (PointInfo info : entity) {
  2902. List<PointData> snap = adapter.getHistoryRaw(uri, info.getPointKey(), start.getTime(), end.getTime());
  2903. ThreadUtil.sleep(5);
  2904. info.setPointDatas(snap);
  2905. }
  2906. }
  2907. public void getStatDataByEntity(List<PointInfo> entity, URI uri, Date start, Date end) {
  2908. for (PointInfo info : entity) {
  2909. DoubleStatData stat = adapter.getHistoryStat(uri, info.getPointKey(), start.getTime(), end.getTime());
  2910. ThreadUtil.sleep(5);
  2911. info.setPointDatas(new ArrayList<>(3));
  2912. if (stat != null) {
  2913. info.getPointDatas().add(stat.getAvg());
  2914. info.getPointDatas().add(stat.getMax());
  2915. info.getPointDatas().add(stat.getMin());
  2916. } else {
  2917. info.getPointDatas().add(new PointData());
  2918. info.getPointDatas().add(new PointData());
  2919. info.getPointDatas().add(new PointData());
  2920. }
  2921. }
  2922. }
  2923. public Map<String, PointInfo> getStatDataByEntity(List<PointInfo> entity, URI uri, Date start, Date end, Function<PointInfo, String> function) {
  2924. getStatDataByEntity(entity, uri, start, end);
  2925. return entity.stream().collect(Collectors.toMap(function, Function.identity()));
  2926. }
  2927. // 主函数或测试方法(如果需要)
  2928. public static void main(String[] args) {
  2929. Double b = 2.0;
  2930. double c = 2.0;
  2931. System.out.println(b == c);
  2932. Double d = Double.valueOf(c);
  2933. System.out.println(Objects.equals(b, c));
  2934. System.out.println(Objects.equals(d, b));
  2935. System.out.println(Objects.equals(null, null));
  2936. List<PointData> points = new ArrayList<>();
  2937. points.add(new PointData(1000, 1));
  2938. points.add(new PointData(1500, 2));
  2939. points.add(new PointData(2000, 1));
  2940. points.add(new PointData(2500, 3));
  2941. // Map<Integer, Long> durations = calculateStateDurations(points);
  2942. // for (Map.Entry<Integer, Long> entry : durations.entrySet()) {
  2943. // System.out.println("State " + entry.getKey() + ": " + entry.getValue() + "ms");
  2944. // }
  2945. }
  2946. public List<PointInfo> getLatest(String uniformCode, String institutionType) {
  2947. List<PointInfo> entity = getEntity(uniformCode, institutionType);
  2948. String collect = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
  2949. Map<String, PointData> latest = adapter.getLatest(goldenUri(), collect);
  2950. entity.forEach(e -> {
  2951. e.setPointDatas(Collections.singletonList(latest.get(e.getPointKey())));
  2952. });
  2953. return entity;
  2954. }
  2955. public void getLatestByEntity(List<PointInfo> entity) {
  2956. String collect = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
  2957. Map<String, PointData> latest = adapter.getLatest(goldenUri(), collect);
  2958. entity.forEach(e -> {
  2959. e.setPointDatas(Collections.singletonList(latest.get(e.getPointKey())));
  2960. });
  2961. }
  2962. public List<PointInfo> calcRealtimeTurbineDizt() {
  2963. List<PointInfo> entity = new ArrayList<>();
  2964. List<PointInfo> result = new ArrayList<>();
  2965. List<PointInfo> entity0 = getEntity("MX000", "state");
  2966. List<PointInfo> entity1 = getEntity("MX001", "state");
  2967. List<PointInfo> entity2 = getEntity("MX002", "state");
  2968. List<PointInfo> entity4 = getEntity("MX004", "state");
  2969. List<PointInfo> entity6 = getEntity("MX006", "state");
  2970. entity.addAll(entity0);
  2971. entity.addAll(entity1);
  2972. entity.addAll(entity2);
  2973. entity.addAll(entity4);
  2974. entity.addAll(entity6);
  2975. String keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
  2976. Map<String, PointData> latest = adapter.getLatest(goldenUri(), keys);
  2977. Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
  2978. wtUcPis.forEach((wtId, map) -> {
  2979. String collect = map.values().stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
  2980. PointInfo info2 = map.get("MX002");
  2981. PointData data2 = latest.get(info2.getPointKey());
  2982. if (data2.getValue() == 1.0) {
  2983. data2.setDoubleValue(2.0);
  2984. data2.setBooleanValue(false);
  2985. info2.setPointDatas(Collections.singletonList(data2));
  2986. result.add(info2);
  2987. } else {
  2988. PointInfo info0 = map.get("MX000");
  2989. PointData data0 = latest.get(info0.getPointKey());
  2990. if (data0.getValue() == 1.0) {
  2991. data0.setDoubleValue(0.0);
  2992. data0.setBooleanValue(false);
  2993. info0.setPointDatas(Collections.singletonList(data0));
  2994. result.add(info0);
  2995. } else {
  2996. PointInfo info6 = map.get("MX006");
  2997. PointData data6 = latest.get(info6.getPointKey());
  2998. if (data6.getValue() == 1.0) {
  2999. data6.setDoubleValue(6.0);
  3000. data6.setBooleanValue(false);
  3001. info6.setPointDatas(Collections.singletonList(data6));
  3002. result.add(info6);
  3003. } else {
  3004. PointInfo info4 = map.get("MX004");
  3005. PointData data4 = latest.get(info4.getPointKey());
  3006. if (data4.getValue() == 1.0) {
  3007. data4.setDoubleValue(4.0);
  3008. data4.setBooleanValue(false);
  3009. info4.setPointDatas(Collections.singletonList(data4));
  3010. result.add(info4);
  3011. } else {
  3012. PointInfo info1 = map.get("MX001");
  3013. PointData data1 = latest.get(info1.getPointKey());
  3014. if (data1.getValue() == 1.0) {
  3015. data1.setDoubleValue(1.0);
  3016. data1.setBooleanValue(false);
  3017. info1.setPointDatas(Collections.singletonList(data1));
  3018. result.add(info1);
  3019. } else {
  3020. Map<String, PointData> latest2 = adapter.getLatest(goldenUri(), collect);
  3021. data1.setDoubleValue(2.0);
  3022. System.out.println("wtId: " + wtId + ",状态值无批配: " + data1.getValue());
  3023. info1.setPointDatas(Collections.singletonList(data1));
  3024. result.add(info1);
  3025. }
  3026. }
  3027. }
  3028. }
  3029. }
  3030. });
  3031. return result;
  3032. }
  3033. public List<PointInfo> calcRealtimeTurbineAizt() {
  3034. List<PointInfo> entityAiZt = getEntity("AI422", "state");
  3035. List<StateAi> list = stateAiService.list();
  3036. //机型,源状态,目标状态
  3037. Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
  3038. String collect = entityAiZt.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
  3039. Map<String, PointData> latest = adapter.getLatest(goldenUri(), collect);
  3040. for (PointInfo info : entityAiZt) {
  3041. PointData data = latest.get(info.getPointKey());
  3042. Integer m = collectAi.get(info.getSpare()).get((int) data.getValue());
  3043. if (m == null) m = 2;
  3044. data.setDoubleValue(m);
  3045. info.setPointDatas(Collections.singletonList(data));
  3046. }
  3047. return entityAiZt;
  3048. }
  3049. public void getAgoAvg(List<PointInfo> entity, Date start, Date end) {
  3050. for (PointInfo info : entity) {
  3051. DoubleStatData snap = adapter.getHistoryStat(goldenUri(), info.getPointKey(), start.getTime(), end.getTime());
  3052. ThreadUtil.sleep(5);
  3053. info.setPointDatas(Collections.singletonList(snap.getAvg()));
  3054. }
  3055. }
  3056. public void calcRealtimeTurbineXd(PointInfo ztInfo, PointData gl, PointData fs, PointData ylzsgd) {
  3057. Map<String, EquipmentModel> map = equipmentModelService.map();
  3058. Double capacity = map.get(ztInfo.getSpare()).getPowerProduction();
  3059. PointData zt = ztInfo.getPointDatas().get(0);
  3060. if (gl.getValue() < capacity * 0.9) {
  3061. if (fs.getValue() >= 12) {
  3062. zt.setDoubleValue(8.0);
  3063. }
  3064. if (ylzsgd.getValue() != 0 && ylzsgd.getValue() < 17.3) {//降出力
  3065. zt.setDoubleValue(8.0);
  3066. }
  3067. }
  3068. }
  3069. //此处加公式
  3070. public boolean calcRealtimeStationXd(PointInfo agcInfo, List<PointData> cxSnap, List<PointData> zsglSnap) {
  3071. String stId = agcInfo.getStationId();
  3072. List<PointData> agcSnap = agcInfo.getPointDatas();
  3073. List<PointData> zsgl5s = get5Avg(zsglSnap);
  3074. List<PointData> agc5s = get5Avg(agcSnap);
  3075. List<PointData> cx5s = get5Avg(cxSnap);
  3076. //之前是否限电
  3077. boolean iszqxd = false;
  3078. for (int i = 0; i < zsglSnap.size(); i++) {
  3079. boolean isxd = false;
  3080. double zsgl = zsglSnap.get(i).getValue();
  3081. double zsgl5 = zsgl5s.get(i).getValue();
  3082. double agc = agcSnap.get(i).getValue();
  3083. double agc5 = agc5s.get(i).getValue();
  3084. double cxgl = cxSnap.get(i).getValue();
  3085. double cxgl5 = cx5s.get(i).getValue();
  3086. boolean k; //agc一直不变
  3087. //第一次初始化复制实时数据到缓存
  3088. if (CalcCache.powerCacheRt.get(stId) == null || CalcCache.powerCacheRt.get(stId) != agc) {
  3089. CalcCache.powerCacheRt.put(stId, agc);
  3090. k = false;
  3091. } else {
  3092. k = true;
  3093. }
  3094. if (agc != 0) {
  3095. //如果场站限电状态为不限电
  3096. if (zsgl5 >= agcInfo.getSpare2() * 40) {
  3097. if (agc5 <= cxgl5) {
  3098. isxd = true;
  3099. } else if (iszqxd) {
  3100. if (zsgl / agc > 1.15) {
  3101. isxd = true;
  3102. } else if (zsgl > agc && agc5 - cxgl5 < 400) {
  3103. isxd = true;
  3104. }
  3105. } else if (zsgl / agc >= 1.2 && agc - cxgl <= 200) {
  3106. isxd = true;
  3107. }
  3108. } else if (k) {
  3109. if (zsgl / agc >= 1.1 && agc5 - cxgl5 <= 200) {
  3110. isxd = true;
  3111. }
  3112. }
  3113. }
  3114. iszqxd = isxd;
  3115. }
  3116. return iszqxd;
  3117. }
  3118. /*public void calcStationSwGwCyRdl(Date date) {
  3119. //date当天零点
  3120. DateTime time = DateUtil.beginOfDay(date);
  3121. //date昨天零点
  3122. DateTime time0 = DateUtil.offsetDay(time, -1);
  3123. List<PointInfo> swdlEt = getEntity("Z-ZXYG-CX", "meter");
  3124. List<PointInfo> gwdlEt = getEntity("Z-FXYG-CX", "meter");
  3125. List<PointInfo> cydlEt = getEntity("Z-ZXYG-ZYB", "meter");
  3126. getZeroNextData(swdlEt, time0, time);
  3127. getZeroNextData(gwdlEt, time0, time);
  3128. getZeroNextData(cydlEt, time0, time);
  3129. Map<String, PointInfo> swdlMap = swdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  3130. Map<String, PointInfo> gwdlMap = gwdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  3131. Map<String, PointInfo> cydlMap = cydlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  3132. List<StationInfoDay> byDate = getStationinfoByDate(time0, swdlEt);
  3133. String stId;
  3134. PointInfo swdlPi, gwdlPi, cydlPi;
  3135. for (StationInfoDay info : byDate) {
  3136. stId = info.getStationId();
  3137. swdlPi = swdlMap.get(stId);
  3138. gwdlPi = gwdlMap.get(stId);
  3139. cydlPi = cydlMap.get(stId);
  3140. int swdl = (int) ((swdlPi.getPointDatas().get(1).getValue() - swdlPi.getPointDatas().get(0).getValue()) * swdlPi.getCoef());
  3141. int gwdl = (int) ((gwdlPi.getPointDatas().get(1).getValue() - gwdlPi.getPointDatas().get(0).getValue()) * gwdlPi.getCoef());
  3142. int cydl = (int) ((cydlPi.getPointDatas().get(1).getValue() - cydlPi.getPointDatas().get(0).getValue()) * cydlPi.getCoef());
  3143. if (swdl < 0 || swdl > 1000000) swdl = 0;
  3144. if (gwdl < 0 || gwdl > 1000000) gwdl = 0;
  3145. if (cydl < 0 || cydl > 1000000) cydl = 0;
  3146. info.setSwdl(swdl);
  3147. info.setGwdl(gwdl);
  3148. info.setCydl(cydl);
  3149. }
  3150. stationInfoDayService.saveOrUpdateBatch(byDate);
  3151. }*/
  3152. public void writeReportPool5SPjfsLlfdlZtsj(Date date) {
  3153. //date当天零点
  3154. DateTime time = DateUtil.beginOfDay(date);
  3155. //date昨天零点
  3156. DateTime time0 = DateUtil.offsetDay(time, -1);
  3157. DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
  3158. DateTime beginOfYear = DateUtil.beginOfYear(time0);
  3159. QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
  3160. wrapper.select("sum(llfdl) llfdl,sum(jhjxss) jhjxss,sum(fjhjxss) fjhjxss,sum(xdss) xdss,sum(slss) slss,sum(xnss) xnss," +
  3161. "sum(gzss) gzss,sum(djss) djss,avg(pjfs) pjfs,sum(dj_min) dj_min,sum(tj_min) tj_min,sum(yx_min) yx_min,sum(gz_min) gz_min," +
  3162. "sum(jx_min) jx_min,sum(xd_min) xd_min,sum(lx_min) lx_min,project_id,station_id")
  3163. .eq("record_date", time0).groupBy("project_id,station_id");
  3164. List<TurbineInfoDay> days = turbineInfoDayService.list(wrapper);
  3165. Map<String, TurbineInfoDay> dayMap = days.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  3166. wrapper = new QueryWrapper<>();
  3167. wrapper.select("sum(llfdl) llfdl,sum(jhjxss) jhjxss,sum(fjhjxss) fjhjxss,sum(xdss) xdss,sum(slss) slss,sum(xnss) xnss," +
  3168. "sum(gzss) gzss,sum(djss) djss,avg(pjfs) pjfs,sum(dj_min) dj_min,sum(tj_min) tj_min,sum(yx_min) yx_min,sum(gz_min) gz_min," +
  3169. "sum(jx_min) jx_min,sum(xd_min) xd_min,sum(lx_min) lx_min,project_id,station_id")
  3170. .between("record_date", beginOfMonth, time0).groupBy("project_id,station_id");
  3171. List<TurbineInfoDay> monthDays = turbineInfoDayService.list(wrapper);
  3172. Map<String, TurbineInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  3173. wrapper = new QueryWrapper<>();
  3174. wrapper.select("sum(llfdl) llfdl,sum(jhjxss) jhjxss,sum(fjhjxss) fjhjxss,sum(xdss) xdss,sum(slss) slss,sum(xnss) xnss," +
  3175. "sum(gzss) gzss,sum(djss) djss,avg(pjfs) pjfs,sum(dj_min) dj_min,sum(tj_min) tj_min,sum(yx_min) yx_min,sum(gz_min) gz_min," +
  3176. "sum(jx_min) jx_min,sum(xd_min) xd_min,sum(lx_min) lx_min,project_id,station_id")
  3177. .between("record_date", beginOfYear, time0).groupBy("project_id,station_id");
  3178. List<TurbineInfoDay> yearDays = turbineInfoDayService.list(wrapper);
  3179. Map<String, TurbineInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  3180. QueryWrapper<ProEconReportIndicatorPool> wrapperRp = new QueryWrapper<>();
  3181. wrapperRp.eq("record_date", time0).last("and foreign_key_id = project_id");
  3182. List<ProEconReportIndicatorPool> poolsProject = reportIndicatorPoolService.list(wrapperRp);
  3183. wrapperRp = new QueryWrapper<>();
  3184. wrapperRp.eq("record_date", time0).last("and foreign_key_id = windpowerstation_id");
  3185. List<ProEconReportIndicatorPool> poolsStation = reportIndicatorPoolService.list(wrapperRp);
  3186. wrapperRp = new QueryWrapper<>();
  3187. wrapperRp.eq("record_date", time0).eq("foreign_key_id", "GJNY_SXGS_DBXNY_ZGS0");
  3188. ProEconReportIndicatorPool poolsCompany = reportIndicatorPoolService.getOne(wrapperRp);
  3189. TurbineInfoDay day, month, year;
  3190. String projectId;
  3191. if (poolsProject.isEmpty()) {
  3192. for (TurbineInfoDay infoDay : days) {
  3193. projectId = infoDay.getProjectId();
  3194. ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
  3195. pool.setRecordDate(time0);
  3196. pool.setForeignKeyId(projectId);
  3197. pool.setWindpowerstationId(infoDay.getStationId());
  3198. pool.setProjectId(projectId);
  3199. month = monthMap.get(projectId);
  3200. year = yearMap.get(projectId);
  3201. poolSetValue1(pool, infoDay, month, year);
  3202. poolsProject.add(pool);
  3203. }
  3204. } else {
  3205. for (ProEconReportIndicatorPool pool : poolsProject) {
  3206. projectId = pool.getProjectId();
  3207. day = dayMap.get(projectId);
  3208. month = monthMap.get(projectId);
  3209. year = yearMap.get(projectId);
  3210. poolSetValue1(pool, day, month, year);
  3211. }
  3212. }
  3213. reportIndicatorPoolService.saveOrUpdateBatch(poolsProject);
  3214. Map<String, List<ProEconReportIndicatorPool>> projectMap = poolsProject.stream().collect(Collectors.groupingBy(ProEconReportIndicatorPool::getWindpowerstationId));
  3215. if (poolsStation.isEmpty()) {
  3216. projectMap.forEach((StId, pis) -> {
  3217. ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
  3218. pool.setRecordDate(time0);
  3219. pool.setForeignKeyId(StId);
  3220. pool.setWindpowerstationId(StId);
  3221. poolSetValue(pool, pis);
  3222. poolsStation.add(pool);
  3223. });
  3224. } else {
  3225. for (ProEconReportIndicatorPool pool : poolsStation) {
  3226. List<ProEconReportIndicatorPool> pools = projectMap.get(pool.getWindpowerstationId());
  3227. poolSetValue(pool, pools);
  3228. }
  3229. }
  3230. reportIndicatorPoolService.saveOrUpdateBatch(poolsStation);
  3231. if (poolsCompany == null) {
  3232. poolsCompany = new ProEconReportIndicatorPool();
  3233. poolsCompany.setRecordDate(time0);
  3234. poolsCompany.setForeignKeyId("GJNY_SXGS_DBXNY_ZGS0");
  3235. poolsCompany.setCompanyId("GJNY_SXGS_DBXNY_ZGS");
  3236. poolSetValue(poolsCompany, poolsStation);
  3237. } else {
  3238. poolSetValue(poolsCompany, poolsStation);
  3239. }
  3240. reportIndicatorPoolService.saveOrUpdate(poolsCompany);
  3241. }
  3242. public void writeReportPoolPjfs2(Date date) {
  3243. //date当天零点
  3244. DateTime time = DateUtil.beginOfDay(date);
  3245. //date昨天零点
  3246. DateTime time0 = DateUtil.offsetDay(time, -1);
  3247. DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
  3248. DateTime beginOfYear = DateUtil.beginOfYear(time0);
  3249. QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
  3250. wrapper.select("avg(pjfs) pjfs,project_id,station_id")
  3251. .eq("record_date", time0).groupBy("project_id,station_id");
  3252. List<TurbineInfoDay> days = turbineInfoDayService.list(wrapper);
  3253. Map<String, TurbineInfoDay> dayMap = days.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  3254. wrapper = new QueryWrapper<>();
  3255. wrapper.select("avg(pjfs) pjfs,project_id,station_id")
  3256. .between("record_date", beginOfMonth, time0).groupBy("project_id,station_id");
  3257. List<TurbineInfoDay> monthDays = turbineInfoDayService.list(wrapper);
  3258. Map<String, TurbineInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  3259. wrapper = new QueryWrapper<>();
  3260. wrapper.select("avg(pjfs) pjfs,project_id,station_id")
  3261. .between("record_date", beginOfYear, time0).groupBy("project_id,station_id");
  3262. List<TurbineInfoDay> yearDays = turbineInfoDayService.list(wrapper);
  3263. Map<String, TurbineInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  3264. QueryWrapper<ProEconReportIndicatorPool> wrapperRp = new QueryWrapper<>();
  3265. wrapperRp.eq("record_date", time0).last("and foreign_key_id = project_id");
  3266. List<ProEconReportIndicatorPool> poolsProject = reportIndicatorPoolService.list(wrapperRp);
  3267. wrapperRp = new QueryWrapper<>();
  3268. wrapperRp.eq("record_date", time0).last("and foreign_key_id = windpowerstation_id");
  3269. List<ProEconReportIndicatorPool> poolsStation = reportIndicatorPoolService.list(wrapperRp);
  3270. wrapperRp = new QueryWrapper<>();
  3271. wrapperRp.eq("record_date", time0).eq("foreign_key_id", "GJNY_SXGS_DBXNY_ZGS0");
  3272. ProEconReportIndicatorPool poolsCompany = reportIndicatorPoolService.getOne(wrapperRp);
  3273. TurbineInfoDay day, month, year;
  3274. String projectId;
  3275. if (poolsProject.isEmpty()) {
  3276. for (TurbineInfoDay infoDay : days) {
  3277. projectId = infoDay.getProjectId();
  3278. ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
  3279. pool.setRecordDate(time0);
  3280. pool.setForeignKeyId(projectId);
  3281. pool.setWindpowerstationId(infoDay.getStationId());
  3282. pool.setProjectId(projectId);
  3283. month = monthMap.get(projectId);
  3284. year = yearMap.get(projectId);
  3285. pool.setRpjfs(infoDay.getPjfs());
  3286. pool.setYpjfs(month.getPjfs());
  3287. pool.setNpjfs(year.getPjfs());
  3288. poolsProject.add(pool);
  3289. }
  3290. } else {
  3291. for (ProEconReportIndicatorPool pool : poolsProject) {
  3292. projectId = pool.getProjectId();
  3293. day = dayMap.get(projectId);
  3294. month = monthMap.get(projectId);
  3295. year = yearMap.get(projectId);
  3296. pool.setRpjfs(day.getPjfs());
  3297. pool.setYpjfs(month.getPjfs());
  3298. pool.setNpjfs(year.getPjfs());
  3299. }
  3300. }
  3301. reportIndicatorPoolService.saveOrUpdateBatch(poolsProject);
  3302. Map<String, List<ProEconReportIndicatorPool>> projectMap = poolsProject.stream().collect(Collectors.groupingBy(ProEconReportIndicatorPool::getWindpowerstationId));
  3303. if (poolsStation.isEmpty()) {
  3304. projectMap.forEach((StId, pis) -> {
  3305. ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
  3306. pool.setRecordDate(time0);
  3307. pool.setForeignKeyId(StId);
  3308. pool.setWindpowerstationId(StId);
  3309. ProEconReportIndicatorPool p = sumProperties(pis, ProEconReportIndicatorPool.class);
  3310. pool.setRpjfs(p.getRpjfs() / pis.size());
  3311. pool.setYpjfs(p.getYpjfs() / pis.size());
  3312. pool.setNpjfs(p.getNpjfs() / pis.size());
  3313. poolsStation.add(pool);
  3314. });
  3315. } else {
  3316. for (ProEconReportIndicatorPool pool : poolsStation) {
  3317. List<ProEconReportIndicatorPool> pools = projectMap.get(pool.getWindpowerstationId());
  3318. ProEconReportIndicatorPool p = sumProperties(pools, ProEconReportIndicatorPool.class);
  3319. pool.setRpjfs(p.getRpjfs() / pools.size());
  3320. pool.setYpjfs(p.getYpjfs() / pools.size());
  3321. pool.setNpjfs(p.getNpjfs() / pools.size());
  3322. }
  3323. }
  3324. reportIndicatorPoolService.saveOrUpdateBatch(poolsStation);
  3325. if (poolsCompany == null) {
  3326. poolsCompany = new ProEconReportIndicatorPool();
  3327. poolsCompany.setRecordDate(time0);
  3328. poolsCompany.setForeignKeyId("GJNY_SXGS_DBXNY_ZGS0");
  3329. poolsCompany.setCompanyId("GJNY_SXGS_DBXNY_ZGS");
  3330. ProEconReportIndicatorPool p = sumProperties(poolsStation, ProEconReportIndicatorPool.class);
  3331. poolsCompany.setRpjfs(p.getRpjfs() / poolsStation.size());
  3332. poolsCompany.setYpjfs(p.getYpjfs() / poolsStation.size());
  3333. poolsCompany.setNpjfs(p.getNpjfs() / poolsStation.size());
  3334. } else {
  3335. ProEconReportIndicatorPool p = sumProperties(poolsStation, ProEconReportIndicatorPool.class);
  3336. poolsCompany.setRpjfs(p.getRpjfs() / poolsStation.size());
  3337. poolsCompany.setYpjfs(p.getYpjfs() / poolsStation.size());
  3338. poolsCompany.setNpjfs(p.getNpjfs() / poolsStation.size());
  3339. }
  3340. reportIndicatorPoolService.saveOrUpdate(poolsCompany);
  3341. }
  3342. public void poolSetValue1(ProEconReportIndicatorPool pool, TurbineInfoDay day, TurbineInfoDay month, TurbineInfoDay year) {
  3343. pool.setRpjfs(day.getPjfs());
  3344. pool.setRgzssdl(day.getGzss() == null ? day.getFjhjxss() * 0.11 : day.getGzss());
  3345. pool.setRjxssdl(day.getJhjxss());
  3346. pool.setRdjssdl(day.getDjss() == null ? day.getFjhjxss() * 0.89 : day.getDjss());
  3347. pool.setRxnssdl(day.getXnss());
  3348. pool.setRxdjclssdl(day.getXdss());
  3349. pool.setRllfdl(day.getLlfdl());
  3350. pool.setRhjdjxs(day.getDjMin() / 60);
  3351. pool.setRhjgztjxs(day.getGzMin() / 60);
  3352. pool.setRhjtxzdxs(day.getLxMin() / 60);
  3353. pool.setRhjjxtjxs(day.getJxMin() / 60);
  3354. pool.setRhjxdxs(day.getXdMin() / 60);
  3355. pool.setRhjyxxs(day.getYxMin() / 60);
  3356. pool.setRhjslxs(0.0);
  3357. pool.setYpjfs(month.getPjfs());
  3358. pool.setYgzssdl(month.getGzss() == null ? month.getFjhjxss() * 0.11 : month.getGzss());
  3359. pool.setYjxssdl(month.getJhjxss());
  3360. pool.setYdjssdl(month.getDjss() == null ? month.getFjhjxss() * 0.89 : month.getDjss());
  3361. pool.setYxnssdl(month.getXnss());
  3362. pool.setYxdjclssdl(month.getXdss());
  3363. pool.setYllfdl(month.getLlfdl());
  3364. pool.setYhjdjxs(month.getDjMin() / 60);
  3365. pool.setYhjgztjxs(month.getGzMin() / 60);
  3366. pool.setYhjtxzdxs(month.getLxMin() / 60);
  3367. pool.setYhjjxtjxs(month.getJxMin() / 60);
  3368. pool.setYhjxdxs(month.getXdMin() / 60);
  3369. pool.setYhjyxxs(month.getYxMin() / 60);
  3370. pool.setYhjslxs(0.0);
  3371. pool.setNpjfs(year.getPjfs());
  3372. pool.setNgzssdl(year.getGzss() == null ? year.getFjhjxss() * 0.11 : year.getGzss());
  3373. pool.setNjxssdl(year.getJhjxss());
  3374. pool.setNdjssdl(year.getDjss() == null ? year.getFjhjxss() * 0.89 : year.getDjss());
  3375. pool.setNxnssdl(year.getXnss());
  3376. pool.setNxdjclssdl(year.getXdss());
  3377. pool.setNllfdl(year.getLlfdl());
  3378. pool.setNhjdjxs(year.getDjMin() / 60);
  3379. pool.setNhjgztjxs(year.getGzMin() / 60);
  3380. pool.setNhjtxzdxs(year.getLxMin() / 60);
  3381. pool.setNhjjxtjxs(year.getJxMin() / 60);
  3382. pool.setNhjxdxs(year.getXdMin() / 60);
  3383. pool.setNhjyxxs(year.getYxMin() / 60);
  3384. pool.setNhjslxs(0.0);
  3385. }
  3386. public void poolSetValue(ProEconReportIndicatorPool pool, List<ProEconReportIndicatorPool> pools) {
  3387. ProEconReportIndicatorPool p = sumProperties(pools, ProEconReportIndicatorPool.class);
  3388. pool.setRpjfs(p.getRpjfs() / pools.size());
  3389. pool.setRgzssdl(p.getRgzssdl());
  3390. pool.setRjxssdl(p.getRjxssdl());
  3391. pool.setRdjssdl(p.getRdjssdl());
  3392. pool.setRxnssdl(p.getRxnssdl());
  3393. pool.setRxdjclssdl(p.getRxdjclssdl());
  3394. pool.setRllfdl(p.getRllfdl());
  3395. pool.setRhjdjxs(p.getRhjdjxs());
  3396. pool.setRhjgztjxs(p.getRhjgztjxs());
  3397. pool.setRhjtxzdxs(p.getRhjtxzdxs());
  3398. pool.setRhjjxtjxs(p.getRhjjxtjxs());
  3399. pool.setRhjxdxs(p.getRhjxdxs());
  3400. pool.setRhjyxxs(p.getRhjyxxs());
  3401. pool.setRhjslxs(0.0);
  3402. pool.setYpjfs(p.getYpjfs() / pools.size());
  3403. pool.setYgzssdl(p.getYgzssdl());
  3404. pool.setYjxssdl(p.getYjxssdl());
  3405. pool.setYdjssdl(p.getYdjssdl());
  3406. pool.setYxnssdl(p.getYxnssdl());
  3407. pool.setYxdjclssdl(p.getYxdjclssdl());
  3408. pool.setYllfdl(p.getYllfdl());
  3409. pool.setYhjdjxs(p.getYhjdjxs());
  3410. pool.setYhjgztjxs(p.getYhjgztjxs());
  3411. pool.setYhjtxzdxs(p.getYhjtxzdxs());
  3412. pool.setYhjjxtjxs(p.getYhjjxtjxs());
  3413. pool.setYhjxdxs(p.getYhjxdxs());
  3414. pool.setYhjyxxs(p.getYhjyxxs());
  3415. pool.setYhjslxs(0.0);
  3416. pool.setNpjfs(p.getNpjfs() / pools.size());
  3417. pool.setNgzssdl(p.getNgzssdl());
  3418. pool.setNjxssdl(p.getNjxssdl());
  3419. pool.setNdjssdl(p.getNdjssdl());
  3420. pool.setNxnssdl(p.getNxnssdl());
  3421. pool.setNxdjclssdl(p.getNxdjclssdl());
  3422. pool.setNllfdl(p.getNllfdl());
  3423. pool.setNhjdjxs(p.getNhjdjxs());
  3424. pool.setNhjgztjxs(p.getNhjgztjxs());
  3425. pool.setNhjtxzdxs(p.getNhjtxzdxs());
  3426. pool.setNhjjxtjxs(p.getNhjjxtjxs());
  3427. pool.setNhjxdxs(p.getNhjxdxs());
  3428. pool.setNhjyxxs(p.getNhjyxxs());
  3429. pool.setNhjslxs(0.0);
  3430. }
  3431. public <T> T sumProperties(List<T> list, Class<T> clazz) {
  3432. T result;
  3433. try {
  3434. result = clazz.getDeclaredConstructor().newInstance();
  3435. } catch (Exception e) {
  3436. e.printStackTrace();
  3437. return null;
  3438. }
  3439. if (list == null || list.isEmpty()) return result;
  3440. // 获取所有字段
  3441. Field[] fields = clazz.getDeclaredFields();
  3442. for (Field field : fields) {
  3443. field.setAccessible(true); // 确保私有字段也可以被访问
  3444. // 检查字段类型是否为Double
  3445. Class<?> type = field.getType();
  3446. if (type.equals(Double.class) || type.equals(Integer.class) || type.equals(Long.class) || type.equals(Float.class)) {
  3447. double sum = 0.0;
  3448. // 遍历列表中的每个对象并累加数值字段
  3449. try {
  3450. for (T item : list) {
  3451. Field itemField = clazz.getDeclaredField(field.getName());
  3452. itemField.setAccessible(true);
  3453. // 尝试获取当前对象的字段值
  3454. Double value = (Double) itemField.get(item); // 注意类型转换
  3455. if (value != null) sum += value;
  3456. }
  3457. // 设置累加后的值到结果对象中
  3458. if (type.equals(Double.class)) {
  3459. field.set(result, sum);
  3460. } else if (type.equals(Integer.class)) {
  3461. field.set(result, (int) sum);
  3462. } else if (type.equals(Long.class)) {
  3463. field.set(result, (long) sum);
  3464. } else {
  3465. field.set(result, (float) sum);
  3466. }
  3467. } catch (Exception e) {
  3468. e.printStackTrace();
  3469. return result;
  3470. }
  3471. }
  3472. }
  3473. return result;
  3474. }
  3475. private ProEconReportIndicatorPool getPoolSum(List<ProEconReportIndicatorPool> pools) {
  3476. ProEconReportIndicatorPool pool0 = new ProEconReportIndicatorPool();
  3477. for (ProEconReportIndicatorPool pool : pools) {
  3478. pool0.setRfdldb(nullSum(pool0.getRfdldb(), pool.getRfdldb()));
  3479. pool0.setRswdldb(nullSum(pool0.getRswdldb(), pool.getRswdldb()));
  3480. pool0.setRgwgwdldb(nullSum(pool0.getRgwgwdldb(), pool.getRgwgwdldb()));
  3481. pool0.setRnwgwdldb(nullSum(pool0.getRnwgwdldb(), pool.getRnwgwdldb()));
  3482. }
  3483. return pool0;
  3484. }
  3485. public double nullSum(Double a, Double b) {
  3486. if (a == null) a = 0.0;
  3487. if (b == null) b = 0.0;
  3488. return a + b;
  3489. }
  3490. public double calcQfzt(Double ssgl, Double zsgl) {
  3491. if (ssgl == null || ssgl < 0) ssgl = 0.0;
  3492. double qfzt, ratioll;
  3493. ratioll = (zsgl == null || zsgl <= 0) ? 0 : (zsgl - ssgl) / zsgl;
  3494. if (ratioll < 0.05) {
  3495. qfzt = 0;
  3496. } else if (ratioll < 0.1) {
  3497. qfzt = 1;
  3498. } else if (ratioll < 0.2) {
  3499. qfzt = 2;
  3500. } else if (ratioll < 0.4) {
  3501. qfzt = 3;
  3502. } else {
  3503. qfzt = 4;
  3504. }
  3505. return qfzt;
  3506. }
  3507. public List<TurbineInfoMin> getTurbineinfoByMin(Date date) {
  3508. QueryWrapper<TurbineInfoMin> wrapper = new QueryWrapper<>();
  3509. wrapper.eq("record_date", date);
  3510. return turbineInfoMinService.list(wrapper);
  3511. }
  3512. public List<TurbineInfoMin> getTurbineinfoByMin(Date date, List<PointInfo> entity) {
  3513. List<TurbineInfoMin> list = getTurbineinfoByMin(date);
  3514. if (list.isEmpty()) {
  3515. entity.forEach(pi -> {
  3516. TurbineInfoMin day = new TurbineInfoMin();
  3517. day.setStationId(pi.getStationId());
  3518. day.setProjectId(pi.getProjectId());
  3519. day.setLineId(pi.getLineId());
  3520. day.setTurbineId(pi.getTurbineId());
  3521. day.setRecordDate(date);
  3522. list.add(day);
  3523. });
  3524. }
  3525. return list;
  3526. }
  3527. public Map<String, TurbineInfoMin> getTurbineinfoByMinMap(Date date) {
  3528. List<TurbineInfoMin> tims = getTurbineinfoByMin(date);
  3529. return tims.stream().collect(Collectors.toMap(TurbineInfoMin::getTurbineId, Function.identity()));
  3530. }
  3531. public Map<String, TurbineInfoMin> getTurbineinfoByMinMap(Date date, List<PointInfo> entity) {
  3532. List<TurbineInfoMin> tims = getTurbineinfoByMin(date, entity);
  3533. return tims.stream().collect(Collectors.toMap(TurbineInfoMin::getTurbineId, Function.identity()));
  3534. }
  3535. public Map<String, PointInfo> getRawDataByEntity(List<PointInfo> entity, URI uri, Date start, Date end, Function<PointInfo, String> function) {
  3536. getRawDataByEntity(entity, uri, start, end);
  3537. return entity.stream().collect(Collectors.toMap(function, Function.identity()));
  3538. }
  3539. public void calcTurbinePjfsPjglKyglLlglMin(Date date, int granularity) {
  3540. date = DateUtil.beginOfMinute(date);
  3541. DateTime start = DateUtil.offsetMinute(date, -granularity);
  3542. //风速
  3543. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  3544. Map<String, PointInfo> rawMapFs = getRawDataByEntity(entityFs, goldenUri(), start, date, PointInfo::getTurbineId);
  3545. //功率
  3546. List<PointInfo> entityGl = getEntity("AI114", "turbine");
  3547. Map<String, PointInfo> rawMapGl = getRawDataByEntity(entityGl, goldenUri(), start, date, PointInfo::getTurbineId);
  3548. List<PointInfo> entityZt = getEntity("MXZT", "turbine");
  3549. Map<String, PointInfo> rawMapZt = getRawDataByEntity(entityZt, goldenUri(), start, date, PointInfo::getTurbineId);
  3550. List<TurbineInfoMin> mins = getTurbineinfoByMin(date, entityFs);
  3551. for (TurbineInfoMin min : mins) {
  3552. String tbId = min.getTurbineId();
  3553. List<PointData> fsDatas = rawMapFs.get(tbId).getPointDatas();
  3554. List<PointData> ztDatas = rawMapZt.get(tbId).getPointDatas();
  3555. ztDatas = doublePointDatasFull(2, ztDatas, start.getTime(), date.getTime(), 1);
  3556. Map<Long, Double> ztMap = ztDatas.stream().collect(Collectors.toMap(PointData::getTs, PointData::getValue));
  3557. double pjfs = fsDatas.stream().mapToDouble(PointData::getValue).average().orElse(0.0);
  3558. fsDatas.stream().peek(pd -> pd.setDoubleValue(pd.getValue() > 25 ? 25 : pd.getValue() < 0 ? 0 : NumberUtil.round(pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
  3559. double llgl = fsDatas.stream().mapToDouble(pd -> pd.getValue() < 3 ? 0d : CalcCache.llgl.get(tbId).get(pd.getValue())).average().orElse(0.0);
  3560. double kygl = fsDatas.stream().filter(pd -> ztMap.get(pd.getTs()) != 4 || ztMap.get(pd.getTs()) != 6)
  3561. .mapToDouble(pd -> CalcCache.fitcoef.get(tbId).get(pd.getValue())).average().orElse(0.0);
  3562. double sjgl = rawMapGl.get(tbId).getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0);
  3563. double v = llgl * 0.9;
  3564. if (kygl > v) kygl = v;
  3565. if (kygl < sjgl) kygl = sjgl;
  3566. if (llgl < sjgl) llgl = sjgl * 1.0005;
  3567. min.setPjfs(pjfs);
  3568. min.setPjgl(sjgl);
  3569. min.setLlgl(llgl);
  3570. min.setKygl(kygl);
  3571. }
  3572. turbineInfoMinService.saveOrUpdateBatch(mins);
  3573. }
  3574. public void calcStationRealtimeLLgl() {
  3575. DateTime end = DateUtil.date();
  3576. DateTime date = DateUtil.offsetMinute(end, -5);
  3577. Map<String, String> sszllglMap = getEntityMap("SSZLLGL", "station");
  3578. //出线
  3579. List<PointInfo> entityCx = getEntity("AGC001", "booster");
  3580. getLatestByEntity(entityCx);
  3581. //风速
  3582. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  3583. getRawDataByEntity(entityFs, goldenUri(), date, end);
  3584. for (PointInfo fsPi : entityFs) {
  3585. List<PointData> pds = fsPi.getPointDatas();
  3586. Double pd = pds.stream().mapToDouble(PointData::getValue).average().orElse(0);
  3587. double fs = pd > 25 ? 25 : pd < 0 ? 0 : NumberUtil.round(pd, 2).doubleValue();
  3588. double llgl = fs < 3 ? 0d : CalcCache.llgl.get(fsPi.getTurbineId()).get(fs);
  3589. fsPi.setSpare2(llgl);
  3590. }
  3591. Map<String, List<PointInfo>> stPisMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  3592. List<PointData> pds = new ArrayList<>();
  3593. for (PointInfo cx : entityCx) {
  3594. PointData pdCx = cx.getPointDatas().get(0);
  3595. double sjgl = pdCx.getValue() * cx.getCoef();
  3596. double llgl = stPisMap.get(cx.getStationId()).stream().mapToDouble(pi -> pi.getSpare2()).sum();
  3597. if (pdCx.getTs() + 10 * 60 * 1000 > end.getTime()) {
  3598. if (llgl < sjgl) llgl = sjgl * 1.0005;
  3599. if (llgl > sjgl * 1.5) llgl = sjgl * 1.5;
  3600. } else {
  3601. System.out.println("实际功率测点离线");
  3602. }
  3603. PointData data = new PointData();
  3604. data.setTs(System.currentTimeMillis());
  3605. data.setTagName(sszllglMap.get(cx.getStationId()));
  3606. data.setDoubleValue(llgl);
  3607. pds.add(data);
  3608. }
  3609. adapter.writeHistoryBatch(taosUri(), pds);
  3610. }
  3611. public void calcTurbineSsfsQx(Date date) {
  3612. DateTime date0 = DateUtil.beginOfDay(date);
  3613. DateTime date1 = DateUtil.endOfDay(date);
  3614. //风速
  3615. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  3616. List<String> fjs = Arrays.asList("GJNY_SXGS_FSG_F_WT_0040_EQ", "GJNY_SXGS_FSG_F_WT_0047_EQ");
  3617. entityFs = entityFs.stream().filter(e -> fjs.contains(e.getTurbineId())).collect(Collectors.toList());
  3618. getSnapDataByEntity(entityFs, date0, date1, 60);
  3619. int i = 0;
  3620. for (PointInfo et : entityFs) {
  3621. StrBuilder sb = new StrBuilder();
  3622. StrBuilder sb1 = new StrBuilder();
  3623. for (PointData v : et.getPointDatas()) {
  3624. sb.append(v.getValue()).append(",");
  3625. sb1.append(i).append(",");
  3626. i++;
  3627. }
  3628. System.out.println(sb1);
  3629. System.out.println(sb);
  3630. }
  3631. }
  3632. public void calcStationLlglKyglSjglAgcMin(Date date, int granularity) {
  3633. date = DateUtil.beginOfMinute(date);
  3634. DateTime start = DateUtil.offsetMinute(date, -granularity);
  3635. //AGC
  3636. List<PointInfo> entityAgc = getEntity("AGC002", "booster");
  3637. Map<String, PointInfo> statMapAgc = getStatDataByEntity(entityAgc, goldenUri(), start, date, PointInfo::getStationId);
  3638. //出线
  3639. List<PointInfo> entityCx = getEntity("AGC001", "booster");
  3640. Map<String, PointInfo> statMapCx = getStatDataByEntity(entityCx, goldenUri(), start, date, PointInfo::getStationId);
  3641. QueryWrapper<TurbineInfoMin> wrapper = new QueryWrapper<>();
  3642. wrapper.select("sum(llgl) llgl,sum(kygl) kygl,avg(pjfs) pjfs,station_id").eq("record_date", date).groupBy("station_id");
  3643. List<TurbineInfoMin> list = turbineInfoMinService.list(wrapper);
  3644. Map<String, TurbineInfoMin> minMap = list.stream().collect(Collectors.toMap(TurbineInfoMin::getStationId, Function.identity()));
  3645. List<StationInfoMin> byDate = getStationinfoByMin(date, entityAgc);
  3646. for (StationInfoMin day : byDate) {
  3647. String stId = day.getStationId();
  3648. TurbineInfoMin min = minMap.get(stId);
  3649. PointInfo agcInfo = statMapAgc.get(stId);
  3650. PointInfo cxInfo = statMapCx.get(stId);
  3651. day.setLlgl(min.getLlgl());
  3652. day.setKygl(min.getKygl());
  3653. day.setAgc(agcInfo.getPointDatas().get(0).getValue() * agcInfo.getCoef());
  3654. day.setPjgl(cxInfo.getPointDatas().get(0).getValue() * cxInfo.getCoef());
  3655. day.setPjfs(min.getPjfs());
  3656. }
  3657. stationInfoMinService.saveOrUpdateBatch(byDate);
  3658. }
  3659. public void calcStationSjglAgcPjfsHjwdDlMin(Date begin, Date end, String stId) {
  3660. //AGC
  3661. List<PointInfo> entityAgc = getEntity("AGC002", "booster");
  3662. entityAgc = entityAgc.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
  3663. Map<String, PointInfo> statMapAgc = getRawDataByEntity(entityAgc, goldenUri(), begin, end, PointInfo::getStationId);
  3664. //出线
  3665. List<PointInfo> entityCx = getEntity("AGC001", "booster");
  3666. entityCx = entityCx.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
  3667. Map<String, PointInfo> statMapCx = getRawDataByEntity(entityCx, goldenUri(), begin, end, PointInfo::getStationId);
  3668. //风速
  3669. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  3670. entityFs = entityFs.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
  3671. getRawDataByEntity(entityFs, goldenUri(), begin, end);
  3672. Map<String, List<PointInfo>> fssMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  3673. //环境温度
  3674. List<PointInfo> entityHjwd = getEntity("AI072", "turbine");
  3675. entityHjwd = entityHjwd.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
  3676. getRawDataByEntity(entityHjwd, goldenUri(), begin, end);
  3677. Map<String, List<PointInfo>> hjwdsMap = entityHjwd.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  3678. //日发电量
  3679. List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
  3680. entity = entity.stream().filter(e -> !"".equals(e.getProjectId()) && stId.equals(e.getStationId())).collect(Collectors.toList());
  3681. getSectionDataByEntity(entity, goldenUri(), begin, end);
  3682. Map<String, List<PointInfo>> fdlsMap = entity.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  3683. List<StationInfoMin> byDate = getStationinfoByMin(end, entityAgc);
  3684. for (StationInfoMin day : byDate) {
  3685. String id = day.getStationId();
  3686. PointInfo agcInfo = statMapAgc.get(id);
  3687. PointInfo cxInfo = statMapCx.get(id);
  3688. List<PointInfo> fsInfos = fssMap.get(id);
  3689. double pjfs = fsInfos.stream().mapToDouble(pi -> pi.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0)).average().orElse(0);
  3690. List<PointInfo> hjwdInfos = hjwdsMap.get(id);
  3691. double hjwd = hjwdInfos.stream().mapToDouble(pi -> pi.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0)).average().orElse(0);
  3692. List<PointInfo> fdlInfos = fdlsMap.get(id);
  3693. double rfdl = fdlInfos.stream().mapToDouble(pi -> {
  3694. double v = (pi.getPointDatas().get(1).getValue() - pi.getPointDatas().get(0).getValue()) * pi.getCoef();
  3695. if (v < 0 || v > 720000) v = 0;
  3696. return v;
  3697. }).sum();
  3698. double agc = agcInfo.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0);
  3699. double cxgl = cxInfo.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0);
  3700. day.setAgc(agc * agcInfo.getCoef());
  3701. day.setPjgl(cxgl * cxInfo.getCoef());
  3702. day.setPjfs(pjfs);
  3703. day.setRfdl(rfdl);
  3704. day.setHjwd(hjwd);
  3705. }
  3706. stationInfoMinService.saveOrUpdateBatch(byDate);
  3707. }
  3708. public void calcPredictExamin(Date date) {
  3709. DateTime end = DateUtil.beginOfDay(date);
  3710. DateTime begin = DateUtil.offsetDay(end, -1);
  3711. List<PointInfo> entity = getEntity("MX000", "state");
  3712. List<PointInfo> entity1 = getEntity("AI422", "state");
  3713. entity.addAll(entity1);
  3714. Map<String, EquipmentModel> map = equipmentModelService.map();
  3715. Map<String, Double> tbPowerMap = entity.stream().collect(Collectors.toMap(pi -> pi.getTurbineId(), pi -> map.get(pi.getTurbineId()).getPowerProduction()));
  3716. List<PointInfo> entityGl = getEntity("AI114", "turbine");
  3717. getSnapDataByEntity(entityGl, begin, end, 15 * 60);
  3718. Map<String, PointInfo> glpisMap = entityGl.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  3719. QueryWrapper<HistoryPredict> predictWrapper = new QueryWrapper<>();
  3720. predictWrapper.lambda().eq(HistoryPredict::getPredictType, "CDQ").eq(HistoryPredict::getDataTime, begin)
  3721. .orderByAsc(HistoryPredict::getDataTime);
  3722. List<HistoryPredict> predictList = historyPredictService.list(predictWrapper);
  3723. Map<String, List<HistoryPredict>> predictsMap = predictList.stream().collect(Collectors.groupingBy(HistoryPredict::getTurbineId));
  3724. //超短期
  3725. List<HistoryPredict> cdqPredicts = new ArrayList<>();
  3726. predictsMap.forEach((stId, hps) -> {
  3727. cdqPredicts.addAll(hps.subList(0, 16));
  3728. });
  3729. for (int i = 1; i < 6; i++) {
  3730. DateTime hour = DateUtil.offsetHour(begin, 4 * i);
  3731. DateTime hour2 = DateUtil.offsetHour(hour, 4);
  3732. QueryWrapper<HistoryPredict> wrapper = new QueryWrapper<>();
  3733. wrapper.lambda().eq(HistoryPredict::getPredictType, "CDQ").eq(HistoryPredict::getDataTime, hour)
  3734. .between(HistoryPredict::getPredictTime, hour, hour2).orderByAsc(HistoryPredict::getDataTime);
  3735. List<HistoryPredict> predicts = historyPredictService.list(predictWrapper);
  3736. cdqPredicts.addAll(predicts);
  3737. }
  3738. Map<String, List<HistoryPredict>> cdqPredictsMap = cdqPredicts.stream().collect(Collectors.groupingBy(HistoryPredict::getTurbineId));
  3739. List<PredictExamin> peList = new ArrayList<>();
  3740. predictsMap.forEach((stId, hps) -> {
  3741. List<Double> predictPower = hps.stream().map(HistoryPredict::getPredictPower).collect(Collectors.toList());
  3742. List<Double> actualPower = glpisMap.get(stId).getPointDatas().stream().map(PointData::getValue).collect(Collectors.toList());
  3743. Double installCapacity = tbPowerMap.get(stId);
  3744. HistoryPredict predict = hps.get(0);
  3745. PredictExamin examin = new PredictExamin();
  3746. examin.setModelId(predict.getModelId());
  3747. examin.setPredictType("DQ");
  3748. examin.setDeviceType(predict.getDeviceType());
  3749. examin.setTime(begin);
  3750. examin.setSiteId(predict.getSiteId());
  3751. examin.setPeriodId(predict.getPeriodId());
  3752. examin.setLineId(predict.getLineId());
  3753. examin.setTurbineId(predict.getTurbineId());
  3754. examin.setExaminScore(calcExaminScore(predictPower, actualPower, installCapacity));
  3755. examin.setAccuracyRate(calcAccuracyRate(predictPower, actualPower, installCapacity));
  3756. peList.add(examin);
  3757. //超短期
  3758. List<Double> predictPowerCdq = cdqPredictsMap.get(stId).stream().map(HistoryPredict::getPredictPower).collect(Collectors.toList());
  3759. PredictExamin e = new PredictExamin();
  3760. e.setModelId(predict.getModelId());
  3761. e.setPredictType("CDQ");
  3762. e.setDeviceType(predict.getDeviceType());
  3763. e.setTime(begin);
  3764. e.setSiteId(predict.getSiteId());
  3765. e.setPeriodId(predict.getPeriodId());
  3766. e.setLineId(predict.getLineId());
  3767. e.setTurbineId(predict.getTurbineId());
  3768. e.setExaminScore(calcExaminScore(predictPowerCdq, actualPower, installCapacity));
  3769. e.setAccuracyRate(calcAccuracyRate(predictPowerCdq, actualPower, installCapacity));
  3770. peList.add(e);
  3771. });
  3772. predictExaminService.saveBatch(peList);
  3773. }
  3774. /**
  3775. * 计算功率日预测曲线最大误差值
  3776. *
  3777. * @param predictPower 96个点的预测功率值
  3778. * @param actualPower 96个点的实际功率值
  3779. * @param installCapacity 装机容量
  3780. * @return 结果
  3781. */
  3782. public double calcExaminScore(List<Double> predictPower, List<Double> actualPower, Double installCapacity) {
  3783. if (CollUtil.isEmpty(predictPower) || CollUtil.isEmpty(actualPower) || installCapacity == null) return 0;
  3784. int n = predictPower.size();
  3785. if (n != actualPower.size()) return 0;
  3786. double maxErrorPercentage = 0.0;
  3787. for (int i = 0; i < n; i++) {
  3788. double errorPercentage = 0.0;
  3789. if (predictPower.get(i) == 0) {
  3790. if (Math.abs(actualPower.get(i)) <= 0.03 * installCapacity) {
  3791. continue; // 不考核
  3792. } else {
  3793. errorPercentage = 100.0;
  3794. }
  3795. } else {
  3796. errorPercentage = Math.abs(predictPower.get(i) - actualPower.get(i)) / predictPower.get(i) * 100;
  3797. }
  3798. if (errorPercentage > maxErrorPercentage) {
  3799. maxErrorPercentage = errorPercentage;
  3800. }
  3801. }
  3802. return maxErrorPercentage;
  3803. }
  3804. /**
  3805. * 计算功率超短期预测曲线准确率
  3806. *
  3807. * @param predictPower 96个点的预测功率值
  3808. * @param actualPower 96个点的实际功率值
  3809. * @param installCapacity 装机容量
  3810. * @return 结果
  3811. */
  3812. public double calcAccuracyRate(List<Double> predictPower, List<Double> actualPower, Double installCapacity) {
  3813. if (CollUtil.isEmpty(predictPower) || CollUtil.isEmpty(actualPower) || installCapacity == null) return 0;
  3814. int n = predictPower.size();
  3815. if (n != actualPower.size()) return 0;
  3816. double totalError = 0.0;
  3817. int validPoints = 0;
  3818. for (int i = 0; i < n; i++) {
  3819. double errorPercentage = 0.0;
  3820. if (Math.abs(predictPower.get(i) - actualPower.get(i)) <= 0.03 * installCapacity) {
  3821. // 该点不计入误差计算
  3822. continue;
  3823. }
  3824. errorPercentage = Math.abs(predictPower.get(i) - actualPower.get(i)) / installCapacity * 100;
  3825. totalError += errorPercentage;
  3826. validPoints++;
  3827. }
  3828. if (validPoints == 0) {
  3829. return 100.0; // 所有点均在3%以内,准确率为100%
  3830. } else {
  3831. return 100 - totalError / validPoints;
  3832. }
  3833. }
  3834. }