ComprehensiveAlarmController.class.php.bak.2022-02-14 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. include '../Common/function.php';
  5. include '../../../../USKYZHAF/Public/vendor/phpMQTT/phpMQTT.php';
  6. class ComprehensiveAlarmController extends ComController
  7. {
  8. //综合告警各类型数据统计
  9. public function getAlarmStatistics()
  10. {
  11. $Date = I();
  12. $company_code = $Date['company_code'];
  13. if (empty($company_code)) {
  14. $res['msg'] = '操作失败,缺少关键参数company_code';
  15. $res['flag'] = false;
  16. echo json_encode($res);
  17. exit();
  18. }
  19. $device_list = $this->getDeviceCode($company_code);
  20. $device_list1 = $this->getDeviceCode1($company_code);
  21. $where2['company_code'] = $company_code;
  22. $data_statistics = M('company_sync')->where($where2)->find();
  23. if(!empty($data_statistics)){
  24. //报警主机未处理数量统计
  25. $untreated_alarm_host_count=$data_statistics['device_01_alarm']-$data_statistics['device_01_alarm_confirm']+$data_statistics['device_01_out']-$data_statistics['device_01_out_confirm'];
  26. //消防水未处理数量统计
  27. $untreated_fire_water_count1=$data_statistics['device_02_alarm']+$data_statistics['device_00_alarm']-($data_statistics['device_02_alarm_confirm']+$data_statistics['device_00_alarm_confirm'])
  28. +$data_statistics['device_00_out']-$data_statistics['device_00_out_confirm']+$data_statistics['device_02_out']-$data_statistics['device_02_out_confirm'];
  29. //RTU未处理数量统计
  30. $untreated_rtu_count=$data_statistics['device_06_alarm'] - $data_statistics['device_06_alarm_confirm']+$data_statistics['device_06_out']-$data_statistics['device_06_out_confirm'];
  31. //电气火灾未处理数量统计
  32. $untreated_electrical_fire_count= $data_statistics['device_07_alarm'] - $data_statistics['device_07_alarm_confirm']+$data_statistics['device_07_out']-$data_statistics['device_07_out_confirm'];
  33. //视频监测未处理数量统计
  34. $untreated_video_monitoring_count=$data_statistics['device_16_alarm'] - $data_statistics['device_16_alarm_confirm']+$data_statistics['device_16_out']-$data_statistics['device_16_out_confirm'];
  35. $data[0]['untreated_alarm_host_count'] = (int)$untreated_alarm_host_count;
  36. $data[0]['untreated_fire_water_count'] = (int)$untreated_fire_water_count1;
  37. $data[0]['untreated_rtu_count'] = (int)$untreated_rtu_count;
  38. $data[0]['untreated_electrical_fire_count'] = (int)$untreated_electrical_fire_count;
  39. $data[0]['untreated_video_monitoring_count'] = (int)$untreated_video_monitoring_count;
  40. }else{
  41. $data[0]['untreated_alarm_host_count'] = 0;
  42. $data[0]['untreated_fire_water_count'] = 0;
  43. $data[0]['untreated_rtu_count'] = 0;
  44. $data[0]['untreated_electrical_fire_count'] = 0;
  45. $data[0]['untreated_video_monitoring_count'] = 0;
  46. }
  47. if (!empty($device_list)){
  48. // //报警主机未处理数量统计
  49. // $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."'");
  50. //// $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 . ")");
  51. // //消防水未处理数量统计
  52. //// $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 . ")");
  53. // $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."'");
  54. //
  55. // //$untreated_fire_water_count = (int)$untreated_fire_water_count1[0]['untreated_fire_water_count'] - (int)$untreated_fire_hydrant_count[0]['untreated_fire_hydrant_count'];
  56. // //电气火灾未处理数量统计
  57. // $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 . ")");
  58. // //视频监测未处理数量统计
  59. // $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 . ")");
  60. //井盖未处理数量统计
  61. $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 . ")");
  62. //门禁未处理数量统计
  63. $untreated_door_count = M()->query("select count(*) as untreated_door_count from sp_door2020 where clzt=0 and device_code in(" . $device_list . ")");
  64. //可燃气体未处理数量统计
  65. $untreated_gas_count = M()->query("select count(*) as untreated_gas_count from sp_gas2020 where clzt=0 and device_code in(" . $device_list . ")");
  66. //地磁未处理数量统计
  67. $untreated_geomagnetism_count = M()->query("select count(*) as untreated_geomagnetism_count from sp_dc2020 where clzt=0 and device_code in(" . $device_list . ")");
  68. // //RTU未处理数量统计
  69. // $untreated_rtu_count = M()->query("select count(*) as untreated_rtu_count from sp_rtu2017 where clzt=0 and device_code in(" . $device_list . ")");
  70. //电梯未处理数量统计
  71. $untreated_elevator_count = M()->query("select count(*) as untreated_elevator_count from sp_lifter2017 where clzt=0 and device_code in(" . $device_list . ")");
  72. // $data[0]['untreated_alarm_host_count'] = (int)$untreated_alarm_host_count[0]['untreated_alarm_host_count'];
  73. // $data[0]['untreated_fire_water_count'] = (int)$untreated_fire_water_count1[0]['untreated_fire_water_count'];
  74. // $data[0]['untreated_electrical_fire_count'] = (int)$untreated_electrical_fire_count[0]['untreated_electrical_fire_count'];
  75. // $data[0]['untreated_video_monitoring_count'] = (int)$untreated_video_monitoring_count[0]['untreated_video_monitoring_count'];
  76. $data[0]['untreated_manhole_cover_count'] = (int)$untreated_manhole_cover_count[0]['untreated_manhole_cover_count'];
  77. $data[0]['untreated_door_count'] = (int)$untreated_door_count[0]['untreated_door_count'];
  78. $data[0]['untreated_gas_count'] = (int)$untreated_gas_count[0]['untreated_gas_count'];
  79. $data[0]['untreated_geomagnetism_count'] = (int)$untreated_geomagnetism_count[0]['untreated_geomagnetism_count'];
  80. // $data[0]['untreated_rtu_count'] = (int)$untreated_rtu_count[0]['untreated_rtu_count'];
  81. $data[0]['untreated_elevator_count'] = (int)$untreated_elevator_count[0]['untreated_elevator_count'];
  82. }else{
  83. // $data[0]['untreated_alarm_host_count'] = 0;
  84. // $data[0]['untreated_fire_water_count'] = 0;
  85. // $data[0]['untreated_electrical_fire_count'] = 0;
  86. // $data[0]['untreated_video_monitoring_count'] = 0;
  87. $data[0]['untreated_manhole_cover_count'] = 0;
  88. $data[0]['untreated_door_count'] = 0;
  89. $data[0]['untreated_gas_count'] = 0;
  90. $data[0]['untreated_geomagnetism_count'] = 0;
  91. // $data[0]['untreated_rtu_count'] = 0;
  92. $data[0]['untreated_elevator_count'] = 0;
  93. }
  94. if (!empty($device_list1)){
  95. //消火栓未处理统计
  96. $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 . ")");
  97. $data[0]['untreated_fire_hydrant_count'] = (int)$untreated_fire_hydrant_count[0]['untreated_fire_hydrant_count'];
  98. }else{
  99. $data[0]['untreated_fire_hydrant_count'] = 0;
  100. }
  101. $data[0]['company_code'] = $company_code;
  102. $res['msg'] = '操作成功';
  103. $res['flag'] = true;
  104. $res['data'] = $data;
  105. echo json_encode($res);
  106. }
  107. public function getIntegratedAlarmList()
  108. {
  109. $Date = I();
  110. $company_code = $Date['company_code'];
  111. $type = $Date['type'];
  112. $processing_status = $Date['processing_status'];
  113. $start_time = $Date['start_time'];
  114. $end_time = $Date['end_time'];
  115. if (empty($company_code) && empty($type)) {
  116. $res['msg'] = '操作失败,缺少关键参数';
  117. $res['flag'] = false;
  118. echo json_encode($res);
  119. exit();
  120. }
  121. $where = '';
  122. if (!empty($start_time)) {
  123. $where .= " and a.time>='" . $start_time . "' ";
  124. }
  125. if (isset($processing_status)) {
  126. $where .= " and a.clzt='" . $processing_status . "' ";
  127. }
  128. if (!empty($start_time)) {
  129. $where .= " and a.time<'" . $end_time . "' ";
  130. }
  131. switch ($type) {
  132. case '1'://报警主机
  133. $table = 'sp_hj2017';
  134. $types = '1';
  135. break;
  136. case '2'://水表和液位
  137. $table = 'sp_sj2017';
  138. $types = '2,5';
  139. break;
  140. case '3'://烟感
  141. $table = 'sp_hj2017';
  142. $types = '3';
  143. break;
  144. case '4'://消防栓
  145. $table = 'sp_sj2017';
  146. $types = $type;
  147. break;
  148. case '5'://液位
  149. $table = 'sp_sj2017';
  150. $types = '5';
  151. break;
  152. case '6'://RTU
  153. $table = 'sp_rtu2017';
  154. $types = $type;
  155. break;
  156. case '7'://电气火灾
  157. $table = 'sp_ef2017';
  158. $types = $type;
  159. break;
  160. case '16'://视频监测
  161. $table = 'sp_video2017';
  162. $types = $type;
  163. break;
  164. case '17'://电梯监测
  165. $table = 'sp_lifter2017';
  166. $types = $type;
  167. break;
  168. case '128'://井盖
  169. $table = 'sp_iw2017';
  170. $types = $type;
  171. break;
  172. case '129'://地磁
  173. $table = 'sp_dc2020';
  174. $types = $type;
  175. break;
  176. case '130'://门禁
  177. $table = 'sp_door2020';
  178. $types = $type;
  179. break;
  180. case '131'://可燃气体
  181. $table = 'sp_gas2020';
  182. $types = $type;
  183. break;
  184. default:
  185. $res['msg'] = '操作失败,设备类型尚未定义,请联系管理员';
  186. $res['flag'] = 3002;
  187. echo json_encode($res);
  188. exit();
  189. break;
  190. }
  191. $start=($Date['page']-1)*$Date['pageSize'];
  192. if (!empty($Date['pageSize'])){
  193. $LIMIT=" LIMIT ".$start.",".$Date['pageSize'];
  194. }
  195. if ($type==1||$type==2||$type==6||$type==7||$type==16){
  196. $where2['company_code'] = $company_code;
  197. $data_statistics = M('company_sync')->where($where2)->find();
  198. if(!empty($data_statistics)){
  199. switch ($type) {
  200. case '1'://报警主机
  201. if ($processing_status==0){
  202. $alarm_count = $data_statistics['device_01_alarm']-$data_statistics['device_01_alarm_confirm']+$data_statistics['device_01_out']-$data_statistics['device_01_out_confirm'];
  203. }else{
  204. $alarm_count = $data_statistics['device_01_alarm_confirm']+$data_statistics['device_01_out_confirm'];
  205. }
  206. break;
  207. case '2'://水表和液位
  208. if ($processing_status==0){
  209. $alarm_count=$data_statistics['device_02_alarm']+$data_statistics['device_00_alarm']-($data_statistics['device_02_alarm_confirm']+$data_statistics['device_00_alarm_confirm'])
  210. +$data_statistics['device_00_out']-$data_statistics['device_00_out_confirm']+$data_statistics['device_02_out']-$data_statistics['device_02_out_confirm'];
  211. }else{
  212. $alarm_count=$data_statistics['device_02_alarm_confirm']+$data_statistics['device_00_alarm_confirm'] +$data_statistics['device_00_out_confirm']+$data_statistics['device_02_out_confirm'];
  213. }
  214. break;
  215. case '5'://液位和水表
  216. if ($processing_status==0){
  217. $alarm_count=$data_statistics['device_02_alarm']+$data_statistics['device_00_alarm']-($data_statistics['device_02_alarm_confirm']+$data_statistics['device_00_alarm_confirm'])
  218. +$data_statistics['device_00_out']-$data_statistics['device_00_out_confirm']+$data_statistics['device_02_out']-$data_statistics['device_02_out_confirm'];
  219. }else{
  220. $alarm_count=$data_statistics['device_02_alarm_confirm']+$data_statistics['device_00_alarm_confirm'] +$data_statistics['device_00_out_confirm']+$data_statistics['device_02_out_confirm'];
  221. }
  222. break;
  223. case '6'://RTU未处理数量统计
  224. if ($processing_status==0){
  225. $alarm_count=$data_statistics['device_06_alarm'] - $data_statistics['device_06_alarm_confirm']+$data_statistics['device_06_out']-$data_statistics['device_06_out_confirm'];
  226. }else{
  227. $alarm_count=$data_statistics['device_06_alarm_confirm']+$data_statistics['device_06_out_confirm'];
  228. }
  229. break;
  230. case '7'://电气火灾未处理数量统计
  231. if ($processing_status==0){
  232. $alarm_count= $data_statistics['device_07_alarm'] - $data_statistics['device_07_alarm_confirm']+$data_statistics['device_07_out']-$data_statistics['device_07_out_confirm'];
  233. }else{
  234. $data_statistics['device_07_alarm_confirm']+$data_statistics['device_07_out_confirm'];
  235. }
  236. break;
  237. case '16'://视频监测未处理数量统计
  238. if ($processing_status==0){
  239. $alarm_count=$data_statistics['device_16_alarm'] - $data_statistics['device_16_alarm_confirm']+$data_statistics['device_16_out']-$data_statistics['device_16_out_confirm'];
  240. }else{
  241. $alarm_count=$data_statistics['device_16_alarm_confirm']+$data_statistics['device_16_out_confirm'];
  242. }
  243. break;
  244. default:
  245. break;
  246. }
  247. }else{
  248. $alarm_count = 0;
  249. }
  250. }else{
  251. $alarm_list = 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 . "' " . $where);
  252. $alarm_count = $alarm_list[0]['alarm_count'];
  253. }
  254. // $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);
  255. $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 ".$LIMIT);
  256. // $alarm_count =sizeof($alarm_list);
  257. if ($type == 2 || $type == 4) {
  258. foreach ($alarm_list as $key => $value) {
  259. switch ($alarm_list[$key]['data1']) {
  260. case 'WP1':
  261. $alarm_list[$key]['data4'] = '低压';
  262. break;
  263. case 'WP2':
  264. $alarm_list[$key]['data4'] = '高压';
  265. break;
  266. case 'WP3':
  267. $alarm_list[$key]['data4'] = '故障';
  268. break;
  269. case 'WP4':
  270. $alarm_list[$key]['data4'] = '离线';
  271. break;
  272. case 'LL1':
  273. $alarm_list[$key]['data4'] = '低水位';
  274. break;
  275. case 'LL2':
  276. $alarm_list[$key]['data4'] = '高水位';
  277. break;
  278. default:
  279. $alarm_list[$key]['data4'] = '其他' . $alarm_list[$key]['data1'];
  280. break;
  281. }
  282. }
  283. } else if ($type == 7) {
  284. foreach ($alarm_list as $key => $value) {
  285. if ($alarm_list[$key]['data1'] == 'EF1') {
  286. $alarm_list[$key]['data4'] = '欠压报警';
  287. } elseif ($alarm_list[$key]['data1'] == 'EF2') {
  288. $alarm_list[$key]['data4'] = '过压报警';
  289. } elseif ($alarm_list[$key]['data1'] == 'EF3') {
  290. $alarm_list[$key]['data4'] = '过流报警';
  291. } elseif ($alarm_list[$key]['data1'] == 'EF4') {
  292. $alarm_list[$key]['data4'] = '漏电报警';
  293. } elseif ($alarm_list[$key]['data1'] == 'EF5') {
  294. $alarm_list[$key]['data4'] = '回路1温度超限报警';
  295. } elseif ($alarm_list[$key]['data1'] == 'EF6') {
  296. $alarm_list[$key]['data4'] = '回路2温度超限报警';
  297. } elseif ($alarm_list[$key]['data1'] == 'EF7') {
  298. $alarm_list[$key]['data4'] = '回路3温度超限报警';
  299. } elseif ($alarm_list[$key]['data1'] == 'EF8') {
  300. $alarm_list[$key]['data4'] = '回路4温度超限报警';
  301. } elseif ($alarm_list[$key]['data1'] == 'EF9') {
  302. $alarm_list[$key]['data4'] = '离线';
  303. } else {
  304. $alarm_list[$key]['data4'] = '其他' . $alarm_list[$key]['data1'];
  305. }
  306. }
  307. }
  308. $res['msg'] = '操作成功';
  309. $res['flag'] = true;
  310. $res['alarm_count'] = (int)$alarm_count;
  311. $res['data'] = $alarm_list;
  312. echo json_encode($res);
  313. }
  314. public function getAlarmDetails()
  315. {
  316. $Date = I();
  317. // print_r($Date);
  318. $id = $Date['id'];
  319. $type = $Date['type'];
  320. // $processing_status = $Date['processing_status'];
  321. if (empty($id) && empty($type)) {
  322. $res['msg'] = '操作失败,缺少关键参数';
  323. $res['flag'] = 3001;
  324. echo json_encode($res);
  325. exit();
  326. }
  327. switch ($type) {
  328. case '1'://报警主机
  329. $table = 'sp_hj2017';
  330. $types = '1';
  331. break;
  332. case '2'://水表和液位
  333. $table = 'sp_sj2017';
  334. $types = '2,';
  335. break;
  336. case '3'://烟感
  337. $table = 'sp_hj2017';
  338. $types = '3';
  339. break;
  340. case '4'://消防栓
  341. $table = 'sp_sj2017';
  342. $types = $type;
  343. break;
  344. case '5'://液位
  345. $table = 'sp_sj2017';
  346. $types = '5';
  347. break;
  348. case '6'://RTU
  349. $table = 'sp_rtu2017';
  350. $types = $type;
  351. break;
  352. case '7'://电气火灾
  353. $table = 'sp_ef2017';
  354. $types = $type;
  355. break;
  356. case '16'://视频监测
  357. $table = 'sp_video2017';
  358. $types = $type;
  359. break;
  360. case '17'://电梯监测
  361. $table = 'sp_lifter2017';
  362. $types = $type;
  363. break;
  364. case '128'://井盖
  365. $table = 'sp_iw2017';
  366. $types = $type;
  367. break;
  368. case '129'://地磁
  369. $table = 'sp_dc2020';
  370. $types = $type;
  371. break;
  372. case '130'://门禁
  373. $table = 'sp_door2020';
  374. $types = $type;
  375. break;
  376. case '131'://可燃气体
  377. $table = 'sp_gas2020';
  378. $types = $type;
  379. break;
  380. default:
  381. $res['msg'] = '操作失败,设备类型尚未定义,请联系管理员';
  382. $res['flag'] = 3002;
  383. echo json_encode($res);
  384. exit();
  385. break;
  386. }
  387. if ($type == 128){
  388. $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);
  389. }elseif($type == 130||$type == 131){
  390. $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);
  391. }else{
  392. // 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);
  393. $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);
  394. }
  395. if($type == 1){
  396. $list[0]['alarm_information'] = $list[0]['data2'];
  397. }elseif ($type == 2 || $type == 4) {
  398. switch ($list[0]['data1']) {
  399. case 'WP1':
  400. $list[0]['alarm_information'] = '低压';
  401. break;
  402. case 'WP2':
  403. $list[0]['alarm_information'] = '高压';
  404. break;
  405. case 'WP3':
  406. $list[0]['alarm_information'] = '故障';
  407. break;
  408. case 'WP4':
  409. $list[0]['alarm_information'] = '离线';
  410. break;
  411. case 'LL1':
  412. $list[0]['alarm_information'] = '低水位';
  413. break;
  414. case 'LL2':
  415. $list[0]['alarm_information'] = '高水位';
  416. break;
  417. default:
  418. $list[0]['alarm_information'] = '其他' . $list[0]['data1'];
  419. break;
  420. }
  421. if ($list[0]['dwtype'] == 5) {
  422. $list[0]['numerical_value'] = '水位值:' . $list[0]['data4'] . 'M';
  423. } else {
  424. $list[0]['numerical_value'] = '水压值:' . $list[0]['data4'] . 'Mpa';
  425. }
  426. }else if ($type == 6){
  427. $list[0]['alarm_information'] =$list[0]['data2'];
  428. if ($list[0]['port'] == 'E6') {
  429. if ($list[0]['data2'] == '低压' || $list[0]['data2'] == '高压') {
  430. $list[0]['numerical_value'] = '水压值:' . $list[0]['data1'] . 'Mpa';
  431. } elseif ($list[0]['data2'] == '低水位' || $list[0]['data2'] == '高水位') {
  432. $list[0]['numerical_value'] = '水位:' . $list[0]['data1'] . 'M';
  433. } elseif ($list[0]['data2'] == '低温' || $list[0]['data2'] == '高温') {
  434. $list[0]['numerical_value'] = '温度:' . $list[0]['data1'] . '℃';
  435. } elseif ($list[0]['data2'] == '低湿度' || $list[0]['data2'] == '高湿度') {
  436. $list[0]['numerical_value'] = '湿度:' . $list[0]['data1'] . '%';
  437. }else if ($list[0]['data2'] == '设备异常'){
  438. $list[0]['numerical_value'] = $list[0]['data4'].':'.$list[0]['data1'];
  439. } else {
  440. $list[0]['numerical_value'] = $list[0]['data4'];
  441. }
  442. } else {
  443. $list[0]['numerical_value'] = $list[0]['data4'];
  444. }
  445. }else if ($type == 7) {
  446. if ($list[0]['data1'] == 'EF1') {
  447. $list[0]['alarm_information'] = '欠压报警';
  448. $list[0]['numerical_value'] = 'A相欠压值:' . $list[0]['data2'] . 'V B相欠压值:' . $list[0]['data3'] . 'V C相欠压值:' . $list[0]['data4'] . 'V';
  449. } elseif ($list[0]['data1'] == 'EF2') {
  450. $list[0]['alarm_information'] = '过压报警';
  451. $list[0]['numerical_value'] = 'A相过压值:' . $list[0]['data2'] . 'V B相过压值:' . $list[0]['data3'] . 'V C相过压值:' . $list[0]['data4'] . 'V';
  452. } elseif ($list[0]['data1'] == 'EF3') {
  453. $list[0]['alarm_information'] = '过流报警';
  454. $list[0]['numerical_value'] = 'A相过流值:' . $list[0]['data2'] . 'mA B相过流值:' . $list[0]['data3'] . 'mA C相过流值:' . $list[0]['data4'] . 'mA';
  455. } elseif ($list[0]['data1'] == 'EF4') {
  456. $list[0]['alarm_information'] = '漏电报警';
  457. $list[0]['numerical_value'] = '漏电流值:' . $list[0]['data2'] . 'mA';
  458. } elseif ($list[0]['data1'] == 'EF5') {
  459. $list[0]['alarm_information'] = '回路1温度超限报警';
  460. $list[0]['numerical_value'] = '温度1值:' . $list[0]['data2'] . '℃';
  461. } elseif ($list[0]['data1'] == 'EF6') {
  462. $list[0]['alarm_information'] = '回路2温度超限报警';
  463. $list[0]['numerical_value'] = '温度2值:' . $list[0]['data2'] . '℃';
  464. } elseif ($list[0]['data1'] == 'EF7') {
  465. $list[0]['alarm_information'] = '回路3温度超限报警';
  466. $list[0]['numerical_value'] = '温度3值:' . $list[0]['data2'] . '℃';
  467. } elseif ($list[0]['data1'] == 'EF8') {
  468. $list[0]['alarm_information'] = '回路4温度超限报警';
  469. $list[0]['numerical_value'] = '温度4值:' . $list[0]['data2'] . '℃';
  470. } elseif ($list[0]['data1'] == 'EF9') {
  471. $list[0]['alarm_information'] = '离线';
  472. $list[0]['numerical_value'] = '设备离线';
  473. } else {
  474. $list[0]['alarm_information'] = '其他' . $list[0]['data1'];
  475. }
  476. }elseif($type == 128){
  477. if ($list[0]['device_status']==1){
  478. $list[0]['alarm_information'] = "设备异常";
  479. }else{
  480. $list[0]['alarm_information'] = "设备正常";
  481. }
  482. }else{
  483. $list[0]['alarm_information'] = $list[0]['data4'];
  484. }
  485. $res['msg'] = '操作成功';
  486. $res['flag'] = true;
  487. $res['data'] = $list;
  488. echo json_encode($res);
  489. }
  490. public function setAlarmHandling(){
  491. $Data = I();
  492. $id = $Data['id'];
  493. $type = $Data['type'];
  494. $device_code = $Data['device_code'];
  495. $if_batch = $Data['if_batch'];
  496. $clwb = $Data['clwb'];
  497. $clnr = $Data['clnr'];
  498. $clr = $_SESSION['phone'];
  499. $port = $Data['port'];
  500. $Source_code=$Data['ncmd'];
  501. if (empty($id) && empty($type)&& empty($device_code)&& empty($clwb)&& empty($Data['data2'])&& empty($Data['data5'])&& empty($Data['data1'])&& empty($Source_code)) {
  502. $res['msg'] = '操作失败,缺少关键参数';
  503. $res['flag'] = false;
  504. echo json_encode($res);
  505. exit();
  506. }
  507. switch ($type) {
  508. case '1'://报警主机
  509. $table = 'sp_hj2017';
  510. $Tabs = M('hj2017');
  511. $types = '1';
  512. // $where['data2'] = $Data['data2'];
  513. $where['data3'] = $Data['data3'];
  514. $where['data5'] = $Data['data5'];
  515. break;
  516. case '2'://水表和液位
  517. $table = 'sp_sj2017';
  518. $Tabs = M('sj2017');
  519. $types = '2';
  520. $where['data1'] = $Data['data1'];
  521. break;
  522. case '3'://烟感
  523. $table = 'sp_hj2017';
  524. $Tabs = M('hj2017');
  525. $types = '3';
  526. $where['data2'] = $Data['data2'];
  527. break;
  528. case '4'://消防栓
  529. $table = 'sp_sj2017';
  530. $Tabs = M('sj2017');
  531. $types = $type;
  532. break;
  533. case '5'://液位
  534. $table = 'sp_sj2017';
  535. $Tabs = M('sj2017');
  536. $types = '5';
  537. break;
  538. case '6'://RTU
  539. $table = 'sp_rtu2017';
  540. $Tabs = M('rtu2017');
  541. $types = $type;
  542. $where['ncmd'] = $Data['ncmd'];
  543. $where['data2'] = $Data['data2'];
  544. $where['data4'] = $Data['data4'];
  545. break;
  546. case '7'://电气火灾
  547. $table = 'sp_ef2017';
  548. $Tabs = M('ef2017');
  549. $types = $type;
  550. $where['data1'] = $Data['data1'];
  551. break;
  552. case '16'://视频监测
  553. $table = 'sp_video2017';
  554. $Tabs = M('video2017');
  555. $types = $type;
  556. break;
  557. case '17'://电梯监测
  558. $table = 'sp_lifter2017';
  559. $Tabs = M('lifter2017');
  560. $types = $type;
  561. break;
  562. case '128'://井盖
  563. $table = 'sp_iw2017';
  564. $Tabs = M('iw2017');
  565. $types = $type;
  566. break;
  567. case '129'://地磁
  568. $table = 'sp_dc2020';
  569. $Tabs = M('dc2020');
  570. $types = $type;
  571. break;
  572. case '130'://门禁
  573. $table = 'sp_door2020';
  574. $Tabs = M('door2020');
  575. $types = $type;
  576. break;
  577. case '131'://可燃气体
  578. $table = 'sp_gas2020';
  579. $Tabs = M('gas2020');
  580. $types = $type;
  581. break;
  582. default:
  583. $res['msg'] = '操作失败,设备类型尚未定义,请联系管理员';
  584. $res['flag'] = false;
  585. echo json_encode($res);
  586. exit();
  587. break;
  588. }
  589. //修改条件
  590. $data['clzt']=1;
  591. $data['clwb']=$clwb;
  592. $data['clnr']=$clnr;
  593. $data['cldh']=$clr;
  594. $data['clr']=$clr;
  595. $data['clsj']=date("Y-m-d H:i:s");
  596. $types_data=M()->query("select dwtype,company from sp_owner where owner_code='".$Data['device_code']."'");
  597. $typess=$types_data[0]['dwtype'];
  598. $company_data=ytapi_query("select * from corps_company where company_code='".$types_data[0]['company']."' and status=1");
  599. if (!empty($company_data)){
  600. switch ($types_data[0]['dwtype']) {
  601. case '1':
  602. $RESS = M()->query("select data3,data5 from sp_hj2017 where id=".$id);
  603. $res_id = M()->query("select id,data3,data4 from sp_hj2017 where device_code='" . $Data['device_code'] . "' and data3='" . $RESS[0]['data3'] . "' and data5='" . $RESS[0]['data5'] . "' and clzt=0");
  604. break;
  605. case '2':
  606. case '5':
  607. $RESS = M()->query("select data1 from sp_sj2017 where id=".$id);
  608. $res_id = M()->query("select id from sp_sj2017 where device_code='" . $Data['device_code'] . "' and data1='" . $RESS[0]['data1'] . "' and clzt=0");
  609. break;
  610. case '3':
  611. $RESS = M()->query("select data2 from sp_hj2017 where id=".$id);
  612. $res_id = M()->query("select id from sp_hj2017 where device_code='" . $Data['device_code'] . "' and data2='" . $RESS[0]['data2'] . "' and clzt=0");
  613. break;
  614. case '7':
  615. $RESS = M()->query("select data2 from sp_ef2017 where id=".$id);
  616. $res_id = M()->query("select * from sp_ef2017 where device_code='" . $Data['device_code'] . "' and data1='" . $RESS[0]['data1'] . "' and clzt=0");
  617. break;
  618. default:
  619. $cs66 = '';
  620. break;
  621. }
  622. if (!empty($res_id)){
  623. foreach ($res_id as $key=>$value){
  624. $cs66[$key] = [
  625. 'SubType' => $types_data[0]['dwtype'],
  626. 'DeviceId' => $Data['device_code'],
  627. 'InsertId' => $res_id[$key]['id'],
  628. 'Confirmed' => true,
  629. ];
  630. }
  631. }
  632. }
  633. //告警处理
  634. if ($if_batch==1){//批量处理
  635. $where['device_code']=$device_code;
  636. $where['clzt']=0;
  637. $R=$Tabs->where($where)->save($data);
  638. }else{
  639. $where['id']=$id;
  640. $R=$Tabs->where($where)->save($data);
  641. }
  642. $url1 = 'http://47.98.201.187:55335/report';
  643. if ($if_batch==1){//批量个处理
  644. //总队推送
  645. if ($typess==1||$typess==2||$typess==3||$typess==7||$typess==5){
  646. if (!empty($cs66)){
  647. foreach ($cs66 as $key=>$value){
  648. $cs88 = json_encode($cs66[$key]);
  649. http_post_advertise($url1, $cs88);
  650. }
  651. }
  652. }
  653. //Redis储存
  654. if ($typess==1){
  655. if (!empty($res_id[0]['data4'])){
  656. $port=mb_substr($res_id[0]['data4'],4,1,'utf-8');
  657. // $port=substr($res_id[0]['data4'],3,1);
  658. }else{
  659. $port='';
  660. }
  661. if (!empty($res_id[0]['data3'])){
  662. $Source_code=str_replace(',','',$res_id[0]['data3']);
  663. }else{
  664. $Source_code='';
  665. }
  666. $unique_number=$Data['device_code'].$port.$Source_code;
  667. }elseif ($typess==2){
  668. $unique_number=$Data['device_code'];
  669. }elseif ($typess==3){
  670. $unique_number=$Data['device_code'];
  671. }elseif ($typess==6){
  672. $unique_number=$Data['device_code'].$port.$Source_code.$Data['data4'].' '.$Data['data2'];
  673. }elseif ($typess==7){
  674. $port=$res_id[0]['port'];
  675. $unique_number=$Data['device_code'].$port;
  676. }else{
  677. $unique_number=$Data['device_code'];
  678. }
  679. $this->setRedisData($unique_number);
  680. }else{//单个处理
  681. //消防总队推送
  682. if (!empty($company_data)){
  683. if ($typess == 1 || $typess == 2 || $typess == 3 || $typess == 7|| $typess == 5|| $typess == 6) {
  684. $cs = [
  685. 'SubType' => $typess,
  686. 'DeviceId' => $Data['device_code'],
  687. 'InsertId' => $Data['id'],
  688. 'Confirmed' => true,
  689. ];
  690. $cs3 = json_encode($cs);
  691. http_post_advertise($url1, $cs3);
  692. }
  693. }
  694. //MQTT推送
  695. if ($typess == 2) {
  696. $MQTT_RESS = M("sj2017")->where("id",$id)->find();
  697. switch ($MQTT_RESS['data1']) {
  698. case 'WP1':
  699. $ftypewtype='低压';
  700. break;
  701. case 'WP2':
  702. $ftypewtype='高压';
  703. break;
  704. }
  705. if ($ftypewtype=='低压'||$ftypewtype=="高压"){
  706. $device = ytapi_query("SELECT * FROM yt_t_mhwater WHERE device_code='".$Data['device_code']."' AND push_status=1");
  707. if (!empty($device)){
  708. $tiem_data = date('Y-m-d H:i:s', time());
  709. $json_data_four=$this->date_array_turn_json($Data['id'],$device[0],strtotime($tiem_data),$ftypewtype,1,'','');
  710. if (!empty($json_data_four)){
  711. $this->message_push_mh("mh/water/statistics",$json_data_four,0);
  712. }
  713. }
  714. }
  715. }
  716. //Redis储存
  717. if ($typess==1){
  718. $res_id = M()->query("select data3,data4 from sp_hj2017 where id=" . $Data['id']);
  719. if (!empty($res_id[0]['data4'])){
  720. $port=mb_substr($res_id[0]['data4'],4,1,'utf-8');
  721. // $port=substr($res_id[0]['data4'],3,1);
  722. }else{
  723. $port='';
  724. }
  725. if (!empty($res_id[0]['data3'])){
  726. $Source_code=str_replace(',','',$res_id[0]['data3']);
  727. }else{
  728. $Source_code='';
  729. }
  730. $unique_number=$Data['device_code'].$port.$Source_code;
  731. }else if ($typess==6){
  732. $port=$Data['port'];
  733. $Source_code=$Data['ncmd'];
  734. $unique_number=$Data['device_code'].$port.$Source_code.$Data['data4'].' '.$Data['data2'];
  735. }else if ($typess==7){
  736. $res_id = M()->query("select port from sp_ef2017 where id=" . $Data['id']);
  737. $port=$res_id[0]['port'];
  738. $unique_number=$Data['device_code'].$port;
  739. }else{
  740. $unique_number=$Data['device_code'];
  741. }
  742. $this->setRedisData($unique_number);
  743. }
  744. if ($R){
  745. $res['msg'] = '操作成功';
  746. $res['flag'] = true;
  747. echo json_encode($res);
  748. }else{
  749. $res['msg'] = '操作失败';
  750. $res['flag'] = false;
  751. echo json_encode($res);
  752. }
  753. }
  754. //Redis
  755. public function setRedisData($unique_number){
  756. //redis储存处理的设备
  757. $redis = new \Redis();
  758. $result = $redis->connect('47.98.201.73', 6379);
  759. $redis->auth("usky2021");
  760. if ($result==1){
  761. $redis->set("$unique_number",1);
  762. $redis->close();
  763. }
  764. }
  765. //MQTT
  766. public function message_push_mh($topic,$msg,$qos){
  767. // vendor('phpMQTT.phpMQTT');
  768. $server = '47.98.201.73'; // 服务器IP
  769. $port = 1883; // 服务器端口
  770. $username = 'usky'; // 用户名
  771. $password = 'usky'; // 密码
  772. $client_id = 'pub_' . uniqid();
  773. $mqtt = new \phpMQTT($server, $port, $client_id);
  774. if ($mqtt->connect(true, NULL, $username, $password)) {
  775. $mqtt->publish($topic, $msg, $qos);
  776. usleep(100000);
  777. $mqtt->close();
  778. // Log::record('MH—4G-MQTT-Push success!('.$topic.')['.date('Y-m-d H:i:s').']:'.json_encode($msg));
  779. } else {
  780. // Log::record('MH—4G-MQTT-Time out!('.$topic.')['.date('Y-m-d H:i:s').']:'.json_encode($msg));
  781. }
  782. }
  783. //获取消防栓设备编号
  784. public function getDeviceCode1($company)
  785. {
  786. $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.")");
  787. $str = "";
  788. foreach ($device as $val) {
  789. $str .= "'" . $val['owner_code'] . "',";
  790. }
  791. $newstr = substr($str, 0, strlen($str) - 1);
  792. return $newstr;
  793. }
  794. }