ComprehensiveAlarmController.class.php.bak.2021-08-02 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. class ComprehensiveAlarmController extends ComController
  5. {
  6. //综合告警各类型数据统计
  7. public function getAlarmStatistics()
  8. {
  9. $Date = I();
  10. $company_code = $Date['company_code'];
  11. if (empty($company_code)) {
  12. $res['msg'] = '操作失败,缺少关键参数company_code';
  13. $res['flag'] = false;
  14. echo json_encode($res);
  15. exit();
  16. }
  17. $device_list = $this->getDeviceCode($company_code);
  18. $device_list1 = $this->getDeviceCode1($company_code);
  19. if (!empty($device_list)){
  20. //报警主机未处理数量统计
  21. $untreated_alarm_host_count = M()->query("select count(*) as untreated_alarm_host_count from sp_hj2017 where clzt=0 and device_code in(" . $device_list . ")");
  22. //消防水未处理数量统计
  23. $untreated_fire_water_count1 = M()->query("select count(*) as untreated_fire_water_count from sp_sj2017 where clzt=0 and device_code in(" . $device_list . ")");
  24. $untreated_fire_water_count = (int)$untreated_fire_water_count1[0]['untreated_fire_water_count'] - (int)$untreated_fire_hydrant_count[0]['untreated_fire_hydrant_count'];
  25. //电气火灾未处理数量统计
  26. $untreated_electrical_fire_count = M()->query("select count(*) as untreated_electrical_fire_count from sp_ef2017 where clzt=0 and device_code in(" . $device_list . ")");
  27. //视频监测未处理数量统计
  28. $untreated_video_monitoring_count = M()->query("select count(*) as untreated_video_monitoring_count from sp_video2017 where clzt=0 and device_code in(" . $device_list . ")");
  29. //井盖未处理数量统计
  30. $untreated_manhole_cover_count = M()->query("select count(*) as untreated_manhole_cover_count from sp_iw2017 where clzt=0 and device_code in(" . $device_list . ")");
  31. //门禁未处理数量统计
  32. $untreated_door_count = M()->query("select count(*) as untreated_door_count from sp_door2020 where clzt=0 and device_code in(" . $device_list . ")");
  33. //可燃气体未处理数量统计
  34. $untreated_gas_count = M()->query("select count(*) as untreated_gas_count from sp_gas2020 where clzt=0 and device_code in(" . $device_list . ")");
  35. //地磁未处理数量统计
  36. $untreated_geomagnetism_count = M()->query("select count(*) as untreated_geomagnetism_count from sp_dc2020 where clzt=0 and device_code in(" . $device_list . ")");
  37. //RTU未处理数量统计
  38. $untreated_rtu_count = M()->query("select count(*) as untreated_rtu_count from sp_rtu2017 where clzt=0 and device_code in(" . $device_list . ")");
  39. //电梯未处理数量统计
  40. $untreated_elevator_count = M()->query("select count(*) as untreated_elevator_count from sp_lifter2017 where clzt=0 and device_code in(" . $device_list . ")");
  41. $data[0]['untreated_alarm_host_count'] = (int)$untreated_alarm_host_count[0]['untreated_alarm_host_count'];
  42. $data[0]['untreated_fire_water_count'] = (int)$untreated_fire_water_count;
  43. $data[0]['untreated_electrical_fire_count'] = (int)$untreated_electrical_fire_count[0]['untreated_electrical_fire_count'];
  44. $data[0]['untreated_video_monitoring_count'] = (int)$untreated_video_monitoring_count[0]['untreated_video_monitoring_count'];
  45. $data[0]['untreated_manhole_cover_count'] = (int)$untreated_manhole_cover_count[0]['untreated_manhole_cover_count'];
  46. $data[0]['untreated_door_count'] = (int)$untreated_door_count[0]['untreated_door_count'];
  47. $data[0]['untreated_gas_count'] = (int)$untreated_gas_count[0]['untreated_gas_count'];
  48. $data[0]['untreated_geomagnetism_count'] = (int)$untreated_geomagnetism_count[0]['untreated_geomagnetism_count'];
  49. $data[0]['untreated_rtu_count'] = (int)$untreated_rtu_count[0]['untreated_rtu_count'];
  50. $data[0]['untreated_elevator_count'] = (int)$untreated_elevator_count[0]['untreated_elevator_count'];
  51. }else{
  52. $data[0]['untreated_alarm_host_count'] = 0;
  53. $data[0]['untreated_fire_water_count'] = 0;
  54. $data[0]['untreated_electrical_fire_count'] = 0;
  55. $data[0]['untreated_video_monitoring_count'] = 0;
  56. $data[0]['untreated_manhole_cover_count'] = 0;
  57. $data[0]['untreated_door_count'] = 0;
  58. $data[0]['untreated_gas_count'] = 0;
  59. $data[0]['untreated_geomagnetism_count'] = 0;
  60. $data[0]['untreated_rtu_count'] = 0;
  61. $data[0]['untreated_elevator_count'] = 0;
  62. }
  63. if (!empty($device_list1)){
  64. //消火栓未处理统计
  65. $untreated_fire_hydrant_count = M()->query("select count(*) as untreated_fire_hydrant_count from sp_sj2017 where clzt=0 and device_code in(" . $device_list1 . ")");
  66. $data[0]['untreated_fire_hydrant_count'] = (int)$untreated_fire_hydrant_count[0]['untreated_fire_hydrant_count'];
  67. }else{
  68. $data[0]['untreated_fire_hydrant_count'] = 0;
  69. }
  70. $data[0]['company_code'] = $company_code;
  71. $res['msg'] = '操作成功';
  72. $res['flag'] = true;
  73. $res['data'] = $data;
  74. echo json_encode($res);
  75. }
  76. public function getIntegratedAlarmList()
  77. {
  78. $Date = I();
  79. $company_code = $Date['company_code'];
  80. $type = $Date['type'];
  81. $processing_status = $Date['processing_status'];
  82. if (empty($company_code) && empty($type) && empty($processing_status)) {
  83. $res['msg'] = '操作失败,缺少关键参数';
  84. $res['flag'] = false;
  85. echo json_encode($res);
  86. exit();
  87. }
  88. switch ($type) {
  89. case '1'://烟感和报警主机
  90. $table = 'sp_hj2017';
  91. $types = '1,3';
  92. break;
  93. case '2'://水表和液位
  94. $table = 'sp_sj2017';
  95. $types = '2,5';
  96. break;
  97. case '4'://消防栓
  98. $table = 'sp_sj2017';
  99. $types = $type;
  100. break;
  101. case '6'://RTU
  102. $table = 'sp_rtu2017';
  103. $types = $type;
  104. break;
  105. case '7'://电气火灾
  106. $table = 'sp_ef2017';
  107. $types = $type;
  108. break;
  109. case '16'://视频监测
  110. $table = 'sp_video2017';
  111. $types = $type;
  112. break;
  113. case '17'://电梯监测
  114. $table = 'sp_lifter2017';
  115. $types = $type;
  116. break;
  117. case '128'://井盖
  118. $table = 'sp_iw2017';
  119. $types = $type;
  120. break;
  121. case '129'://地磁
  122. $table = 'sp_dc2020';
  123. $types = $type;
  124. break;
  125. case '130'://门禁
  126. $table = 'sp_door2020';
  127. $types = $type;
  128. break;
  129. case '131'://可燃气体
  130. $table = 'sp_gas2020';
  131. $types = $type;
  132. break;
  133. default:
  134. $res['msg'] = '操作失败,设备类型尚未定义,请联系管理员';
  135. $res['flag'] = 3002;
  136. echo json_encode($res);
  137. exit();
  138. break;
  139. }
  140. $alarm_count = M()->query("SELECT count(*) as alarm_count FROM " . $table . " AS a JOIN sp_owner AS b ON a.device_code=b.owner_code WHERE b.dwtype in(" . $types . ") AND b.company='" . $company_code . "' AND clzt=" . $processing_status);
  141. $alarm_list = M()->query("SELECT a.id,a.device_code,a.time,a.data1,a.data4,a.data2,a.clzt,b.company AS company_code,b.owner_name,b.unitinfo,b.dwtype as type FROM " . $table . " AS a JOIN sp_owner AS b ON a.device_code=b.owner_code WHERE b.dwtype in(" . $types . ") AND b.company='" . $company_code . "' AND clzt=" . $processing_status . " ORDER BY time DESC LIMIT 1000");
  142. if ($type == 2 || $type == 4) {
  143. foreach ($alarm_list as $key => $value) {
  144. switch ($alarm_list[$key]['data1']) {
  145. case 'WP1':
  146. $alarm_list[$key]['data4'] = '低压';
  147. break;
  148. case 'WP2':
  149. $alarm_list[$key]['data4'] = '高压';
  150. break;
  151. case 'WP3':
  152. $alarm_list[$key]['data4'] = '故障';
  153. break;
  154. case 'WP4':
  155. $alarm_list[$key]['data4'] = '离线';
  156. break;
  157. case 'LL1':
  158. $alarm_list[$key]['data4'] = '低水位';
  159. break;
  160. case 'LL2':
  161. $alarm_list[$key]['data4'] = '高水位';
  162. break;
  163. default:
  164. $alarm_list[$key]['data4'] = '其他' . $alarm_list[$key]['data1'];
  165. break;
  166. }
  167. }
  168. } else if ($type == 7) {
  169. foreach ($alarm_list as $key => $value) {
  170. if ($alarm_list[$key]['data1'] == 'EF1') {
  171. $alarm_list[$key]['data4'] = '欠压报警';
  172. } elseif ($alarm_list[$key]['data1'] == 'EF2') {
  173. $alarm_list[$key]['data4'] = '过压报警';
  174. } elseif ($alarm_list[$key]['data1'] == 'EF3') {
  175. $alarm_list[$key]['data4'] = '过流报警';
  176. } elseif ($alarm_list[$key]['data1'] == 'EF4') {
  177. $alarm_list[$key]['data4'] = '漏电报警';
  178. } elseif ($alarm_list[$key]['data1'] == 'EF5') {
  179. $alarm_list[$key]['data4'] = '回路1温度超限报警';
  180. } elseif ($alarm_list[$key]['data1'] == 'EF6') {
  181. $alarm_list[$key]['data4'] = '回路2温度超限报警';
  182. } elseif ($alarm_list[$key]['data1'] == 'EF7') {
  183. $alarm_list[$key]['data4'] = '回路3温度超限报警';
  184. } elseif ($alarm_list[$key]['data1'] == 'EF8') {
  185. $alarm_list[$key]['data4'] = '回路4温度超限报警';
  186. } elseif ($alarm_list[$key]['data1'] == 'EF9') {
  187. $alarm_list[$key]['data4'] = '离线';
  188. } else {
  189. $alarm_list[$key]['data4'] = '其他' . $alarm_list[$key]['data1'];
  190. }
  191. }
  192. }
  193. $res['msg'] = '操作成功';
  194. $res['flag'] = true;
  195. $res['alarm_count'] = (int)$alarm_count[0]['alarm_count'];
  196. $res['data'] = $alarm_list;
  197. echo json_encode($res);
  198. }
  199. public function getAlarmDetails()
  200. {
  201. $Date = I();
  202. $id = $Date['id'];
  203. $type = $Date['type'];
  204. // $processing_status = $Date['processing_status'];
  205. if (empty($id) && empty($type)) {
  206. $res['msg'] = '操作失败,缺少关键参数';
  207. $res['flag'] = 3001;
  208. echo json_encode($res);
  209. exit();
  210. }
  211. switch ($type) {
  212. case '1'://烟感和报警主机
  213. $table = 'sp_hj2017';
  214. $types = '1,3';
  215. break;
  216. case '2'://水表和液位
  217. $table = 'sp_sj2017';
  218. $types = '2,5';
  219. break;
  220. case '4'://消防栓
  221. $table = 'sp_sj2017';
  222. $types = $type;
  223. break;
  224. case '6'://RTU
  225. $table = 'sp_rtu2017';
  226. $types = $type;
  227. break;
  228. case '7'://电气火灾
  229. $table = 'sp_ef2017';
  230. $types = $type;
  231. break;
  232. case '16'://视频监测
  233. $table = 'sp_video2017';
  234. $types = $type;
  235. break;
  236. case '17'://电梯监测
  237. $table = 'sp_lifter2017';
  238. $types = $type;
  239. break;
  240. case '128'://井盖
  241. $table = 'sp_iw2017';
  242. $types = $type;
  243. break;
  244. case '129'://地磁
  245. $table = 'sp_dc2020';
  246. $types = $type;
  247. break;
  248. case '130'://门禁
  249. $table = 'sp_door2020';
  250. $types = $type;
  251. break;
  252. case '131'://可燃气体
  253. $table = 'sp_gas2020';
  254. $types = $type;
  255. break;
  256. default:
  257. $res['msg'] = '操作失败,设备类型尚未定义,请联系管理员';
  258. $res['flag'] = 3002;
  259. echo json_encode($res);
  260. exit();
  261. break;
  262. }
  263. if ($type == 128){
  264. $list = M()->query("SELECT a.device_status,a.id,a.port,a.device_code,b.owner_name as device_name,a.data1,a.data4,a.data2,a.data3,a.data5,a.clwb,a.clzt,a.clr,a.clnr,b.company AS company_code,a.time,b.unitinfo,b.dwtype,a.ncmd,a.clsj FROM " . $table . " AS a JOIN sp_owner AS b ON a.device_code=b.owner_code WHERE a.id=" . $id);
  265. }else{
  266. $list = M()->query("SELECT a.id,a.port,a.device_code,b.owner_name as device_name,a.data1,a.data4,a.data2,a.data3,a.data5,a.clwb,a.clzt,a.clr,a.clnr,b.company AS company_code,a.time,b.unitinfo,b.dwtype,a.ncmd,a.clsj FROM " . $table . " AS a JOIN sp_owner AS b ON a.device_code=b.owner_code WHERE a.id=" . $id);
  267. }
  268. if($type == 1){
  269. $list[0]['alarm_information'] = $list[0]['data2'];
  270. }elseif ($type == 2 || $type == 4) {
  271. switch ($list[0]['data1']) {
  272. case 'WP1':
  273. $list[0]['alarm_information'] = '低压';
  274. break;
  275. case 'WP2':
  276. $list[0]['alarm_information'] = '高压';
  277. break;
  278. case 'WP3':
  279. $list[0]['alarm_information'] = '故障';
  280. break;
  281. case 'WP4':
  282. $list[0]['alarm_information'] = '离线';
  283. break;
  284. case 'LL1':
  285. $list[0]['alarm_information'] = '低水位';
  286. break;
  287. case 'LL2':
  288. $list[0]['alarm_information'] = '高水位';
  289. break;
  290. default:
  291. $list[0]['alarm_information'] = '其他' . $list[0]['data1'];
  292. break;
  293. }
  294. if ($list[0]['dwtype'] == 5) {
  295. $list[0]['numerical_value'] = '水位值:' . $list[0]['data4'] . 'M';
  296. } else {
  297. $list[0]['numerical_value'] = '水压值:' . $list[0]['data4'] . 'Mpa';
  298. }
  299. }else if ($type == 6){
  300. $list[0]['alarm_information'] =$list[0]['data2'];
  301. if ($list[0]['port'] == 'E6') {
  302. if ($list[0]['data2'] == '低压' || $list[0]['data2'] == '高压') {
  303. $list[0]['numerical_value'] = '水压值:' . $list[0]['data1'] . 'Mpa';
  304. } elseif ($list[0]['data2'] == '低水位' || $list[0]['data2'] == '高水位') {
  305. $list[0]['numerical_value'] = '水位:' . $list[0]['data1'] . 'M';
  306. } elseif ($list[0]['data2'] == '低温' || $list[0]['data2'] == '高温') {
  307. $list[0]['numerical_value'] = '温度:' . $list[0]['data1'] . '℃';
  308. } elseif ($list[0]['data2'] == '低湿度' || $list[0]['data2'] == '高湿度') {
  309. $list[0]['numerical_value'] = '湿度:' . $list[0]['data1'] . '%';
  310. }else if ($list[0]['data2'] == '设备异常'){
  311. $list[0]['numerical_value'] = $list[0]['data4'].':'.$list[0]['data1'];
  312. } else {
  313. $list[0]['numerical_value'] = $list[0]['data4'];
  314. }
  315. } else {
  316. $list[0]['numerical_value'] = $list[0]['data4'];
  317. }
  318. }else if ($type == 7) {
  319. if ($list[0]['data1'] == 'EF1') {
  320. $list[0]['alarm_information'] = '欠压报警';
  321. $list[0]['numerical_value'] = 'A相欠压值:' . $list[0]['data2'] . 'V B相欠压值:' . $list[0]['data3'] . 'V C相欠压值:' . $list[0]['data4'] . 'V';
  322. } elseif ($list[0]['data1'] == 'EF2') {
  323. $list[0]['alarm_information'] = '过压报警';
  324. $list[0]['numerical_value'] = 'A相过压值:' . $list[0]['data2'] . 'V B相过压值:' . $list[0]['data3'] . 'V C相过压值:' . $list[0]['data4'] . 'V';
  325. } elseif ($list[0]['data1'] == 'EF3') {
  326. $list[0]['alarm_information'] = '过流报警';
  327. $list[0]['numerical_value'] = 'A相过流值:' . $list[0]['data2'] . 'mA B相过流值:' . $list[0]['data3'] . 'mA C相过流值:' . $list[0]['data4'] . 'mA';
  328. } elseif ($list[0]['data1'] == 'EF4') {
  329. $list[0]['alarm_information'] = '漏电报警';
  330. $list[0]['numerical_value'] = '漏电流值:' . $list[0]['data2'] . 'mA';
  331. } elseif ($list[0]['data1'] == 'EF5') {
  332. $list[0]['alarm_information'] = '回路1温度超限报警';
  333. $list[0]['numerical_value'] = '温度1值:' . $list[0]['data2'] . '℃';
  334. } elseif ($list[0]['data1'] == 'EF6') {
  335. $list[0]['alarm_information'] = '回路2温度超限报警';
  336. $list[0]['numerical_value'] = '温度2值:' . $list[0]['data2'] . '℃';
  337. } elseif ($list[0]['data1'] == 'EF7') {
  338. $list[0]['alarm_information'] = '回路3温度超限报警';
  339. $list[0]['numerical_value'] = '温度3值:' . $list[0]['data2'] . '℃';
  340. } elseif ($list[0]['data1'] == 'EF8') {
  341. $list[0]['alarm_information'] = '回路4温度超限报警';
  342. $list[0]['numerical_value'] = '温度4值:' . $list[0]['data2'] . '℃';
  343. } elseif ($list[0]['data1'] == 'EF9') {
  344. $list[0]['alarm_information'] = '离线';
  345. $list[0]['numerical_value'] = '设备离线';
  346. } else {
  347. $list[0]['alarm_information'] = '其他' . $list[0]['data1'];
  348. }
  349. }elseif($type == 128){
  350. if ($list[0]['device_status']==1){
  351. $list[0]['alarm_information'] = "设备异常";
  352. }else{
  353. $list[0]['alarm_information'] = "设备正常";
  354. }
  355. }else{
  356. $list[0]['alarm_information'] = $list[0]['data4'];
  357. }
  358. $res['msg'] = '操作成功';
  359. $res['flag'] = true;
  360. $res['data'] = $list;
  361. echo json_encode($res);
  362. }
  363. public function setAlarmHandling(){
  364. $Data = I();
  365. $id = $Data['id'];
  366. $type = $Data['type'];
  367. $device_code = $Data['device_code'];
  368. $if_batch = $Data['if_batch'];
  369. $clwb = $Data['clwb'];
  370. $clnr = $Data['clnr'];
  371. $clr = $_SESSION['phone'];
  372. $port = $Data['port'];
  373. $Source_code=$Data['ncmd'];
  374. if (empty($id) && empty($type)&& empty($device_code)&& empty($clwb)&& empty($Data['data2'])&& empty($Data['data5'])&& empty($Data['data1'])&& empty($Source_code)) {
  375. $res['msg'] = '操作失败,缺少关键参数';
  376. $res['flag'] = false;
  377. echo json_encode($res);
  378. exit();
  379. }
  380. switch ($type) {
  381. case '1'://烟感和报警主机
  382. $table = 'sp_hj2017';
  383. $Tabs = M('hj2017');
  384. $types = '1,3';
  385. $where['data2'] = $Data['data2'];
  386. $where['data3'] = $Data['data3'];
  387. $where['data5'] = $Data['data5'];
  388. break;
  389. case '2'://水表和液位
  390. $table = 'sp_sj2017';
  391. $Tabs = M('sj2017');
  392. $types = '2,5';
  393. $where['data1'] = $Data['data1'];
  394. break;
  395. case '4'://消防栓
  396. $table = 'sp_sj2017';
  397. $Tabs = M('sj2017');
  398. $types = $type;
  399. break;
  400. case '6'://RTU
  401. $table = 'sp_rtu2017';
  402. $Tabs = M('rtu2017');
  403. $types = $type;
  404. $where['ncmd'] = $Data['ncmd'];
  405. $where['data2'] = $Data['data2'];
  406. $where['data4'] = $Data['data4'];
  407. break;
  408. case '7'://电气火灾
  409. $table = 'sp_ef2017';
  410. $Tabs = M('ef2017');
  411. $types = $type;
  412. $where['data1'] = $Data['data1'];
  413. break;
  414. case '16'://视频监测
  415. $table = 'sp_video2017';
  416. $Tabs = M('video2017');
  417. $types = $type;
  418. break;
  419. case '17'://电梯监测
  420. $table = 'sp_lifter2017';
  421. $Tabs = M('lifter2017');
  422. $types = $type;
  423. break;
  424. case '128'://井盖
  425. $table = 'sp_iw2017';
  426. $Tabs = M('iw2017');
  427. $types = $type;
  428. break;
  429. case '129'://地磁
  430. $table = 'sp_dc2020';
  431. $Tabs = M('dc2020');
  432. $types = $type;
  433. break;
  434. case '130'://门禁
  435. $table = 'sp_door2020';
  436. $Tabs = M('door2020');
  437. $types = $type;
  438. break;
  439. case '131'://可燃气体
  440. $table = 'sp_gas2020';
  441. $Tabs = M('gas2020');
  442. $types = $type;
  443. break;
  444. default:
  445. $res['msg'] = '操作失败,设备类型尚未定义,请联系管理员';
  446. $res['flag'] = false;
  447. echo json_encode($res);
  448. exit();
  449. break;
  450. }
  451. //修改条件
  452. $data['clzt']=1;
  453. $data['clwb']=$clwb;
  454. $data['clnr']=$clnr;
  455. $data['cldh']=$clr;
  456. $data['clr']=$clr;
  457. $data['clsj']=date("Y-m-d");
  458. $types_data=M()->query("select dwtype from sp_owner where owner_code='".$Data['device_code']."'");
  459. $typess=$types_data[0]['dwtype'];
  460. if ($if_batch==1){//批量处理
  461. $where['device_code']=$device_code;
  462. $where['clzt']=0;
  463. $R=$Tabs->where($where)->save($data);
  464. }else{
  465. $where['id']=$id;
  466. $R=$Tabs->where($where)->save($data);
  467. }
  468. $url1 = 'http://47.98.201.187:55335/report';
  469. if ($if_batch==1){
  470. if ($typess==1){
  471. $res_id = M()->query("select id,data3,data4 from sp_hj2017 where device_code='" . $Data['device_code'] . "' and data3='" . $Data['data3'] . "' and data5='" . $Data['data5'] . "' and clzt=1 order by time desc LIMIT 1;");
  472. $cs66 = [
  473. 'SubType' => 1,
  474. 'DeviceId' => $Data['device_code'],
  475. 'InsertId' => $res_id[0]['id'],
  476. 'Confirmed' => true,
  477. ];
  478. $cs88 = json_encode($cs66);
  479. $result = http_post_advertise($url1, $cs88);
  480. if (!empty($res_id[0]['data4'])){
  481. $port=mb_substr($res_id[0]['data4'],4,1,'utf-8');
  482. // $port=substr($res_id[0]['data4'],3,1);
  483. }else{
  484. $port='';
  485. }
  486. if (!empty($res_id[0]['data3'])){
  487. $Source_code=str_replace(',','',$res_id[0]['data3']);
  488. }else{
  489. $Source_code='';
  490. }
  491. $unique_number=$Data['device_code'].$port.$Source_code;
  492. }elseif ($typess==2){
  493. $res_id = M()->query("select id from sp_sj2017 where device_code='" . $Data['device_code'] . "' and data1='" . $Data['data1'] . "' and clzt=1 order by time desc limit 1");
  494. $cs66 = [
  495. 'SubType' => 2,
  496. 'DeviceId' => $Data['device_code'],
  497. 'InsertId' => $res_id[0]['id'],
  498. 'Confirmed' => true,
  499. ];
  500. $cs88 = json_encode($cs66);
  501. $result = http_post_advertise($url1, $cs88);
  502. $unique_number=$Data['device_code'];
  503. }elseif ($typess==3){
  504. $res_id = M()->query("select id from sp_hj2017 where device_code='" . $Data['device_code'] . "' and data2='" . $Data['ftypewtype'] . "' and clzt=1 order by time desc limit 1");
  505. $cs66 = [
  506. 'SubType' => 3,
  507. 'DeviceId' => $Data['device_code'],
  508. 'InsertId' => $res_id[0]['id'],
  509. 'Confirmed' => true,
  510. ];
  511. $url1 = 'http://47.98.201.187:55335/report';
  512. $cs88 = json_encode($cs66);
  513. $result = http_post_advertise($url1, $cs88);
  514. $unique_number=$Data['device_code'];
  515. }elseif ($typess==6){
  516. $unique_number=$Data['device_code'].$port.$Source_code.$Data['data4'].' '.$Data['data2'];
  517. }elseif ($typess==7){
  518. $res_id = M()->query("select * from sp_ef2017 where device_code='" . $Data['device_code'] . "' and data1='" . $Data['data1'] . "' and clzt=1 order by time desc limit 1");
  519. $cs66 = [
  520. 'SubType' => 7,
  521. 'DeviceId' => $Data['device_code'],
  522. 'InsertId' => $res_id[0]['id'],
  523. 'Confirmed' => true,
  524. ];
  525. $url1 = 'http://47.98.201.187:55335/report';
  526. $cs88 = json_encode($cs66);
  527. $result = http_post_advertise($url1, $cs88);
  528. $port=$res_id[0]['port'];
  529. $unique_number=$Data['device_code'].$port;
  530. }else{
  531. $unique_number=$Data['device_code'];
  532. }
  533. //redis链接
  534. // $redis = new \Redis();
  535. // $result = $redis->connect('127.0.0.1', 6379);
  536. // if ($result==1){
  537. // $redis->set("$unique_number",1);
  538. // $redis->close();
  539. // }
  540. }else{
  541. $cs = [
  542. 'SubType' => $typess,
  543. 'DeviceId' => $Data['device_code'],
  544. 'InsertId' => $Data['id'],
  545. 'Confirmed' => true,
  546. ];
  547. if ($typess == 1 || $typess == 2 || $typess == 3 || $typess == 7) {
  548. $url = 'http://47.98.201.187:55335/report';
  549. $cs3 = json_encode($cs);
  550. $result = http_post_advertise($url, $cs3);
  551. }
  552. if ($typess==1){
  553. $res_id = M()->query("select data3,data4 from sp_hj2017 where id=" . $Data['id']);
  554. if (!empty($res_id[0]['data4'])){
  555. $port=mb_substr($res_id[0]['data4'],4,1,'utf-8');
  556. // $port=substr($res_id[0]['data4'],3,1);
  557. }else{
  558. $port='';
  559. }
  560. if (!empty($res_id[0]['data3'])){
  561. $Source_code=str_replace(',','',$res_id[0]['data3']);
  562. }else{
  563. $Source_code='';
  564. }
  565. $unique_number=$Data['device_code'].$port.$Source_code;
  566. }else if ($typess==6){
  567. $port=$Data['port'];
  568. $Source_code=$Data['ncmd'];
  569. $unique_number=$Data['device_code'].$port.$Source_code.$Data['data4'].' '.$Data['data2'];
  570. }else if ($typess==7){
  571. $res_id = M()->query("select port from sp_ef2017 where id=" . $Data['id']);
  572. $port=$res_id[0]['port'];
  573. $unique_number=$Data['device_code'].$port;
  574. }else{
  575. $unique_number=$Data['device_code'];
  576. }
  577. //redis储存处理的设备
  578. // $redis = new \Redis();
  579. // $result = $redis->connect('127.0.0.1', 6379);
  580. // if ($result==1){
  581. // $redis->set("$unique_number",1);
  582. // $redis->close();
  583. // }
  584. }
  585. // $data = array("devicestatus" => 0);
  586. // $str_where = "deviceid='" . $Data['device_code'] . "'";
  587. // $str_sql_upd = M('devices_status')->where($str_where)->save($data);
  588. if ($R){
  589. $res['msg'] = '操作成功';
  590. $res['flag'] = true;
  591. echo json_encode($res);
  592. }else{
  593. $res['msg'] = '操作失败';
  594. $res['flag'] = 3002;
  595. echo json_encode($res);
  596. }
  597. }
  598. //获取消防栓设备编号
  599. public function getDeviceCode1($company)
  600. {
  601. $device = M()->query("SELECT o.owner_code,c.owner_name FROM sp_owner o join sp_owner_company c ON o.company =c.owner_id WHERE o.dwtype=4 and o.company in(".$company.")");
  602. $str = "";
  603. foreach ($device as $val) {
  604. $str .= "'" . $val['owner_code'] . "',";
  605. }
  606. $newstr = substr($str, 0, strlen($str) - 1);
  607. return $newstr;
  608. }
  609. }