module_meta_date_changed.cpp 14 KB

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