ComprehensiveAlarmController.class.php.bak.2021-08-27 31 KB

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