1
0

module_meta_date_changed.cpp 14 KB

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