HttpPrcess.cpp 181 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990
  1. #include "stdafx.h"
  2. #include "HttpPrcess.h"
  3. #include <yyjson.h>
  4. #include <Simplelog.h>
  5. #include "MonitorObject.h"
  6. #include "AlarmDefine.h"
  7. #include "ResistAlarm.h"
  8. #include <crc32.h>
  9. #include "AppService.h"
  10. #include <gbk2utf8.h>
  11. #include "Device.h"
  12. #include "SkylightMng.h"
  13. //处理get请求总入口
  14. void DealHttpGet(const httplib::Request& req, httplib::Response& res)
  15. {
  16. int code = 500;
  17. auto start = chrono::steady_clock::now();
  18. auto token = req.get_header_value("token");
  19. if (token.length() == 0 || token.empty())
  20. token = req.get_header_value("Authorization");
  21. char* json = nullptr;
  22. string body;
  23. size_t json_len = 0;
  24. //CSimpleLog::Info(fmt::format("[HTTP][GET][START] {}:{} {}", req.remote_addr, req.remote_port, req.target).c_str());
  25. SPDLOG_INFO("[HTTP][GET][START] {}:{} {}", req.remote_addr, req.remote_port, req.target);
  26. try
  27. {
  28. if (token.empty())
  29. {
  30. code = 401;
  31. }
  32. if (req.path.find("option_svg") != -1)
  33. code = DealOptionSvgData(req, token, res);
  34. else if (req.path.find("get_svg") != -1)
  35. code = DealGetSvgData(req, token, res);
  36. else if (req.path.find("get_mp_stat") != -1)
  37. code = DealGetMpStat(req, token, res);
  38. else if (req.path.find("conf_read/mitie_lock") != -1)
  39. code = DealGetMitieLock(req, token, &json, &json_len);
  40. else if (req.path.find("conf_read/convert_resist") != -1)
  41. code = DealGetConvertResist(req, token, &json, &json_len);
  42. else if (req.path.find("conf_read/retension_force") != -1)
  43. code = DealGetRetesionForce(req, token, &json, &json_len);
  44. else if (req.path.find("resistance_curve") != -1)
  45. code = DealGetResistCurve(req, token, &json, &json_len);
  46. else if (req.path.find("retension_curve") != -1)
  47. code = DealGetRetentionCurve(req, token, &json, &json_len);
  48. else if (req.path.find("resistance_report") != -1)
  49. code = DealGetResistReport(req, token, &json, &json_len);
  50. else if (req.path.find("Retention_report") != -1)
  51. code = DealGetRetentionReport(req, token, &json, &json_len);
  52. else if (req.path.find("move_info") != -1)
  53. code = DealGetMoveInfo(req, token, &json, &json_len);
  54. else if (req.path.find("operation_log") != -1)
  55. code = DealGetOptLog(req, token, &json, &json_len);
  56. else if (req.path.find("refer_curve") != -1)
  57. code = DealGetrefer_curve(req, token, &json, &json_len);
  58. else if (req.path.find("refer_option") != -1)
  59. code = DealGetrefer_option(req, token, &json, &json_len);
  60. else if (req.path.find("reminder_interval") != -1)
  61. code = deal_get_reminder_interval(req, token, &json, &json_len);
  62. else if (req.path.find("resist_data") != -1)
  63. code = DealGetResistData(req, token, &json, &json_len);
  64. //else if (req.path.find("retention_data") != -1)
  65. // code = DealGetRetentionData(req, token, &json, &json_len);
  66. else if (req.path.find("resist_move") != -1)
  67. code = DealResistMove(req, token, &json, &json_len);
  68. else if (req.path.find("alarm_list") != -1)
  69. code = deal_get_alarm_list(req, body, &json, &json_len);
  70. else if (req.path.find("backend_type") != -1)
  71. {
  72. body = R"({"type":1})";
  73. code = 200;
  74. }
  75. else
  76. code = 405;
  77. }
  78. catch (...)
  79. {
  80. code = 500;
  81. }
  82. if (json)
  83. res.set_content(json, "application/json");
  84. if (!body.empty())
  85. res.set_content(body.c_str(), "application/json");
  86. auto cost = chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - start).count();
  87. //CSimpleLog::Info(fmt::format("[HTTP][GET][END] code:{} COST:{} {}:{} {} {}", code, cost, req.remote_addr, req.remote_port, req.target, json ? json : "").c_str());
  88. SPDLOG_INFO("[HTTP][GET][END] code:{} COST:{} {}:{} {}", code, cost, req.remote_addr, req.remote_port, req.target);
  89. res.set_header("cost", to_string(cost) + " ms");
  90. res.status = code;
  91. if (json) free(json);
  92. }
  93. //处理get请求总入口
  94. void DealHttpPost(const httplib::Request& req, httplib::Response& res)
  95. {
  96. int code = 500;
  97. auto start = chrono::steady_clock::now();
  98. auto token = req.get_header_value("token");
  99. if (token.length() == 0 || token.empty())
  100. token = req.get_header_value("Authorization");
  101. char* json = nullptr;
  102. size_t json_len = 0;
  103. //CSimpleLog::Info(fmt::format("[HTTP][POST][START] {}:{} {} body:{}", req.remote_addr, req.remote_port, req.path, req.body).c_str());
  104. SPDLOG_INFO("[HTTP][POST][START] {}:{} {} body:{}", req.remote_addr, req.remote_port, req.path, req.body);
  105. try
  106. {
  107. if (token.empty())
  108. {
  109. code = 401;
  110. }
  111. if (req.path.find("post_svg") != -1)
  112. code = DealPostSvgData(req, token, res);
  113. else if (req.path.find("option_svg") != -1)
  114. code = DealOptionSvgData(req, token, res);
  115. else if (req.path.find("commit_record") != -1)
  116. code = DealPostCommitRecord(req.body.c_str(), req.body.length(), token, &json, &json_len);
  117. else if (req.path.find("get_svg") != -1)
  118. code = DealGetSvgData(req, token, res);
  119. else if (req.path.find("post_soft") != -1)
  120. code = DealPostBinData(req, token, res);
  121. else if (req.path.find("conf_write/convert_resist") != -1)
  122. code = DealPostConvertResist(req.body.c_str(), req.body.length(), token, &json, &json_len);
  123. else if (req.path.find("conf_write/mitie_lock") != -1)
  124. code = DealPostMitieLock(req.body.c_str(), req.body.length(), token, &json, &json_len);
  125. else if (req.path.find("conf_write/retension_force") != -1)
  126. code = DealPosttRetesionForce(req.body.c_str(), req.body.length(), token, &json, &json_len);
  127. else if (req.path.find("refer_curve") != -1)
  128. code = DealPostrefer_curve(req.body.c_str(), req.body.length(), token, &json, &json_len);
  129. else if (req.path.find("reminder_interval") != -1)
  130. code = deal_post_reminder_interval(req.body.c_str(), req.body.length(), token, &json, &json_len);
  131. else
  132. code = 405;
  133. }
  134. catch (...)
  135. {
  136. code = 500;
  137. }
  138. if (json)
  139. res.set_content(json, "application/json");
  140. auto cost = chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - start).count();
  141. //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());
  142. SPDLOG_INFO("[HTTP][POST][END] code:{} COST:{} {}:{} {} body:{}", code, cost, req.remote_addr, req.remote_port, req.path, req.body);
  143. res.set_header("cost", to_string(cost) + " ms");
  144. res.status = code;
  145. if (json) free(json);
  146. }
  147. void DealHttpPut(const httplib::Request& req, httplib::Response& res)
  148. {
  149. int code = 500;
  150. auto start = chrono::steady_clock::now();
  151. auto token = req.get_header_value("token");
  152. if (token.length() == 0 || token.empty())
  153. token = req.get_header_value("Authorization");
  154. char* json = nullptr;
  155. size_t json_len = 0;
  156. SPDLOG_INFO("[HTTP][POST][START] {}:{} {} body:{}", req.remote_addr, req.remote_port, req.path, req.body);
  157. try
  158. {
  159. if (token.empty())
  160. {
  161. code = 401;
  162. }
  163. if (req.path.find("/data/zzjno") != -1)
  164. code = DealPutChangeZzjno(req.body.c_str(), req.body.length(), token, &json, &json_len);
  165. else
  166. code = 405;
  167. }
  168. catch (...)
  169. {
  170. code = 500;
  171. }
  172. if (json)
  173. res.set_content(json, "application/json");
  174. auto cost = chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - start).count();
  175. SPDLOG_INFO("[HTTP][POST][END] code:{} COST:{} {}:{} {} body:{}", code, cost, req.remote_addr, req.remote_port, req.path, req.body);
  176. res.set_header("cost", to_string(cost) + " ms");
  177. res.status = code;
  178. if (json) free(json);
  179. }
  180. int DealPostSvgData(const httplib::Request& req, const string token, httplib::Response& res)
  181. {
  182. if (token.find("AAAAAAAA") == -1) return 403;
  183. auto id = req.get_header_value("id");
  184. if (id.empty()) return 400;//参数错误
  185. char szID[200] = { 0 };
  186. utf82gbk(szID, 200, id.c_str(), id.length()); //处理中文
  187. if (req.body.empty()) return 400;
  188. CString strPath = CSimpleLog::GetAppDir() + "svg\\" + szID + ".svg";
  189. CFile file;
  190. if (file.Open(strPath, CFile::modeWrite | CFile::typeBinary | CFile::modeCreate))
  191. {
  192. file.Write(req.body.c_str(), req.body.length());
  193. file.Close();
  194. return 200;
  195. }
  196. else
  197. {
  198. return 500;
  199. }
  200. return 405;
  201. }
  202. int DealPostBinData(const httplib::Request& req, const string token, httplib::Response& res)
  203. {
  204. auto doc = yyjson_mut_doc_new(nullptr);
  205. auto root = yyjson_mut_obj(doc);
  206. yyjson_mut_doc_set_root(doc, root);
  207. char msg[100] = { 0 };
  208. int code = 500;
  209. string type;
  210. do
  211. {
  212. if (token.find("AAAAAAAA") == -1)
  213. {
  214. code = 403;
  215. gbk2utf8(msg, 100, "无权限");
  216. break;
  217. }
  218. auto IMEI = req.get_header_value("IMEI");
  219. if (IMEI.empty())
  220. {
  221. code = 400;
  222. gbk2utf8(msg, 100, "IMEI不能为空");
  223. break;
  224. }
  225. type = req.get_header_value("type");
  226. if (type.empty())
  227. {
  228. code = 400;
  229. gbk2utf8(msg, 100, "type不能为空");
  230. break;
  231. }
  232. if (req.body.empty())
  233. {
  234. code = 400;
  235. gbk2utf8(msg, 100, "body数据不能为空");
  236. break;
  237. }
  238. time_t tNow;
  239. time(&tNow);
  240. if (CAppService::Instance()->m_bHaveDeviceUpgrade && tNow - CAppService::Instance()->m_tDeviceUpgrade < 60)
  241. {
  242. code = 400;
  243. gbk2utf8(msg, 100, "目前有设备在升级中, 请等待.");
  244. break;
  245. }
  246. auto filesize = req.body.length();
  247. yyjson_mut_obj_add_int(doc, root, "filesize", filesize);
  248. auto filecrc = crc32buf(req.body.c_str(), filesize);
  249. yyjson_mut_obj_add_int(doc, root, "filecrc", filecrc);
  250. auto pData = new char[filesize * 2 + 2];
  251. CAppService::FileDataConvertCharData((uint8_t*)req.body.c_str(), filesize, pData);
  252. {
  253. auto& mapTypeData = CAppService::Instance()->m_mapTypeData;
  254. auto it = mapTypeData.find(type.c_str());
  255. int datalen = filesize * 2;
  256. if (it != mapTypeData.end())
  257. {
  258. it->second->Join();
  259. it->second = nullptr;
  260. }
  261. auto pInfo = new UPGRADE_FILE_DATA;
  262. mapTypeData[type.c_str()] = pInfo;
  263. pInfo->data = pData;
  264. pInfo->len = filesize * 2;
  265. pInfo->crc = filecrc;
  266. pData[datalen] = 0x00;
  267. pData[datalen + 1] = 0x00;
  268. }
  269. gbk2utf8(msg, 100, "数据接收成功");
  270. //通知设备
  271. auto notify_ret = CLNHandle::SendUpdateToDevice(IMEI.c_str(), req.remote_addr, type);
  272. if (notify_ret == 0)
  273. {
  274. code = 200;
  275. gbk2utf8(msg, 100, "数据接收成功, 且下发数据成功!");
  276. }
  277. else if (notify_ret == 1)
  278. {
  279. code = 400;
  280. gbk2utf8(msg, 100, "未找到设备或者设备未在线!");
  281. }
  282. else if (notify_ret == 2)
  283. {
  284. code = 500;
  285. gbk2utf8(msg, 100, "数据接收成功, 但下发数据失败!");
  286. }
  287. } while (false);
  288. yyjson_mut_obj_add_strcpy(doc, root, "type", type.c_str());
  289. yyjson_mut_obj_add_int(doc, root, "code", code);
  290. yyjson_mut_obj_add_str(doc, root, "msg", msg);
  291. size_t len;
  292. auto json = yyjson_mut_write(doc, 0, &len);
  293. if (json)
  294. {
  295. res.set_content(json, len, "application/json");
  296. free((void*)json);
  297. }
  298. yyjson_mut_doc_free(doc);
  299. return code;
  300. }
  301. int DealGetSvgData(const httplib::Request& req, const string token, httplib::Response& res)
  302. {
  303. auto id = req.get_param_value("id");
  304. if (id.empty()) return 400;//参数错误
  305. char szID[200] = { 0 };
  306. utf82gbk(szID, 200, id.c_str(), id.length()); //处理中文
  307. CString strPath = CSimpleLog::GetAppDir() + "svg\\" + szID + ".svg";
  308. auto bExist = CSimpleLog::PathFileExists(strPath);
  309. if (bExist == false) return 404;
  310. CFile file;
  311. if (file.Open(strPath, CFile::modeRead | CFile::typeBinary))
  312. {
  313. int len = file.GetLength();
  314. auto pData = new uint8_t[len];
  315. file.Read(pData, len);
  316. file.Close();
  317. res.set_content((char*)pData, len, "image/svg+xml");
  318. }
  319. else
  320. {
  321. return 500;
  322. }
  323. return 200;
  324. }
  325. int DealOptionSvgData(const httplib::Request& req, const string token, httplib::Response& res)
  326. {
  327. auto id = req.get_param_value("id");
  328. if (id.empty()) return 400;//参数错误
  329. char szID[200] = { 0 };
  330. utf82gbk(szID, 200, id.c_str(), id.length()); //处理中文
  331. //auto doc = yyjson_mut_doc_new(nullptr);
  332. //auto root = yyjson_mut_obj(doc);
  333. //yyjson_mut_doc_set_root(doc, root);
  334. //yyjson_mut_obj_add_bool(doc, root, "result", CSimpleLog::PathFileExists(CSimpleLog::GetAppDir() + id.c_str()));
  335. //size_t len;
  336. //auto json = yyjson_mut_write(doc, 0, &len);
  337. //res.set_content(json, len, "application/json");
  338. //if (json)
  339. //{
  340. // free((void*)json);
  341. // json = nullptr;
  342. //}
  343. //yyjson_mut_doc_free(doc);
  344. CString strPath = CSimpleLog::GetAppDir() + "svg\\" + szID + ".svg";
  345. auto bExist = CSimpleLog::PathFileExists(strPath);
  346. string strResult;
  347. if (bExist)
  348. strResult = R"({"result":true})";
  349. else
  350. strResult = R"({"result":false})";
  351. res.set_content(strResult, "application/json");
  352. return 200;
  353. }
  354. int DealGetMpStat(const httplib::Request& req, const string token, httplib::Response& res)
  355. {
  356. auto id = req.get_param_value("id");//杭南杭甬场
  357. if (id.empty()) return 400;//参数错误
  358. char gbk[200];
  359. int id_len = utf82gbk(gbk, 200, id.c_str(), id.length());
  360. auto pObject = CMonitorObjectMng::Instance()->GetTreeByID(string(gbk));
  361. if (nullptr == pObject) return 404;
  362. if (pObject->type.compare("station") != 0) return 400;
  363. auto doc = yyjson_mut_doc_new(nullptr);
  364. auto root = yyjson_mut_arr(doc);
  365. yyjson_mut_doc_set_root(doc, root);
  366. for (const auto& it : pObject->m_lstMo)
  367. {
  368. auto arr = yyjson_mut_arr(doc);
  369. yyjson_mut_arr_add_val(root, arr);
  370. yyjson_mut_arr_add_strcpy(doc, arr, it->id.c_str());
  371. yyjson_mut_arr_add_strcpy(doc, arr, it->name.c_str());
  372. string imei; int idx;
  373. CMonitorObjectMng::Instance()->MOMP2IMEI(it->id, imei, idx);
  374. if (imei.length())
  375. {
  376. string mo, mp;
  377. if (CMonitorObjectMng::spiltByPoint(it->id, mo, mp))
  378. {
  379. SYSTEMTIME stAlarm = { 0 };
  380. auto ty = CResistAlarmMng::Instance()->GetAlarmStat(mo, mp, stAlarm);
  381. if (ty == eZL_MP_STAT::MP_STAT_OFFLINE_GRAY || ty == eZL_MP_STAT::MP_STAT_UNKNOW)
  382. {
  383. if (CDeviceMng::Instance()->IsDeviceOnline(imei, idx))
  384. yyjson_mut_arr_add_int(doc, arr, (int)eZL_MP_STAT::MP_STAT_NORMAL_GREEN);
  385. else
  386. yyjson_mut_arr_add_int(doc, arr, (int)eZL_MP_STAT::MP_STAT_OFFLINE_GRAY);
  387. }
  388. else
  389. {
  390. yyjson_mut_arr_add_int(doc, arr, (int)ty);
  391. 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);
  392. yyjson_mut_arr_add_strcpy(doc, arr, gbk);
  393. }
  394. }
  395. else
  396. {
  397. yyjson_mut_arr_add_int(doc, arr, (int)eZL_MP_STAT::MP_STAT_UNINSTALL_WHITE);
  398. }
  399. }
  400. else
  401. {
  402. yyjson_mut_arr_add_int(doc, arr, (int)eZL_MP_STAT::MP_STAT_UNINSTALL_WHITE);
  403. }
  404. }
  405. size_t len;
  406. auto json = yyjson_mut_write(doc, 0, &len);
  407. res.set_content(json, len, "application/json");
  408. if (json)
  409. {
  410. free((void*)json);
  411. json = nullptr;
  412. }
  413. yyjson_mut_doc_free(doc);
  414. return 200;
  415. }
  416. int DealGetMitieLock(const httplib::Request& req, const string token, char** json, size_t* json_len)
  417. {
  418. string mo = req.get_param_value("mo");
  419. string mp = req.get_param_value("mp");
  420. eSuoBiPosi posi = (eSuoBiPosi)atoi(req.get_param_value("posi").c_str());
  421. if (posi == eSuoBiPosi::SB_ZERO) posi = eSuoBiPosi::SB_UNKNOWN;
  422. if (mo.length() == 0 || mp.length() == 0)
  423. return 400;
  424. auto doc = yyjson_mut_doc_new(nullptr);
  425. auto root = yyjson_mut_obj(doc);
  426. yyjson_mut_doc_set_root(doc, root);
  427. SUOBI_OVER_LIMIT_INFO* pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)posi, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
  428. if (pInfo)
  429. {
  430. yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
  431. if (pInfo->alarm_low_limit > INT_MIN)
  432. yyjson_mut_obj_add_int(doc, root, "alarm_low_limit", pInfo->alarm_low_limit);
  433. else
  434. yyjson_mut_obj_add_null(doc, root, "alarm_low_limit");
  435. if (pInfo->warn_low_limit > INT_MIN)
  436. yyjson_mut_obj_add_int(doc, root, "warn_low_limit", pInfo->warn_low_limit);
  437. else
  438. yyjson_mut_obj_add_null(doc, root, "warn_low_limit");
  439. if (pInfo->alarm_high_limit < INT_MAX)
  440. yyjson_mut_obj_add_int(doc, root, "alarm_high_limit", pInfo->alarm_high_limit);
  441. else
  442. yyjson_mut_obj_add_null(doc, root, "alarm_high_limit");
  443. if (pInfo->warn_high_limit < INT_MAX)
  444. yyjson_mut_obj_add_int(doc, root, "warn_high_limit", pInfo->warn_high_limit);
  445. else
  446. yyjson_mut_obj_add_null(doc, root, "warn_high_limit");
  447. }
  448. else
  449. {
  450. yyjson_mut_obj_add_bool(doc, root, "enable", false);
  451. yyjson_mut_obj_add_null(doc, root, "alarm_low_limit");
  452. yyjson_mut_obj_add_null(doc, root, "warn_low_limit");
  453. yyjson_mut_obj_add_null(doc, root, "alarm_high_limit");
  454. yyjson_mut_obj_add_null(doc, root, "warn_high_limit");
  455. }
  456. *json = yyjson_mut_write(doc, 0, json_len);
  457. yyjson_mut_doc_free(doc);
  458. return 200;
  459. }
  460. int DealPostMitieLock(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len)
  461. {
  462. int code = 400;
  463. auto req_doc = yyjson_read(body_ptr, body_len, 0);
  464. if (req_doc == nullptr) return 400;
  465. auto req_root = yyjson_doc_get_root(req_doc);
  466. do
  467. {
  468. auto mo = yyjson_get_str(yyjson_obj_get(req_root, "mo"));
  469. auto mp = yyjson_get_str(yyjson_obj_get(req_root, "mp"));
  470. eSuoBiPosi posi = (eSuoBiPosi)yyjson_get_int(yyjson_obj_get(req_root, "posi"));;//预留
  471. if (posi == eSuoBiPosi::SB_ZERO) posi = eSuoBiPosi::SB_UNKNOWN;
  472. auto conf = yyjson_obj_get(req_root, "conf");
  473. if (mo == nullptr || mp == nullptr || conf == nullptr)
  474. break;
  475. auto doc = yyjson_mut_doc_new(nullptr);
  476. auto root = yyjson_mut_obj(doc);
  477. yyjson_mut_doc_set_root(doc, root);
  478. size_t len;
  479. char* str_conf = nullptr;
  480. //更新内存里
  481. SUOBI_OVER_LIMIT_INFO* pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)posi, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
  482. CString sql;
  483. if (pInfo == nullptr)
  484. {
  485. SUOBI_OVER_LIMIT_INFO* pInfo = new SUOBI_OVER_LIMIT_INFO;
  486. pInfo->type = eZL_ALARMTYPE::SUOBI_LOCK_LIMIT;
  487. pInfo->no = (uint8_t)posi;
  488. pInfo->enable = yyjson_get_bool(yyjson_obj_get(conf, "enable"));
  489. yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
  490. {
  491. auto val = yyjson_obj_get(conf, "alarm_low_limit");
  492. if (val && yyjson_is_int(val))
  493. pInfo->alarm_low_limit = yyjson_get_int(val);
  494. yyjson_mut_obj_add_int(doc, root, "alarm_low_limit", pInfo->alarm_low_limit);
  495. }
  496. {
  497. auto val = yyjson_obj_get(conf, "warn_low_limit");
  498. if (val && yyjson_is_int(val))
  499. pInfo->warn_low_limit = yyjson_get_int(val);
  500. yyjson_mut_obj_add_int(doc, root, "warn_low_limit", pInfo->warn_low_limit);
  501. }
  502. {
  503. auto val = yyjson_obj_get(conf, "alarm_high_limit");
  504. if (val && yyjson_is_int(val))
  505. pInfo->alarm_high_limit = yyjson_get_int(val);
  506. yyjson_mut_obj_add_int(doc, root, "alarm_high_limit", pInfo->alarm_high_limit);
  507. }
  508. {
  509. auto val = yyjson_obj_get(conf, "warn_high_limit");
  510. if (val && yyjson_is_int(val))
  511. pInfo->warn_high_limit = yyjson_get_int(val);
  512. yyjson_mut_obj_add_int(doc, root, "warn_high_limit", pInfo->warn_high_limit);
  513. }
  514. str_conf = yyjson_mut_write(doc, 0, &len);
  515. yyjson_mut_doc_free(doc);
  516. CResistAlarmMng::Instance()->Insert(mo, mp, (uint8_t)posi, (uint8_t)eZL_ALARMTYPE::SUOBI_LOCK_LIMIT, pInfo);
  517. time_t tt;
  518. time(&tt);
  519. sql.Format("INSERT INTO [rm_alarm_set]([mo],[mp],[no],[type],[conf],[time]) VALUES ('%s','%s',%d, %d,'%s','%I64u')",
  520. mo, mp, (uint8_t)posi, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT, str_conf, tt);
  521. }
  522. else
  523. {
  524. pInfo->enable = yyjson_get_bool(yyjson_obj_get(conf, "enable"));
  525. yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
  526. {
  527. auto val = yyjson_obj_get(conf, "alarm_low_limit");
  528. if (val && yyjson_is_int(val))
  529. pInfo->alarm_low_limit = yyjson_get_int(val);
  530. else
  531. pInfo->alarm_low_limit = INT_MIN;
  532. yyjson_mut_obj_add_int(doc, root, "alarm_low_limit", pInfo->alarm_low_limit);
  533. }
  534. {
  535. auto val = yyjson_obj_get(conf, "warn_low_limit");
  536. if (val && yyjson_is_int(val))
  537. pInfo->warn_low_limit = yyjson_get_int(val);
  538. else
  539. pInfo->warn_low_limit = INT_MIN;
  540. yyjson_mut_obj_add_int(doc, root, "warn_low_limit", pInfo->warn_low_limit);
  541. }
  542. {
  543. auto val = yyjson_obj_get(conf, "alarm_high_limit");
  544. if (val && yyjson_is_int(val))
  545. pInfo->alarm_high_limit = yyjson_get_int(val);
  546. else
  547. pInfo->alarm_high_limit = INT_MAX;
  548. yyjson_mut_obj_add_int(doc, root, "alarm_high_limit", pInfo->alarm_high_limit);
  549. }
  550. {
  551. auto val = yyjson_obj_get(conf, "warn_high_limit");
  552. if (val && yyjson_is_int(val))
  553. pInfo->warn_high_limit = yyjson_get_int(val);
  554. else
  555. pInfo->warn_high_limit = INT_MAX;
  556. yyjson_mut_obj_add_int(doc, root, "warn_high_limit", pInfo->warn_high_limit);
  557. }
  558. str_conf = yyjson_mut_write(doc, 0, &len);
  559. yyjson_mut_doc_free(doc);
  560. sql.Format("update rm_alarm_set SET conf = '%s' WHERE mo = '%s' and mp = '%s' and no = %d and type = %d",
  561. str_conf, mo, mp, (uint8_t)posi, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
  562. }
  563. if (str_conf) free(str_conf);
  564. if (CDBConnectPool::Instance()->DBExecuteSQL(sql) == FALSE)
  565. {
  566. ASSERT(FALSE);
  567. CSimpleLog::Error("语句执行失败" + sql);
  568. code = 500;
  569. break;
  570. }
  571. code = 200;
  572. } while (false);
  573. yyjson_doc_free(req_doc);
  574. return code;
  575. }
  576. int DealGetConvertResist(const httplib::Request& req, const string token, char** json, size_t* json_len)
  577. {
  578. string mo = req.get_param_value("mo");
  579. string mp = req.get_param_value("mp");
  580. if (mo.length() == 0 || mp.length() == 0)
  581. return 400;
  582. auto doc = yyjson_mut_doc_new(nullptr);
  583. auto root = yyjson_mut_obj(doc);
  584. yyjson_mut_doc_set_root(doc, root);
  585. CONVERT_RESIST_OVER_LIMIT* pInfo = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
  586. if (pInfo)
  587. {
  588. yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
  589. if (pInfo->dw_alarm_low_limit > INT_MIN)
  590. yyjson_mut_obj_add_int(doc, root, "dw_alarm_low_limit", pInfo->dw_alarm_low_limit);
  591. else
  592. yyjson_mut_obj_add_null(doc, root, "dw_alarm_low_limit");
  593. if (pInfo->dw_warn_low_limit > INT_MIN)
  594. yyjson_mut_obj_add_int(doc, root, "dw_warn_low_limit", pInfo->dw_warn_low_limit);
  595. else
  596. yyjson_mut_obj_add_null(doc, root, "dw_warn_low_limit");
  597. if (pInfo->up_alarm_high_limit < INT_MAX)
  598. yyjson_mut_obj_add_int(doc, root, "up_alarm_high_limit", pInfo->up_alarm_high_limit);
  599. else
  600. yyjson_mut_obj_add_null(doc, root, "up_alarm_high_limit");
  601. if (pInfo->up_warn_high_limit < INT_MAX)
  602. yyjson_mut_obj_add_int(doc, root, "up_warn_high_limit", pInfo->up_warn_high_limit);
  603. else
  604. yyjson_mut_obj_add_null(doc, root, "up_warn_high_limit");
  605. }
  606. else
  607. {
  608. yyjson_mut_obj_add_bool(doc, root, "enable", false);
  609. yyjson_mut_obj_add_null(doc, root, "dw_alarm_low_limit");
  610. yyjson_mut_obj_add_null(doc, root, "dw_warn_low_limit");
  611. yyjson_mut_obj_add_null(doc, root, "up_alarm_high_limit");
  612. yyjson_mut_obj_add_null(doc, root, "up_warn_high_limit");
  613. }
  614. *json = yyjson_mut_write(doc, 0, json_len);
  615. yyjson_mut_doc_free(doc);
  616. return 200;
  617. }
  618. int DealGetRetesionForce(const httplib::Request& req, const string token, char** json, size_t* json_len)
  619. {
  620. string mo = req.get_param_value("mo");
  621. string mp = req.get_param_value("mp");
  622. string posi = req.get_param_value("posi");
  623. if (mo.length() == 0 || mp.length() == 0 || posi.length() == 0)
  624. return 400;
  625. eSuoBiPosi no = (eSuoBiPosi)atoi(posi.c_str());
  626. auto doc = yyjson_mut_doc_new(nullptr);
  627. auto root = yyjson_mut_obj(doc);
  628. yyjson_mut_doc_set_root(doc, root);
  629. RETENSION_FORCE_DROP* pInfo = (RETENSION_FORCE_DROP*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)no, eZL_ALARMTYPE::RETENSION_FORCE);
  630. if (pInfo)
  631. {
  632. yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
  633. if (pInfo->dw_alarm_low_drop > INT_MIN)
  634. yyjson_mut_obj_add_int(doc, root, "dw_alarm_low_drop", pInfo->dw_alarm_low_drop);
  635. else
  636. yyjson_mut_obj_add_null(doc, root, "dw_alarm_low_drop");
  637. if (pInfo->alarm_low_percent > INT_MIN)
  638. yyjson_mut_obj_add_int(doc, root, "alarm_low_percent", pInfo->alarm_low_percent);
  639. else
  640. yyjson_mut_obj_add_null(doc, root, "alarm_low_percent");
  641. if (pInfo->alarm_high_percent > INT_MIN)
  642. yyjson_mut_obj_add_int(doc, root, "alarm_high_percent", pInfo->alarm_high_percent);
  643. else
  644. yyjson_mut_obj_add_null(doc, root, "alarm_high_percent");
  645. }
  646. else
  647. {
  648. yyjson_mut_obj_add_bool(doc, root, "enable", false);
  649. yyjson_mut_obj_add_null(doc, root, "dw_alarm_low_drop");
  650. yyjson_mut_obj_add_null(doc, root, "alarm_low_percent");
  651. yyjson_mut_obj_add_null(doc, root, "alarm_high_percent");
  652. }
  653. *json = yyjson_mut_write(doc, 0, json_len);
  654. yyjson_mut_doc_free(doc);
  655. return 200;
  656. }
  657. int DealPostConvertResist(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len)
  658. {
  659. int code = 400;
  660. auto req_doc = yyjson_read(body_ptr, body_len, 0);
  661. if (req_doc == nullptr) return 400;
  662. auto req_root = yyjson_doc_get_root(req_doc);
  663. do
  664. {
  665. auto mo = yyjson_get_str(yyjson_obj_get(req_root, "mo"));
  666. auto mp = yyjson_get_str(yyjson_obj_get(req_root, "mp"));
  667. auto conf = yyjson_obj_get(req_root, "conf");
  668. if (mo == nullptr || mp == nullptr || conf == nullptr)
  669. break;
  670. auto doc = yyjson_mut_doc_new(nullptr);
  671. auto root = yyjson_mut_obj(doc);
  672. yyjson_mut_doc_set_root(doc, root);
  673. size_t len;
  674. char* str_conf = nullptr;
  675. //更新内存里
  676. CONVERT_RESIST_OVER_LIMIT* pInfo = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
  677. CString sql;
  678. if (pInfo == nullptr)
  679. {
  680. CONVERT_RESIST_OVER_LIMIT* pInfo = new CONVERT_RESIST_OVER_LIMIT;
  681. pInfo->type = eZL_ALARMTYPE::CONVERT_LIMIT;
  682. pInfo->no = 2;
  683. pInfo->enable = yyjson_get_bool(yyjson_obj_get(conf, "enable"));
  684. yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
  685. {
  686. auto val = yyjson_obj_get(conf, "dw_alarm_low_limit");
  687. if (val && yyjson_is_int(val))
  688. pInfo->dw_alarm_low_limit = yyjson_get_int(val);
  689. yyjson_mut_obj_add_int(doc, root, "dw_alarm_low_limit", pInfo->dw_alarm_low_limit);
  690. }
  691. {
  692. auto val = yyjson_obj_get(conf, "dw_warn_low_limit");
  693. if (val && yyjson_is_int(val))
  694. pInfo->dw_warn_low_limit = yyjson_get_int(val);
  695. yyjson_mut_obj_add_int(doc, root, "dw_warn_low_limit", pInfo->dw_warn_low_limit);
  696. }
  697. {
  698. auto val = yyjson_obj_get(conf, "up_alarm_high_limit");
  699. if (val && yyjson_is_int(val))
  700. pInfo->up_alarm_high_limit = yyjson_get_int(val);
  701. yyjson_mut_obj_add_int(doc, root, "up_alarm_high_limit", pInfo->up_alarm_high_limit);
  702. }
  703. {
  704. auto val = yyjson_obj_get(conf, "up_warn_high_limit");
  705. if (val && yyjson_is_int(val))
  706. pInfo->up_warn_high_limit = yyjson_get_int(val);
  707. yyjson_mut_obj_add_int(doc, root, "up_warn_high_limit", pInfo->up_warn_high_limit);
  708. }
  709. str_conf = yyjson_mut_write(doc, 0, &len);
  710. yyjson_mut_doc_free(doc);
  711. CResistAlarmMng::Instance()->Insert(mo, mp, 2, (uint8_t)eZL_ALARMTYPE::CONVERT_LIMIT, pInfo);
  712. sql.Format("INSERT INTO [rm_alarm_set]([mo],[mp],[no],[type],[conf],[time]) VALUES ('%s','%s',%d,%d,'%s','%I64u')",
  713. mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT, str_conf, 0);
  714. }
  715. else
  716. {
  717. pInfo->enable = yyjson_get_bool(yyjson_obj_get(conf, "enable"));
  718. yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
  719. {
  720. auto val = yyjson_obj_get(conf, "dw_alarm_low_limit");
  721. if (val && yyjson_is_int(val))
  722. pInfo->dw_alarm_low_limit = yyjson_get_int(val);
  723. else
  724. pInfo->dw_alarm_low_limit = INT_MIN;
  725. yyjson_mut_obj_add_int(doc, root, "dw_alarm_low_limit", pInfo->dw_alarm_low_limit);
  726. }
  727. {
  728. auto val = yyjson_obj_get(conf, "dw_warn_low_limit");
  729. if (val && yyjson_is_int(val))
  730. pInfo->dw_warn_low_limit = yyjson_get_int(val);
  731. else
  732. pInfo->dw_warn_low_limit = INT_MIN;
  733. yyjson_mut_obj_add_int(doc, root, "dw_warn_low_limit", pInfo->dw_warn_low_limit);
  734. }
  735. {
  736. auto val = yyjson_obj_get(conf, "up_alarm_high_limit");
  737. if (val && yyjson_is_int(val))
  738. pInfo->up_alarm_high_limit = yyjson_get_int(val);
  739. else
  740. pInfo->up_alarm_high_limit = INT_MAX;
  741. yyjson_mut_obj_add_int(doc, root, "up_alarm_high_limit", pInfo->up_alarm_high_limit);
  742. }
  743. {
  744. auto val = yyjson_obj_get(conf, "up_warn_high_limit");
  745. if (val && yyjson_is_int(val))
  746. pInfo->up_warn_high_limit = yyjson_get_int(val);
  747. else
  748. pInfo->up_warn_high_limit = INT_MAX;
  749. yyjson_mut_obj_add_int(doc, root, "up_warn_high_limit", pInfo->up_warn_high_limit);
  750. }
  751. str_conf = yyjson_mut_write(doc, 0, &len);
  752. yyjson_mut_doc_free(doc);
  753. sql.Format("update rm_alarm_set SET conf = '%s' WHERE mo = '%s' and mp = '%s' and no = %d and type = %d",
  754. str_conf, mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
  755. }
  756. if (str_conf) free(str_conf);
  757. if (CDBConnectPool::Instance()->DBExecuteSQL(sql) == FALSE)
  758. {
  759. ASSERT(FALSE);
  760. CSimpleLog::Error("语句执行失败" + sql);
  761. code = 500;
  762. break;
  763. }
  764. code = 200;
  765. } while (false);
  766. yyjson_doc_free(req_doc);
  767. return code;
  768. }
  769. int DealPosttRetesionForce(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len)
  770. {
  771. int code = 400;
  772. auto req_doc = yyjson_read(body_ptr, body_len, 0);
  773. if (req_doc == nullptr) return 400;
  774. string msg;
  775. auto req_root = yyjson_doc_get_root(req_doc);
  776. do
  777. {
  778. auto mo = yyjson_get_str(yyjson_obj_get(req_root, "mo"));
  779. auto mp = yyjson_get_str(yyjson_obj_get(req_root, "mp"));
  780. auto posi= yyjson_get_int(yyjson_obj_get(req_root, "posi"));
  781. auto conf = yyjson_obj_get(req_root, "conf");
  782. if (mo == nullptr || mp == nullptr || conf == nullptr || posi == 0)
  783. break;
  784. auto doc = yyjson_mut_doc_new(nullptr);
  785. auto root = yyjson_mut_obj(doc);
  786. yyjson_mut_doc_set_root(doc, root);
  787. size_t len;
  788. char* str_conf = nullptr;
  789. //更新内存里
  790. RETENSION_FORCE_DROP* pInfo = (RETENSION_FORCE_DROP*)CResistAlarmMng::Instance()->Find(mo, mp, posi, eZL_ALARMTYPE::RETENSION_FORCE);
  791. CString sql;
  792. if (pInfo == nullptr/* && pInfo->dw_alarm_low_drop == INT_MIN*/)
  793. {
  794. RETENSION_FORCE_DROP* pInfo = new RETENSION_FORCE_DROP;
  795. pInfo->type = eZL_ALARMTYPE::RETENSION_FORCE;
  796. pInfo->no = posi;
  797. pInfo->enable = yyjson_get_bool(yyjson_obj_get(conf, "enable"));
  798. yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
  799. {
  800. auto val = yyjson_obj_get(conf, "dw_alarm_low_drop");
  801. if (val && yyjson_is_int(val))
  802. pInfo->dw_alarm_low_drop = yyjson_get_int(val);
  803. else
  804. pInfo->dw_alarm_low_drop = INT_MIN;
  805. yyjson_mut_obj_add_int(doc, root, "dw_alarm_low_drop", pInfo->dw_alarm_low_drop);
  806. }
  807. {
  808. auto val = yyjson_obj_get(conf, "alarm_high_percent");
  809. if (val && yyjson_is_int(val))
  810. pInfo->alarm_high_percent = yyjson_get_int(val);
  811. else
  812. pInfo->alarm_high_percent = INT_MIN;
  813. yyjson_mut_obj_add_int(doc, root, "alarm_high_percent", pInfo->alarm_high_percent);
  814. }
  815. {
  816. auto val = yyjson_obj_get(conf, "alarm_low_percent");
  817. if (val && yyjson_is_int(val))
  818. pInfo->alarm_low_percent = yyjson_get_int(val);
  819. else
  820. pInfo->alarm_low_percent = INT_MIN;
  821. yyjson_mut_obj_add_int(doc, root, "alarm_low_percent", pInfo->alarm_low_percent);
  822. }
  823. str_conf = yyjson_mut_write(doc, 0, &len);
  824. yyjson_mut_doc_free(doc);
  825. CResistAlarmMng::Instance()->Insert(mo, mp, posi, (uint8_t)eZL_ALARMTYPE::RETENSION_FORCE, pInfo);
  826. time_t tt;
  827. time(&tt);
  828. sql.Format("INSERT INTO [rm_alarm_set]([mo],[mp],[no],[type],[conf],[time]) VALUES ('%s','%s',%d, %d,'%s','%I64u')",
  829. mo, mp, posi, eZL_ALARMTYPE::RETENSION_FORCE, str_conf, tt);
  830. }
  831. else
  832. {
  833. pInfo->enable = yyjson_get_bool(yyjson_obj_get(conf, "enable"));
  834. yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
  835. {
  836. auto val = yyjson_obj_get(conf, "dw_alarm_low_drop");
  837. if (val && yyjson_is_int(val))
  838. pInfo->dw_alarm_low_drop = yyjson_get_int(val);
  839. else
  840. pInfo->dw_alarm_low_drop = INT_MIN;
  841. yyjson_mut_obj_add_int(doc, root, "dw_alarm_low_drop", pInfo->dw_alarm_low_drop);
  842. }
  843. {
  844. auto val = yyjson_obj_get(conf, "alarm_high_percent");
  845. if (val && yyjson_is_int(val))
  846. pInfo->alarm_high_percent = yyjson_get_int(val);
  847. else
  848. pInfo->alarm_high_percent = INT_MIN;
  849. yyjson_mut_obj_add_int(doc, root, "alarm_high_percent", pInfo->alarm_high_percent);
  850. }
  851. {
  852. auto val = yyjson_obj_get(conf, "alarm_low_percent");
  853. if (val && yyjson_is_int(val))
  854. pInfo->alarm_low_percent = yyjson_get_int(val);
  855. else
  856. pInfo->alarm_low_percent = INT_MIN;
  857. yyjson_mut_obj_add_int(doc, root, "alarm_low_percent", pInfo->alarm_low_percent);
  858. }
  859. str_conf = yyjson_mut_write(doc, 0, &len);
  860. yyjson_mut_doc_free(doc);
  861. sql.Format("update rm_alarm_set SET conf = '%s' WHERE mo = '%s' and mp = '%s' and no = %d and type = %d",
  862. str_conf, mo, mp, posi, eZL_ALARMTYPE::RETENSION_FORCE);
  863. }
  864. if (str_conf) free(str_conf);
  865. if (CDBConnectPool::Instance()->DBExecuteSQL(sql) == FALSE)
  866. {
  867. ASSERT(FALSE);
  868. msg = "语句执行失败" + sql;
  869. CSimpleLog::Error(msg.c_str());
  870. code = 500;
  871. break;
  872. }
  873. code = 200;
  874. } while (false);
  875. yyjson_doc_free(req_doc);
  876. return code;
  877. }
  878. int DealPostCommitRecord(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len)
  879. {
  880. int code = 400;
  881. string msg;
  882. auto req_doc = yyjson_read(body_ptr, body_len, 0);
  883. if (req_doc == nullptr) return 400;
  884. auto req_root = yyjson_doc_get_root(req_doc);
  885. do
  886. {
  887. if (yyjson_is_arr(req_root) == false) break;
  888. auto doc = yyjson_mut_doc_new(nullptr);
  889. auto root = yyjson_mut_obj(doc);
  890. yyjson_mut_doc_set_root(doc, root);
  891. size_t n = yyjson_arr_size(req_root);
  892. auto req_obj = yyjson_arr_get_first(req_root);
  893. for (size_t i = 0; i < n; i++)
  894. {
  895. auto module = yyjson_get_int(yyjson_obj_get(req_obj, "module"));
  896. auto dura = yyjson_get_int(yyjson_obj_get(req_obj, "dura"));
  897. auto analyze_type = yyjson_get_int(yyjson_obj_get(req_obj, "analyze_type"));
  898. auto station = yyjson_get_str(yyjson_obj_get(req_obj, "station"));
  899. auto station_name = yyjson_get_str(yyjson_obj_get(req_obj, "station_name"));
  900. auto mo = yyjson_get_str(yyjson_obj_get(req_obj, "mo"));
  901. auto mo_name = yyjson_get_str(yyjson_obj_get(req_obj, "mo_name"));
  902. auto mp = yyjson_get_str(yyjson_obj_get(req_obj, "mp"));
  903. auto mp_name = yyjson_get_str(yyjson_obj_get(req_obj, "mp_name"));
  904. auto start_time = yyjson_get_uint(yyjson_obj_get(req_obj, "start_time"));
  905. auto end_time = yyjson_get_uint(yyjson_obj_get(req_obj, "end_time"));
  906. time_t tt;
  907. time(&tt);
  908. auto name = yyjson_get_str(yyjson_obj_get(req_obj, "name"));
  909. auto username = yyjson_get_str(yyjson_obj_get(req_obj, "username"));
  910. if (module == 0 || dura == 0 || station == nullptr ||
  911. station_name == nullptr || start_time == 0 || name == nullptr)
  912. break;
  913. auto strStation = UTF8toANSI(station);
  914. auto strStationName = UTF8toANSI(station_name);
  915. auto strName = UTF8toANSI(name);
  916. CString strDuraTime;
  917. dura = dura / 1000.0 + 0.5;
  918. if (dura / 60)
  919. strDuraTime.Format(" 时长:%d分%d秒", dura / 60, dura % 60);
  920. else if (dura)
  921. strDuraTime.Format(" 时长:%d秒", dura);
  922. //CString sql = fmt::format("INSERT INTO [dbo].[rm_record]\
  923. //(module, dura, analyze_type, station\
  924. // , station_name, mo, mo_name, mp, mp_name, start_time\
  925. // , end_time, time, name,username,opt,mark) VALUES\
  926. //({}, {}, {}, '{}', '{}'\
  927. //, '{}', '{}', '{}', '{}', {}\
  928. //, {}, {}, '{}', '{}',{}, '{}')",
  929. // module, dura, analyze_type, strStation, strStationName,
  930. // IS_NULL(mo), IS_NULL(mo_name), IS_NULL(mp), IS_NULL(mp_name), start_time,
  931. // end_time, tt, strName, IS_NULL(username), 1, strDuraTime).c_str();
  932. //if (CDBConnectPool::Instance()->DBExecuteSQL(sql) == FALSE)
  933. //{
  934. // ASSERT(FALSE);
  935. // msg = "语句执行失败:" + sql;
  936. // CSimpleLog::Error(msg.c_str());
  937. // code = 500;
  938. // break;
  939. //}
  940. //else
  941. //{
  942. // code = 200;
  943. //}
  944. 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));
  945. req_obj = unsafe_yyjson_get_next(req_obj);
  946. }
  947. yyjson_mut_obj_add_strcpy(doc, root, "msg", ANSItoUTF8(msg).c_str());
  948. yyjson_mut_obj_add_int(doc, root, "code", code);
  949. if (json) *json = yyjson_mut_write(doc, 0, json_len);
  950. } while (false);
  951. yyjson_doc_free(req_doc);
  952. return code;
  953. }
  954. int DealGetOptLog(const httplib::Request& req, const string token, char** json, size_t* json_len)
  955. {
  956. string station_name = req.get_param_value("station_name");
  957. string time = req.get_param_value("time");
  958. string end_time = req.get_param_value("end_time");
  959. if (time.length() == 0 )
  960. return 400;
  961. time_t uTime = atoll(time.c_str());
  962. time_t uEndTime = atoll(end_time.c_str());
  963. if (uEndTime == 0) uEndTime = uTime + 86400;
  964. COleDateTime odt(uTime);
  965. if (odt.GetStatus() == COleDateTime::invalid)
  966. return 400;
  967. string str_station_name = UTF8toANSI(station_name);
  968. int code = 400;
  969. string msg;
  970. auto doc = yyjson_mut_doc_new(nullptr);
  971. auto root = yyjson_mut_obj(doc);
  972. yyjson_mut_doc_set_root(doc, root);
  973. auto yy_data = yyjson_mut_arr(doc);
  974. auto yy_name = yyjson_mut_arr(doc);
  975. auto yy_mo = yyjson_mut_arr(doc);
  976. auto yy_mp = yyjson_mut_arr(doc);
  977. yyjson_mut_obj_add_val(doc, root, "data", yy_data);
  978. yyjson_mut_obj_add_val(doc, root, "name", yy_name);
  979. yyjson_mut_obj_add_val(doc, root, "mo_name", yy_mo);
  980. yyjson_mut_obj_add_val(doc, root, "mp_name", yy_mp);
  981. //query
  982. //查询数据库
  983. std::map<string, uint16_t> map_name;
  984. std::map<string, uint16_t> map_mo_name;
  985. std::map<string, uint16_t> map_mp_name;
  986. {
  987. //station,station_name,
  988. CString sql;
  989. if (str_station_name.length() == 0)
  990. 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\
  991. FROM rm_record WHERE time between {} AND {}",
  992. uTime, uEndTime).c_str();
  993. else
  994. 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\
  995. FROM rm_record WHERE station_name = '{}' AND time between {} AND {}",
  996. str_station_name, uTime, uEndTime).c_str();
  997. COdbcStatement stmt;
  998. if (CDBConnectPool::Instance()->DBQuery(stmt, sql))
  999. {
  1000. uint8_t umodule, analyze_type;
  1001. int16_t opt = 0;
  1002. int dura;
  1003. 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];
  1004. uint64_t start_time, end_time, tt;
  1005. int nCol = 1;
  1006. stmt.BindTinyIntCol(nCol++, &umodule);
  1007. stmt.BindIntCol(nCol++, &dura);
  1008. stmt.BindTinyIntCol(nCol++, &analyze_type);
  1009. //stmt.BindCharCol(nCol++, station, sizeof(station));
  1010. //stmt.BindCharCol(nCol++, station_name, sizeof(station_name));
  1011. stmt.BindCharCol(nCol++, mo, sizeof(mo));
  1012. stmt.BindCharCol(nCol++, mo_name, sizeof(mo_name));
  1013. stmt.BindCharCol(nCol++, mp, sizeof(mp));
  1014. stmt.BindCharCol(nCol++, mp_name, sizeof(mp_name));
  1015. stmt.BindBigIntCol(nCol++, (__int64*)&start_time);
  1016. stmt.BindBigIntCol(nCol++, (__int64*)&end_time);
  1017. stmt.BindBigIntCol(nCol++, (__int64*)&tt);
  1018. stmt.BindCharCol(nCol++, name, sizeof(name));
  1019. stmt.BindCharCol(nCol++, username, sizeof(username));
  1020. stmt.BindSmallIntCol(nCol++, &opt);
  1021. stmt.BindCharCol(nCol++, mark, sizeof(mark));
  1022. stmt.BindCharCol(nCol++, station_name, sizeof(station_name));
  1023. do
  1024. {
  1025. //ZeroMemory(station, 100);
  1026. //ZeroMemory(station_name, 100);
  1027. ZeroMemory(mo, 50);
  1028. ZeroMemory(mo_name, 50);
  1029. ZeroMemory(mp, 50);
  1030. ZeroMemory(mp_name, 50);
  1031. ZeroMemory(name, 100);
  1032. ZeroMemory(username, 50);
  1033. ZeroMemory(mark, 200);
  1034. ZeroMemory(station_name, 100);
  1035. if (stmt.FetchNext() != 0)
  1036. break;
  1037. map_name[name]++;
  1038. map_mo_name[mo_name]++;
  1039. map_mp_name[mp_name]++;
  1040. auto o = yyjson_mut_obj(doc);
  1041. yyjson_mut_arr_add_val(yy_data, o);
  1042. yyjson_mut_obj_add_int(doc, o, "module", umodule);
  1043. yyjson_mut_obj_add_int(doc, o, "opt", opt);
  1044. yyjson_mut_obj_add_int(doc, o, "analyze_type", analyze_type);
  1045. yyjson_mut_obj_add_strcpy(doc, o, "mo_name", mo_name);
  1046. yyjson_mut_obj_add_strcpy(doc, o, "mp_name", mp_name);
  1047. yyjson_mut_obj_add_strcpy(doc, o, "station_name", ANSItoUTF8(station_name).c_str());
  1048. yyjson_mut_obj_add_int(doc, o, "time", tt);
  1049. yyjson_mut_obj_add_strcpy(doc, o, "name", ANSItoUTF8(name).c_str());
  1050. yyjson_mut_obj_add_strcpy(doc, o, "mark", ANSItoUTF8(mark).c_str());
  1051. } while (TRUE);
  1052. }
  1053. stmt.Close();
  1054. }
  1055. for (auto& it : map_name)
  1056. yyjson_mut_arr_add_strcpy(doc, yy_name, ANSItoUTF8(it.first).c_str());
  1057. for (auto& it : map_mo_name)
  1058. yyjson_mut_arr_add_strcpy(doc, yy_mo, it.first.c_str());
  1059. for (auto& it : map_mp_name)
  1060. yyjson_mut_arr_add_strcpy(doc, yy_mp, it.first.c_str());
  1061. code = 200;
  1062. yyjson_mut_obj_add_int(doc, root, "code", code);
  1063. yyjson_mut_obj_add_strcpy(doc, root, "msg", ANSItoUTF8(msg).c_str());
  1064. if (json)
  1065. {
  1066. *json = yyjson_mut_write(doc, 0, json_len);
  1067. /*
  1068. *json = (char*)malloc(1024);
  1069. strcpy_s(*json, 1024, R"({
  1070. "code": 200,
  1071. "msg": "",
  1072. "data": [{
  1073. "mo_name": "21#",
  1074. "mp_name": "J1",
  1075. "name": "张三",
  1076. "opt":1,
  1077. "time": 1693808336,
  1078. "mark": ""
  1079. }, {
  1080. "mo_name": "22#",
  1081. "mp_name": "J1",
  1082. "name": "李四",
  1083. "opt":1,
  1084. "time": 1693808336,
  1085. "mark": ""
  1086. }],
  1087. "name": ["张三", "李四", "王五"],
  1088. "mo_name": ["21#", "22#", "23#"],
  1089. "mp_name": ["J1", "J2", "J3"]
  1090. }
  1091. )");
  1092. */
  1093. }
  1094. yyjson_mut_doc_free(doc);
  1095. return code;
  1096. }
  1097. 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,
  1098. uint64_t start_time, uint64_t end_time, time_t tt, string& strName, const char* username, eRocord_Opt opt, string& mark)
  1099. {
  1100. CString sql = fmt::format("INSERT INTO rm_record\
  1101. (module, dura, analyze_type, station\
  1102. , station_name, mo, mo_name, mp, mp_name, start_time\
  1103. , end_time, time, name,username,opt,mark) VALUES\
  1104. ({}, {}, {}, '{}', '{}'\
  1105. , '{}', '{}', '{}', '{}', {}\
  1106. , {}, {}, '{}', '{}',{}, '{}')",
  1107. int(module), dura, analyze_type, strStation, strStationName,
  1108. IS_NULL(mo), IS_NULL(mo_name), IS_NULL(mp), IS_NULL(mp_name), start_time,
  1109. end_time, tt, strName, IS_NULL(username), int(opt), mark).c_str();
  1110. if (CDBConnectPool::Instance()->DBExecuteSQL(sql) == FALSE)
  1111. {
  1112. ASSERT(FALSE);
  1113. CSimpleLog::Error("语句执行失败:" + sql);
  1114. return 500;
  1115. }
  1116. else
  1117. {
  1118. return 200;
  1119. }
  1120. }
  1121. int DealGetrefer_option(const httplib::Request& req, const string token, char** json, size_t* json_len)
  1122. {
  1123. string station = req.get_param_value("station");
  1124. string mo = req.get_param_value("mo");
  1125. string mp = req.get_param_value("mp");
  1126. string str_direct = req.get_param_value("direct");
  1127. if (station.length() == 0 || mo.length() == 0 || mp.length() == 0 || str_direct.length() == 0)
  1128. return 400;
  1129. auto direct = atoi(str_direct.c_str());
  1130. if (direct != 3 && direct != 4)
  1131. return 400;
  1132. string str_station = UTF8toANSI(station);
  1133. if (CSimpleLog::PathFileExistsA(CSimpleLog::GetAppDir() + "refer\\" +
  1134. fmt::format("{}.{}.{}.{}.json", str_station, mo, mp, direct).c_str()))
  1135. return 200;
  1136. else
  1137. return 404;
  1138. }
  1139. //获取参考曲线
  1140. int DealGetrefer_curve(const httplib::Request& req, const string token, char** json, size_t* json_len)
  1141. {
  1142. string station = req.get_param_value("station");
  1143. string mo = req.get_param_value("mo");
  1144. string mp = req.get_param_value("mp");
  1145. string str_direct = req.get_param_value("direct");
  1146. string str_show_time = req.get_param_value("show_time");
  1147. if (station.length() == 0 || mo.length() == 0 || mp.length() == 0 || str_direct.length() == 0 || str_show_time.length() == 0)
  1148. return 400;
  1149. auto direct = atoi(str_direct.c_str());
  1150. if (direct != 3 && direct != 4)
  1151. return 400;
  1152. int yy, mm, dd, hh, MM, SS, micromm;
  1153. auto ret_num = sscanf_s(str_show_time.c_str(), "%d-%d-%d %d:%d:%d.%d", &yy, &mm, &dd, &hh, &MM, &SS, &micromm);
  1154. if (ret_num != 7)
  1155. return 400;
  1156. string str_station = UTF8toANSI(station);
  1157. time_t show_time = CTime(yy, mm, dd, hh, MM, SS).GetTime() * 1000 + micromm;
  1158. int code = 400;
  1159. string msg;
  1160. auto doc = yyjson_mut_doc_new(nullptr);
  1161. auto root = yyjson_mut_obj(doc);
  1162. yyjson_mut_doc_set_root(doc, root);
  1163. auto data = yyjson_mut_arr(doc);
  1164. yyjson_mut_obj_add_val(doc, root, "data", data);
  1165. yyjson_mut_obj_add_strcpy(doc, root, "station", station.c_str());
  1166. yyjson_mut_obj_add_strcpy(doc, root, "mo", mo.c_str());
  1167. yyjson_mut_obj_add_strcpy(doc, root, "mp", mp.c_str());
  1168. yyjson_mut_obj_add_int(doc, root, "direct", direct);
  1169. code = ReadReferFile(str_station, mo, mp, direct, show_time, doc, data, msg);
  1170. yyjson_mut_obj_add_int(doc, root, "code", code);
  1171. yyjson_mut_obj_add_strcpy(doc, root, "msg", ANSItoUTF8(msg).c_str());
  1172. if (json)
  1173. {
  1174. *json = yyjson_mut_write(doc, 0, json_len);
  1175. }
  1176. yyjson_mut_doc_free(doc);
  1177. return code;
  1178. }
  1179. int ReadReferFile(const string& station, const string& mo, const string& mp, uint8_t posi, time_t show_time, yyjson_mut_doc* mut_doc,
  1180. yyjson_mut_val* arr, OUT string& msg)
  1181. {
  1182. string strJsonPath = fmt::format("{}refer\\{}.{}.{}.{}.json", CSimpleLog::GetAppDir(), station, mo, mp, posi);
  1183. if (CSimpleLog::PathFileExistsA(strJsonPath.c_str()) == false)
  1184. {
  1185. msg = fmt::format("未设置参考曲线");
  1186. return 404;
  1187. }
  1188. yyjson_read_err err;
  1189. auto doc = yyjson_read_file(strJsonPath.c_str(), strJsonPath.length(), nullptr, &err);
  1190. if (doc == nullptr)
  1191. {
  1192. msg = err.msg;
  1193. return 500;
  1194. }
  1195. auto root = yyjson_doc_get_root(doc);
  1196. auto t = yyjson_obj_get(root, "t");
  1197. auto d0 = yyjson_obj_get(root, "d0");
  1198. auto d1 = yyjson_obj_get(root, "d1");
  1199. auto d2 = yyjson_obj_get(root, "d2");
  1200. if (yyjson_is_arr(t) == false || yyjson_is_arr(d0) == false || yyjson_is_arr(d1) == false || yyjson_is_arr(d2) == false)
  1201. {
  1202. msg = "参考曲线存储格式错误";
  1203. yyjson_doc_free(doc);
  1204. doc = nullptr;
  1205. return 500;
  1206. }
  1207. auto obj1 = yyjson_mut_obj(mut_doc);
  1208. auto obj2 = yyjson_mut_obj(mut_doc);
  1209. auto obj3 = yyjson_mut_obj(mut_doc);
  1210. yyjson_mut_arr_add_val(arr, obj1);
  1211. yyjson_mut_arr_add_val(arr, obj2);
  1212. yyjson_mut_arr_add_val(arr, obj3);
  1213. auto data1 = yyjson_mut_arr(mut_doc);
  1214. auto data2 = yyjson_mut_arr(mut_doc);
  1215. auto data3 = yyjson_mut_arr(mut_doc);
  1216. yyjson_mut_obj_add_val(mut_doc, obj1, "data", data1);
  1217. yyjson_mut_obj_add_val(mut_doc, obj2, "data", data2);
  1218. yyjson_mut_obj_add_val(mut_doc, obj3, "data", data3);
  1219. yyjson_mut_obj_add_val(mut_doc, obj1, "name", yyjson_val_mut_copy(mut_doc, yyjson_obj_get(root, "name0")));
  1220. yyjson_mut_obj_add_val(mut_doc, obj2, "name", yyjson_val_mut_copy(mut_doc, yyjson_obj_get(root, "name1")));
  1221. yyjson_mut_obj_add_val(mut_doc, obj3, "name", yyjson_val_mut_copy(mut_doc, yyjson_obj_get(root, "name2")));
  1222. int n = yyjson_arr_size(t);
  1223. auto it_t = yyjson_arr_get_first(t);
  1224. auto it_d0 = yyjson_arr_get_first(d0);
  1225. auto it_d1 = yyjson_arr_get_first(d1);
  1226. auto it_d2 = yyjson_arr_get_first(d2);
  1227. for (int i = 0; i < n; i++)
  1228. {
  1229. //按双数组的形式添加
  1230. auto o1 = yyjson_mut_arr(mut_doc);
  1231. yyjson_mut_arr_add_val(data1, o1);
  1232. auto o2 = yyjson_mut_arr(mut_doc);
  1233. yyjson_mut_arr_add_val(data2, o2);
  1234. auto o3 = yyjson_mut_arr(mut_doc);
  1235. yyjson_mut_arr_add_val(data3, o3);
  1236. auto t = yyjson_get_int(it_t) + show_time;
  1237. yyjson_mut_arr_add_int(mut_doc, o1, t);
  1238. yyjson_mut_arr_add_int(mut_doc, o2, t);
  1239. yyjson_mut_arr_add_int(mut_doc, o3, t);
  1240. yyjson_mut_arr_add_int(mut_doc, o1, yyjson_get_int(it_d0));
  1241. yyjson_mut_arr_add_int(mut_doc, o2, yyjson_get_int(it_d1));
  1242. yyjson_mut_arr_add_int(mut_doc, o3, yyjson_get_int(it_d2));
  1243. it_t = unsafe_yyjson_get_next(it_t);
  1244. it_d0 = unsafe_yyjson_get_next(it_d0);
  1245. it_d1 = unsafe_yyjson_get_next(it_d1);
  1246. it_d2 = unsafe_yyjson_get_next(it_d2);
  1247. }
  1248. yyjson_doc_free(doc);
  1249. doc = nullptr;
  1250. msg = "读取成功";
  1251. return 200;
  1252. }
  1253. int deal_get_reminder_interval(const httplib::Request& req, const string token, char** json, size_t* json_len)
  1254. {
  1255. auto doc = yyjson_mut_doc_new(nullptr);
  1256. auto root = yyjson_mut_obj(doc);
  1257. yyjson_mut_doc_set_root(doc, root);
  1258. yyjson_mut_obj_add_int(doc, root, "code", 200);
  1259. yyjson_mut_obj_add_int(doc, root, "interval", g_tReminderInterval);
  1260. *json = yyjson_mut_write(doc, 0, json_len);
  1261. yyjson_mut_doc_free(doc);
  1262. return 200;
  1263. }
  1264. int deal_post_reminder_interval(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len)
  1265. {
  1266. int code = 400;
  1267. string msg;
  1268. auto req_doc = yyjson_read(body_ptr, body_len, 0);
  1269. if (req_doc == nullptr) return 400;
  1270. auto req_root = yyjson_doc_get_root(req_doc);
  1271. do
  1272. {
  1273. auto interval = yyjson_get_int(yyjson_obj_get(req_root, "interval"));
  1274. if (interval == 0) break;
  1275. g_tReminderInterval = interval;
  1276. auto strIniPath = CSimpleLog::GetAppDir() + "DataServices.ini";
  1277. ::WritePrivateProfileString("SET", "reminder_interval", (to_string(g_tReminderInterval) + " #报警提醒间隔").c_str(), strIniPath);
  1278. code = 200;
  1279. } while (false);
  1280. return code;
  1281. }
  1282. string convertWhere(string mo, string mp, string starttime, string endtime, string type, string no,
  1283. string level, string ack_result, string handle_result, string sunroof, string recovery)
  1284. {
  1285. string wh = " ";
  1286. if (!starttime.empty()) {
  1287. wh += fmt::format(" AND occur_time >= '{}'", starttime);
  1288. }
  1289. if (!endtime.empty()) {
  1290. wh += fmt::format(" AND occur_time <= '{}'", endtime);
  1291. }
  1292. if (!mo.empty()) {
  1293. wh += fmt::format(" AND mo = '{}'", mo);
  1294. }
  1295. if (!mp.empty()) {
  1296. wh += fmt::format(" AND mp = '{}'", mp);
  1297. }
  1298. if (!type.empty()) {
  1299. wh += fmt::format(" AND a.type = {}", type);
  1300. }
  1301. if (!no.empty()) {
  1302. wh += fmt::format(" AND no = {}", no);
  1303. }
  1304. if (!level.empty()) {
  1305. wh += fmt::format(" AND level = {}", level);
  1306. }
  1307. if (!ack_result.empty()) {
  1308. wh += fmt::format(" AND ack_result = {}", ack_result);
  1309. }
  1310. if (!handle_result.empty()) {
  1311. wh += fmt::format(" AND handle_result = {}", handle_result);
  1312. }
  1313. if (!sunroof.empty()) {
  1314. if (sunroof.compare("0") == 0)
  1315. wh += " AND [sunroof]=0";
  1316. else if (sunroof.compare("1") == 0)
  1317. wh += " AND [sunroof]=1";
  1318. }
  1319. if (!handle_result.empty()) {
  1320. wh += fmt::format(" AND handle_result = {}", handle_result);
  1321. }
  1322. if (!recovery.empty()) {
  1323. if (recovery.compare("0") == 0)
  1324. wh += " AND [recovery_time] < '1901'";
  1325. else if (recovery.compare("1") == 0)
  1326. wh += " AND [recovery_time] > '1901'";
  1327. }
  1328. wh += " AND rel_id = ''";
  1329. int nPos = wh.find("AND");
  1330. if (nPos != -1)
  1331. wh.replace(nPos, 3, "WHERE");
  1332. return wh;
  1333. }
  1334. int deal_get_alarm_list(const httplib::Request& req, const string token, char** json, size_t* json_len)
  1335. {
  1336. string mo = req.get_param_value("mo");
  1337. string mp = req.get_param_value("mp");
  1338. string starttime = req.get_param_value("starttime");
  1339. string endtime = req.get_param_value("endtime");
  1340. string type = req.get_param_value("type");
  1341. string no = req.get_param_value("no");
  1342. string sort = req.get_param_value("sort");
  1343. string order = req.get_param_value("order");
  1344. string offset = req.get_param_value("offset");
  1345. string limit = req.get_param_value("limit");
  1346. string level = req.get_param_value("level");
  1347. string ack_result = req.get_param_value("ack_result");
  1348. string handle_result = req.get_param_value("handle_result");
  1349. string sunroof = req.get_param_value("sunroof");
  1350. string recovery = req.get_param_value("recovery");
  1351. if (sort.empty()) sort = "occur_time";
  1352. if (order.empty()) order = "desc";
  1353. if (offset.empty()) offset = "0";
  1354. if (limit.empty()) limit = "10";
  1355. auto doc = yyjson_mut_doc_new(nullptr);
  1356. auto root = yyjson_mut_obj(doc);
  1357. yyjson_mut_doc_set_root(doc, root);
  1358. auto rows = yyjson_mut_arr(doc);
  1359. yyjson_mut_obj_add_val(doc, root, "rows", rows);
  1360. int total = -1;
  1361. int code = 200;
  1362. string msg;
  1363. string wh = convertWhere(mo, mp, starttime, endtime, type, no, level, ack_result, handle_result, sunroof, recovery);
  1364. string or = " ORDER BY " + sort + " " + order + " OFFSET " + offset + " ROWS FETCH NEXT " + limit + " ROWS ONLY ";
  1365. do
  1366. {
  1367. CString sql = ("select count(*) from rm_alarm as a " + wh).c_str();
  1368. COdbcStatement stmt;
  1369. if (!CDBConnectPool::Instance()->DBQuery(stmt, sql))
  1370. {
  1371. msg = fmt::format("语句执行错误:{}", sql);
  1372. code = 500;
  1373. break;
  1374. }
  1375. stmt.BindIntCol(1, &total);
  1376. if (stmt.FetchNext() == 0)
  1377. yyjson_mut_obj_add_int(doc, root, "total", total);
  1378. } while (false);
  1379. std::map<string, yyjson_mut_val*> mapList;
  1380. do
  1381. {
  1382. if (total == -1)
  1383. break;
  1384. CString sql = fmt::format("select a.[id],[mo],[mp],[no],a.[type] ,[occur_time],[level],[desc],[suggest],[val],[referval],"\
  1385. " [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,"\
  1386. " 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 {} {}",
  1387. wh, or ).c_str();
  1388. COdbcStatement stmt;
  1389. if (!CDBConnectPool::Instance()->DBQuery(stmt, sql))
  1390. {
  1391. msg = fmt::format("语句执行错误:{}", sql);
  1392. code = 500;
  1393. break;
  1394. }
  1395. int id, val, refer;
  1396. char smo[20];
  1397. char smp[10];
  1398. char desc[200];
  1399. char suggest[200];
  1400. char ack_name[50];
  1401. char handle_name[50];
  1402. char hanele_info[50];
  1403. char mo_name[20];
  1404. char station_name[50];
  1405. char station_id[50];
  1406. char event_id[37] = { 0 };
  1407. char rel_id[37] = { 0 };
  1408. uint8_t no, utype , level, ack_result, h_result, skylight ;
  1409. TIMESTAMP_STRUCT tsOcccur, tsHandle, tsAck, tsRecovery;
  1410. int nCol = 1;
  1411. stmt.BindIntCol(nCol++, &id);
  1412. stmt.BindCharCol(nCol++, smo, sizeof(smo));
  1413. stmt.BindCharCol(nCol++, smp, sizeof(smp));
  1414. stmt.BindTinyIntCol(nCol++, &no);
  1415. stmt.BindTinyIntCol(nCol++, &utype);
  1416. stmt.BindTimeStampCol(nCol++, &tsOcccur);
  1417. stmt.BindTinyIntCol(nCol++, &level);
  1418. stmt.BindCharCol(nCol++, desc, sizeof(desc));
  1419. stmt.BindCharCol(nCol++, suggest, sizeof(suggest));
  1420. stmt.BindIntCol(nCol++, &val);
  1421. stmt.BindIntCol(nCol++, &refer);
  1422. stmt.BindTinyIntCol(nCol++, &ack_result);
  1423. stmt.BindCharCol(nCol++, ack_name, sizeof(ack_name));
  1424. stmt.BindTimeStampCol(nCol++, &tsAck);
  1425. stmt.BindTinyIntCol(nCol++, &h_result);
  1426. stmt.BindCharCol(nCol++, handle_name, sizeof(handle_name));
  1427. stmt.BindTimeStampCol(nCol++, &tsHandle);
  1428. stmt.BindCharCol(nCol++, hanele_info, sizeof(hanele_info));
  1429. stmt.BindCharCol(nCol++, mo_name, sizeof(mo_name));
  1430. stmt.BindCharCol(nCol++, station_id, sizeof(station_id));
  1431. stmt.BindCharCol(nCol++, station_name, sizeof(station_name));
  1432. stmt.BindTimeStampCol(nCol++, &tsRecovery);
  1433. stmt.BindTinyIntCol(nCol++, &skylight);
  1434. stmt.BindCharCol(nCol++, event_id, sizeof(event_id));
  1435. while (true)
  1436. {
  1437. if (stmt.FetchNext() != 0)
  1438. break;
  1439. auto obj = yyjson_mut_obj(doc);
  1440. yyjson_mut_arr_add_val(rows, obj);
  1441. auto child = yyjson_mut_arr(doc);
  1442. yyjson_mut_obj_add_val(doc, obj, "child", child);
  1443. mapList[event_id] = child; //临时记录后面统一添加
  1444. if (ack_name[0])
  1445. yyjson_mut_obj_add_strcpy(doc, obj, "ack_name", ANSItoUTF8(ack_name).c_str());
  1446. else
  1447. yyjson_mut_obj_add_str(doc, obj, "ack_name", "");
  1448. if (tsAck.year != 1900)
  1449. yyjson_mut_obj_add_strcpy(doc, obj, "ack_time", fmt::format("{}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}",
  1450. tsAck.year, tsAck.month, tsAck.day, tsAck.hour, tsAck.minute, tsAck.second).c_str());
  1451. else
  1452. yyjson_mut_obj_add_str(doc, obj, "ack_time", "");
  1453. yyjson_mut_obj_add_int(doc, obj, "ack_result", ack_result);
  1454. if (handle_name[0])
  1455. yyjson_mut_obj_add_strcpy(doc, obj, "handle_name", ANSItoUTF8(handle_name).c_str());
  1456. else
  1457. yyjson_mut_obj_add_str(doc, obj, "handle_name", "");
  1458. if (tsHandle.year != 1900)
  1459. yyjson_mut_obj_add_strcpy(doc, obj, "handle_time", fmt::format("{}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}",
  1460. tsHandle.year, tsHandle.month, tsHandle.day, tsHandle.hour, tsHandle.minute, tsHandle.second).c_str());
  1461. else
  1462. yyjson_mut_obj_add_str(doc, obj, "handle_time", "");
  1463. yyjson_mut_obj_add_int(doc, obj, "handle_result", h_result);
  1464. yyjson_mut_obj_add_int(doc, obj, "id", id);
  1465. yyjson_mut_obj_add_int(doc, obj, "level", level);
  1466. yyjson_mut_obj_add_strcpy(doc, obj, "mo", smo);
  1467. yyjson_mut_obj_add_strcpy(doc, obj, "mo_name", mo_name);
  1468. yyjson_mut_obj_add_strcpy(doc, obj, "mp", smp);
  1469. yyjson_mut_obj_add_int(doc, obj, "no", no);
  1470. yyjson_mut_obj_add_strcpy(doc, obj, "type_name", ANSItoUTF8(GetAlarmName((eZL_ALARMTYPE)utype)).c_str());
  1471. yyjson_mut_obj_add_strcpy(doc, obj, "occur_time", fmt::format("{}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}",
  1472. tsOcccur.year, tsOcccur.month, tsOcccur.day, tsOcccur.hour, tsOcccur.minute, tsOcccur.second).c_str());
  1473. if (tsRecovery.year != 1900)
  1474. yyjson_mut_obj_add_strcpy(doc, obj, "recovery_time", fmt::format("{}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}",
  1475. tsRecovery.year, tsRecovery.month, tsRecovery.day, tsRecovery.hour, tsRecovery.minute, tsRecovery.second).c_str());
  1476. else
  1477. yyjson_mut_obj_add_str(doc, obj, "recovery_time", "");
  1478. if (suggest[0])
  1479. yyjson_mut_obj_add_strcpy(doc, obj, "suggest", ANSItoUTF8(suggest).c_str());
  1480. else
  1481. yyjson_mut_obj_add_str(doc, obj, "suggest", "");
  1482. if (desc[0])
  1483. yyjson_mut_obj_add_strcpy(doc, obj, "desc", ANSItoUTF8(desc).c_str());
  1484. else
  1485. yyjson_mut_obj_add_str(doc, obj, "desc", "");
  1486. yyjson_mut_obj_add_int(doc, obj, "sunroof", skylight);
  1487. yyjson_mut_obj_add_int(doc, obj, "type", utype);
  1488. //yyjson_mut_obj_add_strcpy(doc, obj, "type_name", )
  1489. yyjson_mut_obj_add_strcpy(doc, obj, "up", ANSItoUTF8(station_id).c_str());
  1490. yyjson_mut_obj_add_strcpy(doc, obj, "up_name", ANSItoUTF8(station_name).c_str());
  1491. yyjson_mut_obj_add_int(doc, obj, "val", val);
  1492. yyjson_mut_obj_add_int(doc, obj, "referval", refer);
  1493. yyjson_mut_obj_add_strcpy(doc, obj, "event_id", event_id);
  1494. }
  1495. } while (false);
  1496. do
  1497. {
  1498. if (mapList.size() == 0)
  1499. break;
  1500. stringstream ss;
  1501. ss << " where rel_id in (";
  1502. int index = 0;
  1503. for (const auto& it : mapList)
  1504. {
  1505. if (index == 0)
  1506. ss << '\'' << it.first << '\'';
  1507. else
  1508. ss << ",'" << it.first << '\'';
  1509. index++;
  1510. }
  1511. ss << ')';
  1512. CString sql = fmt::format("select a.[id],[mo],[mp],[no],a.[type] ,[occur_time],[level],[desc],[suggest],[val],[referval],"\
  1513. " [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,"\
  1514. " 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 {}",
  1515. ss.str()).c_str();
  1516. COdbcStatement stmt;
  1517. if (!CDBConnectPool::Instance()->DBQuery(stmt, sql))
  1518. {
  1519. msg = fmt::format("语句执行错误:{}", sql);
  1520. code = 500;
  1521. break;
  1522. }
  1523. int id, val, refer;
  1524. char smo[20];
  1525. char smp[10];
  1526. char desc[200];
  1527. char suggest[200];
  1528. char ack_name[50];
  1529. char handle_name[50];
  1530. char hanele_info[50];
  1531. char mo_name[20];
  1532. char station_name[50];
  1533. char station_id[50];
  1534. char event_id[37] = { 0 };
  1535. char rel_id[37] = { 0 };
  1536. uint8_t no, utype, level, ack_result, h_result, skylight;
  1537. TIMESTAMP_STRUCT tsOcccur, tsHandle, tsAck, tsRecovery;
  1538. int nCol = 1;
  1539. stmt.BindIntCol(nCol++, &id);
  1540. stmt.BindCharCol(nCol++, smo, sizeof(smo));
  1541. stmt.BindCharCol(nCol++, smp, sizeof(smp));
  1542. stmt.BindTinyIntCol(nCol++, &no);
  1543. stmt.BindTinyIntCol(nCol++, &utype);
  1544. stmt.BindTimeStampCol(nCol++, &tsOcccur);
  1545. stmt.BindTinyIntCol(nCol++, &level);
  1546. stmt.BindCharCol(nCol++, desc, sizeof(desc));
  1547. stmt.BindCharCol(nCol++, suggest, sizeof(suggest));
  1548. stmt.BindIntCol(nCol++, &val);
  1549. stmt.BindIntCol(nCol++, &refer);
  1550. stmt.BindTinyIntCol(nCol++, &ack_result);
  1551. stmt.BindCharCol(nCol++, ack_name, sizeof(ack_name));
  1552. stmt.BindTimeStampCol(nCol++, &tsAck);
  1553. stmt.BindTinyIntCol(nCol++, &h_result);
  1554. stmt.BindCharCol(nCol++, handle_name, sizeof(handle_name));
  1555. stmt.BindTimeStampCol(nCol++, &tsHandle);
  1556. stmt.BindCharCol(nCol++, hanele_info, sizeof(hanele_info));
  1557. stmt.BindCharCol(nCol++, mo_name, sizeof(mo_name));
  1558. stmt.BindCharCol(nCol++, station_id, sizeof(station_id));
  1559. stmt.BindCharCol(nCol++, station_name, sizeof(station_name));
  1560. stmt.BindTimeStampCol(nCol++, &tsRecovery);
  1561. stmt.BindTinyIntCol(nCol++, &skylight);
  1562. stmt.BindCharCol(nCol++, event_id, sizeof(event_id));
  1563. stmt.BindCharCol(nCol++, rel_id, sizeof(rel_id));
  1564. while (true)
  1565. {
  1566. if (stmt.FetchNext() != 0)
  1567. break;
  1568. auto arr = mapList[rel_id];
  1569. if (arr == nullptr)
  1570. {
  1571. ASSERT(0);
  1572. continue;
  1573. }
  1574. auto obj = yyjson_mut_obj(doc);
  1575. yyjson_mut_arr_add_val(arr, obj);//添加到原有的child里
  1576. if (ack_name[0])
  1577. yyjson_mut_obj_add_strcpy(doc, obj, "ack_name", ANSItoUTF8(ack_name).c_str());
  1578. else
  1579. yyjson_mut_obj_add_str(doc, obj, "ack_name", "");
  1580. if (tsAck.year != 1900)
  1581. yyjson_mut_obj_add_strcpy(doc, obj, "ack_time", fmt::format("{}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}",
  1582. tsAck.year, tsAck.month, tsAck.day, tsAck.hour, tsAck.minute, tsAck.second).c_str());
  1583. else
  1584. yyjson_mut_obj_add_str(doc, obj, "ack_time", "");
  1585. yyjson_mut_obj_add_int(doc, obj, "ack_result", ack_result);
  1586. if (handle_name[0])
  1587. yyjson_mut_obj_add_strcpy(doc, obj, "handle_name", ANSItoUTF8(handle_name).c_str());
  1588. else
  1589. yyjson_mut_obj_add_str(doc, obj, "handle_name", "");
  1590. if (tsHandle.year != 1900)
  1591. yyjson_mut_obj_add_strcpy(doc, obj, "handle_time", fmt::format("{}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}",
  1592. tsHandle.year, tsHandle.month, tsHandle.day, tsHandle.hour, tsHandle.minute, tsHandle.second).c_str());
  1593. else
  1594. yyjson_mut_obj_add_str(doc, obj, "handle_time", "");
  1595. yyjson_mut_obj_add_int(doc, obj, "handle_result", h_result);
  1596. yyjson_mut_obj_add_int(doc, obj, "id", id);
  1597. yyjson_mut_obj_add_int(doc, obj, "level", level);
  1598. yyjson_mut_obj_add_strcpy(doc, obj, "mo", smo);
  1599. yyjson_mut_obj_add_strcpy(doc, obj, "mo_name", mo_name);
  1600. yyjson_mut_obj_add_strcpy(doc, obj, "mp", smp);
  1601. yyjson_mut_obj_add_int(doc, obj, "no", no);
  1602. yyjson_mut_obj_add_strcpy(doc, obj, "type_name", ANSItoUTF8(GetAlarmName((eZL_ALARMTYPE)utype)).c_str());
  1603. yyjson_mut_obj_add_strcpy(doc, obj, "occur_time", fmt::format("{}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}",
  1604. tsOcccur.year, tsOcccur.month, tsOcccur.day, tsOcccur.hour, tsOcccur.minute, tsOcccur.second).c_str());
  1605. if (tsRecovery.year != 1900)
  1606. yyjson_mut_obj_add_strcpy(doc, obj, "recovery_time", fmt::format("{}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}",
  1607. tsRecovery.year, tsRecovery.month, tsRecovery.day, tsRecovery.hour, tsRecovery.minute, tsRecovery.second).c_str());
  1608. else
  1609. yyjson_mut_obj_add_str(doc, obj, "recovery_time", "");
  1610. if (suggest[0])
  1611. yyjson_mut_obj_add_strcpy(doc, obj, "suggest", ANSItoUTF8(suggest).c_str());
  1612. else
  1613. yyjson_mut_obj_add_str(doc, obj, "suggest", "");
  1614. if (desc[0])
  1615. yyjson_mut_obj_add_strcpy(doc, obj, "desc", ANSItoUTF8(desc).c_str());
  1616. else
  1617. yyjson_mut_obj_add_str(doc, obj, "desc", "");
  1618. yyjson_mut_obj_add_int(doc, obj, "sunroof", skylight);
  1619. yyjson_mut_obj_add_int(doc, obj, "type", utype);
  1620. //yyjson_mut_obj_add_strcpy(doc, obj, "type_name", )
  1621. yyjson_mut_obj_add_strcpy(doc, obj, "up", ANSItoUTF8(station_id).c_str());
  1622. yyjson_mut_obj_add_strcpy(doc, obj, "up_name", ANSItoUTF8(station_name).c_str());
  1623. yyjson_mut_obj_add_int(doc, obj, "val", val);
  1624. yyjson_mut_obj_add_int(doc, obj, "referval", refer);
  1625. yyjson_mut_obj_add_strcpy(doc, obj, "event_id", event_id);
  1626. }
  1627. } while (false);
  1628. yyjson_mut_obj_add_int(doc, root, "code", code);
  1629. yyjson_mut_obj_add_strcpy(doc, root, "msg", ANSItoUTF8(msg).c_str());
  1630. *json = yyjson_mut_write(doc, 0, json_len);
  1631. yyjson_mut_doc_free(doc);
  1632. return code;
  1633. }
  1634. //历史数据新接口 10087端口
  1635. int DealGetResistData(const httplib::Request& req, const string token, char** json, size_t* json_len)
  1636. {
  1637. string mo = req.get_param_value("mo");
  1638. string mp = req.get_param_value("mp");
  1639. string starttime = req.get_param_value("starttime");
  1640. string endtime = req.get_param_value("endtime");
  1641. string threshold = req.get_param_value("threshold");
  1642. int nThreshold = 100;
  1643. if (mo.length() == 0 || mp.length() == 0 || starttime.length() == 0 || endtime.length() == 0)
  1644. return 400;
  1645. if (threshold.empty() == false) nThreshold = atoi(threshold.c_str());
  1646. //if (nThreshold < 30) nThreshold = 30;
  1647. //if (nThreshold > 500) nThreshold = 500;
  1648. COleDateTime odtStart, odtEnd;
  1649. try
  1650. {
  1651. odtStart.ParseDateTime(starttime.c_str());
  1652. odtEnd.ParseDateTime(endtime.c_str());
  1653. }
  1654. catch (CException* )
  1655. {
  1656. return 400;
  1657. }
  1658. auto momp = mo + "." + mp;
  1659. auto pInfo = CMonitorObjectMng::Instance()->GetMoMpInfo(momp);
  1660. if (pInfo == nullptr)
  1661. return 404;
  1662. if (pInfo->pDeivce == nullptr)
  1663. return 404;
  1664. if (odtStart >= odtEnd) return 400;
  1665. char tablename[50] = { 0 };
  1666. auto dtStartDate = COleDateTime(odtStart.GetYear(), odtStart.GetMonth(), odtStart.GetDay(), 0, 0, 0);
  1667. //auto dtEndDate = COleDateTime(odtEnd.GetYear(), odtEnd.GetMonth(), odtEnd.GetDay(), 0, 0, 0);
  1668. auto strStartDate = dtStartDate.Format("%Y-%m-%d %H:%M:%S");
  1669. auto strEndDate = odtEnd.Format("%Y-%m-%d %H:%M:%S");;
  1670. //auto strStartTime = odtStart.Format("%Y-%m-%d %H:%M:%S");
  1671. //auto strEndTime = odtEnd.Format("%Y-%m-%d %H:%M:%S");
  1672. CString sql = "SELECT TOP 100000 * FROM (";
  1673. {
  1674. int num = 0;
  1675. for (auto it = dtStartDate; it < odtEnd;)
  1676. {
  1677. sprintf_s(tablename, 50, "rm_resistance_%04d%02d%02d", it.GetYear(), it.GetMonth(), it.GetDay());
  1678. if (num == 0)
  1679. {
  1680. sql += fmt::format("SELECT [acquisitiontime],[data0],[data1],[data2] "\
  1681. "FROM {} WHERE IMEI = '{}' AND acquisitiontime >= '{}' and acquisitiontime < '{}' AND idx = {} ",
  1682. tablename, pInfo->imei.c_str(), starttime.c_str(), endtime.c_str(), pInfo->idx).c_str();
  1683. }
  1684. else
  1685. {
  1686. sql += fmt::format(" UNION ALL "\
  1687. "SELECT [acquisitiontime],[data0],[data1],[data2] "\
  1688. "FROM {} WHERE IMEI = '{}' AND acquisitiontime >= '{}' and acquisitiontime < '{}' AND idx = {} ",
  1689. tablename, pInfo->imei.c_str(), starttime, endtime, pInfo->idx).c_str();
  1690. }
  1691. num++;
  1692. it += COleDateTimeSpan(1, 0, 0, 0);
  1693. }
  1694. sql += ") AS A ORDER BY acquisitiontime ASC";
  1695. }
  1696. TIMESTAMP_STRUCT ts;
  1697. int sdata0, sdata1, sdata2;
  1698. COdbcStatement stmt;
  1699. if (CDBConnectPool::Instance()->DBQuery(stmt, sql) == FALSE)
  1700. {
  1701. SPDLOG_ERROR("查询语句出错:{}", sql);
  1702. return 500;
  1703. }
  1704. int nCol = 1;
  1705. stmt.BindTimeStampCol(nCol++, &ts);
  1706. stmt.BindIntCol(nCol++, &sdata0);
  1707. stmt.BindIntCol(nCol++, &sdata1);
  1708. stmt.BindIntCol(nCol++, &sdata2);
  1709. int nCount = 0;
  1710. auto doc = yyjson_mut_doc_new(nullptr);
  1711. auto root = yyjson_mut_obj(doc);
  1712. yyjson_mut_doc_set_root(doc, root);
  1713. auto data = yyjson_mut_arr(doc);
  1714. yyjson_mut_obj_add_val(doc, root, "data", data);
  1715. auto curve_1 = yyjson_mut_obj(doc);
  1716. auto curve_2 = yyjson_mut_obj(doc);
  1717. auto curve_3 = yyjson_mut_obj(doc);
  1718. yyjson_mut_arr_add_val(data, curve_1);
  1719. yyjson_mut_arr_add_val(data, curve_2);
  1720. yyjson_mut_arr_add_val(data, curve_3);
  1721. yyjson_mut_obj_add_str(doc, root, "cmd", "query_hist");
  1722. yyjson_mut_obj_add_strcpy(doc, root, "tag", (momp + ".resist").c_str());
  1723. yyjson_mut_obj_add_str(doc, root, "data_fmt", "curve");
  1724. yyjson_mut_obj_add_str(doc, root, "unit", "N");
  1725. yyjson_mut_obj_add_str(doc, root, "time", "");
  1726. //1号测力点
  1727. yyjson_mut_obj_add_str(doc, curve_1, "name", pInfo->name1utf.c_str());
  1728. auto points1 = yyjson_mut_arr(doc);
  1729. yyjson_mut_obj_add_val(doc, curve_1, "points", points1);
  1730. //2号测力点
  1731. yyjson_mut_obj_add_str(doc, curve_2, "name", pInfo->name2utf.c_str());
  1732. auto points2 = yyjson_mut_arr(doc);
  1733. yyjson_mut_obj_add_val(doc, curve_2, "points", points2);
  1734. //3号测力点
  1735. yyjson_mut_obj_add_str(doc, curve_3, "name", pInfo->name3utf.c_str());
  1736. auto points3 = yyjson_mut_arr(doc);
  1737. yyjson_mut_obj_add_val(doc, curve_3, "points", points3);
  1738. if (nThreshold == 0)
  1739. {
  1740. do
  1741. {
  1742. if (stmt.FetchNext() != 0)
  1743. break;
  1744. CTime ctTime;
  1745. try
  1746. {
  1747. ctTime = CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
  1748. }
  1749. catch (...)
  1750. {
  1751. continue;
  1752. }
  1753. time_t tm = ctTime.GetTime() * 1000 + ts.fraction / 1000000;
  1754. #ifdef SHOW_DATA
  1755. {
  1756. auto item = yyjson_mut_arr(doc);
  1757. yyjson_mut_arr_add_val(points1, item);
  1758. yyjson_mut_arr_add_uint(doc, item, tm);
  1759. yyjson_mut_arr_add_int(doc, item, sdata0);
  1760. }
  1761. {
  1762. auto item = yyjson_mut_arr(doc);
  1763. yyjson_mut_arr_add_val(points2, item);
  1764. yyjson_mut_arr_add_uint(doc, item, tm);
  1765. yyjson_mut_arr_add_int(doc, item, sdata1);
  1766. }
  1767. {
  1768. auto item = yyjson_mut_arr(doc);
  1769. yyjson_mut_arr_add_val(points3, item);
  1770. yyjson_mut_arr_add_uint(doc, item, tm);
  1771. yyjson_mut_arr_add_int(doc, item, sdata2);
  1772. }
  1773. #endif
  1774. nCount++;
  1775. } while (true);
  1776. }
  1777. else {
  1778. int lastdata0 = INT_MAX, lastdata1 = INT_MAX, lastdata2 = INT_MAX;
  1779. time_t tm = 0;
  1780. do
  1781. {
  1782. if (stmt.FetchNext() != 0)
  1783. {
  1784. if (tm != 0)
  1785. {
  1786. {
  1787. auto item = yyjson_mut_arr(doc);
  1788. yyjson_mut_arr_add_val(points1, item);
  1789. yyjson_mut_arr_add_uint(doc, item, tm);
  1790. yyjson_mut_arr_add_int(doc, item, sdata0);
  1791. }
  1792. {
  1793. auto item = yyjson_mut_arr(doc);
  1794. yyjson_mut_arr_add_val(points2, item);
  1795. yyjson_mut_arr_add_uint(doc, item, tm);
  1796. yyjson_mut_arr_add_int(doc, item, sdata1);
  1797. }
  1798. {
  1799. auto item = yyjson_mut_arr(doc);
  1800. yyjson_mut_arr_add_val(points3, item);
  1801. yyjson_mut_arr_add_uint(doc, item, tm);
  1802. yyjson_mut_arr_add_int(doc, item, sdata2);
  1803. }
  1804. }
  1805. break;
  1806. }
  1807. CTime ctTime;
  1808. try
  1809. {
  1810. ctTime = CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
  1811. }
  1812. catch (...)
  1813. {
  1814. continue;
  1815. }
  1816. tm = ctTime.GetTime() * 1000 + ts.fraction / 1000000;
  1817. #ifdef SHOW_DATA
  1818. if (abs(lastdata0 - sdata0) > nThreshold)
  1819. {
  1820. auto item = yyjson_mut_arr(doc);
  1821. yyjson_mut_arr_add_val(points1, item);
  1822. yyjson_mut_arr_add_uint(doc, item, tm);
  1823. yyjson_mut_arr_add_int(doc, item, sdata0);
  1824. lastdata0 = sdata0;
  1825. }
  1826. if (abs(lastdata1 - sdata1) > nThreshold)
  1827. {
  1828. auto item = yyjson_mut_arr(doc);
  1829. yyjson_mut_arr_add_val(points2, item);
  1830. yyjson_mut_arr_add_uint(doc, item, tm);
  1831. yyjson_mut_arr_add_int(doc, item, sdata1);
  1832. lastdata1 = sdata1;
  1833. }
  1834. if (abs(lastdata2 - sdata2) > nThreshold)
  1835. {
  1836. auto item = yyjson_mut_arr(doc);
  1837. yyjson_mut_arr_add_val(points3, item);
  1838. yyjson_mut_arr_add_uint(doc, item, tm);
  1839. yyjson_mut_arr_add_int(doc, item, sdata2);
  1840. lastdata2 = sdata2;
  1841. }
  1842. #endif
  1843. nCount++;
  1844. } while (true);
  1845. }
  1846. stmt.Close();
  1847. yyjson_mut_obj_add_int(doc, root, "count", nCount);
  1848. if (nCount >= 100000)
  1849. yyjson_mut_obj_add_bool(doc, root, "has_more", true);
  1850. else
  1851. yyjson_mut_obj_add_bool(doc, root, "has_more", false);
  1852. //扳动信息
  1853. auto fix_points = yyjson_mut_arr(doc);
  1854. auto invert_points = yyjson_mut_arr(doc);
  1855. auto convert_points = yyjson_mut_arr(doc);
  1856. if (pInfo->name1.find("定位") != -1)
  1857. {
  1858. yyjson_mut_obj_add_val(doc, curve_1, "mark_points", fix_points);
  1859. yyjson_mut_obj_add_val(doc, curve_2, "mark_points", invert_points);
  1860. }
  1861. else
  1862. {
  1863. yyjson_mut_obj_add_val(doc, curve_1, "mark_points", invert_points);
  1864. yyjson_mut_obj_add_val(doc, curve_2, "mark_points", fix_points);
  1865. }
  1866. yyjson_mut_obj_add_val(doc, curve_3, "mark_points", convert_points);
  1867. auto pConvertLimit = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
  1868. auto pFixSuobi = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_FIX, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
  1869. auto pInvertSuobi = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_INVERT, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
  1870. {
  1871. int num = 0;
  1872. int lastyearmonth = 0;
  1873. for (auto it = dtStartDate; it < odtEnd;)
  1874. {
  1875. int yearmonth = it.GetYear() * 100 + it.GetMonth();
  1876. if (yearmonth != lastyearmonth)
  1877. {
  1878. lastyearmonth = yearmonth;
  1879. sprintf_s(tablename, 50, "rm_move_%04d%02d", it.GetYear(), it.GetMonth());
  1880. if (num == 0)
  1881. {
  1882. sql = fmt::format("SELECT show_time, curr_val, show_val, posi, [type],[sunroof] FROM {} \
  1883. WHERE mo = '{}' AND mp = '{}' AND show_time >= '{}' AND show_time <= '{}' ",
  1884. tablename, mo, mp, starttime, endtime).c_str();
  1885. }
  1886. else
  1887. {
  1888. sql += fmt::format(" UNION ALL "\
  1889. "SELECT show_time, curr_val, show_val, posi, [type],[sunroof] FROM {} \
  1890. WHERE mo = '{}' AND mp = '{}' AND show_time >= '{}' AND show_time <= '{}' ",
  1891. tablename, mo, mp, starttime, endtime).c_str();
  1892. }
  1893. num++;
  1894. }
  1895. it += COleDateTimeSpan(1, 0, 0, 0);
  1896. }
  1897. sql += "order by posi, show_time";
  1898. }
  1899. if (CDBConnectPool::Instance()->DBQuery(stmt, sql))
  1900. {
  1901. TIMESTAMP_STRUCT ts;
  1902. int curr_val;
  1903. int show_val;
  1904. eDaoChaPosi posi;
  1905. ePowerName pn;
  1906. uint8_t sunroof;
  1907. int nCol = 1;
  1908. stmt.BindTimeStampCol(nCol++, &ts);
  1909. stmt.BindIntCol(nCol++, &curr_val);
  1910. stmt.BindIntCol(nCol++, &show_val);
  1911. stmt.BindTinyIntCol(nCol++, (BYTE*)&posi);
  1912. stmt.BindTinyIntCol(nCol++, (BYTE*)&pn);
  1913. stmt.BindTinyIntCol(nCol++, &sunroof);
  1914. do
  1915. {
  1916. if (stmt.FetchNext() != 0)
  1917. break;
  1918. auto obj = yyjson_mut_obj(doc);
  1919. switch (posi)
  1920. {
  1921. case eDaoChaPosi::DCP_FIX:
  1922. {
  1923. if (pn == ePowerName::PN_UNKNOWN || pn == ePowerName::PN_RESIST)
  1924. {
  1925. yyjson_mut_arr_add_val(fix_points, obj);
  1926. auto coord = yyjson_mut_arr(doc);
  1927. yyjson_mut_obj_add_val(doc, obj, "coord", coord);
  1928. 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);
  1929. yyjson_mut_arr_add_int(doc, coord, curr_val);
  1930. yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
  1931. ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
  1932. yyjson_mut_obj_add_int(doc, obj, "val", show_val);
  1933. if (pFixSuobi && pFixSuobi->enable && !sunroof)
  1934. {
  1935. if (pFixSuobi->alarm_low_limit > show_val)
  1936. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  1937. else if (pFixSuobi->alarm_high_limit < show_val)
  1938. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  1939. else if (pFixSuobi->warn_high_limit < show_val)
  1940. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  1941. else if (pFixSuobi->warn_low_limit > show_val)
  1942. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  1943. }
  1944. yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str());
  1945. }
  1946. //if (show_val < 500)//TODO
  1947. //{
  1948. // yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  1949. // yyjson_mut_obj_add_str(doc, obj, "label", lock_low.c_str());
  1950. //}
  1951. //else
  1952. //{
  1953. // yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str());
  1954. //}
  1955. }
  1956. break;
  1957. case eDaoChaPosi::DCP_INVERT:
  1958. {
  1959. if (pn == ePowerName::PN_UNKNOWN || pn == ePowerName::PN_RESIST)
  1960. {
  1961. yyjson_mut_arr_add_val(invert_points, obj);
  1962. auto coord = yyjson_mut_arr(doc);
  1963. yyjson_mut_obj_add_val(doc, obj, "coord", coord);
  1964. 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);
  1965. yyjson_mut_arr_add_int(doc, coord, curr_val);
  1966. yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
  1967. ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
  1968. yyjson_mut_obj_add_int(doc, obj, "val", show_val);
  1969. if (pInvertSuobi && pInvertSuobi->enable && !sunroof)
  1970. {
  1971. if (pInvertSuobi->alarm_low_limit > show_val)
  1972. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  1973. else if (pInvertSuobi->alarm_high_limit < show_val)
  1974. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  1975. else if (pInvertSuobi->warn_high_limit < show_val)
  1976. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  1977. else if (pInvertSuobi->warn_low_limit > show_val)
  1978. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  1979. }
  1980. yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str());
  1981. }
  1982. //if (show_val < 500)//TODO
  1983. //{
  1984. // yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  1985. // yyjson_mut_obj_add_str(doc, obj, "label", lock_low.c_str());
  1986. //}
  1987. //else
  1988. //{
  1989. // yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str());
  1990. //}
  1991. }
  1992. break;
  1993. case eDaoChaPosi::DCP_FIX2INVERT:
  1994. {
  1995. if (pn == ePowerName::PN_UNKNOWN || pn == ePowerName::PN_MOVE)
  1996. {
  1997. yyjson_mut_arr_add_val(convert_points, obj);
  1998. auto coord = yyjson_mut_arr(doc);
  1999. yyjson_mut_obj_add_val(doc, obj, "coord", coord);
  2000. 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);
  2001. yyjson_mut_arr_add_int(doc, coord, curr_val);
  2002. yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
  2003. ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
  2004. yyjson_mut_obj_add_int(doc, obj, "val", show_val);
  2005. if (pConvertLimit && pConvertLimit->enable && !sunroof)
  2006. {
  2007. if (pInfo->out_name.find("定扳反") != -1)
  2008. {
  2009. if (pConvertLimit->dw_alarm_low_limit > show_val)
  2010. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  2011. else if (pConvertLimit->dw_warn_low_limit > show_val)
  2012. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  2013. }
  2014. else
  2015. {
  2016. if (pConvertLimit->up_alarm_high_limit < show_val)
  2017. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  2018. else if (pConvertLimit->up_warn_high_limit < show_val)
  2019. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  2020. }
  2021. }
  2022. if (curr_val < 0)
  2023. yyjson_mut_obj_add_str(doc, obj, "position", "bottom");
  2024. yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("定扳反:{}", show_val)).c_str());
  2025. }
  2026. }
  2027. break;
  2028. case eDaoChaPosi::DCP_INVERT2FIX:
  2029. {
  2030. if (pn == ePowerName::PN_UNKNOWN || pn == ePowerName::PN_MOVE)
  2031. {
  2032. yyjson_mut_arr_add_val(convert_points, obj);
  2033. auto coord = yyjson_mut_arr(doc);
  2034. yyjson_mut_obj_add_val(doc, obj, "coord", coord);
  2035. 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);
  2036. yyjson_mut_arr_add_int(doc, coord, curr_val);
  2037. yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
  2038. ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
  2039. yyjson_mut_obj_add_int(doc, obj, "val", show_val);
  2040. if (pConvertLimit && pConvertLimit->enable && !sunroof)
  2041. {
  2042. if (pInfo->out_name.find("反扳定") != -1)
  2043. {
  2044. if (pConvertLimit->dw_alarm_low_limit > show_val)
  2045. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  2046. else if (pConvertLimit->dw_warn_low_limit > show_val)
  2047. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  2048. }
  2049. else
  2050. {
  2051. if (pConvertLimit->up_alarm_high_limit < show_val)
  2052. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  2053. else if (pConvertLimit->up_warn_high_limit < show_val)
  2054. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  2055. }
  2056. }
  2057. if (curr_val < 0)
  2058. yyjson_mut_obj_add_str(doc, obj, "position", "bottom");
  2059. yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("反扳定:{}", show_val)).c_str());
  2060. }
  2061. }
  2062. break;
  2063. default:
  2064. ASSERT(FALSE);
  2065. break;
  2066. }
  2067. } while (TRUE);
  2068. }
  2069. stmt.Close();
  2070. //报警线
  2071. auto warn_line = yyjson_mut_arr(doc);
  2072. yyjson_mut_obj_add_val(doc, root, "warn_line", warn_line);
  2073. MAX_OVER_LIMIT_INFO* pFixMax = nullptr;
  2074. MAX_OVER_LIMIT_INFO* pInvertMax = nullptr;
  2075. MAX_OVER_LIMIT_INFO* pConvertMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::MAX_OVER_LIMIT);
  2076. if (pInfo->name1.find("定位") != -1)
  2077. {
  2078. pFixMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 0, eZL_ALARMTYPE::MAX_OVER_LIMIT);
  2079. pInvertMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 1, eZL_ALARMTYPE::MAX_OVER_LIMIT);
  2080. }
  2081. else
  2082. {
  2083. pFixMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 1, eZL_ALARMTYPE::MAX_OVER_LIMIT);
  2084. pInvertMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 0, eZL_ALARMTYPE::MAX_OVER_LIMIT);
  2085. }
  2086. //定位
  2087. if (pFixMax && pFixMax->enable)
  2088. {
  2089. static string fixnameutf = ANSItoUTF8("定位");
  2090. if (pFixMax->alarm_high_limit != INT_MAX)
  2091. {
  2092. auto object = yyjson_mut_obj(doc);
  2093. yyjson_mut_arr_add_val(warn_line, object);
  2094. yyjson_mut_obj_add_str(doc, object, "label", fixnameutf.c_str());
  2095. yyjson_mut_obj_add_str(doc, object, "color", "red");
  2096. yyjson_mut_obj_add_int(doc, object, "val", pFixMax->alarm_high_limit);
  2097. }
  2098. if (pFixMax->warn_high_limit != INT_MAX)
  2099. {
  2100. auto object = yyjson_mut_obj(doc);
  2101. yyjson_mut_arr_add_val(warn_line, object);
  2102. yyjson_mut_obj_add_str(doc, object, "label", fixnameutf.c_str());
  2103. yyjson_mut_obj_add_str(doc, object, "color", "orange");
  2104. yyjson_mut_obj_add_int(doc, object, "val", pFixMax->warn_high_limit);
  2105. }
  2106. }
  2107. if (pInvertMax && pInvertMax->enable)
  2108. {
  2109. static string invertnameutf = ANSItoUTF8("反位");
  2110. if (pInvertMax->alarm_high_limit != INT_MAX)
  2111. {
  2112. auto object = yyjson_mut_obj(doc);
  2113. yyjson_mut_arr_add_val(warn_line, object);
  2114. yyjson_mut_obj_add_str(doc, object, "label", invertnameutf.c_str());
  2115. yyjson_mut_obj_add_str(doc, object, "color", "red");
  2116. yyjson_mut_obj_add_int(doc, object, "val", pInvertMax->alarm_high_limit);
  2117. }
  2118. if (pInvertMax->warn_high_limit != INT_MAX)
  2119. {
  2120. auto object = yyjson_mut_obj(doc);
  2121. yyjson_mut_arr_add_val(warn_line, object);
  2122. yyjson_mut_obj_add_str(doc, object, "label", invertnameutf.c_str());
  2123. yyjson_mut_obj_add_str(doc, object, "color", "orange");
  2124. yyjson_mut_obj_add_int(doc, object, "val", pInvertMax->warn_high_limit);
  2125. }
  2126. }
  2127. if (pConvertMax && pConvertMax->enable)
  2128. {
  2129. static string d2fnameutf = ANSItoUTF8("定扳反");
  2130. static string f2dnameutf = ANSItoUTF8("反扳定");
  2131. if (pConvertMax->alarm_high_limit != INT_MAX)
  2132. {
  2133. auto object = yyjson_mut_obj(doc);
  2134. yyjson_mut_arr_add_val(warn_line, object);
  2135. yyjson_mut_obj_add_str(doc, object, "label", d2fnameutf.c_str());
  2136. yyjson_mut_obj_add_str(doc, object, "color", "red");
  2137. yyjson_mut_obj_add_int(doc, object, "val", pConvertMax->alarm_high_limit);
  2138. }
  2139. if (pConvertMax->warn_high_limit != INT_MAX)
  2140. {
  2141. auto object = yyjson_mut_obj(doc);
  2142. yyjson_mut_arr_add_val(warn_line, object);
  2143. yyjson_mut_obj_add_str(doc, object, "label", d2fnameutf.c_str());
  2144. yyjson_mut_obj_add_str(doc, object, "color", "orange");
  2145. yyjson_mut_obj_add_int(doc, object, "val", pConvertMax->warn_high_limit);
  2146. }
  2147. if (pConvertMax->f_alarm_high_limit != INT_MAX)
  2148. {
  2149. auto object = yyjson_mut_obj(doc);
  2150. yyjson_mut_arr_add_val(warn_line, object);
  2151. yyjson_mut_obj_add_str(doc, object, "label", f2dnameutf.c_str());
  2152. yyjson_mut_obj_add_str(doc, object, "color", "red");
  2153. yyjson_mut_obj_add_int(doc, object, "val", pConvertMax->f_alarm_high_limit);
  2154. }
  2155. if (pConvertMax->f_warn_high_limit != INT_MAX)
  2156. {
  2157. auto object = yyjson_mut_obj(doc);
  2158. yyjson_mut_arr_add_val(warn_line, object);
  2159. yyjson_mut_obj_add_str(doc, object, "label", f2dnameutf.c_str());
  2160. yyjson_mut_obj_add_str(doc, object, "color", "orange");
  2161. yyjson_mut_obj_add_int(doc, object, "val", pConvertMax->f_warn_high_limit);
  2162. }
  2163. }
  2164. *json = yyjson_mut_write(doc, 0, json_len);
  2165. yyjson_mut_doc_free(doc);
  2166. return 200;
  2167. }
  2168. int DealPutChangeZzjno(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len)
  2169. {
  2170. if (token.find("AAAAAAAA") == -1) return 403;
  2171. int code = 400;
  2172. string msg;
  2173. auto req_doc = yyjson_read(body_ptr, body_len, 0);
  2174. if (req_doc == nullptr) return 400;
  2175. auto req_root = yyjson_doc_get_root(req_doc);
  2176. do
  2177. {
  2178. auto mo = yyjson_get_str(yyjson_obj_get(req_root, "mo"));
  2179. auto mp = yyjson_get_str(yyjson_obj_get(req_root, "mp"));
  2180. auto newNumber = yyjson_get_int(yyjson_obj_get(req_root, "newNumber"));
  2181. if (mo == nullptr || mp == nullptr || newNumber == 0) break;
  2182. //新编号已存在
  2183. if (CMonitorObjectMng::Instance()->GetMoMpInfoByZZJno(newNumber))
  2184. {
  2185. code = 400;
  2186. break;
  2187. }
  2188. auto pMoMp = CMonitorObjectMng::Instance()->GetMoMpInfo(string(mo) + "." + mp);
  2189. if (pMoMp == nullptr)
  2190. {
  2191. code = 404;
  2192. break;
  2193. }
  2194. CString sql = fmt::format("update rm_map set zzjno = {} where mo='{}' and mp = '{}';",
  2195. newNumber, mo, mp).c_str();
  2196. if (!CDBConnectPool::Instance()->DBExecuteSQL(sql))
  2197. {
  2198. code = 500;
  2199. break;
  2200. }
  2201. pMoMp->zzjno = newNumber;
  2202. code = 200;
  2203. break;
  2204. } while (false);
  2205. return code;
  2206. }
  2207. //int DealGetRetentionData(const httplib::Request& req, const string token, char** json, size_t* json_len)
  2208. //{
  2209. // string mo = req.get_param_value("mo");
  2210. // string mp = req.get_param_value("mp");
  2211. // string starttime = req.get_param_value("starttime");
  2212. // string endtime = req.get_param_value("endtime");
  2213. // string threshold = req.get_param_value("threshold");
  2214. // int nThreshold = 100;
  2215. // if (mo.length() == 0 || mp.length() == 0 || starttime.length() == 0 || endtime.length() == 0)
  2216. // return 400;
  2217. // if (threshold.empty() == false) nThreshold = atoi(threshold.c_str());
  2218. // if (nThreshold < 30) nThreshold = 30;
  2219. // if (nThreshold > 500) nThreshold = 500;
  2220. // COleDateTime odtStart, odtEnd;
  2221. // try
  2222. // {
  2223. // odtStart.ParseDateTime(starttime.c_str());
  2224. // odtEnd.ParseDateTime(endtime.c_str());
  2225. // }
  2226. // catch (CException*)
  2227. // {
  2228. // return 400;
  2229. // }
  2230. //
  2231. // auto momp = mo + "." + mp;
  2232. // auto pInfo = CMonitorObjectMng::Instance()->GetMoMpInfo(momp);
  2233. // if (pInfo == nullptr)
  2234. // return 404;
  2235. // if (pInfo->pDeivce == nullptr)
  2236. // return 404;
  2237. //
  2238. // if (odtStart >= odtEnd) return 400;
  2239. // char tablename[50] = { 0 };
  2240. // auto dtStartDate = COleDateTime(odtStart.GetYear(), odtStart.GetMonth(), odtStart.GetDay(), 0, 0, 0);
  2241. // auto dtEndDate = COleDateTime(odtEnd.GetYear(), odtEnd.GetMonth(), odtEnd.GetDay(), 0, 0, 0);
  2242. // auto strStartDate = dtStartDate.Format("%Y-%m-%d %H:%M:%S");
  2243. // auto strEndDate = dtEndDate.Format("%Y-%m-%d %H:%M:%S");;
  2244. // //auto strStartTime = odtStart.Format("%Y-%m-%d %H:%M:%S");
  2245. // //auto strEndTime = odtEnd.Format("%Y-%m-%d %H:%M:%S");
  2246. //
  2247. // CString sql = "SELECT TOP 100000 * FROM (";
  2248. // {
  2249. // int num = 0;
  2250. // for (auto it = dtStartDate; it < odtEnd;)
  2251. // {
  2252. // sprintf_s(tablename, 50, "rm_resistance_%04d%02d%02d", it.GetYear(), it.GetMonth(), it.GetDay());
  2253. // if (num == 0)
  2254. // {
  2255. // sql += fmt::format("SELECT [acquisitiontime],[data0],[data1],[data2] "\
  2256. // "FROM {} WHERE IMEI = '{}' AND acquisitiontime >= '{}' and acquisitiontime < '{}' AND idx = {} ",
  2257. // tablename, pInfo->imei.c_str(), starttime.c_str(), endtime.c_str(), pInfo->idx).c_str();
  2258. // }
  2259. // else
  2260. // {
  2261. // sql += fmt::format(" UNION ALL "\
  2262. // "SELECT [acquisitiontime],[data0],[data1],[data2] "\
  2263. // "FROM {} WHERE IMEI = '{}' AND acquisitiontime >= '{}' and acquisitiontime < '{}' AND idx = {} ",
  2264. // tablename, pInfo->imei.c_str(), starttime, endtime, pInfo->idx).c_str();
  2265. // }
  2266. // num++;
  2267. // it += COleDateTimeSpan(1, 0, 0, 0);
  2268. // }
  2269. // sql += ") AS A ORDER BY acquisitiontime ASC";
  2270. // }
  2271. //
  2272. // TIMESTAMP_STRUCT ts;
  2273. // int sdata0, sdata1, sdata2;
  2274. //
  2275. // COdbcStatement stmt;
  2276. //
  2277. // if (CDBConnectPool::Instance()->DBQuery(stmt, sql) == FALSE)
  2278. // {
  2279. // ASSERT(0);
  2280. // SPDLOG_ERROR("查询语句出错:{}", sql);
  2281. // return 500;
  2282. // }
  2283. //
  2284. // int nCol = 1;
  2285. // stmt.BindTimeStampCol(nCol++, &ts);
  2286. // stmt.BindIntCol(nCol++, &sdata0);
  2287. // stmt.BindIntCol(nCol++, &sdata1);
  2288. // stmt.BindIntCol(nCol++, &sdata2);
  2289. // int nCount = 0;
  2290. //
  2291. // auto doc = yyjson_mut_doc_new(nullptr);
  2292. // auto root = yyjson_mut_obj(doc);
  2293. // yyjson_mut_doc_set_root(doc, root);
  2294. // auto data = yyjson_mut_arr(doc);
  2295. // yyjson_mut_obj_add_val(doc, root, "data", data);
  2296. // auto curve_1 = yyjson_mut_obj(doc);
  2297. // auto curve_2 = yyjson_mut_obj(doc);
  2298. // auto curve_3 = yyjson_mut_obj(doc);
  2299. // yyjson_mut_arr_add_val(data, curve_1);
  2300. // yyjson_mut_arr_add_val(data, curve_2);
  2301. // yyjson_mut_arr_add_val(data, curve_3);
  2302. //
  2303. // yyjson_mut_obj_add_str(doc, root, "cmd", "query_hist");
  2304. // yyjson_mut_obj_add_strcpy(doc, root, "tag", (momp + ".resist").c_str());
  2305. // yyjson_mut_obj_add_str(doc, root, "data_fmt", "curve");
  2306. // yyjson_mut_obj_add_str(doc, root, "unit", "N");
  2307. // yyjson_mut_obj_add_str(doc, root, "time", "");
  2308. //
  2309. // //1号测力点
  2310. // yyjson_mut_obj_add_str(doc, curve_1, "name", pInfo->name1utf.c_str());
  2311. // auto points1 = yyjson_mut_arr(doc);
  2312. // yyjson_mut_obj_add_val(doc, curve_1, "points", points1);
  2313. //
  2314. // //2号测力点
  2315. // yyjson_mut_obj_add_str(doc, curve_2, "name", pInfo->name2utf.c_str());
  2316. // auto points2 = yyjson_mut_arr(doc);
  2317. // yyjson_mut_obj_add_val(doc, curve_2, "points", points2);
  2318. //
  2319. // //3号测力点
  2320. // yyjson_mut_obj_add_str(doc, curve_3, "name", pInfo->name3utf.c_str());
  2321. // auto points3 = yyjson_mut_arr(doc);
  2322. // yyjson_mut_obj_add_val(doc, curve_3, "points", points3);
  2323. //
  2324. // if (nThreshold == 0)
  2325. // {
  2326. // do
  2327. // {
  2328. // if (stmt.FetchNext() != 0)
  2329. // break;
  2330. //
  2331. // CTime ctTime;
  2332. // try
  2333. // {
  2334. // ctTime = CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
  2335. // }
  2336. // catch (...)
  2337. // {
  2338. // continue;
  2339. // }
  2340. // time_t tm = ctTime.GetTime() * 1000 + ts.fraction / 1000000;
  2341. //
  2342. //#ifdef SHOW_DATA
  2343. // {
  2344. // auto item = yyjson_mut_arr(doc);
  2345. // yyjson_mut_arr_add_val(points1, item);
  2346. // yyjson_mut_arr_add_uint(doc, item, tm);
  2347. // yyjson_mut_arr_add_int(doc, item, sdata0);
  2348. // }
  2349. // {
  2350. // auto item = yyjson_mut_arr(doc);
  2351. // yyjson_mut_arr_add_val(points2, item);
  2352. // yyjson_mut_arr_add_uint(doc, item, tm);
  2353. // yyjson_mut_arr_add_int(doc, item, sdata1);
  2354. // }
  2355. // {
  2356. // auto item = yyjson_mut_arr(doc);
  2357. // yyjson_mut_arr_add_val(points3, item);
  2358. // yyjson_mut_arr_add_uint(doc, item, tm);
  2359. // yyjson_mut_arr_add_int(doc, item, sdata2);
  2360. // }
  2361. //#endif
  2362. //
  2363. // nCount++;
  2364. //
  2365. // } while (true);
  2366. // }
  2367. // else {
  2368. // int lastdata0 = INT_MAX, lastdata1 = INT_MAX, lastdata2 = INT_MAX;
  2369. // time_t tm = 0;
  2370. // do
  2371. // {
  2372. // if (stmt.FetchNext() != 0)
  2373. // {
  2374. // if (tm != 0)
  2375. // {
  2376. // {
  2377. // auto item = yyjson_mut_arr(doc);
  2378. // yyjson_mut_arr_add_val(points1, item);
  2379. // yyjson_mut_arr_add_uint(doc, item, tm);
  2380. // yyjson_mut_arr_add_int(doc, item, sdata0);
  2381. // }
  2382. // {
  2383. // auto item = yyjson_mut_arr(doc);
  2384. // yyjson_mut_arr_add_val(points2, item);
  2385. // yyjson_mut_arr_add_uint(doc, item, tm);
  2386. // yyjson_mut_arr_add_int(doc, item, sdata1);
  2387. // }
  2388. // {
  2389. // auto item = yyjson_mut_arr(doc);
  2390. // yyjson_mut_arr_add_val(points3, item);
  2391. // yyjson_mut_arr_add_uint(doc, item, tm);
  2392. // yyjson_mut_arr_add_int(doc, item, sdata2);
  2393. // }
  2394. // }
  2395. // break;
  2396. // }
  2397. //
  2398. // CTime ctTime;
  2399. // try
  2400. // {
  2401. // ctTime = CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
  2402. // }
  2403. // catch (...)
  2404. // {
  2405. // continue;
  2406. // }
  2407. // tm = ctTime.GetTime() * 1000 + ts.fraction / 1000000;
  2408. //
  2409. //#ifdef SHOW_DATA
  2410. // if (abs(lastdata0 - sdata0) > nThreshold)
  2411. // {
  2412. // auto item = yyjson_mut_arr(doc);
  2413. // yyjson_mut_arr_add_val(points1, item);
  2414. // yyjson_mut_arr_add_uint(doc, item, tm);
  2415. // yyjson_mut_arr_add_int(doc, item, sdata0);
  2416. // lastdata0 = sdata0;
  2417. // }
  2418. // if (abs(lastdata1 - sdata1) > nThreshold)
  2419. // {
  2420. // auto item = yyjson_mut_arr(doc);
  2421. // yyjson_mut_arr_add_val(points2, item);
  2422. // yyjson_mut_arr_add_uint(doc, item, tm);
  2423. // yyjson_mut_arr_add_int(doc, item, sdata1);
  2424. // lastdata1 = sdata1;
  2425. // }
  2426. // if (abs(lastdata2 - sdata2) > nThreshold)
  2427. // {
  2428. // auto item = yyjson_mut_arr(doc);
  2429. // yyjson_mut_arr_add_val(points3, item);
  2430. // yyjson_mut_arr_add_uint(doc, item, tm);
  2431. // yyjson_mut_arr_add_int(doc, item, sdata2);
  2432. // lastdata2 = sdata2;
  2433. // }
  2434. //#endif
  2435. //
  2436. // nCount++;
  2437. //
  2438. // } while (true);
  2439. // }
  2440. //
  2441. // stmt.Close();
  2442. // yyjson_mut_obj_add_int(doc, root, "count", nCount);
  2443. // if (nCount >= 100000)
  2444. // yyjson_mut_obj_add_bool(doc, root, "has_more", true);
  2445. // else
  2446. // yyjson_mut_obj_add_bool(doc, root, "has_more", false);
  2447. // //扳动信息
  2448. // auto fix_points = yyjson_mut_arr(doc);
  2449. // auto invert_points = yyjson_mut_arr(doc);
  2450. // auto convert_points = yyjson_mut_arr(doc);
  2451. // if (pInfo->name1.find("定位") != -1)
  2452. // {
  2453. // yyjson_mut_obj_add_val(doc, curve_1, "mark_points", fix_points);
  2454. // yyjson_mut_obj_add_val(doc, curve_2, "mark_points", invert_points);
  2455. // }
  2456. // else
  2457. // {
  2458. // yyjson_mut_obj_add_val(doc, curve_1, "mark_points", invert_points);
  2459. // yyjson_mut_obj_add_val(doc, curve_2, "mark_points", fix_points);
  2460. // }
  2461. // yyjson_mut_obj_add_val(doc, curve_3, "mark_points", convert_points);
  2462. //
  2463. // //auto pConvertLimit = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
  2464. // //auto pFixSuobi = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_FIX, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
  2465. // //auto pInvertSuobi = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_INVERT, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
  2466. //
  2467. // {
  2468. // int num = 0;
  2469. // int lastyearmonth = 0;
  2470. // for (auto it = dtStartDate; it <= dtEndDate;)
  2471. // {
  2472. // int yearmonth = it.GetYear() * 100 + it.GetMonth();
  2473. // if (yearmonth != lastyearmonth)
  2474. // {
  2475. // lastyearmonth = yearmonth;
  2476. // sprintf_s(tablename, 50, "rm_move_%04d%02d", it.GetYear(), it.GetMonth());
  2477. // if (num == 0)
  2478. // {
  2479. // sql = fmt::format("SELECT show_time, curr_val, show_val, posiFROM {} \
  2480. // WHERE mo = '{}' AND mp = '{}' AND show_time >= '{}' AND show_time <= '{}' AND [type] = 2 ",
  2481. // tablename, mo, mp, starttime, endtime).c_str();
  2482. // }
  2483. // else
  2484. // {
  2485. // sql += fmt::format(" UNION ALL "\
  2486. // "SELECT show_time, curr_val, show_val, posi FROM {} \
  2487. // WHERE mo = '{}' AND mp = '{}' AND show_time >= '{}' AND show_time <= '{}' AND [type] = 2 ",
  2488. // tablename, mo, mp, starttime, endtime).c_str();
  2489. // }
  2490. // num++;
  2491. // }
  2492. // it += COleDateTimeSpan(1, 0, 0, 0);
  2493. // }
  2494. // sql += "order by posi, show_time";
  2495. // }
  2496. //
  2497. // if (CDBConnectPool::Instance()->DBQuery(stmt, sql))
  2498. // {
  2499. //
  2500. // TIMESTAMP_STRUCT ts;
  2501. // int curr_val;
  2502. // int show_val;
  2503. // eDaoChaPosi posi;
  2504. // ePowerName pn;
  2505. //
  2506. // int nCol = 1;
  2507. // stmt.BindTimeStampCol(nCol++, &ts);
  2508. // stmt.BindIntCol(nCol++, &curr_val);
  2509. // stmt.BindIntCol(nCol++, &show_val);
  2510. // stmt.BindTinyIntCol(nCol++, (BYTE*)&posi);
  2511. // stmt.BindTinyIntCol(nCol++, (BYTE*)&pn);
  2512. //
  2513. // do
  2514. // {
  2515. // if (stmt.FetchNext() != 0)
  2516. // break;
  2517. //
  2518. // auto obj = yyjson_mut_obj(doc);
  2519. //
  2520. // switch (posi)
  2521. // {
  2522. // case eDaoChaPosi::DCP_FIX:
  2523. // {
  2524. // if (pn == ePowerName::PN_RETENTION)
  2525. // {
  2526. // yyjson_mut_arr_add_val(fix_points, obj);
  2527. // auto coord = yyjson_mut_arr(doc);
  2528. // yyjson_mut_obj_add_val(doc, obj, "coord", coord);
  2529. // 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);
  2530. // yyjson_mut_arr_add_int(doc, coord, curr_val);
  2531. // yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
  2532. // ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
  2533. // yyjson_mut_obj_add_int(doc, obj, "val", show_val);
  2534. //
  2535. // //if (pFixSuobi && pFixSuobi->enable)
  2536. // //{
  2537. // // if (pFixSuobi->alarm_low_limit > show_val)
  2538. // // yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  2539. // // else if (pFixSuobi->alarm_high_limit < show_val)
  2540. // // yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  2541. // // else if (pFixSuobi->warn_high_limit < show_val)
  2542. // // yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  2543. // // else if (pFixSuobi->warn_low_limit > show_val)
  2544. // // yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  2545. // //}
  2546. // yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("保持力:{}", show_val)).c_str());
  2547. // }
  2548. // //if (show_val < 500)//TODO
  2549. // //{
  2550. // // yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  2551. // // yyjson_mut_obj_add_str(doc, obj, "label", lock_low.c_str());
  2552. // //}
  2553. // //else
  2554. // //{
  2555. // // yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str());
  2556. // //}
  2557. // }
  2558. // break;
  2559. // case eDaoChaPosi::DCP_INVERT:
  2560. // {
  2561. // if (pn == ePowerName::PN_RETENTION)
  2562. // {
  2563. // yyjson_mut_arr_add_val(invert_points, obj);
  2564. // auto coord = yyjson_mut_arr(doc);
  2565. // yyjson_mut_obj_add_val(doc, obj, "coord", coord);
  2566. // 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);
  2567. // yyjson_mut_arr_add_int(doc, coord, curr_val);
  2568. // yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
  2569. // ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
  2570. // yyjson_mut_obj_add_int(doc, obj, "val", show_val);
  2571. //
  2572. // //if (pInvertSuobi && pInvertSuobi->enable)
  2573. // //{
  2574. // // if (pInvertSuobi->alarm_low_limit > show_val)
  2575. // // yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  2576. // // else if (pInvertSuobi->alarm_high_limit < show_val)
  2577. // // yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  2578. // // else if (pInvertSuobi->warn_high_limit < show_val)
  2579. // // yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  2580. // // else if (pInvertSuobi->warn_low_limit > show_val)
  2581. // // yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  2582. // //}
  2583. // yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("保持力:{}", show_val)).c_str());
  2584. // }
  2585. // //if (show_val < 500)//TODO
  2586. // //{
  2587. // // yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  2588. // // yyjson_mut_obj_add_str(doc, obj, "label", lock_low.c_str());
  2589. // //}
  2590. // //else
  2591. // //{
  2592. // // yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str());
  2593. // //}
  2594. // }
  2595. // break;
  2596. // default:
  2597. // ASSERT(FALSE);
  2598. // break;
  2599. // }
  2600. //
  2601. // } while (TRUE);
  2602. // }
  2603. // stmt.Close();
  2604. //
  2605. // ////报警线
  2606. // //auto warn_line = yyjson_mut_arr(doc);
  2607. // //yyjson_mut_obj_add_val(doc, root, "warn_line", warn_line);
  2608. //
  2609. // //MAX_OVER_LIMIT_INFO* pFixMax = nullptr;
  2610. // //MAX_OVER_LIMIT_INFO* pInvertMax = nullptr;
  2611. // //MAX_OVER_LIMIT_INFO* pConvertMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::MAX_OVER_LIMIT);
  2612. // //if (pInfo->name1.find("定位") != -1)
  2613. // //{
  2614. // // pFixMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 0, eZL_ALARMTYPE::MAX_OVER_LIMIT);
  2615. // // pInvertMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 1, eZL_ALARMTYPE::MAX_OVER_LIMIT);
  2616. // //}
  2617. // //else
  2618. // //{
  2619. // // pFixMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 1, eZL_ALARMTYPE::MAX_OVER_LIMIT);
  2620. // // pInvertMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 0, eZL_ALARMTYPE::MAX_OVER_LIMIT);
  2621. // //}
  2622. // ////定位
  2623. // //if (pFixMax && pFixMax->enable)
  2624. // //{
  2625. // // static string fixnameutf = ANSItoUTF8("定位");
  2626. // // if (pFixMax->alarm_high_limit != INT_MAX)
  2627. // // {
  2628. // // auto object = yyjson_mut_obj(doc);
  2629. // // yyjson_mut_arr_add_val(warn_line, object);
  2630. // // yyjson_mut_obj_add_str(doc, object, "label", fixnameutf.c_str());
  2631. // // yyjson_mut_obj_add_str(doc, object, "color", "red");
  2632. // // yyjson_mut_obj_add_int(doc, object, "val", pFixMax->alarm_high_limit);
  2633. // // }
  2634. // // if (pFixMax->warn_high_limit != INT_MAX)
  2635. // // {
  2636. // // auto object = yyjson_mut_obj(doc);
  2637. // // yyjson_mut_arr_add_val(warn_line, object);
  2638. // // yyjson_mut_obj_add_str(doc, object, "label", fixnameutf.c_str());
  2639. // // yyjson_mut_obj_add_str(doc, object, "color", "orange");
  2640. // // yyjson_mut_obj_add_int(doc, object, "val", pFixMax->warn_high_limit);
  2641. // // }
  2642. // //}
  2643. // //if (pInvertMax && pInvertMax->enable)
  2644. // //{
  2645. // // static string invertnameutf = ANSItoUTF8("反位");
  2646. // // if (pInvertMax->alarm_high_limit != INT_MAX)
  2647. // // {
  2648. // // auto object = yyjson_mut_obj(doc);
  2649. // // yyjson_mut_arr_add_val(warn_line, object);
  2650. // // yyjson_mut_obj_add_str(doc, object, "label", invertnameutf.c_str());
  2651. // // yyjson_mut_obj_add_str(doc, object, "color", "red");
  2652. // // yyjson_mut_obj_add_int(doc, object, "val", pInvertMax->alarm_high_limit);
  2653. // // }
  2654. // // if (pInvertMax->warn_high_limit != INT_MAX)
  2655. // // {
  2656. // // auto object = yyjson_mut_obj(doc);
  2657. // // yyjson_mut_arr_add_val(warn_line, object);
  2658. // // yyjson_mut_obj_add_str(doc, object, "label", invertnameutf.c_str());
  2659. // // yyjson_mut_obj_add_str(doc, object, "color", "orange");
  2660. // // yyjson_mut_obj_add_int(doc, object, "val", pInvertMax->warn_high_limit);
  2661. // // }
  2662. // //}
  2663. // //if (pConvertMax && pConvertMax->enable)
  2664. // //{
  2665. // // static string d2fnameutf = ANSItoUTF8("定扳反");
  2666. // // static string f2dnameutf = ANSItoUTF8("反扳定");
  2667. // // if (pConvertMax->alarm_high_limit != INT_MAX)
  2668. // // {
  2669. // // auto object = yyjson_mut_obj(doc);
  2670. // // yyjson_mut_arr_add_val(warn_line, object);
  2671. // // yyjson_mut_obj_add_str(doc, object, "label", d2fnameutf.c_str());
  2672. // // yyjson_mut_obj_add_str(doc, object, "color", "red");
  2673. // // yyjson_mut_obj_add_int(doc, object, "val", pConvertMax->alarm_high_limit);
  2674. // // }
  2675. // // if (pConvertMax->warn_high_limit != INT_MAX)
  2676. // // {
  2677. // // auto object = yyjson_mut_obj(doc);
  2678. // // yyjson_mut_arr_add_val(warn_line, object);
  2679. // // yyjson_mut_obj_add_str(doc, object, "label", d2fnameutf.c_str());
  2680. // // yyjson_mut_obj_add_str(doc, object, "color", "orange");
  2681. // // yyjson_mut_obj_add_int(doc, object, "val", pConvertMax->warn_high_limit);
  2682. // // }
  2683. // // if (pConvertMax->f_alarm_high_limit != INT_MAX)
  2684. // // {
  2685. // // auto object = yyjson_mut_obj(doc);
  2686. // // yyjson_mut_arr_add_val(warn_line, object);
  2687. // // yyjson_mut_obj_add_str(doc, object, "label", f2dnameutf.c_str());
  2688. // // yyjson_mut_obj_add_str(doc, object, "color", "red");
  2689. // // yyjson_mut_obj_add_int(doc, object, "val", pConvertMax->f_alarm_high_limit);
  2690. // // }
  2691. // // if (pConvertMax->f_warn_high_limit != INT_MAX)
  2692. // // {
  2693. // // auto object = yyjson_mut_obj(doc);
  2694. // // yyjson_mut_arr_add_val(warn_line, object);
  2695. // // yyjson_mut_obj_add_str(doc, object, "label", f2dnameutf.c_str());
  2696. // // yyjson_mut_obj_add_str(doc, object, "color", "orange");
  2697. // // yyjson_mut_obj_add_int(doc, object, "val", pConvertMax->f_warn_high_limit);
  2698. // // }
  2699. // //}
  2700. //
  2701. // *json = yyjson_mut_write(doc, 0, json_len);
  2702. // yyjson_mut_doc_free(doc);
  2703. //
  2704. // return 200;
  2705. //}
  2706. //设置参考曲线
  2707. int DealPostrefer_curve(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len)
  2708. {
  2709. int code = 400;
  2710. string msg;
  2711. auto req_doc = yyjson_read(body_ptr, body_len, 0);
  2712. if (req_doc == nullptr) return 400;
  2713. auto req_root = yyjson_doc_get_root(req_doc);
  2714. auto doc = yyjson_mut_doc_new(nullptr);
  2715. auto root = yyjson_mut_obj(doc);
  2716. yyjson_mut_doc_set_root(doc, root);
  2717. do
  2718. {
  2719. auto station = yyjson_get_str(yyjson_obj_get(req_root, "station"));
  2720. auto mo = yyjson_get_str(yyjson_obj_get(req_root, "mo"));
  2721. auto mp = yyjson_get_str(yyjson_obj_get(req_root, "mp"));
  2722. auto mo_name = yyjson_get_str(yyjson_obj_get(req_root, "mo_name"));
  2723. auto mp_name = yyjson_get_str(yyjson_obj_get(req_root, "mp_name"));
  2724. auto direct = yyjson_get_int(yyjson_obj_get(req_root, "direct"));
  2725. auto show_time = yyjson_get_str(yyjson_obj_get(req_root, "show_time"));
  2726. auto full_name = yyjson_get_str(yyjson_obj_get(req_root, "full_name"));
  2727. if (station == nullptr || show_time == 0 || mo == nullptr || mp == nullptr || (direct != 3 && direct != 4) || full_name == nullptr
  2728. || mo_name == nullptr || mp_name == nullptr)
  2729. {
  2730. msg = "参数错误";
  2731. break;
  2732. }
  2733. auto strStation = UTF8toANSI(station);
  2734. auto strName = UTF8toANSI(full_name);
  2735. time_t tt;
  2736. time(&tt);
  2737. auto len = strlen(show_time);
  2738. if (len == 0) //取消参考曲线
  2739. {
  2740. auto strPath = CSimpleLog::GetAppDir() + "refer\\" +
  2741. fmt::format("{}.{}.{}.{}.json", strStation, mo, mp, direct).c_str();
  2742. if (CSimpleLog::PathFileExistsA(strPath))
  2743. DeleteFile(strPath);
  2744. ExecSqlForRecord(eRecord_Module::RM_REFER, 0, 0, strStation, strStation, mo, mo_name, mp, mp_name, 0, 0, tt, strName, "", eRocord_Opt::RO_CONFIG,
  2745. fmt::format("用户[{}]取消了[{}.{}][{}]的参考曲线", strName, mo_name, mp_name, direct == 3 ? "定扳反" : "反扳定"));
  2746. msg = "操作成功.";
  2747. code = 200;
  2748. break;
  2749. }
  2750. int yy, mm, dd, hh, MM, SS, micromm;
  2751. auto ret_num = sscanf_s(show_time, "%d-%d-%d %d:%d:%d.%d", &yy, &mm, &dd, &hh, &MM, &SS, &micromm);
  2752. if (ret_num != 7)
  2753. {
  2754. msg = "show_time参数错误";
  2755. break;
  2756. }
  2757. 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",
  2758. yy, mm, mo, mp, show_time).c_str();
  2759. COdbcStatement stmt;
  2760. if (CDBConnectPool::Instance()->DBQuery(stmt, sql) == FALSE)
  2761. {
  2762. ASSERT(FALSE);
  2763. msg = "语句执行失败:" + sql;
  2764. code = 500;
  2765. break;
  2766. }
  2767. TIMESTAMP_STRUCT ts = { 0 }, tsEnd = { 0 };
  2768. uint8_t idx = -1;
  2769. stmt.BindTimeStampCol(1, &ts);
  2770. stmt.BindTimeStampCol(2, &tsEnd);
  2771. stmt.BindTinyIntCol(3, &idx);
  2772. if (stmt.FetchNext() != 0)
  2773. {
  2774. msg = "查询转换记录失败";
  2775. code = 500;
  2776. break;
  2777. }
  2778. stmt.Close();
  2779. string imei; int idx_2;
  2780. if (CMonitorObjectMng::Instance()->MOMP2IMEI(string(mo), string(mp), imei, idx_2) == FALSE)
  2781. {
  2782. msg = "查询imei失败";
  2783. code = 500;
  2784. break;
  2785. }
  2786. ASSERT(idx == idx_2);
  2787. CTime ctStart(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
  2788. CTime ctEnd(tsEnd.year, tsEnd.month, tsEnd.day, tsEnd.hour, tsEnd.minute, tsEnd.second);
  2789. sql = fmt::format(" SELECT acquisitiontime,data0,data1,data2 FROM rm_resistance_{:0>4}{:0>2}{:0>2}\
  2790. WHERE IMEI = '{}' AND acquisitiontime between '{}' and '{}' AND idx = {}",
  2791. ts.year, ts.month, ts.day, imei, ctStart.Format("%Y-%m-%d %H:%M:%S"), ctEnd.Format("%Y-%m-%d %H:%M:%S"),idx
  2792. ).c_str();
  2793. int sdata0, sdata1, sdata2;
  2794. if (CDBConnectPool::Instance()->DBQuery(stmt, sql) == FALSE)
  2795. {
  2796. ASSERT(FALSE);
  2797. msg = "语句执行失败:" + sql;
  2798. code = 500;
  2799. break;
  2800. }
  2801. int nCol = 1;
  2802. stmt.BindTimeStampCol(nCol++, &ts);
  2803. stmt.BindIntCol(nCol++, &sdata0);
  2804. stmt.BindIntCol(nCol++, &sdata1);
  2805. stmt.BindIntCol(nCol++, &sdata2);
  2806. int no = 0;
  2807. std::map<time_t, int> data0, data1, data2;
  2808. //time_t tmStart = ctStart.GetTime() * 1000; //存储数据时, 以起始时间为0
  2809. time_t tmShowTime = CTime(yy, mm, dd, hh, MM, SS).GetTime() * 1000 + micromm;
  2810. do
  2811. {
  2812. if (stmt.FetchNext() != 0)
  2813. break;
  2814. no++;
  2815. CTime ctTime;
  2816. try
  2817. {
  2818. ctTime = CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
  2819. }
  2820. catch (...)
  2821. {
  2822. continue;
  2823. }
  2824. time_t tm = ctTime.GetTime() * 1000 + ts.fraction / 1000000 - tmShowTime;
  2825. data0[tm] = sdata0;
  2826. data1[tm] = sdata1;
  2827. data2[tm] = sdata2;
  2828. } while (true);
  2829. stmt.Close();
  2830. if (no == 0)
  2831. {
  2832. msg = "数据为空";
  2833. code = 500;
  2834. break;
  2835. }
  2836. //存储数据
  2837. code = WriteReferFile(strStation, mo, mp, direct, data0, data1, data2, msg);
  2838. ExecSqlForRecord(eRecord_Module::RM_REFER, 0, 0, strStation, strStation, mo, mo_name, mp, mp_name, 0, 0, tt, strName, "", eRocord_Opt::RO_CONFIG,
  2839. fmt::format("用户[{}]设置了[{}.{}][{}]的参考曲线", strName, mo_name, mp_name, direct == 3 ? "定扳反" : "反扳定"));
  2840. } while (false);
  2841. yyjson_mut_obj_add_strcpy(doc, root, "msg", ANSItoUTF8(msg).c_str());
  2842. yyjson_mut_obj_add_int(doc, root, "code", code);
  2843. if (json) *json = yyjson_mut_write(doc, 0, json_len);
  2844. yyjson_doc_free(req_doc);
  2845. yyjson_mut_doc_free(doc);
  2846. return code;
  2847. }
  2848. int WriteReferFile(const string& station, const string& mo, const string& mp, uint8_t posi,
  2849. const std::map<time_t, int>& data0, const std::map<time_t, int>& data1, const std::map<time_t, int>& data2, OUT string& msg)
  2850. {
  2851. string strJsonPath = fmt::format("{}refer\\{}.{}.{}.{}.json", CSimpleLog::GetAppDir(), station, mo, mp, posi);
  2852. string name1, name2, name3, out_name, in_name;
  2853. CMonitorObjectMng::Instance()->GetNameByMoMp(mo + "." + mp, name1, name2, name3, out_name, in_name);
  2854. auto doc = yyjson_mut_doc_new(nullptr);
  2855. auto root = yyjson_mut_obj(doc);
  2856. yyjson_mut_doc_set_root(doc, root);
  2857. yyjson_mut_obj_add_strcpy(doc, root, "station", ANSItoUTF8(station).c_str());
  2858. yyjson_mut_obj_add_strcpy(doc, root, "mo", mo.c_str());
  2859. yyjson_mut_obj_add_strcpy(doc, root, "mp", mp.c_str());
  2860. yyjson_mut_obj_add_int(doc, root, "posi", posi);
  2861. auto t = yyjson_mut_arr(doc);
  2862. yyjson_mut_obj_add_val(doc, root, "t", t);
  2863. auto d0 = yyjson_mut_arr(doc);
  2864. yyjson_mut_obj_add_val(doc, root, "d0", d0);
  2865. auto d1 = yyjson_mut_arr(doc);
  2866. yyjson_mut_obj_add_val(doc, root, "d1", d1);
  2867. auto d2 = yyjson_mut_arr(doc);
  2868. yyjson_mut_obj_add_val(doc, root, "d2", d2);
  2869. if (name1.find("定位") != -1)
  2870. {
  2871. yyjson_mut_obj_add_strcpy(doc, root, "name0", ANSItoUTF8("定位参考曲线").c_str());
  2872. yyjson_mut_obj_add_strcpy(doc, root, "name1", ANSItoUTF8("反位参考曲线").c_str());
  2873. yyjson_mut_obj_add_strcpy(doc, root, "name2", ANSItoUTF8("转换参考曲线").c_str());
  2874. }
  2875. else
  2876. {
  2877. yyjson_mut_obj_add_strcpy(doc, root, "name0", ANSItoUTF8("反位参考曲线").c_str());
  2878. yyjson_mut_obj_add_strcpy(doc, root, "name1", ANSItoUTF8("定位参考曲线").c_str());
  2879. yyjson_mut_obj_add_strcpy(doc, root, "name2", ANSItoUTF8("转换参考曲线").c_str());
  2880. }
  2881. for (auto& it : data0)
  2882. {
  2883. yyjson_mut_arr_add_int(doc, t, it.first);
  2884. yyjson_mut_arr_add_int(doc, d0, it.second);
  2885. }
  2886. for (auto& it : data1)
  2887. yyjson_mut_arr_add_int(doc, d1, it.second);
  2888. for (auto& it : data2)
  2889. yyjson_mut_arr_add_int(doc, d2, it.second);
  2890. yyjson_write_err err;
  2891. auto ret = yyjson_mut_write_file(strJsonPath.c_str(), doc, 0, nullptr, &err);
  2892. if (ret == false)
  2893. {
  2894. msg = fmt::format("写入文件错误:{} 错误码:{}", strJsonPath, err.msg);
  2895. CSimpleLog::Error(msg.c_str());
  2896. return 500;
  2897. }
  2898. msg = "处理成功.";
  2899. return 200;
  2900. }
  2901. int DealGetResistCurve(const httplib::Request& req, const string token, char** json, size_t* json_len)
  2902. {
  2903. string mo = req.get_param_value("mo");
  2904. string mp = req.get_param_value("mp");
  2905. string time = req.get_param_value("time");
  2906. string name = req.get_param_value("name");
  2907. string end_time = req.get_param_value("end_time");
  2908. string type = req.get_param_value("type");
  2909. if (mo.length() == 0 || mp.length() == 0 || time.length() == 0 || name.length() == 0)
  2910. return 400;
  2911. if (type.compare("1") != 0)
  2912. return 501;//后台未实现
  2913. time_t uTime = atoll(time.c_str());
  2914. COleDateTime odt(uTime);
  2915. COleDateTime odtEnd(odt);
  2916. if (odt.GetStatus() == COleDateTime::invalid)
  2917. return 400;
  2918. if (end_time.empty() == false)
  2919. {
  2920. odtEnd = COleDateTime(atoll(end_time.c_str()));
  2921. if (odtEnd.GetStatus() == COleDateTime::invalid)
  2922. return 400;
  2923. }
  2924. auto doc = yyjson_mut_doc_new(nullptr);
  2925. auto root = yyjson_mut_obj(doc);
  2926. yyjson_mut_doc_set_root(doc, root);
  2927. auto convert_resist = yyjson_mut_obj(doc);
  2928. yyjson_mut_obj_add_val(doc, root, "convert_resist", convert_resist);//转换阻力
  2929. auto suobi_lock = yyjson_mut_obj(doc);
  2930. yyjson_mut_obj_add_val(doc, root, "suobi_lock", suobi_lock);//锁闭力数据
  2931. //auto baochi_lock = yyjson_mut_obj(doc);
  2932. //yyjson_mut_obj_add_val(doc, root, "baochi_lock", baochi_lock);//保持力数据
  2933. yyjson_mut_obj_add_str(doc, root, "name", name.c_str());
  2934. yyjson_mut_obj_add_str(doc, root, "unit", "N");
  2935. yyjson_mut_obj_add_uint(doc, root, "time", uTime);
  2936. //title
  2937. yyjson_mut_obj_add_strcpy(doc, convert_resist, "title", ANSItoUTF8("转换阻力峰值统计图").c_str());
  2938. yyjson_mut_obj_add_strcpy(doc, suobi_lock, "title", ANSItoUTF8("定反位锁闭力值统计图").c_str());
  2939. //yyjson_mut_obj_add_strcpy(doc, baochi_lock, "title", ANSItoUTF8("定反位保持力值统计图").c_str());
  2940. //curve_data and line
  2941. auto convert_curve_data = yyjson_mut_arr(doc);
  2942. yyjson_mut_obj_add_val(doc, convert_resist, "curve_data", convert_curve_data);
  2943. auto suobi_curve_data = yyjson_mut_arr(doc);
  2944. yyjson_mut_obj_add_val(doc, suobi_lock, "curve_data", suobi_curve_data);
  2945. //auto baochi_curve_data = yyjson_mut_arr(doc);
  2946. //yyjson_mut_obj_add_val(doc, baochi_lock, "curve_data", baochi_curve_data);
  2947. auto convert_line = yyjson_mut_arr(doc);
  2948. yyjson_mut_obj_add_val(doc, convert_resist, "line", convert_line);
  2949. auto suobi_line = yyjson_mut_arr(doc);
  2950. yyjson_mut_obj_add_val(doc, suobi_lock, "line", suobi_line);
  2951. //auto baochi_line = yyjson_mut_arr(doc);
  2952. //yyjson_mut_obj_add_val(doc, baochi_lock, "line", baochi_line);
  2953. //curve_obj
  2954. auto d_convert_obj = yyjson_mut_obj(doc);
  2955. yyjson_mut_obj_add_strcpy(doc, d_convert_obj, "name", ANSItoUTF8("定扳反转换阻力峰值").c_str());
  2956. yyjson_mut_obj_add_str(doc, d_convert_obj, "color", "#a8ff78");// 苹果绿
  2957. yyjson_mut_arr_add_val(convert_curve_data, d_convert_obj);
  2958. auto f_convert_obj = yyjson_mut_obj(doc);
  2959. yyjson_mut_obj_add_strcpy(doc, f_convert_obj, "name", ANSItoUTF8("反扳定转换阻力峰值").c_str());
  2960. yyjson_mut_obj_add_str(doc, f_convert_obj, "color", "#FFE000");// 芒果黄
  2961. yyjson_mut_arr_add_val(convert_curve_data, f_convert_obj);
  2962. auto d_suobi_obj = yyjson_mut_obj(doc);
  2963. yyjson_mut_obj_add_strcpy(doc, d_suobi_obj, "name", ANSItoUTF8("定位锁闭力值").c_str());
  2964. yyjson_mut_obj_add_str(doc, d_suobi_obj, "color", "#a8ff78");// 苹果绿
  2965. yyjson_mut_arr_add_val(suobi_curve_data, d_suobi_obj);
  2966. auto f_suobi_obj = yyjson_mut_obj(doc);
  2967. yyjson_mut_obj_add_strcpy(doc, f_suobi_obj, "name", ANSItoUTF8("反位锁闭力值").c_str());
  2968. yyjson_mut_obj_add_str(doc, f_suobi_obj, "color", "#FFE000");// 芒果黄
  2969. yyjson_mut_arr_add_val(suobi_curve_data, f_suobi_obj);
  2970. //auto d_baochi_obj = yyjson_mut_obj(doc);
  2971. //yyjson_mut_obj_add_strcpy(doc, d_baochi_obj, "name", ANSItoUTF8("定位保持力值").c_str());
  2972. //yyjson_mut_obj_add_str(doc, d_baochi_obj, "color", "#a8ff78");// 苹果绿
  2973. //yyjson_mut_arr_add_val(baochi_curve_data, d_baochi_obj);
  2974. //auto f_baochi_obj = yyjson_mut_obj(doc);
  2975. //yyjson_mut_obj_add_strcpy(doc, f_baochi_obj, "name", ANSItoUTF8("反位保持力值").c_str());
  2976. //yyjson_mut_obj_add_str(doc, f_baochi_obj, "color", "#FFE000");// 芒果黄
  2977. //yyjson_mut_arr_add_val(baochi_curve_data, f_baochi_obj);
  2978. //curve_data
  2979. auto d_convert_data = yyjson_mut_arr(doc);
  2980. yyjson_mut_obj_add_val(doc, d_convert_obj, "data", d_convert_data);
  2981. auto f_convert_data = yyjson_mut_arr(doc);
  2982. yyjson_mut_obj_add_val(doc, f_convert_obj, "data", f_convert_data);
  2983. auto d_suobi_data = yyjson_mut_arr(doc);
  2984. yyjson_mut_obj_add_val(doc, d_suobi_obj, "data", d_suobi_data);
  2985. auto f_suobi_data = yyjson_mut_arr(doc);
  2986. yyjson_mut_obj_add_val(doc, f_suobi_obj, "data", f_suobi_data);
  2987. //auto d_baochi_data = yyjson_mut_arr(doc);
  2988. //yyjson_mut_obj_add_val(doc, d_baochi_obj, "data", d_baochi_data);
  2989. //auto f_baochi_data = yyjson_mut_arr(doc);
  2990. //yyjson_mut_obj_add_val(doc, f_baochi_obj, "data", f_baochi_data);
  2991. //query
  2992. //TODO 查询数据库 填充 d_convert_data f_convert_data d_suobi_data f_suobi_data
  2993. {
  2994. string table_name = fmt::format("rm_move_{:0>4}{:0>2}", odt.GetYear(), odt.GetMonth());
  2995. CString sql;
  2996. if (odt.GetMonth() == odtEnd.GetMonth())
  2997. {
  2998. sql = fmt::format("SELECT show_time,show_val,posi,[type],[sunroof] FROM {} WHERE mo = '{}' AND mp = '{}' AND show_time >= '{}' AND show_time <= '{}'",
  2999. table_name, mo, mp, odt.Format("%Y-%m-%d 00:00:00"), odtEnd.Format("%Y-%m-%d 23:59:59.999")).c_str();
  3000. }
  3001. else
  3002. {
  3003. string table_name_next = fmt::format("rm_move_{:0>4}{:0>2}", odtEnd.GetYear(), odtEnd.GetMonth());
  3004. sql = fmt::format("SELECT show_time,show_val,posi,[type],[sunroof] FROM {0} WHERE mo = '{1}' AND mp = '{2}' AND show_time >= '{3}' \
  3005. UNION SELECT show_time, show_val, posi,[type] FROM {4} WHERE mo = '{1}' AND mp = '{2}' AND show_time <= '{5}'",
  3006. 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();
  3007. }
  3008. COdbcStatement stmt;
  3009. if (CDBConnectPool::Instance()->DBQuery(stmt, sql))
  3010. {
  3011. int nCol = 1;
  3012. TIMESTAMP_STRUCT ts;
  3013. int show_val;
  3014. eDaoChaPosi posi;
  3015. ePowerName pn;
  3016. stmt.BindTimeStampCol(nCol++, &ts);
  3017. stmt.BindIntCol(nCol++, &show_val);
  3018. stmt.BindTinyIntCol(nCol++, (BYTE*)&posi);
  3019. stmt.BindTinyIntCol(nCol++, (BYTE*)&pn);
  3020. do
  3021. {
  3022. if (stmt.FetchNext() != 0)
  3023. break;
  3024. CTime ctTime;
  3025. try
  3026. {
  3027. ctTime = CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
  3028. }
  3029. catch (...)
  3030. {
  3031. continue;
  3032. }
  3033. time_t tt = ctTime.GetTime() * 1000 + ts.fraction / 1000000;
  3034. auto o = yyjson_mut_arr(doc);
  3035. yyjson_mut_arr_add_int(doc, o, tt);
  3036. yyjson_mut_arr_add_int(doc, o, show_val);
  3037. switch (posi)
  3038. {
  3039. case eDaoChaPosi::DCP_FIX:
  3040. if (pn == ePowerName::PN_RETENTION)
  3041. {
  3042. //yyjson_mut_arr_add_val(d_baochi_data, o);
  3043. }
  3044. else
  3045. {
  3046. yyjson_mut_arr_add_val(d_suobi_data, o);
  3047. }
  3048. break;
  3049. case eDaoChaPosi::DCP_INVERT:
  3050. if (pn == ePowerName::PN_RETENTION)
  3051. {
  3052. //yyjson_mut_arr_add_val(f_baochi_data, o);
  3053. }
  3054. else
  3055. {
  3056. yyjson_mut_arr_add_val(f_suobi_data, o);
  3057. }
  3058. break;
  3059. case eDaoChaPosi::DCP_FIX2INVERT:
  3060. yyjson_mut_arr_add_val(d_convert_data, o);
  3061. break;
  3062. case eDaoChaPosi::DCP_INVERT2FIX:
  3063. yyjson_mut_arr_add_val(f_convert_data, o);
  3064. break;
  3065. default:
  3066. ASSERT(FALSE);
  3067. break;
  3068. }
  3069. } while (TRUE);
  3070. }
  3071. stmt.Close();
  3072. }
  3073. //line
  3074. {
  3075. //转换阻力报警线
  3076. CONVERT_RESIST_OVER_LIMIT* pInfo = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
  3077. if (pInfo && pInfo->enable)
  3078. {
  3079. if (pInfo->dw_warn_low_limit > INT_MIN)
  3080. {
  3081. auto obj = yyjson_mut_obj(doc);
  3082. yyjson_mut_arr_add_val(convert_line, obj);
  3083. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("预警线").c_str());
  3084. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->dw_warn_low_limit);
  3085. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  3086. }
  3087. if (pInfo->up_warn_high_limit < INT_MAX)
  3088. {
  3089. auto obj = yyjson_mut_obj(doc);
  3090. yyjson_mut_arr_add_val(convert_line, obj);
  3091. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("预警线").c_str());
  3092. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->up_warn_high_limit);
  3093. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  3094. }
  3095. if (pInfo->dw_alarm_low_limit > INT_MIN)
  3096. {
  3097. auto obj = yyjson_mut_obj(doc);
  3098. yyjson_mut_arr_add_val(convert_line, obj);
  3099. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("告警线").c_str());
  3100. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->dw_alarm_low_limit);
  3101. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  3102. }
  3103. if (pInfo->up_alarm_high_limit < INT_MAX)
  3104. {
  3105. auto obj = yyjson_mut_obj(doc);
  3106. yyjson_mut_arr_add_val(convert_line, obj);
  3107. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("告警线").c_str());
  3108. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->up_alarm_high_limit);
  3109. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  3110. }
  3111. }
  3112. }
  3113. {
  3114. //锁闭力报警线
  3115. SUOBI_OVER_LIMIT_INFO* pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, -1, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
  3116. if (pInfo && pInfo->enable)
  3117. {
  3118. if (pInfo->warn_low_limit > INT_MIN)
  3119. {
  3120. auto obj = yyjson_mut_obj(doc);
  3121. yyjson_mut_arr_add_val(suobi_line, obj);
  3122. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("预警线").c_str());
  3123. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->warn_low_limit);
  3124. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  3125. }
  3126. if (pInfo->warn_high_limit < INT_MAX)
  3127. {
  3128. auto obj = yyjson_mut_obj(doc);
  3129. yyjson_mut_arr_add_val(suobi_line, obj);
  3130. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("预警线").c_str());
  3131. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->warn_high_limit);
  3132. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  3133. }
  3134. if (pInfo->alarm_low_limit > INT_MIN)
  3135. {
  3136. auto obj = yyjson_mut_obj(doc);
  3137. yyjson_mut_arr_add_val(suobi_line, obj);
  3138. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("告警线").c_str());
  3139. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->alarm_low_limit);
  3140. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  3141. }
  3142. if (pInfo->alarm_high_limit < INT_MAX)
  3143. {
  3144. auto obj = yyjson_mut_obj(doc);
  3145. yyjson_mut_arr_add_val(suobi_line, obj);
  3146. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("告警线").c_str());
  3147. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->alarm_high_limit);
  3148. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  3149. }
  3150. }
  3151. }
  3152. {
  3153. //定位锁闭力报警线
  3154. SUOBI_OVER_LIMIT_INFO* pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_FIX, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
  3155. if (pInfo && pInfo->enable)
  3156. {
  3157. if (pInfo->warn_low_limit > INT_MIN)
  3158. {
  3159. auto obj = yyjson_mut_obj(doc);
  3160. yyjson_mut_arr_add_val(suobi_line, obj);
  3161. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("定位预警线").c_str());
  3162. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->warn_low_limit);
  3163. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  3164. }
  3165. if (pInfo->warn_high_limit < INT_MAX)
  3166. {
  3167. auto obj = yyjson_mut_obj(doc);
  3168. yyjson_mut_arr_add_val(suobi_line, obj);
  3169. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("定位预警线").c_str());
  3170. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->warn_high_limit);
  3171. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  3172. }
  3173. if (pInfo->alarm_low_limit > INT_MIN)
  3174. {
  3175. auto obj = yyjson_mut_obj(doc);
  3176. yyjson_mut_arr_add_val(suobi_line, obj);
  3177. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("定位告警线").c_str());
  3178. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->alarm_low_limit);
  3179. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  3180. }
  3181. if (pInfo->alarm_high_limit < INT_MAX)
  3182. {
  3183. auto obj = yyjson_mut_obj(doc);
  3184. yyjson_mut_arr_add_val(suobi_line, obj);
  3185. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("定位告警线").c_str());
  3186. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->alarm_high_limit);
  3187. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  3188. }
  3189. }
  3190. }
  3191. {
  3192. //反位锁闭力报警线
  3193. SUOBI_OVER_LIMIT_INFO* pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_INVERT, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
  3194. if (pInfo && pInfo->enable)
  3195. {
  3196. if (pInfo->warn_low_limit > INT_MIN)
  3197. {
  3198. auto obj = yyjson_mut_obj(doc);
  3199. yyjson_mut_arr_add_val(suobi_line, obj);
  3200. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("反位预警线").c_str());
  3201. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->warn_low_limit);
  3202. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  3203. }
  3204. if (pInfo->warn_high_limit < INT_MAX)
  3205. {
  3206. auto obj = yyjson_mut_obj(doc);
  3207. yyjson_mut_arr_add_val(suobi_line, obj);
  3208. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("反位预警线").c_str());
  3209. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->warn_high_limit);
  3210. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  3211. }
  3212. if (pInfo->alarm_low_limit > INT_MIN)
  3213. {
  3214. auto obj = yyjson_mut_obj(doc);
  3215. yyjson_mut_arr_add_val(suobi_line, obj);
  3216. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("反位告警线").c_str());
  3217. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->alarm_low_limit);
  3218. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  3219. }
  3220. if (pInfo->alarm_high_limit < INT_MAX)
  3221. {
  3222. auto obj = yyjson_mut_obj(doc);
  3223. yyjson_mut_arr_add_val(suobi_line, obj);
  3224. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("反位告警线").c_str());
  3225. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->alarm_high_limit);
  3226. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  3227. }
  3228. }
  3229. }
  3230. *json = yyjson_mut_write(doc, 0, json_len);
  3231. yyjson_mut_doc_free(doc);
  3232. return 200;
  3233. }
  3234. int DealGetRetentionCurve(const httplib::Request& req, const string token, char** json, size_t* json_len)
  3235. {
  3236. string mo = req.get_param_value("mo");
  3237. string mp = req.get_param_value("mp");
  3238. string time = req.get_param_value("time");
  3239. string name = req.get_param_value("name");
  3240. string end_time = req.get_param_value("end_time");
  3241. string type = req.get_param_value("type");
  3242. if (mo.length() == 0 || mp.length() == 0 || time.length() == 0 || name.length() == 0)
  3243. return 400;
  3244. if (type.compare("1") != 0)
  3245. return 501;//后台未实现
  3246. time_t uTime = atoll(time.c_str());
  3247. COleDateTime odt(uTime);
  3248. COleDateTime odtEnd(odt);
  3249. if (odt.GetStatus() == COleDateTime::invalid)
  3250. return 400;
  3251. if (end_time.empty() == false)
  3252. {
  3253. odtEnd = COleDateTime(atoll(end_time.c_str()));
  3254. if (odtEnd.GetStatus() == COleDateTime::invalid)
  3255. return 400;
  3256. }
  3257. auto doc = yyjson_mut_doc_new(nullptr);
  3258. auto root = yyjson_mut_obj(doc);
  3259. yyjson_mut_doc_set_root(doc, root);
  3260. auto data = yyjson_mut_obj(doc);
  3261. yyjson_mut_obj_add_val(doc, root, "data", data);//转换阻力
  3262. yyjson_mut_obj_add_str(doc, root, "name", name.c_str());
  3263. yyjson_mut_obj_add_str(doc, root, "unit", "N");
  3264. yyjson_mut_obj_add_uint(doc, root, "time", uTime);
  3265. //title
  3266. yyjson_mut_obj_add_strcpy(doc, data, "title", ANSItoUTF8("保持力趋势图").c_str());
  3267. //curve_data and line
  3268. auto baochi_curve_data = yyjson_mut_arr(doc);
  3269. yyjson_mut_obj_add_val(doc, data, "curve_data", baochi_curve_data);
  3270. auto baochi_line = yyjson_mut_arr(doc);
  3271. yyjson_mut_obj_add_val(doc, data, "line", baochi_line);
  3272. //curve_obj
  3273. auto d_baochi_obj = yyjson_mut_obj(doc);
  3274. yyjson_mut_obj_add_strcpy(doc, d_baochi_obj, "name", ANSItoUTF8("定位保持力").c_str());
  3275. yyjson_mut_obj_add_str(doc, d_baochi_obj, "color", "#a8ff78");// 苹果绿
  3276. yyjson_mut_arr_add_val(baochi_curve_data, d_baochi_obj);
  3277. auto f_baochi_obj = yyjson_mut_obj(doc);
  3278. yyjson_mut_obj_add_strcpy(doc, f_baochi_obj, "name", ANSItoUTF8("反位保持力").c_str());
  3279. yyjson_mut_obj_add_str(doc, f_baochi_obj, "color", "#FFE000");// 芒果黄
  3280. yyjson_mut_arr_add_val(baochi_curve_data, f_baochi_obj);
  3281. //curve_data
  3282. auto d_baochi_data = yyjson_mut_arr(doc);
  3283. yyjson_mut_obj_add_val(doc, d_baochi_obj, "data", d_baochi_data);
  3284. auto f_baochi_data = yyjson_mut_arr(doc);
  3285. yyjson_mut_obj_add_val(doc, f_baochi_obj, "data", f_baochi_data);
  3286. //query
  3287. //TODO 查询数据库 填充 d_convert_data f_convert_data d_baochi_data f_baochi_data
  3288. {
  3289. string table_name = fmt::format("rm_move_{:0>4}{:0>2}", odt.GetYear(), odt.GetMonth());
  3290. CString sql;
  3291. if (odt.GetMonth() == odtEnd.GetMonth())
  3292. {
  3293. sql = fmt::format("SELECT show_time,show_val,posi FROM {} WHERE [type] = 2 AND mo = '{}' AND mp = '{}' AND show_time >= '{}' AND show_time <= '{}'",
  3294. table_name, mo, mp, odt.Format("%Y-%m-%d 00:00:00"), odtEnd.Format("%Y-%m-%d 23:59:59.999")).c_str();
  3295. }
  3296. else
  3297. {
  3298. string table_name_next = fmt::format("rm_move_{:0>4}{:0>2}", odtEnd.GetYear(), odtEnd.GetMonth());
  3299. sql = fmt::format("SELECT show_time,show_val,posi FROM {0} WHERE [type] = 2 AND mo = '{1}' AND mp = '{2}' AND show_time >= '{3}' \
  3300. UNION SELECT show_time, show_val, posi FROM {4} WHERE [type] = 2 AND mo = '{1}' AND mp = '{2}' AND show_time <= '{5}'",
  3301. 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();
  3302. }
  3303. COdbcStatement stmt;
  3304. if (CDBConnectPool::Instance()->DBQuery(stmt, sql))
  3305. {
  3306. int nCol = 1;
  3307. TIMESTAMP_STRUCT ts;
  3308. int show_val;
  3309. eDaoChaPosi posi;
  3310. ePowerName pn;
  3311. stmt.BindTimeStampCol(nCol++, &ts);
  3312. stmt.BindIntCol(nCol++, &show_val);
  3313. stmt.BindTinyIntCol(nCol++, (BYTE*)&posi);
  3314. stmt.BindTinyIntCol(nCol++, (BYTE*)&pn);
  3315. do
  3316. {
  3317. if (stmt.FetchNext() != 0)
  3318. break;
  3319. CTime ctTime;
  3320. try
  3321. {
  3322. ctTime = CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
  3323. }
  3324. catch (...)
  3325. {
  3326. continue;
  3327. }
  3328. time_t tt = ctTime.GetTime() * 1000 + ts.fraction / 1000000;
  3329. auto o = yyjson_mut_arr(doc);
  3330. yyjson_mut_arr_add_int(doc, o, tt);
  3331. yyjson_mut_arr_add_int(doc, o, show_val);
  3332. switch (posi)
  3333. {
  3334. case eDaoChaPosi::DCP_FIX:
  3335. yyjson_mut_arr_add_val(d_baochi_data, o);
  3336. break;
  3337. case eDaoChaPosi::DCP_INVERT:
  3338. yyjson_mut_arr_add_val(f_baochi_data, o);
  3339. break;
  3340. default:
  3341. ASSERT(FALSE);
  3342. break;
  3343. }
  3344. } while (TRUE);
  3345. }
  3346. stmt.Close();
  3347. }
  3348. //line
  3349. {
  3350. //定位告警线
  3351. RETENSION_FORCE_DROP* pInfo = (RETENSION_FORCE_DROP*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_FIX, eZL_ALARMTYPE::RETENSION_FORCE);
  3352. if (pInfo && pInfo->enable)
  3353. {
  3354. if (pInfo->dw_alarm_low_drop > INT_MIN)
  3355. {
  3356. auto obj = yyjson_mut_obj(doc);
  3357. yyjson_mut_arr_add_val(baochi_line, obj);
  3358. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("定位告警线").c_str());
  3359. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->dw_alarm_low_drop);
  3360. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  3361. }
  3362. }
  3363. }
  3364. {
  3365. //反位告警线
  3366. RETENSION_FORCE_DROP* pInfo = (RETENSION_FORCE_DROP*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_INVERT, eZL_ALARMTYPE::RETENSION_FORCE);
  3367. if (pInfo && pInfo->enable)
  3368. {
  3369. if (pInfo->dw_alarm_low_drop > INT_MIN)
  3370. {
  3371. auto obj = yyjson_mut_obj(doc);
  3372. yyjson_mut_arr_add_val(baochi_line, obj);
  3373. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("反位告警线").c_str());
  3374. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->dw_alarm_low_drop);
  3375. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  3376. }
  3377. }
  3378. }
  3379. *json = yyjson_mut_write(doc, 0, json_len);
  3380. yyjson_mut_doc_free(doc);
  3381. return 200;
  3382. }
  3383. int DealGetRetentionReport(const httplib::Request& req, const string token, char** json, size_t* json_len)
  3384. {
  3385. string station = req.get_param_value("station");
  3386. string time = req.get_param_value("time");
  3387. if (time.length() == 0 || station.length() == 0)
  3388. return 400;
  3389. time_t uTime = atoll(time.c_str());
  3390. COleDateTime odt(uTime);
  3391. if (odt.GetStatus() == COleDateTime::invalid)
  3392. return 400;
  3393. auto doc = yyjson_mut_doc_new(nullptr);
  3394. auto root = yyjson_mut_arr(doc);
  3395. yyjson_mut_doc_set_root(doc, root);
  3396. {
  3397. string strStation = UTF8toANSI(station);
  3398. string table_name = fmt::format("rm_move_{:0>4}{:0>2}", odt.GetYear(), odt.GetMonth());
  3399. 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 \
  3400. LEFT JOIN rm_mo AS B ON A.mo = B.id",
  3401. table_name, strStation, odt.Format("%Y-%m-%d 00:00:00"), odt.Format("%Y-%m-%d 23:59:59.999")).c_str();
  3402. //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
  3403. COdbcStatement stmt;
  3404. struct tagData
  3405. {
  3406. string mo_name;
  3407. string mo;
  3408. string mp;
  3409. int d_baochi_lock = INT_MAX;
  3410. int d_baochi_lock_max = INT_MAX;
  3411. int d_baochi_lock_min = INT_MAX;
  3412. int d_baochi_lock_avg = INT_MAX;
  3413. int f_baochi_lock = INT_MAX;
  3414. int f_baochi_lock_max = INT_MAX;
  3415. int f_baochi_lock_min = INT_MAX;
  3416. int f_baochi_lock_avg = INT_MAX;
  3417. };
  3418. std::map<string, tagData> mapData;
  3419. if (CDBConnectPool::Instance()->DBQuery(stmt, sql))
  3420. {
  3421. int nCol = 1;
  3422. char mo[50], mp[50], mo_name[50];
  3423. int num;
  3424. int max;
  3425. int min;
  3426. int64_t sum;
  3427. eDaoChaPosi posi;
  3428. ePowerName pn;
  3429. stmt.BindCharCol(nCol++, mo, sizeof(mo));
  3430. stmt.BindCharCol(nCol++, mp, sizeof(mp));
  3431. stmt.BindTinyIntCol(nCol++, (BYTE*)&posi);
  3432. stmt.BindIntCol(nCol++, &num);
  3433. stmt.BindIntCol(nCol++, &max);
  3434. stmt.BindIntCol(nCol++, &min);
  3435. stmt.BindBigIntCol(nCol++, &sum);
  3436. stmt.BindTinyIntCol(nCol++, (BYTE*)&pn);
  3437. stmt.BindCharCol(nCol++, mo_name, sizeof(mo_name));
  3438. do
  3439. {
  3440. if (stmt.FetchNext() != 0)
  3441. break;
  3442. SUOBI_OVER_LIMIT_INFO* pInfo = nullptr;
  3443. CONVERT_RESIST_OVER_LIMIT* pInfo2 = nullptr;
  3444. auto& it = mapData[fmt::format("{}.{}", mo, mp)];
  3445. it.mo_name = mo_name;
  3446. it.mo = mo;
  3447. it.mp = mp;
  3448. eSuoBiPosi idx;
  3449. switch (posi)
  3450. {
  3451. case eDaoChaPosi::DCP_FIX:
  3452. it.d_baochi_lock = num;
  3453. it.d_baochi_lock_max = max;
  3454. it.d_baochi_lock_min = min;
  3455. if (num) it.d_baochi_lock_avg = sum / num;
  3456. break;
  3457. case eDaoChaPosi::DCP_INVERT:
  3458. it.f_baochi_lock = num;
  3459. it.f_baochi_lock_max = max;
  3460. it.f_baochi_lock_min = min;
  3461. if (num) it.f_baochi_lock_avg = sum / num;
  3462. break;
  3463. default:
  3464. ASSERT(FALSE);
  3465. break;
  3466. }
  3467. } while (TRUE);
  3468. }
  3469. stmt.Close();
  3470. for (auto& it : mapData)
  3471. {
  3472. auto obj = yyjson_mut_obj(doc);
  3473. yyjson_mut_arr_add_val(root, obj);
  3474. yyjson_mut_obj_add_strcpy(doc, obj, "mo_name", ANSItoUTF8(it.second.mo_name).c_str());
  3475. yyjson_mut_obj_add_strcpy(doc, obj, "mo", it.second.mo.c_str());
  3476. yyjson_mut_obj_add_strcpy(doc, obj, "mp", it.second.mp.c_str());
  3477. if (it.second.d_baochi_lock != INT_MAX)
  3478. yyjson_mut_obj_add_int(doc, obj, "d_retention_fore", it.second.d_baochi_lock);
  3479. else
  3480. yyjson_mut_obj_add_str(doc, obj, "d_retention_fore", "-");
  3481. if (it.second.d_baochi_lock_max != INT_MAX)
  3482. yyjson_mut_obj_add_int(doc, obj, "d_retention_fore_max", it.second.d_baochi_lock_max);
  3483. else
  3484. yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_max", "-");
  3485. if (it.second.d_baochi_lock_min != INT_MAX)
  3486. yyjson_mut_obj_add_int(doc, obj, "d_retention_fore_min", it.second.d_baochi_lock_min);
  3487. else
  3488. yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_min", "-");
  3489. if (it.second.d_baochi_lock_avg != INT_MAX)
  3490. yyjson_mut_obj_add_int(doc, obj, "d_retention_fore_avg", it.second.d_baochi_lock_avg);
  3491. else
  3492. yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_avg", "-");
  3493. if (it.second.f_baochi_lock != INT_MAX)
  3494. yyjson_mut_obj_add_int(doc, obj, "f_retention_fore", it.second.f_baochi_lock);
  3495. else
  3496. yyjson_mut_obj_add_str(doc, obj, "f_retention_fore", "-");
  3497. if (it.second.f_baochi_lock_max != INT_MAX)
  3498. yyjson_mut_obj_add_int(doc, obj, "f_retention_fore_max", it.second.f_baochi_lock_max);
  3499. else
  3500. yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_max", "-");
  3501. if (it.second.f_baochi_lock_min != INT_MAX)
  3502. yyjson_mut_obj_add_int(doc, obj, "f_retention_fore_min", it.second.f_baochi_lock_min);
  3503. else
  3504. yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_min", "-");
  3505. if (it.second.f_baochi_lock_avg != INT_MAX)
  3506. yyjson_mut_obj_add_int(doc, obj, "f_retention_fore_avg", it.second.f_baochi_lock_avg);
  3507. else
  3508. yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_avg", "-");
  3509. }
  3510. }
  3511. *json = yyjson_mut_write(doc, 0, json_len);
  3512. yyjson_mut_doc_free(doc);
  3513. return 200;
  3514. }
  3515. int DealGetResistReport(const httplib::Request& req, const string token, char** json, size_t* json_len)
  3516. {
  3517. string station = req.get_param_value("station");
  3518. string time = req.get_param_value("time");
  3519. if (time.length() == 0 || station.length() == 0)
  3520. return 400;
  3521. time_t uTime = atoll(time.c_str());
  3522. COleDateTime odt(uTime);
  3523. if (odt.GetStatus() == COleDateTime::invalid)
  3524. return 400;
  3525. auto doc = yyjson_mut_doc_new(nullptr);
  3526. auto root = yyjson_mut_arr(doc);
  3527. yyjson_mut_doc_set_root(doc, root);
  3528. {
  3529. string strStation = UTF8toANSI(station);
  3530. string table_name = fmt::format("rm_move_{:0>4}{:0>2}", odt.GetYear(), odt.GetMonth());
  3531. 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, \
  3532. CASE WHEN posi = 3 OR posi = 4 THEN 3 WHEN [type] = 0 THEN 1 ELSE [type] END ) AS A \
  3533. LEFT JOIN rm_mo AS B ON A.mo = B.id",
  3534. table_name, strStation, odt.Format("%Y-%m-%d 00:00:00"), odt.Format("%Y-%m-%d 23:59:59.999")).c_str();
  3535. //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
  3536. COdbcStatement stmt;
  3537. struct tagData
  3538. {
  3539. string mo_name;
  3540. string mo;
  3541. string mp;
  3542. int d_convert_resist = INT_MAX;
  3543. int d_convert_resist_max = INT_MAX;
  3544. int d_convert_resist_min = INT_MAX;
  3545. int d_convert_resist_avg = INT_MAX;
  3546. uint8_t d_convert_resist_max_color = 0; //0 为正常 1 为预警 2 为报警
  3547. uint8_t d_convert_resist_min_color = 0;
  3548. uint8_t d_convert_resist_avg_color = 0;
  3549. int f_convert_resist = INT_MAX;
  3550. int f_convert_resist_max = INT_MAX;
  3551. int f_convert_resist_min = INT_MAX;
  3552. int f_convert_resist_avg = INT_MAX;
  3553. uint8_t f_convert_resist_max_color = 0;
  3554. uint8_t f_convert_resist_min_color = 0;
  3555. uint8_t f_convert_resist_avg_color = 0;
  3556. int d_suobi_lock = INT_MAX;
  3557. int d_suobi_lock_max = INT_MAX;
  3558. int d_suobi_lock_min = INT_MAX;
  3559. int d_suobi_lock_avg = INT_MAX;
  3560. uint8_t d_suobi_lock_max_color = 0;
  3561. uint8_t d_suobi_lock_min_color = 0;
  3562. uint8_t d_suobi_lock_avg_color = 0;
  3563. int f_suobi_lock = INT_MAX;
  3564. int f_suobi_lock_max = INT_MAX;
  3565. int f_suobi_lock_min = INT_MAX;
  3566. int f_suobi_lock_avg = INT_MAX;
  3567. uint8_t f_suobi_lock_max_color = 0;
  3568. uint8_t f_suobi_lock_min_color = 0;
  3569. uint8_t f_suobi_lock_avg_color = 0;
  3570. int d_baochi_lock = INT_MAX;
  3571. int d_baochi_lock_max = INT_MAX;
  3572. int d_baochi_lock_min = INT_MAX;
  3573. int d_baochi_lock_avg = INT_MAX;
  3574. uint8_t d_baochi_lock_max_color = 0;
  3575. uint8_t d_baochi_lock_min_color = 0;
  3576. uint8_t d_baochi_lock_avg_color = 0;
  3577. int f_baochi_lock = INT_MAX;
  3578. int f_baochi_lock_max = INT_MAX;
  3579. int f_baochi_lock_min = INT_MAX;
  3580. int f_baochi_lock_avg = INT_MAX;
  3581. uint8_t f_baochi_lock_max_color = 0;
  3582. uint8_t f_baochi_lock_min_color = 0;
  3583. uint8_t f_baochi_lock_avg_color = 0;
  3584. };
  3585. std::map<string, tagData> mapData;
  3586. if (CDBConnectPool::Instance()->DBQuery(stmt, sql))
  3587. {
  3588. int nCol = 1;
  3589. char mo[50], mp[50], mo_name[50];
  3590. int num;
  3591. int max;
  3592. int min;
  3593. int64_t sum;
  3594. eDaoChaPosi posi;
  3595. ePowerName pn;
  3596. stmt.BindCharCol(nCol++, mo, sizeof(mo));
  3597. stmt.BindCharCol(nCol++, mp, sizeof(mp));
  3598. stmt.BindTinyIntCol(nCol++, (BYTE*)&posi);
  3599. stmt.BindIntCol(nCol++, &num);
  3600. stmt.BindIntCol(nCol++, &max);
  3601. stmt.BindIntCol(nCol++, &min);
  3602. stmt.BindBigIntCol(nCol++, &sum);
  3603. stmt.BindTinyIntCol(nCol++, (BYTE*)&pn);
  3604. stmt.BindCharCol(nCol++, mo_name, sizeof(mo_name));
  3605. do
  3606. {
  3607. if (stmt.FetchNext() != 0)
  3608. break;
  3609. SUOBI_OVER_LIMIT_INFO* pInfo = nullptr;
  3610. CONVERT_RESIST_OVER_LIMIT* pInfo2 = nullptr;
  3611. auto& it = mapData[fmt::format("{}.{}", mo, mp)];
  3612. it.mo_name = mo_name;
  3613. it.mo = mo;
  3614. it.mp = mp;
  3615. eSuoBiPosi idx;
  3616. switch (posi)
  3617. {
  3618. case eDaoChaPosi::DCP_FIX:
  3619. if (pn == ePowerName::PN_RETENTION)
  3620. {
  3621. it.d_baochi_lock = num;
  3622. it.d_baochi_lock_max = max;
  3623. it.d_baochi_lock_min = min;
  3624. if (num) it.d_baochi_lock_avg = sum / num;
  3625. }
  3626. else
  3627. {
  3628. it.d_suobi_lock = num;
  3629. it.d_suobi_lock_max = max;
  3630. it.d_suobi_lock_min = min;
  3631. if (num) it.d_suobi_lock_avg = sum / num;
  3632. idx = eSuoBiPosi::SB_FIX;
  3633. pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)idx, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
  3634. if (pInfo && pInfo->enable)
  3635. {
  3636. if (max > pInfo->alarm_high_limit)
  3637. it.d_suobi_lock_max_color = UINT8_ALARM;
  3638. else if (max > pInfo->warn_high_limit)
  3639. it.d_suobi_lock_max_color = UINT8_WARN;
  3640. if (min < pInfo->alarm_low_limit)
  3641. it.d_suobi_lock_min_color = UINT8_ALARM;
  3642. else if (min < pInfo->warn_low_limit)
  3643. it.d_suobi_lock_min_color = UINT8_WARN;
  3644. if (num && (it.d_suobi_lock_avg > pInfo->alarm_high_limit || it.d_suobi_lock_avg < pInfo->alarm_low_limit))
  3645. it.d_suobi_lock_avg_color = UINT8_ALARM;
  3646. else if (num && (it.d_suobi_lock_avg > pInfo->warn_high_limit || it.d_suobi_lock_avg < pInfo->warn_low_limit))
  3647. it.d_suobi_lock_avg_color = UINT8_WARN;
  3648. }
  3649. }
  3650. break;
  3651. case eDaoChaPosi::DCP_INVERT:
  3652. if (pn == ePowerName::PN_RETENTION)
  3653. {
  3654. it.f_baochi_lock = num;
  3655. it.f_baochi_lock_max = max;
  3656. it.f_baochi_lock_min = min;
  3657. if (num) it.f_baochi_lock_avg = sum / num;
  3658. }
  3659. else
  3660. {
  3661. it.f_suobi_lock = num;
  3662. it.f_suobi_lock_max = max;
  3663. it.f_suobi_lock_min = min;
  3664. if (num) it.f_suobi_lock_avg = sum / num;
  3665. idx = eSuoBiPosi::SB_INVERT;
  3666. pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)idx, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
  3667. if (pInfo && pInfo->enable)
  3668. {
  3669. if (max > pInfo->alarm_high_limit)
  3670. it.f_suobi_lock_max_color = UINT8_ALARM;
  3671. else if (max > pInfo->warn_high_limit)
  3672. it.f_suobi_lock_max_color = UINT8_WARN;
  3673. if (min < pInfo->alarm_low_limit)
  3674. it.f_suobi_lock_min_color = UINT8_ALARM;
  3675. else if (min < pInfo->warn_low_limit)
  3676. it.f_suobi_lock_min_color = UINT8_WARN;
  3677. if (num && (it.f_suobi_lock_avg > pInfo->alarm_high_limit || it.f_suobi_lock_avg < pInfo->alarm_low_limit))
  3678. it.f_suobi_lock_avg_color = UINT8_ALARM;
  3679. else if (num && (it.f_suobi_lock_avg > pInfo->warn_high_limit || it.f_suobi_lock_avg < pInfo->warn_low_limit))
  3680. it.f_suobi_lock_avg_color = UINT8_WARN;
  3681. }
  3682. }
  3683. break;
  3684. case eDaoChaPosi::DCP_FIX2INVERT:
  3685. it.d_convert_resist = num;
  3686. it.d_convert_resist_max = max;
  3687. it.d_convert_resist_min = min;
  3688. if (num) it.d_convert_resist_avg = sum / num;
  3689. pInfo2 = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
  3690. if (pInfo2 && pInfo2->enable)
  3691. {
  3692. string name1, name2, name3, out_name, in_name;
  3693. CMonitorObjectMng::Instance()->GetNameByMoMp(fmt::format("{}.{}", mo, mp), name1, name2, name3, out_name, in_name);
  3694. if (in_name.find("定扳反") == -1) //如果缩进不是定扳反, 那就是伸出
  3695. {
  3696. if (max > pInfo2->dw_alarm_low_limit)
  3697. it.d_convert_resist_max_color = UINT8_ALARM;
  3698. else if (max > pInfo2->dw_warn_low_limit)
  3699. it.d_convert_resist_max_color = UINT8_WARN;
  3700. if (num && it.d_convert_resist_avg > pInfo2->dw_alarm_low_limit)
  3701. it.d_convert_resist_avg_color = UINT8_ALARM;
  3702. else if (num && it.d_convert_resist_avg > pInfo2->dw_warn_low_limit)
  3703. it.d_convert_resist_avg_color = UINT8_WARN;
  3704. }
  3705. else
  3706. {
  3707. if (max > pInfo2->up_alarm_high_limit)
  3708. it.d_convert_resist_max_color = UINT8_ALARM;
  3709. else if (max > pInfo2->up_warn_high_limit)
  3710. it.d_convert_resist_max_color = UINT8_WARN;
  3711. if (num && it.d_convert_resist_avg > pInfo2->up_alarm_high_limit)
  3712. it.d_convert_resist_avg_color = UINT8_ALARM;
  3713. else if (num && it.d_convert_resist_avg > pInfo2->up_warn_high_limit)
  3714. it.d_convert_resist_avg_color = UINT8_WARN;
  3715. }
  3716. }
  3717. break;
  3718. case eDaoChaPosi::DCP_INVERT2FIX:
  3719. it.f_convert_resist = num;
  3720. it.f_convert_resist_max = max;
  3721. it.f_convert_resist_min = min;
  3722. if (num) it.f_convert_resist_avg = sum / num;
  3723. pInfo2 = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
  3724. if (pInfo2 && pInfo2->enable)
  3725. {
  3726. string name1, name2, name3, out_name, in_name;
  3727. CMonitorObjectMng::Instance()->GetNameByMoMp(fmt::format("{}.{}", mo, mp), name1, name2, name3, out_name, in_name);
  3728. if (in_name.find("反扳定") != -1) //如果反扳定是缩进
  3729. {
  3730. if (max > pInfo2->up_alarm_high_limit)
  3731. it.f_convert_resist_max_color = UINT8_ALARM;
  3732. else if (max > pInfo2->up_warn_high_limit)
  3733. it.f_convert_resist_max_color = UINT8_WARN;
  3734. if (num && it.f_convert_resist_avg > pInfo2->up_alarm_high_limit)
  3735. it.f_convert_resist_avg_color = UINT8_ALARM;
  3736. else if (num && it.f_convert_resist_avg > pInfo2->up_warn_high_limit)
  3737. it.f_convert_resist_avg_color = UINT8_WARN;
  3738. }
  3739. else
  3740. {
  3741. if (max > pInfo2->dw_alarm_low_limit)
  3742. it.f_convert_resist_max_color = UINT8_ALARM;
  3743. else if (max > pInfo2->dw_warn_low_limit)
  3744. it.f_convert_resist_max_color = UINT8_WARN;
  3745. if (num && it.f_convert_resist_avg > pInfo2->dw_alarm_low_limit)
  3746. it.f_convert_resist_avg_color = UINT8_ALARM;
  3747. else if (num && it.f_convert_resist_avg > pInfo2->dw_warn_low_limit)
  3748. it.f_convert_resist_avg_color = UINT8_WARN;
  3749. }
  3750. }
  3751. break;
  3752. default:
  3753. ASSERT(FALSE);
  3754. break;
  3755. }
  3756. } while (TRUE);
  3757. }
  3758. stmt.Close();
  3759. for (auto& it : mapData)
  3760. {
  3761. auto obj = yyjson_mut_obj(doc);
  3762. yyjson_mut_arr_add_val(root, obj);
  3763. yyjson_mut_obj_add_strcpy(doc, obj, "mo_name", ANSItoUTF8(it.second.mo_name).c_str());
  3764. yyjson_mut_obj_add_strcpy(doc, obj, "mo", it.second.mo.c_str());
  3765. yyjson_mut_obj_add_strcpy(doc, obj, "mp", it.second.mp.c_str());
  3766. if (it.second.d_convert_resist != INT_MAX)
  3767. yyjson_mut_obj_add_int(doc, obj, "d_convert_resist", it.second.d_convert_resist);
  3768. else
  3769. yyjson_mut_obj_add_str(doc, obj, "d_convert_resist", "-");
  3770. if (it.second.d_convert_resist_max != INT_MAX)
  3771. yyjson_mut_obj_add_int(doc, obj, "d_convert_resist_max", it.second.d_convert_resist_max);
  3772. else
  3773. yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_max", "-");
  3774. if (it.second.d_convert_resist_min != INT_MAX)
  3775. yyjson_mut_obj_add_int(doc, obj, "d_convert_resist_min", it.second.d_convert_resist_min);
  3776. else
  3777. yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_min", "-");
  3778. if (it.second.d_convert_resist_avg != INT_MAX)
  3779. yyjson_mut_obj_add_int(doc, obj, "d_convert_resist_avg", it.second.d_convert_resist_avg);
  3780. else
  3781. yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_avg", "-");
  3782. //颜色
  3783. if (it.second.d_convert_resist_max_color == UINT8_ALARM)
  3784. yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_max_color", "red");
  3785. else if (it.second.d_convert_resist_max_color == UINT8_WARN)
  3786. yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_max_color", "orange");
  3787. if (it.second.d_convert_resist_min_color == UINT8_ALARM)
  3788. yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_min_color", "red");
  3789. else if (it.second.d_convert_resist_min_color == UINT8_WARN)
  3790. yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_min_color", "orange");
  3791. if (it.second.d_convert_resist_avg_color == UINT8_ALARM)
  3792. yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_avg_color", "red");
  3793. else if (it.second.d_convert_resist_avg_color == UINT8_WARN)
  3794. yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_avg_color", "orange");
  3795. if (it.second.f_convert_resist != INT_MAX)
  3796. yyjson_mut_obj_add_int(doc, obj, "f_convert_resist", it.second.f_convert_resist);
  3797. else
  3798. yyjson_mut_obj_add_str(doc, obj, "f_convert_resist", "-");
  3799. if (it.second.f_convert_resist_max != INT_MAX)
  3800. yyjson_mut_obj_add_int(doc, obj, "f_convert_resist_max", it.second.f_convert_resist_max);
  3801. else
  3802. yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_max", "-");
  3803. if (it.second.f_convert_resist_min != INT_MAX)
  3804. yyjson_mut_obj_add_int(doc, obj, "f_convert_resist_min", it.second.f_convert_resist_min);
  3805. else
  3806. yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_min", "-");
  3807. if (it.second.f_convert_resist_avg != INT_MAX)
  3808. yyjson_mut_obj_add_int(doc, obj, "f_convert_resist_avg", it.second.f_convert_resist_avg);
  3809. else
  3810. yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_avg", "-");
  3811. //颜色
  3812. if (it.second.f_convert_resist_max_color == UINT8_ALARM)
  3813. yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_max_color", "red");
  3814. else if (it.second.f_convert_resist_max_color == UINT8_WARN)
  3815. yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_max_color", "orange");
  3816. if (it.second.f_convert_resist_min_color == UINT8_ALARM)
  3817. yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_min_color", "red");
  3818. else if (it.second.f_convert_resist_min_color == UINT8_WARN)
  3819. yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_min_color", "orange");
  3820. if (it.second.f_convert_resist_avg_color == UINT8_ALARM)
  3821. yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_avg_color", "red");
  3822. else if (it.second.f_convert_resist_avg_color == UINT8_WARN)
  3823. yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_avg_color", "orange");
  3824. if (it.second.d_suobi_lock != INT_MAX)
  3825. yyjson_mut_obj_add_int(doc, obj, "d_suobi_lock", it.second.d_suobi_lock);
  3826. else
  3827. yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock", "-");
  3828. if (it.second.d_suobi_lock_max != INT_MAX)
  3829. yyjson_mut_obj_add_int(doc, obj, "d_suobi_lock_max", it.second.d_suobi_lock_max);
  3830. else
  3831. yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_max", "-");
  3832. if (it.second.d_suobi_lock_min != INT_MAX)
  3833. yyjson_mut_obj_add_int(doc, obj, "d_suobi_lock_min", it.second.d_suobi_lock_min);
  3834. else
  3835. yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_min", "-");
  3836. if (it.second.d_suobi_lock_avg != INT_MAX)
  3837. yyjson_mut_obj_add_int(doc, obj, "d_suobi_lock_avg", it.second.d_suobi_lock_avg);
  3838. else
  3839. yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_avg", "-");
  3840. //颜色
  3841. if (it.second.d_suobi_lock_max_color == UINT8_ALARM)
  3842. yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_max_color", "red");
  3843. else if (it.second.d_suobi_lock_max_color == UINT8_WARN)
  3844. yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_max_color", "orange");
  3845. if (it.second.d_suobi_lock_min_color == UINT8_ALARM)
  3846. yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_min_color", "red");
  3847. else if (it.second.d_suobi_lock_min_color == UINT8_WARN)
  3848. yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_min_color", "orange");
  3849. if (it.second.d_suobi_lock_avg_color == UINT8_ALARM)
  3850. yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_avg_color", "red");
  3851. else if (it.second.d_suobi_lock_avg_color == UINT8_WARN)
  3852. yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_avg_color", "orange");
  3853. if (it.second.f_suobi_lock != INT_MAX)
  3854. yyjson_mut_obj_add_int(doc, obj, "f_suobi_lock", it.second.f_suobi_lock);
  3855. else
  3856. yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock", "-");
  3857. if (it.second.f_suobi_lock_max != INT_MAX)
  3858. yyjson_mut_obj_add_int(doc, obj, "f_suobi_lock_max", it.second.f_suobi_lock_max);
  3859. else
  3860. yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_max", "-");
  3861. if (it.second.f_suobi_lock_min!= INT_MAX)
  3862. yyjson_mut_obj_add_int(doc, obj, "f_suobi_lock_min", it.second.f_suobi_lock_min);
  3863. else
  3864. yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_min", "-");
  3865. if (it.second.f_suobi_lock_avg != INT_MAX)
  3866. yyjson_mut_obj_add_int(doc, obj, "f_suobi_lock_avg", it.second.f_suobi_lock_avg);
  3867. else
  3868. yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_avg", "-");
  3869. //颜色
  3870. if (it.second.f_suobi_lock_max_color == UINT8_ALARM)
  3871. yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_max_color", "red");
  3872. else if (it.second.f_suobi_lock_max_color == UINT8_WARN)
  3873. yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_max_color", "orange");
  3874. if (it.second.f_suobi_lock_min_color == UINT8_ALARM)
  3875. yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_min_color", "red");
  3876. else if (it.second.f_suobi_lock_min_color == UINT8_WARN)
  3877. yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_min_color", "orange");
  3878. if (it.second.f_suobi_lock_avg_color == UINT8_ALARM)
  3879. yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_avg_color", "red");
  3880. else if (it.second.f_suobi_lock_avg_color == UINT8_WARN)
  3881. yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_avg_color", "orange");
  3882. if (it.second.d_baochi_lock != INT_MAX)
  3883. yyjson_mut_obj_add_int(doc, obj, "d_retention_fore", it.second.d_baochi_lock);
  3884. else
  3885. yyjson_mut_obj_add_str(doc, obj, "d_retention_fore", "-");
  3886. if (it.second.d_baochi_lock_max != INT_MAX)
  3887. yyjson_mut_obj_add_int(doc, obj, "d_retention_fore_max", it.second.d_baochi_lock_max);
  3888. else
  3889. yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_max", "-");
  3890. if (it.second.d_baochi_lock_min != INT_MAX)
  3891. yyjson_mut_obj_add_int(doc, obj, "d_retention_fore_min", it.second.d_baochi_lock_min);
  3892. else
  3893. yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_min", "-");
  3894. if (it.second.d_baochi_lock_avg != INT_MAX)
  3895. yyjson_mut_obj_add_int(doc, obj, "d_retention_fore_avg", it.second.d_baochi_lock_avg);
  3896. else
  3897. yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_avg", "-");
  3898. //颜色
  3899. if (it.second.d_baochi_lock_max_color == UINT8_ALARM)
  3900. yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_max_color", "red");
  3901. else if (it.second.d_baochi_lock_max_color == UINT8_WARN)
  3902. yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_max_color", "orange");
  3903. if (it.second.d_baochi_lock_min_color == UINT8_ALARM)
  3904. yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_min_color", "red");
  3905. else if (it.second.d_baochi_lock_min_color == UINT8_WARN)
  3906. yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_min_color", "orange");
  3907. if (it.second.d_baochi_lock_avg_color == UINT8_ALARM)
  3908. yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_avg_color", "red");
  3909. else if (it.second.d_baochi_lock_avg_color == UINT8_WARN)
  3910. yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_avg_color", "orange");
  3911. if (it.second.f_baochi_lock != INT_MAX)
  3912. yyjson_mut_obj_add_int(doc, obj, "f_retention_fore", it.second.f_baochi_lock);
  3913. else
  3914. yyjson_mut_obj_add_str(doc, obj, "f_retention_fore", "-");
  3915. if (it.second.f_baochi_lock_max != INT_MAX)
  3916. yyjson_mut_obj_add_int(doc, obj, "f_retention_fore_max", it.second.f_baochi_lock_max);
  3917. else
  3918. yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_max", "-");
  3919. if (it.second.f_baochi_lock_min != INT_MAX)
  3920. yyjson_mut_obj_add_int(doc, obj, "f_retention_fore_min", it.second.f_baochi_lock_min);
  3921. else
  3922. yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_min", "-");
  3923. if (it.second.f_baochi_lock_avg != INT_MAX)
  3924. yyjson_mut_obj_add_int(doc, obj, "f_retention_fore_avg", it.second.f_baochi_lock_avg);
  3925. else
  3926. yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_avg", "-");
  3927. //颜色
  3928. if (it.second.f_baochi_lock_max_color == UINT8_ALARM)
  3929. yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_max_color", "red");
  3930. else if (it.second.f_baochi_lock_max_color == UINT8_WARN)
  3931. yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_max_color", "orange");
  3932. if (it.second.f_baochi_lock_min_color == UINT8_ALARM)
  3933. yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_min_color", "red");
  3934. else if (it.second.f_baochi_lock_min_color == UINT8_WARN)
  3935. yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_min_color", "orange");
  3936. if (it.second.f_baochi_lock_avg_color == UINT8_ALARM)
  3937. yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_avg_color", "red");
  3938. else if (it.second.f_baochi_lock_avg_color == UINT8_WARN)
  3939. yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_avg_color", "orange");
  3940. }
  3941. }
  3942. *json = yyjson_mut_write(doc, 0, json_len);
  3943. yyjson_mut_doc_free(doc);
  3944. return 200;
  3945. }
  3946. int DealGetMoveInfo(const httplib::Request& req, const string token, char** json, size_t* json_len)
  3947. {
  3948. string mo = req.get_param_value("mo");
  3949. string mp = req.get_param_value("mp");
  3950. string start_time = req.get_param_value("start_time");
  3951. string end_time = req.get_param_value("end_time");
  3952. if (mo.length() == 0 || mp.length() == 0 || start_time.length() == 0 || end_time.length() == 0)
  3953. return 400;
  3954. auto doc = yyjson_mut_doc_new(nullptr);
  3955. auto root = yyjson_mut_obj(doc);
  3956. yyjson_mut_doc_set_root(doc, root);
  3957. auto data = yyjson_mut_arr(doc);
  3958. yyjson_mut_obj_add_val(doc, root, "data", data);
  3959. COleDateTime odtStart, odtEnd;
  3960. do {
  3961. auto ret_time = odtEnd.ParseDateTime(end_time.c_str());
  3962. if (ret_time == FALSE)
  3963. break;
  3964. ret_time = odtStart.ParseDateTime(start_time.c_str());
  3965. if (ret_time == FALSE)
  3966. break;
  3967. if (odtEnd <= odtStart)
  3968. break;
  3969. auto fix_object = yyjson_mut_obj(doc);
  3970. yyjson_mut_arr_add_val(data, fix_object);
  3971. auto invert_object = yyjson_mut_obj(doc);
  3972. yyjson_mut_arr_add_val(data, invert_object);
  3973. auto convert_object = yyjson_mut_obj(doc);
  3974. yyjson_mut_arr_add_val(data, convert_object);
  3975. static string fix_name = ANSItoUTF8("定位测力曲线");
  3976. yyjson_mut_obj_add_str(doc, fix_object, "name", fix_name.c_str());
  3977. static string invert_name = ANSItoUTF8("反位测力曲线");
  3978. yyjson_mut_obj_add_str(doc, invert_object, "name", invert_name.c_str());
  3979. static string convert_name = ANSItoUTF8("转换阻力曲线");
  3980. yyjson_mut_obj_add_str(doc, convert_object, "name", convert_name.c_str());
  3981. static string lock_low = ANSItoUTF8("锁闭力过低");
  3982. auto fix_points = yyjson_mut_arr(doc);
  3983. yyjson_mut_obj_add_val(doc, fix_object, "mark_points", fix_points);
  3984. auto invert_points = yyjson_mut_arr(doc);
  3985. yyjson_mut_obj_add_val(doc, invert_object, "mark_points", invert_points);
  3986. auto convert_points = yyjson_mut_arr(doc);
  3987. yyjson_mut_obj_add_val(doc, convert_object, "mark_points", convert_points);
  3988. auto pConvertLimit = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
  3989. auto pFixSuobi = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_FIX, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
  3990. auto pInvertSuobi = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_INVERT, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
  3991. string out_name, in_name;
  3992. CMonitorObjectMng::Instance()->GetDirectByMoMp(mo + "." + mp, out_name, in_name);
  3993. //string name1, name2, name3, out_name, in_name;
  3994. //CMonitorObjectMng::Instance()->GetNameByMoMp(mo + "." + mp, name1, name2, name3, out_name, in_name);
  3995. string table_name = fmt::format("rm_move_{:0>4}{:0>2}", odtStart.GetYear(), odtStart.GetMonth());
  3996. CString sql = fmt::format("SELECT show_time, curr_val, show_val, posi, mark FROM {} \
  3997. WHERE mo = '{}' AND mp = '{}' AND show_time >= '{}' AND show_time <= '{}' AND [type] <> 2 order by posi, show_time",
  3998. table_name, mo, mp, start_time, end_time).c_str();
  3999. COdbcStatement stmt;
  4000. if (CDBConnectPool::Instance()->DBQuery(stmt, sql))
  4001. {
  4002. TIMESTAMP_STRUCT ts;
  4003. int curr_val;
  4004. int show_val;
  4005. eDaoChaPosi posi;
  4006. char mark[200];
  4007. int nCol = 1;
  4008. stmt.BindTimeStampCol(nCol++, &ts);
  4009. stmt.BindIntCol(nCol++, &curr_val);
  4010. stmt.BindIntCol(nCol++, &show_val);
  4011. stmt.BindTinyIntCol(nCol++, (BYTE*)&posi);
  4012. stmt.BindCharCol(nCol++, mark, sizeof(mark));
  4013. do
  4014. {
  4015. if (stmt.FetchNext() != 0)
  4016. break;
  4017. auto obj = yyjson_mut_obj(doc);
  4018. switch (posi)
  4019. {
  4020. case eDaoChaPosi::DCP_FIX:
  4021. {
  4022. yyjson_mut_arr_add_val(fix_points, obj);
  4023. auto coord = yyjson_mut_arr(doc);
  4024. yyjson_mut_obj_add_val(doc, obj, "coord", coord);
  4025. 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);
  4026. yyjson_mut_arr_add_int(doc, coord, curr_val);
  4027. yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
  4028. ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
  4029. yyjson_mut_obj_add_int(doc, obj, "val", show_val);
  4030. if (pFixSuobi && pFixSuobi->enable)
  4031. {
  4032. if (pFixSuobi->alarm_low_limit > show_val)
  4033. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  4034. else if (pFixSuobi->alarm_high_limit < show_val)
  4035. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  4036. else if (pFixSuobi->warn_high_limit < show_val)
  4037. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  4038. else if (pFixSuobi->warn_low_limit > show_val)
  4039. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  4040. }
  4041. yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str());
  4042. //if (show_val < 500)//TODO
  4043. //{
  4044. // yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  4045. // yyjson_mut_obj_add_str(doc, obj, "label", lock_low.c_str());
  4046. //}
  4047. //else
  4048. //{
  4049. // yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str());
  4050. //}
  4051. }
  4052. break;
  4053. case eDaoChaPosi::DCP_INVERT:
  4054. {
  4055. yyjson_mut_arr_add_val(invert_points, obj);
  4056. auto coord = yyjson_mut_arr(doc);
  4057. yyjson_mut_obj_add_val(doc, obj, "coord", coord);
  4058. 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);
  4059. yyjson_mut_arr_add_int(doc, coord, curr_val);
  4060. yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
  4061. ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
  4062. yyjson_mut_obj_add_int(doc, obj, "val", show_val);
  4063. if (pInvertSuobi && pInvertSuobi->enable)
  4064. {
  4065. if (pInvertSuobi->alarm_low_limit > show_val)
  4066. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  4067. else if (pInvertSuobi->alarm_high_limit < show_val)
  4068. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  4069. else if (pInvertSuobi->warn_high_limit < show_val)
  4070. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  4071. else if (pInvertSuobi->warn_low_limit > show_val)
  4072. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  4073. }
  4074. yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str());
  4075. //if (show_val < 500)//TODO
  4076. //{
  4077. // yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  4078. // yyjson_mut_obj_add_str(doc, obj, "label", lock_low.c_str());
  4079. //}
  4080. //else
  4081. //{
  4082. // yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str());
  4083. //}
  4084. }
  4085. break;
  4086. case eDaoChaPosi::DCP_FIX2INVERT:
  4087. {
  4088. yyjson_mut_arr_add_val(convert_points, obj);
  4089. auto coord = yyjson_mut_arr(doc);
  4090. yyjson_mut_obj_add_val(doc, obj, "coord", coord);
  4091. 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);
  4092. yyjson_mut_arr_add_int(doc, coord, curr_val);
  4093. yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
  4094. ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
  4095. yyjson_mut_obj_add_int(doc, obj, "val", show_val);
  4096. if (pConvertLimit && pConvertLimit->enable)
  4097. {
  4098. if (out_name.find("定扳反") != -1)
  4099. {
  4100. if (pConvertLimit->dw_alarm_low_limit > show_val)
  4101. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  4102. else if (pConvertLimit->dw_warn_low_limit > show_val)
  4103. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  4104. }
  4105. else
  4106. {
  4107. if (pConvertLimit->up_alarm_high_limit < show_val)
  4108. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  4109. else if (pConvertLimit->up_warn_high_limit < show_val)
  4110. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  4111. }
  4112. }
  4113. if (curr_val < 0)
  4114. yyjson_mut_obj_add_str(doc, obj, "position", "bottom");
  4115. yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("定扳反:{}", show_val)).c_str());
  4116. }
  4117. break;
  4118. case eDaoChaPosi::DCP_INVERT2FIX:
  4119. {
  4120. yyjson_mut_arr_add_val(convert_points, obj);
  4121. auto coord = yyjson_mut_arr(doc);
  4122. yyjson_mut_obj_add_val(doc, obj, "coord", coord);
  4123. 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);
  4124. yyjson_mut_arr_add_int(doc, coord, curr_val);
  4125. yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
  4126. ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
  4127. yyjson_mut_obj_add_int(doc, obj, "val", show_val);
  4128. if (pConvertLimit && pConvertLimit->enable)
  4129. {
  4130. if (out_name.find("反扳定") != -1)
  4131. {
  4132. if (pConvertLimit->dw_alarm_low_limit > show_val)
  4133. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  4134. else if (pConvertLimit->dw_warn_low_limit > show_val)
  4135. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  4136. }
  4137. else
  4138. {
  4139. if (pConvertLimit->up_alarm_high_limit < show_val)
  4140. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  4141. else if (pConvertLimit->up_warn_high_limit < show_val)
  4142. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  4143. }
  4144. }
  4145. if (curr_val < 0)
  4146. yyjson_mut_obj_add_str(doc, obj, "position", "bottom");
  4147. yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("反扳定:{}", show_val)).c_str());
  4148. }
  4149. break;
  4150. default:
  4151. ASSERT(FALSE);
  4152. break;
  4153. }
  4154. } while (TRUE);
  4155. }
  4156. stmt.Close();
  4157. }while (false);
  4158. *json = yyjson_mut_write(doc, 0, json_len);
  4159. yyjson_mut_doc_free(doc);
  4160. return 200;
  4161. }
  4162. #include "MGWSServer.h"
  4163. int DealResistMove(const httplib::Request& req, const string token, char** json, size_t* json_len)
  4164. {
  4165. string mo = req.get_param_value("mo");
  4166. string mp = req.get_param_value("mp");
  4167. string starttime = req.get_param_value("starttime");
  4168. string endtime = req.get_param_value("endtime");
  4169. if (mo.length() == 0 || mp.length() == 0 || starttime.length() == 0 || endtime.length() == 0)
  4170. return 400;
  4171. auto doc = yyjson_mut_doc_new(nullptr);
  4172. auto root = yyjson_mut_obj(doc);
  4173. yyjson_mut_doc_set_root(doc, root);
  4174. auto data = yyjson_mut_arr(doc);
  4175. yyjson_mut_obj_add_val(doc, root, "data", data);
  4176. COleDateTime odtStart, odtEnd;
  4177. int code = 400;
  4178. do {
  4179. auto ret_time = odtEnd.ParseDateTime(endtime.c_str());
  4180. if (ret_time == FALSE)
  4181. break;
  4182. ret_time = odtStart.ParseDateTime(starttime.c_str());
  4183. if (ret_time == FALSE)
  4184. break;
  4185. if (odtEnd <= odtStart)
  4186. break;
  4187. string momp = mo + "." + mp;
  4188. auto pInfo = CMonitorObjectMng::Instance()->GetMoMpInfo(momp);
  4189. if (pInfo == nullptr)
  4190. {
  4191. code = 404;
  4192. break;
  4193. }
  4194. char tablename[50] = { 0 };
  4195. auto dtStartDate = COleDateTime(odtStart.GetYear(), odtStart.GetMonth(), odtStart.GetDay(), 0, 0, 0);
  4196. auto strStartDate = dtStartDate.Format("%Y-%m-%d %H:%M:%S");
  4197. auto strEndDate = odtEnd.Format("%Y-%m-%d %H:%M:%S");;
  4198. CString sql;
  4199. {
  4200. int num = 0;
  4201. for (auto it = dtStartDate; it < odtEnd;)
  4202. {
  4203. sprintf_s(tablename, 50, "rm_resistance_%04d%02d%02d", it.GetYear(), it.GetMonth(), it.GetDay());
  4204. if (num == 0)
  4205. {
  4206. sql.Format("SELECT [acquisitiontime],[data0],[data1],[data2] "\
  4207. "FROM %s WHERE IMEI = '%s' AND acquisitiontime >= '%s' and acquisitiontime < '%s' AND idx = %d ",
  4208. tablename, pInfo->imei.c_str(), starttime.c_str(), endtime.c_str(), pInfo->idx);
  4209. }
  4210. else
  4211. {
  4212. sql += fmt::format(" UNION ALL "\
  4213. "SELECT [acquisitiontime],[data0],[data1],[data2] "\
  4214. "FROM {} WHERE IMEI = '{}' AND acquisitiontime >= '{}' and acquisitiontime < '{}' AND idx = {} ",
  4215. tablename, pInfo->imei.c_str(), starttime, endtime, pInfo->idx).c_str();
  4216. }
  4217. num++;
  4218. it += COleDateTimeSpan(1, 0, 0, 0);
  4219. }
  4220. sql += "ORDER BY acquisitiontime ASC";
  4221. }
  4222. TIMESTAMP_STRUCT ts;
  4223. int sdata0, sdata1, sdata2;
  4224. COdbcStatement stmt;
  4225. if (CDBConnectPool::Instance()->DBQuery(stmt, sql) == FALSE)
  4226. {
  4227. ASSERT(0);
  4228. SPDLOG_ERROR("查询语句出错:{}", sql);
  4229. code = 500;
  4230. break;
  4231. }
  4232. int nCol = 1;
  4233. stmt.BindTimeStampCol(nCol++, &ts);
  4234. stmt.BindIntCol(nCol++, &sdata0);
  4235. stmt.BindIntCol(nCol++, &sdata1);
  4236. stmt.BindIntCol(nCol++, &sdata2);
  4237. int nCount = 0;
  4238. std::map<time_t, int> data0, data1, data2;
  4239. do
  4240. {
  4241. if (stmt.FetchNext() != 0)
  4242. break;
  4243. CTime ctTime;
  4244. try
  4245. {
  4246. ctTime = CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
  4247. }
  4248. catch (...)
  4249. {
  4250. continue;
  4251. }
  4252. time_t tm = ctTime.GetTime() * 1000 + ts.fraction / 1000000;
  4253. data0[tm] = sdata0;
  4254. data1[tm] = sdata1;
  4255. data2[tm] = sdata2;
  4256. nCount++;
  4257. } while (true);
  4258. stmt.Close();
  4259. list<CONVERT_RESIST> maxResist; //转换力数据
  4260. list<PASS_RESIST> lstPass; //过车数据
  4261. std::map<time_t, int64_t> maxlock0, maxlock1;//锁闭力 前面时间戳, 后面 高4位显示值, 低4位报警值
  4262. std::map<time_t, int64_t> retentionforce0, retentionforce1; //保持力 时间戳, 高4位显示值, 低4位报警值
  4263. std::map<time_t, tagSecondStatInfo> mapSecondStatInfo0, mapSecondStatInfo1, mapSecondStatInfo2;
  4264. mg_per_session_data::GetMaxResist(data2, mapSecondStatInfo2, maxResist, mo, mp);
  4265. mg_per_session_data::GetPassNew(mapSecondStatInfo0, &data0, mapSecondStatInfo1, &data1, mo, mp, &lstPass);
  4266. //过车过滤
  4267. for (auto& item : lstPass)
  4268. {
  4269. for (auto it = maxResist.begin();it != maxResist.end();)
  4270. {
  4271. if (it->tmStart*1000 <= item.show_time && item.show_time <= (it->tmEnd+1)*1000)
  4272. {
  4273. it = maxResist.erase(it);
  4274. break;
  4275. }
  4276. ++it;
  4277. }
  4278. }
  4279. if (maxResist.size())
  4280. {
  4281. mg_per_session_data::GetMaxLockNew(data0, maxResist, maxlock0, retentionforce0);
  4282. mg_per_session_data::GetMaxLockNew(data1, maxResist, maxlock1, retentionforce1);
  4283. }
  4284. else
  4285. {
  4286. code = 200;
  4287. continue; //没有检查到转换阻力
  4288. }
  4289. //CalcFixOrInvert(maxResist, maxlock0, maxlock1, name1, name2);
  4290. //GetMaxForce(data2, maxForce);
  4291. auto fix_object = yyjson_mut_obj(doc);
  4292. yyjson_mut_arr_add_val(data, fix_object);
  4293. auto invert_object = yyjson_mut_obj(doc);
  4294. yyjson_mut_arr_add_val(data, invert_object);
  4295. auto convert_object = yyjson_mut_obj(doc);
  4296. yyjson_mut_arr_add_val(data, convert_object);
  4297. static string fix_name = ANSItoUTF8("定位测力曲线");
  4298. yyjson_mut_obj_add_str(doc, fix_object, "name", fix_name.c_str());
  4299. static string invert_name = ANSItoUTF8("反位测力曲线");
  4300. yyjson_mut_obj_add_str(doc, invert_object, "name", invert_name.c_str());
  4301. static string convert_name = ANSItoUTF8("转换阻力曲线");
  4302. yyjson_mut_obj_add_str(doc, convert_object, "name", convert_name.c_str());
  4303. static string lock_low = ANSItoUTF8("锁闭力过低");
  4304. auto fix_points = yyjson_mut_arr(doc);
  4305. yyjson_mut_obj_add_val(doc, fix_object, "mark_points", fix_points);
  4306. auto invert_points = yyjson_mut_arr(doc);
  4307. yyjson_mut_obj_add_val(doc, invert_object, "mark_points", invert_points);
  4308. auto convert_points = yyjson_mut_arr(doc);
  4309. yyjson_mut_obj_add_val(doc, convert_object, "mark_points", convert_points);
  4310. auto pConvertLimit = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
  4311. auto pFixSuobi = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_FIX, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
  4312. auto pInvertSuobi = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_INVERT, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
  4313. std::map<time_t, int64_t>* pmaxlockfix = nullptr, * pmaxlockinvert = nullptr;
  4314. if (pInfo->name1.find("定位") != -1)
  4315. {
  4316. pmaxlockfix = &maxlock0;
  4317. pmaxlockinvert = &maxlock1;
  4318. }
  4319. else
  4320. {
  4321. pmaxlockfix = &maxlock1;
  4322. pmaxlockinvert = &maxlock0;
  4323. }
  4324. for (auto& it : *pmaxlockfix)
  4325. {
  4326. int curr_val = (int)it.second;
  4327. int show_val = (it.second >> 32);
  4328. time_t show_time = it.first;
  4329. auto obj = yyjson_mut_obj(doc);
  4330. yyjson_mut_arr_add_val(fix_points, obj);
  4331. auto coord = yyjson_mut_arr(doc);
  4332. yyjson_mut_obj_add_val(doc, obj, "coord", coord);
  4333. yyjson_mut_arr_add_int(doc, coord, show_time);
  4334. yyjson_mut_arr_add_int(doc, coord, curr_val);
  4335. 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());
  4336. yyjson_mut_obj_add_int(doc, obj, "val", show_val);
  4337. if (pFixSuobi && pFixSuobi->enable)
  4338. {
  4339. if (pFixSuobi->alarm_low_limit > show_val)
  4340. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  4341. else if (pFixSuobi->alarm_high_limit < show_val)
  4342. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  4343. else if (pFixSuobi->warn_high_limit < show_val)
  4344. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  4345. else if (pFixSuobi->warn_low_limit > show_val)
  4346. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  4347. }
  4348. yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", ++show_val)).c_str());
  4349. //CResistAlarmMng::InsertToDBByMove(mo, mp, it.first, 0, 0,
  4350. // (int)it.second, show_val, i, (uint8_t)eDaoChaPosi::DCP_FIX, fmt::format("锁闭力:{}", show_val));
  4351. //JudgeAlarm(pService, pFixSuobiOverInfo, it.first, show_val, eSuoBiPosi::SB_FIX, mo, mp, zzjno);
  4352. }
  4353. for (auto& it : *pmaxlockinvert)
  4354. {
  4355. int curr_val = (int)it.second;
  4356. int show_val = (it.second >> 32);
  4357. time_t show_time = it.first;
  4358. auto obj = yyjson_mut_obj(doc);
  4359. yyjson_mut_arr_add_val(invert_points, obj);
  4360. auto coord = yyjson_mut_arr(doc);
  4361. yyjson_mut_obj_add_val(doc, obj, "coord", coord);
  4362. yyjson_mut_arr_add_int(doc, coord, show_time);
  4363. yyjson_mut_arr_add_int(doc, coord, curr_val);
  4364. 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());
  4365. yyjson_mut_obj_add_int(doc, obj, "val", show_val);
  4366. if (pInvertSuobi && pInvertSuobi->enable)
  4367. {
  4368. if (pInvertSuobi->alarm_low_limit > show_val)
  4369. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  4370. else if (pInvertSuobi->alarm_high_limit < show_val)
  4371. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  4372. else if (pInvertSuobi->warn_high_limit < show_val)
  4373. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  4374. else if (pInvertSuobi->warn_low_limit > show_val)
  4375. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  4376. }
  4377. yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", ++show_val)).c_str());
  4378. //int show_val = (it.second >> 32);
  4379. //CResistAlarmMng::InsertToDBByMove(mo, mp, it.first, 0, 0,
  4380. // (int)it.second, show_val, i, (uint8_t)eDaoChaPosi::DCP_INVERT, fmt::format("锁闭力:{}", show_val));
  4381. //JudgeAlarm(pService, pInvertSuobiOverInfo, it.first, show_val, eSuoBiPosi::SB_INVERT, mo, mp, zzjno);
  4382. }
  4383. for (auto& it : maxResist)
  4384. {
  4385. auto obj = yyjson_mut_obj(doc);
  4386. int curr_val = it.val;
  4387. int show_val = it.fluctuation_val;
  4388. time_t show_time = it.time;
  4389. eDaoChaPosi posi = eDaoChaPosi::DCP_UNKNOWN;
  4390. if (it.bUpOrDown == eUpOrDownInfo::UOD_UP)
  4391. {
  4392. if (pInfo->in_name.find("定扳反") != -1)
  4393. {
  4394. yyjson_mut_arr_add_val(convert_points, obj);
  4395. auto coord = yyjson_mut_arr(doc);
  4396. yyjson_mut_obj_add_val(doc, obj, "coord", coord);
  4397. yyjson_mut_arr_add_int(doc, coord, show_time);
  4398. yyjson_mut_arr_add_int(doc, coord, curr_val);
  4399. 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());
  4400. yyjson_mut_obj_add_int(doc, obj, "val", show_val);
  4401. if (pConvertLimit && pConvertLimit->enable)
  4402. {
  4403. if (pInfo->out_name.find("定扳反") != -1)
  4404. {
  4405. if (pConvertLimit->dw_alarm_low_limit > show_val)
  4406. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  4407. else if (pConvertLimit->dw_warn_low_limit > show_val)
  4408. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  4409. }
  4410. else
  4411. {
  4412. if (pConvertLimit->up_alarm_high_limit < show_val)
  4413. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  4414. else if (pConvertLimit->up_warn_high_limit < show_val)
  4415. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  4416. }
  4417. }
  4418. if (curr_val < 0)
  4419. yyjson_mut_obj_add_str(doc, obj, "position", "bottom");
  4420. yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("定扳反:{}", ++show_val)).c_str());
  4421. //CResistAlarmMng::InsertToDBByMove(mo, mp, it.time, it.tmStart, it.tmEnd, it.val, it.fluctuation_val, i,
  4422. // (uint8_t)eDaoChaPosi::DCP_FIX2INVERT, fmt::format("{}:{}", in_name, it.fluctuation_val));
  4423. //posi = eDaoChaPosi::DCP_FIX2INVERT;
  4424. //CMonitorObjectMng::Instance()->UpdateZZJEPOS(mo + "." + mp, DAOCHA_POSITION::MP_INVERT);
  4425. //JudgeAlarm(pService, pConvertResistOverLimitInfo, it.time, it.fluctuation_val, posi, it.bUpOrDown, mo, mp, zzjno);
  4426. }
  4427. else
  4428. {
  4429. yyjson_mut_arr_add_val(convert_points, obj);
  4430. auto coord = yyjson_mut_arr(doc);
  4431. yyjson_mut_obj_add_val(doc, obj, "coord", coord);
  4432. yyjson_mut_arr_add_int(doc, coord, show_time);
  4433. yyjson_mut_arr_add_int(doc, coord, curr_val);
  4434. 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());
  4435. yyjson_mut_obj_add_int(doc, obj, "val", show_val);
  4436. if (pConvertLimit && pConvertLimit->enable)
  4437. {
  4438. if (pInfo->out_name.find("反扳定") != -1)
  4439. {
  4440. if (pConvertLimit->dw_alarm_low_limit > show_val)
  4441. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  4442. else if (pConvertLimit->dw_warn_low_limit > show_val)
  4443. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  4444. }
  4445. else
  4446. {
  4447. if (pConvertLimit->up_alarm_high_limit < show_val)
  4448. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  4449. else if (pConvertLimit->up_warn_high_limit < show_val)
  4450. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  4451. }
  4452. }
  4453. if (curr_val < 0)
  4454. yyjson_mut_obj_add_str(doc, obj, "position", "bottom");
  4455. yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("反扳定:{}", ++show_val)).c_str());
  4456. //CResistAlarmMng::InsertToDBByMove(mo, mp, it.time, it.tmStart, it.tmEnd, it.val, it.fluctuation_val, i,
  4457. // (uint8_t)eDaoChaPosi::DCP_INVERT2FIX, fmt::format("{}:{}", in_name, it.fluctuation_val));
  4458. //posi = eDaoChaPosi::DCP_INVERT2FIX;
  4459. //CMonitorObjectMng::Instance()->UpdateZZJEPOS(mo + "." + mp, DAOCHA_POSITION::MP_FIX);
  4460. //JudgeAlarm(pService, pConvertResistOverLimitInfo, it.time, it.fluctuation_val, posi, it.bUpOrDown, mo, mp, zzjno);
  4461. }
  4462. }
  4463. else
  4464. {
  4465. if (pInfo->out_name.find("定扳反") != -1)
  4466. {
  4467. yyjson_mut_arr_add_val(convert_points, obj);
  4468. auto coord = yyjson_mut_arr(doc);
  4469. yyjson_mut_obj_add_val(doc, obj, "coord", coord);
  4470. yyjson_mut_arr_add_int(doc, coord, show_time);
  4471. yyjson_mut_arr_add_int(doc, coord, curr_val);
  4472. 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());
  4473. yyjson_mut_obj_add_int(doc, obj, "val", show_val);
  4474. if (pConvertLimit && pConvertLimit->enable)
  4475. {
  4476. if (pInfo->out_name.find("定扳反") != -1)
  4477. {
  4478. if (pConvertLimit->dw_alarm_low_limit > show_val)
  4479. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  4480. else if (pConvertLimit->dw_warn_low_limit > show_val)
  4481. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  4482. }
  4483. else
  4484. {
  4485. if (pConvertLimit->up_alarm_high_limit < show_val)
  4486. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  4487. else if (pConvertLimit->up_warn_high_limit < show_val)
  4488. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  4489. }
  4490. }
  4491. if (curr_val < 0)
  4492. yyjson_mut_obj_add_str(doc, obj, "position", "bottom");
  4493. yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("定扳反:{}", ++show_val)).c_str());
  4494. //CResistAlarmMng::InsertToDBByMove(mo, mp, it.time, it.tmStart, it.tmEnd, it.val, it.fluctuation_val, i,
  4495. // (uint8_t)eDaoChaPosi::DCP_FIX2INVERT, fmt::format("{}:{}", out_name, it.fluctuation_val));
  4496. //posi = eDaoChaPosi::DCP_FIX2INVERT;
  4497. //CMonitorObjectMng::Instance()->UpdateZZJEPOS(mo + "." + mp, DAOCHA_POSITION::MP_INVERT);
  4498. //JudgeAlarm(pService, pConvertResistOverLimitInfo, it.time, it.fluctuation_val, posi, it.bUpOrDown, mo, mp, zzjno);
  4499. }
  4500. else
  4501. {
  4502. yyjson_mut_arr_add_val(convert_points, obj);
  4503. auto coord = yyjson_mut_arr(doc);
  4504. yyjson_mut_obj_add_val(doc, obj, "coord", coord);
  4505. yyjson_mut_arr_add_int(doc, coord, show_time);
  4506. yyjson_mut_arr_add_int(doc, coord, curr_val);
  4507. 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());
  4508. yyjson_mut_obj_add_int(doc, obj, "val", show_val);
  4509. if (pConvertLimit && pConvertLimit->enable)
  4510. {
  4511. if (pInfo->out_name.find("反扳定") != -1)
  4512. {
  4513. if (pConvertLimit->dw_alarm_low_limit > show_val)
  4514. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  4515. else if (pConvertLimit->dw_warn_low_limit > show_val)
  4516. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  4517. }
  4518. else
  4519. {
  4520. if (pConvertLimit->up_alarm_high_limit < show_val)
  4521. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  4522. else if (pConvertLimit->up_warn_high_limit < show_val)
  4523. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  4524. }
  4525. }
  4526. if (curr_val < 0)
  4527. yyjson_mut_obj_add_str(doc, obj, "position", "bottom");
  4528. yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("反扳定:{}", ++show_val)).c_str());
  4529. //CResistAlarmMng::InsertToDBByMove(mo, mp, it.time, it.tmStart, it.tmEnd, it.val, it.fluctuation_val, i,
  4530. // (uint8_t)eDaoChaPosi::DCP_INVERT2FIX, fmt::format("{}:{}", out_name, it.fluctuation_val));
  4531. //posi = eDaoChaPosi::DCP_INVERT2FIX;
  4532. //CMonitorObjectMng::Instance()->UpdateZZJEPOS(mo + "." + mp, DAOCHA_POSITION::MP_FIX);
  4533. //JudgeAlarm(pService, pConvertResistOverLimitInfo, it.time, it.fluctuation_val, posi, it.bUpOrDown, mo, mp, zzjno);
  4534. }
  4535. }
  4536. }
  4537. code = 200;
  4538. } while (false);
  4539. *json = yyjson_mut_write(doc, 0, json_len);
  4540. yyjson_mut_doc_free(doc);
  4541. return code;
  4542. }