ComprehensiveAlarmController.class.php.bak.2021-12-13 31 KB

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