LNHandle.cpp 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  1. #include "stdafx.h"
  2. #include "LNHandle.h"
  3. #include <Simplelog.h>
  4. #include "AppService.h"
  5. #include "Device.h"
  6. #include <yyjson.h>
  7. #include "MGWSServer.h"
  8. #include "Device.h"
  9. #include "ResistAlarm.h"
  10. #include <gbk2utf8.h>
  11. using namespace jsonxx;
  12. CTask::CTask(LPBYTE pPack, int nPackLen, SOCKADDR* psa, void* pClientContext)
  13. : addr(*psa)
  14. {
  15. pdata = new BYTE[nPackLen];
  16. memcpy(pdata, pPack, nPackLen);
  17. nlen = nPackLen;
  18. }
  19. void CTask::join()
  20. {
  21. delete this;
  22. }
  23. CTask::~CTask()
  24. {
  25. delete[] pdata;
  26. pdata = nullptr;
  27. nlen = 0;
  28. }
  29. CLNHandle::CLNHandle()
  30. {
  31. m_dl_sync = new uint8_t[100];
  32. m_dl_len = CHjDataConver::conver_sendpack(m_dl_sync, nullptr, 0, 0, 0, E_ZL_PROTOCAL::DL_SYNC, OR_DATA_INFO(0,0, 1, 3, OPT_TYPE::OPT_SYNC));
  33. for (auto i = 0; i < MAX_HANDLE_THREAD_NUM; i++)
  34. pThread[i] = nullptr;
  35. Create();
  36. }
  37. CLNHandle::~CLNHandle()
  38. {
  39. delete[] m_dl_sync;
  40. m_dl_sync = nullptr;
  41. m_dl_len = 0;
  42. Close();
  43. }
  44. BOOL CLNHandle::HandlePack(LPBYTE pPack, int nPackLen, SOCKADDR* psa, void* pClientContext /*= NULL*/)
  45. {
  46. if (!m_bWork) return true;
  47. auto pContext = ((CLNContext*)pClientContext);
  48. if ((pPack == NULL || nPackLen == 0) && pClientContext)
  49. {
  50. pContext->SetIPAdress();
  51. SPDLOG_INFO("10090 发现新连接:{}", pContext->GetIPAdress());
  52. pContext->Send(m_dl_sync, m_dl_len);
  53. return TRUE;
  54. }
  55. if (CHjDataConver::conver_recvpack(pPack, nPackLen) == false)
  56. return FALSE;
  57. LPHJDATAHEAD2 lpHead = (HJDATAHEAD2*)pPack;
  58. auto addr = (SOCKADDR_IN*)psa;
  59. auto it = m_mapUser.find(addr->sin_addr.S_un.S_addr);
  60. if (lpHead->protocol == E_ZL_PROTOCAL::ZL_KEEP)
  61. return TRUE;
  62. //SPDLOG_INFO("packno:{} recv {}", lpHead->packno, uint8_t(lpHead->protocol));
  63. switch (lpHead->protocol)
  64. {
  65. case E_ZL_PROTOCAL::ZL_MO:
  66. HandleMoSync(lpHead, (char*)pPack + sizeof(HJDATAHEAD2), lpHead->len, (CLNContext*)pClientContext);
  67. break;
  68. case E_ZL_PROTOCAL::ZL_MP:
  69. HandleMpSync(lpHead, (char*)pPack + sizeof(HJDATAHEAD2), lpHead->len, (CLNContext*)pClientContext);
  70. break;
  71. case E_ZL_PROTOCAL::ZL_SVG:
  72. HandleSvgSync(lpHead, (char*)pPack + sizeof(HJDATAHEAD2), lpHead->len, (CLNContext*)pClientContext);
  73. break;
  74. case E_ZL_PROTOCAL::ZL_REFER:
  75. HandleReferSync(lpHead, (char*)pPack + sizeof(HJDATAHEAD2), lpHead->len, (CLNContext*)pClientContext);
  76. break;
  77. case E_ZL_PROTOCAL::ZL_ALARM_SET:
  78. HandleAlarmSetSync(lpHead, (char*)pPack + sizeof(HJDATAHEAD2), lpHead->len, (CLNContext*)pClientContext);
  79. break;
  80. case E_ZL_PROTOCAL::ZL_ALARM_UNACK:
  81. HandleRecvPack(pContext, lpHead->protocol, lpHead->packno);
  82. break;
  83. case E_ZL_PROTOCAL::ZL_RESIST_DATA:
  84. HandleResistData(lpHead, (char*)pPack + sizeof(HJDATAHEAD2), lpHead->len, (CLNContext*)pClientContext);
  85. break;
  86. case E_ZL_PROTOCAL::ZL_TEMP_HUMI:
  87. HandleTempHumiData(lpHead, (char*)pPack + sizeof(HJDATAHEAD2), lpHead->len, (CLNContext*)pClientContext);
  88. break;
  89. case E_ZL_PROTOCAL::ZL_MOVE:
  90. HandleMove(lpHead, (char*)pPack + sizeof(HJDATAHEAD2), lpHead->len, (CLNContext*)pClientContext);
  91. break;
  92. case E_ZL_PROTOCAL::ZL_ALARM_DATA:
  93. HandleAlarmData(lpHead, (char*)pPack + sizeof(HJDATAHEAD2), lpHead->len, (CLNContext*)pClientContext);
  94. break;
  95. default:
  96. SPDLOG_WARN("收到未解析的命令:{}", uint8_t(lpHead->protocol));
  97. break;
  98. }
  99. return TRUE;
  100. }
  101. void CLNHandle::SendAllClientSync()
  102. {
  103. auto pAcceptor = CAppService::Instance()->GetAcceptor();
  104. if (!pAcceptor) return;
  105. pAcceptor->SendDataAllContexts(m_dl_sync, m_dl_len);
  106. }
  107. void CLNHandle::SendSubNotify(string momp)
  108. {
  109. jsonxx::Object obj;
  110. obj << "momp" << momp;
  111. auto data = obj.json();
  112. BYTE send[100];
  113. int len = CHjDataConver::conver_sendpack(send, (BYTE*)data.c_str(), data.length(), 0, 0, E_ZL_PROTOCAL::DL_SUB_NOTIFY, OR_DATA_INFO(0, 0, 1, 3, OPT_TYPE::OPT_ADD));
  114. auto pAcceptor = CAppService::Instance()->GetAcceptor();
  115. if (!pAcceptor) return;
  116. pAcceptor->SendDataAllContexts(send, len);
  117. }
  118. void CLNHandle::HandleMoSync(LPHJDATAHEAD2 lpHead, char* json, int json_len, CLNContext* pContext)
  119. {
  120. jsonxx::Object doc;
  121. doc.parse(string(json, json_len));
  122. if (doc.empty()) return;
  123. auto id = doc.get<string>("id");
  124. ASSERT(id.compare("100000") == 0);
  125. auto pObj = CMonitorObjectMng::Instance()->GetTreeByID(id);
  126. auto child = doc.get<jsonxx::Array>("child");
  127. auto n = child.size();
  128. for (int i = 0; i < n; i++)
  129. {
  130. auto obj = child.get<Object>(i);
  131. CompareMoSync(obj, pObj);
  132. }
  133. HandleRecvPack(pContext, lpHead->protocol, lpHead->packno);
  134. }
  135. void CLNHandle::HandleMpSync(LPHJDATAHEAD2 lpHead, char* json, int json_len, CLNContext* pContext)
  136. {
  137. using namespace jsonxx;
  138. jsonxx::Array doc;
  139. doc.parse(string(json, json_len));
  140. if (doc.empty()) return;
  141. size_t n = doc.size();
  142. for (size_t i = 0; i < n; i++)
  143. {
  144. auto obj = doc.get<Object>(i);
  145. CompareMpSync(obj);
  146. }
  147. HandleRecvPack(pContext, lpHead->protocol, lpHead->packno);
  148. }
  149. BOOL CLNHandle::HandleSvgSync(LPHJDATAHEAD2 lpHead, char* json, int json_len, CLNContext* pContext)
  150. {
  151. HandleRecvPack(pContext, lpHead->protocol, lpHead->packno);
  152. auto strSvgFolderPath = g_strExepath + "svg\\";
  153. string strFileName(json);
  154. auto strSvgPath = strSvgFolderPath + strFileName + ".svg";
  155. BOOL bSave = true;
  156. WIN32_FILE_ATTRIBUTE_DATA attrs = { 0 };
  157. if (0 != ::GetFileAttributesEx(strSvgPath.c_str(), ::GetFileExInfoStandard, &attrs))
  158. {
  159. auto len = ((uint64_t)attrs.nFileSizeHigh << 32) + attrs.nFileSizeLow;
  160. if (len == json_len - 64)
  161. bSave = false; //大小相等不存储
  162. }
  163. if (bSave)
  164. {
  165. CFile file;
  166. if (file.Open(strSvgPath.c_str(), CFile::modeCreate | CFile::modeWrite | CFile::typeBinary) == FALSE)
  167. {
  168. SPDLOG_ERROR("打开文件{}失败", strSvgPath);
  169. return FALSE;
  170. }
  171. else
  172. {
  173. file.Write(json + 64, json_len - 64);
  174. file.Close();
  175. }
  176. }
  177. return TRUE;
  178. }
  179. BOOL CLNHandle::HandleReferSync(LPHJDATAHEAD2 lpHead, char* json, int json_len, CLNContext* pContext)
  180. {
  181. HandleRecvPack(pContext, lpHead->protocol, lpHead->packno);
  182. auto strSvgFolderPath = g_strExepath + "refer\\";
  183. string strFileName(json);
  184. auto strSvgPath = strSvgFolderPath + strFileName + ".json";
  185. BOOL bSave = true;
  186. WIN32_FILE_ATTRIBUTE_DATA attrs = { 0 };
  187. if (0 != ::GetFileAttributesEx(strSvgPath.c_str(), ::GetFileExInfoStandard, &attrs))
  188. {
  189. auto len = ((uint64_t)attrs.nFileSizeHigh << 32) + attrs.nFileSizeLow;
  190. if (len == json_len - 64)
  191. bSave = false; //大小相等不存储
  192. }
  193. if (bSave)
  194. {
  195. CFile file;
  196. if (file.Open(strSvgPath.c_str(), CFile::modeCreate | CFile::modeWrite | CFile::typeBinary) == FALSE)
  197. {
  198. SPDLOG_ERROR("打开文件{}失败", strSvgPath);
  199. return FALSE;
  200. }
  201. else
  202. {
  203. file.Write(json + 64, json_len - 64);
  204. file.Close();
  205. }
  206. }
  207. return TRUE;
  208. }
  209. BOOL CLNHandle::HandleResistData(LPHJDATAHEAD2 lpHead, char* json, int len, CLNContext* pContext)
  210. {
  211. HandleRecvPack(pContext, lpHead->protocol, lpHead->packno);
  212. static string sz_utf_fix = ANSItoUTF8("定位测力曲线");
  213. static string sz_utf_invert = ANSItoUTF8("反位测力曲线");
  214. static string sz_utf_convert = ANSItoUTF8("转换阻力曲线");
  215. Object doc;
  216. string strJson(json, len);
  217. doc.parse(strJson);
  218. if (doc.empty())
  219. {
  220. SPDLOG_WARN("json格式未正确 {}", strJson);
  221. return FALSE;
  222. }
  223. auto station = doc.get<string>("station");
  224. auto mo = doc.get<string>("mo");
  225. auto mp = doc.get<string>("mp");
  226. auto time = doc.get<Array>("time");
  227. auto fix_data = doc.get<Array>("fix_data");
  228. auto invert_data = doc.get<Array>("invert_data");
  229. auto convert_data = doc.get<Array>("convert_data");
  230. size_t n = time.size();
  231. size_t n1 = fix_data.size();
  232. size_t n2 = invert_data.size();
  233. size_t n3 = convert_data.size();
  234. ASSERT(n == n1 && n == n2 && n == n3);
  235. if (n != n1 || n != n2 || n != n3)
  236. {
  237. SPDLOG_WARN("time fix_data invert_data convert_data not = {}", strJson);
  238. return FALSE;
  239. }
  240. if (n < 1)
  241. {
  242. SPDLOG_WARN("size < 1 {}", strJson);
  243. return FALSE;
  244. }
  245. auto momp = fmt::format("{}.{}", mo, mp);
  246. auto tt = time.get<string>(0);
  247. int year, month, day;
  248. auto s_num = sscanf_s(tt.c_str(), "%d-%d-%d ", &year, &month, &day);
  249. ASSERT(s_num == 3);
  250. auto tablename = fmt::format("rm_resistance_{:0>4}{:0>2}{:0>2}", year, month, day);
  251. auto ii = fix_data.get<Value>(0);
  252. auto pDevice = CDeviceMng::Instance()->Find(momp);
  253. if (pDevice) pDevice->updateActive();
  254. static auto mg_server = CAppService::Instance()->GetMgServer();
  255. auto bSub = mg_server->IsClientSubReal(momp); //判断客户端是否订阅
  256. char* json_res = nullptr;
  257. yyjson_mut_doc* doc_y = nullptr;
  258. yyjson_mut_val* points_fix = nullptr;
  259. yyjson_mut_val* points_invert = nullptr;
  260. yyjson_mut_val* points_convert = nullptr;
  261. if (bSub)
  262. {
  263. doc_y = yyjson_mut_doc_new(nullptr);
  264. auto root = yyjson_mut_obj(doc_y);
  265. yyjson_mut_doc_set_root(doc_y, root);
  266. auto data = yyjson_mut_arr(doc_y);
  267. yyjson_mut_obj_add_val(doc_y, root, "data", data);
  268. auto curve_fix = yyjson_mut_obj(doc_y);//定
  269. auto curve_invert = yyjson_mut_obj(doc_y);//反
  270. auto curve_convert = yyjson_mut_obj(doc_y);//转换
  271. yyjson_mut_arr_add_val(data, curve_fix);
  272. yyjson_mut_arr_add_val(data, curve_invert);
  273. yyjson_mut_arr_add_val(data, curve_convert);
  274. yyjson_mut_obj_add_str(doc_y, root, "cmd", "new_data_notify");
  275. yyjson_mut_obj_add_strcpy(doc_y, root, "tag", (momp + ".resist").c_str());
  276. yyjson_mut_obj_add_str(doc_y, root, "data_fmt", "curve");
  277. yyjson_mut_obj_add_str(doc_y, root, "unit", "N");
  278. yyjson_mut_obj_add_strcpy(doc_y, root, "up", ANSItoUTF8(station).c_str());
  279. yyjson_mut_obj_add_strcpy(doc_y, root, "tag_name", pDevice ? (pDevice->mo_name + "." + pDevice->mp_name).c_str() : momp.c_str());
  280. yyjson_mut_obj_add_str(doc_y, curve_fix, "name", sz_utf_fix.c_str());
  281. yyjson_mut_obj_add_str(doc_y, curve_invert, "name", sz_utf_invert.c_str());
  282. yyjson_mut_obj_add_str(doc_y, curve_convert, "name", sz_utf_convert.c_str());
  283. points_fix = yyjson_mut_arr(doc_y);
  284. yyjson_mut_obj_add_val(doc_y, curve_fix, "points", points_fix);
  285. points_invert = yyjson_mut_arr(doc_y);
  286. yyjson_mut_obj_add_val(doc_y, curve_invert, "points", points_invert);
  287. points_convert = yyjson_mut_arr(doc_y);
  288. yyjson_mut_obj_add_val(doc_y, curve_convert, "points", points_convert);
  289. }
  290. CString sql;
  291. for (size_t i = 0; i < n; i++)
  292. {
  293. auto t = time.get<string>(i);
  294. int f = int(fix_data.get<Number>(i));
  295. int v = int(invert_data.get<Number>(i));
  296. int c = int(convert_data.get<Number>(i));
  297. sql += fmt::format("INSERT INTO {}(momp,acquisitiontime,data0,data1,data2) VALUES ('{}','{}',{},{},{});",
  298. tablename, momp, t, f, v, c).c_str();
  299. if (bSub)
  300. {
  301. int hour, min, second, fra;
  302. auto s_num = sscanf_s(t.c_str(), "%d-%d-%d %d:%d:%d.%d", &year, &month, &day, &hour, &min, &second, &fra);
  303. if (s_num == 7)
  304. {
  305. uint64_t ttt = CTime(year, month, day, hour, min, second).GetTime() * 1000 + fra;
  306. {
  307. auto item = yyjson_mut_arr(doc_y);
  308. yyjson_mut_arr_add_val(points_fix, item);
  309. yyjson_mut_arr_add_uint(doc_y, item, ttt);
  310. yyjson_mut_arr_add_int(doc_y, item, f);
  311. }
  312. {
  313. auto item = yyjson_mut_arr(doc_y);
  314. yyjson_mut_arr_add_val(points_invert, item);
  315. yyjson_mut_arr_add_uint(doc_y, item, ttt);
  316. yyjson_mut_arr_add_int(doc_y, item, v);
  317. }
  318. {
  319. auto item = yyjson_mut_arr(doc_y);
  320. yyjson_mut_arr_add_val(points_convert, item);
  321. yyjson_mut_arr_add_uint(doc_y, item, ttt);
  322. yyjson_mut_arr_add_int(doc_y, item, c);
  323. }
  324. }
  325. else
  326. ASSERT(false);
  327. }
  328. }
  329. auto pConn = CDBConnectPool::Instance()->GetConnection();
  330. COdbcStatement stmt(pConn);
  331. auto iret = pConn->SetAutoCommit(false);
  332. iret = stmt.Prepare(sql);
  333. if (ISODBCSUCCESS(stmt.Execute()))
  334. {
  335. }
  336. else
  337. {
  338. SPDLOG_ERROR("语句执行错误{}", sql);
  339. }
  340. iret = pConn->Commit();
  341. pConn->SetAutoCommit(true);
  342. if (bSub)
  343. {
  344. size_t json_len;
  345. json_res = yyjson_mut_write(doc_y, 0, &json_len);
  346. mg_server->SendClientSubReal(momp, json_res, json_len);
  347. }
  348. //释放
  349. CDBConnectPool::Instance()->FreeConnection(pConn);
  350. if (json_res) free(json_res);
  351. yyjson_mut_doc_free(doc_y);
  352. return TRUE;
  353. }
  354. BOOL CLNHandle::HandleTempHumiData(LPHJDATAHEAD2 lpHead, char* json, int json_len, CLNContext* pContext)
  355. {
  356. HandleRecvPack(pContext, lpHead->protocol, lpHead->packno);
  357. Object doc;
  358. string strJson(json, json_len);
  359. doc.parse(strJson);
  360. if (doc.empty())
  361. {
  362. SPDLOG_WARN("json格式未正确 {}", strJson);
  363. return FALSE;
  364. }
  365. auto station = doc.get<string>("station");
  366. auto mo = doc.get<string>("mo");
  367. auto mp = doc.get<string>("mp");
  368. auto time = doc.get<string>("time");
  369. int temp = doc.get<Number>("temp");
  370. int humi = doc.get<Number>("humi");
  371. int year, month, day;
  372. auto s_num = sscanf_s(time.c_str(), "%d-%d-%d ", &year, &month, &day);
  373. ASSERT(s_num == 3);
  374. auto tablename = fmt::format("rm_temphumidity_{:0>4}{:0>2}", year, month);
  375. CString sql = fmt::format("INSERT INTO {}(mo,mp,acquisitiontime,temperature,humidity) VALUES ('{}','{}','{}',{},{});",
  376. tablename, mo, mp, time, temp, humi).c_str();
  377. if (!CDBConnectPool::Instance()->DBExecuteSQL(sql))
  378. {
  379. SPDLOG_ERROR("语句执行错误{}", sql);
  380. return FALSE;
  381. }
  382. return TRUE;
  383. }
  384. BOOL CLNHandle::HandleAlarmSetSync(LPHJDATAHEAD2 lpHead, char* json, int json_len, CLNContext* pContext)
  385. {
  386. BOOL bRet = false;
  387. do {
  388. Array arr;
  389. arr.parse(string(json, json_len));
  390. if (arr.empty())
  391. {
  392. ASSERT(0);
  393. break;
  394. }
  395. size_t n = arr.size();
  396. for (int i = 0; i < n; i++)
  397. {
  398. auto obj = arr.get<Object>(i);
  399. auto mo = obj.get<string>("mo");
  400. auto mp = obj.get<string>("mp");
  401. auto station = obj.get<string>("station");
  402. uint8_t no = obj.get<Number>("no");
  403. eZL_ALARMTYPE type = (eZL_ALARMTYPE)obj.get<Number>("type");
  404. auto pBaseInfo = CResistAlarmMng::Instance()->Find(mo, mp, no, type);
  405. static auto InsertAlarmSetToDB = [](string& mo, string& mp, uint8_t no, eZL_ALARMTYPE type, string& conf) {
  406. time_t tt;
  407. time(&tt);
  408. CString sql = fmt::format("INSERT INTO[rm_alarm_set]([mo], [mp], [no], [type], [conf], [time]) VALUES('{}', '{}', {}, {}, '{}', '{}')",
  409. mo, mp, no, uint8_t(type), conf, tt).c_str();
  410. if (FALSE == CDBConnectPool::Instance()->DBExecuteSQL(sql))
  411. {
  412. ASSERT(0);
  413. SPDLOG_ERROR("插入语句执行错误:{}", sql);
  414. return FALSE;
  415. }
  416. return TRUE;
  417. };
  418. static auto UpdateAlarmSetToDB = [](string& mo, string& mp, uint8_t no, eZL_ALARMTYPE type, string& conf) {
  419. time_t tt;
  420. time(&tt);
  421. CString sql = fmt::format("UPDATE rm_alarm_set SET [conf] = '{}',[time] = {} WHERE mo='{}' AND mp='{}' AND no = {} AND type = {}",
  422. conf, tt, mo, mp, no, uint8_t(type)).c_str();
  423. if (FALSE == CDBConnectPool::Instance()->DBExecuteSQL(sql))
  424. {
  425. ASSERT(0);
  426. SPDLOG_ERROR("更新语句执行错误:{}", sql);
  427. return FALSE;
  428. }
  429. return TRUE;
  430. };
  431. string strConfig;
  432. Array conf_array;
  433. Object conf_obj;
  434. if (type == eZL_ALARMTYPE::MAX_OVER_LIMIT || type == eZL_ALARMTYPE::FRICTION_OVER_LIMIT)
  435. {
  436. conf_array = obj.get<Array>("conf");
  437. strConfig = conf_array.json();
  438. }
  439. else if (type == eZL_ALARMTYPE::SUOBI_LOCK_LIMIT || type == eZL_ALARMTYPE::CONVERT_LIMIT)
  440. {
  441. conf_obj = obj.get<Object>("conf");
  442. strConfig = conf_obj.json();
  443. }
  444. else
  445. ASSERT(FALSE);
  446. if (pBaseInfo == nullptr)
  447. {//不存在,新增
  448. //插入数据库
  449. if (FALSE == InsertAlarmSetToDB(mo, mp, no, type, strConfig))
  450. break;
  451. switch (type)
  452. {
  453. case eZL_ALARMTYPE::MAX_OVER_LIMIT:
  454. {
  455. auto pInfo = new MAX_OVER_LIMIT_INFO;
  456. pBaseInfo = pInfo;
  457. pInfo->no = no;
  458. pInfo->type = type;
  459. bool enable = false;
  460. short alarm_high_limit = MAXSHORT;
  461. short warn_high_limit = MAXSHORT;
  462. short f_alarm_high_limit = MAXSHORT;
  463. short f_warn_high_limit = MAXSHORT;
  464. size_t n = conf_array.size();
  465. for (size_t i = 0; i < n; i++)
  466. {
  467. auto obj = conf_array.get<Object>(i);
  468. auto key = obj.get<string>("name");
  469. auto value = obj.get<string>("val");
  470. if (key.compare("enable") == 0)
  471. {
  472. enable = (value.compare("true") == 0);
  473. }
  474. else if (key.compare("lock_alarm_high_limit") == 0)
  475. {
  476. alarm_high_limit = atoi(value.c_str());
  477. }
  478. else if (key.compare("lock_warn_high_limit") == 0)
  479. {
  480. warn_high_limit = atoi(value.c_str());
  481. }
  482. else if (key.compare("d_alarm_high_limit") == 0)
  483. {
  484. alarm_high_limit = atoi(value.c_str());
  485. }
  486. else if (key.compare("d_warn_high_limit") == 0)
  487. {
  488. warn_high_limit = atoi(value.c_str());
  489. }
  490. else if (key.compare("f_alarm_high_limit") == 0)
  491. {
  492. f_alarm_high_limit = atoi(value.c_str());
  493. }
  494. else if (key.compare("f_warn_high_limit") == 0)
  495. {
  496. f_warn_high_limit = atoi(value.c_str());
  497. }
  498. else if (key.compare("keep_alarm_high_limit") == 0)
  499. {
  500. f_alarm_high_limit = atoi(value.c_str());
  501. }
  502. else if (key.compare("keep_warn_high_limit") == 0)
  503. {
  504. f_warn_high_limit = atoi(value.c_str());
  505. }
  506. else
  507. {
  508. ASSERT(0);
  509. }
  510. }
  511. pInfo->alarm_high_limit = alarm_high_limit;
  512. pInfo->warn_high_limit = warn_high_limit;
  513. pInfo->f_alarm_high_limit = f_alarm_high_limit;
  514. pInfo->f_warn_high_limit = f_warn_high_limit;
  515. CResistAlarmMng::Instance()->Insert(mo, mp, no, uint8_t(type), pInfo);
  516. }
  517. break;
  518. case eZL_ALARMTYPE::FRICTION_OVER_LIMIT:
  519. {
  520. auto pInfo = new FRICTION_OVER_LIMIT_INFO;
  521. pBaseInfo = pInfo;
  522. pInfo->no = no;
  523. pInfo->type = type;
  524. size_t n = conf_array.size();
  525. for (size_t i = 0; i < n; i++)
  526. {
  527. auto obj = conf_array.get<Object>(i);
  528. auto name = obj.get<string>("name");
  529. auto val = obj.get<string>("val");
  530. if (name.compare("enable") == 0)
  531. {
  532. pInfo->enable = val.compare("true") == 0 ? 1 : 0;
  533. }
  534. else if (name.compare("up_alarm_low_limit") == 0)
  535. {
  536. pInfo->up_alarm_low_limit = atoi(val.c_str());
  537. }
  538. else if (name.compare("up_warn_low_limit") == 0)
  539. {
  540. pInfo->up_warn_low_limit = atoi(val.c_str());
  541. }
  542. else if (name.compare("dw_alarm_high_limit") == 0)
  543. {
  544. pInfo->dw_alarm_high_limit = atoi(val.c_str());
  545. }
  546. else if (name.compare("dw_warn_high_limit") == 0)
  547. {
  548. pInfo->dw_warn_high_limit = atoi(val.c_str());
  549. }
  550. else
  551. ASSERT(0);
  552. }
  553. CResistAlarmMng::Instance()->Insert(mo, mp, no, uint8_t(type), pInfo);
  554. }
  555. break;
  556. case eZL_ALARMTYPE::SUOBI_LOCK_LIMIT:
  557. {
  558. auto pInfo = new SUOBI_OVER_LIMIT_INFO;
  559. pBaseInfo = pInfo;
  560. pInfo->no = no;
  561. pInfo->type = type;
  562. pInfo->enable = conf_obj.get<Boolean>("enable");
  563. pInfo->alarm_low_limit = conf_obj.get<Number>("alarm_low_limit");
  564. pInfo->warn_low_limit = conf_obj.get<Number>("warn_low_limit");
  565. pInfo->alarm_high_limit = conf_obj.get<Number>("alarm_high_limit");
  566. pInfo->warn_high_limit = conf_obj.get<Number>("warn_high_limit");
  567. CResistAlarmMng::Instance()->Insert(mo, mp, no, uint8_t(type), pInfo);
  568. }
  569. break;
  570. case eZL_ALARMTYPE::CONVERT_LIMIT:
  571. {
  572. auto pInfo = new CONVERT_RESIST_OVER_LIMIT;
  573. pBaseInfo = pInfo;
  574. pInfo->no = no;
  575. pInfo->type = type;
  576. pInfo->enable = conf_obj.get<Boolean>("enable");
  577. pInfo->dw_alarm_low_limit = conf_obj.get<Number>("dw_alarm_low_limit");
  578. pInfo->dw_warn_low_limit = conf_obj.get<Number>("dw_warn_low_limit");
  579. pInfo->up_alarm_high_limit = conf_obj.get<Number>("up_alarm_high_limit");
  580. pInfo->up_warn_high_limit = conf_obj.get<Number>("up_warn_high_limit");
  581. CResistAlarmMng::Instance()->Insert(mo, mp, no, uint8_t(type), pInfo);
  582. }
  583. break;
  584. default:
  585. ASSERT(0);
  586. break;
  587. }
  588. }
  589. else
  590. {//存在 对比数值
  591. switch (type)
  592. {
  593. case eZL_ALARMTYPE::MAX_OVER_LIMIT:
  594. {
  595. bool enable = false;
  596. short alarm_high_limit = MAXSHORT;
  597. short warn_high_limit = MAXSHORT;
  598. short f_alarm_high_limit = MAXSHORT;
  599. short f_warn_high_limit = MAXSHORT;
  600. size_t n = conf_array.size();
  601. for (size_t i = 0; i < n; i++)
  602. {
  603. auto obj = conf_array.get<Object>(i);
  604. auto key = obj.get<string>("name");
  605. auto value = obj.get<string>("val");
  606. if (key.compare("enable") == 0)
  607. {
  608. enable = (value.compare("true") == 0);
  609. }
  610. else if (key.compare("lock_alarm_high_limit") == 0)
  611. {
  612. alarm_high_limit = atoi(value.c_str());
  613. }
  614. else if (key.compare("lock_warn_high_limit") == 0)
  615. {
  616. warn_high_limit = atoi(value.c_str());
  617. }
  618. else if (key.compare("d_alarm_high_limit") == 0)
  619. {
  620. alarm_high_limit = atoi(value.c_str());
  621. }
  622. else if (key.compare("d_warn_high_limit") == 0)
  623. {
  624. warn_high_limit = atoi(value.c_str());
  625. }
  626. else if (key.compare("f_alarm_high_limit") == 0)
  627. {
  628. f_alarm_high_limit = atoi(value.c_str());
  629. }
  630. else if (key.compare("f_warn_high_limit") == 0)
  631. {
  632. f_warn_high_limit = atoi(value.c_str());
  633. }
  634. else if (key.compare("keep_alarm_high_limit") == 0)
  635. {
  636. f_alarm_high_limit = atoi(value.c_str());
  637. }
  638. else if (key.compare("keep_warn_high_limit") == 0)
  639. {
  640. f_warn_high_limit = atoi(value.c_str());
  641. }
  642. else
  643. {
  644. ASSERT(0);
  645. }
  646. }
  647. auto pInfo = (MAX_OVER_LIMIT_INFO*)pBaseInfo;
  648. if (enable != pInfo->enable || alarm_high_limit != pInfo->alarm_high_limit || warn_high_limit != pInfo->warn_high_limit ||
  649. f_alarm_high_limit != pInfo->f_alarm_high_limit || f_warn_high_limit != pInfo->f_warn_high_limit)
  650. {
  651. if (UpdateAlarmSetToDB(mo, mp, no, type, strConfig))
  652. {
  653. pInfo->alarm_high_limit = alarm_high_limit;
  654. pInfo->warn_high_limit = warn_high_limit;
  655. pInfo->f_alarm_high_limit = f_alarm_high_limit;
  656. pInfo->f_warn_high_limit = f_warn_high_limit;
  657. pInfo->enable = enable;
  658. }
  659. }
  660. }
  661. break;
  662. case eZL_ALARMTYPE::FRICTION_OVER_LIMIT:
  663. {
  664. bool enable = false;
  665. short up_alarm_low_limit = MAXSHORT;
  666. short up_warn_low_limit = MAXSHORT;
  667. short dw_alarm_high_limit = MAXSHORT;
  668. short dw_warn_high_limit = MAXSHORT;
  669. size_t n = conf_array.size();
  670. for (size_t i = 0; i < n; i++)
  671. {
  672. auto obj = conf_array.get<Object>(i);
  673. auto name = obj.get<string>("name");
  674. auto val = obj.get<string>("val");
  675. if (name.compare("enable") == 0)
  676. {
  677. enable = val.compare("true") == 0 ? 1 : 0;
  678. }
  679. else if (name.compare("up_alarm_low_limit") == 0)
  680. {
  681. up_alarm_low_limit = atoi(val.c_str());
  682. }
  683. else if (name.compare("up_warn_low_limit") == 0)
  684. {
  685. up_warn_low_limit = atoi(val.c_str());
  686. }
  687. else if (name.compare("dw_alarm_high_limit") == 0)
  688. {
  689. dw_alarm_high_limit = atoi(val.c_str());
  690. }
  691. else if (name.compare("dw_warn_high_limit") == 0)
  692. {
  693. dw_warn_high_limit = atoi(val.c_str());
  694. }
  695. else
  696. ASSERT(0);
  697. }
  698. auto pInfo = (FRICTION_OVER_LIMIT_INFO*)pBaseInfo;
  699. if (enable != pInfo->enable || up_alarm_low_limit != pInfo->up_alarm_low_limit || up_warn_low_limit != pInfo->up_warn_low_limit ||
  700. dw_alarm_high_limit != pInfo->dw_alarm_high_limit || dw_warn_high_limit != pInfo->dw_warn_high_limit)
  701. {
  702. if (UpdateAlarmSetToDB(mo, mp, no, type, strConfig))
  703. {
  704. pInfo->up_alarm_low_limit = up_alarm_low_limit;
  705. pInfo->up_warn_low_limit = up_warn_low_limit;
  706. pInfo->dw_alarm_high_limit = dw_alarm_high_limit;
  707. pInfo->dw_warn_high_limit = dw_warn_high_limit;
  708. pInfo->enable = enable;
  709. }
  710. }
  711. }
  712. break;
  713. case eZL_ALARMTYPE::SUOBI_LOCK_LIMIT:
  714. {
  715. auto pInfo = (SUOBI_OVER_LIMIT_INFO*)pBaseInfo;
  716. bool enable = conf_obj.get<Boolean>("enable");
  717. int alarm_low_limit = conf_obj.get<Number>("alarm_low_limit");
  718. int warn_low_limit = conf_obj.get<Number>("warn_low_limit");
  719. int alarm_high_limit = conf_obj.get<Number>("alarm_high_limit");
  720. int warn_high_limit = conf_obj.get<Number>("warn_high_limit");
  721. if (enable != pInfo->enable || alarm_low_limit != pInfo->alarm_low_limit || warn_low_limit != pInfo->warn_low_limit ||
  722. alarm_high_limit != pInfo->alarm_high_limit || warn_high_limit != pInfo->warn_high_limit)
  723. {
  724. if (UpdateAlarmSetToDB(mo, mp, no, type, strConfig))
  725. {
  726. pInfo->alarm_low_limit = alarm_low_limit;
  727. pInfo->warn_low_limit = warn_low_limit;
  728. pInfo->alarm_high_limit = alarm_high_limit;
  729. pInfo->warn_high_limit = warn_high_limit;
  730. pInfo->enable = enable;
  731. }
  732. }
  733. }
  734. break;
  735. case eZL_ALARMTYPE::CONVERT_LIMIT:
  736. {
  737. auto pInfo = (CONVERT_RESIST_OVER_LIMIT*)pBaseInfo;
  738. bool enable = conf_obj.get<Boolean>("enable");
  739. int dw_alarm_low_limit = conf_obj.get<Number>("dw_alarm_low_limit");
  740. int dw_warn_low_limit = conf_obj.get<Number>("dw_warn_low_limit");
  741. int up_alarm_high_limit = conf_obj.get<Number>("up_alarm_high_limit");
  742. int up_warn_high_limit = conf_obj.get<Number>("up_warn_high_limit");
  743. if (enable != pInfo->enable || dw_alarm_low_limit != pInfo->dw_alarm_low_limit || dw_warn_low_limit != pInfo->dw_warn_low_limit ||
  744. up_alarm_high_limit != pInfo->up_alarm_high_limit || up_warn_high_limit != pInfo->up_warn_high_limit)
  745. {
  746. if (UpdateAlarmSetToDB(mo, mp, no, type, strConfig))
  747. {
  748. pInfo->dw_alarm_low_limit = dw_alarm_low_limit;
  749. pInfo->dw_warn_low_limit = dw_warn_low_limit;
  750. pInfo->up_alarm_high_limit = up_alarm_high_limit;
  751. pInfo->up_warn_high_limit = up_warn_high_limit;
  752. pInfo->enable = enable;
  753. }
  754. }
  755. }
  756. break;
  757. default:
  758. ASSERT(0);
  759. break;
  760. }
  761. }
  762. }
  763. } while (false);
  764. HandleRecvPack(pContext, lpHead->protocol, lpHead->packno);
  765. return bRet;
  766. }
  767. BOOL CLNHandle::HandleMove(LPHJDATAHEAD2 lpHead, char* json, int json_len, CLNContext* pContext)
  768. {
  769. BOOL bRet = false;
  770. do {
  771. Array arr;
  772. arr.parse(string(json, json_len));
  773. if (arr.empty())
  774. {
  775. ASSERT(0);
  776. break;
  777. }
  778. size_t n = arr.size();
  779. CString sql;
  780. for (int i = 0; i < n; i++)
  781. {
  782. auto obj = arr.get<Object>(i);
  783. auto mo = obj.get<string>("mo");
  784. auto mp = obj.get<string>("mp");
  785. auto show_time = obj.get<string>("show_time");
  786. auto start_time = obj.get<string>("start_time");
  787. auto end_time = obj.get<string>("end_time");
  788. auto mark = obj.get<string>("mark");
  789. int curr_val = obj.get<Number>("curr_val");
  790. int show_val = obj.get<Number>("show_val");
  791. uint8_t idx = obj.get<Number>("idx");
  792. uint8_t posi = obj.get<Number>("posi");
  793. int year, month, day;
  794. auto num = sscanf_s(show_time.c_str(), "%d-%d-%d ", &year, &month, &day);
  795. auto tablename = fmt::format("rm_move_{:0>4}{:0>2}", year, month);
  796. sql += fmt::format("IF NOT EXISTS (SELECT TOP 1 * FROM {0} WHERE mo = '{1}' and mp = '{2}' and show_time = '{3}')\
  797. BEGIN\
  798. INSERT INTO {0}([mo], [mp], [show_time], [start_time], [end_time], [curr_val], [show_val], [idx], [posi], [mark])\
  799. VALUES('{1}', '{2}', '{3}', '{4}', '{5}', {6}, {7}, {8}, {9}, '{10}')\
  800. END ", tablename, mo, mp, show_time, start_time, end_time, curr_val, show_val, idx, posi, mark).c_str();
  801. }
  802. if (CDBConnectPool::Instance()->DBExecuteSQL(sql))
  803. {
  804. bRet = true;
  805. SPDLOG_INFO("{} 同步move {}条记录,语句长度:{}", pContext->GetIPAdressNew(), n, sql.GetLength());
  806. }
  807. else
  808. SPDLOG_ERROR("{} 同步move {}条记录失败!语句长度:{}", pContext->GetIPAdressNew(), n, sql.GetLength());
  809. } while (false);
  810. HandleRecvPack(pContext, lpHead->protocol, lpHead->packno);
  811. return bRet;
  812. }
  813. BOOL CLNHandle::HandleAlarmData(LPHJDATAHEAD2 lpHead, char* json, int json_len, CLNContext* pContext)
  814. {
  815. BOOL bRet = false;
  816. do {
  817. Array arr;
  818. arr.parse(string(json, json_len));
  819. if (arr.empty())
  820. {
  821. ASSERT(0);
  822. break;
  823. }
  824. const OPT_TYPE opt_type = lpHead->datainfo.opt;
  825. size_t n = arr.size();
  826. CString sql;
  827. ALARM_INFO* pInfo = nullptr;
  828. for (int i = 0; i < n; i++)
  829. {
  830. auto obj = arr.get<Object>(i);
  831. auto event_id = obj.get<string>("event_id");
  832. if (opt_type == OPT_TYPE::OPT_ADD)
  833. {
  834. pInfo = new ALARM_INFO;
  835. pInfo->event_id = event_id;
  836. auto pResistServer = CResistAlarmMng::Instance();
  837. lock_guard<mutex> lock(pResistServer->m_mtxAlarm);
  838. pResistServer->m_lstUnConfirmAlarm.push_back(pInfo);
  839. }
  840. else
  841. {
  842. //TODO
  843. continue;
  844. }
  845. pInfo->id = obj.get<Number>("id");
  846. pInfo->mo = obj.get<string>("mo");
  847. pInfo->mp = obj.get<string>("mp");
  848. pInfo->no = obj.get<Number>("no");
  849. pInfo->type = eZL_ALARMTYPE(obj.get<Number>("type"));
  850. pInfo->level = obj.get<Number>("level");
  851. auto alarm_time = obj.get<string>("time");
  852. //int year, month, day, hour, min, second;
  853. //auto num = sscanf_s(alarm_time.c_str(), "%d-%d-%d %d:%d:%d", &year, &month, &day, &hour, &min, &second);
  854. pInfo->desc = obj.get<string>("desc");
  855. pInfo->suggest = obj.get<string>("suggest");
  856. pInfo->val = obj.get<Number>("val");
  857. pInfo->ack_result = obj.get<Number>("ack_result");
  858. pInfo->ack_name = obj.get<string>("ack_name");
  859. pInfo->ack_time = obj.get<Number>("ack_time");
  860. pInfo->rel_id = obj.get<string>("rel_id");
  861. CString ss;
  862. if (opt_type == OPT_TYPE::OPT_ADD)
  863. {
  864. ss.Format("INSERT INTO [rm_alarm]([ID],[mo],[mp],[no],[type],[occur_time],[level],[desc],[suggest],[val],[event_id],[rel_id]) "\
  865. "VALUES(%d, '%s', '%s', %d, %d, '%s', %d, '%s', '%s', %d, '%s', '%s');",
  866. pInfo->id, pInfo->mo.c_str(), pInfo->mp.c_str(), pInfo->no, pInfo->type,
  867. alarm_time.c_str(), pInfo->level, pInfo->desc.c_str(), pInfo->suggest.c_str(), pInfo->val,
  868. pInfo->event_id.c_str(), pInfo->rel_id.c_str());
  869. sql += ss;
  870. }
  871. }
  872. if (CDBConnectPool::Instance()->DBExecuteSQL(sql))
  873. {
  874. bRet = true;
  875. SPDLOG_INFO("{} 新增 alarm {}条记录,语句长度:{}", pContext->GetIPAdressNew(), n, sql.GetLength());
  876. }
  877. else
  878. SPDLOG_ERROR("{} 新增 alarm {}条记录失败!语句长度:{}", pContext->GetIPAdressNew(), n, sql.GetLength());
  879. } while (false);
  880. HandleRecvPack(pContext, lpHead->protocol, lpHead->packno);
  881. return bRet;
  882. }
  883. void CLNHandle::CompareMoSync(jsonxx::Object obj, CMonitorObject *pObject)
  884. {
  885. using namespace jsonxx;
  886. auto id = obj.get<string>("id");
  887. auto name = obj.get<string>("name");
  888. auto type = obj.get<string>("type");
  889. auto up = obj.get<string>("up");
  890. ASSERT(up.compare(pObject->id) == 0);
  891. bool bHave = false;
  892. CMonitorObject* pObj = nullptr;
  893. for (auto& it : pObject->m_lstMo)
  894. {
  895. if (it->id.compare(id) == 0)
  896. {
  897. bHave = true;
  898. if (name.compare(it->name) != 0) //修改名称
  899. {
  900. CMonitorObjectMng::ReNameMO(id, name);
  901. it->name = name;
  902. }
  903. pObj = it;
  904. break;
  905. }
  906. }
  907. if (!bHave)
  908. {
  909. if (type.compare("mo.mp") == 0)
  910. CMonitorObjectMng::AddMO2(id, name, type, up);
  911. else
  912. CMonitorObjectMng::AddMO(id, name, type, up);
  913. pObj = new CMonitorObject;
  914. pObj->id = id;
  915. pObj->name = name;
  916. pObj->type = type;
  917. pObj->up = up;
  918. pObject->m_lstMo.push_back(pObj);
  919. }
  920. if (!obj.has<Array>("child"))
  921. return;
  922. auto child = obj.get<jsonxx::Array>("child");
  923. auto n = child.size();
  924. for (int i = 0; i < n; i++)
  925. {
  926. auto o = child.get<Object>(i);
  927. CompareMoSync(o, pObj);
  928. }
  929. }
  930. void CLNHandle::CompareMpSync(jsonxx::Object obj)
  931. {
  932. auto mo = obj.get<string>("mo");
  933. auto mp = obj.get<string>("mp");
  934. auto name1 = obj.get<string>("name1");
  935. auto name2 = obj.get<string>("name2");
  936. auto name3 = obj.get<string>("name3");
  937. auto direct1 = obj.get<string>("direct1");
  938. auto direct2 = obj.get<string>("direct2");
  939. auto station = obj.get<string>("station");
  940. auto mo_name = obj.get<string>("mo_name");
  941. auto mp_name = obj.get<string>("mp_name");
  942. //auto taskid = fmt::format("{}.{}.{}", station, mo, mp);
  943. auto taskid = fmt::format("{}.{}", mo, mp);
  944. auto pDevice = CDeviceMng::Instance()->Find(taskid);
  945. if (pDevice)
  946. {
  947. if (pDevice->name1.compare(name1) == 0 && pDevice->name2.compare(name2) == 0 && pDevice->name3.compare("name3")
  948. && pDevice->direct1.compare(direct1) == 0 && pDevice->direct2.compare(direct2) == 0)
  949. int ii = 0;
  950. else
  951. {
  952. //update
  953. CString sql = fmt::format("UPDATE rm_map SET [name1]='{}', [name2]='{}',[name3]='{}',[direct1]='{}',[direct2]='{}' WHERE [mo]='{}' AND [mp]='{}';",
  954. name1, name2, name3, direct1, direct2, mo, mp).c_str();
  955. if (!CDBConnectPool::Instance()->DBExecuteSQL(sql))
  956. {
  957. SPDLOG_ERROR("语句执行错误:{}", sql);
  958. }
  959. else
  960. {
  961. pDevice->name1 = name1;
  962. pDevice->name2 = name2;
  963. pDevice->name3 = name3;
  964. pDevice->direct1 = direct1;
  965. pDevice->direct2 = direct2;
  966. pDevice->mo_name = mo_name;
  967. pDevice->mp_name = mp_name;
  968. }
  969. }
  970. }
  971. else
  972. {
  973. //new
  974. CString sql = fmt::format("INSERT INTO [rm_map] ([mo],[mp],[name1],[name2],[name3],[direct1],[direct2]) VALUES('{}','{}','{}','{}','{}','{}','{}');",
  975. mo, mp, name1, name2, name3, direct1, direct2).c_str();
  976. if (!CDBConnectPool::Instance()->DBExecuteSQL(sql))
  977. {
  978. SPDLOG_ERROR("语句执行错误:{}", sql);
  979. }
  980. //else //即使数据库执行失败,内存还是更新, 以便后面实时数据
  981. {
  982. pDevice = new CDevice(taskid, station, mo, mp);
  983. CDeviceMng::Instance()->Insert(pDevice);
  984. pDevice->name1 = name1;
  985. pDevice->name2 = name2;
  986. pDevice->name3 = name3;
  987. pDevice->direct1 = direct1;
  988. pDevice->direct2 = direct2;
  989. pDevice->mo_name = mo_name;
  990. pDevice->mp_name = mp_name;
  991. }
  992. }
  993. }
  994. BOOL CLNHandle::HandleRecvPack(CLNContext* pContext, E_ZL_PROTOCAL protocal, uint32_t packno)
  995. {
  996. uint8_t bSend[100] = { 0 };
  997. auto len = CHjDataConver::conver_sendpack(bSend, nullptr, 0, 0, packno, protocal, OR_DATA_INFO(0, 1, 1, 3, OPT_TYPE::OPT_RECV));
  998. auto ret = pContext->Send(bSend, len) != SOCKET_ERROR;
  999. //if (ret)
  1000. // SPDLOG_INFO("packno:{} send", packno);
  1001. //else
  1002. // SPDLOG_INFO("packno:{} send fail", packno);
  1003. return ret;
  1004. }