module_meta_date_changed.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. #include "module_meta_date_changed.h"
  2. #include"area_business_person_attendance.h"
  3. #include"area_business_car_attendance.h"
  4. #include"common_tool.h"
  5. #include "websocket/wsClientMgr.h"
  6. #include"db/db_api/CDBSingletonDefine.h"
  7. #include"event.h"
  8. #include"ant.h"
  9. #include"card.h"
  10. #include"area.h"
  11. #include "forbid_staff_down_mine.h"
  12. #include "landmark.h"
  13. #include <three_rates.h>
  14. #include"area_business_geofault.h"
  15. #include <boost/format.hpp>
  16. #include <boost/tokenizer.hpp>
  17. #include <boost/algorithm/string/split.hpp>
  18. #include <boost/algorithm/string.hpp>
  19. #include <card_path.h>
  20. #include "ya_setting.h"
  21. ///基础数据
  22. void module_meta_date_changed::accept(sio::message::ptr const& data)
  23. {
  24. std::string name="";
  25. if(!tool_map::try_get_value(name, JSON_KEY_NAME, data))
  26. {
  27. log_error("web发来的数据: 基础数据找不到name字段");
  28. return;
  29. }
  30. std::string szParam = "0";
  31. tool_map::try_get_value(szParam,JSON_KEY_ID,data);
  32. // int id=-1;
  33. // tool_map::try_get_value(id,JSON_KEY_ID,data);
  34. std::string op_type="";
  35. tool_map::try_get_value(op_type, JSON_KEY_OP_TYPE, data);
  36. log_info("web发来数据:cmd=meta_data_changed.name:%s Param:%s OpType:%s",name.c_str(),szParam.c_str(),op_type.c_str());
  37. if(!szParam.empty() && !op_type.empty())
  38. {
  39. EDIT_TYPE_ID edit_type_id;
  40. if(!try_get_edit_type_id(op_type, edit_type_id))
  41. {
  42. log_error("web发来的数据: 基础数据op_type字段错误:op_type=%s", op_type.c_str());
  43. return;
  44. }
  45. if(JSON_KEY_NAME_VEHICLE == name || JSON_KEY_NAME_VEHICLE_EXTEND == name)
  46. {
  47. deal_call_edit_vehicle_or_staff(szParam, edit_type_id);
  48. }
  49. else if(JSON_KEY_NAME_STAFF == name || JSON_KEY_NAME_STAFF_EXTEND == name)
  50. {
  51. deal_call_edit_vehicle_or_staff(szParam, edit_type_id);
  52. }
  53. else if(JSON_KEY_NAME_CARD == name)
  54. {
  55. deal_call_edit_card(szParam, edit_type_id);
  56. }
  57. else if(JSON_KEY_NAME_AREA == name)
  58. {
  59. deal_call_edit_area(szParam, edit_type_id);
  60. }
  61. else if(JSON_KEY_NAME_READER == name)
  62. {
  63. int id = std::stoi(szParam);
  64. deal_call_edit_reader(id, edit_type_id);
  65. }
  66. else if ("antenna" == name)
  67. {
  68. int id = std::stoi(szParam);
  69. deal_call_edit_antenna(id,edit_type_id);
  70. }
  71. else if(JSON_KEY_NAME_PATH == name)
  72. {
  73. int id = std::stoi(szParam);
  74. deal_call_edit_path(id, edit_type_id);
  75. }
  76. else if(JSON_KEY_NAME_MAP == name || JSON_KEY_NAME_MAP_GIS == name)
  77. {
  78. int id = std::stoi(szParam);
  79. deal_call_edit_map(id, edit_type_id);
  80. }
  81. else if (JSON_KEY_NAME_LIGHT == name)
  82. {
  83. int id = std::stoi(szParam);
  84. deal_call_edit_light(id,edit_type_id);///待实现
  85. }
  86. else if ("lights_group" == name)
  87. {
  88. int id = std::stoi(szParam);
  89. deal_call_edit_lights_group(id,edit_type_id);///待实现
  90. }
  91. else if (JSON_KEY_NAME_FORBID_PERSON_DOWN_MINE == name)
  92. {
  93. deal_call_edit_forbid_person_down_mine(szParam,edit_type_id);
  94. }
  95. else if (JSON_KEY_NAME_PERSONS_DYNAMIC_THRE == name)
  96. {
  97. int id = std::stoi(szParam);
  98. deal_call_edit_persons_dynamic_thre(id,edit_type_id);
  99. }
  100. else if (JSON_KEY_NAME_GEO_FAULT == name)//地址断层更新
  101. {
  102. area_business_geofault::init_geofault_from_db();
  103. }
  104. else if (JSON_KEY_NAME_LANDMARK == name)//地标信息更新
  105. {
  106. deal_call_edit_landmark(szParam, edit_type_id);
  107. }
  108. else if (JSON_KEY_NAME_COALFACE==name|| JSON_KEY_NAME_COALFACE_VEHICLE == name ||
  109. JSON_KEY_NAME_DRIVING_FACE == name || JSON_KEY_NAME_DRIVINGFACE_VEHICLE == name )
  110. {
  111. three_rates::get_instance()->update_db_data(name, szParam, edit_type_id);
  112. }
  113. else
  114. {
  115. log_error("web发来的数据: 基础数据name字段错误:name=%s", name.c_str());
  116. }
  117. }
  118. else
  119. {
  120. if(JSON_KEY_NAME_SETTING == name)
  121. {
  122. //阈值限制接口
  123. init_setting(); ///待实现
  124. }
  125. else
  126. {
  127. log_error("web发来的数据: 基础数据name字段错误:name=%s", name.c_str());
  128. }
  129. }
  130. }
  131. ///3.清除卡相关信息,区域相关,分站相关,考勤相关,清除定时器,
  132. ///速度,状态 呼救 呼叫 告警相关。即保留基础信息,其他的重置。
  133. void module_meta_date_changed::clear_card(const std::shared_ptr<card_location_base>& card_ptr)
  134. {
  135. card_ptr->get_area_tool()->on_leave(card_ptr);
  136. }
  137. /*
  138. * 修改车及卡的数据
  139. * id64 = ;员工ID或者车ID;卡ID=101;0010000001198 分号间隔
  140. */
  141. void module_meta_date_changed::deal_call_edit_vehicle_or_staff(const std::string & id64, EDIT_TYPE_ID edit_type_id)
  142. {
  143. std::vector<std::string> vecSegTag;
  144. boost::split(vecSegTag, id64, boost::is_any_of(";"));
  145. if (vecSegTag.size() == 1) //数据发生错误
  146. {
  147. log_errno("Web Send Data Error!(%s)", id64.c_str());
  148. return;
  149. }
  150. std::string lsz_card_id = vecSegTag[1];
  151. int cid = std::stoi(vecSegTag[0].c_str());
  152. if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
  153. {
  154. if (ET_UPDATE == edit_type_id)
  155. {
  156. auto c = card_list::instance()->get_card_by_cid(cid);
  157. if (nullptr != c && tool_other::type_id_to_str(c->m_type,c->m_id) != lsz_card_id)
  158. {
  159. //如果修改了卡号,则删除原来的卡的数据
  160. remove_card(c);
  161. }
  162. }
  163. int c_type = tool_other::id64_to_type(lsz_card_id);
  164. if (tool_other::is_vehicle(c_type))
  165. {
  166. card_list::instance()->init_vehicle(lsz_card_id);
  167. }
  168. else if (tool_other::is_person(c_type))
  169. {
  170. card_list::instance()->init_staffer(lsz_card_id);
  171. }
  172. }
  173. else
  174. {
  175. if(!lsz_card_id.empty())
  176. remove_card(tool_other::id64_to_id(lsz_card_id), tool_other::id64_to_type(lsz_card_id));
  177. }
  178. }
  179. void module_meta_date_changed::deal_call_edit_card(std::string & id64, EDIT_TYPE_ID edit_type_id)
  180. {
  181. std::string card_id64_str = tool_other::to13str(id64);
  182. int type = tool_other::id64_to_type(card_id64_str);
  183. if(tool_other::is_person(type) || tool_other::is_vehicle(type))
  184. {
  185. auto c = card_list::instance()->get(tool_other::card_id_to_u64(card_id64_str));
  186. if (nullptr == c) {
  187. log_info("web edit card:%s Not bind staff or vehicle. editType:%d", card_id64_str.c_str(), edit_type_id);
  188. return ;
  189. }
  190. std::string lsz = std::to_string(c->m_cid) + ";" + card_id64_str;
  191. deal_call_edit_vehicle_or_staff(lsz,edit_type_id);
  192. }
  193. else
  194. {
  195. log_error("基础数据 删除卡type不对:type=%d", type);
  196. }
  197. }
  198. void module_meta_date_changed::deal_call_edit_area(const std::string& id,EDIT_TYPE_ID edit_type_id)
  199. {
  200. int cid = std::stoi(id);
  201. if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
  202. {
  203. area_list::instance()->init_from_db(cid);
  204. }
  205. else if(ET_DELETE == edit_type_id)
  206. {
  207. if(auto area_ptr = area_list::instance()->get(cid))
  208. {
  209. log_info("区域删除:areaid=%d", cid);
  210. area_ptr->clear();
  211. area_list::instance()->remove(cid);
  212. }
  213. }
  214. }
  215. void module_meta_date_changed::deal_call_edit_reader(int id, EDIT_TYPE_ID edit_type_id)
  216. {
  217. if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
  218. {
  219. sit_list::instance()->init_site(id);
  220. }
  221. else if(ET_DELETE == edit_type_id)
  222. {
  223. sit_list::instance()->remove(id);
  224. card_path::init();
  225. }
  226. }
  227. void module_meta_date_changed::deal_call_edit_antenna(int id,EDIT_TYPE_ID edit_type_id)
  228. {
  229. if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
  230. {
  231. sit_list::instance()->read_sit_list(id);
  232. }
  233. //else if(ET_DELETE == edit_type_id)
  234. //{
  235. //delete_antenna(id);
  236. // }
  237. }
  238. void module_meta_date_changed::deal_call_edit_path(int id, EDIT_TYPE_ID edit_type_id)
  239. {
  240. // if(ET_INSERT == edit_type_id)
  241. // {
  242. // log_error("path不支持增加操作");
  243. // std_debug("path不支持增加操作");
  244. // }
  245. // else if(ET_UPDATE == edit_type_id)
  246. // {
  247. // }
  248. if(sit_list::instance()->get(id))
  249. sit_list::instance()->read_ant_path(id);
  250. }
  251. void module_meta_date_changed::deal_call_edit_map(int id, EDIT_TYPE_ID edit_type_id)
  252. {
  253. if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
  254. {
  255. if(!is_cur_map(id))
  256. {
  257. log_info("修改的不是当前使用的地图,要修改地图id=%d,当前使用地图id=%d", id, cur_map_id());
  258. return;
  259. }
  260. update_map_info(id);
  261. }
  262. else if(ET_DELETE == edit_type_id)
  263. {
  264. if(is_cur_map(id))
  265. {
  266. log_error("删除了当前使用的地图");
  267. return;
  268. }
  269. }
  270. }
  271. void module_meta_date_changed::deal_call_edit_light(int id, EDIT_TYPE_ID edit_type_id)
  272. {
  273. if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
  274. {
  275. }
  276. else if(ET_DELETE == edit_type_id)
  277. {
  278. }
  279. }
  280. void module_meta_date_changed::deal_call_edit_lights_group(int id, EDIT_TYPE_ID edit_type_id)
  281. {
  282. if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
  283. {
  284. }
  285. else if(ET_DELETE == edit_type_id)
  286. {
  287. }
  288. }
  289. // 禁止指定人员下井 id = (rt_person_forbid_down_mine)数据库中自增长ID
  290. void module_meta_date_changed::deal_call_edit_forbid_person_down_mine(const std::string & lszId,EDIT_TYPE_ID edit_type_id)
  291. {
  292. std::vector<std::string> vecSegTag;
  293. boost::split(vecSegTag, lszId, boost::is_any_of(";"));
  294. if (vecSegTag.size() == 1) //数据发生错误
  295. {
  296. log_errno("Web Send Data Error!(%s)", lszId.c_str());
  297. return;
  298. }
  299. int db_id = std::stoi(vecSegTag[0].c_str());
  300. int staff_id = std::stoi(vecSegTag[1].c_str());
  301. if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
  302. {
  303. forbid_staff_down_mine::instance()->init_forbid_staff(db_id,edit_type_id);
  304. }
  305. else if(ET_DELETE == edit_type_id)
  306. {
  307. forbid_staff_down_mine::instance()->del_forbid_data(db_id,staff_id);
  308. }
  309. }
  310. // 设置区域中时间段人员超员阈值等数据
  311. void module_meta_date_changed::deal_call_edit_persons_dynamic_thre(int area_id,EDIT_TYPE_ID edit_type_id)
  312. {
  313. area_list::instance()->init_area_persons_dynamic_thre_from_db(area_id);
  314. }
  315. // 修改地标信息
  316. void module_meta_date_changed::deal_call_edit_landmark(const std::string & landmarkid, EDIT_TYPE_ID edit_type_id)
  317. {
  318. int id = atoi(landmarkid.c_str());
  319. if (ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
  320. {
  321. Landmark_list::instance()->init_landmarkInfo(id);
  322. }
  323. else if (ET_DELETE == edit_type_id)
  324. {
  325. Landmark_list::instance()->remove(id);
  326. }
  327. }
  328. void module_meta_date_changed::init_setting()
  329. {
  330. CYaSetting::Init_sys_setting();
  331. }
  332. void module_meta_date_changed::remove_card(uint32_t id, int32_t type) {
  333. uint64_t card_id = tool_other::type_id_to_u64(type, id);
  334. auto card_ptr = card_list::instance()->get(card_id);
  335. if (!card_ptr) {
  336. log_error("基础数据, 在全局列表中删除卡,全局列表中已经不存在此卡, id=%d, type=%d", id, type);
  337. return;
  338. }
  339. remove_card(card_ptr);
  340. }
  341. void module_meta_date_changed::remove_card(std::shared_ptr<card_location_base> card_ptr)
  342. {
  343. if (!card_ptr)
  344. {
  345. return;
  346. }
  347. log_info("基础数据, 在全局列表中删除卡成功, id=%d, type=%d",card_ptr->m_type, card_ptr->m_id);
  348. // auto area_hover_ptr = card_ptr->get_area_hover();
  349. // if(area_hover_ptr && 0!=area_hover_ptr->id() && 0!=area_hover_ptr->mapid())
  350. // {
  351. // module_area::on_leave(card_ptr->m_id, area_hover_ptr, card_ptr->m_type);
  352. // }
  353. // if(card_ptr->is_person())
  354. // {
  355. // module_attendance_person::up_mine(card_ptr, nullptr);
  356. // }
  357. // else
  358. // {
  359. // module_attendance_vehicle::save_attendance(card_ptr, nullptr);
  360. // module_meta_date_changed::clear_card(card_ptr);
  361. // }
  362. module_meta_date_changed::clear_card(card_ptr);
  363. // 避免状态重置
  364. uint64_t card_id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
  365. card_list::instance()->remove(card_id);
  366. }
  367. bool module_meta_date_changed::try_get_edit_type_id(const std::string& op_type, EDIT_TYPE_ID& out_edit_type_id)
  368. {
  369. if(JSON_KEY_OP_TYPE_UPDATE == op_type)
  370. {
  371. out_edit_type_id = ET_UPDATE;
  372. }
  373. else if(JSON_KEY_OP_TYPE_DELETE == op_type)
  374. {
  375. out_edit_type_id = ET_DELETE;
  376. }
  377. else if(JSON_KEY_OP_TYPE_INSERT == op_type)
  378. {
  379. out_edit_type_id = ET_INSERT;
  380. }
  381. else
  382. {
  383. return false;
  384. }
  385. return true;
  386. }
  387. ///删除区域所有报警信息
  388. //void module_meta_date_changed::delete_area_event(std::shared_ptr<area> area_ptr)
  389. //{
  390. // for(int i=0; i < CARD_EVENT_COUNT_MAX; i++ )
  391. // {
  392. // event_tool::instance()->handle_event(OT_AREA, static_cast<EVENT_TYPE>(i), area_ptr->id(), 0, 0, false);
  393. // }
  394. //}
  395. //void module_meta_date_changed::delete_antenna(int id)
  396. //{
  397. // int sitid=-8;
  398. // auto map = sit_list::instance()->m_map;
  399. // for(auto&it:map)
  400. // {
  401. // auto sit_ptr = it.second;
  402. // if(sit_ptr->m_ant[0].m_id == id)
  403. // {
  404. // sitid=sit_ptr->m_id;
  405. // sit_ptr->delete_antenna(0);
  406. // break;
  407. // }
  408. // if(sit_ptr->m_ant[1].m_id == id)
  409. // {
  410. // sitid=sit_ptr->m_id;
  411. // sit_ptr->delete_antenna(1);
  412. // break;
  413. // }
  414. // }
  415. //
  416. // if(sitid==-8)
  417. // {
  418. // std_debug("天线已经删除了,在分站列表中找不到该天线:天线id=%d", id);
  419. // log_info("天线已经删除了,在分站列表中找不到该天线:天线id=%d", id);
  420. // }
  421. // else
  422. // {
  423. // std_debug("删除天线成功:天线id=%d,分站id=%d", id, sitid);
  424. // log_info("删除天线成功:天线id=%d,分站id=%d", id, sitid);
  425. // }
  426. //}
  427. //
  428. bool module_meta_date_changed::is_cur_map(int id)
  429. {
  430. return cur_map_id()==id;
  431. }
  432. int module_meta_date_changed::cur_map_id()
  433. {
  434. auto tmp = area_list::instance()->m_map;
  435. for(auto&it:tmp)
  436. {
  437. if(0!=it.second->m_mapid)
  438. {
  439. return it.second->m_mapid;
  440. }
  441. }
  442. return -1;
  443. }
  444. void module_meta_date_changed::update_map_info(int id)
  445. {
  446. std::string sql = "SELECT scale FROM dat_map WHERE map_id=";
  447. sql.append(std::to_string(id));
  448. sql.append(";");
  449. std_debug("修改地图 sql=%s", sql.c_str());
  450. log_info("修改地图 sql=%s", sql.c_str());
  451. std::string Error;
  452. YADB::CDBResultSet DBRes;
  453. sDBConnPool.Query(sql.c_str(),DBRes,Error);
  454. int nCount = DBRes.GetRecordCount( Error );
  455. if (nCount < 1)
  456. {
  457. log_error("修改地图失败,数据库中找不到: map_id=%d", id);
  458. return ;
  459. }
  460. double scale = 0;
  461. if (DBRes.GetNextRecod(Error))
  462. {
  463. DBRes.GetField("scale", scale, Error);
  464. }
  465. if (scale < 1e-4)
  466. {
  467. log_error("修改地图,数据库地图比例尺错误: map_id=%d,scale=%.2f", id,scale);
  468. return;
  469. }
  470. auto area = area_list::instance()->m_map;
  471. for(auto& it : area)
  472. {
  473. it.second->m_scale = scale;
  474. }
  475. auto site = sit_list::instance()->m_map;
  476. for(auto& it : site)
  477. {
  478. it.second->m_scale = scale;
  479. }
  480. }