| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990 |
- #include "stdafx.h"
- #include "HttpPrcess.h"
- #include <yyjson.h>
- #include <Simplelog.h>
- #include "MonitorObject.h"
- #include "AlarmDefine.h"
- #include "ResistAlarm.h"
- #include <crc32.h>
- #include "AppService.h"
- #include <gbk2utf8.h>
- #include "Device.h"
- #include "SkylightMng.h"
- //处理get请求总入口
- void DealHttpGet(const httplib::Request& req, httplib::Response& res)
- {
- int code = 500;
- auto start = chrono::steady_clock::now();
- auto token = req.get_header_value("token");
- if (token.length() == 0 || token.empty())
- token = req.get_header_value("Authorization");
- char* json = nullptr;
- string body;
- size_t json_len = 0;
- //CSimpleLog::Info(fmt::format("[HTTP][GET][START] {}:{} {}", req.remote_addr, req.remote_port, req.target).c_str());
- SPDLOG_INFO("[HTTP][GET][START] {}:{} {}", req.remote_addr, req.remote_port, req.target);
- try
- {
- if (token.empty())
- {
- code = 401;
- }
- if (req.path.find("option_svg") != -1)
- code = DealOptionSvgData(req, token, res);
- else if (req.path.find("get_svg") != -1)
- code = DealGetSvgData(req, token, res);
- else if (req.path.find("get_mp_stat") != -1)
- code = DealGetMpStat(req, token, res);
- else if (req.path.find("conf_read/mitie_lock") != -1)
- code = DealGetMitieLock(req, token, &json, &json_len);
- else if (req.path.find("conf_read/convert_resist") != -1)
- code = DealGetConvertResist(req, token, &json, &json_len);
- else if (req.path.find("conf_read/retension_force") != -1)
- code = DealGetRetesionForce(req, token, &json, &json_len);
- else if (req.path.find("resistance_curve") != -1)
- code = DealGetResistCurve(req, token, &json, &json_len);
- else if (req.path.find("retension_curve") != -1)
- code = DealGetRetentionCurve(req, token, &json, &json_len);
- else if (req.path.find("resistance_report") != -1)
- code = DealGetResistReport(req, token, &json, &json_len);
- else if (req.path.find("Retention_report") != -1)
- code = DealGetRetentionReport(req, token, &json, &json_len);
- else if (req.path.find("move_info") != -1)
- code = DealGetMoveInfo(req, token, &json, &json_len);
- else if (req.path.find("operation_log") != -1)
- code = DealGetOptLog(req, token, &json, &json_len);
- else if (req.path.find("refer_curve") != -1)
- code = DealGetrefer_curve(req, token, &json, &json_len);
- else if (req.path.find("refer_option") != -1)
- code = DealGetrefer_option(req, token, &json, &json_len);
- else if (req.path.find("reminder_interval") != -1)
- code = deal_get_reminder_interval(req, token, &json, &json_len);
- else if (req.path.find("resist_data") != -1)
- code = DealGetResistData(req, token, &json, &json_len);
- //else if (req.path.find("retention_data") != -1)
- // code = DealGetRetentionData(req, token, &json, &json_len);
- else if (req.path.find("resist_move") != -1)
- code = DealResistMove(req, token, &json, &json_len);
- else if (req.path.find("alarm_list") != -1)
- code = deal_get_alarm_list(req, body, &json, &json_len);
- else if (req.path.find("backend_type") != -1)
- {
- body = R"({"type":1})";
- code = 200;
- }
- else
- code = 405;
- }
- catch (...)
- {
- code = 500;
- }
- if (json)
- res.set_content(json, "application/json");
- if (!body.empty())
- res.set_content(body.c_str(), "application/json");
- auto cost = chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - start).count();
- //CSimpleLog::Info(fmt::format("[HTTP][GET][END] code:{} COST:{} {}:{} {} {}", code, cost, req.remote_addr, req.remote_port, req.target, json ? json : "").c_str());
- SPDLOG_INFO("[HTTP][GET][END] code:{} COST:{} {}:{} {}", code, cost, req.remote_addr, req.remote_port, req.target);
- res.set_header("cost", to_string(cost) + " ms");
- res.status = code;
- if (json) free(json);
- }
- //处理get请求总入口
- void DealHttpPost(const httplib::Request& req, httplib::Response& res)
- {
- int code = 500;
- auto start = chrono::steady_clock::now();
- auto token = req.get_header_value("token");
- if (token.length() == 0 || token.empty())
- token = req.get_header_value("Authorization");
- char* json = nullptr;
- size_t json_len = 0;
- //CSimpleLog::Info(fmt::format("[HTTP][POST][START] {}:{} {} body:{}", req.remote_addr, req.remote_port, req.path, req.body).c_str());
- SPDLOG_INFO("[HTTP][POST][START] {}:{} {} body:{}", req.remote_addr, req.remote_port, req.path, req.body);
- try
- {
- if (token.empty())
- {
- code = 401;
- }
- if (req.path.find("post_svg") != -1)
- code = DealPostSvgData(req, token, res);
- else if (req.path.find("option_svg") != -1)
- code = DealOptionSvgData(req, token, res);
- else if (req.path.find("commit_record") != -1)
- code = DealPostCommitRecord(req.body.c_str(), req.body.length(), token, &json, &json_len);
- else if (req.path.find("get_svg") != -1)
- code = DealGetSvgData(req, token, res);
- else if (req.path.find("post_soft") != -1)
- code = DealPostBinData(req, token, res);
- else if (req.path.find("conf_write/convert_resist") != -1)
- code = DealPostConvertResist(req.body.c_str(), req.body.length(), token, &json, &json_len);
- else if (req.path.find("conf_write/mitie_lock") != -1)
- code = DealPostMitieLock(req.body.c_str(), req.body.length(), token, &json, &json_len);
- else if (req.path.find("conf_write/retension_force") != -1)
- code = DealPosttRetesionForce(req.body.c_str(), req.body.length(), token, &json, &json_len);
- else if (req.path.find("refer_curve") != -1)
- code = DealPostrefer_curve(req.body.c_str(), req.body.length(), token, &json, &json_len);
- else if (req.path.find("reminder_interval") != -1)
- code = deal_post_reminder_interval(req.body.c_str(), req.body.length(), token, &json, &json_len);
- else
- code = 405;
- }
- catch (...)
- {
- code = 500;
- }
- if (json)
- res.set_content(json, "application/json");
- auto cost = chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - start).count();
- //CSimpleLog::Info(fmt::format("[HTTP][POST][END] code:{} COST:{} {}:{} {} body:{} json:{}", code, cost, req.remote_addr, req.remote_port, req.path, req.body, json ? json : "").c_str());
- SPDLOG_INFO("[HTTP][POST][END] code:{} COST:{} {}:{} {} body:{}", code, cost, req.remote_addr, req.remote_port, req.path, req.body);
- res.set_header("cost", to_string(cost) + " ms");
- res.status = code;
- if (json) free(json);
- }
- void DealHttpPut(const httplib::Request& req, httplib::Response& res)
- {
- int code = 500;
- auto start = chrono::steady_clock::now();
- auto token = req.get_header_value("token");
- if (token.length() == 0 || token.empty())
- token = req.get_header_value("Authorization");
- char* json = nullptr;
- size_t json_len = 0;
- SPDLOG_INFO("[HTTP][POST][START] {}:{} {} body:{}", req.remote_addr, req.remote_port, req.path, req.body);
- try
- {
- if (token.empty())
- {
- code = 401;
- }
- if (req.path.find("/data/zzjno") != -1)
- code = DealPutChangeZzjno(req.body.c_str(), req.body.length(), token, &json, &json_len);
- else
- code = 405;
- }
- catch (...)
- {
- code = 500;
- }
- if (json)
- res.set_content(json, "application/json");
- auto cost = chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - start).count();
- SPDLOG_INFO("[HTTP][POST][END] code:{} COST:{} {}:{} {} body:{}", code, cost, req.remote_addr, req.remote_port, req.path, req.body);
- res.set_header("cost", to_string(cost) + " ms");
- res.status = code;
- if (json) free(json);
- }
- int DealPostSvgData(const httplib::Request& req, const string token, httplib::Response& res)
- {
- if (token.find("AAAAAAAA") == -1) return 403;
- auto id = req.get_header_value("id");
- if (id.empty()) return 400;//参数错误
- char szID[200] = { 0 };
- utf82gbk(szID, 200, id.c_str(), id.length()); //处理中文
- if (req.body.empty()) return 400;
- CString strPath = CSimpleLog::GetAppDir() + "svg\\" + szID + ".svg";
- CFile file;
- if (file.Open(strPath, CFile::modeWrite | CFile::typeBinary | CFile::modeCreate))
- {
- file.Write(req.body.c_str(), req.body.length());
- file.Close();
- return 200;
- }
- else
- {
- return 500;
- }
- return 405;
- }
- int DealPostBinData(const httplib::Request& req, const string token, httplib::Response& res)
- {
- auto doc = yyjson_mut_doc_new(nullptr);
- auto root = yyjson_mut_obj(doc);
- yyjson_mut_doc_set_root(doc, root);
- char msg[100] = { 0 };
- int code = 500;
- string type;
- do
- {
- if (token.find("AAAAAAAA") == -1)
- {
- code = 403;
- gbk2utf8(msg, 100, "无权限");
- break;
- }
- auto IMEI = req.get_header_value("IMEI");
- if (IMEI.empty())
- {
- code = 400;
- gbk2utf8(msg, 100, "IMEI不能为空");
- break;
- }
- type = req.get_header_value("type");
- if (type.empty())
- {
- code = 400;
- gbk2utf8(msg, 100, "type不能为空");
- break;
- }
- if (req.body.empty())
- {
- code = 400;
- gbk2utf8(msg, 100, "body数据不能为空");
- break;
- }
- time_t tNow;
- time(&tNow);
- if (CAppService::Instance()->m_bHaveDeviceUpgrade && tNow - CAppService::Instance()->m_tDeviceUpgrade < 60)
- {
- code = 400;
- gbk2utf8(msg, 100, "目前有设备在升级中, 请等待.");
- break;
- }
- auto filesize = req.body.length();
- yyjson_mut_obj_add_int(doc, root, "filesize", filesize);
- auto filecrc = crc32buf(req.body.c_str(), filesize);
- yyjson_mut_obj_add_int(doc, root, "filecrc", filecrc);
- auto pData = new char[filesize * 2 + 2];
- CAppService::FileDataConvertCharData((uint8_t*)req.body.c_str(), filesize, pData);
- {
- auto& mapTypeData = CAppService::Instance()->m_mapTypeData;
- auto it = mapTypeData.find(type.c_str());
- int datalen = filesize * 2;
- if (it != mapTypeData.end())
- {
- it->second->Join();
- it->second = nullptr;
- }
- auto pInfo = new UPGRADE_FILE_DATA;
- mapTypeData[type.c_str()] = pInfo;
- pInfo->data = pData;
- pInfo->len = filesize * 2;
- pInfo->crc = filecrc;
- pData[datalen] = 0x00;
- pData[datalen + 1] = 0x00;
- }
- gbk2utf8(msg, 100, "数据接收成功");
- //通知设备
- auto notify_ret = CLNHandle::SendUpdateToDevice(IMEI.c_str(), req.remote_addr, type);
-
- if (notify_ret == 0)
- {
- code = 200;
- gbk2utf8(msg, 100, "数据接收成功, 且下发数据成功!");
- }
- else if (notify_ret == 1)
- {
- code = 400;
- gbk2utf8(msg, 100, "未找到设备或者设备未在线!");
- }
- else if (notify_ret == 2)
- {
- code = 500;
- gbk2utf8(msg, 100, "数据接收成功, 但下发数据失败!");
- }
- } while (false);
- yyjson_mut_obj_add_strcpy(doc, root, "type", type.c_str());
- yyjson_mut_obj_add_int(doc, root, "code", code);
- yyjson_mut_obj_add_str(doc, root, "msg", msg);
- size_t len;
- auto json = yyjson_mut_write(doc, 0, &len);
- if (json)
- {
- res.set_content(json, len, "application/json");
- free((void*)json);
- }
- yyjson_mut_doc_free(doc);
- return code;
- }
- int DealGetSvgData(const httplib::Request& req, const string token, httplib::Response& res)
- {
- auto id = req.get_param_value("id");
- if (id.empty()) return 400;//参数错误
- char szID[200] = { 0 };
- utf82gbk(szID, 200, id.c_str(), id.length()); //处理中文
- CString strPath = CSimpleLog::GetAppDir() + "svg\\" + szID + ".svg";
- auto bExist = CSimpleLog::PathFileExists(strPath);
- if (bExist == false) return 404;
- CFile file;
- if (file.Open(strPath, CFile::modeRead | CFile::typeBinary))
- {
- int len = file.GetLength();
- auto pData = new uint8_t[len];
- file.Read(pData, len);
- file.Close();
- res.set_content((char*)pData, len, "image/svg+xml");
- }
- else
- {
- return 500;
- }
- return 200;
- }
- int DealOptionSvgData(const httplib::Request& req, const string token, httplib::Response& res)
- {
- auto id = req.get_param_value("id");
- if (id.empty()) return 400;//参数错误
- char szID[200] = { 0 };
- utf82gbk(szID, 200, id.c_str(), id.length()); //处理中文
- //auto doc = yyjson_mut_doc_new(nullptr);
- //auto root = yyjson_mut_obj(doc);
- //yyjson_mut_doc_set_root(doc, root);
- //yyjson_mut_obj_add_bool(doc, root, "result", CSimpleLog::PathFileExists(CSimpleLog::GetAppDir() + id.c_str()));
- //size_t len;
- //auto json = yyjson_mut_write(doc, 0, &len);
- //res.set_content(json, len, "application/json");
- //if (json)
- //{
- // free((void*)json);
- // json = nullptr;
- //}
- //yyjson_mut_doc_free(doc);
- CString strPath = CSimpleLog::GetAppDir() + "svg\\" + szID + ".svg";
- auto bExist = CSimpleLog::PathFileExists(strPath);
- string strResult;
- if (bExist)
- strResult = R"({"result":true})";
- else
- strResult = R"({"result":false})";
- res.set_content(strResult, "application/json");
- return 200;
- }
- int DealGetMpStat(const httplib::Request& req, const string token, httplib::Response& res)
- {
- auto id = req.get_param_value("id");//杭南杭甬场
- if (id.empty()) return 400;//参数错误
- char gbk[200];
- int id_len = utf82gbk(gbk, 200, id.c_str(), id.length());
- auto pObject = CMonitorObjectMng::Instance()->GetTreeByID(string(gbk));
- if (nullptr == pObject) return 404;
- if (pObject->type.compare("station") != 0) return 400;
- auto doc = yyjson_mut_doc_new(nullptr);
- auto root = yyjson_mut_arr(doc);
- yyjson_mut_doc_set_root(doc, root);
- for (const auto& it : pObject->m_lstMo)
- {
- auto arr = yyjson_mut_arr(doc);
- yyjson_mut_arr_add_val(root, arr);
- yyjson_mut_arr_add_strcpy(doc, arr, it->id.c_str());
- yyjson_mut_arr_add_strcpy(doc, arr, it->name.c_str());
- string imei; int idx;
- CMonitorObjectMng::Instance()->MOMP2IMEI(it->id, imei, idx);
- if (imei.length())
- {
- string mo, mp;
- if (CMonitorObjectMng::spiltByPoint(it->id, mo, mp))
- {
- SYSTEMTIME stAlarm = { 0 };
- auto ty = CResistAlarmMng::Instance()->GetAlarmStat(mo, mp, stAlarm);
- if (ty == eZL_MP_STAT::MP_STAT_OFFLINE_GRAY || ty == eZL_MP_STAT::MP_STAT_UNKNOW)
- {
- if (CDeviceMng::Instance()->IsDeviceOnline(imei, idx))
- yyjson_mut_arr_add_int(doc, arr, (int)eZL_MP_STAT::MP_STAT_NORMAL_GREEN);
- else
- yyjson_mut_arr_add_int(doc, arr, (int)eZL_MP_STAT::MP_STAT_OFFLINE_GRAY);
- }
- else
- {
- yyjson_mut_arr_add_int(doc, arr, (int)ty);
- sprintf_s(gbk, 200, "%04d-%02d-%02d %02d:%02d:%02d.%03d", stAlarm.wYear, stAlarm.wMonth, stAlarm.wDay, stAlarm.wHour, stAlarm.wMinute, stAlarm.wSecond, stAlarm.wMilliseconds);
- yyjson_mut_arr_add_strcpy(doc, arr, gbk);
- }
- }
- else
- {
- yyjson_mut_arr_add_int(doc, arr, (int)eZL_MP_STAT::MP_STAT_UNINSTALL_WHITE);
- }
- }
- else
- {
- yyjson_mut_arr_add_int(doc, arr, (int)eZL_MP_STAT::MP_STAT_UNINSTALL_WHITE);
- }
- }
- size_t len;
- auto json = yyjson_mut_write(doc, 0, &len);
- res.set_content(json, len, "application/json");
- if (json)
- {
- free((void*)json);
- json = nullptr;
- }
- yyjson_mut_doc_free(doc);
- return 200;
- }
- int DealGetMitieLock(const httplib::Request& req, const string token, char** json, size_t* json_len)
- {
- string mo = req.get_param_value("mo");
- string mp = req.get_param_value("mp");
- eSuoBiPosi posi = (eSuoBiPosi)atoi(req.get_param_value("posi").c_str());
- if (posi == eSuoBiPosi::SB_ZERO) posi = eSuoBiPosi::SB_UNKNOWN;
- if (mo.length() == 0 || mp.length() == 0)
- return 400;
- auto doc = yyjson_mut_doc_new(nullptr);
- auto root = yyjson_mut_obj(doc);
- yyjson_mut_doc_set_root(doc, root);
- SUOBI_OVER_LIMIT_INFO* pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)posi, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
- if (pInfo)
- {
- yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
- if (pInfo->alarm_low_limit > INT_MIN)
- yyjson_mut_obj_add_int(doc, root, "alarm_low_limit", pInfo->alarm_low_limit);
- else
- yyjson_mut_obj_add_null(doc, root, "alarm_low_limit");
- if (pInfo->warn_low_limit > INT_MIN)
- yyjson_mut_obj_add_int(doc, root, "warn_low_limit", pInfo->warn_low_limit);
- else
- yyjson_mut_obj_add_null(doc, root, "warn_low_limit");
- if (pInfo->alarm_high_limit < INT_MAX)
- yyjson_mut_obj_add_int(doc, root, "alarm_high_limit", pInfo->alarm_high_limit);
- else
- yyjson_mut_obj_add_null(doc, root, "alarm_high_limit");
- if (pInfo->warn_high_limit < INT_MAX)
- yyjson_mut_obj_add_int(doc, root, "warn_high_limit", pInfo->warn_high_limit);
- else
- yyjson_mut_obj_add_null(doc, root, "warn_high_limit");
- }
- else
- {
- yyjson_mut_obj_add_bool(doc, root, "enable", false);
- yyjson_mut_obj_add_null(doc, root, "alarm_low_limit");
- yyjson_mut_obj_add_null(doc, root, "warn_low_limit");
- yyjson_mut_obj_add_null(doc, root, "alarm_high_limit");
- yyjson_mut_obj_add_null(doc, root, "warn_high_limit");
- }
- *json = yyjson_mut_write(doc, 0, json_len);
- yyjson_mut_doc_free(doc);
- return 200;
- }
- int DealPostMitieLock(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len)
- {
- int code = 400;
- auto req_doc = yyjson_read(body_ptr, body_len, 0);
- if (req_doc == nullptr) return 400;
- auto req_root = yyjson_doc_get_root(req_doc);
- do
- {
- auto mo = yyjson_get_str(yyjson_obj_get(req_root, "mo"));
- auto mp = yyjson_get_str(yyjson_obj_get(req_root, "mp"));
- eSuoBiPosi posi = (eSuoBiPosi)yyjson_get_int(yyjson_obj_get(req_root, "posi"));;//预留
- if (posi == eSuoBiPosi::SB_ZERO) posi = eSuoBiPosi::SB_UNKNOWN;
- auto conf = yyjson_obj_get(req_root, "conf");
- if (mo == nullptr || mp == nullptr || conf == nullptr)
- break;
- auto doc = yyjson_mut_doc_new(nullptr);
- auto root = yyjson_mut_obj(doc);
- yyjson_mut_doc_set_root(doc, root);
- size_t len;
- char* str_conf = nullptr;
- //更新内存里
- SUOBI_OVER_LIMIT_INFO* pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)posi, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
- CString sql;
- if (pInfo == nullptr)
- {
- SUOBI_OVER_LIMIT_INFO* pInfo = new SUOBI_OVER_LIMIT_INFO;
- pInfo->type = eZL_ALARMTYPE::SUOBI_LOCK_LIMIT;
- pInfo->no = (uint8_t)posi;
- pInfo->enable = yyjson_get_bool(yyjson_obj_get(conf, "enable"));
- yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
- {
- auto val = yyjson_obj_get(conf, "alarm_low_limit");
- if (val && yyjson_is_int(val))
- pInfo->alarm_low_limit = yyjson_get_int(val);
- yyjson_mut_obj_add_int(doc, root, "alarm_low_limit", pInfo->alarm_low_limit);
- }
- {
- auto val = yyjson_obj_get(conf, "warn_low_limit");
- if (val && yyjson_is_int(val))
- pInfo->warn_low_limit = yyjson_get_int(val);
- yyjson_mut_obj_add_int(doc, root, "warn_low_limit", pInfo->warn_low_limit);
- }
- {
- auto val = yyjson_obj_get(conf, "alarm_high_limit");
- if (val && yyjson_is_int(val))
- pInfo->alarm_high_limit = yyjson_get_int(val);
- yyjson_mut_obj_add_int(doc, root, "alarm_high_limit", pInfo->alarm_high_limit);
- }
- {
- auto val = yyjson_obj_get(conf, "warn_high_limit");
- if (val && yyjson_is_int(val))
- pInfo->warn_high_limit = yyjson_get_int(val);
- yyjson_mut_obj_add_int(doc, root, "warn_high_limit", pInfo->warn_high_limit);
- }
- str_conf = yyjson_mut_write(doc, 0, &len);
- yyjson_mut_doc_free(doc);
- CResistAlarmMng::Instance()->Insert(mo, mp, (uint8_t)posi, (uint8_t)eZL_ALARMTYPE::SUOBI_LOCK_LIMIT, pInfo);
- time_t tt;
- time(&tt);
- sql.Format("INSERT INTO [rm_alarm_set]([mo],[mp],[no],[type],[conf],[time]) VALUES ('%s','%s',%d, %d,'%s','%I64u')",
- mo, mp, (uint8_t)posi, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT, str_conf, tt);
- }
- else
- {
- pInfo->enable = yyjson_get_bool(yyjson_obj_get(conf, "enable"));
- yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
- {
- auto val = yyjson_obj_get(conf, "alarm_low_limit");
- if (val && yyjson_is_int(val))
- pInfo->alarm_low_limit = yyjson_get_int(val);
- else
- pInfo->alarm_low_limit = INT_MIN;
- yyjson_mut_obj_add_int(doc, root, "alarm_low_limit", pInfo->alarm_low_limit);
- }
- {
- auto val = yyjson_obj_get(conf, "warn_low_limit");
- if (val && yyjson_is_int(val))
- pInfo->warn_low_limit = yyjson_get_int(val);
- else
- pInfo->warn_low_limit = INT_MIN;
- yyjson_mut_obj_add_int(doc, root, "warn_low_limit", pInfo->warn_low_limit);
- }
- {
- auto val = yyjson_obj_get(conf, "alarm_high_limit");
- if (val && yyjson_is_int(val))
- pInfo->alarm_high_limit = yyjson_get_int(val);
- else
- pInfo->alarm_high_limit = INT_MAX;
- yyjson_mut_obj_add_int(doc, root, "alarm_high_limit", pInfo->alarm_high_limit);
- }
- {
- auto val = yyjson_obj_get(conf, "warn_high_limit");
- if (val && yyjson_is_int(val))
- pInfo->warn_high_limit = yyjson_get_int(val);
- else
- pInfo->warn_high_limit = INT_MAX;
- yyjson_mut_obj_add_int(doc, root, "warn_high_limit", pInfo->warn_high_limit);
- }
- str_conf = yyjson_mut_write(doc, 0, &len);
- yyjson_mut_doc_free(doc);
- sql.Format("update rm_alarm_set SET conf = '%s' WHERE mo = '%s' and mp = '%s' and no = %d and type = %d",
- str_conf, mo, mp, (uint8_t)posi, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
- }
-
- if (str_conf) free(str_conf);
- if (CDBConnectPool::Instance()->DBExecuteSQL(sql) == FALSE)
- {
- ASSERT(FALSE);
- CSimpleLog::Error("语句执行失败" + sql);
- code = 500;
- break;
- }
- code = 200;
- } while (false);
- yyjson_doc_free(req_doc);
- return code;
- }
- int DealGetConvertResist(const httplib::Request& req, const string token, char** json, size_t* json_len)
- {
- string mo = req.get_param_value("mo");
- string mp = req.get_param_value("mp");
- if (mo.length() == 0 || mp.length() == 0)
- return 400;
- auto doc = yyjson_mut_doc_new(nullptr);
- auto root = yyjson_mut_obj(doc);
- yyjson_mut_doc_set_root(doc, root);
- CONVERT_RESIST_OVER_LIMIT* pInfo = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
- if (pInfo)
- {
- yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
- if (pInfo->dw_alarm_low_limit > INT_MIN)
- yyjson_mut_obj_add_int(doc, root, "dw_alarm_low_limit", pInfo->dw_alarm_low_limit);
- else
- yyjson_mut_obj_add_null(doc, root, "dw_alarm_low_limit");
- if (pInfo->dw_warn_low_limit > INT_MIN)
- yyjson_mut_obj_add_int(doc, root, "dw_warn_low_limit", pInfo->dw_warn_low_limit);
- else
- yyjson_mut_obj_add_null(doc, root, "dw_warn_low_limit");
- if (pInfo->up_alarm_high_limit < INT_MAX)
- yyjson_mut_obj_add_int(doc, root, "up_alarm_high_limit", pInfo->up_alarm_high_limit);
- else
- yyjson_mut_obj_add_null(doc, root, "up_alarm_high_limit");
- if (pInfo->up_warn_high_limit < INT_MAX)
- yyjson_mut_obj_add_int(doc, root, "up_warn_high_limit", pInfo->up_warn_high_limit);
- else
- yyjson_mut_obj_add_null(doc, root, "up_warn_high_limit");
- }
- else
- {
- yyjson_mut_obj_add_bool(doc, root, "enable", false);
- yyjson_mut_obj_add_null(doc, root, "dw_alarm_low_limit");
- yyjson_mut_obj_add_null(doc, root, "dw_warn_low_limit");
- yyjson_mut_obj_add_null(doc, root, "up_alarm_high_limit");
- yyjson_mut_obj_add_null(doc, root, "up_warn_high_limit");
- }
- *json = yyjson_mut_write(doc, 0, json_len);
- yyjson_mut_doc_free(doc);
- return 200;
- }
- int DealGetRetesionForce(const httplib::Request& req, const string token, char** json, size_t* json_len)
- {
- string mo = req.get_param_value("mo");
- string mp = req.get_param_value("mp");
- string posi = req.get_param_value("posi");
- if (mo.length() == 0 || mp.length() == 0 || posi.length() == 0)
- return 400;
- eSuoBiPosi no = (eSuoBiPosi)atoi(posi.c_str());
- auto doc = yyjson_mut_doc_new(nullptr);
- auto root = yyjson_mut_obj(doc);
- yyjson_mut_doc_set_root(doc, root);
- RETENSION_FORCE_DROP* pInfo = (RETENSION_FORCE_DROP*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)no, eZL_ALARMTYPE::RETENSION_FORCE);
- if (pInfo)
- {
- yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
- if (pInfo->dw_alarm_low_drop > INT_MIN)
- yyjson_mut_obj_add_int(doc, root, "dw_alarm_low_drop", pInfo->dw_alarm_low_drop);
- else
- yyjson_mut_obj_add_null(doc, root, "dw_alarm_low_drop");
- if (pInfo->alarm_low_percent > INT_MIN)
- yyjson_mut_obj_add_int(doc, root, "alarm_low_percent", pInfo->alarm_low_percent);
- else
- yyjson_mut_obj_add_null(doc, root, "alarm_low_percent");
- if (pInfo->alarm_high_percent > INT_MIN)
- yyjson_mut_obj_add_int(doc, root, "alarm_high_percent", pInfo->alarm_high_percent);
- else
- yyjson_mut_obj_add_null(doc, root, "alarm_high_percent");
- }
- else
- {
- yyjson_mut_obj_add_bool(doc, root, "enable", false);
- yyjson_mut_obj_add_null(doc, root, "dw_alarm_low_drop");
- yyjson_mut_obj_add_null(doc, root, "alarm_low_percent");
- yyjson_mut_obj_add_null(doc, root, "alarm_high_percent");
- }
- *json = yyjson_mut_write(doc, 0, json_len);
- yyjson_mut_doc_free(doc);
- return 200;
- }
- int DealPostConvertResist(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len)
- {
- int code = 400;
- auto req_doc = yyjson_read(body_ptr, body_len, 0);
- if (req_doc == nullptr) return 400;
- auto req_root = yyjson_doc_get_root(req_doc);
- do
- {
- auto mo = yyjson_get_str(yyjson_obj_get(req_root, "mo"));
- auto mp = yyjson_get_str(yyjson_obj_get(req_root, "mp"));
- auto conf = yyjson_obj_get(req_root, "conf");
- if (mo == nullptr || mp == nullptr || conf == nullptr)
- break;
- auto doc = yyjson_mut_doc_new(nullptr);
- auto root = yyjson_mut_obj(doc);
- yyjson_mut_doc_set_root(doc, root);
- size_t len;
- char* str_conf = nullptr;
- //更新内存里
- CONVERT_RESIST_OVER_LIMIT* pInfo = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
- CString sql;
- if (pInfo == nullptr)
- {
- CONVERT_RESIST_OVER_LIMIT* pInfo = new CONVERT_RESIST_OVER_LIMIT;
- pInfo->type = eZL_ALARMTYPE::CONVERT_LIMIT;
- pInfo->no = 2;
- pInfo->enable = yyjson_get_bool(yyjson_obj_get(conf, "enable"));
- yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
- {
- auto val = yyjson_obj_get(conf, "dw_alarm_low_limit");
- if (val && yyjson_is_int(val))
- pInfo->dw_alarm_low_limit = yyjson_get_int(val);
- yyjson_mut_obj_add_int(doc, root, "dw_alarm_low_limit", pInfo->dw_alarm_low_limit);
- }
- {
- auto val = yyjson_obj_get(conf, "dw_warn_low_limit");
- if (val && yyjson_is_int(val))
- pInfo->dw_warn_low_limit = yyjson_get_int(val);
- yyjson_mut_obj_add_int(doc, root, "dw_warn_low_limit", pInfo->dw_warn_low_limit);
- }
- {
- auto val = yyjson_obj_get(conf, "up_alarm_high_limit");
- if (val && yyjson_is_int(val))
- pInfo->up_alarm_high_limit = yyjson_get_int(val);
- yyjson_mut_obj_add_int(doc, root, "up_alarm_high_limit", pInfo->up_alarm_high_limit);
- }
- {
- auto val = yyjson_obj_get(conf, "up_warn_high_limit");
- if (val && yyjson_is_int(val))
- pInfo->up_warn_high_limit = yyjson_get_int(val);
- yyjson_mut_obj_add_int(doc, root, "up_warn_high_limit", pInfo->up_warn_high_limit);
- }
- str_conf = yyjson_mut_write(doc, 0, &len);
- yyjson_mut_doc_free(doc);
- CResistAlarmMng::Instance()->Insert(mo, mp, 2, (uint8_t)eZL_ALARMTYPE::CONVERT_LIMIT, pInfo);
- sql.Format("INSERT INTO [rm_alarm_set]([mo],[mp],[no],[type],[conf],[time]) VALUES ('%s','%s',%d,%d,'%s','%I64u')",
- mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT, str_conf, 0);
- }
- else
- {
- pInfo->enable = yyjson_get_bool(yyjson_obj_get(conf, "enable"));
- yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
- {
- auto val = yyjson_obj_get(conf, "dw_alarm_low_limit");
- if (val && yyjson_is_int(val))
- pInfo->dw_alarm_low_limit = yyjson_get_int(val);
- else
- pInfo->dw_alarm_low_limit = INT_MIN;
- yyjson_mut_obj_add_int(doc, root, "dw_alarm_low_limit", pInfo->dw_alarm_low_limit);
- }
- {
- auto val = yyjson_obj_get(conf, "dw_warn_low_limit");
- if (val && yyjson_is_int(val))
- pInfo->dw_warn_low_limit = yyjson_get_int(val);
- else
- pInfo->dw_warn_low_limit = INT_MIN;
- yyjson_mut_obj_add_int(doc, root, "dw_warn_low_limit", pInfo->dw_warn_low_limit);
- }
- {
- auto val = yyjson_obj_get(conf, "up_alarm_high_limit");
- if (val && yyjson_is_int(val))
- pInfo->up_alarm_high_limit = yyjson_get_int(val);
- else
- pInfo->up_alarm_high_limit = INT_MAX;
- yyjson_mut_obj_add_int(doc, root, "up_alarm_high_limit", pInfo->up_alarm_high_limit);
- }
- {
- auto val = yyjson_obj_get(conf, "up_warn_high_limit");
- if (val && yyjson_is_int(val))
- pInfo->up_warn_high_limit = yyjson_get_int(val);
- else
- pInfo->up_warn_high_limit = INT_MAX;
- yyjson_mut_obj_add_int(doc, root, "up_warn_high_limit", pInfo->up_warn_high_limit);
- }
- str_conf = yyjson_mut_write(doc, 0, &len);
- yyjson_mut_doc_free(doc);
- sql.Format("update rm_alarm_set SET conf = '%s' WHERE mo = '%s' and mp = '%s' and no = %d and type = %d",
- str_conf, mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
- }
- if (str_conf) free(str_conf);
- if (CDBConnectPool::Instance()->DBExecuteSQL(sql) == FALSE)
- {
- ASSERT(FALSE);
- CSimpleLog::Error("语句执行失败" + sql);
- code = 500;
- break;
- }
- code = 200;
- } while (false);
- yyjson_doc_free(req_doc);
- return code;
- }
- int DealPosttRetesionForce(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len)
- {
- int code = 400;
- auto req_doc = yyjson_read(body_ptr, body_len, 0);
- if (req_doc == nullptr) return 400;
- string msg;
- auto req_root = yyjson_doc_get_root(req_doc);
- do
- {
- auto mo = yyjson_get_str(yyjson_obj_get(req_root, "mo"));
- auto mp = yyjson_get_str(yyjson_obj_get(req_root, "mp"));
- auto posi= yyjson_get_int(yyjson_obj_get(req_root, "posi"));
- auto conf = yyjson_obj_get(req_root, "conf");
- if (mo == nullptr || mp == nullptr || conf == nullptr || posi == 0)
- break;
- auto doc = yyjson_mut_doc_new(nullptr);
- auto root = yyjson_mut_obj(doc);
- yyjson_mut_doc_set_root(doc, root);
- size_t len;
- char* str_conf = nullptr;
- //更新内存里
- RETENSION_FORCE_DROP* pInfo = (RETENSION_FORCE_DROP*)CResistAlarmMng::Instance()->Find(mo, mp, posi, eZL_ALARMTYPE::RETENSION_FORCE);
- CString sql;
- if (pInfo == nullptr/* && pInfo->dw_alarm_low_drop == INT_MIN*/)
- {
- RETENSION_FORCE_DROP* pInfo = new RETENSION_FORCE_DROP;
- pInfo->type = eZL_ALARMTYPE::RETENSION_FORCE;
- pInfo->no = posi;
- pInfo->enable = yyjson_get_bool(yyjson_obj_get(conf, "enable"));
- yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
- {
- auto val = yyjson_obj_get(conf, "dw_alarm_low_drop");
- if (val && yyjson_is_int(val))
- pInfo->dw_alarm_low_drop = yyjson_get_int(val);
- else
- pInfo->dw_alarm_low_drop = INT_MIN;
- yyjson_mut_obj_add_int(doc, root, "dw_alarm_low_drop", pInfo->dw_alarm_low_drop);
- }
- {
- auto val = yyjson_obj_get(conf, "alarm_high_percent");
- if (val && yyjson_is_int(val))
- pInfo->alarm_high_percent = yyjson_get_int(val);
- else
- pInfo->alarm_high_percent = INT_MIN;
- yyjson_mut_obj_add_int(doc, root, "alarm_high_percent", pInfo->alarm_high_percent);
- }
- {
- auto val = yyjson_obj_get(conf, "alarm_low_percent");
- if (val && yyjson_is_int(val))
- pInfo->alarm_low_percent = yyjson_get_int(val);
- else
- pInfo->alarm_low_percent = INT_MIN;
- yyjson_mut_obj_add_int(doc, root, "alarm_low_percent", pInfo->alarm_low_percent);
- }
- str_conf = yyjson_mut_write(doc, 0, &len);
- yyjson_mut_doc_free(doc);
- CResistAlarmMng::Instance()->Insert(mo, mp, posi, (uint8_t)eZL_ALARMTYPE::RETENSION_FORCE, pInfo);
- time_t tt;
- time(&tt);
- sql.Format("INSERT INTO [rm_alarm_set]([mo],[mp],[no],[type],[conf],[time]) VALUES ('%s','%s',%d, %d,'%s','%I64u')",
- mo, mp, posi, eZL_ALARMTYPE::RETENSION_FORCE, str_conf, tt);
- }
- else
- {
- pInfo->enable = yyjson_get_bool(yyjson_obj_get(conf, "enable"));
- yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
- {
- auto val = yyjson_obj_get(conf, "dw_alarm_low_drop");
- if (val && yyjson_is_int(val))
- pInfo->dw_alarm_low_drop = yyjson_get_int(val);
- else
- pInfo->dw_alarm_low_drop = INT_MIN;
- yyjson_mut_obj_add_int(doc, root, "dw_alarm_low_drop", pInfo->dw_alarm_low_drop);
- }
- {
- auto val = yyjson_obj_get(conf, "alarm_high_percent");
- if (val && yyjson_is_int(val))
- pInfo->alarm_high_percent = yyjson_get_int(val);
- else
- pInfo->alarm_high_percent = INT_MIN;
- yyjson_mut_obj_add_int(doc, root, "alarm_high_percent", pInfo->alarm_high_percent);
- }
- {
- auto val = yyjson_obj_get(conf, "alarm_low_percent");
- if (val && yyjson_is_int(val))
- pInfo->alarm_low_percent = yyjson_get_int(val);
- else
- pInfo->alarm_low_percent = INT_MIN;
- yyjson_mut_obj_add_int(doc, root, "alarm_low_percent", pInfo->alarm_low_percent);
- }
- str_conf = yyjson_mut_write(doc, 0, &len);
- yyjson_mut_doc_free(doc);
- sql.Format("update rm_alarm_set SET conf = '%s' WHERE mo = '%s' and mp = '%s' and no = %d and type = %d",
- str_conf, mo, mp, posi, eZL_ALARMTYPE::RETENSION_FORCE);
- }
- if (str_conf) free(str_conf);
- if (CDBConnectPool::Instance()->DBExecuteSQL(sql) == FALSE)
- {
- ASSERT(FALSE);
- msg = "语句执行失败" + sql;
- CSimpleLog::Error(msg.c_str());
- code = 500;
- break;
- }
- code = 200;
- } while (false);
- yyjson_doc_free(req_doc);
- return code;
- }
- int DealPostCommitRecord(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len)
- {
- int code = 400;
- string msg;
- auto req_doc = yyjson_read(body_ptr, body_len, 0);
- if (req_doc == nullptr) return 400;
- auto req_root = yyjson_doc_get_root(req_doc);
- do
- {
- if (yyjson_is_arr(req_root) == false) break;
- auto doc = yyjson_mut_doc_new(nullptr);
- auto root = yyjson_mut_obj(doc);
- yyjson_mut_doc_set_root(doc, root);
- size_t n = yyjson_arr_size(req_root);
- auto req_obj = yyjson_arr_get_first(req_root);
- for (size_t i = 0; i < n; i++)
- {
- auto module = yyjson_get_int(yyjson_obj_get(req_obj, "module"));
- auto dura = yyjson_get_int(yyjson_obj_get(req_obj, "dura"));
- auto analyze_type = yyjson_get_int(yyjson_obj_get(req_obj, "analyze_type"));
- auto station = yyjson_get_str(yyjson_obj_get(req_obj, "station"));
- auto station_name = yyjson_get_str(yyjson_obj_get(req_obj, "station_name"));
- auto mo = yyjson_get_str(yyjson_obj_get(req_obj, "mo"));
- auto mo_name = yyjson_get_str(yyjson_obj_get(req_obj, "mo_name"));
- auto mp = yyjson_get_str(yyjson_obj_get(req_obj, "mp"));
- auto mp_name = yyjson_get_str(yyjson_obj_get(req_obj, "mp_name"));
- auto start_time = yyjson_get_uint(yyjson_obj_get(req_obj, "start_time"));
- auto end_time = yyjson_get_uint(yyjson_obj_get(req_obj, "end_time"));
- time_t tt;
- time(&tt);
- auto name = yyjson_get_str(yyjson_obj_get(req_obj, "name"));
- auto username = yyjson_get_str(yyjson_obj_get(req_obj, "username"));
- if (module == 0 || dura == 0 || station == nullptr ||
- station_name == nullptr || start_time == 0 || name == nullptr)
- break;
- auto strStation = UTF8toANSI(station);
- auto strStationName = UTF8toANSI(station_name);
- auto strName = UTF8toANSI(name);
- CString strDuraTime;
- dura = dura / 1000.0 + 0.5;
- if (dura / 60)
- strDuraTime.Format(" 时长:%d分%d秒", dura / 60, dura % 60);
- else if (dura)
- strDuraTime.Format(" 时长:%d秒", dura);
- //CString sql = fmt::format("INSERT INTO [dbo].[rm_record]\
- //(module, dura, analyze_type, station\
- // , station_name, mo, mo_name, mp, mp_name, start_time\
- // , end_time, time, name,username,opt,mark) VALUES\
- //({}, {}, {}, '{}', '{}'\
- //, '{}', '{}', '{}', '{}', {}\
- //, {}, {}, '{}', '{}',{}, '{}')",
- // module, dura, analyze_type, strStation, strStationName,
- // IS_NULL(mo), IS_NULL(mo_name), IS_NULL(mp), IS_NULL(mp_name), start_time,
- // end_time, tt, strName, IS_NULL(username), 1, strDuraTime).c_str();
- //if (CDBConnectPool::Instance()->DBExecuteSQL(sql) == FALSE)
- //{
- // ASSERT(FALSE);
- // msg = "语句执行失败:" + sql;
- // CSimpleLog::Error(msg.c_str());
- // code = 500;
- // break;
- //}
- //else
- //{
- // code = 200;
- //}
- code = ExecSqlForRecord((eRecord_Module)module, dura, analyze_type, strStation, strStationName, mo, mo_name, mp, mp_name, start_time, end_time, tt, strName, username, eRocord_Opt::RO_RECORD, string(strDuraTime));
- req_obj = unsafe_yyjson_get_next(req_obj);
- }
- yyjson_mut_obj_add_strcpy(doc, root, "msg", ANSItoUTF8(msg).c_str());
- yyjson_mut_obj_add_int(doc, root, "code", code);
- if (json) *json = yyjson_mut_write(doc, 0, json_len);
- } while (false);
- yyjson_doc_free(req_doc);
- return code;
- }
- int DealGetOptLog(const httplib::Request& req, const string token, char** json, size_t* json_len)
- {
- string station_name = req.get_param_value("station_name");
- string time = req.get_param_value("time");
- string end_time = req.get_param_value("end_time");
- if (time.length() == 0 )
- return 400;
- time_t uTime = atoll(time.c_str());
- time_t uEndTime = atoll(end_time.c_str());
- if (uEndTime == 0) uEndTime = uTime + 86400;
- COleDateTime odt(uTime);
- if (odt.GetStatus() == COleDateTime::invalid)
- return 400;
- string str_station_name = UTF8toANSI(station_name);
- int code = 400;
- string msg;
- auto doc = yyjson_mut_doc_new(nullptr);
- auto root = yyjson_mut_obj(doc);
- yyjson_mut_doc_set_root(doc, root);
- auto yy_data = yyjson_mut_arr(doc);
- auto yy_name = yyjson_mut_arr(doc);
- auto yy_mo = yyjson_mut_arr(doc);
- auto yy_mp = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, root, "data", yy_data);
- yyjson_mut_obj_add_val(doc, root, "name", yy_name);
- yyjson_mut_obj_add_val(doc, root, "mo_name", yy_mo);
- yyjson_mut_obj_add_val(doc, root, "mp_name", yy_mp);
- //query
- //查询数据库
- std::map<string, uint16_t> map_name;
- std::map<string, uint16_t> map_mo_name;
- std::map<string, uint16_t> map_mp_name;
- {
- //station,station_name,
- CString sql;
- if (str_station_name.length() == 0)
- sql = fmt::format("SELECT module,dura,analyze_type, mo, mo_name, mp, mp_name, start_time, end_time, [time], name, username, opt, mark,station_name\
- FROM rm_record WHERE time between {} AND {}",
- uTime, uEndTime).c_str();
- else
- sql = fmt::format("SELECT module,dura,analyze_type, mo, mo_name, mp, mp_name, start_time, end_time, [time], name, username, opt, mark,station_name\
- FROM rm_record WHERE station_name = '{}' AND time between {} AND {}",
- str_station_name, uTime, uEndTime).c_str();
- COdbcStatement stmt;
- if (CDBConnectPool::Instance()->DBQuery(stmt, sql))
- {
- uint8_t umodule, analyze_type;
- int16_t opt = 0;
- int dura;
- char /*station[100], char station_name[100], */mo[50], mo_name[50], mp[50], mp_name[50], name[100], username[50], mark[200], station_name[100];
- uint64_t start_time, end_time, tt;
- int nCol = 1;
- stmt.BindTinyIntCol(nCol++, &umodule);
- stmt.BindIntCol(nCol++, &dura);
- stmt.BindTinyIntCol(nCol++, &analyze_type);
- //stmt.BindCharCol(nCol++, station, sizeof(station));
- //stmt.BindCharCol(nCol++, station_name, sizeof(station_name));
- stmt.BindCharCol(nCol++, mo, sizeof(mo));
- stmt.BindCharCol(nCol++, mo_name, sizeof(mo_name));
- stmt.BindCharCol(nCol++, mp, sizeof(mp));
- stmt.BindCharCol(nCol++, mp_name, sizeof(mp_name));
- stmt.BindBigIntCol(nCol++, (__int64*)&start_time);
- stmt.BindBigIntCol(nCol++, (__int64*)&end_time);
- stmt.BindBigIntCol(nCol++, (__int64*)&tt);
- stmt.BindCharCol(nCol++, name, sizeof(name));
- stmt.BindCharCol(nCol++, username, sizeof(username));
- stmt.BindSmallIntCol(nCol++, &opt);
- stmt.BindCharCol(nCol++, mark, sizeof(mark));
- stmt.BindCharCol(nCol++, station_name, sizeof(station_name));
- do
- {
- //ZeroMemory(station, 100);
- //ZeroMemory(station_name, 100);
- ZeroMemory(mo, 50);
- ZeroMemory(mo_name, 50);
- ZeroMemory(mp, 50);
- ZeroMemory(mp_name, 50);
- ZeroMemory(name, 100);
- ZeroMemory(username, 50);
- ZeroMemory(mark, 200);
- ZeroMemory(station_name, 100);
- if (stmt.FetchNext() != 0)
- break;
- map_name[name]++;
- map_mo_name[mo_name]++;
- map_mp_name[mp_name]++;
- auto o = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(yy_data, o);
- yyjson_mut_obj_add_int(doc, o, "module", umodule);
- yyjson_mut_obj_add_int(doc, o, "opt", opt);
- yyjson_mut_obj_add_int(doc, o, "analyze_type", analyze_type);
- yyjson_mut_obj_add_strcpy(doc, o, "mo_name", mo_name);
- yyjson_mut_obj_add_strcpy(doc, o, "mp_name", mp_name);
- yyjson_mut_obj_add_strcpy(doc, o, "station_name", ANSItoUTF8(station_name).c_str());
- yyjson_mut_obj_add_int(doc, o, "time", tt);
- yyjson_mut_obj_add_strcpy(doc, o, "name", ANSItoUTF8(name).c_str());
- yyjson_mut_obj_add_strcpy(doc, o, "mark", ANSItoUTF8(mark).c_str());
- } while (TRUE);
- }
- stmt.Close();
- }
- for (auto& it : map_name)
- yyjson_mut_arr_add_strcpy(doc, yy_name, ANSItoUTF8(it.first).c_str());
- for (auto& it : map_mo_name)
- yyjson_mut_arr_add_strcpy(doc, yy_mo, it.first.c_str());
- for (auto& it : map_mp_name)
- yyjson_mut_arr_add_strcpy(doc, yy_mp, it.first.c_str());
- code = 200;
- yyjson_mut_obj_add_int(doc, root, "code", code);
- yyjson_mut_obj_add_strcpy(doc, root, "msg", ANSItoUTF8(msg).c_str());
- if (json)
- {
- *json = yyjson_mut_write(doc, 0, json_len);
- /*
- *json = (char*)malloc(1024);
- strcpy_s(*json, 1024, R"({
- "code": 200,
- "msg": "",
- "data": [{
- "mo_name": "21#",
- "mp_name": "J1",
- "name": "张三",
- "opt":1,
- "time": 1693808336,
- "mark": ""
- }, {
- "mo_name": "22#",
- "mp_name": "J1",
- "name": "李四",
- "opt":1,
- "time": 1693808336,
- "mark": ""
- }],
- "name": ["张三", "李四", "王五"],
- "mo_name": ["21#", "22#", "23#"],
- "mp_name": ["J1", "J2", "J3"]
- }
- )");
- */
- }
- yyjson_mut_doc_free(doc);
- return code;
- }
- int ExecSqlForRecord(eRecord_Module module, int dura, uint8_t analyze_type, string& strStation, string& strStationName, const char* mo, const char* mo_name, const char* mp, const char* mp_name,
- uint64_t start_time, uint64_t end_time, time_t tt, string& strName, const char* username, eRocord_Opt opt, string& mark)
- {
- CString sql = fmt::format("INSERT INTO rm_record\
- (module, dura, analyze_type, station\
- , station_name, mo, mo_name, mp, mp_name, start_time\
- , end_time, time, name,username,opt,mark) VALUES\
- ({}, {}, {}, '{}', '{}'\
- , '{}', '{}', '{}', '{}', {}\
- , {}, {}, '{}', '{}',{}, '{}')",
- int(module), dura, analyze_type, strStation, strStationName,
- IS_NULL(mo), IS_NULL(mo_name), IS_NULL(mp), IS_NULL(mp_name), start_time,
- end_time, tt, strName, IS_NULL(username), int(opt), mark).c_str();
- if (CDBConnectPool::Instance()->DBExecuteSQL(sql) == FALSE)
- {
- ASSERT(FALSE);
- CSimpleLog::Error("语句执行失败:" + sql);
- return 500;
- }
- else
- {
- return 200;
- }
- }
- int DealGetrefer_option(const httplib::Request& req, const string token, char** json, size_t* json_len)
- {
- string station = req.get_param_value("station");
- string mo = req.get_param_value("mo");
- string mp = req.get_param_value("mp");
- string str_direct = req.get_param_value("direct");
- if (station.length() == 0 || mo.length() == 0 || mp.length() == 0 || str_direct.length() == 0)
- return 400;
- auto direct = atoi(str_direct.c_str());
- if (direct != 3 && direct != 4)
- return 400;
- string str_station = UTF8toANSI(station);
- if (CSimpleLog::PathFileExistsA(CSimpleLog::GetAppDir() + "refer\\" +
- fmt::format("{}.{}.{}.{}.json", str_station, mo, mp, direct).c_str()))
- return 200;
- else
- return 404;
- }
- //获取参考曲线
- int DealGetrefer_curve(const httplib::Request& req, const string token, char** json, size_t* json_len)
- {
- string station = req.get_param_value("station");
- string mo = req.get_param_value("mo");
- string mp = req.get_param_value("mp");
- string str_direct = req.get_param_value("direct");
- string str_show_time = req.get_param_value("show_time");
- if (station.length() == 0 || mo.length() == 0 || mp.length() == 0 || str_direct.length() == 0 || str_show_time.length() == 0)
- return 400;
- auto direct = atoi(str_direct.c_str());
- if (direct != 3 && direct != 4)
- return 400;
- int yy, mm, dd, hh, MM, SS, micromm;
- auto ret_num = sscanf_s(str_show_time.c_str(), "%d-%d-%d %d:%d:%d.%d", &yy, &mm, &dd, &hh, &MM, &SS, µmm);
- if (ret_num != 7)
- return 400;
- string str_station = UTF8toANSI(station);
- time_t show_time = CTime(yy, mm, dd, hh, MM, SS).GetTime() * 1000 + micromm;
- int code = 400;
- string msg;
- auto doc = yyjson_mut_doc_new(nullptr);
- auto root = yyjson_mut_obj(doc);
- yyjson_mut_doc_set_root(doc, root);
- auto data = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, root, "data", data);
- yyjson_mut_obj_add_strcpy(doc, root, "station", station.c_str());
- yyjson_mut_obj_add_strcpy(doc, root, "mo", mo.c_str());
- yyjson_mut_obj_add_strcpy(doc, root, "mp", mp.c_str());
- yyjson_mut_obj_add_int(doc, root, "direct", direct);
- code = ReadReferFile(str_station, mo, mp, direct, show_time, doc, data, msg);
- yyjson_mut_obj_add_int(doc, root, "code", code);
- yyjson_mut_obj_add_strcpy(doc, root, "msg", ANSItoUTF8(msg).c_str());
- if (json)
- {
- *json = yyjson_mut_write(doc, 0, json_len);
- }
- yyjson_mut_doc_free(doc);
- return code;
- }
- int ReadReferFile(const string& station, const string& mo, const string& mp, uint8_t posi, time_t show_time, yyjson_mut_doc* mut_doc,
- yyjson_mut_val* arr, OUT string& msg)
- {
- string strJsonPath = fmt::format("{}refer\\{}.{}.{}.{}.json", CSimpleLog::GetAppDir(), station, mo, mp, posi);
- if (CSimpleLog::PathFileExistsA(strJsonPath.c_str()) == false)
- {
- msg = fmt::format("未设置参考曲线");
- return 404;
- }
- yyjson_read_err err;
- auto doc = yyjson_read_file(strJsonPath.c_str(), strJsonPath.length(), nullptr, &err);
- if (doc == nullptr)
- {
- msg = err.msg;
- return 500;
- }
- auto root = yyjson_doc_get_root(doc);
- auto t = yyjson_obj_get(root, "t");
- auto d0 = yyjson_obj_get(root, "d0");
- auto d1 = yyjson_obj_get(root, "d1");
- auto d2 = yyjson_obj_get(root, "d2");
- if (yyjson_is_arr(t) == false || yyjson_is_arr(d0) == false || yyjson_is_arr(d1) == false || yyjson_is_arr(d2) == false)
- {
- msg = "参考曲线存储格式错误";
- yyjson_doc_free(doc);
- doc = nullptr;
- return 500;
- }
- auto obj1 = yyjson_mut_obj(mut_doc);
- auto obj2 = yyjson_mut_obj(mut_doc);
- auto obj3 = yyjson_mut_obj(mut_doc);
- yyjson_mut_arr_add_val(arr, obj1);
- yyjson_mut_arr_add_val(arr, obj2);
- yyjson_mut_arr_add_val(arr, obj3);
- auto data1 = yyjson_mut_arr(mut_doc);
- auto data2 = yyjson_mut_arr(mut_doc);
- auto data3 = yyjson_mut_arr(mut_doc);
- yyjson_mut_obj_add_val(mut_doc, obj1, "data", data1);
- yyjson_mut_obj_add_val(mut_doc, obj2, "data", data2);
- yyjson_mut_obj_add_val(mut_doc, obj3, "data", data3);
- yyjson_mut_obj_add_val(mut_doc, obj1, "name", yyjson_val_mut_copy(mut_doc, yyjson_obj_get(root, "name0")));
- yyjson_mut_obj_add_val(mut_doc, obj2, "name", yyjson_val_mut_copy(mut_doc, yyjson_obj_get(root, "name1")));
- yyjson_mut_obj_add_val(mut_doc, obj3, "name", yyjson_val_mut_copy(mut_doc, yyjson_obj_get(root, "name2")));
- int n = yyjson_arr_size(t);
- auto it_t = yyjson_arr_get_first(t);
- auto it_d0 = yyjson_arr_get_first(d0);
- auto it_d1 = yyjson_arr_get_first(d1);
- auto it_d2 = yyjson_arr_get_first(d2);
- for (int i = 0; i < n; i++)
- {
- //按双数组的形式添加
- auto o1 = yyjson_mut_arr(mut_doc);
- yyjson_mut_arr_add_val(data1, o1);
- auto o2 = yyjson_mut_arr(mut_doc);
- yyjson_mut_arr_add_val(data2, o2);
- auto o3 = yyjson_mut_arr(mut_doc);
- yyjson_mut_arr_add_val(data3, o3);
- auto t = yyjson_get_int(it_t) + show_time;
- yyjson_mut_arr_add_int(mut_doc, o1, t);
- yyjson_mut_arr_add_int(mut_doc, o2, t);
- yyjson_mut_arr_add_int(mut_doc, o3, t);
- yyjson_mut_arr_add_int(mut_doc, o1, yyjson_get_int(it_d0));
- yyjson_mut_arr_add_int(mut_doc, o2, yyjson_get_int(it_d1));
- yyjson_mut_arr_add_int(mut_doc, o3, yyjson_get_int(it_d2));
- it_t = unsafe_yyjson_get_next(it_t);
- it_d0 = unsafe_yyjson_get_next(it_d0);
- it_d1 = unsafe_yyjson_get_next(it_d1);
- it_d2 = unsafe_yyjson_get_next(it_d2);
- }
- yyjson_doc_free(doc);
- doc = nullptr;
- msg = "读取成功";
- return 200;
- }
- int deal_get_reminder_interval(const httplib::Request& req, const string token, char** json, size_t* json_len)
- {
- auto doc = yyjson_mut_doc_new(nullptr);
- auto root = yyjson_mut_obj(doc);
- yyjson_mut_doc_set_root(doc, root);
- yyjson_mut_obj_add_int(doc, root, "code", 200);
- yyjson_mut_obj_add_int(doc, root, "interval", g_tReminderInterval);
- *json = yyjson_mut_write(doc, 0, json_len);
- yyjson_mut_doc_free(doc);
- return 200;
- }
- int deal_post_reminder_interval(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len)
- {
- int code = 400;
- string msg;
- auto req_doc = yyjson_read(body_ptr, body_len, 0);
- if (req_doc == nullptr) return 400;
- auto req_root = yyjson_doc_get_root(req_doc);
- do
- {
- auto interval = yyjson_get_int(yyjson_obj_get(req_root, "interval"));
- if (interval == 0) break;
- g_tReminderInterval = interval;
- auto strIniPath = CSimpleLog::GetAppDir() + "DataServices.ini";
- ::WritePrivateProfileString("SET", "reminder_interval", (to_string(g_tReminderInterval) + " #报警提醒间隔").c_str(), strIniPath);
- code = 200;
- } while (false);
- return code;
- }
- string convertWhere(string mo, string mp, string starttime, string endtime, string type, string no,
- string level, string ack_result, string handle_result, string sunroof, string recovery)
- {
- string wh = " ";
- if (!starttime.empty()) {
- wh += fmt::format(" AND occur_time >= '{}'", starttime);
- }
- if (!endtime.empty()) {
- wh += fmt::format(" AND occur_time <= '{}'", endtime);
- }
- if (!mo.empty()) {
- wh += fmt::format(" AND mo = '{}'", mo);
- }
- if (!mp.empty()) {
- wh += fmt::format(" AND mp = '{}'", mp);
- }
- if (!type.empty()) {
- wh += fmt::format(" AND a.type = {}", type);
- }
- if (!no.empty()) {
- wh += fmt::format(" AND no = {}", no);
- }
- if (!level.empty()) {
- wh += fmt::format(" AND level = {}", level);
- }
- if (!ack_result.empty()) {
- wh += fmt::format(" AND ack_result = {}", ack_result);
- }
- if (!handle_result.empty()) {
- wh += fmt::format(" AND handle_result = {}", handle_result);
- }
- if (!sunroof.empty()) {
- if (sunroof.compare("0") == 0)
- wh += " AND [sunroof]=0";
- else if (sunroof.compare("1") == 0)
- wh += " AND [sunroof]=1";
- }
- if (!handle_result.empty()) {
- wh += fmt::format(" AND handle_result = {}", handle_result);
- }
- if (!recovery.empty()) {
- if (recovery.compare("0") == 0)
- wh += " AND [recovery_time] < '1901'";
- else if (recovery.compare("1") == 0)
- wh += " AND [recovery_time] > '1901'";
- }
- wh += " AND rel_id = ''";
- int nPos = wh.find("AND");
- if (nPos != -1)
- wh.replace(nPos, 3, "WHERE");
- return wh;
- }
- int deal_get_alarm_list(const httplib::Request& req, const string token, char** json, size_t* json_len)
- {
- string mo = req.get_param_value("mo");
- string mp = req.get_param_value("mp");
- string starttime = req.get_param_value("starttime");
- string endtime = req.get_param_value("endtime");
- string type = req.get_param_value("type");
- string no = req.get_param_value("no");
- string sort = req.get_param_value("sort");
- string order = req.get_param_value("order");
- string offset = req.get_param_value("offset");
- string limit = req.get_param_value("limit");
- string level = req.get_param_value("level");
- string ack_result = req.get_param_value("ack_result");
- string handle_result = req.get_param_value("handle_result");
- string sunroof = req.get_param_value("sunroof");
- string recovery = req.get_param_value("recovery");
- if (sort.empty()) sort = "occur_time";
- if (order.empty()) order = "desc";
- if (offset.empty()) offset = "0";
- if (limit.empty()) limit = "10";
- auto doc = yyjson_mut_doc_new(nullptr);
- auto root = yyjson_mut_obj(doc);
- yyjson_mut_doc_set_root(doc, root);
- auto rows = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, root, "rows", rows);
- int total = -1;
- int code = 200;
- string msg;
- string wh = convertWhere(mo, mp, starttime, endtime, type, no, level, ack_result, handle_result, sunroof, recovery);
- string or = " ORDER BY " + sort + " " + order + " OFFSET " + offset + " ROWS FETCH NEXT " + limit + " ROWS ONLY ";
- do
- {
- CString sql = ("select count(*) from rm_alarm as a " + wh).c_str();
- COdbcStatement stmt;
- if (!CDBConnectPool::Instance()->DBQuery(stmt, sql))
- {
- msg = fmt::format("语句执行错误:{}", sql);
- code = 500;
- break;
- }
- stmt.BindIntCol(1, &total);
- if (stmt.FetchNext() == 0)
- yyjson_mut_obj_add_int(doc, root, "total", total);
- } while (false);
- std::map<string, yyjson_mut_val*> mapList;
- do
- {
- if (total == -1)
- break;
- CString sql = fmt::format("select a.[id],[mo],[mp],[no],a.[type] ,[occur_time],[level],[desc],[suggest],[val],[referval],"\
- " [ack_result],ISNULL([ack_name], ''),ISNULL([ack_time], 0),[handle_result],ISNULL([handle_name],''),ISNULL([handle_time], 0),ISNULL([handle_info], '') ,b.name,c.id,c.name,"\
- " recovery_time,sunroof,[event_id] from [rm_alarm] as a left join rm_mo as b on b.id = a.mo left join rm_mo as c on b.up = c.id {} {}",
- wh, or ).c_str();
- COdbcStatement stmt;
- if (!CDBConnectPool::Instance()->DBQuery(stmt, sql))
- {
- msg = fmt::format("语句执行错误:{}", sql);
- code = 500;
- break;
- }
- int id, val, refer;
- char smo[20];
- char smp[10];
- char desc[200];
- char suggest[200];
- char ack_name[50];
- char handle_name[50];
- char hanele_info[50];
- char mo_name[20];
- char station_name[50];
- char station_id[50];
- char event_id[37] = { 0 };
- char rel_id[37] = { 0 };
- uint8_t no, utype , level, ack_result, h_result, skylight ;
- TIMESTAMP_STRUCT tsOcccur, tsHandle, tsAck, tsRecovery;
- int nCol = 1;
- stmt.BindIntCol(nCol++, &id);
- stmt.BindCharCol(nCol++, smo, sizeof(smo));
- stmt.BindCharCol(nCol++, smp, sizeof(smp));
- stmt.BindTinyIntCol(nCol++, &no);
- stmt.BindTinyIntCol(nCol++, &utype);
- stmt.BindTimeStampCol(nCol++, &tsOcccur);
- stmt.BindTinyIntCol(nCol++, &level);
- stmt.BindCharCol(nCol++, desc, sizeof(desc));
- stmt.BindCharCol(nCol++, suggest, sizeof(suggest));
- stmt.BindIntCol(nCol++, &val);
- stmt.BindIntCol(nCol++, &refer);
- stmt.BindTinyIntCol(nCol++, &ack_result);
- stmt.BindCharCol(nCol++, ack_name, sizeof(ack_name));
- stmt.BindTimeStampCol(nCol++, &tsAck);
- stmt.BindTinyIntCol(nCol++, &h_result);
- stmt.BindCharCol(nCol++, handle_name, sizeof(handle_name));
- stmt.BindTimeStampCol(nCol++, &tsHandle);
- stmt.BindCharCol(nCol++, hanele_info, sizeof(hanele_info));
- stmt.BindCharCol(nCol++, mo_name, sizeof(mo_name));
- stmt.BindCharCol(nCol++, station_id, sizeof(station_id));
- stmt.BindCharCol(nCol++, station_name, sizeof(station_name));
- stmt.BindTimeStampCol(nCol++, &tsRecovery);
- stmt.BindTinyIntCol(nCol++, &skylight);
- stmt.BindCharCol(nCol++, event_id, sizeof(event_id));
- while (true)
- {
- if (stmt.FetchNext() != 0)
- break;
- auto obj = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(rows, obj);
- auto child = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, obj, "child", child);
- mapList[event_id] = child; //临时记录后面统一添加
- if (ack_name[0])
- yyjson_mut_obj_add_strcpy(doc, obj, "ack_name", ANSItoUTF8(ack_name).c_str());
- else
- yyjson_mut_obj_add_str(doc, obj, "ack_name", "");
- if (tsAck.year != 1900)
- yyjson_mut_obj_add_strcpy(doc, obj, "ack_time", fmt::format("{}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}",
- tsAck.year, tsAck.month, tsAck.day, tsAck.hour, tsAck.minute, tsAck.second).c_str());
- else
- yyjson_mut_obj_add_str(doc, obj, "ack_time", "");
- yyjson_mut_obj_add_int(doc, obj, "ack_result", ack_result);
- if (handle_name[0])
- yyjson_mut_obj_add_strcpy(doc, obj, "handle_name", ANSItoUTF8(handle_name).c_str());
- else
- yyjson_mut_obj_add_str(doc, obj, "handle_name", "");
- if (tsHandle.year != 1900)
- yyjson_mut_obj_add_strcpy(doc, obj, "handle_time", fmt::format("{}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}",
- tsHandle.year, tsHandle.month, tsHandle.day, tsHandle.hour, tsHandle.minute, tsHandle.second).c_str());
- else
- yyjson_mut_obj_add_str(doc, obj, "handle_time", "");
- yyjson_mut_obj_add_int(doc, obj, "handle_result", h_result);
- yyjson_mut_obj_add_int(doc, obj, "id", id);
- yyjson_mut_obj_add_int(doc, obj, "level", level);
- yyjson_mut_obj_add_strcpy(doc, obj, "mo", smo);
- yyjson_mut_obj_add_strcpy(doc, obj, "mo_name", mo_name);
- yyjson_mut_obj_add_strcpy(doc, obj, "mp", smp);
- yyjson_mut_obj_add_int(doc, obj, "no", no);
- yyjson_mut_obj_add_strcpy(doc, obj, "type_name", ANSItoUTF8(GetAlarmName((eZL_ALARMTYPE)utype)).c_str());
- yyjson_mut_obj_add_strcpy(doc, obj, "occur_time", fmt::format("{}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}",
- tsOcccur.year, tsOcccur.month, tsOcccur.day, tsOcccur.hour, tsOcccur.minute, tsOcccur.second).c_str());
- if (tsRecovery.year != 1900)
- yyjson_mut_obj_add_strcpy(doc, obj, "recovery_time", fmt::format("{}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}",
- tsRecovery.year, tsRecovery.month, tsRecovery.day, tsRecovery.hour, tsRecovery.minute, tsRecovery.second).c_str());
- else
- yyjson_mut_obj_add_str(doc, obj, "recovery_time", "");
-
- if (suggest[0])
- yyjson_mut_obj_add_strcpy(doc, obj, "suggest", ANSItoUTF8(suggest).c_str());
- else
- yyjson_mut_obj_add_str(doc, obj, "suggest", "");
- if (desc[0])
- yyjson_mut_obj_add_strcpy(doc, obj, "desc", ANSItoUTF8(desc).c_str());
- else
- yyjson_mut_obj_add_str(doc, obj, "desc", "");
- yyjson_mut_obj_add_int(doc, obj, "sunroof", skylight);
- yyjson_mut_obj_add_int(doc, obj, "type", utype);
- //yyjson_mut_obj_add_strcpy(doc, obj, "type_name", )
- yyjson_mut_obj_add_strcpy(doc, obj, "up", ANSItoUTF8(station_id).c_str());
- yyjson_mut_obj_add_strcpy(doc, obj, "up_name", ANSItoUTF8(station_name).c_str());
- yyjson_mut_obj_add_int(doc, obj, "val", val);
- yyjson_mut_obj_add_int(doc, obj, "referval", refer);
- yyjson_mut_obj_add_strcpy(doc, obj, "event_id", event_id);
- }
- } while (false);
- do
- {
- if (mapList.size() == 0)
- break;
- stringstream ss;
- ss << " where rel_id in (";
- int index = 0;
- for (const auto& it : mapList)
- {
- if (index == 0)
- ss << '\'' << it.first << '\'';
- else
- ss << ",'" << it.first << '\'';
- index++;
- }
- ss << ')';
- CString sql = fmt::format("select a.[id],[mo],[mp],[no],a.[type] ,[occur_time],[level],[desc],[suggest],[val],[referval],"\
- " [ack_result],ISNULL([ack_name], ''),ISNULL([ack_time], 0),[handle_result],ISNULL([handle_name],''),ISNULL([handle_time], 0),ISNULL([handle_info], '') ,b.name,c.id,c.name,"\
- " recovery_time,sunroof,[event_id],[rel_id] from [rm_alarm] as a left join rm_mo as b on b.id = a.mo left join rm_mo as c on b.up = c.id {}",
- ss.str()).c_str();
- COdbcStatement stmt;
- if (!CDBConnectPool::Instance()->DBQuery(stmt, sql))
- {
- msg = fmt::format("语句执行错误:{}", sql);
- code = 500;
- break;
- }
- int id, val, refer;
- char smo[20];
- char smp[10];
- char desc[200];
- char suggest[200];
- char ack_name[50];
- char handle_name[50];
- char hanele_info[50];
- char mo_name[20];
- char station_name[50];
- char station_id[50];
- char event_id[37] = { 0 };
- char rel_id[37] = { 0 };
- uint8_t no, utype, level, ack_result, h_result, skylight;
- TIMESTAMP_STRUCT tsOcccur, tsHandle, tsAck, tsRecovery;
- int nCol = 1;
- stmt.BindIntCol(nCol++, &id);
- stmt.BindCharCol(nCol++, smo, sizeof(smo));
- stmt.BindCharCol(nCol++, smp, sizeof(smp));
- stmt.BindTinyIntCol(nCol++, &no);
- stmt.BindTinyIntCol(nCol++, &utype);
- stmt.BindTimeStampCol(nCol++, &tsOcccur);
- stmt.BindTinyIntCol(nCol++, &level);
- stmt.BindCharCol(nCol++, desc, sizeof(desc));
- stmt.BindCharCol(nCol++, suggest, sizeof(suggest));
- stmt.BindIntCol(nCol++, &val);
- stmt.BindIntCol(nCol++, &refer);
- stmt.BindTinyIntCol(nCol++, &ack_result);
- stmt.BindCharCol(nCol++, ack_name, sizeof(ack_name));
- stmt.BindTimeStampCol(nCol++, &tsAck);
- stmt.BindTinyIntCol(nCol++, &h_result);
- stmt.BindCharCol(nCol++, handle_name, sizeof(handle_name));
- stmt.BindTimeStampCol(nCol++, &tsHandle);
- stmt.BindCharCol(nCol++, hanele_info, sizeof(hanele_info));
- stmt.BindCharCol(nCol++, mo_name, sizeof(mo_name));
- stmt.BindCharCol(nCol++, station_id, sizeof(station_id));
- stmt.BindCharCol(nCol++, station_name, sizeof(station_name));
- stmt.BindTimeStampCol(nCol++, &tsRecovery);
- stmt.BindTinyIntCol(nCol++, &skylight);
- stmt.BindCharCol(nCol++, event_id, sizeof(event_id));
- stmt.BindCharCol(nCol++, rel_id, sizeof(rel_id));
- while (true)
- {
- if (stmt.FetchNext() != 0)
- break;
- auto arr = mapList[rel_id];
- if (arr == nullptr)
- {
- ASSERT(0);
- continue;
- }
- auto obj = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(arr, obj);//添加到原有的child里
- if (ack_name[0])
- yyjson_mut_obj_add_strcpy(doc, obj, "ack_name", ANSItoUTF8(ack_name).c_str());
- else
- yyjson_mut_obj_add_str(doc, obj, "ack_name", "");
- if (tsAck.year != 1900)
- yyjson_mut_obj_add_strcpy(doc, obj, "ack_time", fmt::format("{}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}",
- tsAck.year, tsAck.month, tsAck.day, tsAck.hour, tsAck.minute, tsAck.second).c_str());
- else
- yyjson_mut_obj_add_str(doc, obj, "ack_time", "");
- yyjson_mut_obj_add_int(doc, obj, "ack_result", ack_result);
- if (handle_name[0])
- yyjson_mut_obj_add_strcpy(doc, obj, "handle_name", ANSItoUTF8(handle_name).c_str());
- else
- yyjson_mut_obj_add_str(doc, obj, "handle_name", "");
- if (tsHandle.year != 1900)
- yyjson_mut_obj_add_strcpy(doc, obj, "handle_time", fmt::format("{}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}",
- tsHandle.year, tsHandle.month, tsHandle.day, tsHandle.hour, tsHandle.minute, tsHandle.second).c_str());
- else
- yyjson_mut_obj_add_str(doc, obj, "handle_time", "");
- yyjson_mut_obj_add_int(doc, obj, "handle_result", h_result);
- yyjson_mut_obj_add_int(doc, obj, "id", id);
- yyjson_mut_obj_add_int(doc, obj, "level", level);
- yyjson_mut_obj_add_strcpy(doc, obj, "mo", smo);
- yyjson_mut_obj_add_strcpy(doc, obj, "mo_name", mo_name);
- yyjson_mut_obj_add_strcpy(doc, obj, "mp", smp);
- yyjson_mut_obj_add_int(doc, obj, "no", no);
- yyjson_mut_obj_add_strcpy(doc, obj, "type_name", ANSItoUTF8(GetAlarmName((eZL_ALARMTYPE)utype)).c_str());
- yyjson_mut_obj_add_strcpy(doc, obj, "occur_time", fmt::format("{}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}",
- tsOcccur.year, tsOcccur.month, tsOcccur.day, tsOcccur.hour, tsOcccur.minute, tsOcccur.second).c_str());
- if (tsRecovery.year != 1900)
- yyjson_mut_obj_add_strcpy(doc, obj, "recovery_time", fmt::format("{}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}",
- tsRecovery.year, tsRecovery.month, tsRecovery.day, tsRecovery.hour, tsRecovery.minute, tsRecovery.second).c_str());
- else
- yyjson_mut_obj_add_str(doc, obj, "recovery_time", "");
- if (suggest[0])
- yyjson_mut_obj_add_strcpy(doc, obj, "suggest", ANSItoUTF8(suggest).c_str());
- else
- yyjson_mut_obj_add_str(doc, obj, "suggest", "");
- if (desc[0])
- yyjson_mut_obj_add_strcpy(doc, obj, "desc", ANSItoUTF8(desc).c_str());
- else
- yyjson_mut_obj_add_str(doc, obj, "desc", "");
- yyjson_mut_obj_add_int(doc, obj, "sunroof", skylight);
- yyjson_mut_obj_add_int(doc, obj, "type", utype);
- //yyjson_mut_obj_add_strcpy(doc, obj, "type_name", )
- yyjson_mut_obj_add_strcpy(doc, obj, "up", ANSItoUTF8(station_id).c_str());
- yyjson_mut_obj_add_strcpy(doc, obj, "up_name", ANSItoUTF8(station_name).c_str());
- yyjson_mut_obj_add_int(doc, obj, "val", val);
- yyjson_mut_obj_add_int(doc, obj, "referval", refer);
- yyjson_mut_obj_add_strcpy(doc, obj, "event_id", event_id);
- }
- } while (false);
- yyjson_mut_obj_add_int(doc, root, "code", code);
- yyjson_mut_obj_add_strcpy(doc, root, "msg", ANSItoUTF8(msg).c_str());
- *json = yyjson_mut_write(doc, 0, json_len);
- yyjson_mut_doc_free(doc);
- return code;
- }
- //历史数据新接口 10087端口
- int DealGetResistData(const httplib::Request& req, const string token, char** json, size_t* json_len)
- {
- string mo = req.get_param_value("mo");
- string mp = req.get_param_value("mp");
- string starttime = req.get_param_value("starttime");
- string endtime = req.get_param_value("endtime");
- string threshold = req.get_param_value("threshold");
- int nThreshold = 100;
- if (mo.length() == 0 || mp.length() == 0 || starttime.length() == 0 || endtime.length() == 0)
- return 400;
- if (threshold.empty() == false) nThreshold = atoi(threshold.c_str());
- //if (nThreshold < 30) nThreshold = 30;
- //if (nThreshold > 500) nThreshold = 500;
- COleDateTime odtStart, odtEnd;
- try
- {
- odtStart.ParseDateTime(starttime.c_str());
- odtEnd.ParseDateTime(endtime.c_str());
- }
- catch (CException* )
- {
- return 400;
- }
- auto momp = mo + "." + mp;
- auto pInfo = CMonitorObjectMng::Instance()->GetMoMpInfo(momp);
- if (pInfo == nullptr)
- return 404;
- if (pInfo->pDeivce == nullptr)
- return 404;
- if (odtStart >= odtEnd) return 400;
- char tablename[50] = { 0 };
- auto dtStartDate = COleDateTime(odtStart.GetYear(), odtStart.GetMonth(), odtStart.GetDay(), 0, 0, 0);
- //auto dtEndDate = COleDateTime(odtEnd.GetYear(), odtEnd.GetMonth(), odtEnd.GetDay(), 0, 0, 0);
- auto strStartDate = dtStartDate.Format("%Y-%m-%d %H:%M:%S");
- auto strEndDate = odtEnd.Format("%Y-%m-%d %H:%M:%S");;
- //auto strStartTime = odtStart.Format("%Y-%m-%d %H:%M:%S");
- //auto strEndTime = odtEnd.Format("%Y-%m-%d %H:%M:%S");
- CString sql = "SELECT TOP 100000 * FROM (";
- {
- int num = 0;
- for (auto it = dtStartDate; it < odtEnd;)
- {
- sprintf_s(tablename, 50, "rm_resistance_%04d%02d%02d", it.GetYear(), it.GetMonth(), it.GetDay());
- if (num == 0)
- {
- sql += fmt::format("SELECT [acquisitiontime],[data0],[data1],[data2] "\
- "FROM {} WHERE IMEI = '{}' AND acquisitiontime >= '{}' and acquisitiontime < '{}' AND idx = {} ",
- tablename, pInfo->imei.c_str(), starttime.c_str(), endtime.c_str(), pInfo->idx).c_str();
- }
- else
- {
- sql += fmt::format(" UNION ALL "\
- "SELECT [acquisitiontime],[data0],[data1],[data2] "\
- "FROM {} WHERE IMEI = '{}' AND acquisitiontime >= '{}' and acquisitiontime < '{}' AND idx = {} ",
- tablename, pInfo->imei.c_str(), starttime, endtime, pInfo->idx).c_str();
- }
- num++;
- it += COleDateTimeSpan(1, 0, 0, 0);
- }
- sql += ") AS A ORDER BY acquisitiontime ASC";
- }
- TIMESTAMP_STRUCT ts;
- int sdata0, sdata1, sdata2;
- COdbcStatement stmt;
- if (CDBConnectPool::Instance()->DBQuery(stmt, sql) == FALSE)
- {
- SPDLOG_ERROR("查询语句出错:{}", sql);
- return 500;
- }
- int nCol = 1;
- stmt.BindTimeStampCol(nCol++, &ts);
- stmt.BindIntCol(nCol++, &sdata0);
- stmt.BindIntCol(nCol++, &sdata1);
- stmt.BindIntCol(nCol++, &sdata2);
- int nCount = 0;
- auto doc = yyjson_mut_doc_new(nullptr);
- auto root = yyjson_mut_obj(doc);
- yyjson_mut_doc_set_root(doc, root);
- auto data = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, root, "data", data);
- auto curve_1 = yyjson_mut_obj(doc);
- auto curve_2 = yyjson_mut_obj(doc);
- auto curve_3 = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(data, curve_1);
- yyjson_mut_arr_add_val(data, curve_2);
- yyjson_mut_arr_add_val(data, curve_3);
- yyjson_mut_obj_add_str(doc, root, "cmd", "query_hist");
- yyjson_mut_obj_add_strcpy(doc, root, "tag", (momp + ".resist").c_str());
- yyjson_mut_obj_add_str(doc, root, "data_fmt", "curve");
- yyjson_mut_obj_add_str(doc, root, "unit", "N");
- yyjson_mut_obj_add_str(doc, root, "time", "");
- //1号测力点
- yyjson_mut_obj_add_str(doc, curve_1, "name", pInfo->name1utf.c_str());
- auto points1 = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, curve_1, "points", points1);
- //2号测力点
- yyjson_mut_obj_add_str(doc, curve_2, "name", pInfo->name2utf.c_str());
- auto points2 = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, curve_2, "points", points2);
- //3号测力点
- yyjson_mut_obj_add_str(doc, curve_3, "name", pInfo->name3utf.c_str());
- auto points3 = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, curve_3, "points", points3);
- if (nThreshold == 0)
- {
- do
- {
- if (stmt.FetchNext() != 0)
- break;
- CTime ctTime;
- try
- {
- ctTime = CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
- }
- catch (...)
- {
- continue;
- }
- time_t tm = ctTime.GetTime() * 1000 + ts.fraction / 1000000;
- #ifdef SHOW_DATA
- {
- auto item = yyjson_mut_arr(doc);
- yyjson_mut_arr_add_val(points1, item);
- yyjson_mut_arr_add_uint(doc, item, tm);
- yyjson_mut_arr_add_int(doc, item, sdata0);
- }
- {
- auto item = yyjson_mut_arr(doc);
- yyjson_mut_arr_add_val(points2, item);
- yyjson_mut_arr_add_uint(doc, item, tm);
- yyjson_mut_arr_add_int(doc, item, sdata1);
- }
- {
- auto item = yyjson_mut_arr(doc);
- yyjson_mut_arr_add_val(points3, item);
- yyjson_mut_arr_add_uint(doc, item, tm);
- yyjson_mut_arr_add_int(doc, item, sdata2);
- }
- #endif
- nCount++;
- } while (true);
- }
- else {
- int lastdata0 = INT_MAX, lastdata1 = INT_MAX, lastdata2 = INT_MAX;
- time_t tm = 0;
- do
- {
- if (stmt.FetchNext() != 0)
- {
- if (tm != 0)
- {
- {
- auto item = yyjson_mut_arr(doc);
- yyjson_mut_arr_add_val(points1, item);
- yyjson_mut_arr_add_uint(doc, item, tm);
- yyjson_mut_arr_add_int(doc, item, sdata0);
- }
- {
- auto item = yyjson_mut_arr(doc);
- yyjson_mut_arr_add_val(points2, item);
- yyjson_mut_arr_add_uint(doc, item, tm);
- yyjson_mut_arr_add_int(doc, item, sdata1);
- }
- {
- auto item = yyjson_mut_arr(doc);
- yyjson_mut_arr_add_val(points3, item);
- yyjson_mut_arr_add_uint(doc, item, tm);
- yyjson_mut_arr_add_int(doc, item, sdata2);
- }
- }
- break;
- }
- CTime ctTime;
- try
- {
- ctTime = CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
- }
- catch (...)
- {
- continue;
- }
- tm = ctTime.GetTime() * 1000 + ts.fraction / 1000000;
- #ifdef SHOW_DATA
- if (abs(lastdata0 - sdata0) > nThreshold)
- {
- auto item = yyjson_mut_arr(doc);
- yyjson_mut_arr_add_val(points1, item);
- yyjson_mut_arr_add_uint(doc, item, tm);
- yyjson_mut_arr_add_int(doc, item, sdata0);
- lastdata0 = sdata0;
- }
- if (abs(lastdata1 - sdata1) > nThreshold)
- {
- auto item = yyjson_mut_arr(doc);
- yyjson_mut_arr_add_val(points2, item);
- yyjson_mut_arr_add_uint(doc, item, tm);
- yyjson_mut_arr_add_int(doc, item, sdata1);
- lastdata1 = sdata1;
- }
- if (abs(lastdata2 - sdata2) > nThreshold)
- {
- auto item = yyjson_mut_arr(doc);
- yyjson_mut_arr_add_val(points3, item);
- yyjson_mut_arr_add_uint(doc, item, tm);
- yyjson_mut_arr_add_int(doc, item, sdata2);
- lastdata2 = sdata2;
- }
- #endif
- nCount++;
- } while (true);
- }
- stmt.Close();
- yyjson_mut_obj_add_int(doc, root, "count", nCount);
- if (nCount >= 100000)
- yyjson_mut_obj_add_bool(doc, root, "has_more", true);
- else
- yyjson_mut_obj_add_bool(doc, root, "has_more", false);
- //扳动信息
- auto fix_points = yyjson_mut_arr(doc);
- auto invert_points = yyjson_mut_arr(doc);
- auto convert_points = yyjson_mut_arr(doc);
- if (pInfo->name1.find("定位") != -1)
- {
- yyjson_mut_obj_add_val(doc, curve_1, "mark_points", fix_points);
- yyjson_mut_obj_add_val(doc, curve_2, "mark_points", invert_points);
- }
- else
- {
- yyjson_mut_obj_add_val(doc, curve_1, "mark_points", invert_points);
- yyjson_mut_obj_add_val(doc, curve_2, "mark_points", fix_points);
- }
- yyjson_mut_obj_add_val(doc, curve_3, "mark_points", convert_points);
- auto pConvertLimit = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
- auto pFixSuobi = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_FIX, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
- auto pInvertSuobi = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_INVERT, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
- {
- int num = 0;
- int lastyearmonth = 0;
- for (auto it = dtStartDate; it < odtEnd;)
- {
- int yearmonth = it.GetYear() * 100 + it.GetMonth();
- if (yearmonth != lastyearmonth)
- {
- lastyearmonth = yearmonth;
- sprintf_s(tablename, 50, "rm_move_%04d%02d", it.GetYear(), it.GetMonth());
- if (num == 0)
- {
- sql = fmt::format("SELECT show_time, curr_val, show_val, posi, [type],[sunroof] FROM {} \
- WHERE mo = '{}' AND mp = '{}' AND show_time >= '{}' AND show_time <= '{}' ",
- tablename, mo, mp, starttime, endtime).c_str();
- }
- else
- {
- sql += fmt::format(" UNION ALL "\
- "SELECT show_time, curr_val, show_val, posi, [type],[sunroof] FROM {} \
- WHERE mo = '{}' AND mp = '{}' AND show_time >= '{}' AND show_time <= '{}' ",
- tablename, mo, mp, starttime, endtime).c_str();
- }
- num++;
- }
- it += COleDateTimeSpan(1, 0, 0, 0);
- }
- sql += "order by posi, show_time";
- }
- if (CDBConnectPool::Instance()->DBQuery(stmt, sql))
- {
- TIMESTAMP_STRUCT ts;
- int curr_val;
- int show_val;
- eDaoChaPosi posi;
- ePowerName pn;
- uint8_t sunroof;
- int nCol = 1;
- stmt.BindTimeStampCol(nCol++, &ts);
- stmt.BindIntCol(nCol++, &curr_val);
- stmt.BindIntCol(nCol++, &show_val);
- stmt.BindTinyIntCol(nCol++, (BYTE*)&posi);
- stmt.BindTinyIntCol(nCol++, (BYTE*)&pn);
- stmt.BindTinyIntCol(nCol++, &sunroof);
- do
- {
- if (stmt.FetchNext() != 0)
- break;
- auto obj = yyjson_mut_obj(doc);
- switch (posi)
- {
- case eDaoChaPosi::DCP_FIX:
- {
- if (pn == ePowerName::PN_UNKNOWN || pn == ePowerName::PN_RESIST)
- {
- yyjson_mut_arr_add_val(fix_points, obj);
- auto coord = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, obj, "coord", coord);
- yyjson_mut_arr_add_int(doc, coord, CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second).GetTime() * 1000 + ts.fraction / 1000000);
- yyjson_mut_arr_add_int(doc, coord, curr_val);
- yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
- ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
- yyjson_mut_obj_add_int(doc, obj, "val", show_val);
-
- if (pFixSuobi && pFixSuobi->enable && !sunroof)
- {
- if (pFixSuobi->alarm_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pFixSuobi->alarm_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pFixSuobi->warn_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- else if (pFixSuobi->warn_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str());
- }
- //if (show_val < 500)//TODO
- //{
- // yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- // yyjson_mut_obj_add_str(doc, obj, "label", lock_low.c_str());
- //}
- //else
- //{
- // yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str());
- //}
- }
- break;
- case eDaoChaPosi::DCP_INVERT:
- {
- if (pn == ePowerName::PN_UNKNOWN || pn == ePowerName::PN_RESIST)
- {
- yyjson_mut_arr_add_val(invert_points, obj);
- auto coord = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, obj, "coord", coord);
- yyjson_mut_arr_add_int(doc, coord, CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second).GetTime() * 1000 + ts.fraction / 1000000);
- yyjson_mut_arr_add_int(doc, coord, curr_val);
- yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
- ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
- yyjson_mut_obj_add_int(doc, obj, "val", show_val);
-
- if (pInvertSuobi && pInvertSuobi->enable && !sunroof)
- {
- if (pInvertSuobi->alarm_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pInvertSuobi->alarm_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pInvertSuobi->warn_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- else if (pInvertSuobi->warn_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str());
- }
- //if (show_val < 500)//TODO
- //{
- // yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- // yyjson_mut_obj_add_str(doc, obj, "label", lock_low.c_str());
- //}
- //else
- //{
- // yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str());
- //}
- }
- break;
- case eDaoChaPosi::DCP_FIX2INVERT:
- {
- if (pn == ePowerName::PN_UNKNOWN || pn == ePowerName::PN_MOVE)
- {
- yyjson_mut_arr_add_val(convert_points, obj);
- auto coord = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, obj, "coord", coord);
- yyjson_mut_arr_add_int(doc, coord, CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second).GetTime() * 1000 + ts.fraction / 1000000);
- yyjson_mut_arr_add_int(doc, coord, curr_val);
- yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
- ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
- yyjson_mut_obj_add_int(doc, obj, "val", show_val);
- if (pConvertLimit && pConvertLimit->enable && !sunroof)
- {
- if (pInfo->out_name.find("定扳反") != -1)
- {
- if (pConvertLimit->dw_alarm_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pConvertLimit->dw_warn_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- else
- {
- if (pConvertLimit->up_alarm_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pConvertLimit->up_warn_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- }
- if (curr_val < 0)
- yyjson_mut_obj_add_str(doc, obj, "position", "bottom");
- yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("定扳反:{}", show_val)).c_str());
- }
- }
- break;
- case eDaoChaPosi::DCP_INVERT2FIX:
- {
- if (pn == ePowerName::PN_UNKNOWN || pn == ePowerName::PN_MOVE)
- {
- yyjson_mut_arr_add_val(convert_points, obj);
- auto coord = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, obj, "coord", coord);
- yyjson_mut_arr_add_int(doc, coord, CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second).GetTime() * 1000 + ts.fraction / 1000000);
- yyjson_mut_arr_add_int(doc, coord, curr_val);
- yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
- ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
- yyjson_mut_obj_add_int(doc, obj, "val", show_val);
- if (pConvertLimit && pConvertLimit->enable && !sunroof)
- {
- if (pInfo->out_name.find("反扳定") != -1)
- {
- if (pConvertLimit->dw_alarm_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pConvertLimit->dw_warn_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- else
- {
- if (pConvertLimit->up_alarm_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pConvertLimit->up_warn_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- }
- if (curr_val < 0)
- yyjson_mut_obj_add_str(doc, obj, "position", "bottom");
- yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("反扳定:{}", show_val)).c_str());
- }
- }
- break;
- default:
- ASSERT(FALSE);
- break;
- }
- } while (TRUE);
- }
- stmt.Close();
- //报警线
- auto warn_line = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, root, "warn_line", warn_line);
- MAX_OVER_LIMIT_INFO* pFixMax = nullptr;
- MAX_OVER_LIMIT_INFO* pInvertMax = nullptr;
- MAX_OVER_LIMIT_INFO* pConvertMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::MAX_OVER_LIMIT);
- if (pInfo->name1.find("定位") != -1)
- {
- pFixMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 0, eZL_ALARMTYPE::MAX_OVER_LIMIT);
- pInvertMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 1, eZL_ALARMTYPE::MAX_OVER_LIMIT);
- }
- else
- {
- pFixMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 1, eZL_ALARMTYPE::MAX_OVER_LIMIT);
- pInvertMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 0, eZL_ALARMTYPE::MAX_OVER_LIMIT);
- }
- //定位
- if (pFixMax && pFixMax->enable)
- {
- static string fixnameutf = ANSItoUTF8("定位");
- if (pFixMax->alarm_high_limit != INT_MAX)
- {
- auto object = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(warn_line, object);
- yyjson_mut_obj_add_str(doc, object, "label", fixnameutf.c_str());
- yyjson_mut_obj_add_str(doc, object, "color", "red");
- yyjson_mut_obj_add_int(doc, object, "val", pFixMax->alarm_high_limit);
- }
- if (pFixMax->warn_high_limit != INT_MAX)
- {
- auto object = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(warn_line, object);
- yyjson_mut_obj_add_str(doc, object, "label", fixnameutf.c_str());
- yyjson_mut_obj_add_str(doc, object, "color", "orange");
- yyjson_mut_obj_add_int(doc, object, "val", pFixMax->warn_high_limit);
- }
- }
- if (pInvertMax && pInvertMax->enable)
- {
- static string invertnameutf = ANSItoUTF8("反位");
- if (pInvertMax->alarm_high_limit != INT_MAX)
- {
- auto object = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(warn_line, object);
- yyjson_mut_obj_add_str(doc, object, "label", invertnameutf.c_str());
- yyjson_mut_obj_add_str(doc, object, "color", "red");
- yyjson_mut_obj_add_int(doc, object, "val", pInvertMax->alarm_high_limit);
- }
- if (pInvertMax->warn_high_limit != INT_MAX)
- {
- auto object = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(warn_line, object);
- yyjson_mut_obj_add_str(doc, object, "label", invertnameutf.c_str());
- yyjson_mut_obj_add_str(doc, object, "color", "orange");
- yyjson_mut_obj_add_int(doc, object, "val", pInvertMax->warn_high_limit);
- }
- }
- if (pConvertMax && pConvertMax->enable)
- {
- static string d2fnameutf = ANSItoUTF8("定扳反");
- static string f2dnameutf = ANSItoUTF8("反扳定");
- if (pConvertMax->alarm_high_limit != INT_MAX)
- {
- auto object = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(warn_line, object);
- yyjson_mut_obj_add_str(doc, object, "label", d2fnameutf.c_str());
- yyjson_mut_obj_add_str(doc, object, "color", "red");
- yyjson_mut_obj_add_int(doc, object, "val", pConvertMax->alarm_high_limit);
- }
- if (pConvertMax->warn_high_limit != INT_MAX)
- {
- auto object = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(warn_line, object);
- yyjson_mut_obj_add_str(doc, object, "label", d2fnameutf.c_str());
- yyjson_mut_obj_add_str(doc, object, "color", "orange");
- yyjson_mut_obj_add_int(doc, object, "val", pConvertMax->warn_high_limit);
- }
- if (pConvertMax->f_alarm_high_limit != INT_MAX)
- {
- auto object = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(warn_line, object);
- yyjson_mut_obj_add_str(doc, object, "label", f2dnameutf.c_str());
- yyjson_mut_obj_add_str(doc, object, "color", "red");
- yyjson_mut_obj_add_int(doc, object, "val", pConvertMax->f_alarm_high_limit);
- }
- if (pConvertMax->f_warn_high_limit != INT_MAX)
- {
- auto object = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(warn_line, object);
- yyjson_mut_obj_add_str(doc, object, "label", f2dnameutf.c_str());
- yyjson_mut_obj_add_str(doc, object, "color", "orange");
- yyjson_mut_obj_add_int(doc, object, "val", pConvertMax->f_warn_high_limit);
- }
- }
- *json = yyjson_mut_write(doc, 0, json_len);
- yyjson_mut_doc_free(doc);
- return 200;
- }
- int DealPutChangeZzjno(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len)
- {
- if (token.find("AAAAAAAA") == -1) return 403;
- int code = 400;
- string msg;
- auto req_doc = yyjson_read(body_ptr, body_len, 0);
- if (req_doc == nullptr) return 400;
- auto req_root = yyjson_doc_get_root(req_doc);
- do
- {
- auto mo = yyjson_get_str(yyjson_obj_get(req_root, "mo"));
- auto mp = yyjson_get_str(yyjson_obj_get(req_root, "mp"));
- auto newNumber = yyjson_get_int(yyjson_obj_get(req_root, "newNumber"));
- if (mo == nullptr || mp == nullptr || newNumber == 0) break;
- //新编号已存在
- if (CMonitorObjectMng::Instance()->GetMoMpInfoByZZJno(newNumber))
- {
- code = 400;
- break;
- }
- auto pMoMp = CMonitorObjectMng::Instance()->GetMoMpInfo(string(mo) + "." + mp);
- if (pMoMp == nullptr)
- {
- code = 404;
- break;
- }
- CString sql = fmt::format("update rm_map set zzjno = {} where mo='{}' and mp = '{}';",
- newNumber, mo, mp).c_str();
- if (!CDBConnectPool::Instance()->DBExecuteSQL(sql))
- {
- code = 500;
- break;
- }
- pMoMp->zzjno = newNumber;
- code = 200;
- break;
- } while (false);
- return code;
- }
- //int DealGetRetentionData(const httplib::Request& req, const string token, char** json, size_t* json_len)
- //{
- // string mo = req.get_param_value("mo");
- // string mp = req.get_param_value("mp");
- // string starttime = req.get_param_value("starttime");
- // string endtime = req.get_param_value("endtime");
- // string threshold = req.get_param_value("threshold");
- // int nThreshold = 100;
- // if (mo.length() == 0 || mp.length() == 0 || starttime.length() == 0 || endtime.length() == 0)
- // return 400;
- // if (threshold.empty() == false) nThreshold = atoi(threshold.c_str());
- // if (nThreshold < 30) nThreshold = 30;
- // if (nThreshold > 500) nThreshold = 500;
- // COleDateTime odtStart, odtEnd;
- // try
- // {
- // odtStart.ParseDateTime(starttime.c_str());
- // odtEnd.ParseDateTime(endtime.c_str());
- // }
- // catch (CException*)
- // {
- // return 400;
- // }
- //
- // auto momp = mo + "." + mp;
- // auto pInfo = CMonitorObjectMng::Instance()->GetMoMpInfo(momp);
- // if (pInfo == nullptr)
- // return 404;
- // if (pInfo->pDeivce == nullptr)
- // return 404;
- //
- // if (odtStart >= odtEnd) return 400;
- // char tablename[50] = { 0 };
- // auto dtStartDate = COleDateTime(odtStart.GetYear(), odtStart.GetMonth(), odtStart.GetDay(), 0, 0, 0);
- // auto dtEndDate = COleDateTime(odtEnd.GetYear(), odtEnd.GetMonth(), odtEnd.GetDay(), 0, 0, 0);
- // auto strStartDate = dtStartDate.Format("%Y-%m-%d %H:%M:%S");
- // auto strEndDate = dtEndDate.Format("%Y-%m-%d %H:%M:%S");;
- // //auto strStartTime = odtStart.Format("%Y-%m-%d %H:%M:%S");
- // //auto strEndTime = odtEnd.Format("%Y-%m-%d %H:%M:%S");
- //
- // CString sql = "SELECT TOP 100000 * FROM (";
- // {
- // int num = 0;
- // for (auto it = dtStartDate; it < odtEnd;)
- // {
- // sprintf_s(tablename, 50, "rm_resistance_%04d%02d%02d", it.GetYear(), it.GetMonth(), it.GetDay());
- // if (num == 0)
- // {
- // sql += fmt::format("SELECT [acquisitiontime],[data0],[data1],[data2] "\
- // "FROM {} WHERE IMEI = '{}' AND acquisitiontime >= '{}' and acquisitiontime < '{}' AND idx = {} ",
- // tablename, pInfo->imei.c_str(), starttime.c_str(), endtime.c_str(), pInfo->idx).c_str();
- // }
- // else
- // {
- // sql += fmt::format(" UNION ALL "\
- // "SELECT [acquisitiontime],[data0],[data1],[data2] "\
- // "FROM {} WHERE IMEI = '{}' AND acquisitiontime >= '{}' and acquisitiontime < '{}' AND idx = {} ",
- // tablename, pInfo->imei.c_str(), starttime, endtime, pInfo->idx).c_str();
- // }
- // num++;
- // it += COleDateTimeSpan(1, 0, 0, 0);
- // }
- // sql += ") AS A ORDER BY acquisitiontime ASC";
- // }
- //
- // TIMESTAMP_STRUCT ts;
- // int sdata0, sdata1, sdata2;
- //
- // COdbcStatement stmt;
- //
- // if (CDBConnectPool::Instance()->DBQuery(stmt, sql) == FALSE)
- // {
- // ASSERT(0);
- // SPDLOG_ERROR("查询语句出错:{}", sql);
- // return 500;
- // }
- //
- // int nCol = 1;
- // stmt.BindTimeStampCol(nCol++, &ts);
- // stmt.BindIntCol(nCol++, &sdata0);
- // stmt.BindIntCol(nCol++, &sdata1);
- // stmt.BindIntCol(nCol++, &sdata2);
- // int nCount = 0;
- //
- // auto doc = yyjson_mut_doc_new(nullptr);
- // auto root = yyjson_mut_obj(doc);
- // yyjson_mut_doc_set_root(doc, root);
- // auto data = yyjson_mut_arr(doc);
- // yyjson_mut_obj_add_val(doc, root, "data", data);
- // auto curve_1 = yyjson_mut_obj(doc);
- // auto curve_2 = yyjson_mut_obj(doc);
- // auto curve_3 = yyjson_mut_obj(doc);
- // yyjson_mut_arr_add_val(data, curve_1);
- // yyjson_mut_arr_add_val(data, curve_2);
- // yyjson_mut_arr_add_val(data, curve_3);
- //
- // yyjson_mut_obj_add_str(doc, root, "cmd", "query_hist");
- // yyjson_mut_obj_add_strcpy(doc, root, "tag", (momp + ".resist").c_str());
- // yyjson_mut_obj_add_str(doc, root, "data_fmt", "curve");
- // yyjson_mut_obj_add_str(doc, root, "unit", "N");
- // yyjson_mut_obj_add_str(doc, root, "time", "");
- //
- // //1号测力点
- // yyjson_mut_obj_add_str(doc, curve_1, "name", pInfo->name1utf.c_str());
- // auto points1 = yyjson_mut_arr(doc);
- // yyjson_mut_obj_add_val(doc, curve_1, "points", points1);
- //
- // //2号测力点
- // yyjson_mut_obj_add_str(doc, curve_2, "name", pInfo->name2utf.c_str());
- // auto points2 = yyjson_mut_arr(doc);
- // yyjson_mut_obj_add_val(doc, curve_2, "points", points2);
- //
- // //3号测力点
- // yyjson_mut_obj_add_str(doc, curve_3, "name", pInfo->name3utf.c_str());
- // auto points3 = yyjson_mut_arr(doc);
- // yyjson_mut_obj_add_val(doc, curve_3, "points", points3);
- //
- // if (nThreshold == 0)
- // {
- // do
- // {
- // if (stmt.FetchNext() != 0)
- // break;
- //
- // CTime ctTime;
- // try
- // {
- // ctTime = CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
- // }
- // catch (...)
- // {
- // continue;
- // }
- // time_t tm = ctTime.GetTime() * 1000 + ts.fraction / 1000000;
- //
- //#ifdef SHOW_DATA
- // {
- // auto item = yyjson_mut_arr(doc);
- // yyjson_mut_arr_add_val(points1, item);
- // yyjson_mut_arr_add_uint(doc, item, tm);
- // yyjson_mut_arr_add_int(doc, item, sdata0);
- // }
- // {
- // auto item = yyjson_mut_arr(doc);
- // yyjson_mut_arr_add_val(points2, item);
- // yyjson_mut_arr_add_uint(doc, item, tm);
- // yyjson_mut_arr_add_int(doc, item, sdata1);
- // }
- // {
- // auto item = yyjson_mut_arr(doc);
- // yyjson_mut_arr_add_val(points3, item);
- // yyjson_mut_arr_add_uint(doc, item, tm);
- // yyjson_mut_arr_add_int(doc, item, sdata2);
- // }
- //#endif
- //
- // nCount++;
- //
- // } while (true);
- // }
- // else {
- // int lastdata0 = INT_MAX, lastdata1 = INT_MAX, lastdata2 = INT_MAX;
- // time_t tm = 0;
- // do
- // {
- // if (stmt.FetchNext() != 0)
- // {
- // if (tm != 0)
- // {
- // {
- // auto item = yyjson_mut_arr(doc);
- // yyjson_mut_arr_add_val(points1, item);
- // yyjson_mut_arr_add_uint(doc, item, tm);
- // yyjson_mut_arr_add_int(doc, item, sdata0);
- // }
- // {
- // auto item = yyjson_mut_arr(doc);
- // yyjson_mut_arr_add_val(points2, item);
- // yyjson_mut_arr_add_uint(doc, item, tm);
- // yyjson_mut_arr_add_int(doc, item, sdata1);
- // }
- // {
- // auto item = yyjson_mut_arr(doc);
- // yyjson_mut_arr_add_val(points3, item);
- // yyjson_mut_arr_add_uint(doc, item, tm);
- // yyjson_mut_arr_add_int(doc, item, sdata2);
- // }
- // }
- // break;
- // }
- //
- // CTime ctTime;
- // try
- // {
- // ctTime = CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
- // }
- // catch (...)
- // {
- // continue;
- // }
- // tm = ctTime.GetTime() * 1000 + ts.fraction / 1000000;
- //
- //#ifdef SHOW_DATA
- // if (abs(lastdata0 - sdata0) > nThreshold)
- // {
- // auto item = yyjson_mut_arr(doc);
- // yyjson_mut_arr_add_val(points1, item);
- // yyjson_mut_arr_add_uint(doc, item, tm);
- // yyjson_mut_arr_add_int(doc, item, sdata0);
- // lastdata0 = sdata0;
- // }
- // if (abs(lastdata1 - sdata1) > nThreshold)
- // {
- // auto item = yyjson_mut_arr(doc);
- // yyjson_mut_arr_add_val(points2, item);
- // yyjson_mut_arr_add_uint(doc, item, tm);
- // yyjson_mut_arr_add_int(doc, item, sdata1);
- // lastdata1 = sdata1;
- // }
- // if (abs(lastdata2 - sdata2) > nThreshold)
- // {
- // auto item = yyjson_mut_arr(doc);
- // yyjson_mut_arr_add_val(points3, item);
- // yyjson_mut_arr_add_uint(doc, item, tm);
- // yyjson_mut_arr_add_int(doc, item, sdata2);
- // lastdata2 = sdata2;
- // }
- //#endif
- //
- // nCount++;
- //
- // } while (true);
- // }
- //
- // stmt.Close();
- // yyjson_mut_obj_add_int(doc, root, "count", nCount);
- // if (nCount >= 100000)
- // yyjson_mut_obj_add_bool(doc, root, "has_more", true);
- // else
- // yyjson_mut_obj_add_bool(doc, root, "has_more", false);
- // //扳动信息
- // auto fix_points = yyjson_mut_arr(doc);
- // auto invert_points = yyjson_mut_arr(doc);
- // auto convert_points = yyjson_mut_arr(doc);
- // if (pInfo->name1.find("定位") != -1)
- // {
- // yyjson_mut_obj_add_val(doc, curve_1, "mark_points", fix_points);
- // yyjson_mut_obj_add_val(doc, curve_2, "mark_points", invert_points);
- // }
- // else
- // {
- // yyjson_mut_obj_add_val(doc, curve_1, "mark_points", invert_points);
- // yyjson_mut_obj_add_val(doc, curve_2, "mark_points", fix_points);
- // }
- // yyjson_mut_obj_add_val(doc, curve_3, "mark_points", convert_points);
- //
- // //auto pConvertLimit = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
- // //auto pFixSuobi = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_FIX, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
- // //auto pInvertSuobi = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_INVERT, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
- //
- // {
- // int num = 0;
- // int lastyearmonth = 0;
- // for (auto it = dtStartDate; it <= dtEndDate;)
- // {
- // int yearmonth = it.GetYear() * 100 + it.GetMonth();
- // if (yearmonth != lastyearmonth)
- // {
- // lastyearmonth = yearmonth;
- // sprintf_s(tablename, 50, "rm_move_%04d%02d", it.GetYear(), it.GetMonth());
- // if (num == 0)
- // {
- // sql = fmt::format("SELECT show_time, curr_val, show_val, posiFROM {} \
- // WHERE mo = '{}' AND mp = '{}' AND show_time >= '{}' AND show_time <= '{}' AND [type] = 2 ",
- // tablename, mo, mp, starttime, endtime).c_str();
- // }
- // else
- // {
- // sql += fmt::format(" UNION ALL "\
- // "SELECT show_time, curr_val, show_val, posi FROM {} \
- // WHERE mo = '{}' AND mp = '{}' AND show_time >= '{}' AND show_time <= '{}' AND [type] = 2 ",
- // tablename, mo, mp, starttime, endtime).c_str();
- // }
- // num++;
- // }
- // it += COleDateTimeSpan(1, 0, 0, 0);
- // }
- // sql += "order by posi, show_time";
- // }
- //
- // if (CDBConnectPool::Instance()->DBQuery(stmt, sql))
- // {
- //
- // TIMESTAMP_STRUCT ts;
- // int curr_val;
- // int show_val;
- // eDaoChaPosi posi;
- // ePowerName pn;
- //
- // int nCol = 1;
- // stmt.BindTimeStampCol(nCol++, &ts);
- // stmt.BindIntCol(nCol++, &curr_val);
- // stmt.BindIntCol(nCol++, &show_val);
- // stmt.BindTinyIntCol(nCol++, (BYTE*)&posi);
- // stmt.BindTinyIntCol(nCol++, (BYTE*)&pn);
- //
- // do
- // {
- // if (stmt.FetchNext() != 0)
- // break;
- //
- // auto obj = yyjson_mut_obj(doc);
- //
- // switch (posi)
- // {
- // case eDaoChaPosi::DCP_FIX:
- // {
- // if (pn == ePowerName::PN_RETENTION)
- // {
- // yyjson_mut_arr_add_val(fix_points, obj);
- // auto coord = yyjson_mut_arr(doc);
- // yyjson_mut_obj_add_val(doc, obj, "coord", coord);
- // yyjson_mut_arr_add_int(doc, coord, CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second).GetTime() * 1000 + ts.fraction / 1000000);
- // yyjson_mut_arr_add_int(doc, coord, curr_val);
- // yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
- // ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
- // yyjson_mut_obj_add_int(doc, obj, "val", show_val);
- //
- // //if (pFixSuobi && pFixSuobi->enable)
- // //{
- // // if (pFixSuobi->alarm_low_limit > show_val)
- // // yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- // // else if (pFixSuobi->alarm_high_limit < show_val)
- // // yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- // // else if (pFixSuobi->warn_high_limit < show_val)
- // // yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- // // else if (pFixSuobi->warn_low_limit > show_val)
- // // yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- // //}
- // yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("保持力:{}", show_val)).c_str());
- // }
- // //if (show_val < 500)//TODO
- // //{
- // // yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- // // yyjson_mut_obj_add_str(doc, obj, "label", lock_low.c_str());
- // //}
- // //else
- // //{
- // // yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str());
- // //}
- // }
- // break;
- // case eDaoChaPosi::DCP_INVERT:
- // {
- // if (pn == ePowerName::PN_RETENTION)
- // {
- // yyjson_mut_arr_add_val(invert_points, obj);
- // auto coord = yyjson_mut_arr(doc);
- // yyjson_mut_obj_add_val(doc, obj, "coord", coord);
- // yyjson_mut_arr_add_int(doc, coord, CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second).GetTime() * 1000 + ts.fraction / 1000000);
- // yyjson_mut_arr_add_int(doc, coord, curr_val);
- // yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
- // ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
- // yyjson_mut_obj_add_int(doc, obj, "val", show_val);
- //
- // //if (pInvertSuobi && pInvertSuobi->enable)
- // //{
- // // if (pInvertSuobi->alarm_low_limit > show_val)
- // // yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- // // else if (pInvertSuobi->alarm_high_limit < show_val)
- // // yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- // // else if (pInvertSuobi->warn_high_limit < show_val)
- // // yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- // // else if (pInvertSuobi->warn_low_limit > show_val)
- // // yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- // //}
- // yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("保持力:{}", show_val)).c_str());
- // }
- // //if (show_val < 500)//TODO
- // //{
- // // yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- // // yyjson_mut_obj_add_str(doc, obj, "label", lock_low.c_str());
- // //}
- // //else
- // //{
- // // yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str());
- // //}
- // }
- // break;
- // default:
- // ASSERT(FALSE);
- // break;
- // }
- //
- // } while (TRUE);
- // }
- // stmt.Close();
- //
- // ////报警线
- // //auto warn_line = yyjson_mut_arr(doc);
- // //yyjson_mut_obj_add_val(doc, root, "warn_line", warn_line);
- //
- // //MAX_OVER_LIMIT_INFO* pFixMax = nullptr;
- // //MAX_OVER_LIMIT_INFO* pInvertMax = nullptr;
- // //MAX_OVER_LIMIT_INFO* pConvertMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::MAX_OVER_LIMIT);
- // //if (pInfo->name1.find("定位") != -1)
- // //{
- // // pFixMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 0, eZL_ALARMTYPE::MAX_OVER_LIMIT);
- // // pInvertMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 1, eZL_ALARMTYPE::MAX_OVER_LIMIT);
- // //}
- // //else
- // //{
- // // pFixMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 1, eZL_ALARMTYPE::MAX_OVER_LIMIT);
- // // pInvertMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 0, eZL_ALARMTYPE::MAX_OVER_LIMIT);
- // //}
- // ////定位
- // //if (pFixMax && pFixMax->enable)
- // //{
- // // static string fixnameutf = ANSItoUTF8("定位");
- // // if (pFixMax->alarm_high_limit != INT_MAX)
- // // {
- // // auto object = yyjson_mut_obj(doc);
- // // yyjson_mut_arr_add_val(warn_line, object);
- // // yyjson_mut_obj_add_str(doc, object, "label", fixnameutf.c_str());
- // // yyjson_mut_obj_add_str(doc, object, "color", "red");
- // // yyjson_mut_obj_add_int(doc, object, "val", pFixMax->alarm_high_limit);
- // // }
- // // if (pFixMax->warn_high_limit != INT_MAX)
- // // {
- // // auto object = yyjson_mut_obj(doc);
- // // yyjson_mut_arr_add_val(warn_line, object);
- // // yyjson_mut_obj_add_str(doc, object, "label", fixnameutf.c_str());
- // // yyjson_mut_obj_add_str(doc, object, "color", "orange");
- // // yyjson_mut_obj_add_int(doc, object, "val", pFixMax->warn_high_limit);
- // // }
- // //}
- // //if (pInvertMax && pInvertMax->enable)
- // //{
- // // static string invertnameutf = ANSItoUTF8("反位");
- // // if (pInvertMax->alarm_high_limit != INT_MAX)
- // // {
- // // auto object = yyjson_mut_obj(doc);
- // // yyjson_mut_arr_add_val(warn_line, object);
- // // yyjson_mut_obj_add_str(doc, object, "label", invertnameutf.c_str());
- // // yyjson_mut_obj_add_str(doc, object, "color", "red");
- // // yyjson_mut_obj_add_int(doc, object, "val", pInvertMax->alarm_high_limit);
- // // }
- // // if (pInvertMax->warn_high_limit != INT_MAX)
- // // {
- // // auto object = yyjson_mut_obj(doc);
- // // yyjson_mut_arr_add_val(warn_line, object);
- // // yyjson_mut_obj_add_str(doc, object, "label", invertnameutf.c_str());
- // // yyjson_mut_obj_add_str(doc, object, "color", "orange");
- // // yyjson_mut_obj_add_int(doc, object, "val", pInvertMax->warn_high_limit);
- // // }
- // //}
- // //if (pConvertMax && pConvertMax->enable)
- // //{
- // // static string d2fnameutf = ANSItoUTF8("定扳反");
- // // static string f2dnameutf = ANSItoUTF8("反扳定");
- // // if (pConvertMax->alarm_high_limit != INT_MAX)
- // // {
- // // auto object = yyjson_mut_obj(doc);
- // // yyjson_mut_arr_add_val(warn_line, object);
- // // yyjson_mut_obj_add_str(doc, object, "label", d2fnameutf.c_str());
- // // yyjson_mut_obj_add_str(doc, object, "color", "red");
- // // yyjson_mut_obj_add_int(doc, object, "val", pConvertMax->alarm_high_limit);
- // // }
- // // if (pConvertMax->warn_high_limit != INT_MAX)
- // // {
- // // auto object = yyjson_mut_obj(doc);
- // // yyjson_mut_arr_add_val(warn_line, object);
- // // yyjson_mut_obj_add_str(doc, object, "label", d2fnameutf.c_str());
- // // yyjson_mut_obj_add_str(doc, object, "color", "orange");
- // // yyjson_mut_obj_add_int(doc, object, "val", pConvertMax->warn_high_limit);
- // // }
- // // if (pConvertMax->f_alarm_high_limit != INT_MAX)
- // // {
- // // auto object = yyjson_mut_obj(doc);
- // // yyjson_mut_arr_add_val(warn_line, object);
- // // yyjson_mut_obj_add_str(doc, object, "label", f2dnameutf.c_str());
- // // yyjson_mut_obj_add_str(doc, object, "color", "red");
- // // yyjson_mut_obj_add_int(doc, object, "val", pConvertMax->f_alarm_high_limit);
- // // }
- // // if (pConvertMax->f_warn_high_limit != INT_MAX)
- // // {
- // // auto object = yyjson_mut_obj(doc);
- // // yyjson_mut_arr_add_val(warn_line, object);
- // // yyjson_mut_obj_add_str(doc, object, "label", f2dnameutf.c_str());
- // // yyjson_mut_obj_add_str(doc, object, "color", "orange");
- // // yyjson_mut_obj_add_int(doc, object, "val", pConvertMax->f_warn_high_limit);
- // // }
- // //}
- //
- // *json = yyjson_mut_write(doc, 0, json_len);
- // yyjson_mut_doc_free(doc);
- //
- // return 200;
- //}
- //设置参考曲线
- int DealPostrefer_curve(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len)
- {
- int code = 400;
- string msg;
- auto req_doc = yyjson_read(body_ptr, body_len, 0);
- if (req_doc == nullptr) return 400;
- auto req_root = yyjson_doc_get_root(req_doc);
- auto doc = yyjson_mut_doc_new(nullptr);
- auto root = yyjson_mut_obj(doc);
- yyjson_mut_doc_set_root(doc, root);
- do
- {
- auto station = yyjson_get_str(yyjson_obj_get(req_root, "station"));
- auto mo = yyjson_get_str(yyjson_obj_get(req_root, "mo"));
- auto mp = yyjson_get_str(yyjson_obj_get(req_root, "mp"));
- auto mo_name = yyjson_get_str(yyjson_obj_get(req_root, "mo_name"));
- auto mp_name = yyjson_get_str(yyjson_obj_get(req_root, "mp_name"));
- auto direct = yyjson_get_int(yyjson_obj_get(req_root, "direct"));
- auto show_time = yyjson_get_str(yyjson_obj_get(req_root, "show_time"));
- auto full_name = yyjson_get_str(yyjson_obj_get(req_root, "full_name"));
- if (station == nullptr || show_time == 0 || mo == nullptr || mp == nullptr || (direct != 3 && direct != 4) || full_name == nullptr
- || mo_name == nullptr || mp_name == nullptr)
- {
- msg = "参数错误";
- break;
- }
- auto strStation = UTF8toANSI(station);
- auto strName = UTF8toANSI(full_name);
- time_t tt;
- time(&tt);
- auto len = strlen(show_time);
- if (len == 0) //取消参考曲线
- {
- auto strPath = CSimpleLog::GetAppDir() + "refer\\" +
- fmt::format("{}.{}.{}.{}.json", strStation, mo, mp, direct).c_str();
- if (CSimpleLog::PathFileExistsA(strPath))
- DeleteFile(strPath);
- ExecSqlForRecord(eRecord_Module::RM_REFER, 0, 0, strStation, strStation, mo, mo_name, mp, mp_name, 0, 0, tt, strName, "", eRocord_Opt::RO_CONFIG,
- fmt::format("用户[{}]取消了[{}.{}][{}]的参考曲线", strName, mo_name, mp_name, direct == 3 ? "定扳反" : "反扳定"));
- msg = "操作成功.";
- code = 200;
- break;
- }
- int yy, mm, dd, hh, MM, SS, micromm;
- auto ret_num = sscanf_s(show_time, "%d-%d-%d %d:%d:%d.%d", &yy, &mm, &dd, &hh, &MM, &SS, µmm);
- if (ret_num != 7)
- {
- msg = "show_time参数错误";
- break;
- }
- CString sql = fmt::format("SELECT start_time,end_time,idx FROM rm_move_{:0>4}{:0>2} WHERE mo = '{}' and mp = '{}' and show_time = '{}' and [type] <> 2",
- yy, mm, mo, mp, show_time).c_str();
- COdbcStatement stmt;
- if (CDBConnectPool::Instance()->DBQuery(stmt, sql) == FALSE)
- {
- ASSERT(FALSE);
- msg = "语句执行失败:" + sql;
- code = 500;
- break;
- }
- TIMESTAMP_STRUCT ts = { 0 }, tsEnd = { 0 };
- uint8_t idx = -1;
- stmt.BindTimeStampCol(1, &ts);
- stmt.BindTimeStampCol(2, &tsEnd);
- stmt.BindTinyIntCol(3, &idx);
- if (stmt.FetchNext() != 0)
- {
- msg = "查询转换记录失败";
- code = 500;
- break;
- }
- stmt.Close();
- string imei; int idx_2;
- if (CMonitorObjectMng::Instance()->MOMP2IMEI(string(mo), string(mp), imei, idx_2) == FALSE)
- {
- msg = "查询imei失败";
- code = 500;
- break;
- }
- ASSERT(idx == idx_2);
- CTime ctStart(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
- CTime ctEnd(tsEnd.year, tsEnd.month, tsEnd.day, tsEnd.hour, tsEnd.minute, tsEnd.second);
- sql = fmt::format(" SELECT acquisitiontime,data0,data1,data2 FROM rm_resistance_{:0>4}{:0>2}{:0>2}\
- WHERE IMEI = '{}' AND acquisitiontime between '{}' and '{}' AND idx = {}",
- ts.year, ts.month, ts.day, imei, ctStart.Format("%Y-%m-%d %H:%M:%S"), ctEnd.Format("%Y-%m-%d %H:%M:%S"),idx
- ).c_str();
- int sdata0, sdata1, sdata2;
- if (CDBConnectPool::Instance()->DBQuery(stmt, sql) == FALSE)
- {
- ASSERT(FALSE);
- msg = "语句执行失败:" + sql;
- code = 500;
- break;
- }
- int nCol = 1;
- stmt.BindTimeStampCol(nCol++, &ts);
- stmt.BindIntCol(nCol++, &sdata0);
- stmt.BindIntCol(nCol++, &sdata1);
- stmt.BindIntCol(nCol++, &sdata2);
- int no = 0;
- std::map<time_t, int> data0, data1, data2;
- //time_t tmStart = ctStart.GetTime() * 1000; //存储数据时, 以起始时间为0
- time_t tmShowTime = CTime(yy, mm, dd, hh, MM, SS).GetTime() * 1000 + micromm;
- do
- {
- if (stmt.FetchNext() != 0)
- break;
- no++;
- CTime ctTime;
- try
- {
- ctTime = CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
- }
- catch (...)
- {
- continue;
- }
- time_t tm = ctTime.GetTime() * 1000 + ts.fraction / 1000000 - tmShowTime;
- data0[tm] = sdata0;
- data1[tm] = sdata1;
- data2[tm] = sdata2;
- } while (true);
- stmt.Close();
- if (no == 0)
- {
- msg = "数据为空";
- code = 500;
- break;
- }
- //存储数据
- code = WriteReferFile(strStation, mo, mp, direct, data0, data1, data2, msg);
- ExecSqlForRecord(eRecord_Module::RM_REFER, 0, 0, strStation, strStation, mo, mo_name, mp, mp_name, 0, 0, tt, strName, "", eRocord_Opt::RO_CONFIG,
- fmt::format("用户[{}]设置了[{}.{}][{}]的参考曲线", strName, mo_name, mp_name, direct == 3 ? "定扳反" : "反扳定"));
- } while (false);
- yyjson_mut_obj_add_strcpy(doc, root, "msg", ANSItoUTF8(msg).c_str());
- yyjson_mut_obj_add_int(doc, root, "code", code);
- if (json) *json = yyjson_mut_write(doc, 0, json_len);
- yyjson_doc_free(req_doc);
- yyjson_mut_doc_free(doc);
- return code;
- }
- int WriteReferFile(const string& station, const string& mo, const string& mp, uint8_t posi,
- const std::map<time_t, int>& data0, const std::map<time_t, int>& data1, const std::map<time_t, int>& data2, OUT string& msg)
- {
- string strJsonPath = fmt::format("{}refer\\{}.{}.{}.{}.json", CSimpleLog::GetAppDir(), station, mo, mp, posi);
- string name1, name2, name3, out_name, in_name;
- CMonitorObjectMng::Instance()->GetNameByMoMp(mo + "." + mp, name1, name2, name3, out_name, in_name);
- auto doc = yyjson_mut_doc_new(nullptr);
- auto root = yyjson_mut_obj(doc);
- yyjson_mut_doc_set_root(doc, root);
- yyjson_mut_obj_add_strcpy(doc, root, "station", ANSItoUTF8(station).c_str());
- yyjson_mut_obj_add_strcpy(doc, root, "mo", mo.c_str());
- yyjson_mut_obj_add_strcpy(doc, root, "mp", mp.c_str());
- yyjson_mut_obj_add_int(doc, root, "posi", posi);
- auto t = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, root, "t", t);
- auto d0 = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, root, "d0", d0);
- auto d1 = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, root, "d1", d1);
- auto d2 = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, root, "d2", d2);
- if (name1.find("定位") != -1)
- {
- yyjson_mut_obj_add_strcpy(doc, root, "name0", ANSItoUTF8("定位参考曲线").c_str());
- yyjson_mut_obj_add_strcpy(doc, root, "name1", ANSItoUTF8("反位参考曲线").c_str());
- yyjson_mut_obj_add_strcpy(doc, root, "name2", ANSItoUTF8("转换参考曲线").c_str());
- }
- else
- {
- yyjson_mut_obj_add_strcpy(doc, root, "name0", ANSItoUTF8("反位参考曲线").c_str());
- yyjson_mut_obj_add_strcpy(doc, root, "name1", ANSItoUTF8("定位参考曲线").c_str());
- yyjson_mut_obj_add_strcpy(doc, root, "name2", ANSItoUTF8("转换参考曲线").c_str());
- }
- for (auto& it : data0)
- {
- yyjson_mut_arr_add_int(doc, t, it.first);
- yyjson_mut_arr_add_int(doc, d0, it.second);
- }
- for (auto& it : data1)
- yyjson_mut_arr_add_int(doc, d1, it.second);
- for (auto& it : data2)
- yyjson_mut_arr_add_int(doc, d2, it.second);
- yyjson_write_err err;
- auto ret = yyjson_mut_write_file(strJsonPath.c_str(), doc, 0, nullptr, &err);
- if (ret == false)
- {
- msg = fmt::format("写入文件错误:{} 错误码:{}", strJsonPath, err.msg);
- CSimpleLog::Error(msg.c_str());
- return 500;
- }
- msg = "处理成功.";
- return 200;
- }
- int DealGetResistCurve(const httplib::Request& req, const string token, char** json, size_t* json_len)
- {
- string mo = req.get_param_value("mo");
- string mp = req.get_param_value("mp");
- string time = req.get_param_value("time");
- string name = req.get_param_value("name");
- string end_time = req.get_param_value("end_time");
- string type = req.get_param_value("type");
- if (mo.length() == 0 || mp.length() == 0 || time.length() == 0 || name.length() == 0)
- return 400;
- if (type.compare("1") != 0)
- return 501;//后台未实现
- time_t uTime = atoll(time.c_str());
- COleDateTime odt(uTime);
- COleDateTime odtEnd(odt);
- if (odt.GetStatus() == COleDateTime::invalid)
- return 400;
- if (end_time.empty() == false)
- {
- odtEnd = COleDateTime(atoll(end_time.c_str()));
- if (odtEnd.GetStatus() == COleDateTime::invalid)
- return 400;
- }
- auto doc = yyjson_mut_doc_new(nullptr);
- auto root = yyjson_mut_obj(doc);
- yyjson_mut_doc_set_root(doc, root);
- auto convert_resist = yyjson_mut_obj(doc);
- yyjson_mut_obj_add_val(doc, root, "convert_resist", convert_resist);//转换阻力
- auto suobi_lock = yyjson_mut_obj(doc);
- yyjson_mut_obj_add_val(doc, root, "suobi_lock", suobi_lock);//锁闭力数据
- //auto baochi_lock = yyjson_mut_obj(doc);
- //yyjson_mut_obj_add_val(doc, root, "baochi_lock", baochi_lock);//保持力数据
- yyjson_mut_obj_add_str(doc, root, "name", name.c_str());
- yyjson_mut_obj_add_str(doc, root, "unit", "N");
- yyjson_mut_obj_add_uint(doc, root, "time", uTime);
- //title
- yyjson_mut_obj_add_strcpy(doc, convert_resist, "title", ANSItoUTF8("转换阻力峰值统计图").c_str());
- yyjson_mut_obj_add_strcpy(doc, suobi_lock, "title", ANSItoUTF8("定反位锁闭力值统计图").c_str());
- //yyjson_mut_obj_add_strcpy(doc, baochi_lock, "title", ANSItoUTF8("定反位保持力值统计图").c_str());
- //curve_data and line
- auto convert_curve_data = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, convert_resist, "curve_data", convert_curve_data);
- auto suobi_curve_data = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, suobi_lock, "curve_data", suobi_curve_data);
- //auto baochi_curve_data = yyjson_mut_arr(doc);
- //yyjson_mut_obj_add_val(doc, baochi_lock, "curve_data", baochi_curve_data);
- auto convert_line = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, convert_resist, "line", convert_line);
- auto suobi_line = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, suobi_lock, "line", suobi_line);
- //auto baochi_line = yyjson_mut_arr(doc);
- //yyjson_mut_obj_add_val(doc, baochi_lock, "line", baochi_line);
- //curve_obj
- auto d_convert_obj = yyjson_mut_obj(doc);
- yyjson_mut_obj_add_strcpy(doc, d_convert_obj, "name", ANSItoUTF8("定扳反转换阻力峰值").c_str());
- yyjson_mut_obj_add_str(doc, d_convert_obj, "color", "#a8ff78");// 苹果绿
- yyjson_mut_arr_add_val(convert_curve_data, d_convert_obj);
- auto f_convert_obj = yyjson_mut_obj(doc);
- yyjson_mut_obj_add_strcpy(doc, f_convert_obj, "name", ANSItoUTF8("反扳定转换阻力峰值").c_str());
- yyjson_mut_obj_add_str(doc, f_convert_obj, "color", "#FFE000");// 芒果黄
- yyjson_mut_arr_add_val(convert_curve_data, f_convert_obj);
- auto d_suobi_obj = yyjson_mut_obj(doc);
- yyjson_mut_obj_add_strcpy(doc, d_suobi_obj, "name", ANSItoUTF8("定位锁闭力值").c_str());
- yyjson_mut_obj_add_str(doc, d_suobi_obj, "color", "#a8ff78");// 苹果绿
- yyjson_mut_arr_add_val(suobi_curve_data, d_suobi_obj);
- auto f_suobi_obj = yyjson_mut_obj(doc);
- yyjson_mut_obj_add_strcpy(doc, f_suobi_obj, "name", ANSItoUTF8("反位锁闭力值").c_str());
- yyjson_mut_obj_add_str(doc, f_suobi_obj, "color", "#FFE000");// 芒果黄
- yyjson_mut_arr_add_val(suobi_curve_data, f_suobi_obj);
- //auto d_baochi_obj = yyjson_mut_obj(doc);
- //yyjson_mut_obj_add_strcpy(doc, d_baochi_obj, "name", ANSItoUTF8("定位保持力值").c_str());
- //yyjson_mut_obj_add_str(doc, d_baochi_obj, "color", "#a8ff78");// 苹果绿
- //yyjson_mut_arr_add_val(baochi_curve_data, d_baochi_obj);
- //auto f_baochi_obj = yyjson_mut_obj(doc);
- //yyjson_mut_obj_add_strcpy(doc, f_baochi_obj, "name", ANSItoUTF8("反位保持力值").c_str());
- //yyjson_mut_obj_add_str(doc, f_baochi_obj, "color", "#FFE000");// 芒果黄
- //yyjson_mut_arr_add_val(baochi_curve_data, f_baochi_obj);
- //curve_data
- auto d_convert_data = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, d_convert_obj, "data", d_convert_data);
- auto f_convert_data = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, f_convert_obj, "data", f_convert_data);
- auto d_suobi_data = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, d_suobi_obj, "data", d_suobi_data);
- auto f_suobi_data = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, f_suobi_obj, "data", f_suobi_data);
- //auto d_baochi_data = yyjson_mut_arr(doc);
- //yyjson_mut_obj_add_val(doc, d_baochi_obj, "data", d_baochi_data);
- //auto f_baochi_data = yyjson_mut_arr(doc);
- //yyjson_mut_obj_add_val(doc, f_baochi_obj, "data", f_baochi_data);
- //query
- //TODO 查询数据库 填充 d_convert_data f_convert_data d_suobi_data f_suobi_data
- {
- string table_name = fmt::format("rm_move_{:0>4}{:0>2}", odt.GetYear(), odt.GetMonth());
- CString sql;
- if (odt.GetMonth() == odtEnd.GetMonth())
- {
- sql = fmt::format("SELECT show_time,show_val,posi,[type],[sunroof] FROM {} WHERE mo = '{}' AND mp = '{}' AND show_time >= '{}' AND show_time <= '{}'",
- table_name, mo, mp, odt.Format("%Y-%m-%d 00:00:00"), odtEnd.Format("%Y-%m-%d 23:59:59.999")).c_str();
- }
- else
- {
- string table_name_next = fmt::format("rm_move_{:0>4}{:0>2}", odtEnd.GetYear(), odtEnd.GetMonth());
- sql = fmt::format("SELECT show_time,show_val,posi,[type],[sunroof] FROM {0} WHERE mo = '{1}' AND mp = '{2}' AND show_time >= '{3}' \
- UNION SELECT show_time, show_val, posi,[type] FROM {4} WHERE mo = '{1}' AND mp = '{2}' AND show_time <= '{5}'",
- table_name, mo, mp, odt.Format("%Y-%m-%d 00:00:00"), table_name_next, odtEnd.Format("%Y-%m-%d 23:59:59.999")).c_str();
- }
- COdbcStatement stmt;
- if (CDBConnectPool::Instance()->DBQuery(stmt, sql))
- {
- int nCol = 1;
- TIMESTAMP_STRUCT ts;
- int show_val;
- eDaoChaPosi posi;
- ePowerName pn;
- stmt.BindTimeStampCol(nCol++, &ts);
- stmt.BindIntCol(nCol++, &show_val);
- stmt.BindTinyIntCol(nCol++, (BYTE*)&posi);
- stmt.BindTinyIntCol(nCol++, (BYTE*)&pn);
- do
- {
- if (stmt.FetchNext() != 0)
- break;
- CTime ctTime;
- try
- {
- ctTime = CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
- }
- catch (...)
- {
- continue;
- }
- time_t tt = ctTime.GetTime() * 1000 + ts.fraction / 1000000;
- auto o = yyjson_mut_arr(doc);
- yyjson_mut_arr_add_int(doc, o, tt);
- yyjson_mut_arr_add_int(doc, o, show_val);
- switch (posi)
- {
- case eDaoChaPosi::DCP_FIX:
- if (pn == ePowerName::PN_RETENTION)
- {
- //yyjson_mut_arr_add_val(d_baochi_data, o);
- }
- else
- {
- yyjson_mut_arr_add_val(d_suobi_data, o);
- }
- break;
- case eDaoChaPosi::DCP_INVERT:
- if (pn == ePowerName::PN_RETENTION)
- {
- //yyjson_mut_arr_add_val(f_baochi_data, o);
- }
- else
- {
- yyjson_mut_arr_add_val(f_suobi_data, o);
- }
- break;
- case eDaoChaPosi::DCP_FIX2INVERT:
- yyjson_mut_arr_add_val(d_convert_data, o);
- break;
- case eDaoChaPosi::DCP_INVERT2FIX:
- yyjson_mut_arr_add_val(f_convert_data, o);
- break;
- default:
- ASSERT(FALSE);
- break;
- }
- } while (TRUE);
- }
- stmt.Close();
- }
- //line
- {
- //转换阻力报警线
- CONVERT_RESIST_OVER_LIMIT* pInfo = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
- if (pInfo && pInfo->enable)
- {
- if (pInfo->dw_warn_low_limit > INT_MIN)
- {
- auto obj = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(convert_line, obj);
- yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("预警线").c_str());
- yyjson_mut_obj_add_int(doc, obj, "value", pInfo->dw_warn_low_limit);
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- if (pInfo->up_warn_high_limit < INT_MAX)
- {
- auto obj = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(convert_line, obj);
- yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("预警线").c_str());
- yyjson_mut_obj_add_int(doc, obj, "value", pInfo->up_warn_high_limit);
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- if (pInfo->dw_alarm_low_limit > INT_MIN)
- {
- auto obj = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(convert_line, obj);
- yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("告警线").c_str());
- yyjson_mut_obj_add_int(doc, obj, "value", pInfo->dw_alarm_low_limit);
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- }
- if (pInfo->up_alarm_high_limit < INT_MAX)
- {
- auto obj = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(convert_line, obj);
- yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("告警线").c_str());
- yyjson_mut_obj_add_int(doc, obj, "value", pInfo->up_alarm_high_limit);
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- }
- }
- }
- {
- //锁闭力报警线
- SUOBI_OVER_LIMIT_INFO* pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, -1, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
- if (pInfo && pInfo->enable)
- {
- if (pInfo->warn_low_limit > INT_MIN)
- {
- auto obj = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(suobi_line, obj);
- yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("预警线").c_str());
- yyjson_mut_obj_add_int(doc, obj, "value", pInfo->warn_low_limit);
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- if (pInfo->warn_high_limit < INT_MAX)
- {
- auto obj = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(suobi_line, obj);
- yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("预警线").c_str());
- yyjson_mut_obj_add_int(doc, obj, "value", pInfo->warn_high_limit);
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- if (pInfo->alarm_low_limit > INT_MIN)
- {
- auto obj = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(suobi_line, obj);
- yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("告警线").c_str());
- yyjson_mut_obj_add_int(doc, obj, "value", pInfo->alarm_low_limit);
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- }
- if (pInfo->alarm_high_limit < INT_MAX)
- {
- auto obj = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(suobi_line, obj);
- yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("告警线").c_str());
- yyjson_mut_obj_add_int(doc, obj, "value", pInfo->alarm_high_limit);
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- }
- }
- }
- {
- //定位锁闭力报警线
- SUOBI_OVER_LIMIT_INFO* pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_FIX, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
- if (pInfo && pInfo->enable)
- {
- if (pInfo->warn_low_limit > INT_MIN)
- {
- auto obj = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(suobi_line, obj);
- yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("定位预警线").c_str());
- yyjson_mut_obj_add_int(doc, obj, "value", pInfo->warn_low_limit);
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- if (pInfo->warn_high_limit < INT_MAX)
- {
- auto obj = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(suobi_line, obj);
- yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("定位预警线").c_str());
- yyjson_mut_obj_add_int(doc, obj, "value", pInfo->warn_high_limit);
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- if (pInfo->alarm_low_limit > INT_MIN)
- {
- auto obj = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(suobi_line, obj);
- yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("定位告警线").c_str());
- yyjson_mut_obj_add_int(doc, obj, "value", pInfo->alarm_low_limit);
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- }
- if (pInfo->alarm_high_limit < INT_MAX)
- {
- auto obj = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(suobi_line, obj);
- yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("定位告警线").c_str());
- yyjson_mut_obj_add_int(doc, obj, "value", pInfo->alarm_high_limit);
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- }
- }
- }
- {
- //反位锁闭力报警线
- SUOBI_OVER_LIMIT_INFO* pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_INVERT, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
- if (pInfo && pInfo->enable)
- {
- if (pInfo->warn_low_limit > INT_MIN)
- {
- auto obj = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(suobi_line, obj);
- yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("反位预警线").c_str());
- yyjson_mut_obj_add_int(doc, obj, "value", pInfo->warn_low_limit);
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- if (pInfo->warn_high_limit < INT_MAX)
- {
- auto obj = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(suobi_line, obj);
- yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("反位预警线").c_str());
- yyjson_mut_obj_add_int(doc, obj, "value", pInfo->warn_high_limit);
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- if (pInfo->alarm_low_limit > INT_MIN)
- {
- auto obj = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(suobi_line, obj);
- yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("反位告警线").c_str());
- yyjson_mut_obj_add_int(doc, obj, "value", pInfo->alarm_low_limit);
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- }
- if (pInfo->alarm_high_limit < INT_MAX)
- {
- auto obj = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(suobi_line, obj);
- yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("反位告警线").c_str());
- yyjson_mut_obj_add_int(doc, obj, "value", pInfo->alarm_high_limit);
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- }
- }
- }
- *json = yyjson_mut_write(doc, 0, json_len);
- yyjson_mut_doc_free(doc);
- return 200;
- }
- int DealGetRetentionCurve(const httplib::Request& req, const string token, char** json, size_t* json_len)
- {
- string mo = req.get_param_value("mo");
- string mp = req.get_param_value("mp");
- string time = req.get_param_value("time");
- string name = req.get_param_value("name");
- string end_time = req.get_param_value("end_time");
- string type = req.get_param_value("type");
- if (mo.length() == 0 || mp.length() == 0 || time.length() == 0 || name.length() == 0)
- return 400;
- if (type.compare("1") != 0)
- return 501;//后台未实现
- time_t uTime = atoll(time.c_str());
- COleDateTime odt(uTime);
- COleDateTime odtEnd(odt);
- if (odt.GetStatus() == COleDateTime::invalid)
- return 400;
- if (end_time.empty() == false)
- {
- odtEnd = COleDateTime(atoll(end_time.c_str()));
- if (odtEnd.GetStatus() == COleDateTime::invalid)
- return 400;
- }
- auto doc = yyjson_mut_doc_new(nullptr);
- auto root = yyjson_mut_obj(doc);
- yyjson_mut_doc_set_root(doc, root);
- auto data = yyjson_mut_obj(doc);
- yyjson_mut_obj_add_val(doc, root, "data", data);//转换阻力
- yyjson_mut_obj_add_str(doc, root, "name", name.c_str());
- yyjson_mut_obj_add_str(doc, root, "unit", "N");
- yyjson_mut_obj_add_uint(doc, root, "time", uTime);
- //title
- yyjson_mut_obj_add_strcpy(doc, data, "title", ANSItoUTF8("保持力趋势图").c_str());
- //curve_data and line
- auto baochi_curve_data = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, data, "curve_data", baochi_curve_data);
- auto baochi_line = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, data, "line", baochi_line);
- //curve_obj
- auto d_baochi_obj = yyjson_mut_obj(doc);
- yyjson_mut_obj_add_strcpy(doc, d_baochi_obj, "name", ANSItoUTF8("定位保持力").c_str());
- yyjson_mut_obj_add_str(doc, d_baochi_obj, "color", "#a8ff78");// 苹果绿
- yyjson_mut_arr_add_val(baochi_curve_data, d_baochi_obj);
- auto f_baochi_obj = yyjson_mut_obj(doc);
- yyjson_mut_obj_add_strcpy(doc, f_baochi_obj, "name", ANSItoUTF8("反位保持力").c_str());
- yyjson_mut_obj_add_str(doc, f_baochi_obj, "color", "#FFE000");// 芒果黄
- yyjson_mut_arr_add_val(baochi_curve_data, f_baochi_obj);
- //curve_data
- auto d_baochi_data = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, d_baochi_obj, "data", d_baochi_data);
- auto f_baochi_data = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, f_baochi_obj, "data", f_baochi_data);
- //query
- //TODO 查询数据库 填充 d_convert_data f_convert_data d_baochi_data f_baochi_data
- {
- string table_name = fmt::format("rm_move_{:0>4}{:0>2}", odt.GetYear(), odt.GetMonth());
- CString sql;
- if (odt.GetMonth() == odtEnd.GetMonth())
- {
- sql = fmt::format("SELECT show_time,show_val,posi FROM {} WHERE [type] = 2 AND mo = '{}' AND mp = '{}' AND show_time >= '{}' AND show_time <= '{}'",
- table_name, mo, mp, odt.Format("%Y-%m-%d 00:00:00"), odtEnd.Format("%Y-%m-%d 23:59:59.999")).c_str();
- }
- else
- {
- string table_name_next = fmt::format("rm_move_{:0>4}{:0>2}", odtEnd.GetYear(), odtEnd.GetMonth());
- sql = fmt::format("SELECT show_time,show_val,posi FROM {0} WHERE [type] = 2 AND mo = '{1}' AND mp = '{2}' AND show_time >= '{3}' \
- UNION SELECT show_time, show_val, posi FROM {4} WHERE [type] = 2 AND mo = '{1}' AND mp = '{2}' AND show_time <= '{5}'",
- table_name, mo, mp, odt.Format("%Y-%m-%d 00:00:00"), table_name_next, odtEnd.Format("%Y-%m-%d 23:59:59.999")).c_str();
- }
- COdbcStatement stmt;
- if (CDBConnectPool::Instance()->DBQuery(stmt, sql))
- {
- int nCol = 1;
- TIMESTAMP_STRUCT ts;
- int show_val;
- eDaoChaPosi posi;
- ePowerName pn;
- stmt.BindTimeStampCol(nCol++, &ts);
- stmt.BindIntCol(nCol++, &show_val);
- stmt.BindTinyIntCol(nCol++, (BYTE*)&posi);
- stmt.BindTinyIntCol(nCol++, (BYTE*)&pn);
- do
- {
- if (stmt.FetchNext() != 0)
- break;
- CTime ctTime;
- try
- {
- ctTime = CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
- }
- catch (...)
- {
- continue;
- }
- time_t tt = ctTime.GetTime() * 1000 + ts.fraction / 1000000;
- auto o = yyjson_mut_arr(doc);
- yyjson_mut_arr_add_int(doc, o, tt);
- yyjson_mut_arr_add_int(doc, o, show_val);
- switch (posi)
- {
- case eDaoChaPosi::DCP_FIX:
- yyjson_mut_arr_add_val(d_baochi_data, o);
- break;
- case eDaoChaPosi::DCP_INVERT:
- yyjson_mut_arr_add_val(f_baochi_data, o);
- break;
- default:
- ASSERT(FALSE);
- break;
- }
- } while (TRUE);
- }
- stmt.Close();
- }
- //line
- {
- //定位告警线
- RETENSION_FORCE_DROP* pInfo = (RETENSION_FORCE_DROP*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_FIX, eZL_ALARMTYPE::RETENSION_FORCE);
- if (pInfo && pInfo->enable)
- {
- if (pInfo->dw_alarm_low_drop > INT_MIN)
- {
- auto obj = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(baochi_line, obj);
- yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("定位告警线").c_str());
- yyjson_mut_obj_add_int(doc, obj, "value", pInfo->dw_alarm_low_drop);
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- }
- }
- }
- {
- //反位告警线
- RETENSION_FORCE_DROP* pInfo = (RETENSION_FORCE_DROP*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_INVERT, eZL_ALARMTYPE::RETENSION_FORCE);
- if (pInfo && pInfo->enable)
- {
- if (pInfo->dw_alarm_low_drop > INT_MIN)
- {
- auto obj = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(baochi_line, obj);
- yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("反位告警线").c_str());
- yyjson_mut_obj_add_int(doc, obj, "value", pInfo->dw_alarm_low_drop);
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- }
- }
- }
- *json = yyjson_mut_write(doc, 0, json_len);
- yyjson_mut_doc_free(doc);
- return 200;
- }
- int DealGetRetentionReport(const httplib::Request& req, const string token, char** json, size_t* json_len)
- {
- string station = req.get_param_value("station");
- string time = req.get_param_value("time");
- if (time.length() == 0 || station.length() == 0)
- return 400;
- time_t uTime = atoll(time.c_str());
- COleDateTime odt(uTime);
- if (odt.GetStatus() == COleDateTime::invalid)
- return 400;
- auto doc = yyjson_mut_doc_new(nullptr);
- auto root = yyjson_mut_arr(doc);
- yyjson_mut_doc_set_root(doc, root);
- {
- string strStation = UTF8toANSI(station);
- string table_name = fmt::format("rm_move_{:0>4}{:0>2}", odt.GetYear(), odt.GetMonth());
- CString sql = fmt::format("SELECT A.*,B.name FROM (SELECT mo, mp, posi, count(*) as num, max(show_val) as l, min(show_val) as s, sum(show_val) as sum FROM {} WHERE [type] = 2 AND mo in (SELECT id FROM rm_mo WHERE up = '{}') AND show_time >= '{}' AND show_time <= '{}' GROUP BY mo, mp, posi) AS A \
- LEFT JOIN rm_mo AS B ON A.mo = B.id",
- table_name, strStation, odt.Format("%Y-%m-%d 00:00:00"), odt.Format("%Y-%m-%d 23:59:59.999")).c_str();
- //SELECT A.*,B.name FROM (SELECT mo, mp, posi, count(*) as num, max(show_val) as l, min(show_val) as s FROM rm_move_202301 WHERE mo in (SELECT id FROM rm_mo WHERE up = '温州南站') AND show_time >= '2023-01-10 00:00:00' AND show_time <= '2023-01-10 23:59:59.999' GROUP BY mo, mp, posi) AS A LEFT JOIN rm_mo AS B ON A.mo = B.id
- COdbcStatement stmt;
- struct tagData
- {
- string mo_name;
- string mo;
- string mp;
- int d_baochi_lock = INT_MAX;
- int d_baochi_lock_max = INT_MAX;
- int d_baochi_lock_min = INT_MAX;
- int d_baochi_lock_avg = INT_MAX;
- int f_baochi_lock = INT_MAX;
- int f_baochi_lock_max = INT_MAX;
- int f_baochi_lock_min = INT_MAX;
- int f_baochi_lock_avg = INT_MAX;
- };
- std::map<string, tagData> mapData;
- if (CDBConnectPool::Instance()->DBQuery(stmt, sql))
- {
- int nCol = 1;
- char mo[50], mp[50], mo_name[50];
- int num;
- int max;
- int min;
- int64_t sum;
- eDaoChaPosi posi;
- ePowerName pn;
- stmt.BindCharCol(nCol++, mo, sizeof(mo));
- stmt.BindCharCol(nCol++, mp, sizeof(mp));
- stmt.BindTinyIntCol(nCol++, (BYTE*)&posi);
- stmt.BindIntCol(nCol++, &num);
- stmt.BindIntCol(nCol++, &max);
- stmt.BindIntCol(nCol++, &min);
- stmt.BindBigIntCol(nCol++, &sum);
- stmt.BindTinyIntCol(nCol++, (BYTE*)&pn);
- stmt.BindCharCol(nCol++, mo_name, sizeof(mo_name));
- do
- {
- if (stmt.FetchNext() != 0)
- break;
- SUOBI_OVER_LIMIT_INFO* pInfo = nullptr;
- CONVERT_RESIST_OVER_LIMIT* pInfo2 = nullptr;
- auto& it = mapData[fmt::format("{}.{}", mo, mp)];
- it.mo_name = mo_name;
- it.mo = mo;
- it.mp = mp;
- eSuoBiPosi idx;
- switch (posi)
- {
- case eDaoChaPosi::DCP_FIX:
- it.d_baochi_lock = num;
- it.d_baochi_lock_max = max;
- it.d_baochi_lock_min = min;
- if (num) it.d_baochi_lock_avg = sum / num;
- break;
- case eDaoChaPosi::DCP_INVERT:
- it.f_baochi_lock = num;
- it.f_baochi_lock_max = max;
- it.f_baochi_lock_min = min;
- if (num) it.f_baochi_lock_avg = sum / num;
- break;
- default:
- ASSERT(FALSE);
- break;
- }
- } while (TRUE);
- }
- stmt.Close();
- for (auto& it : mapData)
- {
- auto obj = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(root, obj);
- yyjson_mut_obj_add_strcpy(doc, obj, "mo_name", ANSItoUTF8(it.second.mo_name).c_str());
- yyjson_mut_obj_add_strcpy(doc, obj, "mo", it.second.mo.c_str());
- yyjson_mut_obj_add_strcpy(doc, obj, "mp", it.second.mp.c_str());
-
- if (it.second.d_baochi_lock != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "d_retention_fore", it.second.d_baochi_lock);
- else
- yyjson_mut_obj_add_str(doc, obj, "d_retention_fore", "-");
- if (it.second.d_baochi_lock_max != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "d_retention_fore_max", it.second.d_baochi_lock_max);
- else
- yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_max", "-");
- if (it.second.d_baochi_lock_min != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "d_retention_fore_min", it.second.d_baochi_lock_min);
- else
- yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_min", "-");
- if (it.second.d_baochi_lock_avg != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "d_retention_fore_avg", it.second.d_baochi_lock_avg);
- else
- yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_avg", "-");
- if (it.second.f_baochi_lock != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "f_retention_fore", it.second.f_baochi_lock);
- else
- yyjson_mut_obj_add_str(doc, obj, "f_retention_fore", "-");
- if (it.second.f_baochi_lock_max != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "f_retention_fore_max", it.second.f_baochi_lock_max);
- else
- yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_max", "-");
- if (it.second.f_baochi_lock_min != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "f_retention_fore_min", it.second.f_baochi_lock_min);
- else
- yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_min", "-");
- if (it.second.f_baochi_lock_avg != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "f_retention_fore_avg", it.second.f_baochi_lock_avg);
- else
- yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_avg", "-");
- }
- }
- *json = yyjson_mut_write(doc, 0, json_len);
- yyjson_mut_doc_free(doc);
- return 200;
- }
- int DealGetResistReport(const httplib::Request& req, const string token, char** json, size_t* json_len)
- {
- string station = req.get_param_value("station");
- string time = req.get_param_value("time");
- if (time.length() == 0 || station.length() == 0)
- return 400;
- time_t uTime = atoll(time.c_str());
- COleDateTime odt(uTime);
- if (odt.GetStatus() == COleDateTime::invalid)
- return 400;
- auto doc = yyjson_mut_doc_new(nullptr);
- auto root = yyjson_mut_arr(doc);
- yyjson_mut_doc_set_root(doc, root);
- {
- string strStation = UTF8toANSI(station);
- string table_name = fmt::format("rm_move_{:0>4}{:0>2}", odt.GetYear(), odt.GetMonth());
- CString sql = fmt::format("SELECT A.*,B.name FROM (SELECT mo, mp, posi, count(*) as num, max(show_val) as l, min(show_val) as s, sum(show_val) as sum, CASE WHEN posi = 3 OR posi = 4 THEN 3 WHEN [type] = 0 THEN 1 ELSE [type] END AS [newtype] FROM {} WHERE mo in (SELECT id FROM rm_mo WHERE up = '{}') AND show_time >= '{}' AND show_time <= '{}' GROUP BY mo, mp, posi, \
- CASE WHEN posi = 3 OR posi = 4 THEN 3 WHEN [type] = 0 THEN 1 ELSE [type] END ) AS A \
- LEFT JOIN rm_mo AS B ON A.mo = B.id",
- table_name, strStation, odt.Format("%Y-%m-%d 00:00:00"), odt.Format("%Y-%m-%d 23:59:59.999")).c_str();
- //SELECT A.*,B.name FROM (SELECT mo, mp, posi, count(*) as num, max(show_val) as l, min(show_val) as s FROM rm_move_202301 WHERE mo in (SELECT id FROM rm_mo WHERE up = '温州南站') AND show_time >= '2023-01-10 00:00:00' AND show_time <= '2023-01-10 23:59:59.999' GROUP BY mo, mp, posi) AS A LEFT JOIN rm_mo AS B ON A.mo = B.id
- COdbcStatement stmt;
- struct tagData
- {
- string mo_name;
- string mo;
- string mp;
- int d_convert_resist = INT_MAX;
- int d_convert_resist_max = INT_MAX;
- int d_convert_resist_min = INT_MAX;
- int d_convert_resist_avg = INT_MAX;
- uint8_t d_convert_resist_max_color = 0; //0 为正常 1 为预警 2 为报警
- uint8_t d_convert_resist_min_color = 0;
- uint8_t d_convert_resist_avg_color = 0;
- int f_convert_resist = INT_MAX;
- int f_convert_resist_max = INT_MAX;
- int f_convert_resist_min = INT_MAX;
- int f_convert_resist_avg = INT_MAX;
- uint8_t f_convert_resist_max_color = 0;
- uint8_t f_convert_resist_min_color = 0;
- uint8_t f_convert_resist_avg_color = 0;
- int d_suobi_lock = INT_MAX;
- int d_suobi_lock_max = INT_MAX;
- int d_suobi_lock_min = INT_MAX;
- int d_suobi_lock_avg = INT_MAX;
- uint8_t d_suobi_lock_max_color = 0;
- uint8_t d_suobi_lock_min_color = 0;
- uint8_t d_suobi_lock_avg_color = 0;
- int f_suobi_lock = INT_MAX;
- int f_suobi_lock_max = INT_MAX;
- int f_suobi_lock_min = INT_MAX;
- int f_suobi_lock_avg = INT_MAX;
- uint8_t f_suobi_lock_max_color = 0;
- uint8_t f_suobi_lock_min_color = 0;
- uint8_t f_suobi_lock_avg_color = 0;
- int d_baochi_lock = INT_MAX;
- int d_baochi_lock_max = INT_MAX;
- int d_baochi_lock_min = INT_MAX;
- int d_baochi_lock_avg = INT_MAX;
- uint8_t d_baochi_lock_max_color = 0;
- uint8_t d_baochi_lock_min_color = 0;
- uint8_t d_baochi_lock_avg_color = 0;
- int f_baochi_lock = INT_MAX;
- int f_baochi_lock_max = INT_MAX;
- int f_baochi_lock_min = INT_MAX;
- int f_baochi_lock_avg = INT_MAX;
- uint8_t f_baochi_lock_max_color = 0;
- uint8_t f_baochi_lock_min_color = 0;
- uint8_t f_baochi_lock_avg_color = 0;
- };
- std::map<string, tagData> mapData;
- if (CDBConnectPool::Instance()->DBQuery(stmt, sql))
- {
- int nCol = 1;
- char mo[50], mp[50], mo_name[50];
- int num;
- int max;
- int min;
- int64_t sum;
- eDaoChaPosi posi;
- ePowerName pn;
- stmt.BindCharCol(nCol++, mo, sizeof(mo));
- stmt.BindCharCol(nCol++, mp, sizeof(mp));
- stmt.BindTinyIntCol(nCol++, (BYTE*)&posi);
- stmt.BindIntCol(nCol++, &num);
- stmt.BindIntCol(nCol++, &max);
- stmt.BindIntCol(nCol++, &min);
- stmt.BindBigIntCol(nCol++, &sum);
- stmt.BindTinyIntCol(nCol++, (BYTE*)&pn);
- stmt.BindCharCol(nCol++, mo_name, sizeof(mo_name));
- do
- {
- if (stmt.FetchNext() != 0)
- break;
- SUOBI_OVER_LIMIT_INFO* pInfo = nullptr;
- CONVERT_RESIST_OVER_LIMIT* pInfo2 = nullptr;
- auto& it = mapData[fmt::format("{}.{}", mo, mp)];
- it.mo_name = mo_name;
- it.mo = mo;
- it.mp = mp;
- eSuoBiPosi idx;
- switch (posi)
- {
- case eDaoChaPosi::DCP_FIX:
- if (pn == ePowerName::PN_RETENTION)
- {
- it.d_baochi_lock = num;
- it.d_baochi_lock_max = max;
- it.d_baochi_lock_min = min;
- if (num) it.d_baochi_lock_avg = sum / num;
- }
- else
- {
- it.d_suobi_lock = num;
- it.d_suobi_lock_max = max;
- it.d_suobi_lock_min = min;
- if (num) it.d_suobi_lock_avg = sum / num;
- idx = eSuoBiPosi::SB_FIX;
- pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)idx, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
- if (pInfo && pInfo->enable)
- {
- if (max > pInfo->alarm_high_limit)
- it.d_suobi_lock_max_color = UINT8_ALARM;
- else if (max > pInfo->warn_high_limit)
- it.d_suobi_lock_max_color = UINT8_WARN;
- if (min < pInfo->alarm_low_limit)
- it.d_suobi_lock_min_color = UINT8_ALARM;
- else if (min < pInfo->warn_low_limit)
- it.d_suobi_lock_min_color = UINT8_WARN;
- if (num && (it.d_suobi_lock_avg > pInfo->alarm_high_limit || it.d_suobi_lock_avg < pInfo->alarm_low_limit))
- it.d_suobi_lock_avg_color = UINT8_ALARM;
- else if (num && (it.d_suobi_lock_avg > pInfo->warn_high_limit || it.d_suobi_lock_avg < pInfo->warn_low_limit))
- it.d_suobi_lock_avg_color = UINT8_WARN;
- }
- }
-
- break;
- case eDaoChaPosi::DCP_INVERT:
- if (pn == ePowerName::PN_RETENTION)
- {
- it.f_baochi_lock = num;
- it.f_baochi_lock_max = max;
- it.f_baochi_lock_min = min;
- if (num) it.f_baochi_lock_avg = sum / num;
- }
- else
- {
- it.f_suobi_lock = num;
- it.f_suobi_lock_max = max;
- it.f_suobi_lock_min = min;
- if (num) it.f_suobi_lock_avg = sum / num;
-
- idx = eSuoBiPosi::SB_INVERT;
- pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)idx, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
- if (pInfo && pInfo->enable)
- {
- if (max > pInfo->alarm_high_limit)
- it.f_suobi_lock_max_color = UINT8_ALARM;
- else if (max > pInfo->warn_high_limit)
- it.f_suobi_lock_max_color = UINT8_WARN;
-
- if (min < pInfo->alarm_low_limit)
- it.f_suobi_lock_min_color = UINT8_ALARM;
- else if (min < pInfo->warn_low_limit)
- it.f_suobi_lock_min_color = UINT8_WARN;
-
- if (num && (it.f_suobi_lock_avg > pInfo->alarm_high_limit || it.f_suobi_lock_avg < pInfo->alarm_low_limit))
- it.f_suobi_lock_avg_color = UINT8_ALARM;
- else if (num && (it.f_suobi_lock_avg > pInfo->warn_high_limit || it.f_suobi_lock_avg < pInfo->warn_low_limit))
- it.f_suobi_lock_avg_color = UINT8_WARN;
- }
- }
- break;
- case eDaoChaPosi::DCP_FIX2INVERT:
- it.d_convert_resist = num;
- it.d_convert_resist_max = max;
- it.d_convert_resist_min = min;
- if (num) it.d_convert_resist_avg = sum / num;
- pInfo2 = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
- if (pInfo2 && pInfo2->enable)
- {
- string name1, name2, name3, out_name, in_name;
- CMonitorObjectMng::Instance()->GetNameByMoMp(fmt::format("{}.{}", mo, mp), name1, name2, name3, out_name, in_name);
- if (in_name.find("定扳反") == -1) //如果缩进不是定扳反, 那就是伸出
- {
- if (max > pInfo2->dw_alarm_low_limit)
- it.d_convert_resist_max_color = UINT8_ALARM;
- else if (max > pInfo2->dw_warn_low_limit)
- it.d_convert_resist_max_color = UINT8_WARN;
- if (num && it.d_convert_resist_avg > pInfo2->dw_alarm_low_limit)
- it.d_convert_resist_avg_color = UINT8_ALARM;
- else if (num && it.d_convert_resist_avg > pInfo2->dw_warn_low_limit)
- it.d_convert_resist_avg_color = UINT8_WARN;
- }
- else
- {
- if (max > pInfo2->up_alarm_high_limit)
- it.d_convert_resist_max_color = UINT8_ALARM;
- else if (max > pInfo2->up_warn_high_limit)
- it.d_convert_resist_max_color = UINT8_WARN;
- if (num && it.d_convert_resist_avg > pInfo2->up_alarm_high_limit)
- it.d_convert_resist_avg_color = UINT8_ALARM;
- else if (num && it.d_convert_resist_avg > pInfo2->up_warn_high_limit)
- it.d_convert_resist_avg_color = UINT8_WARN;
- }
- }
- break;
- case eDaoChaPosi::DCP_INVERT2FIX:
- it.f_convert_resist = num;
- it.f_convert_resist_max = max;
- it.f_convert_resist_min = min;
- if (num) it.f_convert_resist_avg = sum / num;
- pInfo2 = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
- if (pInfo2 && pInfo2->enable)
- {
- string name1, name2, name3, out_name, in_name;
- CMonitorObjectMng::Instance()->GetNameByMoMp(fmt::format("{}.{}", mo, mp), name1, name2, name3, out_name, in_name);
- if (in_name.find("反扳定") != -1) //如果反扳定是缩进
- {
- if (max > pInfo2->up_alarm_high_limit)
- it.f_convert_resist_max_color = UINT8_ALARM;
- else if (max > pInfo2->up_warn_high_limit)
- it.f_convert_resist_max_color = UINT8_WARN;
- if (num && it.f_convert_resist_avg > pInfo2->up_alarm_high_limit)
- it.f_convert_resist_avg_color = UINT8_ALARM;
- else if (num && it.f_convert_resist_avg > pInfo2->up_warn_high_limit)
- it.f_convert_resist_avg_color = UINT8_WARN;
- }
- else
- {
- if (max > pInfo2->dw_alarm_low_limit)
- it.f_convert_resist_max_color = UINT8_ALARM;
- else if (max > pInfo2->dw_warn_low_limit)
- it.f_convert_resist_max_color = UINT8_WARN;
- if (num && it.f_convert_resist_avg > pInfo2->dw_alarm_low_limit)
- it.f_convert_resist_avg_color = UINT8_ALARM;
- else if (num && it.f_convert_resist_avg > pInfo2->dw_warn_low_limit)
- it.f_convert_resist_avg_color = UINT8_WARN;
- }
- }
- break;
- default:
- ASSERT(FALSE);
- break;
- }
- } while (TRUE);
- }
- stmt.Close();
- for (auto& it : mapData)
- {
- auto obj = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(root, obj);
- yyjson_mut_obj_add_strcpy(doc, obj, "mo_name", ANSItoUTF8(it.second.mo_name).c_str());
- yyjson_mut_obj_add_strcpy(doc, obj, "mo", it.second.mo.c_str());
- yyjson_mut_obj_add_strcpy(doc, obj, "mp", it.second.mp.c_str());
- if (it.second.d_convert_resist != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "d_convert_resist", it.second.d_convert_resist);
- else
- yyjson_mut_obj_add_str(doc, obj, "d_convert_resist", "-");
- if (it.second.d_convert_resist_max != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "d_convert_resist_max", it.second.d_convert_resist_max);
- else
- yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_max", "-");
- if (it.second.d_convert_resist_min != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "d_convert_resist_min", it.second.d_convert_resist_min);
- else
- yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_min", "-");
- if (it.second.d_convert_resist_avg != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "d_convert_resist_avg", it.second.d_convert_resist_avg);
- else
- yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_avg", "-");
- //颜色
- if (it.second.d_convert_resist_max_color == UINT8_ALARM)
- yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_max_color", "red");
- else if (it.second.d_convert_resist_max_color == UINT8_WARN)
- yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_max_color", "orange");
- if (it.second.d_convert_resist_min_color == UINT8_ALARM)
- yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_min_color", "red");
- else if (it.second.d_convert_resist_min_color == UINT8_WARN)
- yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_min_color", "orange");
- if (it.second.d_convert_resist_avg_color == UINT8_ALARM)
- yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_avg_color", "red");
- else if (it.second.d_convert_resist_avg_color == UINT8_WARN)
- yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_avg_color", "orange");
- if (it.second.f_convert_resist != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "f_convert_resist", it.second.f_convert_resist);
- else
- yyjson_mut_obj_add_str(doc, obj, "f_convert_resist", "-");
- if (it.second.f_convert_resist_max != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "f_convert_resist_max", it.second.f_convert_resist_max);
- else
- yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_max", "-");
- if (it.second.f_convert_resist_min != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "f_convert_resist_min", it.second.f_convert_resist_min);
- else
- yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_min", "-");
- if (it.second.f_convert_resist_avg != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "f_convert_resist_avg", it.second.f_convert_resist_avg);
- else
- yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_avg", "-");
- //颜色
- if (it.second.f_convert_resist_max_color == UINT8_ALARM)
- yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_max_color", "red");
- else if (it.second.f_convert_resist_max_color == UINT8_WARN)
- yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_max_color", "orange");
- if (it.second.f_convert_resist_min_color == UINT8_ALARM)
- yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_min_color", "red");
- else if (it.second.f_convert_resist_min_color == UINT8_WARN)
- yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_min_color", "orange");
- if (it.second.f_convert_resist_avg_color == UINT8_ALARM)
- yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_avg_color", "red");
- else if (it.second.f_convert_resist_avg_color == UINT8_WARN)
- yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_avg_color", "orange");
- if (it.second.d_suobi_lock != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "d_suobi_lock", it.second.d_suobi_lock);
- else
- yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock", "-");
- if (it.second.d_suobi_lock_max != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "d_suobi_lock_max", it.second.d_suobi_lock_max);
- else
- yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_max", "-");
- if (it.second.d_suobi_lock_min != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "d_suobi_lock_min", it.second.d_suobi_lock_min);
- else
- yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_min", "-");
- if (it.second.d_suobi_lock_avg != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "d_suobi_lock_avg", it.second.d_suobi_lock_avg);
- else
- yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_avg", "-");
- //颜色
- if (it.second.d_suobi_lock_max_color == UINT8_ALARM)
- yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_max_color", "red");
- else if (it.second.d_suobi_lock_max_color == UINT8_WARN)
- yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_max_color", "orange");
- if (it.second.d_suobi_lock_min_color == UINT8_ALARM)
- yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_min_color", "red");
- else if (it.second.d_suobi_lock_min_color == UINT8_WARN)
- yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_min_color", "orange");
- if (it.second.d_suobi_lock_avg_color == UINT8_ALARM)
- yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_avg_color", "red");
- else if (it.second.d_suobi_lock_avg_color == UINT8_WARN)
- yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_avg_color", "orange");
- if (it.second.f_suobi_lock != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "f_suobi_lock", it.second.f_suobi_lock);
- else
- yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock", "-");
- if (it.second.f_suobi_lock_max != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "f_suobi_lock_max", it.second.f_suobi_lock_max);
- else
- yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_max", "-");
- if (it.second.f_suobi_lock_min!= INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "f_suobi_lock_min", it.second.f_suobi_lock_min);
- else
- yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_min", "-");
- if (it.second.f_suobi_lock_avg != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "f_suobi_lock_avg", it.second.f_suobi_lock_avg);
- else
- yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_avg", "-");
- //颜色
- if (it.second.f_suobi_lock_max_color == UINT8_ALARM)
- yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_max_color", "red");
- else if (it.second.f_suobi_lock_max_color == UINT8_WARN)
- yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_max_color", "orange");
- if (it.second.f_suobi_lock_min_color == UINT8_ALARM)
- yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_min_color", "red");
- else if (it.second.f_suobi_lock_min_color == UINT8_WARN)
- yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_min_color", "orange");
- if (it.second.f_suobi_lock_avg_color == UINT8_ALARM)
- yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_avg_color", "red");
- else if (it.second.f_suobi_lock_avg_color == UINT8_WARN)
- yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_avg_color", "orange");
- if (it.second.d_baochi_lock != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "d_retention_fore", it.second.d_baochi_lock);
- else
- yyjson_mut_obj_add_str(doc, obj, "d_retention_fore", "-");
- if (it.second.d_baochi_lock_max != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "d_retention_fore_max", it.second.d_baochi_lock_max);
- else
- yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_max", "-");
- if (it.second.d_baochi_lock_min != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "d_retention_fore_min", it.second.d_baochi_lock_min);
- else
- yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_min", "-");
- if (it.second.d_baochi_lock_avg != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "d_retention_fore_avg", it.second.d_baochi_lock_avg);
- else
- yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_avg", "-");
- //颜色
- if (it.second.d_baochi_lock_max_color == UINT8_ALARM)
- yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_max_color", "red");
- else if (it.second.d_baochi_lock_max_color == UINT8_WARN)
- yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_max_color", "orange");
- if (it.second.d_baochi_lock_min_color == UINT8_ALARM)
- yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_min_color", "red");
- else if (it.second.d_baochi_lock_min_color == UINT8_WARN)
- yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_min_color", "orange");
- if (it.second.d_baochi_lock_avg_color == UINT8_ALARM)
- yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_avg_color", "red");
- else if (it.second.d_baochi_lock_avg_color == UINT8_WARN)
- yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_avg_color", "orange");
- if (it.second.f_baochi_lock != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "f_retention_fore", it.second.f_baochi_lock);
- else
- yyjson_mut_obj_add_str(doc, obj, "f_retention_fore", "-");
- if (it.second.f_baochi_lock_max != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "f_retention_fore_max", it.second.f_baochi_lock_max);
- else
- yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_max", "-");
- if (it.second.f_baochi_lock_min != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "f_retention_fore_min", it.second.f_baochi_lock_min);
- else
- yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_min", "-");
- if (it.second.f_baochi_lock_avg != INT_MAX)
- yyjson_mut_obj_add_int(doc, obj, "f_retention_fore_avg", it.second.f_baochi_lock_avg);
- else
- yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_avg", "-");
- //颜色
- if (it.second.f_baochi_lock_max_color == UINT8_ALARM)
- yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_max_color", "red");
- else if (it.second.f_baochi_lock_max_color == UINT8_WARN)
- yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_max_color", "orange");
- if (it.second.f_baochi_lock_min_color == UINT8_ALARM)
- yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_min_color", "red");
- else if (it.second.f_baochi_lock_min_color == UINT8_WARN)
- yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_min_color", "orange");
- if (it.second.f_baochi_lock_avg_color == UINT8_ALARM)
- yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_avg_color", "red");
- else if (it.second.f_baochi_lock_avg_color == UINT8_WARN)
- yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_avg_color", "orange");
- }
- }
- *json = yyjson_mut_write(doc, 0, json_len);
- yyjson_mut_doc_free(doc);
- return 200;
- }
- int DealGetMoveInfo(const httplib::Request& req, const string token, char** json, size_t* json_len)
- {
- string mo = req.get_param_value("mo");
- string mp = req.get_param_value("mp");
- string start_time = req.get_param_value("start_time");
- string end_time = req.get_param_value("end_time");
- if (mo.length() == 0 || mp.length() == 0 || start_time.length() == 0 || end_time.length() == 0)
- return 400;
- auto doc = yyjson_mut_doc_new(nullptr);
- auto root = yyjson_mut_obj(doc);
- yyjson_mut_doc_set_root(doc, root);
- auto data = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, root, "data", data);
- COleDateTime odtStart, odtEnd;
- do {
- auto ret_time = odtEnd.ParseDateTime(end_time.c_str());
- if (ret_time == FALSE)
- break;
- ret_time = odtStart.ParseDateTime(start_time.c_str());
- if (ret_time == FALSE)
- break;
- if (odtEnd <= odtStart)
- break;
- auto fix_object = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(data, fix_object);
- auto invert_object = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(data, invert_object);
- auto convert_object = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(data, convert_object);
- static string fix_name = ANSItoUTF8("定位测力曲线");
- yyjson_mut_obj_add_str(doc, fix_object, "name", fix_name.c_str());
- static string invert_name = ANSItoUTF8("反位测力曲线");
- yyjson_mut_obj_add_str(doc, invert_object, "name", invert_name.c_str());
- static string convert_name = ANSItoUTF8("转换阻力曲线");
- yyjson_mut_obj_add_str(doc, convert_object, "name", convert_name.c_str());
- static string lock_low = ANSItoUTF8("锁闭力过低");
- auto fix_points = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, fix_object, "mark_points", fix_points);
- auto invert_points = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, invert_object, "mark_points", invert_points);
- auto convert_points = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, convert_object, "mark_points", convert_points);
- auto pConvertLimit = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
- auto pFixSuobi = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_FIX, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
- auto pInvertSuobi = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_INVERT, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
- string out_name, in_name;
- CMonitorObjectMng::Instance()->GetDirectByMoMp(mo + "." + mp, out_name, in_name);
- //string name1, name2, name3, out_name, in_name;
- //CMonitorObjectMng::Instance()->GetNameByMoMp(mo + "." + mp, name1, name2, name3, out_name, in_name);
- string table_name = fmt::format("rm_move_{:0>4}{:0>2}", odtStart.GetYear(), odtStart.GetMonth());
- CString sql = fmt::format("SELECT show_time, curr_val, show_val, posi, mark FROM {} \
- WHERE mo = '{}' AND mp = '{}' AND show_time >= '{}' AND show_time <= '{}' AND [type] <> 2 order by posi, show_time",
- table_name, mo, mp, start_time, end_time).c_str();
- COdbcStatement stmt;
- if (CDBConnectPool::Instance()->DBQuery(stmt, sql))
- {
- TIMESTAMP_STRUCT ts;
- int curr_val;
- int show_val;
- eDaoChaPosi posi;
- char mark[200];
- int nCol = 1;
- stmt.BindTimeStampCol(nCol++, &ts);
- stmt.BindIntCol(nCol++, &curr_val);
- stmt.BindIntCol(nCol++, &show_val);
- stmt.BindTinyIntCol(nCol++, (BYTE*)&posi);
- stmt.BindCharCol(nCol++, mark, sizeof(mark));
- do
- {
- if (stmt.FetchNext() != 0)
- break;
- auto obj = yyjson_mut_obj(doc);
- switch (posi)
- {
- case eDaoChaPosi::DCP_FIX:
- {
- yyjson_mut_arr_add_val(fix_points, obj);
- auto coord = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, obj, "coord", coord);
- yyjson_mut_arr_add_int(doc, coord, CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second).GetTime() * 1000 + ts.fraction / 1000000);
- yyjson_mut_arr_add_int(doc, coord, curr_val);
- yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
- ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
- yyjson_mut_obj_add_int(doc, obj, "val", show_val);
- if (pFixSuobi && pFixSuobi->enable)
- {
- if (pFixSuobi->alarm_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pFixSuobi->alarm_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pFixSuobi->warn_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- else if (pFixSuobi->warn_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str());
- //if (show_val < 500)//TODO
- //{
- // yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- // yyjson_mut_obj_add_str(doc, obj, "label", lock_low.c_str());
- //}
- //else
- //{
- // yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str());
- //}
- }
- break;
- case eDaoChaPosi::DCP_INVERT:
- {
- yyjson_mut_arr_add_val(invert_points, obj);
- auto coord = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, obj, "coord", coord);
- yyjson_mut_arr_add_int(doc, coord, CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second).GetTime() * 1000 + ts.fraction / 1000000);
- yyjson_mut_arr_add_int(doc, coord, curr_val);
- yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
- ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
- yyjson_mut_obj_add_int(doc, obj, "val", show_val);
- if (pInvertSuobi && pInvertSuobi->enable)
- {
- if (pInvertSuobi->alarm_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pInvertSuobi->alarm_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pInvertSuobi->warn_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- else if (pInvertSuobi->warn_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str());
- //if (show_val < 500)//TODO
- //{
- // yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- // yyjson_mut_obj_add_str(doc, obj, "label", lock_low.c_str());
- //}
- //else
- //{
- // yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str());
- //}
- }
- break;
- case eDaoChaPosi::DCP_FIX2INVERT:
- {
- yyjson_mut_arr_add_val(convert_points, obj);
- auto coord = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, obj, "coord", coord);
- yyjson_mut_arr_add_int(doc, coord, CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second).GetTime() * 1000 + ts.fraction / 1000000);
- yyjson_mut_arr_add_int(doc, coord, curr_val);
- yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
- ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
- yyjson_mut_obj_add_int(doc, obj, "val", show_val);
- if (pConvertLimit && pConvertLimit->enable)
- {
- if (out_name.find("定扳反") != -1)
- {
- if (pConvertLimit->dw_alarm_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pConvertLimit->dw_warn_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- else
- {
- if (pConvertLimit->up_alarm_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pConvertLimit->up_warn_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- }
- if (curr_val < 0)
- yyjson_mut_obj_add_str(doc, obj, "position", "bottom");
- yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("定扳反:{}", show_val)).c_str());
- }
- break;
- case eDaoChaPosi::DCP_INVERT2FIX:
- {
- yyjson_mut_arr_add_val(convert_points, obj);
- auto coord = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, obj, "coord", coord);
- yyjson_mut_arr_add_int(doc, coord, CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second).GetTime() * 1000 + ts.fraction / 1000000);
- yyjson_mut_arr_add_int(doc, coord, curr_val);
- yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
- ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
- yyjson_mut_obj_add_int(doc, obj, "val", show_val);
- if (pConvertLimit && pConvertLimit->enable)
- {
- if (out_name.find("反扳定") != -1)
- {
- if (pConvertLimit->dw_alarm_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pConvertLimit->dw_warn_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- else
- {
- if (pConvertLimit->up_alarm_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pConvertLimit->up_warn_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- }
- if (curr_val < 0)
- yyjson_mut_obj_add_str(doc, obj, "position", "bottom");
- yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("反扳定:{}", show_val)).c_str());
- }
- break;
- default:
- ASSERT(FALSE);
- break;
- }
- } while (TRUE);
- }
- stmt.Close();
-
- }while (false);
- *json = yyjson_mut_write(doc, 0, json_len);
- yyjson_mut_doc_free(doc);
- return 200;
- }
- #include "MGWSServer.h"
- int DealResistMove(const httplib::Request& req, const string token, char** json, size_t* json_len)
- {
- string mo = req.get_param_value("mo");
- string mp = req.get_param_value("mp");
- string starttime = req.get_param_value("starttime");
- string endtime = req.get_param_value("endtime");
- if (mo.length() == 0 || mp.length() == 0 || starttime.length() == 0 || endtime.length() == 0)
- return 400;
- auto doc = yyjson_mut_doc_new(nullptr);
- auto root = yyjson_mut_obj(doc);
- yyjson_mut_doc_set_root(doc, root);
- auto data = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, root, "data", data);
- COleDateTime odtStart, odtEnd;
- int code = 400;
- do {
- auto ret_time = odtEnd.ParseDateTime(endtime.c_str());
- if (ret_time == FALSE)
- break;
- ret_time = odtStart.ParseDateTime(starttime.c_str());
- if (ret_time == FALSE)
- break;
- if (odtEnd <= odtStart)
- break;
- string momp = mo + "." + mp;
- auto pInfo = CMonitorObjectMng::Instance()->GetMoMpInfo(momp);
- if (pInfo == nullptr)
- {
- code = 404;
- break;
- }
- char tablename[50] = { 0 };
- auto dtStartDate = COleDateTime(odtStart.GetYear(), odtStart.GetMonth(), odtStart.GetDay(), 0, 0, 0);
- auto strStartDate = dtStartDate.Format("%Y-%m-%d %H:%M:%S");
- auto strEndDate = odtEnd.Format("%Y-%m-%d %H:%M:%S");;
- CString sql;
- {
- int num = 0;
- for (auto it = dtStartDate; it < odtEnd;)
- {
- sprintf_s(tablename, 50, "rm_resistance_%04d%02d%02d", it.GetYear(), it.GetMonth(), it.GetDay());
- if (num == 0)
- {
- sql.Format("SELECT [acquisitiontime],[data0],[data1],[data2] "\
- "FROM %s WHERE IMEI = '%s' AND acquisitiontime >= '%s' and acquisitiontime < '%s' AND idx = %d ",
- tablename, pInfo->imei.c_str(), starttime.c_str(), endtime.c_str(), pInfo->idx);
- }
- else
- {
- sql += fmt::format(" UNION ALL "\
- "SELECT [acquisitiontime],[data0],[data1],[data2] "\
- "FROM {} WHERE IMEI = '{}' AND acquisitiontime >= '{}' and acquisitiontime < '{}' AND idx = {} ",
- tablename, pInfo->imei.c_str(), starttime, endtime, pInfo->idx).c_str();
- }
- num++;
- it += COleDateTimeSpan(1, 0, 0, 0);
- }
- sql += "ORDER BY acquisitiontime ASC";
- }
- TIMESTAMP_STRUCT ts;
- int sdata0, sdata1, sdata2;
- COdbcStatement stmt;
- if (CDBConnectPool::Instance()->DBQuery(stmt, sql) == FALSE)
- {
- ASSERT(0);
- SPDLOG_ERROR("查询语句出错:{}", sql);
- code = 500;
- break;
- }
- int nCol = 1;
- stmt.BindTimeStampCol(nCol++, &ts);
- stmt.BindIntCol(nCol++, &sdata0);
- stmt.BindIntCol(nCol++, &sdata1);
- stmt.BindIntCol(nCol++, &sdata2);
- int nCount = 0;
- std::map<time_t, int> data0, data1, data2;
- do
- {
- if (stmt.FetchNext() != 0)
- break;
- CTime ctTime;
- try
- {
- ctTime = CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
- }
- catch (...)
- {
- continue;
- }
- time_t tm = ctTime.GetTime() * 1000 + ts.fraction / 1000000;
- data0[tm] = sdata0;
- data1[tm] = sdata1;
- data2[tm] = sdata2;
- nCount++;
- } while (true);
- stmt.Close();
- list<CONVERT_RESIST> maxResist; //转换力数据
- list<PASS_RESIST> lstPass; //过车数据
- std::map<time_t, int64_t> maxlock0, maxlock1;//锁闭力 前面时间戳, 后面 高4位显示值, 低4位报警值
- std::map<time_t, int64_t> retentionforce0, retentionforce1; //保持力 时间戳, 高4位显示值, 低4位报警值
- std::map<time_t, tagSecondStatInfo> mapSecondStatInfo0, mapSecondStatInfo1, mapSecondStatInfo2;
- mg_per_session_data::GetMaxResist(data2, mapSecondStatInfo2, maxResist, mo, mp);
- mg_per_session_data::GetPassNew(mapSecondStatInfo0, &data0, mapSecondStatInfo1, &data1, mo, mp, &lstPass);
- //过车过滤
- for (auto& item : lstPass)
- {
- for (auto it = maxResist.begin();it != maxResist.end();)
- {
- if (it->tmStart*1000 <= item.show_time && item.show_time <= (it->tmEnd+1)*1000)
- {
- it = maxResist.erase(it);
- break;
- }
- ++it;
- }
- }
- if (maxResist.size())
- {
- mg_per_session_data::GetMaxLockNew(data0, maxResist, maxlock0, retentionforce0);
- mg_per_session_data::GetMaxLockNew(data1, maxResist, maxlock1, retentionforce1);
- }
- else
- {
- code = 200;
- continue; //没有检查到转换阻力
- }
- //CalcFixOrInvert(maxResist, maxlock0, maxlock1, name1, name2);
- //GetMaxForce(data2, maxForce);
- auto fix_object = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(data, fix_object);
- auto invert_object = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(data, invert_object);
- auto convert_object = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(data, convert_object);
- static string fix_name = ANSItoUTF8("定位测力曲线");
- yyjson_mut_obj_add_str(doc, fix_object, "name", fix_name.c_str());
- static string invert_name = ANSItoUTF8("反位测力曲线");
- yyjson_mut_obj_add_str(doc, invert_object, "name", invert_name.c_str());
- static string convert_name = ANSItoUTF8("转换阻力曲线");
- yyjson_mut_obj_add_str(doc, convert_object, "name", convert_name.c_str());
- static string lock_low = ANSItoUTF8("锁闭力过低");
- auto fix_points = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, fix_object, "mark_points", fix_points);
- auto invert_points = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, invert_object, "mark_points", invert_points);
- auto convert_points = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, convert_object, "mark_points", convert_points);
- auto pConvertLimit = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
- auto pFixSuobi = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_FIX, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
- auto pInvertSuobi = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_INVERT, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
- std::map<time_t, int64_t>* pmaxlockfix = nullptr, * pmaxlockinvert = nullptr;
- if (pInfo->name1.find("定位") != -1)
- {
- pmaxlockfix = &maxlock0;
- pmaxlockinvert = &maxlock1;
- }
- else
- {
- pmaxlockfix = &maxlock1;
- pmaxlockinvert = &maxlock0;
- }
- for (auto& it : *pmaxlockfix)
- {
- int curr_val = (int)it.second;
- int show_val = (it.second >> 32);
- time_t show_time = it.first;
- auto obj = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(fix_points, obj);
- auto coord = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, obj, "coord", coord);
- yyjson_mut_arr_add_int(doc, coord, show_time);
- yyjson_mut_arr_add_int(doc, coord, curr_val);
- yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{}.{:0>3}", CTime(show_time/1000).Format("%Y-%m-%d %H:%M:%S"), show_time % 1000).c_str());
- yyjson_mut_obj_add_int(doc, obj, "val", show_val);
- if (pFixSuobi && pFixSuobi->enable)
- {
- if (pFixSuobi->alarm_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pFixSuobi->alarm_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pFixSuobi->warn_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- else if (pFixSuobi->warn_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", ++show_val)).c_str());
- //CResistAlarmMng::InsertToDBByMove(mo, mp, it.first, 0, 0,
- // (int)it.second, show_val, i, (uint8_t)eDaoChaPosi::DCP_FIX, fmt::format("锁闭力:{}", show_val));
- //JudgeAlarm(pService, pFixSuobiOverInfo, it.first, show_val, eSuoBiPosi::SB_FIX, mo, mp, zzjno);
- }
- for (auto& it : *pmaxlockinvert)
- {
- int curr_val = (int)it.second;
- int show_val = (it.second >> 32);
- time_t show_time = it.first;
- auto obj = yyjson_mut_obj(doc);
- yyjson_mut_arr_add_val(invert_points, obj);
- auto coord = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, obj, "coord", coord);
- yyjson_mut_arr_add_int(doc, coord, show_time);
- yyjson_mut_arr_add_int(doc, coord, curr_val);
- yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{}.{:0>3}", CTime(show_time / 1000).Format("%Y-%m-%d %H:%M:%S"), show_time % 1000).c_str());
- yyjson_mut_obj_add_int(doc, obj, "val", show_val);
- if (pInvertSuobi && pInvertSuobi->enable)
- {
- if (pInvertSuobi->alarm_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pInvertSuobi->alarm_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pInvertSuobi->warn_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- else if (pInvertSuobi->warn_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", ++show_val)).c_str());
- //int show_val = (it.second >> 32);
- //CResistAlarmMng::InsertToDBByMove(mo, mp, it.first, 0, 0,
- // (int)it.second, show_val, i, (uint8_t)eDaoChaPosi::DCP_INVERT, fmt::format("锁闭力:{}", show_val));
- //JudgeAlarm(pService, pInvertSuobiOverInfo, it.first, show_val, eSuoBiPosi::SB_INVERT, mo, mp, zzjno);
- }
- for (auto& it : maxResist)
- {
- auto obj = yyjson_mut_obj(doc);
- int curr_val = it.val;
- int show_val = it.fluctuation_val;
- time_t show_time = it.time;
- eDaoChaPosi posi = eDaoChaPosi::DCP_UNKNOWN;
- if (it.bUpOrDown == eUpOrDownInfo::UOD_UP)
- {
- if (pInfo->in_name.find("定扳反") != -1)
- {
- yyjson_mut_arr_add_val(convert_points, obj);
- auto coord = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, obj, "coord", coord);
- yyjson_mut_arr_add_int(doc, coord, show_time);
- yyjson_mut_arr_add_int(doc, coord, curr_val);
- yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{}.{:0>3}", CTime(show_time / 1000).Format("%Y-%m-%d %H:%M:%S"), show_time % 1000).c_str());
- yyjson_mut_obj_add_int(doc, obj, "val", show_val);
- if (pConvertLimit && pConvertLimit->enable)
- {
- if (pInfo->out_name.find("定扳反") != -1)
- {
- if (pConvertLimit->dw_alarm_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pConvertLimit->dw_warn_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- else
- {
- if (pConvertLimit->up_alarm_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pConvertLimit->up_warn_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- }
- if (curr_val < 0)
- yyjson_mut_obj_add_str(doc, obj, "position", "bottom");
- yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("定扳反:{}", ++show_val)).c_str());
- //CResistAlarmMng::InsertToDBByMove(mo, mp, it.time, it.tmStart, it.tmEnd, it.val, it.fluctuation_val, i,
- // (uint8_t)eDaoChaPosi::DCP_FIX2INVERT, fmt::format("{}:{}", in_name, it.fluctuation_val));
- //posi = eDaoChaPosi::DCP_FIX2INVERT;
- //CMonitorObjectMng::Instance()->UpdateZZJEPOS(mo + "." + mp, DAOCHA_POSITION::MP_INVERT);
- //JudgeAlarm(pService, pConvertResistOverLimitInfo, it.time, it.fluctuation_val, posi, it.bUpOrDown, mo, mp, zzjno);
- }
- else
- {
- yyjson_mut_arr_add_val(convert_points, obj);
- auto coord = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, obj, "coord", coord);
- yyjson_mut_arr_add_int(doc, coord, show_time);
- yyjson_mut_arr_add_int(doc, coord, curr_val);
- yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{}.{:0>3}", CTime(show_time / 1000).Format("%Y-%m-%d %H:%M:%S"), show_time % 1000).c_str());
- yyjson_mut_obj_add_int(doc, obj, "val", show_val);
- if (pConvertLimit && pConvertLimit->enable)
- {
- if (pInfo->out_name.find("反扳定") != -1)
- {
- if (pConvertLimit->dw_alarm_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pConvertLimit->dw_warn_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- else
- {
- if (pConvertLimit->up_alarm_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pConvertLimit->up_warn_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- }
- if (curr_val < 0)
- yyjson_mut_obj_add_str(doc, obj, "position", "bottom");
- yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("反扳定:{}", ++show_val)).c_str());
- //CResistAlarmMng::InsertToDBByMove(mo, mp, it.time, it.tmStart, it.tmEnd, it.val, it.fluctuation_val, i,
- // (uint8_t)eDaoChaPosi::DCP_INVERT2FIX, fmt::format("{}:{}", in_name, it.fluctuation_val));
- //posi = eDaoChaPosi::DCP_INVERT2FIX;
- //CMonitorObjectMng::Instance()->UpdateZZJEPOS(mo + "." + mp, DAOCHA_POSITION::MP_FIX);
- //JudgeAlarm(pService, pConvertResistOverLimitInfo, it.time, it.fluctuation_val, posi, it.bUpOrDown, mo, mp, zzjno);
- }
- }
- else
- {
- if (pInfo->out_name.find("定扳反") != -1)
- {
- yyjson_mut_arr_add_val(convert_points, obj);
- auto coord = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, obj, "coord", coord);
- yyjson_mut_arr_add_int(doc, coord, show_time);
- yyjson_mut_arr_add_int(doc, coord, curr_val);
- yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{}.{:0>3}", CTime(show_time / 1000).Format("%Y-%m-%d %H:%M:%S"), show_time % 1000).c_str());
- yyjson_mut_obj_add_int(doc, obj, "val", show_val);
- if (pConvertLimit && pConvertLimit->enable)
- {
- if (pInfo->out_name.find("定扳反") != -1)
- {
- if (pConvertLimit->dw_alarm_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pConvertLimit->dw_warn_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- else
- {
- if (pConvertLimit->up_alarm_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pConvertLimit->up_warn_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- }
- if (curr_val < 0)
- yyjson_mut_obj_add_str(doc, obj, "position", "bottom");
- yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("定扳反:{}", ++show_val)).c_str());
- //CResistAlarmMng::InsertToDBByMove(mo, mp, it.time, it.tmStart, it.tmEnd, it.val, it.fluctuation_val, i,
- // (uint8_t)eDaoChaPosi::DCP_FIX2INVERT, fmt::format("{}:{}", out_name, it.fluctuation_val));
- //posi = eDaoChaPosi::DCP_FIX2INVERT;
- //CMonitorObjectMng::Instance()->UpdateZZJEPOS(mo + "." + mp, DAOCHA_POSITION::MP_INVERT);
- //JudgeAlarm(pService, pConvertResistOverLimitInfo, it.time, it.fluctuation_val, posi, it.bUpOrDown, mo, mp, zzjno);
- }
- else
- {
- yyjson_mut_arr_add_val(convert_points, obj);
- auto coord = yyjson_mut_arr(doc);
- yyjson_mut_obj_add_val(doc, obj, "coord", coord);
- yyjson_mut_arr_add_int(doc, coord, show_time);
- yyjson_mut_arr_add_int(doc, coord, curr_val);
- yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{}.{:0>3}", CTime(show_time / 1000).Format("%Y-%m-%d %H:%M:%S"), show_time % 1000).c_str());
- yyjson_mut_obj_add_int(doc, obj, "val", show_val);
- if (pConvertLimit && pConvertLimit->enable)
- {
- if (pInfo->out_name.find("反扳定") != -1)
- {
- if (pConvertLimit->dw_alarm_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pConvertLimit->dw_warn_low_limit > show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- else
- {
- if (pConvertLimit->up_alarm_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Red");
- else if (pConvertLimit->up_warn_high_limit < show_val)
- yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
- }
- }
- if (curr_val < 0)
- yyjson_mut_obj_add_str(doc, obj, "position", "bottom");
- yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("反扳定:{}", ++show_val)).c_str());
- //CResistAlarmMng::InsertToDBByMove(mo, mp, it.time, it.tmStart, it.tmEnd, it.val, it.fluctuation_val, i,
- // (uint8_t)eDaoChaPosi::DCP_INVERT2FIX, fmt::format("{}:{}", out_name, it.fluctuation_val));
- //posi = eDaoChaPosi::DCP_INVERT2FIX;
- //CMonitorObjectMng::Instance()->UpdateZZJEPOS(mo + "." + mp, DAOCHA_POSITION::MP_FIX);
- //JudgeAlarm(pService, pConvertResistOverLimitInfo, it.time, it.fluctuation_val, posi, it.bUpOrDown, mo, mp, zzjno);
- }
- }
- }
- code = 200;
- } while (false);
- *json = yyjson_mut_write(doc, 0, json_len);
- yyjson_mut_doc_free(doc);
- return code;
- }
|