JavaFunctionJobHandler.java 294 KB

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