JavaFunctionJobHandler.java 294 KB

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