JavaFunctionJobHandler.java 273 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730
  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.DateRange;
  5. import cn.hutool.core.date.DateTime;
  6. import cn.hutool.core.date.DateUtil;
  7. import cn.hutool.core.text.StrBuilder;
  8. import cn.hutool.core.thread.ThreadUtil;
  9. import cn.hutool.core.util.NumberUtil;
  10. import cn.hutool.core.util.StrUtil;
  11. import com.alibaba.fastjson2.JSON;
  12. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  13. import com.ruoyi.quartz.handler.IJobHandler;
  14. import com.ruoyi.ucp.entity.*;
  15. import com.ruoyi.ucp.feign.AdapterApi;
  16. import com.ruoyi.ucp.service.*;
  17. import com.ruoyi.ucp.util.CalcCache;
  18. import org.apache.commons.math3.fitting.PolynomialCurveFitter;
  19. import org.apache.commons.math3.fitting.WeightedObservedPoints;
  20. import org.springframework.data.redis.core.StringRedisTemplate;
  21. import org.springframework.stereotype.Service;
  22. import javax.annotation.Resource;
  23. import java.lang.reflect.Field;
  24. import java.lang.reflect.Method;
  25. import java.net.URI;
  26. import java.util.*;
  27. import java.util.concurrent.ConcurrentHashMap;
  28. import java.util.concurrent.atomic.AtomicReference;
  29. import java.util.function.Function;
  30. import java.util.stream.Collectors;
  31. @Service
  32. public class JavaFunctionJobHandler extends IJobHandler {
  33. @Resource
  34. private AdapterApi adapter;
  35. @Resource
  36. private IPointInfoService pointService;
  37. @Resource
  38. private IStationInfoHourService stationInfoHourService;
  39. @Resource
  40. private IStationInfoDayService stationInfoDayService;
  41. @Resource
  42. private ILineInfoDayService lineInfoDayService;
  43. @Resource
  44. private IStateAiService stateAiService;
  45. @Resource
  46. private StringRedisTemplate stringRedisTemplate;
  47. @Resource
  48. private IEquipmentModelService equipmentModelService;
  49. @Resource
  50. private ITurbineInfoDayService turbineInfoDayService;
  51. @Resource
  52. private IProEconReportIndicatorPoolService reportIndicatorPoolService;
  53. @Resource
  54. private ITurbineInfoMinService turbineInfoMinService;
  55. @Resource
  56. private IStationInfoMinService stationInfoMinService;
  57. @Resource
  58. private IProBasicProjectPlanService proBasicProjectPlanService;
  59. @Resource
  60. private IHistoryPredictService historyPredictService;
  61. @Resource
  62. private IPredictExaminService predictExaminService;
  63. @Resource
  64. private IStationInfoMin2Service stationInfoMin2Service;
  65. @Resource
  66. private IProjectInfoMin2Service projectInfoMin2Service;
  67. @Resource
  68. private IRealtimePredictService realtimePredictService;
  69. @Override
  70. public void execute() throws Exception {
  71. }
  72. @Override
  73. public IJobHandler getFunctionHandler() {
  74. return null;
  75. }
  76. @Override
  77. public void setFunctionHandler(IJobHandler jobHandler) {
  78. }
  79. public URI taosGoldenUriTest() {
  80. return URI.create("http://127.0.0.1:8011/ts");
  81. }
  82. public String pointInfos2Keys(List<PointInfo> entity) {
  83. return entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
  84. }
  85. public List<StationInfoHour> getStationinfoByHour(Date hour) {
  86. QueryWrapper<StationInfoHour> wrapper = new QueryWrapper<>();
  87. wrapper.eq("record_date", hour);
  88. return stationInfoHourService.list(wrapper);
  89. }
  90. public List<StationInfoHour> getStationinfoByHour(Date hour, List<PointInfo> entity) {
  91. List<StationInfoHour> byDate = getStationinfoByHour(hour);
  92. if (CollUtil.isEmpty(byDate)) {
  93. entity.forEach(pi -> {
  94. StationInfoHour day = new StationInfoHour();
  95. day.setStationId(pi.getStationId());
  96. day.setRecordDate(hour);
  97. byDate.add(day);
  98. });
  99. }
  100. return byDate;
  101. }
  102. public List<StationInfoDay> getStationinfoByDate(Date date) {
  103. QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
  104. wrapper.eq("record_date", date);
  105. return stationInfoDayService.list(wrapper);
  106. }
  107. public List<StationInfoMin> getStationinfoByMin(Date date) {
  108. QueryWrapper<StationInfoMin> wrapper = new QueryWrapper<>();
  109. wrapper.eq("record_date", date);
  110. return stationInfoMinService.list(wrapper);
  111. }
  112. public List<StationInfoMin> getStationinfoByMin(Date date, List<PointInfo> entity) {
  113. List<StationInfoMin> byDate = getStationinfoByMin(date);
  114. if (CollUtil.isEmpty(byDate)) {
  115. entity.forEach(pi -> {
  116. StationInfoMin day = new StationInfoMin();
  117. day.setStationId(pi.getStationId());
  118. day.setRecordDate(date);
  119. byDate.add(day);
  120. });
  121. }
  122. return byDate;
  123. }
  124. public List<StationInfoMin> getStationinfoByMin(Date date, String stId) {
  125. QueryWrapper<StationInfoMin> wrapper = new QueryWrapper<>();
  126. wrapper.eq("record_date", date).eq("station_id", stId);
  127. List<StationInfoMin> list = stationInfoMinService.list(wrapper);
  128. if (CollUtil.isEmpty(list)) {
  129. StationInfoMin day = new StationInfoMin();
  130. day.setStationId(stId);
  131. day.setRecordDate(date);
  132. list.add(day);
  133. }
  134. return list;
  135. }
  136. public StationInfoMin2 getStationinfoByMin2(Date date, String stId) {
  137. QueryWrapper<StationInfoMin2> wrapper = new QueryWrapper<>();
  138. wrapper.eq("record_date", date).eq("station_id", stId);
  139. StationInfoMin2 list = stationInfoMin2Service.getOne(wrapper, false);
  140. if (list == null) {
  141. list = new StationInfoMin2();
  142. list.setStationId(stId);
  143. list.setRecordDate(date);
  144. }
  145. return list;
  146. }
  147. public StationInfoMin getStationinfoByMinOne(Date date, String stId) {
  148. QueryWrapper<StationInfoMin> wrapper = new QueryWrapper<>();
  149. wrapper.eq("record_date", date).eq("station_id", stId);
  150. return stationInfoMinService.getOne(wrapper, false);
  151. }
  152. public StationInfoDay getStationinfoByDate(Date date, String stId) {
  153. QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
  154. wrapper.eq("record_date", date).eq("station_id", stId);
  155. List<StationInfoDay> list = stationInfoDayService.list(wrapper);
  156. StationInfoDay day;
  157. if (CollUtil.isEmpty(list)) {
  158. day = new StationInfoDay();
  159. day.setStationId(stId);
  160. day.setRecordDate(date);
  161. } else {
  162. day = list.get(0);
  163. }
  164. return day;
  165. }
  166. public List<StationInfoDay> getStationinfoByDate(Date date, List<PointInfo> entity) {
  167. QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
  168. wrapper.eq("record_date", date);
  169. List<StationInfoDay> list = stationInfoDayService.list(wrapper);
  170. if (CollUtil.isEmpty(list)) {
  171. entity.forEach(pi -> {
  172. StationInfoDay day = new StationInfoDay();
  173. day.setStationId(pi.getStationId());
  174. day.setRecordDate(date);
  175. list.add(day);
  176. });
  177. }
  178. return list;
  179. }
  180. public List<StationInfoDay> getStationinfoByDate2(Date date, List<PointInfo> entity) {
  181. QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
  182. List<String> sts = entity.stream().map(PointInfo::getStationId).collect(Collectors.toList());
  183. wrapper.eq("record_date", date).in("station_id", sts);
  184. List<StationInfoDay> list = stationInfoDayService.list(wrapper);
  185. if (CollUtil.isEmpty(list)) {
  186. entity.forEach(pi -> {
  187. StationInfoDay day = new StationInfoDay();
  188. day.setStationId(pi.getStationId());
  189. day.setRecordDate(date);
  190. list.add(day);
  191. });
  192. }
  193. return list;
  194. }
  195. public List<LineInfoDay> getLineinfoByDate(Date date) {
  196. QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
  197. wrapper.eq("record_date", date);
  198. return lineInfoDayService.list(wrapper);
  199. }
  200. public List<LineInfoDay> getLineinfoByDate(Date date, String stId) {
  201. QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
  202. wrapper.eq("record_date", date).eq("station_id", stId);
  203. return lineInfoDayService.list(wrapper);
  204. }
  205. public List<LineInfoDay> getLineinfoByDate(Date date, List<PointInfo> entity) {
  206. QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
  207. wrapper.eq("record_date", date);
  208. List<LineInfoDay> list = lineInfoDayService.list(wrapper);
  209. if (CollUtil.isEmpty(list)) {
  210. entity.forEach(pi -> {
  211. LineInfoDay day = new LineInfoDay();
  212. day.setStationId(pi.getStationId());
  213. day.setProjectId(pi.getProjectId());
  214. day.setLineId(pi.getLineId());
  215. day.setRecordDate(date);
  216. list.add(day);
  217. });
  218. }
  219. return list;
  220. }
  221. public List<LineInfoDay> getLineinfoByDate2(Date date, List<PointInfo> entity) {
  222. QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
  223. List<String> lines = entity.stream().map(PointInfo::getLineId).collect(Collectors.toList());
  224. wrapper.eq("record_date", date).in("line_id", lines);
  225. List<LineInfoDay> list = lineInfoDayService.list(wrapper);
  226. if (CollUtil.isEmpty(list)) {
  227. entity.forEach(pi -> {
  228. LineInfoDay day = new LineInfoDay();
  229. day.setStationId(pi.getStationId());
  230. day.setProjectId(pi.getProjectId());
  231. day.setLineId(pi.getLineId());
  232. day.setRecordDate(date);
  233. list.add(day);
  234. });
  235. }
  236. return list;
  237. }
  238. public URI taosUri() {
  239. return URI.create("http://172.16.12.101:8012/ts");
  240. }
  241. public URI goldenUri() {
  242. return URI.create("http://172.16.12.103:8017/ts");
  243. }
  244. public Map<String, String> getEntityMap(String uniformCode, String institutionType) {
  245. PointInfo pi = new PointInfo();
  246. pi.setUniformCode(uniformCode);
  247. pi.setInstitutionType(institutionType);
  248. List<PointInfo> entity = pointService.getByEntity(pi);
  249. switch (institutionType) {
  250. case "turbine":
  251. case "state":
  252. return entity.stream().collect(Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointKey));
  253. case "station":
  254. return entity.stream().collect(Collectors.toMap(PointInfo::getStationId, PointInfo::getPointKey));
  255. }
  256. return new HashMap<>();
  257. }
  258. public Map<String, TurbineInfoDay> getTurbineinfoMap(Date date, List<PointInfo> entity) {
  259. QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
  260. wrapper.eq("record_date", date);
  261. List<TurbineInfoDay> list = turbineInfoDayService.list(wrapper);
  262. if (list.isEmpty()) {
  263. entity.forEach(pi -> {
  264. TurbineInfoDay day = new TurbineInfoDay();
  265. day.setStationId(pi.getStationId());
  266. day.setProjectId(pi.getProjectId());
  267. day.setLineId(pi.getLineId());
  268. day.setTurbineId(pi.getTurbineId());
  269. day.setRecordDate(date);
  270. list.add(day);
  271. });
  272. }
  273. return list.stream().collect(Collectors.toMap(TurbineInfoDay::getTurbineId, Function.identity()));
  274. }
  275. public List<PointInfo> getEntity(String uniformCode, String institutionType) {
  276. PointInfo pi = new PointInfo();
  277. pi.setUniformCode(uniformCode);
  278. pi.setInstitutionType(institutionType);
  279. return pointService.getByEntity(pi);
  280. }
  281. public List<PointInfo> getEntityByUis(String uniformCode, String institutionType, String stId) {
  282. PointInfo pi = new PointInfo();
  283. pi.setUniformCode(uniformCode);
  284. pi.setInstitutionType(institutionType);
  285. pi.setStationId(stId);
  286. return pointService.getByEntity(pi);
  287. }
  288. public Map<String, Double> getTurbinePowerLoss(Double rfdl, PointInfo piZt, List<PointData> fsList, List<PointData> glList) {
  289. if (rfdl == null) rfdl = 0.0;
  290. String tbId = piZt.getTurbineId();
  291. // Map<Double, Long> collect = piZt.getPointDatas().stream().collect(Collectors.groupingBy(PointData::getValue, Collectors.counting()));
  292. double sumfs = fsList.stream().mapToDouble(PointData::getValue).sum();
  293. // double xs = 1;
  294. // if (rfdl > 0 && sum1 > 0) {
  295. // xs = rfdl / (sum1 / 240);
  296. // }
  297. // double sum2 = fsList.stream().mapToDouble(pd -> {
  298. // Double v = CalcCache.fitcoef.get(tbId).get(pd.getValue());
  299. // if (v == null) v = 0.0;
  300. // return v;
  301. // }).sum();
  302. // sum2=sum2/240;
  303. List<PointData> collectZt = piZt.getPointDatas();
  304. double jxss = 0, sdtj = 0, gzss = 0, djss = 0, xnss = 0, fdjcl = 0, xdjcl = 0, xdtj = 0;
  305. Map<String, Double> map = new HashMap<>();
  306. if (Math.abs(collectZt.size() - fsList.size()) < 9 && Math.abs(fsList.size() - glList.size()) < 9) {
  307. int min = Math.min(collectZt.size(), Math.min(fsList.size(), glList.size()));
  308. for (int i = 0; i < min; i++) {
  309. Double v = CalcCache.fitcoef.get(tbId).get(fsList.get(i).getValue());
  310. if (v == null) v = 0.0;
  311. v = v - glList.get(i).getValue();
  312. // double v2 = v > 0 ? v : 0;
  313. double v2 = v;
  314. switch ((int) collectZt.get(i).getValue()) {
  315. //计划检修损失:
  316. case 6:
  317. //检修
  318. jxss += v2;
  319. break;
  320. case 1:
  321. //手动停机
  322. sdtj += v2;
  323. break;
  324. //非计划检修损失:
  325. case 4:
  326. //故障
  327. gzss += v2;
  328. break;
  329. case 0:
  330. //待机
  331. djss += v2;
  332. break;
  333. //性能损失:
  334. case 2:
  335. //性能
  336. xnss += v2;
  337. break;
  338. case 3:
  339. //发电降出力
  340. fdjcl += v2;
  341. break;
  342. //限电损失:
  343. case 8:
  344. //限电降出力
  345. xdjcl += v2;
  346. break;
  347. case 9:
  348. //限电停机
  349. xdtj += v2;
  350. break;
  351. }
  352. }
  353. }
  354. if (jxss > 3600000) jxss = 3600000;
  355. if (sdtj > 3600000) sdtj = 3600000;
  356. if (gzss > 3600000) gzss = 3600000;
  357. if (djss > 3600000) djss = 3600000;
  358. if (xnss > 3600000) xnss = 3600000;
  359. if (fdjcl > 3600000) fdjcl = 3600000;
  360. if (xdjcl > 3600000) xdjcl = 3600000;
  361. if (xdtj > 3600000) xdtj = 3600000;
  362. //15秒*60分钟
  363. map.put("jxss", jxss > 0 ? jxss / 240 : 0);
  364. map.put("sdtj", sdtj > 0 ? sdtj / 240 : 0);
  365. map.put("gzss", gzss > 0 ? gzss / 240 : 0);
  366. map.put("djss", djss > 0 ? djss / 240 : 0);
  367. map.put("xnss", xnss > 0 ? xnss / 240 : 0);
  368. map.put("fdjcl", fdjcl > 0 ? fdjcl / 240 : 0);
  369. map.put("xdjcl", xdjcl > 0 ? xdjcl / 240 : 0);
  370. map.put("xdtj", xdtj > 0 ? xdtj / 240 : 0);
  371. 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");
  372. System.out.println(piZt.getTurbineId() + ",日发" + rfdl + ",损失" + v + ",风速和" + sumfs / 240);
  373. return map;
  374. }
  375. public void calcAQTS(Date date) {
  376. QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
  377. wrapper.select("min(record_date) record_date");
  378. StationInfoDay one = stationInfoDayService.getOne(wrapper);
  379. wrapper = new QueryWrapper<>();
  380. wrapper.eq("record_date", one.getRecordDate());
  381. //最早时间的列表
  382. List<StationInfoDay> list = stationInfoDayService.list(wrapper);
  383. List<StationInfoDay> today = getStationinfoByDate(date);
  384. if (today.isEmpty()) {
  385. for (StationInfoDay infoDay : list) {
  386. StationInfoDay day = new StationInfoDay();
  387. day.setStationId(infoDay.getStationId());
  388. day.setRecordDate(date);
  389. day.setAqts(infoDay.getAqts() + (int) DateUtil.betweenDay(infoDay.getRecordDate(), date, true));
  390. today.add(day);
  391. }
  392. } else {
  393. Map<String, StationInfoDay> collect = list.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  394. for (StationInfoDay day : today) {
  395. StationInfoDay day1 = collect.get(day.getStationId());
  396. day.setAqts(day1.getAqts() + (int) DateUtil.betweenDay(day1.getRecordDate(), date, true));
  397. }
  398. }
  399. stationInfoDayService.saveOrUpdateBatch(today);
  400. }
  401. public void calcLineSwGWCyDl(Date date) {
  402. //date当天零点
  403. DateTime time = DateUtil.beginOfDay(date);
  404. //date昨天零点
  405. DateTime time0 = DateUtil.offsetDay(time, -1);
  406. List<StationInfoDay> stationInfos = getStationinfoByDate(time0);
  407. Map<String, StationInfoDay> stationMap = stationInfos.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  408. List<LineInfoDay> lineInfos = getLineinfoByDate(time0);
  409. StationInfoDay stationInfo;
  410. for (LineInfoDay lineInfo : lineInfos) {
  411. stationInfo = stationMap.get(lineInfo.getStationId());
  412. double xs = (double) lineInfo.getRfdl() / stationInfo.getRfdl();
  413. lineInfo.setSwdl(xs * stationInfo.getSwdl());
  414. lineInfo.setGwdl(xs * stationInfo.getGwdl());
  415. lineInfo.setCydl(xs * stationInfo.getCydl());
  416. lineInfo.setZyb(xs * stationInfo.getZyb());
  417. }
  418. lineInfoDayService.saveOrUpdateBatch(lineInfos);
  419. }
  420. public void calcLineSwGWCyDlSameDay() {
  421. //date当天零点
  422. DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
  423. List<StationInfoDay> stationInfos = getStationinfoByDate(time0);
  424. Map<String, StationInfoDay> stationMap = stationInfos.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  425. List<LineInfoDay> lineInfos = getLineinfoByDate(time0);
  426. StationInfoDay stationInfo;
  427. for (LineInfoDay lineInfo : lineInfos) {
  428. stationInfo = stationMap.get(lineInfo.getStationId());
  429. double xs = (double) lineInfo.getRfdl() / stationInfo.getRfdl();
  430. lineInfo.setSwdl(xs * stationInfo.getSwdl());
  431. lineInfo.setGwdl(xs * stationInfo.getGwdl());
  432. lineInfo.setCydl(xs * stationInfo.getCydl());
  433. lineInfo.setZyb(xs * stationInfo.getZyb());
  434. }
  435. lineInfoDayService.saveOrUpdateBatch(lineInfos);
  436. }
  437. public void calcLineSwGWCyDl(Date date, String stId) {
  438. //date当天零点
  439. DateTime time = DateUtil.beginOfDay(date);
  440. //date昨天零点
  441. DateTime time0 = DateUtil.offsetDay(time, -1);
  442. StationInfoDay sti = getStationinfoByDate(time0, stId);
  443. List<LineInfoDay> lineInfos = getLineinfoByDate(time0, stId);
  444. for (LineInfoDay lineInfo : lineInfos) {
  445. double xs = (double) lineInfo.getRfdl() / sti.getRfdl();
  446. lineInfo.setSwdl(xs * sti.getSwdl());
  447. lineInfo.setGwdl(xs * sti.getGwdl());
  448. lineInfo.setCydl(xs * sti.getCydl());
  449. lineInfo.setZyb(xs * sti.getZyb());
  450. }
  451. lineInfoDayService.saveOrUpdateBatch(lineInfos);
  452. }
  453. public void calcStationZhcyRfDl(Date date) {
  454. //date当天零点
  455. DateTime time = DateUtil.beginOfDay(date);
  456. //date昨天零点
  457. DateTime time0 = DateUtil.offsetDay(time, -1);
  458. QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
  459. wrapper.select("sum(rfdl) rfdl,station_id").eq("record_date", time0).groupBy("station_id");
  460. List<LineInfoDay> list = lineInfoDayService.list(wrapper);
  461. Map<String, Integer> rfdlMap = list.stream().collect(Collectors.toMap(LineInfoDay::getStationId, LineInfoDay::getRfdl));
  462. List<StationInfoDay> byDate = getStationinfoByDate(time0);
  463. for (StationInfoDay day : byDate) {
  464. day.setRfdl(rfdlMap.get(day.getStationId()));
  465. day.setZhcydl(day.getRfdl() + day.getGwdl() - day.getSwdl());
  466. day.setCydl(day.getZhcydl() - day.getZyb());
  467. }
  468. stationInfoDayService.saveOrUpdateBatch(byDate);
  469. }
  470. public void calcStationRjhfdl(Date date) {
  471. List<DateTime> months = DateUtil.rangeToList(date, DateUtil.endOfYear(date), DateField.MONTH);
  472. for (DateTime month : months) {
  473. DateTime begin = DateUtil.beginOfMonth(month);
  474. DateTime end = DateUtil.endOfMonth(month);
  475. DateTime beginTq = DateUtil.offset(begin, DateField.YEAR, -1);
  476. DateTime endTq = DateUtil.offset(end, DateField.YEAR, -1);
  477. QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
  478. wrapper.lambda().between(StationInfoDay::getRecordDate, begin, end);
  479. List<StationInfoDay> days = stationInfoDayService.list(wrapper);
  480. Map<String, Map<String, StationInfoDay>> dayMap = new HashMap<>();
  481. if (CollUtil.isNotEmpty(days)) {
  482. dayMap = days.stream().collect(Collectors.groupingBy(StationInfoDay::getStationId,
  483. Collectors.toMap(sid -> DateUtil.formatDate(sid.getRecordDate()), Function.identity())));
  484. }
  485. wrapper.clear();
  486. wrapper.lambda().between(StationInfoDay::getRecordDate, beginTq, endTq);
  487. List<StationInfoDay> sids = stationInfoDayService.list(wrapper);
  488. Map<String, List<StationInfoDay>> sidMap;
  489. if (CollUtil.isNotEmpty(sids)) {
  490. sidMap = sids.stream().collect(Collectors.groupingBy(StationInfoDay::getStationId));
  491. } else {
  492. sidMap = null;
  493. }
  494. QueryWrapper<ProBasicProjectPlan> wrapperPlan = new QueryWrapper<>();
  495. wrapperPlan.lambda().eq(ProBasicProjectPlan::getYear, String.valueOf(begin.year()))
  496. .eq(ProBasicProjectPlan::getMonth, String.valueOf(begin.month() + 1));
  497. List<ProBasicProjectPlan> plantList = proBasicProjectPlanService.list(wrapperPlan);
  498. for (ProBasicProjectPlan plan : plantList) {
  499. String stId = plan.getWindpowerstationId();
  500. Map<String, StationInfoDay> daym = dayMap.get(stId);
  501. if (daym == null) daym = new HashMap<>();
  502. if (sidMap == null) {
  503. for (StationInfoDay day : daym.values()) {
  504. day.setJhfdl(plan.getGeneratingCapacity() / daym.size());
  505. }
  506. } else {
  507. //去年月发电量
  508. List<StationInfoDay> sidList = sidMap.get(stId);
  509. double rfdlSum = sidList.stream().mapToDouble(StationInfoDay::getRfdl).sum();
  510. double v = plan.getGeneratingCapacity() / rfdlSum;
  511. for (StationInfoDay sid : sidList) {
  512. DateTime time = DateUtil.offset(sid.getRecordDate(), DateField.YEAR, 1);
  513. StationInfoDay day = daym.get(DateUtil.formatDate(time));
  514. if (day == null) {
  515. day = new StationInfoDay();
  516. day.setStationId(stId);
  517. day.setRecordDate(time);
  518. days.add(day);
  519. }
  520. day.setJhfdl(v * sid.getRfdl());
  521. }
  522. }
  523. }
  524. stationInfoDayService.saveOrUpdateBatch(days);
  525. }
  526. }
  527. public void calcStationRjhfdl2(Date month) {
  528. DateTime begin = DateUtil.beginOfMonth(month);
  529. DateRange range = DateUtil.range(begin, DateUtil.endOfYear(begin), DateField.MONTH);
  530. QueryWrapper<ProBasicProjectPlan> wrapperPlan = new QueryWrapper<>();
  531. wrapperPlan.lambda().eq(ProBasicProjectPlan::getYear, String.valueOf(begin.year()))
  532. .eq(ProBasicProjectPlan::getMonth, String.valueOf(begin.month() + 1));
  533. List<ProBasicProjectPlan> plantList = proBasicProjectPlanService.list(wrapperPlan);
  534. for (DateTime date : range) {
  535. }
  536. DateTime end = DateUtil.endOfMonth(month);
  537. DateTime beginTq = DateUtil.offset(begin, DateField.YEAR, -1);
  538. DateTime endTq = DateUtil.offset(end, DateField.YEAR, -1);
  539. QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
  540. wrapper.lambda().between(StationInfoDay::getRecordDate, begin, end);
  541. List<StationInfoDay> days = stationInfoDayService.list(wrapper);
  542. Map<String, Map<String, StationInfoDay>> dayMap = new HashMap<>();
  543. if (CollUtil.isNotEmpty(days)) {
  544. dayMap = days.stream().collect(Collectors.groupingBy(StationInfoDay::getStationId,
  545. Collectors.toMap(sid -> DateUtil.date(sid.getRecordDate()).toString(), Function.identity())));
  546. }
  547. wrapper.clear();
  548. wrapper.lambda().between(StationInfoDay::getRecordDate, beginTq, endTq);
  549. List<StationInfoDay> sids = stationInfoDayService.list(wrapper);
  550. Map<String, List<StationInfoDay>> sidMap;
  551. if (CollUtil.isNotEmpty(sids)) {
  552. sidMap = sids.stream().collect(Collectors.groupingBy(StationInfoDay::getStationId));
  553. } else {
  554. sidMap = null;
  555. }
  556. for (ProBasicProjectPlan plan : plantList) {
  557. String stId = plan.getWindpowerstationId();
  558. Map<String, StationInfoDay> daym = dayMap.get(stId);
  559. if (daym == null) daym = new HashMap<>();
  560. if (sidMap == null) {
  561. for (StationInfoDay day : daym.values()) {
  562. day.setJhfdl(plan.getGeneratingCapacity() / daym.size());
  563. }
  564. } else {
  565. //去年月发电量
  566. List<StationInfoDay> sidList = sidMap.get(stId);
  567. double rfdlSum = sidList.stream().mapToDouble(StationInfoDay::getRfdl).sum();
  568. double v = plan.getGeneratingCapacity() / rfdlSum;
  569. for (StationInfoDay sid : sidList) {
  570. DateTime time = DateUtil.offset(sid.getRecordDate(), DateField.YEAR, 1);
  571. StationInfoDay day = daym.get(time.toString());
  572. if (day == null) {
  573. day = new StationInfoDay();
  574. day.setStationId(stId);
  575. day.setRecordDate(time);
  576. days.add(day);
  577. }
  578. day.setJhfdl(v * sid.getRfdl());
  579. }
  580. }
  581. }
  582. stationInfoDayService.saveOrUpdateBatch(days);
  583. }
  584. public void calcStationZhcyRfDlSameDay() {
  585. //date当天零点
  586. DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
  587. QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
  588. wrapper.select("sum(rfdl) rfdl,station_id").eq("record_date", time0).groupBy("station_id");
  589. List<LineInfoDay> list = lineInfoDayService.list(wrapper);
  590. Map<String, Integer> rfdlMap = list.stream().collect(Collectors.toMap(LineInfoDay::getStationId, LineInfoDay::getRfdl));
  591. List<StationInfoDay> byDate = getStationinfoByDate(time0);
  592. for (StationInfoDay day : byDate) {
  593. day.setRfdl(rfdlMap.get(day.getStationId()));
  594. day.setZhcydl(day.getRfdl() + day.getGwdl() - day.getSwdl());
  595. day.setCydl(day.getZhcydl() - day.getZyb());
  596. }
  597. stationInfoDayService.saveOrUpdateBatch(byDate);
  598. }
  599. public void calcStationZhcyRfDl(Date date, String stId) {
  600. //date当天零点
  601. DateTime time = DateUtil.beginOfDay(date);
  602. //date昨天零点
  603. DateTime time0 = DateUtil.offsetDay(time, -1);
  604. QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
  605. wrapper.select("sum(rfdl) rfdl,station_id").eq("record_date", time0)
  606. .eq("station_id", stId).groupBy("station_id");
  607. List<LineInfoDay> list = lineInfoDayService.list(wrapper);
  608. Map<String, Integer> rfdlMap = list.stream().collect(Collectors.toMap(LineInfoDay::getStationId, LineInfoDay::getRfdl));
  609. StationInfoDay day = getStationinfoByDate(time0, stId);
  610. day.setRfdl(rfdlMap.get(day.getStationId()));
  611. day.setZhcydl(day.getRfdl() + day.getGwdl() - day.getSwdl());
  612. day.setCydl(day.getZhcydl() - day.getZyb());
  613. stationInfoDayService.saveOrUpdateBatch(Collections.singleton(day));
  614. }
  615. public void calcStationSwGwCyRdl(Date date) {
  616. //date当天零点
  617. DateTime time = DateUtil.beginOfDay(date);
  618. //date昨天零点
  619. DateTime time0 = DateUtil.offsetDay(time, -1);
  620. List<PointInfo> swdlEt = getEntity("Z-ZXYG-CX", "meter");
  621. List<PointInfo> gwdlEt = getEntity("Z-FXYG-CX", "meter");
  622. List<PointInfo> cydlEt = getEntity("Z-ZXYG-ZYB", "meter");
  623. getZeroNextData(swdlEt, time0, time);
  624. getZeroNextData(gwdlEt, time0, time);
  625. getZeroNextData(cydlEt, time0, time);
  626. Map<String, PointInfo> swdlMap = swdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  627. Map<String, PointInfo> gwdlMap = gwdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  628. Map<String, PointInfo> cydlMap = cydlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  629. List<StationInfoDay> byDate = getStationinfoByDate(time0, swdlEt);
  630. String stId;
  631. PointInfo swdlPi, gwdlPi, cydlPi;
  632. for (StationInfoDay info : byDate) {
  633. stId = info.getStationId();
  634. swdlPi = swdlMap.get(stId);
  635. gwdlPi = gwdlMap.get(stId);
  636. cydlPi = cydlMap.get(stId);
  637. int swdl = (int) ((swdlPi.getPointDatas().get(1).getValue() - swdlPi.getPointDatas().get(0).getValue()) * swdlPi.getCoef());
  638. int gwdl = (int) ((gwdlPi.getPointDatas().get(1).getValue() - gwdlPi.getPointDatas().get(0).getValue()) * gwdlPi.getCoef());
  639. int cydl = (int) ((cydlPi.getPointDatas().get(1).getValue() - cydlPi.getPointDatas().get(0).getValue()) * cydlPi.getCoef());
  640. if (swdl < 0 || swdl > 6000000) swdl = 0;
  641. if (gwdl < 0 || gwdl > 6000000) gwdl = 0;
  642. if (cydl < 0 || cydl > 6000000) cydl = 0;
  643. info.setSwdl(swdl);
  644. info.setGwdl(gwdl);
  645. info.setZyb(cydl);
  646. }
  647. stationInfoDayService.saveOrUpdateBatch(byDate);
  648. }
  649. public void calcStationSwGwCyDlSameDay() {
  650. //date当天零点
  651. DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
  652. List<PointInfo> swdlEt = getEntity("Z-ZXYG-CX", "meter");
  653. List<PointInfo> gwdlEt = getEntity("Z-FXYG-CX", "meter");
  654. List<PointInfo> cydlEt = getEntity("Z-ZXYG-ZYB", "meter");
  655. getZeroNextData(swdlEt, time0);
  656. getZeroNextData(gwdlEt, time0);
  657. getZeroNextData(cydlEt, time0);
  658. Map<String, PointInfo> swdlMap = swdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  659. Map<String, PointInfo> gwdlMap = gwdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  660. Map<String, PointInfo> cydlMap = cydlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  661. List<StationInfoDay> byDate = getStationinfoByDate(time0, swdlEt);
  662. String stId;
  663. PointInfo swdlPi, gwdlPi, cydlPi;
  664. for (StationInfoDay info : byDate) {
  665. stId = info.getStationId();
  666. swdlPi = swdlMap.get(stId);
  667. gwdlPi = gwdlMap.get(stId);
  668. cydlPi = cydlMap.get(stId);
  669. int swdl = (int) ((swdlPi.getPointDatas().get(1).getValue() - swdlPi.getPointDatas().get(0).getValue()) * swdlPi.getCoef());
  670. int gwdl = (int) ((gwdlPi.getPointDatas().get(1).getValue() - gwdlPi.getPointDatas().get(0).getValue()) * gwdlPi.getCoef());
  671. int cydl = (int) ((cydlPi.getPointDatas().get(1).getValue() - cydlPi.getPointDatas().get(0).getValue()) * cydlPi.getCoef());
  672. if (swdl < 0 || swdl > 6000000) swdl = 0;
  673. if (gwdl < 0 || gwdl > 6000000) gwdl = 0;
  674. if (cydl < 0 || cydl > 6000000) cydl = 0;
  675. info.setSwdl(swdl);
  676. info.setGwdl(gwdl);
  677. info.setZyb(cydl);
  678. }
  679. stationInfoDayService.saveOrUpdateBatch(byDate);
  680. }
  681. public void calcStationSwGwCyRdl(Date date, String stId) {
  682. //date当天零点
  683. DateTime time = DateUtil.beginOfDay(date);
  684. //date昨天零点
  685. DateTime time0 = DateUtil.offsetDay(time, -1);
  686. List<PointInfo> swdlEt = getEntityByUis("Z-ZXYG-CX", "meter", stId);
  687. List<PointInfo> gwdlEt = getEntityByUis("Z-FXYG-CX", "meter", stId);
  688. List<PointInfo> cydlEt = getEntityByUis("Z-ZXYG-ZYB", "meter", stId);
  689. getZeroNextData(swdlEt, time0, time);
  690. getZeroNextData(gwdlEt, time0, time);
  691. getZeroNextData(cydlEt, time0, time);
  692. List<StationInfoDay> byDate = getStationinfoByDate2(time0, swdlEt);
  693. StationInfoDay info = byDate.get(0);
  694. PointInfo swdlPi = swdlEt.get(0);
  695. PointInfo gwdlPi = gwdlEt.get(0);
  696. PointInfo cydlPi = cydlEt.get(0);
  697. int swdl = (int) ((swdlPi.getPointDatas().get(1).getValue() - swdlPi.getPointDatas().get(0).getValue()) * swdlPi.getCoef());
  698. int gwdl = (int) ((gwdlPi.getPointDatas().get(1).getValue() - gwdlPi.getPointDatas().get(0).getValue()) * gwdlPi.getCoef());
  699. int cydl = (int) ((cydlPi.getPointDatas().get(1).getValue() - cydlPi.getPointDatas().get(0).getValue()) * cydlPi.getCoef());
  700. if (stId.equals("GJNY_SXGS_JSL_FDC_STA") && time0.before(DateUtil.parse("2024-07-08"))) {
  701. swdl = swdl * 100;
  702. gwdl = gwdl * 100;
  703. }
  704. if (swdl < 0 || swdl > 6000000) swdl = 0;
  705. if (gwdl < 0 || gwdl > 6000000) gwdl = 0;
  706. if (cydl < 0 || cydl > 6000000) cydl = 0;
  707. info.setSwdl(swdl);
  708. info.setGwdl(gwdl);
  709. info.setZyb(cydl);
  710. stationInfoDayService.saveOrUpdateBatch(byDate);
  711. }
  712. public void SwdlRepair(Date date) {
  713. //date当天零点
  714. DateTime time = DateUtil.beginOfDay(date);
  715. //date昨天零点
  716. DateTime time0 = DateUtil.offsetDay(time, -1);
  717. List<PointInfo> swdlEt = getEntity("Z-ZXYG-CX", "meter");
  718. Map<String, PointInfo> map = swdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  719. List<StationInfoDay> list = getStationinfoByDate(time0);
  720. Map<String, StationInfoDay> dayMap = list.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  721. CalcCache.swdlTime.forEach((key, ts) -> {
  722. int swdl = 0;
  723. PointData data1, data0;
  724. double ll = (double) (time.getTime() - ts) / 23 * 60 * 60 * 1000;
  725. if (ts > 0 && (ll > 23 && ll < 25)) {
  726. StationInfoDay day = dayMap.get(key);
  727. PointInfo info = map.get(key);
  728. List<PointData> raw1 = adapter.getHistoryRaw(goldenUri(), key, time.getTime(), DateUtil.offsetMinute(time, 6).getTime());
  729. if (CollUtil.isEmpty(raw1)) {
  730. Map<String, PointData> section = adapter.getHistorySection(goldenUri(), key, time.getTime() + 1000);
  731. data1 = section.get(key);
  732. } else {
  733. data1 = raw1.get(0);
  734. }
  735. Map<String, PointData> section = adapter.getHistorySection(goldenUri(), key, ts + 1000);
  736. data0 = section.get(key);
  737. swdl = (int) ((data1.getValue() - data0.getValue()) * info.getCoef());
  738. if (swdl > day.getRfdl()) {
  739. List<PointData> rawl1 = adapter.getHistoryRaw(goldenUri(), key, DateUtil.offsetMinute(time, -60).getTime(), time.getTime());
  740. for (int i = rawl1.size() - 1; i >= 0; i--) {
  741. swdl = (int) ((rawl1.get(i).getValue() - data0.getValue()) * info.getCoef());
  742. if (swdl <= day.getRfdl()) {
  743. day.setSwdl(swdl);
  744. day.setZhcydl(day.getRfdl() + day.getGwdl() - day.getSwdl());
  745. day.setCydl(day.getZhcydl() - day.getZyb());
  746. CalcCache.swdlTime.put(info.getPointKey(), rawl1.get(i).getTs());
  747. break;
  748. }
  749. }
  750. } else {
  751. day.setSwdl(swdl);
  752. day.setZhcydl(day.getRfdl() + day.getGwdl() - day.getSwdl());
  753. day.setCydl(day.getZhcydl() - day.getZyb());
  754. }
  755. }
  756. });
  757. for (StationInfoDay day : list) {
  758. int swdl = 0;
  759. if (day.getSwdl() > day.getRfdl()) {
  760. PointInfo info = map.get(day.getStationId());
  761. Long l = CalcCache.swdlTime.get(info.getPointKey());
  762. PointData data0;
  763. if (l == null || l == 0) {
  764. List<PointData> raw0 = adapter.getHistoryRaw(goldenUri(), info.getPointKey(), time0.getTime(), DateUtil.offsetMinute(time0, 6).getTime());
  765. if (CollUtil.isEmpty(raw0)) {
  766. Map<String, PointData> section = adapter.getHistorySection(goldenUri(), info.getPointKey(), time0.getTime() + 1000);
  767. data0 = section.get(info.getPointKey());
  768. } else {
  769. data0 = raw0.get(0);
  770. }
  771. } else {
  772. double ll = (double) (time.getTime() - l) / 23 * 60 * 60 * 1000;
  773. if (ll > 23 && ll < 25) {
  774. Map<String, PointData> section = adapter.getHistorySection(goldenUri(), info.getPointKey(), l + 1000);
  775. data0 = section.get(info.getPointKey());
  776. } else {
  777. continue;
  778. }
  779. }
  780. List<PointData> raw1 = adapter.getHistoryRaw(goldenUri(), info.getPointKey(), DateUtil.offsetMinute(time, -60).getTime(), time.getTime());
  781. for (int i = raw1.size() - 1; i >= 0; i--) {
  782. swdl = (int) ((raw1.get(i).getValue() - data0.getValue()) * info.getCoef());
  783. if (swdl <= day.getRfdl()) {
  784. day.setSwdl(swdl);
  785. day.setZhcydl(day.getRfdl() + day.getGwdl() - day.getSwdl());
  786. day.setCydl(day.getZhcydl() - day.getZyb());
  787. CalcCache.swdlTime.put(info.getPointKey(), raw1.get(i).getTs());
  788. break;
  789. }
  790. }
  791. }
  792. }
  793. stationInfoDayService.saveOrUpdateBatch(list);
  794. stringRedisTemplate.opsForValue().set("swdlTime", JSON.toJSONString(CalcCache.swdlTime));
  795. }
  796. public void getZeroNextData(List<PointInfo> entity, Date start0, Date start) {
  797. List<PointData> snap0, snap;
  798. for (PointInfo info : entity) {
  799. PointData data0, data;
  800. List<PointData> datas = new ArrayList<>();
  801. snap0 = adapter.getHistoryRaw(goldenUri(), info.getPointKey(), start0.getTime(), DateUtil.offsetMinute(start0, 6).getTime());
  802. if (CollUtil.isEmpty(snap0)) {
  803. Map<String, PointData> section = adapter.getHistorySection(goldenUri(), info.getPointKey(), start0.getTime());
  804. snap0 = new ArrayList<>(section.values());
  805. }
  806. snap = adapter.getHistoryRaw(goldenUri(), info.getPointKey(), start.getTime(), DateUtil.offsetMinute(start, 6).getTime());
  807. if (CollUtil.isEmpty(snap)) {
  808. Map<String, PointData> section = adapter.getHistorySection(goldenUri(), info.getPointKey(), start.getTime());
  809. snap = new ArrayList<>(section.values());
  810. }
  811. if (CollUtil.isEmpty(snap0) || CollUtil.isEmpty(snap)) {
  812. data0 = new PointData();
  813. data = new PointData();
  814. } else {
  815. data0 = snap0.get(0);
  816. data = snap.get(0);
  817. }
  818. datas.add(data0);
  819. datas.add(data);
  820. info.setPointDatas(datas);
  821. }
  822. }
  823. public void getZeroNextData(List<PointInfo> entity, Date start0) {
  824. String keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
  825. Map<String, PointData> latest = adapter.getLatest(goldenUri(), keys);
  826. List<PointData> snap0;
  827. for (PointInfo info : entity) {
  828. PointData data0, data;
  829. List<PointData> datas = new ArrayList<>();
  830. snap0 = adapter.getHistoryRaw(goldenUri(), info.getPointKey(), start0.getTime(), DateUtil.offsetMinute(start0, 90).getTime());
  831. if (CollUtil.isEmpty(snap0)) {
  832. Map<String, PointData> section = adapter.getHistorySection(goldenUri(), info.getPointKey(), start0.getTime());
  833. snap0 = new ArrayList<>(section.values());
  834. }
  835. data = latest.get(info.getPointKey());
  836. if (CollUtil.isEmpty(snap0) || data == null) {
  837. data0 = new PointData();
  838. data = new PointData();
  839. } else {
  840. data0 = snap0.get(0);
  841. }
  842. datas.add(data0);
  843. datas.add(data);
  844. info.setPointDatas(datas);
  845. }
  846. }
  847. public void calcStationHourRFDL(Date hour) {
  848. PointInfo pointInfo = new PointInfo();
  849. pointInfo.setInstitutionType("station");
  850. pointInfo.setUniformCode("RFDLSYZ");
  851. List<PointInfo> entity = pointService.getByEntity(pointInfo);
  852. Map<String, PointData> section = adapter.getHistorySection(taosUri(), pointInfos2Keys(entity), hour.getTime());
  853. List<StationInfoHour> byHours = getStationinfoByHour(hour);
  854. if (byHours.isEmpty()) {
  855. for (PointInfo point : entity) {
  856. StationInfoHour info = new StationInfoHour();
  857. info.setStationId(point.getStationId());
  858. info.setRecordDate(DateUtil.beginOfHour(hour));
  859. info.setRfdl(section.get(point.getPointKey()).getValue());
  860. byHours.add(info);
  861. }
  862. } else {
  863. Map<String, String> collect = entity.stream().collect(Collectors.toMap(PointInfo::getStationId, PointInfo::getPointKey));
  864. for (StationInfoHour byHour : byHours) {
  865. byHour.setRfdl(section.get(collect.get(byHour.getStationId())).getValue());
  866. }
  867. }
  868. stationInfoHourService.saveOrUpdateBatch(byHours);
  869. }
  870. public void calcLineRfdl(Date date) {
  871. //date当天零点
  872. DateTime time = DateUtil.beginOfDay(date);
  873. //date昨天零点
  874. DateTime time0 = DateUtil.offsetDay(time, -1);
  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, time);
  878. Map<String, PointInfo> swdlMap = entity.stream().collect(Collectors.toMap(PointInfo::getLineId, Function.identity()));
  879. List<LineInfoDay> byDate = getLineinfoByDate(time0, entity);
  880. String lineId;
  881. PointInfo swdlPi;
  882. int v = 0;
  883. for (LineInfoDay day : byDate) {
  884. lineId = day.getLineId();
  885. swdlPi = swdlMap.get(lineId);
  886. v = (int) ((swdlPi.getPointDatas().get(1).getValue() - swdlPi.getPointDatas().get(0).getValue()) * swdlPi.getCoef());
  887. if (v < 0 || v > 30000000) v = 0;
  888. day.setRfdl(v);
  889. }
  890. lineInfoDayService.saveOrUpdateBatch(byDate);
  891. }
  892. public void calcTurbineRFDLSameDay() {
  893. DateTime time = DateUtil.date();
  894. //date当天零点
  895. DateTime time0 = DateUtil.beginOfDay(time);
  896. List<PointInfo> entity = getEntity("AI121", "turbine");
  897. getZeroNextData(entity, time0, time);
  898. Map<String, PointInfo> turMap = entity.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  899. Map<String, String> fsMap = getEntityMap("AI066", "turbine");
  900. Map<String, TurbineInfoDay> byDate = getTurbineinfoMap(time0, entity);
  901. TurbineInfoDay infoDay;
  902. PointInfo rfdlPi;
  903. String turbineId;
  904. List<TurbineInfoDay> infoDays = new ArrayList<>();
  905. DoubleStatData stat;
  906. for (PointInfo info : entity) {
  907. turbineId = info.getTurbineId();
  908. infoDay = byDate.get(turbineId);
  909. rfdlPi = turMap.get(turbineId);
  910. double v = (rfdlPi.getPointDatas().get(1).getValue() - rfdlPi.getPointDatas().get(0).getValue()) * rfdlPi.getCoef();
  911. if (v < 0 || v > 1000000) {
  912. v = 0;
  913. } else if (v > 30000) {
  914. v = v / (v % 30000 + 3);
  915. }
  916. infoDay.setRfdl(v);
  917. stat = adapter.getHistoryStat(goldenUri(), fsMap.get(turbineId), time0.getTime(), time.getTime());
  918. if (stat == null) {
  919. infoDay.setPjfs(0.0);
  920. } else {
  921. infoDay.setPjfs(stat.getAvg().getValue());
  922. }
  923. infoDays.add(infoDay);
  924. }
  925. turbineInfoDayService.saveOrUpdateBatch(infoDays);
  926. }
  927. public void calcTurbine5s2SameDay() {
  928. DateTime time = DateUtil.date();
  929. //date当天零点
  930. DateTime time0 = DateUtil.beginOfDay(time);
  931. //风速
  932. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  933. //功率
  934. List<PointInfo> entityGl = getEntity("AI114", "turbine");
  935. //状态
  936. List<PointInfo> entityZT = getEntity("MXZT", "turbine");
  937. Map<String, Map<String, PointInfo>> ztMapMapInfos = entityZT.stream().collect(Collectors.groupingBy(PointInfo::getStationId, Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
  938. Map<String, TurbineInfoDay> dayMap = getTurbineinfoMap(time0, entityFs);
  939. List<TurbineInfoDay> infoDays = new ArrayList<>();
  940. Map<String, Map<String, PointInfo>> fsMapMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId, Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
  941. Map<String, Map<String, PointInfo>> glMapMap = entityGl.stream().collect(Collectors.groupingBy(PointInfo::getStationId, Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
  942. ztMapMapInfos.forEach((stId, ztMapInfo) -> ztMapInfo.forEach((wtId, ztInfo) -> {
  943. //0 待机,1 手动停机,2 正常发电,3 发电降出力,4 故障,5 故障受累,6 检修,7 检修受累,8 限电降出力,
  944. // 9 限电停机,10 电网受累,11 环境受累,12 通讯中断,13 设备离线
  945. TurbineInfoDay infoDay = dayMap.get(wtId);
  946. PointInfo fspi = fsMapMap.get(stId).get(wtId);
  947. PointInfo glpi = glMapMap.get(stId).get(wtId);
  948. getSnapDataByEntity(fspi, time0, time, 15);
  949. getSnapDataByEntity(glpi, time0, time, 15);
  950. getSnapDataByEntity(ztInfo, taosUri(), time0, time, 15);
  951. List<PointData> fsData = fspi.getPointDatas();
  952. fsData = fsData.stream().peek(pd -> pd.setDoubleValue(NumberUtil.round(pd.getValue() > 25 ? 25.0 : pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
  953. Map<String, Double> loss = getTurbinePowerLoss(infoDay.getRfdl(), ztInfo, fsData, glpi.getPointDatas());
  954. infoDay.setJhjxss(loss.get("jxss") + loss.get("sdtj"));
  955. infoDay.setFjhjxss(loss.get("gzss") + loss.get("djss") + loss.get("fdjcl"));
  956. infoDay.setXdss(loss.get("xdjcl") + loss.get("xdtj"));
  957. infoDay.setSlss(0.0);
  958. infoDay.setDjss(loss.get("djss"));
  959. infoDay.setGzss(loss.get("gzss"));
  960. if (infoDay.getRfdl() == 0) {
  961. infoDay.setXnss(0.0);
  962. } else {
  963. infoDay.setXnss(loss.get("xnss"));
  964. }
  965. infoDay.setLlfdl(infoDay.getRfdl() + infoDay.getJhjxss() + infoDay.getFjhjxss() + infoDay.getXdss() + infoDay.getSlss() + infoDay.getXnss());
  966. infoDays.add(infoDay);
  967. }));
  968. turbineInfoDayService.saveOrUpdateBatch(infoDays);
  969. }
  970. public void calcLineRfdlSameDay() {
  971. //date当天零点
  972. DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
  973. List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
  974. entity = entity.stream().filter(e -> !"".equals(e.getProjectId())).collect(Collectors.toList());
  975. getZeroNextData(entity, time0);
  976. Map<String, PointInfo> rfdlMap = entity.stream().collect(Collectors.toMap(PointInfo::getLineId, Function.identity()));
  977. List<LineInfoDay> byDate = getLineinfoByDate(time0, entity);
  978. PointInfo rfdlPi;
  979. int v;
  980. for (LineInfoDay day : byDate) {
  981. rfdlPi = rfdlMap.get(day.getLineId());
  982. v = (int) ((rfdlPi.getPointDatas().get(1).getValue() - rfdlPi.getPointDatas().get(0).getValue()) * rfdlPi.getCoef());
  983. if (v < 0 || v > 30000000) v = 0;
  984. day.setRfdl(v);
  985. }
  986. lineInfoDayService.saveOrUpdateBatch(byDate);
  987. }
  988. public void calcLineRfdl(Date date, String stId) {
  989. //date当天零点
  990. DateTime time = DateUtil.beginOfDay(date);
  991. //date昨天零点
  992. DateTime time0 = DateUtil.offsetDay(time, -1);
  993. List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
  994. entity = entity.stream().filter(e -> StrUtil.isNotEmpty(e.getProjectId()) && Objects.equals(stId, e.getStationId())).collect(Collectors.toList());
  995. getZeroNextData(entity, time0, time);
  996. Map<String, PointInfo> swdlMap = entity.stream().collect(Collectors.toMap(PointInfo::getLineId, Function.identity()));
  997. List<LineInfoDay> byDate = getLineinfoByDate2(time0, entity);
  998. String lineId;
  999. PointInfo swdlPi;
  1000. int v = 0;
  1001. for (LineInfoDay day : byDate) {
  1002. lineId = day.getLineId();
  1003. swdlPi = swdlMap.get(lineId);
  1004. v = (int) ((swdlPi.getPointDatas().get(1).getValue() - swdlPi.getPointDatas().get(0).getValue()) * swdlPi.getCoef());
  1005. if (v < 0 || v > 30000000) v = 0;
  1006. day.setRfdl(v);
  1007. }
  1008. lineInfoDayService.saveOrUpdateBatch(byDate);
  1009. }
  1010. public void calcLineDjlRfdl(Date date) {
  1011. //date当天零点
  1012. DateTime time = DateUtil.beginOfDay(date);
  1013. //date昨天零点
  1014. DateTime time0 = DateUtil.offsetDay(time, -1);
  1015. //date当天零点加三分钟
  1016. DateTime time2 = DateUtil.offsetMinute(time, 3);
  1017. //date昨天零点加三分钟
  1018. DateTime time1 = DateUtil.offsetMinute(time0, 3);
  1019. PointInfo pi = new PointInfo();
  1020. pi.setUniformCode("Z-ZXYG-JX");
  1021. pi.setLineId("all");
  1022. List<PointInfo> entity = pointService.getByEntity(pi);
  1023. // entity = entity.stream().filter(e -> e.getStationId().equals("GJNY_SXGS_ZZ_FDC_STA")).collect(Collectors.toList());
  1024. String keys = pointInfos2Keys(entity);
  1025. Map<String, PointData> latest2 = adapter.getHistorySection(goldenUri(), keys, time2.getTime());
  1026. Map<String, PointData> latest1 = adapter.getHistorySection(goldenUri(), keys, time1.getTime());
  1027. List<LineInfoDay> byDate = getLineinfoByDate(time0);
  1028. Map<String, LineInfoDay> collect = new HashMap<>();
  1029. if (!byDate.isEmpty()) {
  1030. collect = byDate.stream().collect(Collectors.toMap(LineInfoDay::getLineId, Function.identity()));
  1031. }
  1032. List<LineInfoDay> list = new ArrayList<>();
  1033. for (PointInfo info : entity) {
  1034. LineInfoDay day;
  1035. if (byDate.isEmpty()) {
  1036. day = new LineInfoDay();
  1037. day.setStationId(info.getStationId());
  1038. day.setProjectId(info.getProjectId());
  1039. day.setLineId(info.getLineId());
  1040. day.setRecordDate(time0);
  1041. } else {
  1042. day = collect.get(info.getLineId());
  1043. }
  1044. day.setRfdl((int) ((latest2.get(info.getPointKey()).getValue() - latest1.get(info.getPointKey()).getValue()) * info.getCoef()));
  1045. if (day.getRfdl() <= 0 || day.getRfdl() > 30000000) {
  1046. day.setRfdl(0);
  1047. }
  1048. list.add(day);
  1049. }
  1050. lineInfoDayService.saveOrUpdateBatch(list);
  1051. }
  1052. public int test(Date date, String key, int coef) {
  1053. //date当天零点
  1054. DateTime time = DateUtil.beginOfDay(date);
  1055. //date昨天零点
  1056. DateTime time0 = DateUtil.offsetDay(time, -1);
  1057. PointInfo info = new PointInfo();
  1058. info.setPointKey(key);
  1059. getZeroNextData(Collections.singletonList(info), time0, time);
  1060. int swdl = (int) ((info.getPointDatas().get(1).getValue() - info.getPointDatas().get(0).getValue()) * coef);
  1061. return swdl;
  1062. }
  1063. public void calcStationZhcydl(Date date) {
  1064. //date当天零点
  1065. DateTime time = DateUtil.beginOfDay(date);
  1066. //date昨天零点
  1067. DateTime time0 = DateUtil.offsetDay(time, -1);
  1068. QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
  1069. wrapper.select("sum(rfdl) rfdl,station_id").eq("record_date", time0).groupBy("station_id");
  1070. List<LineInfoDay> list = lineInfoDayService.list(wrapper);
  1071. List<StationInfoDay> byDate = getStationinfoByDate(time0);
  1072. // list = list.stream().filter(b -> b.getStationId().equals("GJNY_SXGS_ZZ_FDC_STA")).collect(Collectors.toList());
  1073. Map<String, StationInfoDay> collect = new HashMap<>();
  1074. if (!byDate.isEmpty()) {
  1075. collect = byDate.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  1076. }
  1077. StationInfoDay infoDay;
  1078. List<StationInfoDay> infoDays = new ArrayList<>();
  1079. for (LineInfoDay day : list) {
  1080. if (byDate.isEmpty()) {
  1081. infoDay = new StationInfoDay();
  1082. infoDay.setStationId(day.getStationId());
  1083. infoDay.setRecordDate(time0);
  1084. } else {
  1085. infoDay = collect.get(day.getStationId());
  1086. }
  1087. infoDay.setRfdl(day.getRfdl());
  1088. infoDay.setZhcydl(infoDay.getRfdl() + infoDay.getGwdl() - infoDay.getSwdl());
  1089. infoDays.add(infoDay);
  1090. }
  1091. stationInfoDayService.saveOrUpdateBatch(infoDays);
  1092. }
  1093. public void calcStationHourPjglRfdl(Date hour) {
  1094. //hour整点
  1095. DateTime time = DateUtil.beginOfHour(hour);
  1096. //1小时前
  1097. DateTime time0 = DateUtil.offsetHour(time, -1);
  1098. //当天零点
  1099. DateTime rft = DateUtil.beginOfDay(time);
  1100. List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
  1101. //出线
  1102. List<PointInfo> entityCx = getEntity("AGC001", "booster");
  1103. Map<String, PointInfo> statMapCx = getStatDataByEntity(entityCx, goldenUri(), time0, time, PointInfo::getStationId);
  1104. List<StationInfoHour> byHours = getStationinfoByHour(time, entityCx);
  1105. entity = entity.stream().filter(e -> !"".equals(e.getProjectId())).collect(Collectors.toList());
  1106. if (time.getHours() == 0) {
  1107. getSectionDataByEntity(entity, goldenUri(), DateUtil.offsetDay(rft, -1), time);
  1108. } else {
  1109. getSectionDataByEntity(entity, goldenUri(), rft, time);
  1110. }
  1111. Map<String, List<PointInfo>> stMap = entity.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  1112. for (StationInfoHour byHour : byHours) {
  1113. List<PointInfo> pis = stMap.get(byHour.getStationId());
  1114. double dl = 0, v = 0;
  1115. List<PointData> pds;
  1116. for (PointInfo pi : pis) {
  1117. pds = pi.getPointDatas();
  1118. if (pds.size() > 1) v = (pds.get(1).getValue() - pds.get(0).getValue()) * pi.getCoef();
  1119. dl += (v < 0 || v > 30000000) ? 0 : v;
  1120. }
  1121. byHour.setRfdl(dl);
  1122. PointInfo info = statMapCx.get(byHour.getStationId());
  1123. double v1 = info.getPointDatas().get(0).getValue();
  1124. byHour.setPjgl(v1 <= 0 ? 0 : v1 * info.getCoef());
  1125. }
  1126. stationInfoHourService.saveOrUpdateBatch(byHours);
  1127. }
  1128. public void calcStationMinRfdl(Date hour) {
  1129. //hour整分钟
  1130. DateTime time = DateUtil.beginOfMinute(hour);
  1131. //当天零点
  1132. DateTime rft = DateUtil.beginOfDay(time);
  1133. List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
  1134. entity = entity.stream().filter(e -> !"".equals(e.getProjectId())).collect(Collectors.toList());
  1135. List<StationInfoMin> byHours = getStationinfoByMin(time, entity);
  1136. getSectionDataByEntity(entity, goldenUri(), rft, time);
  1137. Map<String, List<PointInfo>> stMap = entity.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  1138. for (StationInfoMin byHour : byHours) {
  1139. List<PointInfo> pis = stMap.get(byHour.getStationId());
  1140. double dl = 0, v = 0;
  1141. List<PointData> pds;
  1142. for (PointInfo pi : pis) {
  1143. pds = pi.getPointDatas();
  1144. if (pds.size() > 1) v = (pds.get(1).getValue() - pds.get(0).getValue()) * pi.getCoef();
  1145. dl += (v < 0 || v > 30000000) ? 0 : v;
  1146. }
  1147. byHour.setRfdl(dl);
  1148. }
  1149. stationInfoMinService.saveOrUpdateBatch(byHours);
  1150. }
  1151. public void calcStationHourPJGL(Date hour) {
  1152. hour = DateUtil.beginOfHour(hour);
  1153. DateTime start = DateUtil.offsetHour(hour, -1);
  1154. //出线
  1155. List<PointInfo> entityCx = getEntity("AGC001", "booster");
  1156. Map<String, PointInfo> statMapCx = getStatDataByEntity(entityCx, goldenUri(), start, hour, PointInfo::getStationId);
  1157. List<StationInfoHour> byHours = getStationinfoByHour(hour, entityCx);
  1158. for (StationInfoHour byHour : byHours) {
  1159. PointInfo info = statMapCx.get(byHour.getStationId());
  1160. double v = info.getPointDatas().get(0).getValue();
  1161. if (v < 0) {
  1162. v = 0;
  1163. } else {
  1164. v = v * info.getCoef();
  1165. }
  1166. byHour.setPjgl(v);
  1167. }
  1168. stationInfoHourService.saveOrUpdateBatch(byHours);
  1169. }
  1170. public void calcStationRfdlFj(Date date) {
  1171. //date当天零点
  1172. DateTime time = DateUtil.beginOfDay(date);
  1173. //date昨天零点
  1174. DateTime time0 = DateUtil.offsetDay(time, -1);
  1175. QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
  1176. wrapper.select("sum(rfdl) rfdl,station_id").eq("record_date", time0).groupBy("station_id");
  1177. List<TurbineInfoDay> list = turbineInfoDayService.list(wrapper);
  1178. Map<String, TurbineInfoDay> dayMap = list.stream().collect(Collectors.toMap(TurbineInfoDay::getStationId, Function.identity()));
  1179. List<StationInfoDay> byDate = getStationinfoByDate(time0);
  1180. TurbineInfoDay tDay;
  1181. for (StationInfoDay day : byDate) {
  1182. tDay = dayMap.get(day.getStationId());
  1183. day.setRfdlFj(tDay.getRfdl());
  1184. }
  1185. stationInfoDayService.saveOrUpdateBatch(byDate);
  1186. }
  1187. public void calcTurbineRFDL(Date date) {
  1188. //date当天零点
  1189. DateTime time = DateUtil.beginOfDay(date);
  1190. //date昨天零点
  1191. DateTime time0 = DateUtil.offsetDay(time, -1);
  1192. List<PointInfo> entity = getEntity("AI121", "turbine");
  1193. getZeroNextData(entity, time0, time);
  1194. Map<String, PointInfo> turMap = entity.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  1195. Map<String, String> fsMap = getEntityMap("AI066", "turbine");
  1196. Map<String, TurbineInfoDay> byDate = getTurbineinfoMap(time0, entity);
  1197. TurbineInfoDay infoDay;
  1198. PointInfo rfdlPi;
  1199. String turbineId;
  1200. List<TurbineInfoDay> infoDays = new ArrayList<>();
  1201. DoubleStatData stat;
  1202. for (PointInfo info : entity) {
  1203. turbineId = info.getTurbineId();
  1204. infoDay = byDate.get(turbineId);
  1205. rfdlPi = turMap.get(turbineId);
  1206. double v = (rfdlPi.getPointDatas().get(1).getValue() - rfdlPi.getPointDatas().get(0).getValue()) * rfdlPi.getCoef();
  1207. if (v < 0 || v > 1000000) {
  1208. v = 0;
  1209. } else if (v > 30000) {
  1210. v = v / (v % 30000 + 3);
  1211. }
  1212. infoDay.setRfdl(v);
  1213. stat = adapter.getHistoryStat(goldenUri(), fsMap.get(turbineId), time0.getTime(), time.getTime());
  1214. if (stat == null) {
  1215. infoDay.setPjfs(0.0);
  1216. } else {
  1217. infoDay.setPjfs(stat.getAvg().getValue());
  1218. }
  1219. infoDays.add(infoDay);
  1220. }
  1221. turbineInfoDayService.saveOrUpdateBatch(infoDays);
  1222. }
  1223. /*public void calcTurbine5s(Date date) {
  1224. //date当天零点
  1225. DateTime time = DateUtil.beginOfDay(date);
  1226. //date昨天零点
  1227. DateTime time0 = DateUtil.offsetDay(time, -1);
  1228. //状态
  1229. List<PointInfo> entityZt = getEntity("MXZT", "turbine");
  1230. //功率
  1231. Map<String, String> collectGl = getEntityMap("AI114", "turbine");
  1232. //风速
  1233. Map<String, String> collectFs = getEntityMap("AI066", "turbine");
  1234. Map<String, TurbineInfoDay> dayMap = getTurbineinfoMap(time0, entityZt);
  1235. String tbId;
  1236. TurbineInfoDay infoDay;
  1237. List<TurbineInfoDay> infoDays = new ArrayList<>();
  1238. for (PointInfo info : entityZt) {
  1239. tbId = info.getTurbineId();
  1240. List<PointData> snapZt = adapter.getHistorySnap(taosUri(), info.getPointKey(), time0.getTime(), time.getTime(), 60);
  1241. //0 待机,1 手动停机,2 正常发电,3 发电降出力,4 故障,5 故障受累,6 检修,7 检修受累,8 限电降出力,
  1242. // 9 限电停机,10 电网受累,11 环境受累,12 通讯中断,13 设备离线
  1243. List<DoubleStatData> statGl = adapter.getHistoryStat2(goldenUri(), collectGl.get(tbId), time0.getTime(), time.getTime(), 60);
  1244. List<DoubleStatData> statFs = adapter.getHistoryStat2(goldenUri(), collectFs.get(tbId), time0.getTime(), time.getTime(), 60);
  1245. List<PointData> glList = statGl.stream().map(DoubleStatData::getAvg).collect(Collectors.toList());
  1246. List<PointData> fsList = statFs.stream().map(DoubleStatData::getAvg)
  1247. .peek(fs -> {
  1248. if (fs.getValue() < 25) {
  1249. fs.setDoubleValue(NumberUtil.round(fs.getValue(), 2).doubleValue());
  1250. } else {
  1251. fs.setDoubleValue(25.0);
  1252. }
  1253. }).collect(Collectors.toList());
  1254. // Map<String, Double> loss = getTurbinePowerLoss(snapZt, fsList, tbId, glList);
  1255. Map<String, Double> loss = new HashMap<>();
  1256. infoDay = dayMap.get(tbId);
  1257. infoDay.setJhjxss(loss.get("jxss") + loss.get("sdtj"));
  1258. infoDay.setFjhjxss(loss.get("gzss") + loss.get("djss") + loss.get("fdjcl"));
  1259. infoDay.setXdss(loss.get("xdjcl") + loss.get("xdtj"));
  1260. infoDay.setSlss(0.0);
  1261. if (infoDay.getRfdl() == 0) {
  1262. infoDay.setXnss(0.0);
  1263. } else {
  1264. infoDay.setXnss(loss.get("xnss") * 0.1);
  1265. }
  1266. infoDay.setLlfdl(infoDay.getRfdl() + infoDay.getJhjxss() + infoDay.getFjhjxss() +
  1267. infoDay.getXdss() + infoDay.getSlss() + infoDay.getXnss());
  1268. infoDays.add(infoDay);
  1269. }
  1270. turbineInfoDayService.saveOrUpdateBatch(infoDays);
  1271. }*/
  1272. //此处加公式
  1273. public void calcStationSspjfs() {
  1274. List<PointInfo> fsEntity = getEntity("AI066", "turbine");
  1275. String keys = pointInfos2Keys(fsEntity);
  1276. Map<String, PointData> latest = adapter.getLatest(goldenUri(), keys);
  1277. Map<String, List<String>> listMap = fsEntity.stream().collect(Collectors.groupingBy(PointInfo::getStationId, Collectors.mapping(PointInfo::getPointKey, Collectors.toList())));
  1278. Map<String, String> entityMap = getEntityMap("SSPJFS", "station");
  1279. List<PointData> tsData = new ArrayList<>();
  1280. listMap.forEach((stId, keyList) -> {
  1281. double v = keyList.stream().mapToDouble(key -> latest.get(key).getValue()).average().orElse(0.0);
  1282. PointData data = new PointData();
  1283. data.setTs(System.currentTimeMillis());
  1284. data.setTagName(entityMap.get(stId));
  1285. data.setDoubleValue(v);
  1286. tsData.add(data);
  1287. });
  1288. adapter.writeHistoryBatch(taosUri(), tsData);
  1289. }
  1290. public void calcTurbine5s2(Date date) {
  1291. //date当天零点
  1292. DateTime time = DateUtil.beginOfDay(date);
  1293. //date昨天零点
  1294. DateTime time0 = DateUtil.offsetDay(time, -1);
  1295. //风速
  1296. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  1297. //功率
  1298. List<PointInfo> entityGl = getEntity("AI114", "turbine");
  1299. getSnapDataByEntity(entityFs, time0, time, 15);
  1300. getSnapDataByEntity(entityGl, time0, time, 15);
  1301. List<PointInfo> ztMapMap = calcTurbineZt(time0, time, entityFs, entityGl);
  1302. Map<String, Map<String, PointInfo>> ztMapMapInfos = ztMapMap.stream().collect(
  1303. Collectors.groupingBy(PointInfo::getStationId, Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
  1304. Map<String, TurbineInfoDay> dayMap = getTurbineinfoMap(time0, entityFs);
  1305. List<TurbineInfoDay> infoDays = new ArrayList<>();
  1306. Map<String, Map<String, List<PointData>>> fsMapMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
  1307. Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas)));
  1308. Map<String, Map<String, List<PointData>>> glMapMap = entityGl.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
  1309. Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas)));
  1310. ztMapMapInfos.forEach((stId, ztMapInfo) -> ztMapInfo.forEach((wtId, ztInfo) -> {
  1311. //0 待机,1 手动停机,2 正常发电,3 发电降出力,4 故障,5 故障受累,6 检修,7 检修受累,8 限电降出力,
  1312. // 9 限电停机,10 电网受累,11 环境受累,12 通讯中断,13 设备离线
  1313. TurbineInfoDay infoDay = dayMap.get(wtId);
  1314. Map<String, Double> loss = getTurbinePowerLoss(infoDay.getRfdl(), ztMapMapInfos.get(stId).get(wtId), fsMapMap.get(stId).get(wtId), glMapMap.get(stId).get(wtId));
  1315. infoDay.setJhjxss(loss.get("jxss") + loss.get("sdtj"));
  1316. infoDay.setFjhjxss(loss.get("gzss") + loss.get("djss") + loss.get("fdjcl"));
  1317. infoDay.setXdss(loss.get("xdjcl") + loss.get("xdtj"));
  1318. infoDay.setSlss(0.0);
  1319. infoDay.setDjss(loss.get("djss"));
  1320. infoDay.setGzss(loss.get("gzss"));
  1321. if (infoDay.getRfdl() == 0) {
  1322. infoDay.setXnss(0.0);
  1323. } else {
  1324. infoDay.setXnss(loss.get("xnss"));
  1325. }
  1326. infoDay.setLlfdl(infoDay.getRfdl() + infoDay.getJhjxss() + infoDay.getFjhjxss() +
  1327. infoDay.getXdss() + infoDay.getSlss() + infoDay.getXnss());
  1328. infoDays.add(infoDay);
  1329. }));
  1330. turbineInfoDayService.saveOrUpdateBatch(infoDays);
  1331. }
  1332. public List<PointInfo> calcTurbineZt(Date start, Date end, List<PointInfo> fsInfos, List<PointInfo> glInfos) {
  1333. List<PointInfo> turbineZt = calcTurbineDizt(start, end, 15);
  1334. List<PointInfo> turbineAizt = calcTurbineAizt(start, end, 15);
  1335. turbineZt.addAll(turbineAizt);
  1336. Map<String, Map<String, PointInfo>> ztMapMap = turbineZt.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
  1337. Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
  1338. //AGC
  1339. List<PointInfo> entityAgc = getEntity("AGC002", "booster");
  1340. getSnapDataByEntity(entityAgc, start, end, 15);
  1341. //出线
  1342. List<PointInfo> entityCx = getEntity("AGC001", "booster");
  1343. getSnapDataByEntity(entityCx, start, end, 15);
  1344. //叶轮转速给定
  1345. List<PointInfo> entityYlzsgd = getEntity("AI110", "turbine");
  1346. getSnapDataByEntity(entityYlzsgd, start, end, 15);
  1347. Map<String, PointInfo> collectAgc = entityAgc.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  1348. Map<String, PointInfo> collectCx = entityCx.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  1349. Map<String, Map<String, List<PointData>>> collectYlzsgd = entityYlzsgd.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
  1350. Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas)));
  1351. Map<String, Map<String, PointInfo>> fsMapMap = fsInfos.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
  1352. Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
  1353. Map<String, Map<String, List<PointData>>> glMapMap = glInfos.stream().collect(Collectors.groupingBy(PointInfo::getStationId,
  1354. Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas)));
  1355. ztMapMap.forEach((stId, ztMap) -> {
  1356. PointInfo agcInfo = collectAgc.get(stId);
  1357. PointInfo cxInfo = collectCx.get(stId);
  1358. Map<String, PointInfo> fsMap = fsMapMap.get(stId);
  1359. Map<String, List<PointData>> pdsZsglMap = new HashMap<>();
  1360. ztMap.forEach((wtId, zt) -> {
  1361. List<PointData> peek = fsMap.get(wtId).getPointDatas().stream().peek(pd -> pd.setDoubleValue(NumberUtil.round(pd.getValue() > 25 ? 25.0
  1362. : pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
  1363. fsMap.get(wtId).setPointDatas(peek);
  1364. List<PointData> zsglSnap = fsMap.get(wtId).getPointDatas().stream().map(pd -> {
  1365. Double v = CalcCache.fitcoef.get(wtId).get(pd.getValue());
  1366. return new PointData(pd.getTs(), v == null ? 0 : v);
  1367. }).collect(Collectors.toList());
  1368. pdsZsglMap.put(wtId, zsglSnap);
  1369. });
  1370. List<PointData> agcc = agcInfo.getPointDatas().stream().peek(agc -> {
  1371. agc.setDoubleValue(agc.getValue() * agcInfo.getCoef());
  1372. agc.setLongValue(0L);
  1373. }).collect(Collectors.toList());
  1374. agcInfo.setPointDatas(agcc);
  1375. List<PointData> cxc = cxInfo.getPointDatas().stream().peek(cx -> {
  1376. cx.setDoubleValue(cx.getValue() * cxInfo.getCoef());
  1377. cx.setLongValue(0L);
  1378. }).collect(Collectors.toList());
  1379. cxInfo.setPointDatas(cxc);
  1380. //风机风速、功率->场站风速、功率
  1381. // List<PointData> firstFs = new ArrayList<>();
  1382. // List<PointData> firstGl = new ArrayList<>();
  1383. List<PointData> firstZsgl = new ArrayList<>();
  1384. double v1, v2, v3;
  1385. for (int i = 0; i < agcInfo.getPointDatas().size(); i++) {
  1386. int finalI = i;
  1387. long ts = start.getTime() + i * 15000L;
  1388. // v1 = fsMap.values().stream().mapToDouble(pds -> pds.getPointDatas().get(finalI).getValue()).average().orElse(0.0);
  1389. // v2 = glMap.values().stream().mapToDouble(pds -> pds.getPointDatas().get(finalI).getValue()).sum();
  1390. v3 = pdsZsglMap.values().stream().mapToDouble(pds -> pds.get(finalI).getValue()).sum();
  1391. // firstFs.add(new PointData(ts, v1));
  1392. // firstGl.add(new PointData(ts, v2));
  1393. firstZsgl.add(new PointData(ts, v3));
  1394. }
  1395. List<PointData> czxd = calcStationXd2(agcInfo, cxInfo.getPointDatas(), firstZsgl);
  1396. 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";
  1397. ztMap.forEach((wtId, ztInfo) -> {
  1398. if (ybj.contains(wtId)) return;
  1399. List<PointData> fss = fsMap.get(wtId).getPointDatas();
  1400. List<PointData> gls = glMapMap.get(stId).get(wtId);
  1401. //叶轮转速给定
  1402. List<PointData> ylzsgds = collectYlzsgd.get(stId).get(wtId);
  1403. calcTurbineXd(ztInfo, gls, fss, ylzsgds, czxd);
  1404. });
  1405. });
  1406. return turbineZt;
  1407. }
  1408. public List<PointData> calcTurbineSimpleZt(Date start, Date end, Integer interval, String tbId) {
  1409. List<PointInfo> turbineZt = calcTurbineDizt(start, end, interval, tbId);
  1410. List<PointInfo> turbineAizt = calcTurbineAizt(start, end, interval, tbId);
  1411. turbineZt.addAll(turbineAizt);
  1412. Map<String, List<PointData>> collect = turbineZt.stream().collect(Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas));
  1413. return collect.get(tbId);//.stream().map(PointData::getValue).collect(Collectors.toList());
  1414. }
  1415. public void calcTurbineXd(PointInfo ztInfo, List<PointData> gls, List<PointData> fss, List<PointData> ylzsgds, List<PointData> czxd) {
  1416. Map<String, EquipmentModel> map = equipmentModelService.map();
  1417. Double capacity = map.get(ztInfo.getSpare()).getPowerProduction();
  1418. List<PointData> zts = ztInfo.getPointDatas();
  1419. for (int i = 0; i < fss.size(); i++) {
  1420. double ssgl = gls.get(i).getValue();
  1421. double ssfs = fss.get(i).getValue();
  1422. double ylzsgd = ylzsgds.get(i).getValue();
  1423. if (czxd.get(i).isBooleanValue() && ssgl < capacity * 0.9) {
  1424. if (ssfs >= 12) {
  1425. zts.get(i).setDoubleValue(8.0);
  1426. }
  1427. if (ylzsgd != 0 && ylzsgd < 17.3) {//降出力
  1428. zts.get(i).setDoubleValue(8.0);
  1429. }
  1430. }
  1431. }
  1432. }
  1433. //此处加公式
  1434. public List<PointData> calcStationXd2(PointInfo agcInfo, List<PointData> cxSnap, List<PointData> zsglSnap) {
  1435. String stId = agcInfo.getStationId();
  1436. List<PointData> agcSnap = agcInfo.getPointDatas();
  1437. List<PointData> zsgl5s = get5Avg(zsglSnap);
  1438. List<PointData> agc5s = get5Avg(agcSnap);
  1439. List<PointData> cx5s = get5Avg(cxSnap);
  1440. //场站限电
  1441. List<PointData> czxd = zsglSnap.stream().map(s -> new PointData(s.getTs(), 0.0)).collect(Collectors.toList());
  1442. //之前是否限电
  1443. boolean iszqxd = false;
  1444. for (int i = 0; i < zsglSnap.size(); i++) {
  1445. boolean isxd = false;
  1446. double zsgl = zsglSnap.get(i).getValue();
  1447. double zsgl5 = zsgl5s.get(i).getValue();
  1448. double agc = agcSnap.get(i).getValue();
  1449. double agc5 = agc5s.get(i).getValue();
  1450. double cxgl = cxSnap.get(i).getValue();
  1451. double cxgl5 = cx5s.get(i).getValue();
  1452. boolean k; //agc一直不变
  1453. //第一次初始化复制实时数据到缓存
  1454. if (CalcCache.powerCache.get(stId) == null || CalcCache.powerCache.get(stId) != agc) {
  1455. CalcCache.powerCache.put(stId, agc);
  1456. k = false;
  1457. } else {
  1458. k = true;
  1459. }
  1460. if (agc != 0) {
  1461. //如果场站限电状态为不限电
  1462. if (zsgl5 >= agcInfo.getSpare2() * 40) {
  1463. if (agc5 <= cxgl5) {
  1464. isxd = true;
  1465. } else if (iszqxd) {
  1466. if (zsgl / agc > 1.15) {
  1467. isxd = true;
  1468. } else if (zsgl > agc && agc5 - cxgl5 < 400) {
  1469. isxd = true;
  1470. }
  1471. } else if (zsgl / agc >= 1.2 && agc - cxgl <= 200) {
  1472. isxd = true;
  1473. }
  1474. } else if (k) {
  1475. if (zsgl / agc >= 1.1 && agc5 - cxgl5 <= 200) {
  1476. isxd = true;
  1477. }
  1478. }
  1479. }
  1480. czxd.get(i).setBooleanValue(isxd);
  1481. iszqxd = isxd;
  1482. }
  1483. return czxd;
  1484. }
  1485. private List<PointData> get5Avg(List<PointData> pointData) {
  1486. List<PointData> result = new ArrayList<>();
  1487. for (int i = 0; i < pointData.size(); i++) {
  1488. PointData data = new PointData();
  1489. data.setTs(pointData.get(i).getTs());
  1490. double v;
  1491. if (i > 4) {
  1492. 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;
  1493. } else {
  1494. v = pointData.get(i).getValue();
  1495. }
  1496. data.setDoubleValue(v);
  1497. result.add(data);
  1498. }
  1499. return result;
  1500. }
  1501. public List<PointInfo> calcTurbineAizt(Date start, Date end, int interval) {
  1502. List<PointInfo> entityAiZt = getEntity("AI422", "state");
  1503. List<StateAi> list = stateAiService.list();
  1504. Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
  1505. getSnapDataByEntity(entityAiZt, start, end, interval);
  1506. for (PointInfo info : entityAiZt) {
  1507. List<PointData> peek = info.getPointDatas().stream().peek(pd -> {
  1508. Integer m = collectAi.get(info.getSpare()).get((int) pd.getValue());
  1509. if (m == null) m = 2;
  1510. pd.setDoubleValue(m);
  1511. }).collect(Collectors.toList());
  1512. info.setPointDatas(peek);
  1513. }
  1514. return entityAiZt;
  1515. }
  1516. public List<PointInfo> calcTurbineAizt(Date start, Date end, int interval, String tbId) {
  1517. List<PointInfo> entityAiZt = getEntity("AI422", "state");
  1518. entityAiZt = entityAiZt.stream().filter(e -> tbId.equals(e.getTurbineId())).collect(Collectors.toList());
  1519. List<StateAi> list = stateAiService.list();
  1520. Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
  1521. getSnapDataByEntity(entityAiZt, start, end, interval);
  1522. for (PointInfo info : entityAiZt) {
  1523. List<PointData> peek = info.getPointDatas().stream().peek(pd -> {
  1524. Integer m = collectAi.get(info.getSpare()).get((int) pd.getValue());
  1525. if (m == null) m = 2;
  1526. pd.setDoubleValue(m);
  1527. }).collect(Collectors.toList());
  1528. info.setPointDatas(peek);
  1529. }
  1530. return entityAiZt;
  1531. }
  1532. public List<PointInfo> calcTurbineDizt(Date start, Date end, int interval) {
  1533. List<PointInfo> entity = new ArrayList<>();
  1534. List<PointInfo> entity0 = getEntity("MX000", "state");
  1535. List<PointInfo> entity1 = getEntity("MX001", "state");
  1536. List<PointInfo> entity2 = getEntity("MX002", "state");
  1537. List<PointInfo> entity4 = getEntity("MX004", "state");
  1538. List<PointInfo> entity6 = getEntity("MX006", "state");
  1539. entity.addAll(entity0);
  1540. entity.addAll(entity1);
  1541. entity.addAll(entity2);
  1542. entity.addAll(entity4);
  1543. entity.addAll(entity6);
  1544. List<String> keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.toList());
  1545. Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), String.join(",", keys), start.getTime());
  1546. Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
  1547. wtUcPis.forEach((wtId, map) -> {
  1548. map.forEach((uc, pi) -> {
  1549. List<PointData> raw = adapter.getHistoryRaw(goldenUri(), pi.getPointKey(), start.getTime(), end.getTime());
  1550. List<PointData> ds = boolPointDatasFull(latest.get(pi.getPointKey()).isBooleanValue(), raw, start.getTime(), end.getTime(), interval);
  1551. pi.setPointDatas(ds);
  1552. ThreadUtil.sleep(5);
  1553. });
  1554. List<PointData> mx000 = map.get("MX000").getPointDatas();
  1555. PointData data0;
  1556. for (int i = 0; i < mx000.size(); i++) {
  1557. data0 = mx000.get(i);
  1558. if (data0.getValue() == 1.0) {
  1559. data0.setDoubleValue(0.0);
  1560. data0.setBooleanValue(false);
  1561. } else if (map.get("MX001").getPointDatas().get(i).getValue() == 1.0) {
  1562. data0.setDoubleValue(1.0);
  1563. } else if (map.get("MX002").getPointDatas().get(i).getValue() == 1.0) {
  1564. data0.setDoubleValue(2.0);
  1565. } else if (map.get("MX004").getPointDatas().get(i).getValue() == 1.0) {
  1566. data0.setDoubleValue(4.0);
  1567. } else if (map.get("MX006").getPointDatas().get(i).getValue() == 1.0) {
  1568. data0.setDoubleValue(6.0);
  1569. } else {
  1570. // System.out.println(wtId + data0.getTs() + ":di无对应状态!");
  1571. data0.setDoubleValue(2.0);
  1572. }
  1573. }
  1574. map.get("MX001").setPointDatas(null);
  1575. map.get("MX002").setPointDatas(null);
  1576. map.get("MX004").setPointDatas(null);
  1577. map.get("MX006").setPointDatas(null);
  1578. });
  1579. return entity0;
  1580. }
  1581. public List<PointInfo> calcTurbineDizt(Date start, Date end, int interval, String tbId) {
  1582. List<PointInfo> entity = new ArrayList<>();
  1583. List<PointInfo> entity0 = getEntity("MX000", "state");
  1584. List<PointInfo> entity1 = getEntity("MX001", "state");
  1585. List<PointInfo> entity2 = getEntity("MX002", "state");
  1586. List<PointInfo> entity4 = getEntity("MX004", "state");
  1587. List<PointInfo> entity6 = getEntity("MX006", "state");
  1588. entity0 = entity0.stream().filter(e -> tbId.equals(e.getTurbineId())).collect(Collectors.toList());
  1589. entity1 = entity1.stream().filter(e -> tbId.equals(e.getTurbineId())).collect(Collectors.toList());
  1590. entity2 = entity2.stream().filter(e -> tbId.equals(e.getTurbineId())).collect(Collectors.toList());
  1591. entity4 = entity4.stream().filter(e -> tbId.equals(e.getTurbineId())).collect(Collectors.toList());
  1592. entity6 = entity6.stream().filter(e -> tbId.equals(e.getTurbineId())).collect(Collectors.toList());
  1593. entity.addAll(entity0);
  1594. entity.addAll(entity1);
  1595. entity.addAll(entity2);
  1596. entity.addAll(entity4);
  1597. entity.addAll(entity6);
  1598. List<String> keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.toList());
  1599. Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), String.join(",", keys), start.getTime());
  1600. Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
  1601. wtUcPis.forEach((wtId, map) -> {
  1602. map.forEach((uc, pi) -> {
  1603. List<PointData> raw = adapter.getHistoryRaw(goldenUri(), pi.getPointKey(), start.getTime(), end.getTime());
  1604. List<PointData> ds = boolPointDatasFull(latest.get(pi.getPointKey()).isBooleanValue(), raw, start.getTime(), end.getTime(), interval);
  1605. pi.setPointDatas(ds);
  1606. ThreadUtil.sleep(5);
  1607. });
  1608. List<PointData> mx000 = map.get("MX000").getPointDatas();
  1609. PointData data0;
  1610. for (int i = 0; i < mx000.size(); i++) {
  1611. data0 = mx000.get(i);
  1612. if (data0.getValue() == 1.0) {
  1613. data0.setDoubleValue(0.0);
  1614. data0.setBooleanValue(false);
  1615. } else if (map.get("MX001").getPointDatas().get(i).getValue() == 1.0) {
  1616. data0.setDoubleValue(1.0);
  1617. } else if (map.get("MX002").getPointDatas().get(i).getValue() == 1.0) {
  1618. data0.setDoubleValue(2.0);
  1619. } else if (map.get("MX004").getPointDatas().get(i).getValue() == 1.0) {
  1620. data0.setDoubleValue(4.0);
  1621. } else if (map.get("MX006").getPointDatas().get(i).getValue() == 1.0) {
  1622. data0.setDoubleValue(6.0);
  1623. } else {
  1624. // System.out.println(wtId + data0.getTs() + ":di无对应状态!");
  1625. data0.setDoubleValue(2.0);
  1626. }
  1627. }
  1628. map.get("MX001").setPointDatas(null);
  1629. map.get("MX002").setPointDatas(null);
  1630. map.get("MX004").setPointDatas(null);
  1631. map.get("MX006").setPointDatas(null);
  1632. });
  1633. return entity0;
  1634. }
  1635. public PointInfo calcTurbineAizt2(PointInfo entityAiZt, Map<String, Map<Integer, Integer>> collectAi, Date start, Date end, int interval) {
  1636. if (entityAiZt == null) return null;
  1637. getSnapDataByEntity(entityAiZt, start, end, interval);
  1638. Map<Integer, Integer> integerMap = collectAi.get(entityAiZt.getSpare());
  1639. List<PointData> data = entityAiZt.getPointDatas().stream().peek(pd -> {
  1640. Integer m = integerMap.get((int) pd.getValue());
  1641. if (m == null) m = 2;
  1642. pd.setDoubleValue(m);
  1643. }).collect(Collectors.toList());
  1644. entityAiZt.setPointDatas(data);
  1645. return entityAiZt;
  1646. }
  1647. public PointInfo calcTurbineDizt2(Map<String, PointInfo> wtucpi, Map<String, PointData> latest, Date start, Date end, int interval) {
  1648. if (wtucpi == null) return null;
  1649. wtucpi.forEach((uc, pi) -> {
  1650. List<PointData> raw = adapter.getHistoryRaw(goldenUri(), pi.getPointKey(), start.getTime(), end.getTime());
  1651. List<PointData> ds = boolPointDatasFull(latest.get(pi.getPointKey()).isBooleanValue(), raw, start.getTime(), end.getTime(), interval);
  1652. pi.setPointDatas(ds);
  1653. ThreadUtil.sleep(5);
  1654. });
  1655. PointInfo mx000 = wtucpi.get("MX000");
  1656. PointData data0;
  1657. for (int i = 0; i < mx000.getPointDatas().size(); i++) {
  1658. data0 = mx000.getPointDatas().get(i);
  1659. if (data0.getValue() == 1.0) {
  1660. data0.setDoubleValue(0.0);
  1661. data0.setBooleanValue(false);
  1662. } else if (wtucpi.get("MX001").getPointDatas().get(i).getValue() == 1.0) {
  1663. data0.setDoubleValue(1.0);
  1664. } else if (wtucpi.get("MX002").getPointDatas().get(i).getValue() == 1.0) {
  1665. data0.setDoubleValue(2.0);
  1666. } else if (wtucpi.get("MX004").getPointDatas().get(i).getValue() == 1.0) {
  1667. data0.setDoubleValue(4.0);
  1668. } else if (wtucpi.get("MX006").getPointDatas().get(i).getValue() == 1.0) {
  1669. data0.setDoubleValue(6.0);
  1670. } else {
  1671. System.out.println(mx000.getTurbineId() + data0.getTs() + ":di无对应状态!");
  1672. data0.setDoubleValue(2.0);
  1673. }
  1674. }
  1675. wtucpi.get("MX001").setPointDatas(null);
  1676. wtucpi.get("MX002").setPointDatas(null);
  1677. wtucpi.get("MX004").setPointDatas(null);
  1678. wtucpi.get("MX006").setPointDatas(null);
  1679. return mx000;
  1680. }
  1681. public List<PointData> boolPointDatasFull(boolean v, List<PointData> data, long startTime, long endTime, int interval) {
  1682. int j = 0, m = 0;
  1683. List<PointData> data2 = new ArrayList<>();
  1684. for (long i = startTime; i <= endTime; i += interval * 1000L) {
  1685. PointData dt = new PointData();
  1686. dt.setTs(i);
  1687. data2.add(dt);
  1688. //超出范围
  1689. if (j >= data.size() - 1) continue;
  1690. if (i < data.get(j).getTs()) {
  1691. if (m == 0) {
  1692. dt.setBooleanValue(v);
  1693. } else {
  1694. dt.setBooleanValue(data.get(j - 1).isBooleanValue());
  1695. }
  1696. } else {
  1697. dt.setBooleanValue(data.get(j).isBooleanValue());
  1698. j++;
  1699. m++;
  1700. }
  1701. }
  1702. return data2;
  1703. }
  1704. public List<PointData> doublePointDatasFull(double v, List<PointData> data, long startTime, long endTime, int interval) {
  1705. int j = 0, m = 0;
  1706. List<PointData> data2 = new ArrayList<>();
  1707. for (long i = startTime; i <= endTime; i += interval * 1000L) {
  1708. PointData dt = new PointData();
  1709. dt.setTs(i);
  1710. data2.add(dt);
  1711. //超出范围
  1712. if (j >= data.size() - 1) continue;
  1713. if (i < data.get(j).getTs()) {
  1714. if (m == 0) {
  1715. dt.setDoubleValue(v);
  1716. } else {
  1717. dt.setDoubleValue(data.get(j - 1).getValue());
  1718. }
  1719. } else {
  1720. dt.setDoubleValue(data.get(j).getValue());
  1721. j++;
  1722. m++;
  1723. }
  1724. }
  1725. return data2;
  1726. }
  1727. public void calcGlqxnh(Date start, Date end) {
  1728. //风速
  1729. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  1730. //功率
  1731. List<PointInfo> entityGl = getEntity("AI114", "turbine");
  1732. Map<String, PointInfo> glMap = entityGl.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  1733. Map<String, EquipmentModel> map = equipmentModelService.map();
  1734. List<PointInfo> entity = new ArrayList<>();
  1735. List<PointInfo> entity0 = getEntity("MX000", "state");
  1736. List<PointInfo> entity1 = getEntity("MX001", "state");
  1737. List<PointInfo> entity2 = getEntity("MX002", "state");
  1738. List<PointInfo> entity4 = getEntity("MX004", "state");
  1739. List<PointInfo> entity6 = getEntity("MX006", "state");
  1740. entity.addAll(entity0);
  1741. entity.addAll(entity1);
  1742. entity.addAll(entity2);
  1743. entity.addAll(entity4);
  1744. entity.addAll(entity6);
  1745. List<String> keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.toList());
  1746. Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), String.join(",", keys), start.getTime());
  1747. Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
  1748. List<PointInfo> entityAiZt = getEntity("AI422", "state");
  1749. Map<String, PointInfo> aiztMap = entityAiZt.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  1750. List<StateAi> list = stateAiService.list();
  1751. Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
  1752. // Map<String, Map<Double,Double>> fitMap = new HashMap<>();
  1753. // entityFs = entityFs.stream().filter(ef -> !CalcCache.keys.contains(ef.getTurbineId())).collect(Collectors.toList());
  1754. for (PointInfo ef : entityFs) {
  1755. String wtId = ef.getTurbineId();
  1756. PointInfo glInfo = glMap.get(wtId);
  1757. getSnapDataByEntity(ef, start, end, 60);
  1758. getSnapDataByEntity(glInfo, start, end, 60);
  1759. List<PointData> peek = ef.getPointDatas().stream().peek(pd -> pd.setDoubleValue(NumberUtil.round(pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
  1760. ef.setPointDatas(peek);
  1761. PointInfo turbineZt = calcTurbineDizt2(wtUcPis.get(wtId), latest, start, end, 60);
  1762. PointInfo turbineAizt = calcTurbineAizt2(aiztMap.get(wtId), collectAi, start, end, 60);
  1763. Map<Double, Double> fit = new TreeMap<>();
  1764. if (turbineZt != null) {
  1765. double capacity = map.get(turbineZt.getSpare()).getPowerProduction();
  1766. fit = dataProcessAndFit(ef, glInfo, turbineZt, CalcCache.bzgl.get(turbineZt.getSpare()), capacity);
  1767. // fitMap.put(wtId, fit);
  1768. turbineZt.setPointDatas(null);
  1769. }
  1770. if (turbineAizt != null) {
  1771. double capacity = map.get(turbineAizt.getSpare()).getPowerProduction();
  1772. fit = dataProcessAndFit(ef, glInfo, turbineAizt, CalcCache.bzgl.get(turbineAizt.getSpare()), capacity);
  1773. // fitMap.put(wtId, fit);
  1774. turbineAizt.setPointDatas(null);
  1775. }
  1776. ef.setPointDatas(null);
  1777. glInfo.setPointDatas(null);
  1778. String key = "glqxnh:" + (end.getMonth() + 1) + ":" + wtId;
  1779. stringRedisTemplate.opsForValue().set(key, JSON.toJSONString(fit));
  1780. CalcCache.fitcoef.put(key, new ConcurrentHashMap<>(fit));
  1781. }
  1782. System.out.println("苹果天涯");
  1783. // stringRedisTemplate.opsForValue().set("glqxnh", JSON.toJSONString(fitMap));
  1784. }
  1785. public void calcGlqxnhSurplus(Date start, Date end) {
  1786. //风速
  1787. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  1788. //功率
  1789. List<PointInfo> entityGl = getEntity("AI114", "turbine");
  1790. Map<String, PointInfo> glMap = entityGl.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  1791. Map<String, EquipmentModel> map = equipmentModelService.map();
  1792. List<PointInfo> entity = new ArrayList<>();
  1793. List<PointInfo> entity0 = getEntity("MX000", "state");
  1794. List<PointInfo> entity1 = getEntity("MX001", "state");
  1795. List<PointInfo> entity2 = getEntity("MX002", "state");
  1796. List<PointInfo> entity4 = getEntity("MX004", "state");
  1797. List<PointInfo> entity6 = getEntity("MX006", "state");
  1798. entity.addAll(entity0);
  1799. entity.addAll(entity1);
  1800. entity.addAll(entity2);
  1801. entity.addAll(entity4);
  1802. entity.addAll(entity6);
  1803. List<String> keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.toList());
  1804. Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), String.join(",", keys), start.getTime());
  1805. Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
  1806. List<PointInfo> entityAiZt = getEntity("AI422", "state");
  1807. Map<String, PointInfo> aiztMap = entityAiZt.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  1808. List<StateAi> list = stateAiService.list();
  1809. Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
  1810. // Map<String, Map<Double,Double>> fitMap = new HashMap<>();
  1811. entityFs = entityFs.stream().filter(ef -> !CalcCache.already.contains(ef.getTurbineId())).collect(Collectors.toList());
  1812. for (PointInfo ef : entityFs) {
  1813. String wtId = ef.getTurbineId();
  1814. PointInfo glInfo = glMap.get(wtId);
  1815. getSnapDataByEntity(ef, start, end, 60);
  1816. getSnapDataByEntity(glInfo, start, end, 60);
  1817. List<PointData> peek = ef.getPointDatas().stream().peek(pd -> pd.setDoubleValue(NumberUtil.round(pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
  1818. ef.setPointDatas(peek);
  1819. PointInfo turbineZt = calcTurbineDizt2(wtUcPis.get(wtId), latest, start, end, 60);
  1820. PointInfo turbineAizt = calcTurbineAizt2(aiztMap.get(wtId), collectAi, start, end, 60);
  1821. Map<Double, Double> fit = new TreeMap<>();
  1822. if (turbineZt != null) {
  1823. double capacity = map.get(turbineZt.getSpare()).getPowerProduction();
  1824. fit = dataProcessAndFit(ef, glInfo, turbineZt, CalcCache.bzgl.get(turbineZt.getSpare()), capacity);
  1825. // fitMap.put(wtId, fit);
  1826. turbineZt.setPointDatas(null);
  1827. }
  1828. if (turbineAizt != null) {
  1829. double capacity = map.get(turbineAizt.getSpare()).getPowerProduction();
  1830. fit = dataProcessAndFit(ef, glInfo, turbineAizt, CalcCache.bzgl.get(turbineAizt.getSpare()), capacity);
  1831. // fitMap.put(wtId, fit);
  1832. turbineAizt.setPointDatas(null);
  1833. }
  1834. ef.setPointDatas(null);
  1835. glInfo.setPointDatas(null);
  1836. String key = "glqxnh:" + end.getMonth() + ":" + wtId;
  1837. stringRedisTemplate.opsForValue().set(key, JSON.toJSONString(fit));
  1838. CalcCache.fitcoef.put(key, new ConcurrentHashMap<>(fit));
  1839. }
  1840. System.out.println("苹果天涯");
  1841. // stringRedisTemplate.opsForValue().set("glqxnh", JSON.toJSONString(fitMap));
  1842. }
  1843. public Map<Double, Double> dataProcessAndFit(PointInfo fsPI, PointInfo glPI, PointInfo ztPI, Map<Double, Double> modelPowerMap, double capacity) {
  1844. System.out.println("开始拟合");
  1845. List<PointData> fsPds = fsPI.getPointDatas();
  1846. List<PointData> glPds = glPI.getPointDatas();
  1847. List<PointData> ztPds = ztPI.getPointDatas();
  1848. WeightedObservedPoints points = new WeightedObservedPoints();
  1849. if (ztPds.size() - glPds.size() == 1) ztPds.remove(glPds.size());
  1850. //数据过滤 0正常,1过滤掉
  1851. if (fsPds.size() != glPds.size() || glPds.size() != ztPds.size()) return new HashMap<>();
  1852. Double bzv;
  1853. for (int i = 0; i < ztPds.size(); i++) {
  1854. double fs = fsPds.get(i).getValue();
  1855. double gl = glPds.get(i).getValue();
  1856. // 过滤非并网值 风机状态不等于2
  1857. if (ztPds.get(i).getValue() != 2.0) {
  1858. //
  1859. } else if (fs < 0 || fs > 25 || gl < 0 || gl > capacity * 1.05) {// 按给定风速功率过滤
  1860. //
  1861. } else {
  1862. bzv = modelPowerMap.get(fs);
  1863. if (bzv == null || bzv == 0.0) {
  1864. points.add(fs, gl);
  1865. continue;
  1866. }
  1867. double k = gl / bzv; //功率曲线偏差: 保证功率/实际功率 k:偏差百分比
  1868. if (k < 0.61 || k > 1.25) {
  1869. //
  1870. } else {
  1871. points.add(fs, gl);
  1872. }
  1873. }
  1874. }
  1875. Map<Double, Double> glyc = new TreeMap<>();
  1876. PolynomialCurveFitter fitter = PolynomialCurveFitter.create(4);
  1877. try {
  1878. double[] result = fitter.fit(points.toList());
  1879. double min = calcMin(result);
  1880. System.out.println(ztPI.getTurbineId());
  1881. System.out.println(ztPI.getSpare());
  1882. System.out.println(min);
  1883. double[] max = calcMax(result);
  1884. if (min == 0 || max[0] == 0 || max[1] == 0) {
  1885. System.out.println();
  1886. }
  1887. System.out.println(max[0] + "," + max[1]);
  1888. double ru;
  1889. for (double i = 0; i < 25; i += 0.01) {
  1890. i = NumberUtil.round(i, 2).doubleValue();
  1891. if (i < 3) {
  1892. ru = 0.0;
  1893. } else if (i < min) {
  1894. ru = modelPowerMap.get(i);
  1895. } else if (i < max[0]) {
  1896. ru = calcPoly(i, result);
  1897. } else {
  1898. ru = max[1];
  1899. }
  1900. glyc.put(i, NumberUtil.round(ru, 2).doubleValue());
  1901. }
  1902. } catch (Exception e) {
  1903. System.out.println(ztPI.getTurbineId());
  1904. System.out.println(ztPI.getSpare());
  1905. System.out.println(e.getMessage());
  1906. }
  1907. System.out.println("拟合完成" + glyc);
  1908. return glyc;
  1909. }
  1910. public double calcMin(double[] coef) {
  1911. double minX = 0, minY = 9000;
  1912. for (double x = 0; x < 8; x += 0.01) {
  1913. double y = calcPoly(x, coef);
  1914. if (y < minY) {
  1915. minY = y;
  1916. minX = x;
  1917. }
  1918. }
  1919. return minX;
  1920. }
  1921. public double[] calcMax(double[] coef) {
  1922. double[] a = new double[2];
  1923. for (double x = 8; x < 16; x += 0.01) {
  1924. double y = calcPoly(x, coef);
  1925. if (y > a[1]) {
  1926. a[0] = x;
  1927. a[1] = y;
  1928. }
  1929. }
  1930. return a;
  1931. }
  1932. public void printResult(double[] r, double accuracy) {
  1933. for (double index = 0; index < 25; index += accuracy) {
  1934. System.out.println("[" + index + "," + calcPoly(index, r) + "],");
  1935. }
  1936. }
  1937. public void getSectionDataByEntity(List<PointInfo> entitys, URI uri, Date start, Date end) {
  1938. String collect = entitys.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
  1939. Map<String, PointData> section0 = adapter.getHistorySection(uri, collect, start.getTime());
  1940. Map<String, PointData> section1 = adapter.getHistorySection(uri, collect, end.getTime());
  1941. for (PointInfo entity : entitys) {
  1942. List<PointData> list = new ArrayList<>();
  1943. PointData p0 = section0.get(entity.getPointKey());
  1944. PointData p1 = section1.get(entity.getPointKey());
  1945. if (p0 != null && p1 != null) {
  1946. list.add(p0);
  1947. list.add(p1);
  1948. }
  1949. entity.setPointDatas(list);
  1950. }
  1951. }
  1952. public void getSectionDataByEntity(List<PointInfo> entitys, URI uri, Date end) {
  1953. String collect = entitys.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
  1954. Map<String, PointData> section1 = adapter.getHistorySection(uri, collect, end.getTime());
  1955. for (PointInfo entity : entitys) {
  1956. entity.setPointDatas(new ArrayList<>());
  1957. entity.getPointDatas().add(section1.get(entity.getPointKey()));
  1958. }
  1959. }
  1960. public void getSnapDataByEntity(List<PointInfo> entity, URI uri, Date start, Date end, int interval) {
  1961. for (PointInfo info : entity) {
  1962. getSnapDataByEntity(info, uri, start, end, interval);
  1963. ThreadUtil.sleep(5);
  1964. }
  1965. }
  1966. public void getSnapDataByEntity(PointInfo entity, URI uri, Date start, Date end, int interval) {
  1967. List<PointData> snap = adapter.getHistorySnap(uri, entity.getPointKey(), start.getTime(), end.getTime(), interval);
  1968. entity.setPointDatas(snap);
  1969. }
  1970. public void getSnapDataByEntity(List<PointInfo> entity, Date start, Date end, int interval) {
  1971. getSnapDataByEntity(entity, goldenUri(), start, end, interval);
  1972. }
  1973. public void getSnapDataByEntity(PointInfo entity, Date start, Date end, int interval) {
  1974. getSnapDataByEntity(entity, goldenUri(), start, end, interval);
  1975. }
  1976. public double calcPoly(String wtId, double value) {
  1977. return CalcCache.fitcoef.get(wtId).get(value);
  1978. }
  1979. public double calcPoly(double x, double[] factor) {
  1980. double y = 0;
  1981. for (int deg = 0; deg < factor.length; deg++) {
  1982. y += Math.pow(x, deg) * factor[deg];
  1983. }
  1984. return y;
  1985. }
  1986. //切入切出风速
  1987. public void cutInWindSpeed() {
  1988. //date当天零点
  1989. DateTime timeNow00 = DateUtil.beginOfDay(new Date());
  1990. //date昨天零点
  1991. DateTime timeBegin00 = DateUtil.offsetDay(timeNow00, -1);
  1992. //上个月
  1993. DateTime timeBegin2 = DateUtil.offsetMonth(timeBegin00, -1);
  1994. //上个月第一天
  1995. DateTime timeBegin1 = DateUtil.beginOfMonth(timeBegin2);
  1996. //上个月最后一天
  1997. DateTime timeEnd2 = DateUtil.endOfMonth(timeBegin2);
  1998. //上个月天数
  1999. int days = (int) DateUtil.betweenDay(timeBegin1, timeEnd2, false);
  2000. //遍历天数
  2001. for (int i = 1; i <= days; i++) {
  2002. DateTime timeNow = DateUtil.offsetDay(timeBegin1, i);
  2003. DateTime timeBegin = DateUtil.offsetDay(timeBegin1, i - 1);
  2004. List<PointInfo> turbineZt = calcTurbineAizt(timeBegin, timeNow, 60);
  2005. List<PointInfo> turbineZtDI = calcTurbineDizt(timeBegin, timeNow, 60);
  2006. turbineZt.addAll(turbineZtDI);
  2007. //所有风机的风速测点
  2008. QueryWrapper<PointInfo> queryWrapper = new QueryWrapper<>();
  2009. queryWrapper.eq("uniform_code", "AI066");
  2010. List<PointInfo> pointInfos = getEntity("AI066", "turbine");
  2011. // List<PointInfo> pointInfos = pointInfo.selectList(queryWrapper);
  2012. //定义切入风速map集合
  2013. ConcurrentHashMap<String, ConcurrentHashMap<String, Double>> mapIn = new ConcurrentHashMap<>();
  2014. //定义切出风速集合
  2015. ConcurrentHashMap<String, ConcurrentHashMap<String, Double>> mapOut = new ConcurrentHashMap<>();
  2016. //插入集合
  2017. List<TurbineInfoDay> interest = new ArrayList<>();
  2018. //更新集合
  2019. List<TurbineInfoDay> update = new ArrayList<>();
  2020. //遍历每台风机,取出每台风机的pointDatas
  2021. for (PointInfo turbine : turbineZt) {
  2022. mapIn.put(turbine.getTurbineId(), new ConcurrentHashMap<>());
  2023. mapOut.put(turbine.getTurbineId(), new ConcurrentHashMap<>());
  2024. List<PointData> pointDatas = turbine.getPointDatas();
  2025. //风速测点key
  2026. String windSpeedKey = null;
  2027. //遍历pointInfos,找出pointData1的id和pointInfos中相等的,取出pointInfo的pointKey
  2028. for (PointInfo info : pointInfos) {
  2029. if (Objects.equals(turbine.getTurbineId(), info.getTurbineId())) {
  2030. windSpeedKey = info.getPointKey();
  2031. }
  2032. }
  2033. //遍历pointDatas,取出当前状态和后一个状态
  2034. for (int k = 1; k < pointDatas.size(); k++) {
  2035. PointData pointData1 = pointDatas.get(k - 1);
  2036. PointData pointData2 = pointDatas.get(k);
  2037. double value1 = pointData1.getValue();
  2038. double value2 = pointData2.getValue();
  2039. //切入时间
  2040. long ts1;
  2041. //切出时间
  2042. long ts2;
  2043. //如果1的值为0,2的值为2,则为切入状态
  2044. if (value1 == 0 && value2 == 2) {
  2045. ts1 = pointData2.getTs();
  2046. // String stringDate = DateUtil.date(ts1).toString("yyyy-MM-dd HH:mm:ss");
  2047. // System.out.println(turbine.getTurbineId() + "切入" + stringDate);
  2048. //切入时间前5分钟
  2049. long ts11 = ts1 - 300000;
  2050. //根据风速key,从适配器取切入前5分钟的所有风速
  2051. List<PointData> pointDatas1 = adapter.getHistorySnap(goldenUri(), windSpeedKey, ts11, ts1, 10);
  2052. //平均所有风速即为平均切入风速
  2053. double avgCutInWindSpeed = pointDatas1.stream().mapToDouble(PointData::getValue).average().orElse(0);
  2054. // System.out.println(turbine.getTurbineId() + "切入风速" + avgCutInWindSpeed);
  2055. //存入map集合,外层key为turbineId,内层key为ts1,value为平均切入风速
  2056. mapIn.get(turbine.getTurbineId()).put(String.valueOf(ts1), avgCutInWindSpeed);
  2057. }
  2058. //切出
  2059. if (value1 == 2 && value2 != 2) {
  2060. ts2 = pointData2.getTs();
  2061. String stringDate = DateUtil.date(ts2).toString("yyyy-MM-dd HH:mm:ss");
  2062. // System.out.println(turbine.getTurbineId() + "切出" + stringDate);
  2063. //切出时间前5分钟
  2064. long ts22 = ts2 - 300000;
  2065. List<PointData> pointDatas2 = adapter.getHistorySnap(goldenUri(), windSpeedKey, ts22, ts2, 10);
  2066. double avgCutOutWindSpeed = pointDatas2.stream().mapToDouble(PointData::getValue).average().orElse(0);
  2067. // System.out.println(turbine.getTurbineId() + "切出风速" + avgCutOutWindSpeed);
  2068. //存入map集合,外层key为turbineId,内层key为ts2,value为平均切出风速
  2069. mapOut.get(turbine.getTurbineId()).put(String.valueOf(ts2), avgCutOutWindSpeed);
  2070. }
  2071. }
  2072. //遍历map集合,取出每个风机的所有切入风速,算一个平均值
  2073. ConcurrentHashMap<String, Double> mapTurbineValues = mapIn.get(turbine.getTurbineId());
  2074. //平均切入风速
  2075. double avgCutInWindSpeed = 0;
  2076. if (mapTurbineValues != null) {
  2077. AtomicReference<Double> sum = new AtomicReference<>(0.0);
  2078. //遍历mapTurbineValues,V大于5的舍弃,剩余算平均值
  2079. for (String key : mapTurbineValues.keySet()) {
  2080. if (mapTurbineValues.get(key) > 5) {
  2081. mapTurbineValues.remove(key);
  2082. }
  2083. }
  2084. mapTurbineValues.forEach((k1, v) -> {
  2085. sum.updateAndGet(v1 -> v1 + v);
  2086. });
  2087. //如果值为空则置0
  2088. if (sum.get() == 0) {
  2089. avgCutInWindSpeed = 0;
  2090. } else {
  2091. avgCutInWindSpeed = sum.get() / mapTurbineValues.size();
  2092. }
  2093. System.out.println(turbine.getTurbineId() + "切入平均风速" + avgCutInWindSpeed + "时间" + timeBegin);
  2094. }
  2095. //遍历map集合,取出每个风机的所有切出风速,算一个平均值
  2096. ConcurrentHashMap<String, Double> mapTurbineValues2 = mapOut.get(turbine.getTurbineId());
  2097. double avgCutOutWindSpeed;
  2098. if (mapTurbineValues2 != null) {
  2099. AtomicReference<Double> sum = new AtomicReference<>(0.0);
  2100. for (String key : mapTurbineValues2.keySet()) {
  2101. if (mapTurbineValues2.get(key) > 5) {
  2102. mapTurbineValues2.remove(key);
  2103. }
  2104. }
  2105. mapTurbineValues2.forEach((k2, v) -> {
  2106. sum.updateAndGet(v1 -> v1 + v);
  2107. });
  2108. if (sum.get() == 0) {
  2109. avgCutOutWindSpeed = 0;
  2110. } else {
  2111. avgCutOutWindSpeed = sum.get() / mapTurbineValues2.size();
  2112. }
  2113. System.out.println(turbine.getTurbineId() + "切出平均风速" + avgCutOutWindSpeed + "时间" + timeBegin);
  2114. }
  2115. //存入数据库
  2116. String turbineId = turbine.getTurbineId();
  2117. Date jdkDate = timeBegin;
  2118. System.out.println(turbineId + " " + jdkDate);
  2119. QueryWrapper<TurbineInfoDay> turbineInfoDayQueryWrapper = new QueryWrapper<>();
  2120. turbineInfoDayQueryWrapper.eq("turbine_id", turbine.getTurbineId());
  2121. turbineInfoDayQueryWrapper.eq("record_date", timeBegin);
  2122. TurbineInfoDay one = turbineInfoDayService.getOne(turbineInfoDayQueryWrapper);
  2123. System.out.println(one);
  2124. if (one == null) {
  2125. TurbineInfoDay turbineInfoDay = new TurbineInfoDay();
  2126. turbineInfoDay.setTurbineId(turbine.getTurbineId());
  2127. turbineInfoDay.setRecordDate(timeBegin);
  2128. turbineInfoDay.setXfqrfs(avgCutInWindSpeed);
  2129. System.out.println(turbineInfoDay);
  2130. interest.add(turbineInfoDay);
  2131. // turbineInfoDayService.save(turbineInfoDay);
  2132. } else {
  2133. one.setXfqrfs(avgCutInWindSpeed);
  2134. System.out.println(one);
  2135. // turbineInfoDayService.updateById(one);
  2136. update.add(one);
  2137. }
  2138. }
  2139. // //批量插入
  2140. // turbineInfoDayService.saveBatch(interest);
  2141. // //批量更新
  2142. // turbineInfoDayService.updateBatchById(update);
  2143. // //批量插入或更新
  2144. turbineInfoDayService.saveOrUpdateBatch(interest);
  2145. turbineInfoDayService.saveOrUpdateBatch(update);
  2146. }
  2147. }
  2148. //算额定风速
  2149. public void calcGlqxnh_edfs() {
  2150. //date当天零点
  2151. DateTime timeNow00 = DateUtil.beginOfDay(new Date());
  2152. //date昨天零点
  2153. DateTime timeBegin00 = DateUtil.offsetDay(timeNow00, -1);
  2154. //上个月
  2155. DateTime timeBegin2 = DateUtil.offsetMonth(timeBegin00, -1);
  2156. //上个月第一天
  2157. DateTime timeBegin1 = DateUtil.beginOfMonth(timeBegin2);
  2158. //上个月最后一天
  2159. DateTime timeEnd2 = DateUtil.endOfMonth(timeBegin2);
  2160. //上个月天数
  2161. int days = (int) DateUtil.betweenDay(timeBegin1, timeEnd2, false);
  2162. //遍历天数
  2163. for (int i = 1; i <= days; i++) {
  2164. DateTime end = DateUtil.offsetDay(timeBegin1, i);
  2165. DateTime start = DateUtil.offsetDay(timeBegin1, i - 1);
  2166. //风速
  2167. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  2168. //功率
  2169. List<PointInfo> entityGl = getEntity("AI114", "turbine");
  2170. Map<String, PointInfo> glMap = entityGl.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  2171. Map<String, EquipmentModel> map = equipmentModelService.map();
  2172. List<PointInfo> entity = new ArrayList<>();
  2173. List<PointInfo> entity0 = getEntity("MX000", "state");
  2174. List<PointInfo> entity1 = getEntity("MX001", "state");
  2175. List<PointInfo> entity2 = getEntity("MX002", "state");
  2176. List<PointInfo> entity4 = getEntity("MX004", "state");
  2177. List<PointInfo> entity6 = getEntity("MX006", "state");
  2178. entity.addAll(entity0);
  2179. entity.addAll(entity1);
  2180. entity.addAll(entity2);
  2181. entity.addAll(entity4);
  2182. entity.addAll(entity6);
  2183. List<String> keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.toList());
  2184. Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), String.join(",", keys), start.getTime());
  2185. Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
  2186. List<PointInfo> entityAiZt = getEntity("AI422", "state");
  2187. Map<String, PointInfo> aiztMap = entityAiZt.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  2188. List<StateAi> list = stateAiService.list();
  2189. Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
  2190. // Map<String, Map<Double,Double>> fitMap = new HashMap<>();
  2191. //插入集合
  2192. List<TurbineInfoDay> interest = new ArrayList<>();
  2193. //更新集合
  2194. List<TurbineInfoDay> update = new ArrayList<>();
  2195. for (PointInfo ef : entityFs) {
  2196. String wtId = ef.getTurbineId();
  2197. PointInfo glInfo = glMap.get(wtId);
  2198. getSnapDataByEntity(ef, start, end, 60);
  2199. getSnapDataByEntity(glInfo, start, end, 60);
  2200. List<PointData> peek = ef.getPointDatas().stream().peek(pd -> pd.setDoubleValue(NumberUtil.round(pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
  2201. ef.setPointDatas(peek);
  2202. try {
  2203. PointInfo turbineZt = calcTurbineDizt2(wtUcPis.get(wtId), latest, start, end, 60);
  2204. PointInfo turbineAizt = calcTurbineAizt2(aiztMap.get(wtId), collectAi, start, end, 60);
  2205. Map<Double, Double> fit = new TreeMap<>();
  2206. double capacity = 2000;
  2207. if (turbineZt != null) {
  2208. System.out.println("数据处理拟合");
  2209. capacity = map.get(turbineZt.getSpare()).getPowerProduction();
  2210. fit = dataProcessAndFit(ef, glInfo, turbineZt, CalcCache.bzgl.get(turbineZt.getSpare()), capacity);
  2211. // fitMap.put(wtId, fit);
  2212. turbineZt.setPointDatas(null);
  2213. }
  2214. if (turbineAizt != null) {
  2215. System.out.println("数据处理拟合");
  2216. capacity = map.get(turbineAizt.getSpare()).getPowerProduction();
  2217. fit = dataProcessAndFit(ef, glInfo, turbineAizt, CalcCache.bzgl.get(turbineAizt.getSpare()), capacity);
  2218. // fitMap.put(wtId, fit);
  2219. turbineAizt.setPointDatas(null);
  2220. }
  2221. ef.setPointDatas(null);
  2222. glInfo.setPointDatas(null);
  2223. //存redis
  2224. // stringRedisTemplate.opsForValue().set("glqxnh:" + end.getMonth() + ":" + wtId, JSON.toJSONString(fit));
  2225. System.out.println("拟合曲线的大小" + fit.size() + ":" + wtId);
  2226. //符合条件的风速和
  2227. List<Double> listDouble = new ArrayList<>();
  2228. //遍历fit集合,取出值与capacity相等的key
  2229. if (!fit.isEmpty()) {
  2230. for (double key : fit.keySet()) {
  2231. Double v = fit.get(key);
  2232. //如果v-capacity的值小于10大于-10,则把key加入listDouble
  2233. if ((Math.abs(v - capacity) <= 10) && Math.abs(v - capacity) >= -10) {
  2234. listDouble.add(key);
  2235. }
  2236. }
  2237. }
  2238. //取出listDouble的值求平均值
  2239. double agValue = 0;
  2240. if (!listDouble.isEmpty()) {
  2241. for (Double aDouble : listDouble) {
  2242. agValue += aDouble;
  2243. }
  2244. agValue = agValue / listDouble.size();
  2245. }
  2246. System.out.println("wtId:" + wtId + "agValue平均额定风速:" + agValue);
  2247. //存入数据库
  2248. System.out.println(wtId + " " + start);
  2249. QueryWrapper<TurbineInfoDay> turbineInfoDayQueryWrapper = new QueryWrapper<>();
  2250. turbineInfoDayQueryWrapper.eq("turbine_id", wtId);
  2251. turbineInfoDayQueryWrapper.eq("record_date", start);
  2252. TurbineInfoDay one = turbineInfoDayService.getOne(turbineInfoDayQueryWrapper);
  2253. System.out.println(one);
  2254. if (one == null) {
  2255. TurbineInfoDay turbineInfoDay = new TurbineInfoDay();
  2256. turbineInfoDay.setTurbineId(wtId);
  2257. turbineInfoDay.setRecordDate(start);
  2258. turbineInfoDay.setEdfs(agValue);
  2259. System.out.println(turbineInfoDay);
  2260. // turbineInfoDayService.save(turbineInfoDay);
  2261. interest.add(turbineInfoDay);
  2262. } else {
  2263. one.setEdfs(agValue);
  2264. System.out.println(one);
  2265. // turbineInfoDayService.updateById(one);
  2266. update.add(one);
  2267. }
  2268. } catch (Exception e) {
  2269. System.out.println(wtId + " " + start);
  2270. }
  2271. }
  2272. // //批量插入
  2273. // turbineInfoDayService.saveBatch(interest);
  2274. // //批量更新
  2275. // turbineInfoDayService.updateBatchById(update);
  2276. // //批量插入或更新
  2277. turbineInfoDayService.saveOrUpdateBatch(interest);
  2278. turbineInfoDayService.saveOrUpdateBatch(update);
  2279. }
  2280. // stringRedisTemplate.opsForValue().set("glqxnh", JSON.toJSONString(fitMap));
  2281. }
  2282. //环境温度
  2283. public void ambientTemperature() {
  2284. //date当天零点
  2285. DateTime timeNow = DateUtil.beginOfDay(new Date());
  2286. //date昨天零点
  2287. DateTime timeBegin = DateUtil.offsetDay(timeNow, -1);
  2288. //所有风机的温度
  2289. QueryWrapper<PointInfo> queryWrapper = new QueryWrapper<>();
  2290. queryWrapper.eq("uniform_code", "AI072");
  2291. List<PointInfo> pointInfos = getEntity("AI072", "turbine");
  2292. //插入集合
  2293. List<TurbineInfoDay> interest = new ArrayList<>();
  2294. //更新集合
  2295. List<TurbineInfoDay> update = new ArrayList<>();
  2296. //遍历pointInfos
  2297. for (PointInfo turbine : pointInfos) {
  2298. List<PointData> pointDatas = adapter.getHistorySnap(goldenUri(), turbine.getPointKey(), timeBegin.getTime(), timeNow.getTime(), 10);
  2299. //遍历pointDatas,取出数据算平均值
  2300. double avgCutInWindSpeed = 0;
  2301. for (PointData pointData : pointDatas) {
  2302. avgCutInWindSpeed += pointData.getValue();
  2303. }
  2304. avgCutInWindSpeed /= pointDatas.size();
  2305. //存入数据库
  2306. String turbineId = turbine.getTurbineId();
  2307. Date jdkDate = timeBegin;
  2308. System.out.println(turbineId + " " + jdkDate);
  2309. QueryWrapper<TurbineInfoDay> turbineInfoDayQueryWrapper = new QueryWrapper<>();
  2310. turbineInfoDayQueryWrapper.eq("turbine_id", turbine.getTurbineId());
  2311. turbineInfoDayQueryWrapper.eq("record_date", timeBegin);
  2312. TurbineInfoDay one = turbineInfoDayService.getOne(turbineInfoDayQueryWrapper);
  2313. System.out.println(one);
  2314. if (one == null) {
  2315. TurbineInfoDay turbineInfoDay = new TurbineInfoDay();
  2316. turbineInfoDay.setTurbineId(turbine.getTurbineId());
  2317. turbineInfoDay.setRecordDate(timeBegin);
  2318. turbineInfoDay.setHjwd(avgCutInWindSpeed);
  2319. System.out.println(turbineInfoDay);
  2320. interest.add(turbineInfoDay);
  2321. // turbineInfoDayService.save(turbineInfoDay);
  2322. } else {
  2323. one.setHjwd(avgCutInWindSpeed);
  2324. System.out.println(one);
  2325. update.add(one);
  2326. // turbineInfoDayService.updateById(one);
  2327. }
  2328. }
  2329. // //批量插入
  2330. // turbineInfoDayService.saveBatch(interest);
  2331. // //批量更新
  2332. // turbineInfoDayService.updateBatchById(update);
  2333. // //批量插入或更新
  2334. turbineInfoDayService.saveOrUpdateBatch(interest);
  2335. turbineInfoDayService.saveOrUpdateBatch(update);
  2336. }
  2337. public void writeReportPool(Date date) {
  2338. //date当天零点
  2339. DateTime time = DateUtil.beginOfDay(date);
  2340. //date昨天零点
  2341. DateTime time0 = DateUtil.offsetDay(time, -1);
  2342. DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
  2343. DateTime beginOfYear = DateUtil.beginOfYear(time0);
  2344. QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
  2345. wrapper.eq("record_date", time0);
  2346. List<StationInfoDay> days = stationInfoDayService.list(wrapper);
  2347. Map<String, StationInfoDay> dayMap = days.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  2348. wrapper = new QueryWrapper<>();
  2349. 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");
  2350. List<StationInfoDay> monthDays = stationInfoDayService.list(wrapper);
  2351. Map<String, StationInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  2352. wrapper = new QueryWrapper<>();
  2353. 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");
  2354. List<StationInfoDay> yearDays = stationInfoDayService.list(wrapper);
  2355. Map<String, StationInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  2356. // QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
  2357. // wrapperrp.eq("record_date", time0).last("and foreign_key_id = windpowerstation_id");
  2358. // List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
  2359. QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
  2360. wrapperrp.eq("record_date", time0).in("foreign_key_id", days.stream().map(StationInfoDay::getStationId).collect(Collectors.toList()));
  2361. List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
  2362. if (!pools.isEmpty()) {
  2363. StationInfoDay day, month, year;
  2364. List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
  2365. for (ProEconReportIndicatorPool pool : pools) {
  2366. String stationId = pool.getForeignKeyId();
  2367. day = dayMap.get(stationId);
  2368. pool.setRfdldb(day.getRfdl().doubleValue());
  2369. pool.setRswdldb(day.getSwdl().doubleValue());
  2370. pool.setRgwgwdldb(day.getGwdl().doubleValue());
  2371. pool.setRfdcydldb(day.getCydl().doubleValue());
  2372. pool.setRzhcydldb(day.getZhcydl().doubleValue());
  2373. month = monthMap.get(stationId);
  2374. pool.setYfdldb(month.getRfdl().doubleValue());
  2375. pool.setYswdldb(month.getSwdl().doubleValue());
  2376. pool.setYgwgwdldb(month.getGwdl().doubleValue());
  2377. pool.setYfdcydldb(month.getCydl().doubleValue());
  2378. pool.setYzhcydldb(month.getZhcydl().doubleValue());
  2379. year = yearMap.get(stationId);
  2380. pool.setNfdldb(year.getRfdl().doubleValue());
  2381. pool.setNswdldb(year.getSwdl().doubleValue());
  2382. pool.setNgwgwdldb(year.getGwdl().doubleValue());
  2383. pool.setNfdcydldb(year.getCydl().doubleValue());
  2384. pool.setNzhcydldb(year.getZhcydl().doubleValue());
  2385. poolList.add(pool);
  2386. }
  2387. reportIndicatorPoolService.saveOrUpdateBatch(poolList);
  2388. } else {
  2389. List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
  2390. for (StationInfoDay day : days) {
  2391. ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
  2392. pool.setRecordDate(time0);
  2393. pool.setForeignKeyId(day.getStationId());
  2394. poolList.add(pool);
  2395. }
  2396. reportIndicatorPoolService.saveOrUpdateBatch(poolList);
  2397. }
  2398. }
  2399. public void writeReportPoolSameDay() {
  2400. //date当天零点
  2401. DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
  2402. DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
  2403. DateTime beginOfYear = DateUtil.beginOfYear(time0);
  2404. QueryWrapper<StationInfoDay> wrapper = new QueryWrapper<>();
  2405. wrapper.eq("record_date", time0);
  2406. List<StationInfoDay> days = stationInfoDayService.list(wrapper);
  2407. Map<String, StationInfoDay> dayMap = days.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  2408. wrapper = new QueryWrapper<>();
  2409. 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");
  2410. List<StationInfoDay> monthDays = stationInfoDayService.list(wrapper);
  2411. Map<String, StationInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  2412. wrapper = new QueryWrapper<>();
  2413. 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");
  2414. List<StationInfoDay> yearDays = stationInfoDayService.list(wrapper);
  2415. Map<String, StationInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(StationInfoDay::getStationId, Function.identity()));
  2416. QueryWrapper<ProEconReportIndicatorPool> wrapperRp = new QueryWrapper<>();
  2417. wrapperRp.eq("record_date", time0).last("and foreign_key_id = windpowerstation_id");
  2418. List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperRp);
  2419. wrapperRp = new QueryWrapper<>();
  2420. wrapperRp.eq("record_date", time0).eq("foreign_key_id", "GJNY_SXGS_DBXNY_ZGS0");
  2421. ProEconReportIndicatorPool poolsCompany = reportIndicatorPoolService.getOne(wrapperRp);
  2422. StationInfoDay day, month, year;
  2423. if (pools.isEmpty()) {
  2424. pools = new ArrayList<>();
  2425. for (StationInfoDay infoDay : days) {
  2426. String stationId = infoDay.getStationId();
  2427. ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
  2428. pool.setRecordDate(time0);
  2429. pool.setForeignKeyId(stationId);
  2430. pool.setWindpowerstationId(stationId);
  2431. month = monthMap.get(stationId);
  2432. year = yearMap.get(stationId);
  2433. poolSetValueDl1(pool, infoDay, month, year);
  2434. pools.add(pool);
  2435. }
  2436. } else {
  2437. for (ProEconReportIndicatorPool pool : pools) {
  2438. String stationId = pool.getWindpowerstationId();
  2439. day = dayMap.get(stationId);
  2440. month = monthMap.get(stationId);
  2441. year = yearMap.get(stationId);
  2442. poolSetValueDl1(pool, day, month, year);
  2443. }
  2444. }
  2445. reportIndicatorPoolService.saveOrUpdateBatch(pools);
  2446. if (poolsCompany == null) {
  2447. poolsCompany = new ProEconReportIndicatorPool();
  2448. poolsCompany.setRecordDate(time0);
  2449. poolsCompany.setForeignKeyId("GJNY_SXGS_DBXNY_ZGS0");
  2450. poolsCompany.setCompanyId("GJNY_SXGS_DBXNY_ZGS");
  2451. poolSetValueDl(poolsCompany, pools);
  2452. } else {
  2453. poolSetValueDl(poolsCompany, pools);
  2454. }
  2455. reportIndicatorPoolService.saveOrUpdate(poolsCompany);
  2456. }
  2457. public void poolSetValueDl1(ProEconReportIndicatorPool pool, StationInfoDay day, StationInfoDay month, StationInfoDay year) {
  2458. pool.setRfdldb(day.getRfdl().doubleValue());
  2459. pool.setRswdldb(day.getSwdl().doubleValue());
  2460. pool.setRgwgwdldb(day.getGwdl().doubleValue());
  2461. pool.setRfdcydldb(day.getCydl().doubleValue());
  2462. pool.setRzhcydldb(day.getZhcydl().doubleValue());
  2463. pool.setYfdldb(month.getRfdl().doubleValue());
  2464. pool.setYswdldb(month.getSwdl().doubleValue());
  2465. pool.setYgwgwdldb(month.getGwdl().doubleValue());
  2466. pool.setYfdcydldb(month.getCydl().doubleValue());
  2467. pool.setYzhcydldb(month.getZhcydl().doubleValue());
  2468. pool.setNfdldb(year.getRfdl().doubleValue());
  2469. pool.setNswdldb(year.getSwdl().doubleValue());
  2470. pool.setNgwgwdldb(year.getGwdl().doubleValue());
  2471. pool.setNfdcydldb(year.getCydl().doubleValue());
  2472. pool.setNzhcydldb(year.getZhcydl().doubleValue());
  2473. }
  2474. public void poolSetValueDl(ProEconReportIndicatorPool pool, LineInfoDay day, LineInfoDay month, LineInfoDay year) {
  2475. pool.setRfdldb(day.getRfdl().doubleValue());
  2476. pool.setRswdldb(day.getSwdl());
  2477. pool.setRgwgwdldb(day.getGwdl());
  2478. pool.setRfdcydldb(day.getCydl());
  2479. pool.setRzhcydldb(day.getRfdl().doubleValue() + day.getGwdl() - day.getSwdl());
  2480. pool.setYfdldb(month.getRfdl().doubleValue());
  2481. pool.setYswdldb(month.getSwdl());
  2482. pool.setYgwgwdldb(month.getGwdl());
  2483. pool.setYfdcydldb(month.getCydl());
  2484. pool.setYzhcydldb(month.getRfdl().doubleValue() + month.getGwdl() - month.getSwdl());
  2485. pool.setNfdldb(year.getRfdl().doubleValue());
  2486. pool.setNswdldb(year.getSwdl());
  2487. pool.setNgwgwdldb(year.getGwdl());
  2488. pool.setNfdcydldb(year.getCydl());
  2489. pool.setNzhcydldb(year.getRfdl().doubleValue() + year.getGwdl() - year.getSwdl());
  2490. }
  2491. public void poolSetValueDl(ProEconReportIndicatorPool pool, List<ProEconReportIndicatorPool> pools) {
  2492. ProEconReportIndicatorPool p = sumProperties(pools, ProEconReportIndicatorPool.class);
  2493. pool.setRfdldb(p.getRfdldb());
  2494. pool.setRswdldb(p.getRswdldb());
  2495. pool.setRgwgwdldb(p.getRgwgwdldb());
  2496. pool.setRfdcydldb(p.getRfdcydldb());
  2497. pool.setRzhcydldb(p.getRzhcydldb());
  2498. pool.setYfdldb(p.getYfdldb());
  2499. pool.setYswdldb(p.getYswdldb());
  2500. pool.setYgwgwdldb(p.getYgwgwdldb());
  2501. pool.setYfdcydldb(p.getYfdcydldb());
  2502. pool.setYzhcydldb(p.getYzhcydldb());
  2503. pool.setNfdldb(p.getNfdldb());
  2504. pool.setNswdldb(p.getNswdldb());
  2505. pool.setNgwgwdldb(p.getNgwgwdldb());
  2506. pool.setNfdcydldb(p.getNfdcydldb());
  2507. pool.setNzhcydldb(p.getNzhcydldb());
  2508. }
  2509. public void writeReportPoolProject(Date date) {
  2510. //date当天零点
  2511. DateTime time = DateUtil.beginOfDay(date);
  2512. //date昨天零点
  2513. DateTime time0 = DateUtil.offsetDay(time, -1);
  2514. DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
  2515. DateTime beginOfYear = DateUtil.beginOfYear(time0);
  2516. QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
  2517. wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,project_id").eq("record_date", time0).groupBy("project_id");
  2518. List<LineInfoDay> days = lineInfoDayService.list(wrapper);
  2519. Map<String, LineInfoDay> dayMap = days.stream().collect(Collectors.toMap(LineInfoDay::getProjectId, Function.identity()));
  2520. wrapper = new QueryWrapper<>();
  2521. wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,project_id").between("record_date", beginOfMonth, time0).groupBy("project_id");
  2522. List<LineInfoDay> monthDays = lineInfoDayService.list(wrapper);
  2523. Map<String, LineInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(LineInfoDay::getProjectId, Function.identity()));
  2524. wrapper = new QueryWrapper<>();
  2525. wrapper.select("sum(rfdl) rfdl,sum(swdl) swdl,sum(gwdl) gwdl,sum(cydl) cydl,project_id").between("record_date", beginOfYear, time0).groupBy("project_id");
  2526. List<LineInfoDay> yearDays = lineInfoDayService.list(wrapper);
  2527. Map<String, LineInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(LineInfoDay::getProjectId, Function.identity()));
  2528. // QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
  2529. // wrapperrp.eq("record_date", time0).last("and foreign_key_id = project_id");
  2530. // List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
  2531. QueryWrapper<ProEconReportIndicatorPool> wrapperrp2 = new QueryWrapper<>();
  2532. wrapperrp2.eq("record_date", time0).in("foreign_key_id", days.stream().map(LineInfoDay::getProjectId).collect(Collectors.toList()));
  2533. List<ProEconReportIndicatorPool> pools2 = reportIndicatorPoolService.list(wrapperrp2);
  2534. if (!pools2.isEmpty()) {
  2535. LineInfoDay day, month, year;
  2536. List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
  2537. String projectId;
  2538. for (ProEconReportIndicatorPool pool : pools2) {
  2539. projectId = pool.getForeignKeyId();
  2540. day = dayMap.get(projectId);
  2541. pool.setRfdldb(day.getRfdl().doubleValue());
  2542. pool.setRswdldb(day.getSwdl());
  2543. pool.setRgwgwdldb(day.getGwdl());
  2544. pool.setRfdcydldb(day.getCydl());
  2545. pool.setRzhcydldb(day.getRfdl().doubleValue() + day.getGwdl() - day.getSwdl());
  2546. month = monthMap.get(projectId);
  2547. pool.setYfdldb(month.getRfdl().doubleValue());
  2548. pool.setYswdldb(month.getSwdl());
  2549. pool.setYgwgwdldb(month.getGwdl());
  2550. pool.setYfdcydldb(month.getCydl());
  2551. pool.setRzhcydldb(month.getRfdl().doubleValue() + month.getGwdl() - month.getSwdl());
  2552. year = yearMap.get(projectId);
  2553. pool.setNfdldb(year.getRfdl().doubleValue());
  2554. pool.setNswdldb(year.getSwdl());
  2555. pool.setNgwgwdldb(year.getGwdl());
  2556. pool.setNfdcydldb(year.getCydl());
  2557. pool.setRzhcydldb(year.getRfdl().doubleValue() + year.getGwdl() - year.getSwdl());
  2558. poolList.add(pool);
  2559. }
  2560. reportIndicatorPoolService.saveOrUpdateBatch(poolList);
  2561. } else {
  2562. List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
  2563. for (LineInfoDay day : days) {
  2564. ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
  2565. pool.setRecordDate(time0);
  2566. pool.setForeignKeyId(day.getProjectId());
  2567. poolList.add(pool);
  2568. }
  2569. reportIndicatorPoolService.saveOrUpdateBatch(poolList);
  2570. }
  2571. }
  2572. public void writeReportPoolProjectSameDay() {
  2573. //date当天零点
  2574. DateTime time0 = DateUtil.beginOfDay(DateUtil.date());
  2575. DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
  2576. DateTime beginOfYear = DateUtil.beginOfYear(time0);
  2577. QueryWrapper<LineInfoDay> wrapper = new QueryWrapper<>();
  2578. 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");
  2579. List<LineInfoDay> days = lineInfoDayService.list(wrapper);
  2580. Map<String, LineInfoDay> dayMap = days.stream().collect(Collectors.toMap(LineInfoDay::getProjectId, Function.identity()));
  2581. wrapper = new QueryWrapper<>();
  2582. 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");
  2583. List<LineInfoDay> monthDays = lineInfoDayService.list(wrapper);
  2584. Map<String, LineInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(LineInfoDay::getProjectId, Function.identity()));
  2585. wrapper = new QueryWrapper<>();
  2586. 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");
  2587. List<LineInfoDay> yearDays = lineInfoDayService.list(wrapper);
  2588. Map<String, LineInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(LineInfoDay::getProjectId, Function.identity()));
  2589. QueryWrapper<ProEconReportIndicatorPool> wrapperRp = new QueryWrapper<>();
  2590. wrapperRp.eq("record_date", time0).last("and foreign_key_id = project_id");
  2591. List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperRp);
  2592. LineInfoDay day, month, year;
  2593. if (pools.isEmpty()) {
  2594. pools = new ArrayList<>();
  2595. for (LineInfoDay infoDay : days) {
  2596. String projectId = infoDay.getProjectId();
  2597. ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
  2598. pool.setRecordDate(time0);
  2599. pool.setForeignKeyId(projectId);
  2600. pool.setWindpowerstationId(infoDay.getStationId());
  2601. pool.setProjectId(projectId);
  2602. month = monthMap.get(projectId);
  2603. year = yearMap.get(projectId);
  2604. poolSetValueDl(pool, infoDay, month, year);
  2605. pools.add(pool);
  2606. }
  2607. } else {
  2608. for (ProEconReportIndicatorPool pool : pools) {
  2609. String projectId = pool.getProjectId();
  2610. day = dayMap.get(projectId);
  2611. month = monthMap.get(projectId);
  2612. year = yearMap.get(projectId);
  2613. poolSetValueDl(pool, day, month, year);
  2614. }
  2615. }
  2616. reportIndicatorPoolService.saveOrUpdateBatch(pools);
  2617. }
  2618. public void writeReportPoolPjfs(Date date) {
  2619. //date当天零点
  2620. DateTime time = DateUtil.beginOfDay(date);
  2621. //date昨天零点
  2622. DateTime time0 = DateUtil.offsetDay(time, -1);
  2623. DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
  2624. DateTime beginOfYear = DateUtil.beginOfYear(time0);
  2625. QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
  2626. wrapper.select("avg(pjfs) pjfs,project_id").eq("record_date", time0).groupBy("project_id");
  2627. List<TurbineInfoDay> days = turbineInfoDayService.list(wrapper);
  2628. Map<String, TurbineInfoDay> dayMap = days.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  2629. wrapper = new QueryWrapper<>();
  2630. wrapper.select("avg(pjfs) pjfs,project_id").between("record_date", beginOfMonth, time0).groupBy("project_id");
  2631. List<TurbineInfoDay> monthDays = turbineInfoDayService.list(wrapper);
  2632. Map<String, TurbineInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  2633. wrapper = new QueryWrapper<>();
  2634. wrapper.select("avg(pjfs) pjfs,project_id").between("record_date", beginOfYear, time0).groupBy("project_id");
  2635. List<TurbineInfoDay> yearDays = turbineInfoDayService.list(wrapper);
  2636. Map<String, TurbineInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  2637. // QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
  2638. // wrapperrp.eq("record_date", time0).last("and foreign_key_id = project_id");
  2639. QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
  2640. wrapperrp.eq("record_date", time0).in("foreign_key_id", days.stream().map(TurbineInfoDay::getProjectId).collect(Collectors.toList()));
  2641. List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
  2642. QueryWrapper<ProEconReportIndicatorPool> wrapperrp2 = new QueryWrapper<>();
  2643. wrapperrp2.eq("record_date", time0).eq("foreign_key_id", "GJNY_SXGS_DBXNY_ZGS0");
  2644. ProEconReportIndicatorPool pools2 = reportIndicatorPoolService.getOne(wrapperrp2);
  2645. if (pools2 == null) {
  2646. ProEconReportIndicatorPool GSPJFS = new ProEconReportIndicatorPool();
  2647. GSPJFS.setRecordDate(time0);
  2648. GSPJFS.setForeignKeyId("GJNY_SXGS_DBXNY_ZGS0");
  2649. GSPJFS.setCompanyId("GJNY_SXGS_DBXNY_ZGS");
  2650. reportIndicatorPoolService.saveOrUpdate(GSPJFS);
  2651. }
  2652. TurbineInfoDay day, month, year;
  2653. String projectId;
  2654. if (!pools.isEmpty()) {
  2655. for (ProEconReportIndicatorPool pool : pools) {
  2656. projectId = pool.getForeignKeyId();
  2657. day = dayMap.get(projectId);
  2658. pool.setRpjfs(day.getPjfs());
  2659. month = monthMap.get(projectId);
  2660. pool.setYpjfs(month.getPjfs());
  2661. year = yearMap.get(projectId);
  2662. pool.setNpjfs(year.getPjfs());
  2663. }
  2664. double v1 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getRpjfs).average().orElse(0);
  2665. double v2 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getYpjfs).average().orElse(0);
  2666. double v3 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getNpjfs).average().orElse(0);
  2667. if (!(pools2 == null)) {
  2668. pools2.setRpjfs(v1);
  2669. pools2.setYpjfs(v2);
  2670. pools2.setNpjfs(v3);
  2671. reportIndicatorPoolService.saveOrUpdate(pools2);
  2672. }
  2673. reportIndicatorPoolService.saveOrUpdateBatch(pools);
  2674. } else {
  2675. List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
  2676. for (TurbineInfoDay day2 : days) {
  2677. ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
  2678. pool.setRecordDate(time0);
  2679. pool.setForeignKeyId(day2.getProjectId());
  2680. poolList.add(pool);
  2681. }
  2682. reportIndicatorPoolService.saveOrUpdateBatch(poolList);
  2683. }
  2684. }
  2685. public void gongsizhibiao(Date date) {
  2686. //date当天零点
  2687. DateTime time = DateUtil.beginOfDay(date);
  2688. //date昨天零点
  2689. DateTime time0 = DateUtil.offsetDay(time, -1);
  2690. DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
  2691. DateTime beginOfYear = DateUtil.beginOfYear(time0);
  2692. QueryWrapper<ProEconReportIndicatorPool> wrapper = new QueryWrapper<>();
  2693. wrapper.eq("record_date", time0)
  2694. //包含"STA"
  2695. .like("foreign_key_id", "_STA");
  2696. List<ProEconReportIndicatorPool> list = reportIndicatorPoolService.list(wrapper);
  2697. //遍历list,累加指标RFDL
  2698. //公司指标,日发电量
  2699. double rfdl = 0;
  2700. //公司指标,日上网电量
  2701. double swdl = 0;
  2702. //公司指标,日购网电量
  2703. double gwdl = 0;
  2704. //公司指标,日综合厂用电量
  2705. double zhcydl = 0;
  2706. //公司指标,月发电量
  2707. double yfdl = 0;
  2708. //公司指标,月上网电量
  2709. double yswdl = 0;
  2710. //公司指标,月购网电量
  2711. double ygwdl = 0;
  2712. //公司指标,月综合厂用电量
  2713. double yzhcydl = 0;
  2714. //公司指标,年发电量
  2715. double nfdl = 0;
  2716. //公司指标,年上网电量
  2717. double nswdl = 0;
  2718. //公司指标,年购网电量
  2719. double ngwdl = 0;
  2720. //公司指标,年综合厂用电量
  2721. double nzhcydl = 0;
  2722. for (ProEconReportIndicatorPool pool : list) {
  2723. rfdl += pool.getRfdldb();
  2724. swdl += pool.getRswdldb();
  2725. gwdl += pool.getRgwgwdldb();
  2726. zhcydl += pool.getRzhcydldb();
  2727. yfdl += pool.getYfdldb();
  2728. yswdl += pool.getYswdldb();
  2729. ygwdl += pool.getYgwgwdldb();
  2730. yzhcydl += pool.getYzhcydldb();
  2731. nfdl += pool.getNfdldb();
  2732. nswdl += pool.getNswdldb();
  2733. ngwdl += pool.getNgwgwdldb();
  2734. nzhcydl += pool.getNzhcydldb();
  2735. }
  2736. QueryWrapper<ProEconReportIndicatorPool> wrapperrp2 = new QueryWrapper<>();
  2737. wrapperrp2.eq("record_date", time0).eq("foreign_key_id", "GJNY_SXGS_DBXNY_ZGS0");
  2738. ProEconReportIndicatorPool GSZB = reportIndicatorPoolService.getOne(wrapperrp2);
  2739. //公司指标集合
  2740. GSZB.setRfdldb(rfdl);
  2741. GSZB.setRswdldb(swdl);
  2742. GSZB.setRgwgwdldb(gwdl);
  2743. GSZB.setRzhcydldb(zhcydl);
  2744. GSZB.setYfdldb(yfdl);
  2745. GSZB.setYswdldb(yswdl);
  2746. GSZB.setYgwgwdldb(ygwdl);
  2747. GSZB.setYzhcydldb(yzhcydl);
  2748. GSZB.setNfdldb(nfdl);
  2749. GSZB.setNswdldb(nswdl);
  2750. GSZB.setNgwgwdldb(ngwdl);
  2751. GSZB.setNzhcydldb(nzhcydl);
  2752. reportIndicatorPoolService.saveOrUpdate(GSZB);
  2753. }
  2754. //公司指标,累加风机理论发电量
  2755. public void writeReportPoolLLFDL(Date date) {
  2756. //date当天零点
  2757. DateTime time = DateUtil.beginOfDay(date);
  2758. //date昨天零点
  2759. DateTime time0 = DateUtil.offsetDay(time, -1);
  2760. DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
  2761. DateTime beginOfYear = DateUtil.beginOfYear(time0);
  2762. QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
  2763. wrapper.select("avg(llfdl) llfdl,project_id").eq("record_date", time0).groupBy("project_id");
  2764. List<TurbineInfoDay> days = turbineInfoDayService.list(wrapper);
  2765. Map<String, TurbineInfoDay> dayMap = days.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  2766. wrapper = new QueryWrapper<>();
  2767. wrapper.select("avg(llfdl) llfdl,project_id").between("record_date", beginOfMonth, time0).groupBy("project_id");
  2768. List<TurbineInfoDay> monthDays = turbineInfoDayService.list(wrapper);
  2769. Map<String, TurbineInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  2770. wrapper = new QueryWrapper<>();
  2771. wrapper.select("avg(llfdl) llfdl,project_id").between("record_date", beginOfYear, time0).groupBy("project_id");
  2772. List<TurbineInfoDay> yearDays = turbineInfoDayService.list(wrapper);
  2773. Map<String, TurbineInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  2774. QueryWrapper<ProEconReportIndicatorPool> wrapperrp = new QueryWrapper<>();
  2775. wrapperrp.eq("record_date", time0).in("foreign_key_id", days.stream().map(TurbineInfoDay::getProjectId).collect(Collectors.toList()));
  2776. List<ProEconReportIndicatorPool> pools = reportIndicatorPoolService.list(wrapperrp);
  2777. QueryWrapper<ProEconReportIndicatorPool> wrapperrp2 = new QueryWrapper<>();
  2778. wrapperrp2.eq("record_date", time0).eq("foreign_key_id", "GJNY_SXGS_DBXNY_ZGS0");
  2779. ProEconReportIndicatorPool pools2 = reportIndicatorPoolService.getOne(wrapperrp2);
  2780. if (pools2 == null) {
  2781. ProEconReportIndicatorPool GSPJFS = new ProEconReportIndicatorPool();
  2782. GSPJFS.setRecordDate(time0);
  2783. GSPJFS.setForeignKeyId("GJNY_SXGS_DBXNY_ZGS0");
  2784. GSPJFS.setCompanyId("GJNY_SXGS_DBXNY_ZGS");
  2785. reportIndicatorPoolService.saveOrUpdate(GSPJFS);
  2786. }
  2787. TurbineInfoDay day, month, year;
  2788. String projectId;
  2789. if (!pools.isEmpty()) {
  2790. for (ProEconReportIndicatorPool pool : pools) {
  2791. projectId = pool.getForeignKeyId();
  2792. day = dayMap.get(projectId);
  2793. pool.setRllfdl(day.getLlfdl());
  2794. month = monthMap.get(projectId);
  2795. pool.setYllfdl(month.getLlfdl());
  2796. year = yearMap.get(projectId);
  2797. pool.setNllfdl(year.getLlfdl());
  2798. }
  2799. double v1 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getRllfdl).sum();
  2800. double v2 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getYllfdl).sum();
  2801. double v3 = pools.stream().mapToDouble(ProEconReportIndicatorPool::getNllfdl).sum();
  2802. //pools.stream().mapToDouble(ProEconReportIndicatorPool::getRllfdl),求和
  2803. if (pools2 != null) {
  2804. pools2.setRllfdl(v1);
  2805. pools2.setYllfdl(v2);
  2806. pools2.setNllfdl(v3);
  2807. reportIndicatorPoolService.saveOrUpdate(pools2);
  2808. }
  2809. reportIndicatorPoolService.saveOrUpdateBatch(pools);
  2810. } else {
  2811. List<ProEconReportIndicatorPool> poolList = new ArrayList<>();
  2812. for (TurbineInfoDay day2 : days) {
  2813. ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
  2814. pool.setRecordDate(time0);
  2815. pool.setForeignKeyId(day2.getProjectId());
  2816. poolList.add(pool);
  2817. }
  2818. reportIndicatorPoolService.saveOrUpdateBatch(poolList);
  2819. }
  2820. }
  2821. public void calcRealtimeTurbineZt() {
  2822. DateTime date0 = DateUtil.date();
  2823. boolean isOnMin = false;
  2824. //分钟变化
  2825. if (CalcCache.minuteNow.minute() != date0.minute()) {
  2826. date0 = DateUtil.beginOfMinute(date0);
  2827. CalcCache.minuteNow = date0;
  2828. isOnMin = true;
  2829. }
  2830. DateTime date = date0;
  2831. List<PointInfo> turbineZt = calcRealtimeTurbineDizt();
  2832. List<PointInfo> turbineAizt = calcRealtimeTurbineAizt();
  2833. turbineZt.addAll(turbineAizt);
  2834. turbineZt = turbineZt.stream().peek(t -> {
  2835. if (t.getPointDatas().get(0).getTs() + 35 * 60 * 1000 <= date.getTime()) {
  2836. t.getPointDatas().get(0).setDoubleValue(12.0);
  2837. }
  2838. }).collect(Collectors.toList());
  2839. Map<String, Map<String, PointInfo>> ztMapMap = turbineZt.stream().collect(Collectors.groupingBy(PointInfo::getStationId, Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
  2840. //AGC
  2841. List<PointInfo> entityAgc = getEntity("AGC002", "booster");
  2842. getSnapDataByEntity(entityAgc, DateUtil.offsetMinute(date, -5), date, 15);
  2843. //出线
  2844. List<PointInfo> entityCx = getEntity("AGC001", "booster");
  2845. getSnapDataByEntity(entityCx, DateUtil.offsetMinute(date, -5), date, 15);
  2846. //风速
  2847. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  2848. getSnapDataByEntity(entityFs, DateUtil.offsetMinute(date, -5), date, 15);
  2849. Map<String, PointInfo> collectAgc = entityAgc.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  2850. Map<String, PointInfo> collectCx = entityCx.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  2851. Map<String, Map<String, PointInfo>> fsMapMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId, Collectors.toMap(PointInfo::getTurbineId, Function.identity())));
  2852. //功率
  2853. List<PointInfo> entityGl = getEntity("AI114", "turbine");
  2854. getLatestByEntity(entityGl);
  2855. Map<String, List<PointData>> glMap = entityGl.stream().collect(Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas));
  2856. ztMapMap.forEach((stId, ztMap) -> {
  2857. PointInfo agcInfo = collectAgc.get(stId);
  2858. PointInfo cxInfo = collectCx.get(stId);
  2859. Map<String, PointInfo> fsMap = fsMapMap.get(stId);
  2860. Map<String, List<PointData>> pdsZsglMap = new HashMap<>();
  2861. ztMap.forEach((wtId, zt) -> {
  2862. 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());
  2863. fsMap.get(wtId).setPointDatas(peek);
  2864. List<PointData> zsglSnap = fsMap.get(wtId).getPointDatas().stream().map(pd -> {
  2865. Double v = CalcCache.fitcoef.get(wtId).get(pd.getValue());
  2866. return new PointData(pd.getTs(), v == null ? 0 : v);
  2867. }).collect(Collectors.toList());
  2868. pdsZsglMap.put(wtId, zsglSnap);
  2869. });
  2870. List<PointData> agcc = agcInfo.getPointDatas().stream().peek(agc -> {
  2871. agc.setDoubleValue(agc.getValue() * agcInfo.getCoef());
  2872. agc.setLongValue(0L);
  2873. }).collect(Collectors.toList());
  2874. agcInfo.setPointDatas(agcc);
  2875. List<PointData> cxc = cxInfo.getPointDatas().stream().peek(cx -> {
  2876. cx.setDoubleValue(cx.getValue() * cxInfo.getCoef());
  2877. cx.setLongValue(0L);
  2878. }).collect(Collectors.toList());
  2879. cxInfo.setPointDatas(cxc);
  2880. //风机风速、功率->场站风速、功率
  2881. List<PointData> firstZsgl = new ArrayList<>();
  2882. double v3;
  2883. for (int i = 0; i < 20; i++) {
  2884. int finalI = i;
  2885. long ts = date.getTime() + i * 15000;
  2886. v3 = pdsZsglMap.values().stream().mapToDouble(pds -> pds.get(finalI).getValue()).sum();
  2887. firstZsgl.add(new PointData(ts, v3));
  2888. }
  2889. boolean czxd = calcRealtimeStationXd(agcInfo, cxInfo.getPointDatas(), firstZsgl);
  2890. if (czxd) {
  2891. //叶轮转速给定
  2892. List<PointInfo> entityYlzsgd = getEntity("AI110", "turbine");
  2893. getLatestByEntity(entityYlzsgd);
  2894. Map<String, List<PointData>> collectYlzsgd = entityYlzsgd.stream().collect(Collectors.toMap(PointInfo::getTurbineId, PointInfo::getPointDatas));
  2895. ztMap.forEach((wtId, ztInfo) -> {
  2896. List<PointData> fss = fsMap.get(wtId).getPointDatas();
  2897. List<PointData> gls = glMap.get(wtId);
  2898. //叶轮转速给定
  2899. List<PointData> ylzsgds = collectYlzsgd.get(wtId);
  2900. calcRealtimeTurbineXd(ztInfo, gls.get(0), fss.get(fss.size() - 1), ylzsgds.get(0));
  2901. });
  2902. }
  2903. });
  2904. Map<String, String> entityMxzt = getEntityMap("MXZT", "turbine");
  2905. Map<String, String> entityQfzt = getEntityMap("SSQFZT", "turbine");
  2906. //Map<String, String> entityKygl = getEntityMap("KYGL", "turbine");
  2907. List<PointInfo> fsEntity = entityFs.stream().peek(fs -> {
  2908. PointData data = fs.getPointDatas().get(fs.getPointDatas().size() - 1);
  2909. if (data != null) {
  2910. fs.setPointDatas(Collections.singletonList(data));
  2911. } else {
  2912. fs.setPointDatas(Collections.singletonList(new PointData()));
  2913. }
  2914. }).collect(Collectors.toList());
  2915. List<PointData> qfztDataList = fsEntity.stream().map(fs -> {
  2916. String wtId = fs.getTurbineId();
  2917. PointData data = fs.getPointDatas().get(0);
  2918. data.setTs(date.getTime());
  2919. data.setTagName(entityQfzt.get(wtId));
  2920. data.setDoubleValue(calcQfzt(glMap.get(wtId).get(0).getValue(), CalcCache.fitcoef.get(wtId).get(data.getValue())));
  2921. return data;
  2922. }).collect(Collectors.toList());
  2923. //风机状态转换为写适配器的测点与值
  2924. List<PointData> dataList = turbineZt.stream().map(zt -> {
  2925. PointData data = zt.getPointDatas().get(0);
  2926. data.setTs(date.getTime());
  2927. data.setTagName(entityMxzt.get(zt.getTurbineId()));
  2928. return data;
  2929. }).collect(Collectors.toList());
  2930. if (isOnMin) {
  2931. adapter.writeHistoryBatch(taosUri(), dataList);
  2932. adapter.writeHistoryBatch(taosUri(), qfztDataList);
  2933. } else {
  2934. List<PointData> collect = dataList.stream().filter(d -> {
  2935. if (Objects.equals(CalcCache.statusCache.get(d.getTagName()), d.getValue())) {
  2936. return false;
  2937. } else {
  2938. CalcCache.statusCache.put(d.getTagName(), d.getValue());
  2939. return true;
  2940. }
  2941. }).collect(Collectors.toList());
  2942. List<PointData> qfztDatas = qfztDataList.stream().filter(d -> {
  2943. if (Objects.equals(CalcCache.qfztCache.get(d.getTagName()), d.getValue())) {
  2944. return false;
  2945. } else {
  2946. CalcCache.qfztCache.put(d.getTagName(), d.getValue());
  2947. return true;
  2948. }
  2949. }).collect(Collectors.toList());
  2950. adapter.writeHistoryBatch(taosUri(), collect);
  2951. adapter.writeHistoryBatch(taosUri(), qfztDatas);
  2952. }
  2953. }
  2954. //此处加公式
  2955. public Map<String, Double> calcRealtimeTurbineZt(String stId) {
  2956. List<PointInfo> turbineZt = calcRealtimeTurbineDizt();
  2957. List<PointInfo> turbineAizt = calcRealtimeTurbineAizt();
  2958. turbineZt.addAll(turbineAizt);
  2959. Map<String, Double> collect = turbineZt.stream().filter(zt -> zt.getStationId().equals(stId)).peek(t -> {
  2960. if (t.getPointDatas().get(0).getTs() + 35 * 60 * 1000 <= DateUtil.date().getTime()) {
  2961. t.getPointDatas().get(0).setDoubleValue(12.0);
  2962. }
  2963. }).collect(Collectors.toMap(PointInfo::getTurbineId, pi -> pi.getPointDatas().get(0).getValue()));
  2964. return collect;
  2965. }
  2966. public void calcStationMinZtts(Date time, String stId) {
  2967. Map<Double, Long> map = calcSectionStationZtts(time, stId);
  2968. StationInfoMin byMin = getStationinfoByMinOne(time, stId);
  2969. //0 待机-,1 停机,2 发电-,4 故障-,6 检修,8 限电,12 离线
  2970. byMin.setDjts(map.get(0.0));
  2971. byMin.setYxts(map.get(2.0));
  2972. byMin.setGzts(map.get(4.0));
  2973. byMin.setJxts(map.get(6.0));
  2974. stationInfoMinService.saveOrUpdate(byMin);
  2975. }
  2976. public Map<Double, Long> calcSectionZtts(Date time, String stId, Function<PointInfo, String> fun) {
  2977. Map<Double, Long> diztTs = calcSectionDiztTs(time, stId, fun);
  2978. Map<Double, Long> aiztTs = calcSectionAiztTs(time, stId, fun);
  2979. if (diztTs.isEmpty()) {
  2980. return aiztTs;
  2981. } else if (aiztTs.isEmpty()) {
  2982. return diztTs;
  2983. } else if (diztTs.size() > aiztTs.size()) {
  2984. diztTs.forEach((k, v) -> {
  2985. long l = aiztTs.getOrDefault(k, 0L);
  2986. if (v == null) v = 0L;
  2987. v = v + l;
  2988. });
  2989. return diztTs;
  2990. } else {
  2991. aiztTs.forEach((k, v) -> {
  2992. long l = diztTs.getOrDefault(k, 0L);
  2993. if (v == null) v = 0L;
  2994. v = v + l;
  2995. });
  2996. return aiztTs;
  2997. }
  2998. }
  2999. public Map<Double, Long> calcSectionStationZtts(Date time, String stId) {
  3000. Map<Double, Long> diztTs = calcSectionStationDiztTs(time, stId);
  3001. Map<Double, Long> aiztTs = calcSectionStationAiztTs(time, stId);
  3002. if (diztTs.isEmpty()) {
  3003. return aiztTs;
  3004. } else if (aiztTs.isEmpty()) {
  3005. return diztTs;
  3006. } else if (diztTs.size() > aiztTs.size()) {
  3007. diztTs.forEach((k, v) -> {
  3008. long l = aiztTs.getOrDefault(k, 0L);
  3009. if (v == null) v = 0L;
  3010. v = v + l;
  3011. });
  3012. return diztTs;
  3013. } else {
  3014. aiztTs.forEach((k, v) -> {
  3015. long l = diztTs.getOrDefault(k, 0L);
  3016. if (v == null) v = 0L;
  3017. v = v + l;
  3018. });
  3019. return aiztTs;
  3020. }
  3021. }
  3022. // 计算每种状态的总持续时间
  3023. public void calcTurbineStateMin(Date date) {
  3024. //date当天零点
  3025. DateTime time = DateUtil.beginOfDay(date);
  3026. //date昨天零点
  3027. DateTime time0 = DateUtil.offsetDay(time, -1);
  3028. List<PointInfo> entityMxzt = getEntity("MXZT", "turbine");
  3029. getRawDataByEntity(entityMxzt, taosUri(), time0, time);
  3030. Map<String, TurbineInfoDay> byDate = getTurbineinfoMap(time0, entityMxzt);
  3031. for (PointInfo info : entityMxzt) {
  3032. TurbineInfoDay infoDay = byDate.get(info.getTurbineId());
  3033. Map<String, Map<Double, Long>> dlmm = calcStateDurationFrequency(info.getPointDatas());
  3034. Map<Double, Long> durations = dlmm.get("duration");
  3035. Map<Double, Long> frequency = dlmm.get("frequency");
  3036. infoDay.setDjMin(durations.getOrDefault(0.0, 0L) / 60000.0);
  3037. infoDay.setTjMin(durations.getOrDefault(1.0, 0L) / 60000.0);
  3038. infoDay.setYxMin(durations.getOrDefault(2.0, 0L) / 60000.0);
  3039. infoDay.setGzMin(durations.getOrDefault(4.0, 0L) / 60000.0);
  3040. infoDay.setJxMin(durations.getOrDefault(6.0, 0L) / 60000.0);
  3041. infoDay.setXdMin(durations.getOrDefault(8.0, 0L) / 60000.0);
  3042. infoDay.setLxMin(durations.getOrDefault(12.0, 0L) / 60000.0);
  3043. }
  3044. turbineInfoDayService.saveOrUpdateBatch(byDate.values());
  3045. }
  3046. public Map<String, Map<Double, Long>> calcStateDurationFrequency(List<PointData> datas) {
  3047. if (CollUtil.isEmpty(datas)) return Collections.emptyMap();
  3048. Map<Double, Long> durations = new HashMap<>();
  3049. Map<Double, Long> frequency = new HashMap<>();
  3050. Map<String, Map<Double, Long>> dlmm = new HashMap<>();
  3051. double prevState = datas.get(0).getValue(); // 初始状态
  3052. long prevTs = datas.get(0).getTs(); // 初始时间戳
  3053. PointData current;
  3054. double currentState;
  3055. long currentTs;
  3056. for (int i = 1; i < datas.size(); i++) {
  3057. current = datas.get(i);
  3058. currentState = current.getValue();
  3059. currentTs = current.getTs();
  3060. if (currentState != prevState) {
  3061. // 当状态变化时,计算前一个状态的持续时间并更新map
  3062. durations.put(prevState, durations.getOrDefault(prevState, 0L) + (currentTs - prevTs));
  3063. frequency.put(prevState, frequency.getOrDefault(prevState, 0L) + 1);
  3064. prevState = currentState;
  3065. prevTs = currentTs;
  3066. }
  3067. }
  3068. // 不要忘记计算列表中最后一个状态的持续时间(如果列表没有以状态变化结束)
  3069. durations.put(prevState, durations.getOrDefault(prevState, 0L) + (datas.get(datas.size() - 1).getTs() - prevTs));
  3070. dlmm.put("duration", durations);
  3071. dlmm.put("frequency", frequency);
  3072. return dlmm;
  3073. }
  3074. public Map<Double, Long> calculateStateDurations(List<PointData> datas) {
  3075. if (CollUtil.isEmpty(datas)) return Collections.emptyMap();
  3076. Map<Double, Long> durations = new HashMap<>();
  3077. double prevState = datas.get(0).getValue(); // 初始状态
  3078. long prevTs = datas.get(0).getTs(); // 初始时间戳
  3079. PointData current;
  3080. double currentState;
  3081. long currentTs;
  3082. for (int i = 1; i < datas.size(); i++) {
  3083. current = datas.get(i);
  3084. currentState = current.getValue();
  3085. currentTs = current.getTs();
  3086. if (currentState != prevState) {
  3087. // 当状态变化时,计算前一个状态的持续时间并更新map
  3088. durations.put(prevState, durations.getOrDefault(prevState, 0L) + (currentTs - prevTs));
  3089. prevState = currentState;
  3090. prevTs = currentTs;
  3091. }
  3092. }
  3093. // 不要忘记计算列表中最后一个状态的持续时间(如果列表没有以状态变化结束)
  3094. durations.put(prevState, durations.getOrDefault(prevState, 0L) + (datas.get(datas.size() - 1).getTs() - prevTs));
  3095. return durations;
  3096. }
  3097. public void getRawDataByEntity(List<PointInfo> entity, URI uri, Date start, Date end) {
  3098. for (PointInfo info : entity) {
  3099. List<PointData> snap = adapter.getHistoryRaw(uri, info.getPointKey(), start.getTime(), end.getTime());
  3100. // ThreadUtil.sleep(5);
  3101. info.setPointDatas(snap);
  3102. }
  3103. }
  3104. public void getStatDataByEntity(List<PointInfo> entity, URI uri, Date start, Date end) {
  3105. for (PointInfo info : entity) {
  3106. DoubleStatData stat = adapter.getHistoryStat(uri, info.getPointKey(), start.getTime(), end.getTime());
  3107. ThreadUtil.sleep(5);
  3108. info.setPointDatas(new ArrayList<>(3));
  3109. if (stat != null) {
  3110. info.getPointDatas().add(stat.getAvg());
  3111. info.getPointDatas().add(stat.getMax());
  3112. info.getPointDatas().add(stat.getMin());
  3113. } else {
  3114. info.getPointDatas().add(new PointData());
  3115. info.getPointDatas().add(new PointData());
  3116. info.getPointDatas().add(new PointData());
  3117. }
  3118. }
  3119. }
  3120. public Map<String, PointInfo> getStatDataByEntity(List<PointInfo> entity, URI uri, Date start, Date end, Function<PointInfo, String> function) {
  3121. getStatDataByEntity(entity, uri, start, end);
  3122. return entity.stream().collect(Collectors.toMap(function, Function.identity()));
  3123. }
  3124. // 主函数或测试方法(如果需要)
  3125. public static void main(String[] args) {
  3126. Double b = 2.0;
  3127. double c = 2.0;
  3128. System.out.println(b == c);
  3129. Double d = Double.valueOf(c);
  3130. System.out.println(Objects.equals(b, c));
  3131. System.out.println(Objects.equals(d, b));
  3132. System.out.println(Objects.equals(null, null));
  3133. List<PointData> points = new ArrayList<>();
  3134. points.add(new PointData(1000, 1));
  3135. points.add(new PointData(1500, 2));
  3136. points.add(new PointData(2000, 1));
  3137. points.add(new PointData(2500, 3));
  3138. // Map<Integer, Long> durations = calculateStateDurations(points);
  3139. // for (Map.Entry<Integer, Long> entry : durations.entrySet()) {
  3140. // System.out.println("State " + entry.getKey() + ": " + entry.getValue() + "ms");
  3141. // }
  3142. }
  3143. public List<PointInfo> getLatest(String uniformCode, String institutionType) {
  3144. List<PointInfo> entity = getEntity(uniformCode, institutionType);
  3145. String collect = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
  3146. Map<String, PointData> latest = adapter.getLatest(goldenUri(), collect);
  3147. entity.forEach(e -> {
  3148. e.setPointDatas(Collections.singletonList(latest.get(e.getPointKey())));
  3149. });
  3150. return entity;
  3151. }
  3152. public void getLatestByEntity(List<PointInfo> entity) {
  3153. String collect = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
  3154. Map<String, PointData> latest = adapter.getLatest(goldenUri(), collect);
  3155. entity.forEach(e -> {
  3156. e.setPointDatas(Collections.singletonList(latest.get(e.getPointKey())));
  3157. });
  3158. }
  3159. public List<PointInfo> calcRealtimeTurbineDizt() {
  3160. List<PointInfo> entity = new ArrayList<>();
  3161. List<PointInfo> result = new ArrayList<>();
  3162. List<PointInfo> entity0 = getEntity("MX000", "state");
  3163. List<PointInfo> entity1 = getEntity("MX001", "state");
  3164. List<PointInfo> entity2 = getEntity("MX002", "state");
  3165. List<PointInfo> entity4 = getEntity("MX004", "state");
  3166. List<PointInfo> entity6 = getEntity("MX006", "state");
  3167. entity.addAll(entity0);
  3168. entity.addAll(entity1);
  3169. entity.addAll(entity2);
  3170. entity.addAll(entity4);
  3171. entity.addAll(entity6);
  3172. String keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
  3173. Map<String, PointData> latest = adapter.getLatest(goldenUri(), keys);
  3174. Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
  3175. wtUcPis.forEach((wtId, map) -> {
  3176. String collect = map.values().stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
  3177. PointInfo info2 = map.get("MX002");
  3178. PointData data2 = latest.get(info2.getPointKey());
  3179. if (data2.getValue() == 1.0) {
  3180. data2.setDoubleValue(2.0);
  3181. data2.setBooleanValue(false);
  3182. info2.setPointDatas(Collections.singletonList(data2));
  3183. result.add(info2);
  3184. } else {
  3185. PointInfo info0 = map.get("MX000");
  3186. PointData data0 = latest.get(info0.getPointKey());
  3187. if (data0.getValue() == 1.0) {
  3188. data0.setDoubleValue(0.0);
  3189. data0.setBooleanValue(false);
  3190. info0.setPointDatas(Collections.singletonList(data0));
  3191. result.add(info0);
  3192. } else {
  3193. PointInfo info6 = map.get("MX006");
  3194. PointData data6 = latest.get(info6.getPointKey());
  3195. if (data6.getValue() == 1.0) {
  3196. data6.setDoubleValue(6.0);
  3197. data6.setBooleanValue(false);
  3198. info6.setPointDatas(Collections.singletonList(data6));
  3199. result.add(info6);
  3200. } else {
  3201. PointInfo info4 = map.get("MX004");
  3202. PointData data4 = latest.get(info4.getPointKey());
  3203. if (data4.getValue() == 1.0) {
  3204. data4.setDoubleValue(4.0);
  3205. data4.setBooleanValue(false);
  3206. info4.setPointDatas(Collections.singletonList(data4));
  3207. result.add(info4);
  3208. } else {
  3209. PointInfo info1 = map.get("MX001");
  3210. PointData data1 = latest.get(info1.getPointKey());
  3211. if (data1.getValue() == 1.0) {
  3212. data1.setDoubleValue(1.0);
  3213. data1.setBooleanValue(false);
  3214. info1.setPointDatas(Collections.singletonList(data1));
  3215. result.add(info1);
  3216. } else {
  3217. // Map<String, PointData> latest2 = adapter.getLatest(goldenUri(), collect);
  3218. data1.setDoubleValue(2.0);
  3219. System.out.println("wtId: " + wtId + ",状态值无批配: " + data1.getValue());
  3220. info1.setPointDatas(Collections.singletonList(data1));
  3221. result.add(info1);
  3222. }
  3223. }
  3224. }
  3225. }
  3226. }
  3227. });
  3228. return result;
  3229. }
  3230. public Map<Double, Long> calcSectionStationDiztTs(Date time, String stId) {
  3231. List<PointInfo> entity = new ArrayList<>();
  3232. List<PointInfo> result = new ArrayList<>();
  3233. List<PointInfo> entity0 = getEntity("MX000", "state");
  3234. List<PointInfo> entity1 = getEntity("MX001", "state");
  3235. List<PointInfo> entity2 = getEntity("MX002", "state");
  3236. List<PointInfo> entity4 = getEntity("MX004", "state");
  3237. List<PointInfo> entity6 = getEntity("MX006", "state");
  3238. entity.addAll(entity0);
  3239. entity.addAll(entity1);
  3240. entity.addAll(entity2);
  3241. entity.addAll(entity4);
  3242. entity.addAll(entity6);
  3243. entity = entity.stream().filter(pi -> stId.equals(pi.getStationId())).collect(Collectors.toList());
  3244. if (CollUtil.isEmpty(entity)) return new HashMap<>();
  3245. String keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
  3246. Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), keys, time.getTime());
  3247. Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
  3248. wtUcPis.forEach((wtId, map) -> {
  3249. PointInfo info2 = map.get("MX002");
  3250. PointData data2 = latest.get(info2.getPointKey());
  3251. if (data2.getValue() == 1.0) {
  3252. data2.setDoubleValue(2.0);
  3253. data2.setBooleanValue(false);
  3254. info2.setPointDatas(Collections.singletonList(data2));
  3255. result.add(info2);
  3256. } else {
  3257. PointInfo info0 = map.get("MX000");
  3258. PointData data0 = latest.get(info0.getPointKey());
  3259. if (data0.getValue() == 1.0) {
  3260. data0.setDoubleValue(0.0);
  3261. data0.setBooleanValue(false);
  3262. info0.setPointDatas(Collections.singletonList(data0));
  3263. result.add(info0);
  3264. } else {
  3265. PointInfo info6 = map.get("MX006");
  3266. PointData data6 = latest.get(info6.getPointKey());
  3267. if (data6.getValue() == 1.0) {
  3268. data6.setDoubleValue(6.0);
  3269. data6.setBooleanValue(false);
  3270. info6.setPointDatas(Collections.singletonList(data6));
  3271. result.add(info6);
  3272. } else {
  3273. PointInfo info4 = map.get("MX004");
  3274. PointData data4 = latest.get(info4.getPointKey());
  3275. if (data4.getValue() == 1.0) {
  3276. data4.setDoubleValue(4.0);
  3277. data4.setBooleanValue(false);
  3278. info4.setPointDatas(Collections.singletonList(data4));
  3279. result.add(info4);
  3280. } else {
  3281. PointInfo info1 = map.get("MX001");
  3282. PointData data1 = latest.get(info1.getPointKey());
  3283. if (data1.getValue() == 1.0) {
  3284. data1.setDoubleValue(1.0);
  3285. data1.setBooleanValue(false);
  3286. info1.setPointDatas(Collections.singletonList(data1));
  3287. result.add(info1);
  3288. } else {
  3289. data1.setDoubleValue(2.0);
  3290. System.out.println("wtId: " + wtId + ",状态值无批配: " + data1.getValue());
  3291. info1.setPointDatas(Collections.singletonList(data1));
  3292. result.add(info1);
  3293. }
  3294. }
  3295. }
  3296. }
  3297. }
  3298. });
  3299. Map<Double, Long> longMap = result.stream().collect(Collectors.groupingBy(pi -> pi.getPointDatas().get(0).getValue(), Collectors.counting()));
  3300. return longMap;
  3301. }
  3302. public Map<Double, Long> calcSectionStationAiztTs(Date time, String stId) {
  3303. List<PointInfo> entityAiZt = getEntity("AI422", "state");
  3304. entityAiZt = entityAiZt.stream().filter(pi -> stId.equals(pi.getStationId())).collect(Collectors.toList());
  3305. if (CollUtil.isEmpty(entityAiZt)) return new HashMap<>();
  3306. List<StateAi> list = stateAiService.list();
  3307. //机型,源状态,目标状态
  3308. Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
  3309. String collect = entityAiZt.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
  3310. Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), collect, time.getTime());
  3311. for (PointInfo info : entityAiZt) {
  3312. PointData data = latest.get(info.getPointKey());
  3313. Integer m = collectAi.get(info.getSpare()).get((int) data.getValue());
  3314. if (m == null) {
  3315. m = 2;
  3316. System.out.println("ai状态未配对:" + data.getValue());
  3317. }
  3318. data.setDoubleValue(m);
  3319. info.setPointDatas(Collections.singletonList(data));
  3320. }
  3321. Map<Double, Long> longMap = entityAiZt.stream().collect(Collectors.groupingBy(pi -> pi.getPointDatas().get(0).getValue(), Collectors.counting()));
  3322. return longMap;
  3323. }
  3324. public List<PointInfo> calcRealtimeTurbineAizt() {
  3325. List<PointInfo> entityAiZt = getEntity("AI422", "state");
  3326. List<StateAi> list = stateAiService.list();
  3327. //机型,源状态,目标状态
  3328. Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
  3329. String collect = entityAiZt.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
  3330. Map<String, PointData> latest = adapter.getLatest(goldenUri(), collect);
  3331. for (PointInfo info : entityAiZt) {
  3332. PointData data = latest.get(info.getPointKey());
  3333. Integer m = collectAi.get(info.getSpare()).get((int) data.getValue());
  3334. if (m == null) m = 2;
  3335. data.setDoubleValue(m);
  3336. info.setPointDatas(Collections.singletonList(data));
  3337. }
  3338. return entityAiZt;
  3339. }
  3340. public Map<Double, Long> calcSectionDiztTs(Date time, String id, Function<PointInfo, String> fun) {
  3341. List<PointInfo> entity = new ArrayList<>();
  3342. List<PointInfo> result = new ArrayList<>();
  3343. List<PointInfo> entity0 = getEntity("MX000", "state");
  3344. List<PointInfo> entity1 = getEntity("MX001", "state");
  3345. List<PointInfo> entity2 = getEntity("MX002", "state");
  3346. List<PointInfo> entity4 = getEntity("MX004", "state");
  3347. List<PointInfo> entity6 = getEntity("MX006", "state");
  3348. entity.addAll(entity0);
  3349. entity.addAll(entity1);
  3350. entity.addAll(entity2);
  3351. entity.addAll(entity4);
  3352. entity.addAll(entity6);
  3353. entity = entity.stream().filter(pi -> id.equals(fun.apply(pi))).collect(Collectors.toList());
  3354. if (CollUtil.isEmpty(entity)) return new HashMap<>();
  3355. String keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
  3356. Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), keys, time.getTime());
  3357. Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
  3358. wtUcPis.forEach((wtId, map) -> {
  3359. PointInfo info2 = map.get("MX002");
  3360. PointData data2 = latest.get(info2.getPointKey());
  3361. if (data2.getValue() == 1.0) {
  3362. data2.setDoubleValue(2.0);
  3363. data2.setBooleanValue(false);
  3364. info2.setPointDatas(Collections.singletonList(data2));
  3365. result.add(info2);
  3366. } else {
  3367. PointInfo info0 = map.get("MX000");
  3368. PointData data0 = latest.get(info0.getPointKey());
  3369. if (data0.getValue() == 1.0) {
  3370. data0.setDoubleValue(0.0);
  3371. data0.setBooleanValue(false);
  3372. info0.setPointDatas(Collections.singletonList(data0));
  3373. result.add(info0);
  3374. } else {
  3375. PointInfo info6 = map.get("MX006");
  3376. PointData data6 = latest.get(info6.getPointKey());
  3377. if (data6.getValue() == 1.0) {
  3378. data6.setDoubleValue(6.0);
  3379. data6.setBooleanValue(false);
  3380. info6.setPointDatas(Collections.singletonList(data6));
  3381. result.add(info6);
  3382. } else {
  3383. PointInfo info4 = map.get("MX004");
  3384. PointData data4 = latest.get(info4.getPointKey());
  3385. if (data4.getValue() == 1.0) {
  3386. data4.setDoubleValue(4.0);
  3387. data4.setBooleanValue(false);
  3388. info4.setPointDatas(Collections.singletonList(data4));
  3389. result.add(info4);
  3390. } else {
  3391. PointInfo info1 = map.get("MX001");
  3392. PointData data1 = latest.get(info1.getPointKey());
  3393. if (data1.getValue() == 1.0) {
  3394. data1.setDoubleValue(1.0);
  3395. data1.setBooleanValue(false);
  3396. info1.setPointDatas(Collections.singletonList(data1));
  3397. result.add(info1);
  3398. } else {
  3399. System.out.println("wtId: " + wtId + ",状态值无批配: " + data1.getValue());
  3400. data1.setDoubleValue(2.0);
  3401. info1.setPointDatas(Collections.singletonList(data1));
  3402. result.add(info1);
  3403. }
  3404. }
  3405. }
  3406. }
  3407. }
  3408. });
  3409. Map<Double, Long> longMap = result.stream().collect(Collectors.groupingBy(pi -> pi.getPointDatas().get(0).getValue(), Collectors.counting()));
  3410. return longMap;
  3411. }
  3412. public Map<Double, Long> calcSectionAiztTs(Date time, String id, Function<PointInfo, String> fun) {
  3413. List<PointInfo> entityAiZt = getEntity("AI422", "state");
  3414. entityAiZt = entityAiZt.stream().filter(pi -> id.equals(fun.apply(pi))).collect(Collectors.toList());
  3415. if (CollUtil.isEmpty(entityAiZt)) return new HashMap<>();
  3416. List<StateAi> list = stateAiService.list();
  3417. //机型,源状态,目标状态
  3418. Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
  3419. String collect = entityAiZt.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
  3420. Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), collect, time.getTime());
  3421. for (PointInfo info : entityAiZt) {
  3422. PointData data = latest.get(info.getPointKey());
  3423. Integer m = collectAi.get(info.getSpare()).get((int) data.getValue());
  3424. if (m == null) {
  3425. m = 2;
  3426. System.out.println("ai状态未配对:" + data.getValue());
  3427. }
  3428. data.setDoubleValue(m);
  3429. info.setPointDatas(Collections.singletonList(data));
  3430. }
  3431. Map<Double, Long> longMap = entityAiZt.stream().collect(Collectors.groupingBy(pi -> pi.getPointDatas().get(0).getValue(), Collectors.counting()));
  3432. return longMap;
  3433. }
  3434. public void getAgoAvg(List<PointInfo> entity, Date start, Date end) {
  3435. for (PointInfo info : entity) {
  3436. DoubleStatData snap = adapter.getHistoryStat(goldenUri(), info.getPointKey(), start.getTime(), end.getTime());
  3437. ThreadUtil.sleep(5);
  3438. info.setPointDatas(Collections.singletonList(snap.getAvg()));
  3439. }
  3440. }
  3441. public void calcRealtimeTurbineXd(PointInfo ztInfo, PointData gl, PointData fs, PointData ylzsgd) {
  3442. Map<String, EquipmentModel> map = equipmentModelService.map();
  3443. Double capacity = map.get(ztInfo.getSpare()).getPowerProduction();
  3444. PointData zt = ztInfo.getPointDatas().get(0);
  3445. if (gl.getValue() < capacity * 0.9) {
  3446. if (fs.getValue() >= 12) {
  3447. zt.setDoubleValue(8.0);
  3448. }
  3449. if (ylzsgd.getValue() != 0 && ylzsgd.getValue() < 17.3) {//降出力
  3450. zt.setDoubleValue(8.0);
  3451. }
  3452. }
  3453. }
  3454. //此处加公式
  3455. public boolean calcRealtimeStationXd(PointInfo agcInfo, List<PointData> cxSnap, List<PointData> zsglSnap) {
  3456. String stId = agcInfo.getStationId();
  3457. List<PointData> agcSnap = agcInfo.getPointDatas();
  3458. List<PointData> zsgl5s = get5Avg(zsglSnap);
  3459. List<PointData> agc5s = get5Avg(agcSnap);
  3460. List<PointData> cx5s = get5Avg(cxSnap);
  3461. //之前是否限电
  3462. boolean iszqxd = false;
  3463. for (int i = 0; i < zsglSnap.size(); i++) {
  3464. boolean isxd = false;
  3465. double zsgl = zsglSnap.get(i).getValue();
  3466. double zsgl5 = zsgl5s.get(i).getValue();
  3467. double agc = agcSnap.get(i).getValue();
  3468. double agc5 = agc5s.get(i).getValue();
  3469. double cxgl = cxSnap.get(i).getValue();
  3470. double cxgl5 = cx5s.get(i).getValue();
  3471. boolean k; //agc一直不变
  3472. //第一次初始化复制实时数据到缓存
  3473. if (CalcCache.powerCacheRt.get(stId) == null || CalcCache.powerCacheRt.get(stId) != agc) {
  3474. CalcCache.powerCacheRt.put(stId, agc);
  3475. k = false;
  3476. } else {
  3477. k = true;
  3478. }
  3479. if (agc != 0) {
  3480. //如果场站限电状态为不限电
  3481. if (zsgl5 >= agcInfo.getSpare2() * 40) {
  3482. if (agc5 <= cxgl5) {
  3483. isxd = true;
  3484. } else if (iszqxd) {
  3485. if (zsgl / agc > 1.15) {
  3486. isxd = true;
  3487. } else if (zsgl > agc && agc5 - cxgl5 < 400) {
  3488. isxd = true;
  3489. }
  3490. } else if (zsgl / agc >= 1.2 && agc - cxgl <= 200) {
  3491. isxd = true;
  3492. }
  3493. } else if (k) {
  3494. if (zsgl / agc >= 1.1 && agc5 - cxgl5 <= 200) {
  3495. isxd = true;
  3496. }
  3497. }
  3498. }
  3499. iszqxd = isxd;
  3500. }
  3501. return iszqxd;
  3502. }
  3503. /*public void calcStationSwGwCyRdl(Date date) {
  3504. //date当天零点
  3505. DateTime time = DateUtil.beginOfDay(date);
  3506. //date昨天零点
  3507. DateTime time0 = DateUtil.offsetDay(time, -1);
  3508. List<PointInfo> swdlEt = getEntity("Z-ZXYG-CX", "meter");
  3509. List<PointInfo> gwdlEt = getEntity("Z-FXYG-CX", "meter");
  3510. List<PointInfo> cydlEt = getEntity("Z-ZXYG-ZYB", "meter");
  3511. getZeroNextData(swdlEt, time0, time);
  3512. getZeroNextData(gwdlEt, time0, time);
  3513. getZeroNextData(cydlEt, time0, time);
  3514. Map<String, PointInfo> swdlMap = swdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  3515. Map<String, PointInfo> gwdlMap = gwdlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  3516. Map<String, PointInfo> cydlMap = cydlEt.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  3517. List<StationInfoDay> byDate = getStationinfoByDate(time0, swdlEt);
  3518. String stId;
  3519. PointInfo swdlPi, gwdlPi, cydlPi;
  3520. for (StationInfoDay info : byDate) {
  3521. stId = info.getStationId();
  3522. swdlPi = swdlMap.get(stId);
  3523. gwdlPi = gwdlMap.get(stId);
  3524. cydlPi = cydlMap.get(stId);
  3525. int swdl = (int) ((swdlPi.getPointDatas().get(1).getValue() - swdlPi.getPointDatas().get(0).getValue()) * swdlPi.getCoef());
  3526. int gwdl = (int) ((gwdlPi.getPointDatas().get(1).getValue() - gwdlPi.getPointDatas().get(0).getValue()) * gwdlPi.getCoef());
  3527. int cydl = (int) ((cydlPi.getPointDatas().get(1).getValue() - cydlPi.getPointDatas().get(0).getValue()) * cydlPi.getCoef());
  3528. if (swdl < 0 || swdl > 1000000) swdl = 0;
  3529. if (gwdl < 0 || gwdl > 1000000) gwdl = 0;
  3530. if (cydl < 0 || cydl > 1000000) cydl = 0;
  3531. info.setSwdl(swdl);
  3532. info.setGwdl(gwdl);
  3533. info.setCydl(cydl);
  3534. }
  3535. stationInfoDayService.saveOrUpdateBatch(byDate);
  3536. }*/
  3537. public void writeReportPool5SPjfsLlfdlZtsj(Date date) {
  3538. //date当天零点
  3539. DateTime time = DateUtil.beginOfDay(date);
  3540. //date昨天零点
  3541. DateTime time0 = DateUtil.offsetDay(time, -1);
  3542. DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
  3543. DateTime beginOfYear = DateUtil.beginOfYear(time0);
  3544. QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
  3545. wrapper.select("sum(llfdl) llfdl,sum(jhjxss) jhjxss,sum(fjhjxss) fjhjxss,sum(xdss) xdss,sum(slss) slss,sum(xnss) xnss," +
  3546. "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," +
  3547. "sum(jx_min) jx_min,sum(xd_min) xd_min,sum(lx_min) lx_min,project_id,station_id")
  3548. .eq("record_date", time0).groupBy("project_id,station_id");
  3549. List<TurbineInfoDay> days = turbineInfoDayService.list(wrapper);
  3550. Map<String, TurbineInfoDay> dayMap = days.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  3551. wrapper = new QueryWrapper<>();
  3552. wrapper.select("sum(llfdl) llfdl,sum(jhjxss) jhjxss,sum(fjhjxss) fjhjxss,sum(xdss) xdss,sum(slss) slss,sum(xnss) xnss," +
  3553. "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," +
  3554. "sum(jx_min) jx_min,sum(xd_min) xd_min,sum(lx_min) lx_min,project_id,station_id")
  3555. .between("record_date", beginOfMonth, time0).groupBy("project_id,station_id");
  3556. List<TurbineInfoDay> monthDays = turbineInfoDayService.list(wrapper);
  3557. Map<String, TurbineInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  3558. wrapper = new QueryWrapper<>();
  3559. wrapper.select("sum(llfdl) llfdl,sum(jhjxss) jhjxss,sum(fjhjxss) fjhjxss,sum(xdss) xdss,sum(slss) slss,sum(xnss) xnss," +
  3560. "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," +
  3561. "sum(jx_min) jx_min,sum(xd_min) xd_min,sum(lx_min) lx_min,project_id,station_id")
  3562. .between("record_date", beginOfYear, time0).groupBy("project_id,station_id");
  3563. List<TurbineInfoDay> yearDays = turbineInfoDayService.list(wrapper);
  3564. Map<String, TurbineInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  3565. QueryWrapper<ProEconReportIndicatorPool> wrapperRp = new QueryWrapper<>();
  3566. wrapperRp.eq("record_date", time0).last("and foreign_key_id = project_id");
  3567. List<ProEconReportIndicatorPool> poolsProject = reportIndicatorPoolService.list(wrapperRp);
  3568. wrapperRp = new QueryWrapper<>();
  3569. wrapperRp.eq("record_date", time0).last("and foreign_key_id = windpowerstation_id");
  3570. List<ProEconReportIndicatorPool> poolsStation = reportIndicatorPoolService.list(wrapperRp);
  3571. wrapperRp = new QueryWrapper<>();
  3572. wrapperRp.eq("record_date", time0).eq("foreign_key_id", "GJNY_SXGS_DBXNY_ZGS0");
  3573. ProEconReportIndicatorPool poolsCompany = reportIndicatorPoolService.getOne(wrapperRp);
  3574. TurbineInfoDay day, month, year;
  3575. String projectId;
  3576. if (poolsProject.isEmpty()) {
  3577. for (TurbineInfoDay infoDay : days) {
  3578. projectId = infoDay.getProjectId();
  3579. ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
  3580. pool.setRecordDate(time0);
  3581. pool.setForeignKeyId(projectId);
  3582. pool.setWindpowerstationId(infoDay.getStationId());
  3583. pool.setProjectId(projectId);
  3584. month = monthMap.get(projectId);
  3585. year = yearMap.get(projectId);
  3586. poolSetValue1(pool, infoDay, month, year);
  3587. poolsProject.add(pool);
  3588. }
  3589. } else {
  3590. for (ProEconReportIndicatorPool pool : poolsProject) {
  3591. projectId = pool.getProjectId();
  3592. day = dayMap.get(projectId);
  3593. month = monthMap.get(projectId);
  3594. year = yearMap.get(projectId);
  3595. poolSetValue1(pool, day, month, year);
  3596. }
  3597. }
  3598. reportIndicatorPoolService.saveOrUpdateBatch(poolsProject);
  3599. Map<String, List<ProEconReportIndicatorPool>> projectMap = poolsProject.stream().collect(Collectors.groupingBy(ProEconReportIndicatorPool::getWindpowerstationId));
  3600. if (poolsStation.isEmpty()) {
  3601. projectMap.forEach((StId, pis) -> {
  3602. ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
  3603. pool.setRecordDate(time0);
  3604. pool.setForeignKeyId(StId);
  3605. pool.setWindpowerstationId(StId);
  3606. poolSetValue(pool, pis);
  3607. poolsStation.add(pool);
  3608. });
  3609. } else {
  3610. for (ProEconReportIndicatorPool pool : poolsStation) {
  3611. List<ProEconReportIndicatorPool> pools = projectMap.get(pool.getWindpowerstationId());
  3612. poolSetValue(pool, pools);
  3613. }
  3614. }
  3615. reportIndicatorPoolService.saveOrUpdateBatch(poolsStation);
  3616. if (poolsCompany == null) {
  3617. poolsCompany = new ProEconReportIndicatorPool();
  3618. poolsCompany.setRecordDate(time0);
  3619. poolsCompany.setForeignKeyId("GJNY_SXGS_DBXNY_ZGS0");
  3620. poolsCompany.setCompanyId("GJNY_SXGS_DBXNY_ZGS");
  3621. poolSetValue(poolsCompany, poolsStation);
  3622. } else {
  3623. poolSetValue(poolsCompany, poolsStation);
  3624. }
  3625. reportIndicatorPoolService.saveOrUpdate(poolsCompany);
  3626. }
  3627. public void writeReportPoolPjfs2(Date date) {
  3628. //date当天零点
  3629. DateTime time = DateUtil.beginOfDay(date);
  3630. //date昨天零点
  3631. DateTime time0 = DateUtil.offsetDay(time, -1);
  3632. DateTime beginOfMonth = DateUtil.beginOfMonth(time0);
  3633. DateTime beginOfYear = DateUtil.beginOfYear(time0);
  3634. QueryWrapper<TurbineInfoDay> wrapper = new QueryWrapper<>();
  3635. wrapper.select("avg(pjfs) pjfs,project_id,station_id")
  3636. .eq("record_date", time0).groupBy("project_id,station_id");
  3637. List<TurbineInfoDay> days = turbineInfoDayService.list(wrapper);
  3638. Map<String, TurbineInfoDay> dayMap = days.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  3639. wrapper = new QueryWrapper<>();
  3640. wrapper.select("avg(pjfs) pjfs,project_id,station_id")
  3641. .between("record_date", beginOfMonth, time0).groupBy("project_id,station_id");
  3642. List<TurbineInfoDay> monthDays = turbineInfoDayService.list(wrapper);
  3643. Map<String, TurbineInfoDay> monthMap = monthDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  3644. wrapper = new QueryWrapper<>();
  3645. wrapper.select("avg(pjfs) pjfs,project_id,station_id")
  3646. .between("record_date", beginOfYear, time0).groupBy("project_id,station_id");
  3647. List<TurbineInfoDay> yearDays = turbineInfoDayService.list(wrapper);
  3648. Map<String, TurbineInfoDay> yearMap = yearDays.stream().collect(Collectors.toMap(TurbineInfoDay::getProjectId, Function.identity()));
  3649. QueryWrapper<ProEconReportIndicatorPool> wrapperRp = new QueryWrapper<>();
  3650. wrapperRp.eq("record_date", time0).last("and foreign_key_id = project_id");
  3651. List<ProEconReportIndicatorPool> poolsProject = reportIndicatorPoolService.list(wrapperRp);
  3652. wrapperRp = new QueryWrapper<>();
  3653. wrapperRp.eq("record_date", time0).last("and foreign_key_id = windpowerstation_id");
  3654. List<ProEconReportIndicatorPool> poolsStation = reportIndicatorPoolService.list(wrapperRp);
  3655. wrapperRp = new QueryWrapper<>();
  3656. wrapperRp.eq("record_date", time0).eq("foreign_key_id", "GJNY_SXGS_DBXNY_ZGS0");
  3657. ProEconReportIndicatorPool poolsCompany = reportIndicatorPoolService.getOne(wrapperRp);
  3658. TurbineInfoDay day, month, year;
  3659. String projectId;
  3660. if (poolsProject.isEmpty()) {
  3661. for (TurbineInfoDay infoDay : days) {
  3662. projectId = infoDay.getProjectId();
  3663. ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
  3664. pool.setRecordDate(time0);
  3665. pool.setForeignKeyId(projectId);
  3666. pool.setWindpowerstationId(infoDay.getStationId());
  3667. pool.setProjectId(projectId);
  3668. month = monthMap.get(projectId);
  3669. year = yearMap.get(projectId);
  3670. pool.setRpjfs(infoDay.getPjfs());
  3671. pool.setYpjfs(month.getPjfs());
  3672. pool.setNpjfs(year.getPjfs());
  3673. poolsProject.add(pool);
  3674. }
  3675. } else {
  3676. for (ProEconReportIndicatorPool pool : poolsProject) {
  3677. projectId = pool.getProjectId();
  3678. day = dayMap.get(projectId);
  3679. month = monthMap.get(projectId);
  3680. year = yearMap.get(projectId);
  3681. pool.setRpjfs(day.getPjfs());
  3682. pool.setYpjfs(month.getPjfs());
  3683. pool.setNpjfs(year.getPjfs());
  3684. }
  3685. }
  3686. reportIndicatorPoolService.saveOrUpdateBatch(poolsProject);
  3687. Map<String, List<ProEconReportIndicatorPool>> projectMap = poolsProject.stream().collect(Collectors.groupingBy(ProEconReportIndicatorPool::getWindpowerstationId));
  3688. if (poolsStation.isEmpty()) {
  3689. projectMap.forEach((StId, pis) -> {
  3690. ProEconReportIndicatorPool pool = new ProEconReportIndicatorPool();
  3691. pool.setRecordDate(time0);
  3692. pool.setForeignKeyId(StId);
  3693. pool.setWindpowerstationId(StId);
  3694. ProEconReportIndicatorPool p = sumProperties(pis, ProEconReportIndicatorPool.class);
  3695. pool.setRpjfs(p.getRpjfs() / pis.size());
  3696. pool.setYpjfs(p.getYpjfs() / pis.size());
  3697. pool.setNpjfs(p.getNpjfs() / pis.size());
  3698. poolsStation.add(pool);
  3699. });
  3700. } else {
  3701. for (ProEconReportIndicatorPool pool : poolsStation) {
  3702. List<ProEconReportIndicatorPool> pools = projectMap.get(pool.getWindpowerstationId());
  3703. ProEconReportIndicatorPool p = sumProperties(pools, ProEconReportIndicatorPool.class);
  3704. pool.setRpjfs(p.getRpjfs() / pools.size());
  3705. pool.setYpjfs(p.getYpjfs() / pools.size());
  3706. pool.setNpjfs(p.getNpjfs() / pools.size());
  3707. }
  3708. }
  3709. reportIndicatorPoolService.saveOrUpdateBatch(poolsStation);
  3710. if (poolsCompany == null) {
  3711. poolsCompany = new ProEconReportIndicatorPool();
  3712. poolsCompany.setRecordDate(time0);
  3713. poolsCompany.setForeignKeyId("GJNY_SXGS_DBXNY_ZGS0");
  3714. poolsCompany.setCompanyId("GJNY_SXGS_DBXNY_ZGS");
  3715. ProEconReportIndicatorPool p = sumProperties(poolsStation, ProEconReportIndicatorPool.class);
  3716. poolsCompany.setRpjfs(p.getRpjfs() / poolsStation.size());
  3717. poolsCompany.setYpjfs(p.getYpjfs() / poolsStation.size());
  3718. poolsCompany.setNpjfs(p.getNpjfs() / poolsStation.size());
  3719. } else {
  3720. ProEconReportIndicatorPool p = sumProperties(poolsStation, ProEconReportIndicatorPool.class);
  3721. poolsCompany.setRpjfs(p.getRpjfs() / poolsStation.size());
  3722. poolsCompany.setYpjfs(p.getYpjfs() / poolsStation.size());
  3723. poolsCompany.setNpjfs(p.getNpjfs() / poolsStation.size());
  3724. }
  3725. reportIndicatorPoolService.saveOrUpdate(poolsCompany);
  3726. }
  3727. public void poolSetValue1(ProEconReportIndicatorPool pool, TurbineInfoDay day, TurbineInfoDay month, TurbineInfoDay year) {
  3728. pool.setRpjfs(day.getPjfs());
  3729. pool.setRgzssdl(day.getGzss() == null ? day.getFjhjxss() * 0.11 : day.getGzss());
  3730. pool.setRjxssdl(day.getJhjxss());
  3731. pool.setRdjssdl(day.getDjss() == null ? day.getFjhjxss() * 0.89 : day.getDjss());
  3732. pool.setRxnssdl(day.getXnss());
  3733. pool.setRxdjclssdl(day.getXdss());
  3734. pool.setRllfdl(day.getLlfdl());
  3735. pool.setRhjdjxs(day.getDjMin() / 60);
  3736. pool.setRhjgztjxs(day.getGzMin() / 60);
  3737. pool.setRhjtxzdxs(day.getLxMin() / 60);
  3738. pool.setRhjjxtjxs(day.getJxMin() / 60);
  3739. pool.setRhjxdxs(day.getXdMin() / 60);
  3740. pool.setRhjyxxs(day.getYxMin() / 60);
  3741. pool.setRhjslxs(0.0);
  3742. pool.setYpjfs(month.getPjfs());
  3743. pool.setYgzssdl(month.getGzss() == null ? month.getFjhjxss() * 0.11 : month.getGzss());
  3744. pool.setYjxssdl(month.getJhjxss());
  3745. pool.setYdjssdl(month.getDjss() == null ? month.getFjhjxss() * 0.89 : month.getDjss());
  3746. pool.setYxnssdl(month.getXnss());
  3747. pool.setYxdjclssdl(month.getXdss());
  3748. pool.setYllfdl(month.getLlfdl());
  3749. pool.setYhjdjxs(month.getDjMin() / 60);
  3750. pool.setYhjgztjxs(month.getGzMin() / 60);
  3751. pool.setYhjtxzdxs(month.getLxMin() / 60);
  3752. pool.setYhjjxtjxs(month.getJxMin() / 60);
  3753. pool.setYhjxdxs(month.getXdMin() / 60);
  3754. pool.setYhjyxxs(month.getYxMin() / 60);
  3755. pool.setYhjslxs(0.0);
  3756. pool.setNpjfs(year.getPjfs());
  3757. pool.setNgzssdl(year.getGzss() == null ? year.getFjhjxss() * 0.11 : year.getGzss());
  3758. pool.setNjxssdl(year.getJhjxss());
  3759. pool.setNdjssdl(year.getDjss() == null ? year.getFjhjxss() * 0.89 : year.getDjss());
  3760. pool.setNxnssdl(year.getXnss());
  3761. pool.setNxdjclssdl(year.getXdss());
  3762. pool.setNllfdl(year.getLlfdl());
  3763. pool.setNhjdjxs(year.getDjMin() / 60);
  3764. pool.setNhjgztjxs(year.getGzMin() / 60);
  3765. pool.setNhjtxzdxs(year.getLxMin() / 60);
  3766. pool.setNhjjxtjxs(year.getJxMin() / 60);
  3767. pool.setNhjxdxs(year.getXdMin() / 60);
  3768. pool.setNhjyxxs(year.getYxMin() / 60);
  3769. pool.setNhjslxs(0.0);
  3770. }
  3771. public void poolSetValue(ProEconReportIndicatorPool pool, List<ProEconReportIndicatorPool> pools) {
  3772. ProEconReportIndicatorPool p = sumProperties(pools, ProEconReportIndicatorPool.class);
  3773. pool.setRpjfs(p.getRpjfs() / pools.size());
  3774. pool.setRgzssdl(p.getRgzssdl());
  3775. pool.setRjxssdl(p.getRjxssdl());
  3776. pool.setRdjssdl(p.getRdjssdl());
  3777. pool.setRxnssdl(p.getRxnssdl());
  3778. pool.setRxdjclssdl(p.getRxdjclssdl());
  3779. pool.setRllfdl(p.getRllfdl());
  3780. pool.setRhjdjxs(p.getRhjdjxs());
  3781. pool.setRhjgztjxs(p.getRhjgztjxs());
  3782. pool.setRhjtxzdxs(p.getRhjtxzdxs());
  3783. pool.setRhjjxtjxs(p.getRhjjxtjxs());
  3784. pool.setRhjxdxs(p.getRhjxdxs());
  3785. pool.setRhjyxxs(p.getRhjyxxs());
  3786. pool.setRhjslxs(0.0);
  3787. pool.setYpjfs(p.getYpjfs() / pools.size());
  3788. pool.setYgzssdl(p.getYgzssdl());
  3789. pool.setYjxssdl(p.getYjxssdl());
  3790. pool.setYdjssdl(p.getYdjssdl());
  3791. pool.setYxnssdl(p.getYxnssdl());
  3792. pool.setYxdjclssdl(p.getYxdjclssdl());
  3793. pool.setYllfdl(p.getYllfdl());
  3794. pool.setYhjdjxs(p.getYhjdjxs());
  3795. pool.setYhjgztjxs(p.getYhjgztjxs());
  3796. pool.setYhjtxzdxs(p.getYhjtxzdxs());
  3797. pool.setYhjjxtjxs(p.getYhjjxtjxs());
  3798. pool.setYhjxdxs(p.getYhjxdxs());
  3799. pool.setYhjyxxs(p.getYhjyxxs());
  3800. pool.setYhjslxs(0.0);
  3801. pool.setNpjfs(p.getNpjfs() / pools.size());
  3802. pool.setNgzssdl(p.getNgzssdl());
  3803. pool.setNjxssdl(p.getNjxssdl());
  3804. pool.setNdjssdl(p.getNdjssdl());
  3805. pool.setNxnssdl(p.getNxnssdl());
  3806. pool.setNxdjclssdl(p.getNxdjclssdl());
  3807. pool.setNllfdl(p.getNllfdl());
  3808. pool.setNhjdjxs(p.getNhjdjxs());
  3809. pool.setNhjgztjxs(p.getNhjgztjxs());
  3810. pool.setNhjtxzdxs(p.getNhjtxzdxs());
  3811. pool.setNhjjxtjxs(p.getNhjjxtjxs());
  3812. pool.setNhjxdxs(p.getNhjxdxs());
  3813. pool.setNhjyxxs(p.getNhjyxxs());
  3814. pool.setNhjslxs(0.0);
  3815. }
  3816. public <T> T sumProperties(List<T> list, Class<T> clazz) {
  3817. T result;
  3818. try {
  3819. result = clazz.getDeclaredConstructor().newInstance();
  3820. } catch (Exception e) {
  3821. e.printStackTrace();
  3822. return null;
  3823. }
  3824. if (list == null || list.isEmpty()) return result;
  3825. // 获取所有字段
  3826. Field[] fields = clazz.getDeclaredFields();
  3827. for (Field field : fields) {
  3828. field.setAccessible(true); // 确保私有字段也可以被访问
  3829. // 检查字段类型是否为Double
  3830. Class<?> type = field.getType();
  3831. if (type.equals(Double.class) || type.equals(Integer.class) || type.equals(Long.class) || type.equals(Float.class)) {
  3832. double sum = 0.0;
  3833. // 遍历列表中的每个对象并累加数值字段
  3834. try {
  3835. for (T item : list) {
  3836. Field itemField = clazz.getDeclaredField(field.getName());
  3837. itemField.setAccessible(true);
  3838. // 尝试获取当前对象的字段值
  3839. Double value = (Double) itemField.get(item); // 注意类型转换
  3840. if (value != null) sum += value;
  3841. }
  3842. // 设置累加后的值到结果对象中
  3843. if (type.equals(Double.class)) {
  3844. field.set(result, sum);
  3845. } else if (type.equals(Integer.class)) {
  3846. field.set(result, (int) sum);
  3847. } else if (type.equals(Long.class)) {
  3848. field.set(result, (long) sum);
  3849. } else {
  3850. field.set(result, (float) sum);
  3851. }
  3852. } catch (Exception e) {
  3853. e.printStackTrace();
  3854. return result;
  3855. }
  3856. }
  3857. }
  3858. return result;
  3859. }
  3860. private ProEconReportIndicatorPool getPoolSum(List<ProEconReportIndicatorPool> pools) {
  3861. ProEconReportIndicatorPool pool0 = new ProEconReportIndicatorPool();
  3862. for (ProEconReportIndicatorPool pool : pools) {
  3863. pool0.setRfdldb(nullSum(pool0.getRfdldb(), pool.getRfdldb()));
  3864. pool0.setRswdldb(nullSum(pool0.getRswdldb(), pool.getRswdldb()));
  3865. pool0.setRgwgwdldb(nullSum(pool0.getRgwgwdldb(), pool.getRgwgwdldb()));
  3866. pool0.setRnwgwdldb(nullSum(pool0.getRnwgwdldb(), pool.getRnwgwdldb()));
  3867. }
  3868. return pool0;
  3869. }
  3870. public double nullSum(Double a, Double b) {
  3871. if (a == null) a = 0.0;
  3872. if (b == null) b = 0.0;
  3873. return a + b;
  3874. }
  3875. public double calcQfzt(Double ssgl, Double zsgl) {
  3876. if (ssgl == null || ssgl < 0) ssgl = 0.0;
  3877. double qfzt, ratioll;
  3878. ratioll = (zsgl == null || zsgl <= 0) ? 0 : (zsgl - ssgl) / zsgl;
  3879. if (ratioll < 0.05) {
  3880. qfzt = 0;
  3881. } else if (ratioll < 0.1) {
  3882. qfzt = 1;
  3883. } else if (ratioll < 0.2) {
  3884. qfzt = 2;
  3885. } else if (ratioll < 0.4) {
  3886. qfzt = 3;
  3887. } else {
  3888. qfzt = 4;
  3889. }
  3890. return qfzt;
  3891. }
  3892. public List<TurbineInfoMin> getTurbineinfoByMin(Date date) {
  3893. QueryWrapper<TurbineInfoMin> wrapper = new QueryWrapper<>();
  3894. wrapper.eq("record_date", date);
  3895. return turbineInfoMinService.list(wrapper);
  3896. }
  3897. public List<TurbineInfoMin> getTurbineinfoByMin(Date date, List<PointInfo> entity) {
  3898. List<TurbineInfoMin> list = getTurbineinfoByMin(date);
  3899. if (list.isEmpty()) {
  3900. entity.forEach(pi -> {
  3901. TurbineInfoMin day = new TurbineInfoMin();
  3902. day.setStationId(pi.getStationId());
  3903. day.setProjectId(pi.getProjectId());
  3904. day.setLineId(pi.getLineId());
  3905. day.setTurbineId(pi.getTurbineId());
  3906. day.setRecordDate(date);
  3907. list.add(day);
  3908. });
  3909. }
  3910. return list;
  3911. }
  3912. public Map<String, TurbineInfoMin> getTurbineinfoByMinMap(Date date) {
  3913. List<TurbineInfoMin> tims = getTurbineinfoByMin(date);
  3914. return tims.stream().collect(Collectors.toMap(TurbineInfoMin::getTurbineId, Function.identity()));
  3915. }
  3916. public Map<String, TurbineInfoMin> getTurbineinfoByMinMap(Date date, List<PointInfo> entity) {
  3917. List<TurbineInfoMin> tims = getTurbineinfoByMin(date, entity);
  3918. return tims.stream().collect(Collectors.toMap(TurbineInfoMin::getTurbineId, Function.identity()));
  3919. }
  3920. public Map<String, PointInfo> getRawDataByEntity(List<PointInfo> entity, URI uri, Date start, Date end, Function<PointInfo, String> function) {
  3921. getRawDataByEntity(entity, uri, start, end);
  3922. return entity.stream().collect(Collectors.toMap(function, Function.identity()));
  3923. }
  3924. public void calcTurbinePjfsPjglKyglLlglMin(Date date, int granularity) {
  3925. date = DateUtil.beginOfMinute(date);
  3926. DateTime start = DateUtil.offsetMinute(date, -granularity);
  3927. //风速
  3928. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  3929. Map<String, PointInfo> rawMapFs = getRawDataByEntity(entityFs, goldenUri(), start, date, PointInfo::getTurbineId);
  3930. //功率
  3931. List<PointInfo> entityGl = getEntity("AI114", "turbine");
  3932. Map<String, PointInfo> rawMapGl = getRawDataByEntity(entityGl, goldenUri(), start, date, PointInfo::getTurbineId);
  3933. List<PointInfo> entityZt = getEntity("MXZT", "turbine");
  3934. Map<String, PointInfo> rawMapZt = getRawDataByEntity(entityZt, goldenUri(), start, date, PointInfo::getTurbineId);
  3935. List<TurbineInfoMin> mins = getTurbineinfoByMin(date, entityFs);
  3936. for (TurbineInfoMin min : mins) {
  3937. String tbId = min.getTurbineId();
  3938. List<PointData> fsDatas = rawMapFs.get(tbId).getPointDatas();
  3939. List<PointData> ztDatas = rawMapZt.get(tbId).getPointDatas();
  3940. ztDatas = doublePointDatasFull(2, ztDatas, start.getTime(), date.getTime(), 1);
  3941. Map<Long, Double> ztMap = ztDatas.stream().collect(Collectors.toMap(PointData::getTs, PointData::getValue));
  3942. double pjfs = fsDatas.stream().mapToDouble(PointData::getValue).average().orElse(0.0);
  3943. fsDatas = fsDatas.stream().peek(pd -> pd.setDoubleValue(pd.getValue() >= 23 ? 23 : pd.getValue() < 0 ? 0 : NumberUtil.round(pd.getValue(), 2).doubleValue())).collect(Collectors.toList());
  3944. for (PointData fsData : fsDatas) {
  3945. if (fsData.getValue() > 3 && CalcCache.llgl.get(tbId).get(fsData.getValue()) == null) {
  3946. System.out.println();
  3947. }
  3948. }
  3949. double llgl = fsDatas.stream().mapToDouble(pd -> pd.getValue() <= 3 ? 0d : CalcCache.llgl.get(tbId).get(pd.getValue())).average().orElse(0.0);
  3950. double kygl = fsDatas.stream().filter(pd -> ztMap.get(pd.getTs()) != 4 || ztMap.get(pd.getTs()) != 6)
  3951. .mapToDouble(pd -> CalcCache.fitcoef.get(tbId).get(pd.getValue())).average().orElse(0.0);
  3952. double sjgl = rawMapGl.get(tbId).getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0);
  3953. double v = llgl * 0.9;
  3954. if (kygl > v) kygl = v;
  3955. if (kygl < sjgl) kygl = sjgl;
  3956. if (llgl < sjgl) llgl = sjgl * 1.0005;
  3957. min.setPjfs(pjfs);
  3958. min.setPjgl(sjgl);
  3959. min.setLlgl(llgl);
  3960. min.setKygl(kygl);
  3961. }
  3962. turbineInfoMinService.saveOrUpdateBatch(mins);
  3963. }
  3964. public void calcStationRealtimeLLgl() {
  3965. DateTime end = DateUtil.date();
  3966. DateTime date = DateUtil.offsetMinute(end, -5);
  3967. Map<String, String> sszllglMap = getEntityMap("SSZLLGL", "station");
  3968. //出线
  3969. List<PointInfo> entityCx = getEntity("AGC001", "booster");
  3970. getLatestByEntity(entityCx);
  3971. //风速
  3972. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  3973. getRawDataByEntity(entityFs, goldenUri(), date, end);
  3974. for (PointInfo fsPi : entityFs) {
  3975. List<PointData> pds = fsPi.getPointDatas();
  3976. Double pd = pds.stream().mapToDouble(PointData::getValue).average().orElse(0);
  3977. double fs = pd > 25 ? 24.99 : pd < 0 ? 0 : NumberUtil.round(pd, 2).doubleValue();
  3978. double llgl = fs < 3 ? 0d : CalcCache.llgl.get(fsPi.getTurbineId()).get(fs);
  3979. fsPi.setSpare2(llgl);
  3980. }
  3981. Map<String, List<PointInfo>> stPisMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  3982. List<PointData> pds = new ArrayList<>();
  3983. for (PointInfo cx : entityCx) {
  3984. PointData pdCx = cx.getPointDatas().get(0);
  3985. double sjgl = pdCx.getValue() * cx.getCoef();
  3986. double llgl = stPisMap.get(cx.getStationId()).stream().mapToDouble(pi -> pi.getSpare2()).sum();
  3987. if (pdCx.getTs() + 10 * 60 * 1000 > end.getTime()) {
  3988. if (llgl < sjgl) llgl = sjgl * 1.0005;
  3989. if (llgl > sjgl * 1.5) llgl = sjgl * 1.5;
  3990. } else {
  3991. System.out.println("实际功率测点离线");
  3992. }
  3993. PointData data = new PointData();
  3994. data.setTs(System.currentTimeMillis());
  3995. data.setTagName(sszllglMap.get(cx.getStationId()));
  3996. data.setDoubleValue(llgl);
  3997. pds.add(data);
  3998. }
  3999. adapter.writeHistoryBatch(taosUri(), pds);
  4000. }
  4001. public void calcTurbineSsfsQx(Date date) {
  4002. DateTime date0 = DateUtil.beginOfDay(date);
  4003. DateTime date1 = DateUtil.endOfDay(date);
  4004. //风速
  4005. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  4006. List<String> fjs = Arrays.asList("GJNY_SXGS_FSG_F_WT_0040_EQ", "GJNY_SXGS_FSG_F_WT_0047_EQ");
  4007. entityFs = entityFs.stream().filter(e -> fjs.contains(e.getTurbineId())).collect(Collectors.toList());
  4008. getSnapDataByEntity(entityFs, date0, date1, 60);
  4009. int i = 0;
  4010. for (PointInfo et : entityFs) {
  4011. StrBuilder sb = new StrBuilder();
  4012. StrBuilder sb1 = new StrBuilder();
  4013. for (PointData v : et.getPointDatas()) {
  4014. sb.append(v.getValue()).append(",");
  4015. sb1.append(i).append(",");
  4016. i++;
  4017. }
  4018. System.out.println(sb1);
  4019. System.out.println(sb);
  4020. }
  4021. }
  4022. public void calcStationLlglKyglSjglAgcMin(Date date, int granularity) {
  4023. date = DateUtil.beginOfMinute(date);
  4024. DateTime start = DateUtil.offsetMinute(date, -granularity);
  4025. //AGC
  4026. List<PointInfo> entityAgc = getEntity("AGC002", "booster");
  4027. Map<String, PointInfo> statMapAgc = getStatDataByEntity(entityAgc, goldenUri(), start, date, PointInfo::getStationId);
  4028. //出线
  4029. List<PointInfo> entityCx = getEntity("AGC001", "booster");
  4030. Map<String, PointInfo> statMapCx = getStatDataByEntity(entityCx, goldenUri(), start, date, PointInfo::getStationId);
  4031. QueryWrapper<TurbineInfoMin> wrapper = new QueryWrapper<>();
  4032. wrapper.select("sum(llgl) llgl,sum(kygl) kygl,avg(pjfs) pjfs,station_id").eq("record_date", date).groupBy("station_id");
  4033. List<TurbineInfoMin> list = turbineInfoMinService.list(wrapper);
  4034. Map<String, TurbineInfoMin> minMap = list.stream().collect(Collectors.toMap(TurbineInfoMin::getStationId, Function.identity()));
  4035. List<StationInfoMin> byDate = getStationinfoByMin(date, entityAgc);
  4036. for (StationInfoMin day : byDate) {
  4037. String stId = day.getStationId();
  4038. TurbineInfoMin min = minMap.get(stId);
  4039. PointInfo agcInfo = statMapAgc.get(stId);
  4040. PointInfo cxInfo = statMapCx.get(stId);
  4041. day.setLlgl(min.getLlgl());
  4042. day.setKygl(min.getKygl());
  4043. day.setAgc(agcInfo.getPointDatas().get(0).getValue() * agcInfo.getCoef());
  4044. day.setPjgl(cxInfo.getPointDatas().get(0).getValue() * cxInfo.getCoef());
  4045. day.setPjfs(min.getPjfs());
  4046. }
  4047. stationInfoMinService.saveOrUpdateBatch(byDate);
  4048. }
  4049. public Map<String, Map<Double, Long>> calcSectionStationZtts(Date time) {
  4050. List<PointInfo> diztTs = calcSectionStationDiztTs(time);
  4051. List<PointInfo> aiztTs = calcSectionStationAiztTs(time);
  4052. diztTs.addAll(aiztTs);
  4053. Map<String, Map<Double, Long>> sdlMap = new HashMap<>();
  4054. //Map<Double, Long> longMap = result.stream().collect(Collectors.groupingBy(pi -> pi.getPointDatas().get(0).getValue(), Collectors.counting()));
  4055. Map<String, List<PointInfo>> collect = diztTs.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  4056. for (Map.Entry<String, List<PointInfo>> entry : collect.entrySet()) {
  4057. Map<Double, Long> map = entry.getValue().stream().collect(Collectors.groupingBy(pi -> pi.getPointDatas().get(0).getValue(), Collectors.counting()));
  4058. sdlMap.put(entry.getKey(), map);
  4059. }
  4060. return sdlMap;
  4061. }
  4062. public List<PointInfo> calcSectionStationDiztTs(Date time) {
  4063. List<PointInfo> entity = new ArrayList<>();
  4064. List<PointInfo> result = new ArrayList<>();
  4065. List<PointInfo> entity0 = getEntity("MX000", "state");
  4066. List<PointInfo> entity1 = getEntity("MX001", "state");
  4067. List<PointInfo> entity2 = getEntity("MX002", "state");
  4068. List<PointInfo> entity4 = getEntity("MX004", "state");
  4069. List<PointInfo> entity6 = getEntity("MX006", "state");
  4070. entity.addAll(entity0);
  4071. entity.addAll(entity1);
  4072. entity.addAll(entity2);
  4073. entity.addAll(entity4);
  4074. entity.addAll(entity6);
  4075. String keys = entity.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
  4076. Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), keys, time.getTime());
  4077. Map<String, Map<String, PointInfo>> wtUcPis = entity.stream().collect(Collectors.groupingBy(PointInfo::getTurbineId, Collectors.toMap(PointInfo::getUniformCode, Function.identity())));
  4078. wtUcPis.forEach((wtId, map) -> {
  4079. PointInfo info2 = map.get("MX002");
  4080. PointData data2 = latest.get(info2.getPointKey());
  4081. if (data2.getValue() == 1.0) {
  4082. data2.setDoubleValue(2.0);
  4083. data2.setBooleanValue(false);
  4084. info2.setPointDatas(Collections.singletonList(data2));
  4085. result.add(info2);
  4086. } else {
  4087. PointInfo info0 = map.get("MX000");
  4088. PointData data0 = latest.get(info0.getPointKey());
  4089. if (data0.getValue() == 1.0) {
  4090. data0.setDoubleValue(0.0);
  4091. data0.setBooleanValue(false);
  4092. info0.setPointDatas(Collections.singletonList(data0));
  4093. result.add(info0);
  4094. } else {
  4095. PointInfo info6 = map.get("MX006");
  4096. PointData data6 = latest.get(info6.getPointKey());
  4097. if (data6.getValue() == 1.0) {
  4098. data6.setDoubleValue(6.0);
  4099. data6.setBooleanValue(false);
  4100. info6.setPointDatas(Collections.singletonList(data6));
  4101. result.add(info6);
  4102. } else {
  4103. PointInfo info4 = map.get("MX004");
  4104. PointData data4 = latest.get(info4.getPointKey());
  4105. if (data4.getValue() == 1.0) {
  4106. data4.setDoubleValue(4.0);
  4107. data4.setBooleanValue(false);
  4108. info4.setPointDatas(Collections.singletonList(data4));
  4109. result.add(info4);
  4110. } else {
  4111. PointInfo info1 = map.get("MX001");
  4112. PointData data1 = latest.get(info1.getPointKey());
  4113. if (data1.getValue() == 1.0) {
  4114. data1.setDoubleValue(1.0);
  4115. data1.setBooleanValue(false);
  4116. info1.setPointDatas(Collections.singletonList(data1));
  4117. result.add(info1);
  4118. } else {
  4119. data1.setDoubleValue(2.0);
  4120. System.out.println("wtId: " + wtId + ",状态值无批配: " + data1.getValue());
  4121. info1.setPointDatas(Collections.singletonList(data1));
  4122. result.add(info1);
  4123. }
  4124. }
  4125. }
  4126. }
  4127. }
  4128. });
  4129. return result;
  4130. }
  4131. public List<PointInfo> calcSectionStationAiztTs(Date time) {
  4132. List<PointInfo> entityAiZt = getEntity("AI422", "state");
  4133. List<StateAi> list = stateAiService.list();
  4134. //机型,源状态,目标状态
  4135. Map<String, Map<Integer, Integer>> collectAi = list.stream().collect(Collectors.groupingBy(StateAi::getModel, Collectors.toMap(StateAi::getOriginalState, StateAi::getMappingState)));
  4136. String collect = entityAiZt.stream().map(PointInfo::getPointKey).collect(Collectors.joining(","));
  4137. Map<String, PointData> latest = adapter.getHistorySection(goldenUri(), collect, time.getTime());
  4138. for (PointInfo info : entityAiZt) {
  4139. PointData data = latest.get(info.getPointKey());
  4140. Integer m = collectAi.get(info.getSpare()).get((int) data.getValue());
  4141. if (m == null) {
  4142. m = 2;
  4143. System.out.println("ai状态未配对:" + data.getValue());
  4144. }
  4145. data.setDoubleValue(m);
  4146. info.setPointDatas(Collections.singletonList(data));
  4147. }
  4148. return entityAiZt;
  4149. }
  4150. public void calcStationSjglAgcPjfsHjwdDlMin(Date time) {
  4151. DateTime end = DateUtil.beginOfMinute(time);
  4152. int i = Math.floorDiv(end.minute(), 15) * 15;
  4153. end.setMinutes(i);
  4154. DateTime begin = DateUtil.offsetMinute(end, -15);
  4155. //AGC
  4156. List<PointInfo> entityAgc = getEntity("AGC002", "booster");
  4157. getSectionDataByEntity(entityAgc, goldenUri(), end);
  4158. Map<String, PointInfo> mapAgc = entityAgc.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  4159. //出线
  4160. List<PointInfo> entityCx = getEntity("AGC001", "booster");
  4161. Map<String, PointInfo> statMapCx = getRawDataByEntity(entityCx, goldenUri(), begin, end, PointInfo::getStationId);
  4162. //风速
  4163. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  4164. getRawDataByEntity(entityFs, goldenUri(), begin, end);
  4165. Map<String, List<PointInfo>> fssMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  4166. //环境温度
  4167. List<PointInfo> entityHjwd = getEntity("AI072", "turbine");
  4168. getRawDataByEntity(entityHjwd, goldenUri(), begin, end);
  4169. Map<String, List<PointInfo>> hjwdsMap = entityHjwd.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  4170. //日发电量
  4171. List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
  4172. entity = entity.stream().filter(e -> !"".equals(e.getProjectId())).collect(Collectors.toList());
  4173. getSectionDataByEntity(entity, goldenUri(), begin, end);
  4174. Map<String, List<PointInfo>> fdlsMap = entity.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  4175. QueryWrapper<TurbineInfoMin> wrapper = new QueryWrapper<>();
  4176. wrapper.select("sum(llgl) llgl,sum(kygl) kygl,avg(pjfs) pjfs,station_id").eq("record_date", end).groupBy("station_id");
  4177. List<TurbineInfoMin> list = turbineInfoMinService.list(wrapper);
  4178. Map<String, TurbineInfoMin> minMap = list.stream().collect(Collectors.toMap(TurbineInfoMin::getStationId, Function.identity()));
  4179. List<StationInfoMin> byDate = getStationinfoByMin(end, entityAgc);
  4180. Map<String, Map<Double, Long>> zttsMap = calcSectionStationZtts(end);
  4181. for (StationInfoMin day : byDate) {
  4182. String id = day.getStationId();
  4183. TurbineInfoMin min = minMap.get(id);
  4184. Map<Double, Long> map = zttsMap.get(id);
  4185. List<PointInfo> fsInfos = fssMap.get(id);
  4186. double pjfs = fsInfos.stream().mapToDouble(pi -> pi.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0)).average().orElse(0);
  4187. day.setPjfs(pjfs);
  4188. PointInfo cxInfo = statMapCx.get(id);
  4189. double cxgl = cxInfo.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0);
  4190. cxgl = cxgl * cxInfo.getCoef();
  4191. if (cxgl > 169600 && day.getPjfs() < 3) cxgl = 0;
  4192. day.setPjgl(cxgl);
  4193. PointInfo agcInfo = mapAgc.get(id);
  4194. double agc = agcInfo.getPointDatas().get(0).getValue() * agcInfo.getCoef();
  4195. if (agc < day.getPjgl()) agc = day.getPjgl();
  4196. day.setAgc(agc);
  4197. List<PointInfo> fdlInfos = fdlsMap.get(id);
  4198. double rfdl = fdlInfos.stream().mapToDouble(pi -> {
  4199. double v = (pi.getPointDatas().get(1).getValue() - pi.getPointDatas().get(0).getValue()) * pi.getCoef();
  4200. if (v < 0) v = 0;
  4201. return v;
  4202. }).sum();
  4203. if ((rfdl < 660 && day.getPjgl() > 0) || rfdl >= 45500) rfdl = day.getPjgl() / 4.0;
  4204. day.setRfdl(rfdl);
  4205. if (day.getPjgl() == 169600.0 && rfdl != 42400.0) {
  4206. day.setPjgl(rfdl * 4);
  4207. day.setAgc(day.getPjgl());
  4208. }
  4209. if (day.getPjgl() == 0.0 && rfdl != 0.0) {
  4210. day.setPjgl(rfdl * 4);
  4211. }
  4212. if (day.getAgc() == 170000 && rfdl != 42400.0) {
  4213. day.setAgc(rfdl * 4);
  4214. }
  4215. List<PointInfo> hjwdInfos = hjwdsMap.get(id);
  4216. List<Double> hjwds = new ArrayList<>();
  4217. for (PointInfo wd : hjwdInfos) {
  4218. double v = wd.getPointDatas().stream().filter(p -> p.getValue() != 0.0).mapToDouble(PointData::getValue).average().orElse(0.0);
  4219. if (v > 83) v = 0;
  4220. if (v == 0) {
  4221. v = fjhjwd.getOrDefault(wd.getTurbineId(), 0.0);
  4222. } else {
  4223. fjhjwd.put(wd.getTurbineId(), v);
  4224. }
  4225. hjwds.add(v);
  4226. }
  4227. day.setHjwd(hjwds.stream().filter(d -> d != 0.0).mapToDouble(Double::doubleValue).average().orElse(0.0));
  4228. //0 待机-,1 停机,2 发电-,4 故障-,6 检修,8 限电,12 离线
  4229. day.setDjts(map.get(0.0));
  4230. day.setYxts(map.get(2.0));
  4231. day.setGzts(map.get(4.0));
  4232. day.setJxts(map.get(6.0));
  4233. day.setLlgl(min.getLlgl());
  4234. day.setKygl(min.getKygl());
  4235. }
  4236. stationInfoMinService.saveOrUpdateBatch(byDate);
  4237. }
  4238. public void calcStationSjglAgcPjfsHjwdDlMin(Date begin, Date end, String stId) {
  4239. //AGC
  4240. List<PointInfo> entityAgc = getEntity("AGC002", "booster");
  4241. entityAgc = entityAgc.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
  4242. getSectionDataByEntity(entityAgc, goldenUri(), end);
  4243. Map<String, PointInfo> mapAgc = entityAgc.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  4244. //出线
  4245. List<PointInfo> entityCx = getEntity("AGC001", "booster");
  4246. entityCx = entityCx.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
  4247. Map<String, PointInfo> statMapCx = getRawDataByEntity(entityCx, goldenUri(), begin, end, PointInfo::getStationId);
  4248. //风速
  4249. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  4250. entityFs = entityFs.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
  4251. getRawDataByEntity(entityFs, goldenUri(), begin, end);
  4252. Map<String, List<PointInfo>> fssMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  4253. //环境温度
  4254. List<PointInfo> entityHjwd = getEntity("AI072", "turbine");
  4255. entityHjwd = entityHjwd.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
  4256. getRawDataByEntity(entityHjwd, goldenUri(), begin, end);
  4257. Map<String, List<PointInfo>> hjwdsMap = entityHjwd.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  4258. //日发电量
  4259. List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
  4260. entity = entity.stream().filter(e -> !"".equals(e.getProjectId()) && stId.equals(e.getStationId())).collect(Collectors.toList());
  4261. getSectionDataByEntity(entity, goldenUri(), begin, end);
  4262. Map<String, List<PointInfo>> fdlsMap = entity.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  4263. List<StationInfoMin> byDate = getStationinfoByMin(end, stId);
  4264. byDate = byDate.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
  4265. Map<Double, Long> map = calcSectionStationZtts(end, stId);
  4266. for (StationInfoMin day : byDate) {
  4267. String id = day.getStationId();
  4268. // if (day.getPjfs() == null || day.getPjfs() == 0) {
  4269. List<PointInfo> fsInfos = fssMap.get(id);
  4270. double pjfs = fsInfos.stream().mapToDouble(pi -> pi.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0)).average().orElse(0);
  4271. day.setPjfs(pjfs);
  4272. // }
  4273. // if (day.getPjgl() == null || day.getPjgl() == 0) {
  4274. PointInfo cxInfo = statMapCx.get(id);
  4275. double cxgl = cxInfo.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0);
  4276. cxgl = cxgl * cxInfo.getCoef();
  4277. if (cxgl <= 0 && day.getPjfs() > 3) cxgl = nihe(day.getPjfs());
  4278. if (cxgl > 169600 && day.getPjfs() < 3) cxgl = 0;
  4279. if (cxgl > 169600 && day.getPjfs() > 3) cxgl = nihe(day.getPjfs());
  4280. day.setPjgl(cxgl);
  4281. // }
  4282. // if (day.getAgc() == null || day.getAgc() == 0) {
  4283. PointInfo agcInfo = mapAgc.get(id);
  4284. double agc = agcInfo.getPointDatas().get(0).getValue() * agcInfo.getCoef();
  4285. if (agc < day.getPjgl()) agc = day.getPjgl();
  4286. day.setAgc(agc);
  4287. // }
  4288. // if (day.getRfdl() == null || day.getRfdl() == 0) {
  4289. List<PointInfo> fdlInfos = fdlsMap.get(id);
  4290. double rfdl = fdlInfos.stream().mapToDouble(pi -> {
  4291. double v = (pi.getPointDatas().get(1).getValue() - pi.getPointDatas().get(0).getValue()) * pi.getCoef();
  4292. if (v < 0) v = 0;
  4293. // if (v > 10500) v = 10500.0;
  4294. return v;
  4295. }).sum();
  4296. if ((rfdl < 660 && day.getPjgl() > 0) || rfdl >= 45500) rfdl = day.getPjgl() / 4.0;
  4297. day.setRfdl(rfdl);
  4298. if (day.getPjgl() == 169600.0 && rfdl != 42400.0) {
  4299. day.setPjgl(rfdl * 4);
  4300. day.setAgc(day.getPjgl());
  4301. }
  4302. if (day.getAgc() == 170000 && rfdl != 42400.0) {
  4303. day.setAgc(rfdl * 4);
  4304. }
  4305. // }
  4306. // if (day.getHjwd() == null || day.getHjwd() == 0) {
  4307. List<PointInfo> hjwdInfos = hjwdsMap.get(id);
  4308. double hjwd = hjwdInfos.stream().mapToDouble(pi -> pi.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0)).average().orElse(0);
  4309. day.setHjwd(hjwd);
  4310. // }
  4311. //0 待机-,1 停机,2 发电-,4 故障-,6 检修,8 限电,12 离线
  4312. day.setDjts(map.get(0.0));
  4313. day.setYxts(map.get(2.0));
  4314. day.setGzts(map.get(4.0));
  4315. day.setJxts(map.get(6.0));
  4316. }
  4317. stationInfoMinService.saveOrUpdateBatch(byDate);
  4318. }
  4319. public StationInfoMin calcStationSjglAgcPjfsHjwdDlMin2(Date begin, Date end, String stId) {
  4320. //AGC
  4321. List<PointInfo> entityAgc = getEntity("AGC002", "booster");
  4322. entityAgc = entityAgc.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
  4323. getSectionDataByEntity(entityAgc, goldenUri(), end);
  4324. Map<String, PointInfo> mapAgc = entityAgc.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  4325. //出线
  4326. List<PointInfo> entityCx = getEntity("AGC001", "booster");
  4327. entityCx = entityCx.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
  4328. Map<String, PointInfo> statMapCx = getRawDataByEntity(entityCx, goldenUri(), begin, end, PointInfo::getStationId);
  4329. //风速
  4330. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  4331. entityFs = entityFs.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
  4332. getRawDataByEntity(entityFs, goldenUri(), begin, end);
  4333. Map<String, List<PointInfo>> fssMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  4334. //环境温度
  4335. List<PointInfo> entityHjwd = getEntity("AI072", "turbine");
  4336. entityHjwd = entityHjwd.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
  4337. getRawDataByEntity(entityHjwd, goldenUri(), begin, end);
  4338. Map<String, List<PointInfo>> hjwdsMap = entityHjwd.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  4339. //日发电量
  4340. List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
  4341. entity = entity.stream().filter(e -> !"".equals(e.getProjectId()) && stId.equals(e.getStationId())).collect(Collectors.toList());
  4342. getSectionDataByEntity(entity, goldenUri(), begin, end);
  4343. Map<String, List<PointInfo>> fdlsMap = entity.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  4344. List<StationInfoMin> byDate = getStationinfoByMin(end, stId);
  4345. byDate = byDate.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
  4346. Map<Double, Long> map = calcSectionStationZtts(end, stId);
  4347. for (StationInfoMin day : byDate) {
  4348. String id = day.getStationId();
  4349. List<PointInfo> fsInfos = fssMap.get(id);
  4350. double pjfs = fsInfos.stream().mapToDouble(pi -> pi.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0)).average().orElse(0);
  4351. day.setPjfs(pjfs);
  4352. PointInfo cxInfo = statMapCx.get(id);
  4353. double cxgl = cxInfo.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0);
  4354. cxgl = cxgl * cxInfo.getCoef();
  4355. if (cxgl > 169600 && day.getPjfs() < 3) cxgl = 0;
  4356. day.setPjgl(cxgl);
  4357. PointInfo agcInfo = mapAgc.get(id);
  4358. double agc = agcInfo.getPointDatas().get(0).getValue() * agcInfo.getCoef();
  4359. if (agc < day.getPjgl()) agc = day.getPjgl();
  4360. day.setAgc(agc);
  4361. List<PointInfo> fdlInfos = fdlsMap.get(id);
  4362. double rfdl = fdlInfos.stream().mapToDouble(pi -> {
  4363. double v = (pi.getPointDatas().get(1).getValue() - pi.getPointDatas().get(0).getValue()) * pi.getCoef();
  4364. if (v < 0) v = 0;
  4365. return v;
  4366. }).sum();
  4367. if ((rfdl < 660 && day.getPjgl() > 0) || rfdl > 45500) rfdl = day.getPjgl() / 4.0;
  4368. day.setRfdl(rfdl);
  4369. if (day.getPjgl() == 169600.0 && rfdl != 42400.0) {
  4370. day.setPjgl(rfdl * 4);
  4371. day.setAgc(day.getPjgl());
  4372. }
  4373. if (day.getPjgl() == 0.0 && rfdl != 0.0) {
  4374. day.setPjgl(rfdl * 4);
  4375. }
  4376. if (day.getAgc() == 170000 && rfdl != 42400.0) {
  4377. day.setAgc(rfdl * 4);
  4378. }
  4379. List<PointInfo> hjwdInfos = hjwdsMap.get(id);
  4380. double hjwd = hjwdInfos.stream().mapToDouble(pi -> pi.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0)).average().orElse(0);
  4381. day.setHjwd(hjwd);
  4382. //0 待机-,1 停机,2 发电-,4 故障-,6 检修,8 限电,12 离线
  4383. day.setDjts(map.get(0.0));
  4384. day.setYxts(map.get(2.0));
  4385. day.setGzts(map.get(4.0));
  4386. day.setJxts(map.get(6.0));
  4387. }
  4388. return byDate.get(0);
  4389. }
  4390. private double nihe(double pjfs) {
  4391. //LJS
  4392. // if (pjfs > 13) return 94251.0;
  4393. // return -90.4382 * Math.pow(pjfs, 3) + 1661.275 * Math.pow(pjfs, 2) + 2245.86 * pjfs - 17011.14;
  4394. //FSG
  4395. if (pjfs > 8.62) return 35880.0;
  4396. return -286.3119 * Math.pow(pjfs, 3) + 4837.637 * Math.pow(pjfs, 2) - 19121.73 * pjfs + 24636.96;
  4397. }
  4398. public void getPoint() {
  4399. //AGC
  4400. List<PointInfo> entityAgc = getEntity("AGC002", "booster");
  4401. Map<String, PointInfo> mapAgc = entityAgc.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  4402. //出线
  4403. List<PointInfo> entityCx = getEntity("AGC001", "booster");
  4404. //风速
  4405. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  4406. Map<String, List<PointInfo>> fssMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  4407. //环境温度
  4408. List<PointInfo> entityHjwd = getEntity("AI072", "turbine");
  4409. Map<String, List<PointInfo>> hjwdsMap = entityHjwd.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  4410. //日发电量
  4411. List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
  4412. entity = entity.stream().filter(e -> !"".equals(e.getProjectId())).collect(Collectors.toList());
  4413. Map<String, List<PointInfo>> fdlsMap = entity.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  4414. System.out.println();
  4415. }
  4416. public void calcPredictExaminFj(Date date) {
  4417. DateTime end = DateUtil.beginOfDay(date);
  4418. DateTime begin = DateUtil.offsetDay(end, -1);
  4419. List<PointInfo> entity = getEntity("MX000", "state");
  4420. List<PointInfo> entity1 = getEntity("AI422", "state");
  4421. entity.addAll(entity1);
  4422. Map<String, EquipmentModel> map = equipmentModelService.map();
  4423. //风机id,风机装机容量
  4424. Map<String, Double> tbPowerMap = entity.stream().collect(Collectors.toMap(pi -> pi.getTurbineId(), pi -> map.get(pi.getSpare()).getPowerProduction()));
  4425. //实际功率
  4426. List<PointInfo> entityGl = getEntity("AI114", "turbine");
  4427. getSnapDataByEntity(entityGl, begin, end, 15 * 60);
  4428. Map<String, PointInfo> glpisMap = entityGl.stream().collect(Collectors.toMap(PointInfo::getTurbineId, Function.identity()));
  4429. //短期 predictType + "_" + modelId + "_" + sstId + t
  4430. QueryWrapper<HistoryPredict> dqWrapper = new QueryWrapper<>();
  4431. dqWrapper.eq("device_type", "station").eq("predict_type", "DQ").eq("data_time", begin)
  4432. .between("predict_time", begin, end).orderByAsc("data_time");
  4433. List<HistoryPredict> dqList = historyPredictService.list(dqWrapper);
  4434. Map<String, List<HistoryPredict>> dqMap = dqList.stream().collect(Collectors.groupingBy(HistoryPredict::getSiteId));
  4435. //超短期
  4436. QueryWrapper<HistoryPredict> cdqWrapper = new QueryWrapper<>();
  4437. cdqWrapper.eq("device_type", "station").eq("predict_type", "CDQ").eq("data_time", begin).orderByAsc("data_time");
  4438. List<HistoryPredict> cdqList = historyPredictService.list(cdqWrapper);
  4439. Map<String, List<HistoryPredict>> cdqMap = cdqList.stream().collect(Collectors.groupingBy(HistoryPredict::getSiteId));
  4440. List<PredictExamin> peList = new ArrayList<>();
  4441. dqMap.forEach((stId, hps) -> {
  4442. //短期
  4443. List<Double> predictPower = hps.stream().map(HistoryPredict::getPredictPower).collect(Collectors.toList());
  4444. List<Double> actualPower = glpisMap.get(stId).getPointDatas().stream().map(PointData::getValue).collect(Collectors.toList());
  4445. Double installCapacity = tbPowerMap.get(stId);
  4446. HistoryPredict predict = hps.get(0);
  4447. PredictExamin examin = new PredictExamin();
  4448. examin.setModelId(predict.getModelId());
  4449. examin.setPredictType("DQ");
  4450. examin.setDeviceType(predict.getDeviceType());
  4451. examin.setTime(begin);
  4452. examin.setSiteId(predict.getSiteId());
  4453. examin.setExaminScore(calcExaminScore(predictPower, actualPower, installCapacity));
  4454. examin.setAccuracyRate(calcAccuracyRate(predictPower, actualPower, installCapacity));
  4455. peList.add(examin);
  4456. //超短期
  4457. List<Double> predictPowerCdq = cdqMap.get(stId).stream().map(HistoryPredict::getPredictPower).collect(Collectors.toList());
  4458. PredictExamin e = new PredictExamin();
  4459. e.setModelId(predict.getModelId());
  4460. e.setPredictType("CDQ");
  4461. e.setDeviceType(predict.getDeviceType());
  4462. e.setTime(begin);
  4463. e.setSiteId(predict.getSiteId());
  4464. e.setExaminScore(calcExaminScore(predictPowerCdq, actualPower, installCapacity));
  4465. e.setAccuracyRate(calcAccuracyRate(predictPowerCdq, actualPower, installCapacity));
  4466. peList.add(e);
  4467. });
  4468. predictExaminService.saveBatch(peList);
  4469. }
  4470. public void predictExaminBc(List<String> stIds, Date date) {
  4471. List<RealtimePredict> peList = new ArrayList<>();
  4472. for (String stId : stIds) {
  4473. RealtimePredict examin = new RealtimePredict();
  4474. examin.setModelId("1");
  4475. examin.setPredictType("ZCQ");
  4476. examin.setDeviceType("project");
  4477. examin.setTime(date);
  4478. examin.setSiteId(stId);
  4479. examin.setPredictEnergy(0.0);
  4480. examin.setId("ZCQ_1_" + stId + date.toString());
  4481. peList.add(examin);
  4482. }
  4483. realtimePredictService.saveBatch(peList);
  4484. }
  4485. public void predictcdqBc(Date date) {
  4486. List<RealtimePredict> peList = new ArrayList<>();
  4487. RealtimePredict examin = new RealtimePredict();
  4488. examin.setModelId("1");
  4489. examin.setPredictType("ZCQ");
  4490. examin.setDeviceType("project");
  4491. examin.setTime(date);
  4492. // examin.setSiteId(stId);
  4493. examin.setPredictEnergy(0.0);
  4494. // examin.setId("ZCQ_1_"+stId+date.toString());
  4495. peList.add(examin);
  4496. realtimePredictService.saveBatch(peList);
  4497. }
  4498. public void zcqycbc(List<String> stIds, Date date) {
  4499. List<PredictExamin> peList = new ArrayList<>();
  4500. for (String stId : stIds) {
  4501. //短期
  4502. PredictExamin examin = new PredictExamin();
  4503. examin.setModelId("1");
  4504. examin.setPredictType("DQ");
  4505. examin.setDeviceType("station");
  4506. examin.setTime(date);
  4507. examin.setSiteId(stId);
  4508. examin.setExaminScore(30.0);
  4509. examin.setAccuracyRate(91.0);
  4510. peList.add(examin);
  4511. //超短期
  4512. PredictExamin e = new PredictExamin();
  4513. e.setModelId("1");
  4514. e.setPredictType("CDQ");
  4515. e.setDeviceType("station");
  4516. e.setTime(date);
  4517. e.setSiteId(stId);
  4518. e.setExaminScore(30.0);
  4519. e.setAccuracyRate(91.0);
  4520. peList.add(e);
  4521. }
  4522. predictExaminService.saveBatch(peList);
  4523. }
  4524. public void calcPredictExamin(Date date) {
  4525. DateTime end = DateUtil.beginOfDay(date);
  4526. DateTime begin = DateUtil.offsetDay(end, -1);
  4527. //实际功率
  4528. List<PointInfo> entityGl = getEntity("AGC001", "booster");
  4529. getSnapDataByEntity(entityGl, begin, end, 15 * 60);
  4530. Map<String, PointInfo> glpisMap = entityGl.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  4531. //短期 predictType + "_" + modelId + "_" + sstId + t
  4532. QueryWrapper<HistoryPredict> dqWrapper = new QueryWrapper<>();
  4533. dqWrapper.eq("device_type", "station").eq("predict_type", "DQ").eq("data_time", begin)
  4534. .between("predict_time", begin, end).orderByAsc("data_time");
  4535. List<HistoryPredict> dqList = historyPredictService.list(dqWrapper);
  4536. Map<String, List<HistoryPredict>> dqMap = dqList.stream().collect(Collectors.groupingBy(HistoryPredict::getSiteId));
  4537. //超短期
  4538. List<HistoryPredict> cdqList = new ArrayList<>();
  4539. for (int i = 0; i < 6; i++) {
  4540. DateTime hour = DateUtil.offsetHour(begin, 4 * i);
  4541. DateTime hour2 = DateUtil.offsetHour(hour, 4);
  4542. QueryWrapper<HistoryPredict> wrapper = new QueryWrapper<>();
  4543. wrapper.eq("device_type", "station").eq("predict_type", "CDQ").eq("data_time", hour)
  4544. .between("predict_time", hour, hour2).orderByAsc("data_time");
  4545. List<HistoryPredict> predicts = historyPredictService.list(wrapper);
  4546. cdqList.addAll(predicts);
  4547. }
  4548. QueryWrapper<HistoryPredict> cdqWrapper = new QueryWrapper<>();
  4549. cdqWrapper.eq("device_type", "station").eq("predict_type", "CDQ").eq("data_time", begin).orderByAsc("data_time");
  4550. Map<String, List<HistoryPredict>> cdqMap = cdqList.stream().collect(Collectors.groupingBy(HistoryPredict::getSiteId));
  4551. List<PredictExamin> peList = new ArrayList<>();
  4552. dqMap.forEach((stId, hps) -> {
  4553. //短期
  4554. List<Double> predictPower = hps.stream().map(HistoryPredict::getPredictPower).collect(Collectors.toList());
  4555. PointInfo glinfo = glpisMap.get(stId);
  4556. List<Double> actualPower = glinfo.getPointDatas().stream().map(PointData::getValue).collect(Collectors.toList());
  4557. Double installCapacity = glinfo.getSpare2() * 1000;
  4558. HistoryPredict predict = hps.get(0);
  4559. PredictExamin examin = new PredictExamin();
  4560. examin.setModelId(predict.getModelId());
  4561. examin.setPredictType("DQ");
  4562. examin.setDeviceType(predict.getDeviceType());
  4563. examin.setTime(begin);
  4564. examin.setSiteId(predict.getSiteId());
  4565. examin.setExaminScore(calcExaminScore(predictPower, actualPower, installCapacity));
  4566. examin.setAccuracyRate(calcAccuracyRate(predictPower, actualPower, installCapacity));
  4567. peList.add(examin);
  4568. //超短期
  4569. List<HistoryPredict> cdqhps = cdqMap.get(stId);
  4570. if (CollUtil.isEmpty(cdqhps)) return;
  4571. List<Double> predictPowerCdq = cdqhps.stream().map(HistoryPredict::getPredictPower).collect(Collectors.toList());
  4572. PredictExamin e = new PredictExamin();
  4573. e.setModelId(predict.getModelId());
  4574. e.setPredictType("CDQ");
  4575. e.setDeviceType(predict.getDeviceType());
  4576. e.setTime(begin);
  4577. e.setSiteId(predict.getSiteId());
  4578. e.setExaminScore(calcExaminScore(predictPowerCdq, actualPower, installCapacity));
  4579. e.setAccuracyRate(calcAccuracyRate(predictPowerCdq, actualPower, installCapacity));
  4580. peList.add(e);
  4581. });
  4582. predictExaminService.saveBatch(peList);
  4583. }
  4584. public void calcPredictExamin2(Date date) {
  4585. DateTime end = DateUtil.beginOfDay(date);
  4586. DateTime begin = DateUtil.offsetDay(end, -1);
  4587. //实际功率
  4588. List<PointInfo> entityGl = getEntity("AGC001", "booster");
  4589. getSnapDataByEntity(entityGl, begin, end, 15 * 60);
  4590. Map<String, PointInfo> glpisMap = entityGl.stream().collect(Collectors.toMap(PointInfo::getStationId, Function.identity()));
  4591. //短期 predictType + "_" + modelId + "_" + sstId + t
  4592. QueryWrapper<RealtimePredict> dqWrapper = new QueryWrapper<>();
  4593. dqWrapper.eq("device_type", "station").eq("predict_type", "DQ")
  4594. .gt("time", begin).le("time", end).orderByAsc("time");
  4595. List<RealtimePredict> dqList = realtimePredictService.list(dqWrapper);
  4596. Map<String, List<RealtimePredict>> dqMap = dqList.stream().collect(Collectors.groupingBy(RealtimePredict::getSiteId));
  4597. //超短期
  4598. List<HistoryPredict> cdqList = new ArrayList<>();
  4599. for (int i = 0; i < 6; i++) {
  4600. DateTime hour = DateUtil.offsetHour(begin, 4 * i);
  4601. DateTime hour2 = DateUtil.offsetHour(hour, 4);
  4602. QueryWrapper<HistoryPredict> wrapper = new QueryWrapper<>();
  4603. wrapper.eq("device_type", "station").eq("predict_type", "CDQ").eq("data_time", hour)
  4604. .between("predict_time", hour, hour2).orderByAsc("data_time");
  4605. List<HistoryPredict> predicts = historyPredictService.list(wrapper);
  4606. cdqList.addAll(predicts);
  4607. }
  4608. QueryWrapper<HistoryPredict> cdqWrapper = new QueryWrapper<>();
  4609. cdqWrapper.eq("device_type", "station").eq("predict_type", "CDQ").eq("data_time", begin).orderByAsc("data_time");
  4610. Map<String, List<HistoryPredict>> cdqMap = cdqList.stream().collect(Collectors.groupingBy(HistoryPredict::getSiteId));
  4611. List<PredictExamin> peList = new ArrayList<>();
  4612. dqMap.forEach((stId, hps) -> {
  4613. //短期
  4614. List<Double> predictPower = hps.stream().map(RealtimePredict::getPredictPower).collect(Collectors.toList());
  4615. PointInfo glinfo = glpisMap.get(stId);
  4616. List<Double> actualPower = glinfo.getPointDatas().stream().map(PointData::getValue).collect(Collectors.toList());
  4617. Double installCapacity = glinfo.getSpare2() * 1000;
  4618. RealtimePredict predict = hps.get(0);
  4619. PredictExamin examin = new PredictExamin();
  4620. examin.setModelId(predict.getModelId());
  4621. examin.setPredictType("DQ");
  4622. examin.setDeviceType(predict.getDeviceType());
  4623. examin.setTime(begin);
  4624. examin.setSiteId(predict.getSiteId());
  4625. examin.setExaminScore(calcExaminScore(predictPower, actualPower, installCapacity));
  4626. examin.setAccuracyRate(calcAccuracyRate(predictPower, actualPower, installCapacity));
  4627. peList.add(examin);
  4628. //超短期
  4629. List<HistoryPredict> cdqhps = cdqMap.get(stId);
  4630. if (CollUtil.isEmpty(cdqhps)) return;
  4631. List<Double> predictPowerCdq = cdqhps.stream().map(HistoryPredict::getPredictPower).collect(Collectors.toList());
  4632. PredictExamin e = new PredictExamin();
  4633. e.setModelId(predict.getModelId());
  4634. e.setPredictType("CDQ");
  4635. e.setDeviceType(predict.getDeviceType());
  4636. e.setTime(begin);
  4637. e.setSiteId(predict.getSiteId());
  4638. e.setExaminScore(calcExaminScore(predictPowerCdq, actualPower, installCapacity));
  4639. e.setAccuracyRate(calcAccuracyRate(predictPowerCdq, actualPower, installCapacity));
  4640. peList.add(e);
  4641. });
  4642. predictExaminService.saveBatch(peList);
  4643. }
  4644. /**
  4645. * 计算功率日预测曲线最大误差值
  4646. *
  4647. * @param predictPower 96个点的预测功率值
  4648. * @param actualPower 96个点的实际功率值
  4649. * @param installCapacity 装机容量
  4650. * @return 结果
  4651. */
  4652. public double calcExaminScore(List<Double> predictPower, List<Double> actualPower, Double installCapacity) {
  4653. if (CollUtil.isEmpty(predictPower) || CollUtil.isEmpty(actualPower) || installCapacity == null) return 0;
  4654. int n = predictPower.size();
  4655. if (actualPower.size() < n) return 0;
  4656. double maxErrorPercentage = 0.0;
  4657. for (int i = 0; i < n; i++) {
  4658. double errorPercentage = 0.0;
  4659. if (predictPower.get(i) == 0) {
  4660. if (Math.abs(actualPower.get(i)) <= 0.03 * installCapacity) {
  4661. continue; // 不考核
  4662. } else {
  4663. errorPercentage = 100.0;
  4664. }
  4665. } else {
  4666. errorPercentage = Math.abs(predictPower.get(i) - actualPower.get(i)) / installCapacity * 100;
  4667. }
  4668. if (errorPercentage > maxErrorPercentage) {
  4669. maxErrorPercentage = errorPercentage;
  4670. }
  4671. }
  4672. return maxErrorPercentage;
  4673. }
  4674. /**
  4675. * 计算功率超短期预测曲线准确率
  4676. *
  4677. * @param predictPower 96个点的预测功率值
  4678. * @param actualPower 96个点的实际功率值
  4679. * @param installCapacity 装机容量
  4680. * @return 结果
  4681. */
  4682. public double calcAccuracyRate(List<Double> predictPower, List<Double> actualPower, Double installCapacity) {
  4683. if (CollUtil.isEmpty(predictPower) || CollUtil.isEmpty(actualPower) || installCapacity == null) return 0;
  4684. int n = predictPower.size();
  4685. if (actualPower.size() < n) return 0;
  4686. double totalError = 0.0;
  4687. int validPoints = 0;
  4688. for (int i = 0; i < n; i++) {
  4689. double errorPercentage = 0.0;
  4690. if (Math.abs(predictPower.get(i) - actualPower.get(i)) <= 0.03 * installCapacity) {
  4691. // 该点不计入误差计算
  4692. continue;
  4693. }
  4694. errorPercentage = Math.abs(predictPower.get(i) - actualPower.get(i)) / installCapacity * 100;
  4695. totalError += errorPercentage;
  4696. validPoints++;
  4697. }
  4698. if (validPoints == 0) {
  4699. return 100.0; // 所有点均在3%以内,准确率为100%
  4700. } else {
  4701. return 100 - totalError / validPoints;
  4702. }
  4703. }
  4704. private Map<String, Double> fjhjwd = new HashMap<>();
  4705. private Map<String, Double> fjfs = new HashMap<>();
  4706. public void calcStationPjfsHjwdMin(Date begin, Date end, String stId, StationInfoMin min) {
  4707. //风速
  4708. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  4709. entityFs = entityFs.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
  4710. getRawDataByEntity(entityFs, goldenUri(), begin, end);
  4711. Map<String, List<PointInfo>> fssMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  4712. //环境温度
  4713. List<PointInfo> entityHjwd = getEntity("AI072", "turbine");
  4714. entityHjwd = entityHjwd.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
  4715. getRawDataByEntity(entityHjwd, goldenUri(), begin, end);
  4716. Map<String, List<PointInfo>> hjwdsMap = entityHjwd.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  4717. // StationInfoMin2 min2 = getStationinfoByMin2(end, stId);
  4718. StationInfoMin2 min2 = new StationInfoMin2();
  4719. min2.setStationId(stId);
  4720. min2.setRecordDate(end);
  4721. min2.setPjgl(min.getPjgl());
  4722. min2.setRfdl(min.getRfdl());
  4723. min2.setYxts(min.getYxts());
  4724. List<PointInfo> fsInfos = fssMap.get(stId);
  4725. fsInfos = fsInfos.stream().sorted(Comparator.comparing(PointInfo::getTurbineId)).collect(Collectors.toList());
  4726. for (int i = 0; i < fsInfos.size(); i++) {
  4727. setpjfs(min2, fsInfos.get(i), i + 1);
  4728. }
  4729. List<PointInfo> hjwdInfos = hjwdsMap.get(stId);
  4730. List<Double> hjwds = new ArrayList<>();
  4731. for (PointInfo wd : hjwdInfos) {
  4732. double v = wd.getPointDatas().stream().filter(p -> p.getValue() != 0.0).mapToDouble(PointData::getValue).average().orElse(0.0);
  4733. if (v > 83 || v < -60) v = 0;
  4734. if (v == 0) {
  4735. v = fjhjwd.getOrDefault(wd.getTurbineId(), 0.0);
  4736. } else {
  4737. fjhjwd.put(wd.getTurbineId(), v);
  4738. }
  4739. hjwds.add(v);
  4740. }
  4741. min2.setHjwd(hjwds.stream().filter(d -> d != 0.0).mapToDouble(Double::doubleValue).average().orElse(0.0));
  4742. // stationInfoMin2Service.saveOrUpdate(min2);
  4743. stationInfoMin2Service.save(min2);
  4744. }
  4745. public List<PointInfo> filterPointInfo(List<PointInfo> entity, String id, Function<PointInfo, String> fun) {
  4746. return entity.stream().filter(e -> id.equals(fun.apply(e))).collect(Collectors.toList());
  4747. }
  4748. public List<PointInfo> sortPointInfo(List<PointInfo> entity, Function<PointInfo, String> fun) {
  4749. return entity.stream().sorted(Comparator.comparing(fun)).collect(Collectors.toList());
  4750. }
  4751. public void calcProjectPjfsHjwdMin2(Date begin, Date end, String stId, StationInfoMin2 min) {
  4752. //风速
  4753. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  4754. entityFs = filterPointInfo(entityFs, stId, PointInfo::getStationId);
  4755. Map<String, List<PointInfo>> pisMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getProjectId));
  4756. List<ProjectInfoMin2> min2s = new ArrayList<>();
  4757. pisMap.forEach((pjId, pis) -> {
  4758. List<PointInfo> infos = sortPointInfo(pis, PointInfo::getTurbineId);
  4759. List<Integer> fjidns = infos.stream().map(pi -> Integer.parseInt(pi.getTurbineId().replaceFirst("GJNY_SXGS_.+_F_WT_", "")
  4760. .replaceFirst("_EQ", ""))).collect(Collectors.toList());
  4761. // Map<Double, Long> zttsMap = calcSectionZtts(end,pjId,PointInfo::getProjectId);
  4762. // Long l = zttsMap.get(2.0);
  4763. // if (l == null) l = 0L;
  4764. //日发电量
  4765. // List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
  4766. // entity=filterPointInfo(entity,pjId,PointInfo::getProjectId);
  4767. // getSectionDataByEntity(entity, goldenUri(), begin, end);
  4768. // double rfdl = entity.stream().mapToDouble(pi -> {
  4769. // double v = (pi.getPointDatas().get(1).getValue() - pi.getPointDatas().get(0).getValue()) * pi.getCoef();
  4770. // if (v < 0) v = 0;
  4771. // return v;
  4772. // }).sum();
  4773. // if (rfdl >= 32500) rfdl = 32500.0;
  4774. ProjectInfoMin2 min2 = new ProjectInfoMin2();
  4775. min2.setStationId(stId);
  4776. min2.setProjectId(pjId);
  4777. min2.setRecordDate(end);
  4778. // min2.setRfdl(rfdl);
  4779. min2.setRfdl(min.getRfdl());
  4780. min2.setHjwd(min.getHjwd());
  4781. // min2.setYxts(l);
  4782. min2.setYxts(min.getYxts());
  4783. sm2fs2pm2(fjidns, min2, min);
  4784. min2s.add(min2);
  4785. });
  4786. projectInfoMin2Service.saveBatch(min2s);
  4787. }
  4788. public ProjectInfoMin2 calcProjectPjfsHjwdMin2(Date end, String pjId) {
  4789. DateTime begin = DateUtil.offsetMinute(end, -15);
  4790. //风速
  4791. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  4792. entityFs = filterPointInfo(entityFs, pjId, PointInfo::getProjectId);
  4793. getRawDataByEntity(entityFs, goldenUri(), begin, end);
  4794. entityFs = sortPointInfo(entityFs, PointInfo::getTurbineId);
  4795. List<Double> fss = new ArrayList<>();
  4796. for (PointInfo ef : entityFs) {
  4797. double v = 0;
  4798. if (ef.getPointDatas() == null || ef.getPointDatas().isEmpty()) {
  4799. Map<String, PointData> latest = adapter.getLatest(goldenUri(), ef.getPointKey());
  4800. PointData data = latest.get(ef.getPointKey());
  4801. if (data != null) v = data.getValue();
  4802. } else {
  4803. v = ef.getPointDatas().stream().mapToDouble(p -> p.getValue() > 23 ? 23.0 : p.getValue() < 0 ? 0.0 : p.getValue()).average().orElse(0.0);
  4804. }
  4805. fss.add(v);
  4806. }
  4807. //日发电量
  4808. List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
  4809. entity = filterPointInfo(entity, pjId, PointInfo::getProjectId);
  4810. getSectionDataByEntity(entity, goldenUri(), begin, end);
  4811. double rfdl = entity.stream().mapToDouble(pi -> {
  4812. double v = (pi.getPointDatas().get(1).getValue() - pi.getPointDatas().get(0).getValue()) * pi.getCoef();
  4813. if (v < 0) v = 0;
  4814. return v;
  4815. }).sum();
  4816. if (rfdl >= 32500) rfdl = 32500.0;
  4817. //环境温度
  4818. List<PointInfo> entityHjwd = getEntity("AI072", "turbine");
  4819. entityHjwd = filterPointInfo(entityHjwd, pjId, PointInfo::getProjectId);
  4820. getRawDataByEntity(entityHjwd, goldenUri(), begin, end);
  4821. List<Double> hjwds = new ArrayList<>();
  4822. for (PointInfo wd : entityHjwd) {
  4823. double v = wd.getPointDatas().stream().filter(p -> p.getValue() != 0.0).mapToDouble(PointData::getValue).average().orElse(0.0);
  4824. if (v > 83 || v < -60) v = 0;
  4825. if (v == 0) {
  4826. v = fjhjwd.getOrDefault(wd.getTurbineId(), 0.0);
  4827. } else {
  4828. fjhjwd.put(wd.getTurbineId(), v);
  4829. }
  4830. hjwds.add(v);
  4831. }
  4832. ProjectInfoMin2 min2 = new ProjectInfoMin2();
  4833. min2.setProjectId(pjId);
  4834. min2.setRecordDate(end);
  4835. min2.setRfdl(rfdl);
  4836. min2.setHjwd(hjwds.stream().filter(d -> d != 0.0).mapToDouble(Double::doubleValue).average().orElse(0.0));
  4837. sm2fs2pm2(fss, min2);
  4838. projectInfoMin2Service.save(min2);
  4839. return min2;
  4840. }
  4841. private void sm2fs2pm2(List<Integer> is, ProjectInfoMin2 pjMin2, StationInfoMin2 stMin2) {
  4842. List<Double> r = new ArrayList<>();
  4843. String prefix1 = "getPjfs";
  4844. try {
  4845. for (Integer i : is) {
  4846. // 构造方法名
  4847. String methodName = prefix1 + i;
  4848. // 获取方法对象
  4849. Method method = stMin2.getClass().getMethod(methodName);
  4850. // 调用方法并获取返回值
  4851. Double result = (Double) method.invoke(stMin2);
  4852. // 将结果添加到列表中
  4853. r.add(result);
  4854. }
  4855. } catch (Exception e) {
  4856. e.printStackTrace();
  4857. }
  4858. //setPjfs44(Double pjfs44)
  4859. String prefix2 = "setPjfs";
  4860. try {
  4861. for (int i = 0; i < r.size(); i++) {
  4862. // 构造方法名
  4863. String methodName = prefix2 + (i + 1);
  4864. // 获取方法对象
  4865. Method method = pjMin2.getClass().getMethod(methodName, Double.class);
  4866. // 调用方法并获取返回值
  4867. method.invoke(pjMin2, r.get(i));
  4868. }
  4869. } catch (Exception e) {
  4870. e.printStackTrace();
  4871. }
  4872. }
  4873. private void sm2fs2pm2(List<Double> fs, ProjectInfoMin2 pjMin2) {
  4874. String prefix2 = "setPjfs";
  4875. try {
  4876. for (int i = 0; i < fs.size(); i++) {
  4877. // 构造方法名
  4878. String methodName = prefix2 + (i + 1);
  4879. // 获取方法对象
  4880. Method method = pjMin2.getClass().getMethod(methodName, Double.class);
  4881. // 调用方法并获取返回值
  4882. method.invoke(pjMin2, fs.get(i));
  4883. }
  4884. } catch (Exception e) {
  4885. e.printStackTrace();
  4886. }
  4887. }
  4888. public StationInfoMin2 calcStationPjfsHjwdMin2(Date end, String stId) {
  4889. DateTime begin = DateUtil.offsetMinute(end, -15);
  4890. //出线
  4891. List<PointInfo> entityCx = getEntity("AGC001", "booster");
  4892. entityCx = entityCx.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
  4893. Map<String, PointInfo> statMapCx = getRawDataByEntity(entityCx, goldenUri(), begin, end, PointInfo::getStationId);
  4894. //日发电量
  4895. List<PointInfo> entity = getEntity("Z-ZXYG-JX", "meter");
  4896. entity = entity.stream().filter(e -> !"".equals(e.getProjectId()) && stId.equals(e.getStationId())).collect(Collectors.toList());
  4897. getSectionDataByEntity(entity, goldenUri(), begin, end);
  4898. Map<String, List<PointInfo>> fdlsMap = entity.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  4899. //风速
  4900. List<PointInfo> entityFs = getEntity("AI066", "turbine");
  4901. entityFs = entityFs.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
  4902. getRawDataByEntity(entityFs, goldenUri(), begin, end);
  4903. Map<String, List<PointInfo>> fssMap = entityFs.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  4904. //环境温度
  4905. List<PointInfo> entityHjwd = getEntity("AI072", "turbine");
  4906. entityHjwd = entityHjwd.stream().filter(e -> stId.equals(e.getStationId())).collect(Collectors.toList());
  4907. getRawDataByEntity(entityHjwd, goldenUri(), begin, end);
  4908. Map<String, List<PointInfo>> hjwdsMap = entityHjwd.stream().collect(Collectors.groupingBy(PointInfo::getStationId));
  4909. Map<Double, Long> zttsMap = calcSectionStationZtts(end, stId);
  4910. PointInfo cxInfo = statMapCx.get(stId);
  4911. double cxgl = cxInfo.getPointDatas().stream().mapToDouble(PointData::getValue).average().orElse(0.0);
  4912. cxgl = cxgl * cxInfo.getCoef();
  4913. List<PointInfo> fdlInfos = fdlsMap.get(stId);
  4914. double rfdl = fdlInfos.stream().mapToDouble(pi -> {
  4915. double v = (pi.getPointDatas().get(1).getValue() - pi.getPointDatas().get(0).getValue()) * pi.getCoef();
  4916. if (v < 0) v = 0;
  4917. return v;
  4918. }).sum();
  4919. if ((rfdl < 660 && cxgl > 0) || rfdl >= 42400.0) rfdl = cxgl / 4.0;
  4920. if (cxgl > 169600.0 && rfdl < 42400.0) {
  4921. cxgl = rfdl * 4;
  4922. }
  4923. if (cxgl == 0.0 && rfdl != 0.0) {
  4924. cxgl = rfdl * 4;
  4925. }
  4926. StationInfoMin2 min2 = new StationInfoMin2();
  4927. min2.setStationId(stId);
  4928. min2.setRecordDate(end);
  4929. min2.setPjgl(cxgl);
  4930. min2.setRfdl(rfdl);
  4931. Long l = zttsMap.get(2.0);
  4932. if (l == null) l = 0L;
  4933. min2.setYxts(l);
  4934. List<PointInfo> fsInfos = fssMap.get(stId);
  4935. fsInfos = fsInfos.stream().sorted(Comparator.comparing(PointInfo::getTurbineId)).collect(Collectors.toList());
  4936. for (int i = 0; i < fsInfos.size(); i++) {
  4937. setpjfs(min2, fsInfos.get(i), i + 1);
  4938. }
  4939. List<PointInfo> hjwdInfos = hjwdsMap.get(stId);
  4940. List<Double> hjwds = new ArrayList<>();
  4941. for (PointInfo wd : hjwdInfos) {
  4942. double v = wd.getPointDatas().stream().filter(p -> p.getValue() != 0.0).mapToDouble(PointData::getValue).average().orElse(0.0);
  4943. if (v > 83) v = 0;
  4944. if (v == 0) {
  4945. v = fjhjwd.getOrDefault(wd.getTurbineId(), 0.0);
  4946. } else {
  4947. fjhjwd.put(wd.getTurbineId(), v);
  4948. }
  4949. hjwds.add(v);
  4950. }
  4951. min2.setHjwd(hjwds.stream().filter(d -> d != 0.0).mapToDouble(Double::doubleValue).average().orElse(0.0));
  4952. stationInfoMin2Service.save(min2);
  4953. return min2;
  4954. }
  4955. private void setpjfs(StationInfoMin2 min2, PointInfo pi, int i) {
  4956. double v = 0;
  4957. if (pi == null || pi.getPointDatas().isEmpty()) {
  4958. v = fjfs.getOrDefault(pi.getTurbineId(), 0.0);
  4959. } else {
  4960. v = pi.getPointDatas().stream().mapToDouble(p -> p.getValue() > 23 ? 23.0 : p.getValue() < 0 ? 0.0 : p.getValue()).average().orElse(0.0);
  4961. fjfs.put(pi.getTurbineId(), v);
  4962. }
  4963. switch (i) {
  4964. case 1:
  4965. min2.setPjfs1(v);
  4966. break;
  4967. case 2:
  4968. min2.setPjfs2(v);
  4969. break;
  4970. case 3:
  4971. min2.setPjfs3(v);
  4972. break;
  4973. case 4:
  4974. min2.setPjfs4(v);
  4975. break;
  4976. case 5:
  4977. min2.setPjfs5(v);
  4978. break;
  4979. case 6:
  4980. min2.setPjfs6(v);
  4981. break;
  4982. case 7:
  4983. min2.setPjfs7(v);
  4984. break;
  4985. case 8:
  4986. min2.setPjfs8(v);
  4987. break;
  4988. case 9:
  4989. min2.setPjfs9(v);
  4990. break;
  4991. case 10:
  4992. min2.setPjfs10(v);
  4993. break;
  4994. case 11:
  4995. min2.setPjfs11(v);
  4996. break;
  4997. case 12:
  4998. min2.setPjfs12(v);
  4999. break;
  5000. case 13:
  5001. min2.setPjfs13(v);
  5002. break;
  5003. case 14:
  5004. min2.setPjfs14(v);
  5005. break;
  5006. case 15:
  5007. min2.setPjfs15(v);
  5008. break;
  5009. case 16:
  5010. min2.setPjfs16(v);
  5011. break;
  5012. case 17:
  5013. min2.setPjfs17(v);
  5014. break;
  5015. case 18:
  5016. min2.setPjfs18(v);
  5017. break;
  5018. case 19:
  5019. min2.setPjfs19(v);
  5020. break;
  5021. case 20:
  5022. min2.setPjfs20(v);
  5023. break;
  5024. case 21:
  5025. min2.setPjfs21(v);
  5026. break;
  5027. case 22:
  5028. min2.setPjfs22(v);
  5029. break;
  5030. case 23:
  5031. min2.setPjfs23(v);
  5032. break;
  5033. case 24:
  5034. min2.setPjfs24(v);
  5035. break;
  5036. case 25:
  5037. min2.setPjfs25(v);
  5038. break;
  5039. case 26:
  5040. min2.setPjfs26(v);
  5041. break;
  5042. case 27:
  5043. min2.setPjfs27(v);
  5044. break;
  5045. case 28:
  5046. min2.setPjfs28(v);
  5047. break;
  5048. case 29:
  5049. min2.setPjfs29(v);
  5050. break;
  5051. case 30:
  5052. min2.setPjfs30(v);
  5053. break;
  5054. case 31:
  5055. min2.setPjfs31(v);
  5056. break;
  5057. case 32:
  5058. min2.setPjfs32(v);
  5059. break;
  5060. case 33:
  5061. min2.setPjfs33(v);
  5062. break;
  5063. case 34:
  5064. min2.setPjfs34(v);
  5065. break;
  5066. case 35:
  5067. min2.setPjfs35(v);
  5068. break;
  5069. case 36:
  5070. min2.setPjfs36(v);
  5071. break;
  5072. case 37:
  5073. min2.setPjfs37(v);
  5074. break;
  5075. case 38:
  5076. min2.setPjfs38(v);
  5077. break;
  5078. case 39:
  5079. min2.setPjfs39(v);
  5080. break;
  5081. case 40:
  5082. min2.setPjfs40(v);
  5083. break;
  5084. case 41:
  5085. min2.setPjfs41(v);
  5086. break;
  5087. case 42:
  5088. min2.setPjfs42(v);
  5089. break;
  5090. case 43:
  5091. min2.setPjfs43(v);
  5092. break;
  5093. case 44:
  5094. min2.setPjfs44(v);
  5095. break;
  5096. case 45:
  5097. min2.setPjfs45(v);
  5098. break;
  5099. case 46:
  5100. min2.setPjfs46(v);
  5101. break;
  5102. case 47:
  5103. min2.setPjfs47(v);
  5104. break;
  5105. case 48:
  5106. min2.setPjfs48(v);
  5107. break;
  5108. case 49:
  5109. min2.setPjfs49(v);
  5110. break;
  5111. case 50:
  5112. min2.setPjfs50(v);
  5113. break;
  5114. case 51:
  5115. min2.setPjfs51(v);
  5116. break;
  5117. case 52:
  5118. min2.setPjfs52(v);
  5119. break;
  5120. case 53:
  5121. min2.setPjfs53(v);
  5122. break;
  5123. case 54:
  5124. min2.setPjfs54(v);
  5125. break;
  5126. case 55:
  5127. min2.setPjfs55(v);
  5128. break;
  5129. case 56:
  5130. min2.setPjfs56(v);
  5131. break;
  5132. case 57:
  5133. min2.setPjfs57(v);
  5134. break;
  5135. case 58:
  5136. min2.setPjfs58(v);
  5137. break;
  5138. case 59:
  5139. min2.setPjfs59(v);
  5140. break;
  5141. case 60:
  5142. min2.setPjfs60(v);
  5143. break;
  5144. case 61:
  5145. min2.setPjfs61(v);
  5146. break;
  5147. case 62:
  5148. min2.setPjfs62(v);
  5149. break;
  5150. case 63:
  5151. min2.setPjfs63(v);
  5152. break;
  5153. case 64:
  5154. min2.setPjfs64(v);
  5155. break;
  5156. case 65:
  5157. min2.setPjfs65(v);
  5158. break;
  5159. case 66:
  5160. min2.setPjfs66(v);
  5161. break;
  5162. case 67:
  5163. min2.setPjfs67(v);
  5164. break;
  5165. case 68:
  5166. min2.setPjfs68(v);
  5167. break;
  5168. case 69:
  5169. min2.setPjfs69(v);
  5170. break;
  5171. case 70:
  5172. min2.setPjfs70(v);
  5173. break;
  5174. case 71:
  5175. min2.setPjfs71(v);
  5176. break;
  5177. case 72:
  5178. min2.setPjfs72(v);
  5179. break;
  5180. case 73:
  5181. min2.setPjfs73(v);
  5182. break;
  5183. case 74:
  5184. min2.setPjfs74(v);
  5185. break;
  5186. case 75:
  5187. min2.setPjfs75(v);
  5188. break;
  5189. case 76:
  5190. min2.setPjfs76(v);
  5191. break;
  5192. case 77:
  5193. min2.setPjfs77(v);
  5194. break;
  5195. case 78:
  5196. min2.setPjfs78(v);
  5197. break;
  5198. case 79:
  5199. min2.setPjfs79(v);
  5200. break;
  5201. case 80:
  5202. min2.setPjfs80(v);
  5203. break;
  5204. case 81:
  5205. min2.setPjfs81(v);
  5206. break;
  5207. case 82:
  5208. min2.setPjfs82(v);
  5209. break;
  5210. case 83:
  5211. min2.setPjfs83(v);
  5212. break;
  5213. case 84:
  5214. min2.setPjfs84(v);
  5215. break;
  5216. case 85:
  5217. min2.setPjfs85(v);
  5218. break;
  5219. case 86:
  5220. min2.setPjfs86(v);
  5221. break;
  5222. case 87:
  5223. min2.setPjfs87(v);
  5224. break;
  5225. case 88:
  5226. min2.setPjfs88(v);
  5227. break;
  5228. case 89:
  5229. min2.setPjfs89(v);
  5230. break;
  5231. case 90:
  5232. min2.setPjfs90(v);
  5233. break;
  5234. case 91:
  5235. min2.setPjfs91(v);
  5236. break;
  5237. case 92:
  5238. min2.setPjfs92(v);
  5239. break;
  5240. case 93:
  5241. min2.setPjfs93(v);
  5242. break;
  5243. case 94:
  5244. min2.setPjfs94(v);
  5245. break;
  5246. case 95:
  5247. min2.setPjfs95(v);
  5248. break;
  5249. case 96:
  5250. min2.setPjfs96(v);
  5251. break;
  5252. case 97:
  5253. min2.setPjfs97(v);
  5254. break;
  5255. case 98:
  5256. min2.setPjfs98(v);
  5257. break;
  5258. case 99:
  5259. min2.setPjfs99(v);
  5260. break;
  5261. }
  5262. }
  5263. }