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

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