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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. class ComprehensiveAlarmController extends ComController
  5. {
  6. //综合告警各类型数据统计
  7. public function getAlarmStatistics()
  8. {
  9. $Date = I();
  10. $company_code = $Date['company_code'];
  11. if (empty($company_code)) {
  12. $res['msg'] = '操作失败,缺少关键参数company_code';
  13. $res['flag'] = false;
  14. echo json_encode($res);
  15. exit();
  16. }
  17. $device_list = $this->getDeviceCode($company_code);
  18. $device_list1 = $this->getDeviceCode1($company_code);
  19. if (!empty($device_list)){
  20. //报警主机未处理数量统计
  21. $untreated_alarm_host_count = M()->query("select count(*) as untreated_alarm_host_count from sp_hj2017 where clzt=0 and device_code in(" . $device_list . ")");
  22. //消防水未处理数量统计
  23. $untreated_fire_water_count1 = M()->query("select count(*) as untreated_fire_water_count from sp_sj2017 where clzt=0 and device_code in(" . $device_list . ")");
  24. $untreated_fire_water_count = (int)$untreated_fire_water_count1[0]['untreated_fire_water_count'] - (int)$untreated_fire_hydrant_count[0]['untreated_fire_hydrant_count'];
  25. //电气火灾未处理数量统计
  26. $untreated_electrical_fire_count = M()->query("select count(*) as untreated_electrical_fire_count from sp_ef2017 where clzt=0 and device_code in(" . $device_list . ")");
  27. //视频监测未处理数量统计
  28. $untreated_video_monitoring_count = M()->query("select count(*) as untreated_video_monitoring_count from sp_video2017 where clzt=0 and device_code in(" . $device_list . ")");
  29. //井盖未处理数量统计
  30. $untreated_manhole_cover_count = M()->query("select count(*) as untreated_manhole_cover_count from sp_iw2017 where clzt=0 and device_code in(" . $device_list . ")");
  31. //门禁未处理数量统计
  32. $untreated_door_count = M()->query("select count(*) as untreated_door_count from sp_door2020 where clzt=0 and device_code in(" . $device_list . ")");
  33. //可燃气体未处理数量统计
  34. $untreated_gas_count = M()->query("select count(*) as untreated_gas_count from sp_gas2020 where clzt=0 and device_code in(" . $device_list . ")");
  35. //地磁未处理数量统计
  36. $untreated_geomagnetism_count = M()->query("select count(*) as untreated_geomagnetism_count from sp_dc2020 where clzt=0 and device_code in(" . $device_list . ")");
  37. //RTU未处理数量统计
  38. $untreated_rtu_count = M()->query("select count(*) as untreated_rtu_count from sp_rtu2017 where clzt=0 and device_code in(" . $device_list . ")");
  39. //电梯未处理数量统计
  40. $untreated_elevator_count = M()->query("select count(*) as untreated_elevator_count from sp_lifter2017 where clzt=0 and device_code in(" . $device_list . ")");
  41. $data[0]['untreated_alarm_host_count'] = (int)$untreated_alarm_host_count[0]['untreated_alarm_host_count'];
  42. $data[0]['untreated_fire_water_count'] = (int)$untreated_fire_water_count;
  43. $data[0]['untreated_electrical_fire_count'] = (int)$untreated_electrical_fire_count[0]['untreated_electrical_fire_count'];
  44. $data[0]['untreated_video_monitoring_count'] = (int)$untreated_video_monitoring_count[0]['untreated_video_monitoring_count'];
  45. $data[0]['untreated_manhole_cover_count'] = (int)$untreated_manhole_cover_count[0]['untreated_manhole_cover_count'];
  46. $data[0]['untreated_door_count'] = (int)$untreated_door_count[0]['untreated_door_count'];
  47. $data[0]['untreated_gas_count'] = (int)$untreated_gas_count[0]['untreated_gas_count'];
  48. $data[0]['untreated_geomagnetism_count'] = (int)$untreated_geomagnetism_count[0]['untreated_geomagnetism_count'];
  49. $data[0]['untreated_rtu_count'] = (int)$untreated_rtu_count[0]['untreated_rtu_count'];
  50. $data[0]['untreated_elevator_count'] = (int)$untreated_elevator_count[0]['untreated_elevator_count'];
  51. }else{
  52. $data[0]['untreated_alarm_host_count'] = 0;
  53. $data[0]['untreated_fire_water_count'] = 0;
  54. $data[0]['untreated_electrical_fire_count'] = 0;
  55. $data[0]['untreated_video_monitoring_count'] = 0;
  56. $data[0]['untreated_manhole_cover_count'] = 0;
  57. $data[0]['untreated_door_count'] = 0;
  58. $data[0]['untreated_gas_count'] = 0;
  59. $data[0]['untreated_geomagnetism_count'] = 0;
  60. $data[0]['untreated_rtu_count'] = 0;
  61. $data[0]['untreated_elevator_count'] = 0;
  62. }
  63. if (!empty($device_list1)){
  64. //消火栓未处理统计
  65. $untreated_fire_hydrant_count = M()->query("select count(*) as untreated_fire_hydrant_count from sp_sj2017 where clzt=0 and device_code in(" . $device_list1 . ")");
  66. $data[0]['untreated_fire_hydrant_count'] = (int)$untreated_fire_hydrant_count[0]['untreated_fire_hydrant_count'];
  67. }else{
  68. $data[0]['untreated_fire_hydrant_count'] = 0;
  69. }
  70. $data[0]['company_code'] = $company_code;
  71. $res['msg'] = '操作成功';
  72. $res['flag'] = true;
  73. $res['data'] = $data;
  74. echo json_encode($res);
  75. }
  76. public function getIntegratedAlarmList()
  77. {
  78. $Date = I();
  79. $company_code = $Date['company_code'];
  80. $type = $Date['type'];
  81. $processing_status = $Date['processing_status'];
  82. if (empty($company_code) && empty($type) && empty($processing_status)) {
  83. $res['msg'] = '操作失败,缺少关键参数';
  84. $res['flag'] = false;
  85. echo json_encode($res);
  86. exit();
  87. }
  88. switch ($type) {
  89. case '1'://烟感和报警主机
  90. $table = 'sp_hj2017';
  91. $types = '1,3';
  92. break;
  93. case '2'://水表和液位
  94. $table = 'sp_sj2017';
  95. $types = '2,5';
  96. break;
  97. case '4'://消防栓
  98. $table = 'sp_sj2017';
  99. $types = $type;
  100. break;
  101. case '6'://RTU
  102. $table = 'sp_rtu2017';
  103. $types = $type;
  104. break;
  105. case '7'://电气火灾
  106. $table = 'sp_ef2017';
  107. $types = $type;
  108. break;
  109. case '16'://视频监测
  110. $table = 'sp_video2017';
  111. $types = $type;
  112. break;
  113. case '17'://电梯监测
  114. $table = 'sp_lifter2017';
  115. $types = $type;
  116. break;
  117. case '128'://井盖
  118. $table = 'sp_iw2017';
  119. $types = $type;
  120. break;
  121. case '129'://地磁
  122. $table = 'sp_dc2020';
  123. $types = $type;
  124. break;
  125. case '130'://门禁
  126. $table = 'sp_door2020';
  127. $types = $type;
  128. break;
  129. case '131'://可燃气体
  130. $table = 'sp_gas2020';
  131. $types = $type;
  132. break;
  133. default:
  134. $res['msg'] = '操作失败,设备类型尚未定义,请联系管理员';
  135. $res['flag'] = 3002;
  136. echo json_encode($res);
  137. exit();
  138. break;
  139. }
  140. // $alarm_count = M()->query("SELECT count(*) as alarm_count FROM " . $table . " AS a JOIN sp_owner AS b ON a.device_code=b.owner_code WHERE b.dwtype in(" . $types . ") AND b.company='" . $company_code . "' AND clzt=" . $processing_status);
  141. $alarm_list = M()->query("SELECT a.id,a.device_code,a.time,a.data1,a.data4,a.data2,a.clzt,b.company AS company_code,b.owner_name,b.unitinfo,b.dwtype as type FROM " . $table . " AS a JOIN sp_owner AS b ON a.device_code=b.owner_code WHERE b.dwtype in(" . $types . ") AND b.company='" . $company_code . "' AND clzt=" . $processing_status . " ORDER BY time DESC LIMIT 1000");
  142. $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,3';
  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,5';
  394. $where['data1'] = $Data['data1'];
  395. break;
  396. case '4'://消防栓
  397. $table = 'sp_sj2017';
  398. $Tabs = M('sj2017');
  399. $types = $type;
  400. break;
  401. case '6'://RTU
  402. $table = 'sp_rtu2017';
  403. $Tabs = M('rtu2017');
  404. $types = $type;
  405. $where['ncmd'] = $Data['ncmd'];
  406. $where['data2'] = $Data['data2'];
  407. $where['data4'] = $Data['data4'];
  408. break;
  409. case '7'://电气火灾
  410. $table = 'sp_ef2017';
  411. $Tabs = M('ef2017');
  412. $types = $type;
  413. $where['data1'] = $Data['data1'];
  414. break;
  415. case '16'://视频监测
  416. $table = 'sp_video2017';
  417. $Tabs = M('video2017');
  418. $types = $type;
  419. break;
  420. case '17'://电梯监测
  421. $table = 'sp_lifter2017';
  422. $Tabs = M('lifter2017');
  423. $types = $type;
  424. break;
  425. case '128'://井盖
  426. $table = 'sp_iw2017';
  427. $Tabs = M('iw2017');
  428. $types = $type;
  429. break;
  430. case '129'://地磁
  431. $table = 'sp_dc2020';
  432. $Tabs = M('dc2020');
  433. $types = $type;
  434. break;
  435. case '130'://门禁
  436. $table = 'sp_door2020';
  437. $Tabs = M('door2020');
  438. $types = $type;
  439. break;
  440. case '131'://可燃气体
  441. $table = 'sp_gas2020';
  442. $Tabs = M('gas2020');
  443. $types = $type;
  444. break;
  445. default:
  446. $res['msg'] = '操作失败,设备类型尚未定义,请联系管理员';
  447. $res['flag'] = false;
  448. echo json_encode($res);
  449. exit();
  450. break;
  451. }
  452. //修改条件
  453. $data['clzt']=1;
  454. $data['clwb']=$clwb;
  455. $data['clnr']=$clnr;
  456. $data['cldh']=$clr;
  457. $data['clr']=$clr;
  458. $data['clsj']=date("Y-m-d");
  459. $types_data=M()->query("select dwtype from sp_owner where owner_code='".$Data['device_code']."'");
  460. $typess=$types_data[0]['dwtype'];
  461. if ($if_batch==1){//批量处理
  462. $where['device_code']=$device_code;
  463. $where['clzt']=0;
  464. $R=$Tabs->where($where)->save($data);
  465. }else{
  466. $where['id']=$id;
  467. $R=$Tabs->where($where)->save($data);
  468. }
  469. $url1 = 'http://47.98.201.187:55335/report';
  470. if ($if_batch==1){
  471. if ($typess==1){
  472. $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;");
  473. $cs66 = [
  474. 'SubType' => 1,
  475. 'DeviceId' => $Data['device_code'],
  476. 'InsertId' => $res_id[0]['id'],
  477. 'Confirmed' => true,
  478. ];
  479. $cs88 = json_encode($cs66);
  480. $result = http_post_advertise($url1, $cs88);
  481. if (!empty($res_id[0]['data4'])){
  482. $port=mb_substr($res_id[0]['data4'],4,1,'utf-8');
  483. // $port=substr($res_id[0]['data4'],3,1);
  484. }else{
  485. $port='';
  486. }
  487. if (!empty($res_id[0]['data3'])){
  488. $Source_code=str_replace(',','',$res_id[0]['data3']);
  489. }else{
  490. $Source_code='';
  491. }
  492. $unique_number=$Data['device_code'].$port.$Source_code;
  493. }elseif ($typess==2){
  494. $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");
  495. $cs66 = [
  496. 'SubType' => 2,
  497. 'DeviceId' => $Data['device_code'],
  498. 'InsertId' => $res_id[0]['id'],
  499. 'Confirmed' => true,
  500. ];
  501. $cs88 = json_encode($cs66);
  502. $result = http_post_advertise($url1, $cs88);
  503. $unique_number=$Data['device_code'];
  504. }elseif ($typess==3){
  505. $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");
  506. $cs66 = [
  507. 'SubType' => 3,
  508. 'DeviceId' => $Data['device_code'],
  509. 'InsertId' => $res_id[0]['id'],
  510. 'Confirmed' => true,
  511. ];
  512. $url1 = 'http://47.98.201.187:55335/report';
  513. $cs88 = json_encode($cs66);
  514. $result = http_post_advertise($url1, $cs88);
  515. $unique_number=$Data['device_code'];
  516. }elseif ($typess==6){
  517. $unique_number=$Data['device_code'].$port.$Source_code.$Data['data4'].' '.$Data['data2'];
  518. }elseif ($typess==7){
  519. $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");
  520. $cs66 = [
  521. 'SubType' => 7,
  522. 'DeviceId' => $Data['device_code'],
  523. 'InsertId' => $res_id[0]['id'],
  524. 'Confirmed' => true,
  525. ];
  526. $url1 = 'http://47.98.201.187:55335/report';
  527. $cs88 = json_encode($cs66);
  528. $result = http_post_advertise($url1, $cs88);
  529. $port=$res_id[0]['port'];
  530. $unique_number=$Data['device_code'].$port;
  531. }else{
  532. $unique_number=$Data['device_code'];
  533. }
  534. //redis链接
  535. // $redis = new \Redis();
  536. // $result = $redis->connect('127.0.0.1', 6379);
  537. // if ($result==1){
  538. // $redis->set("$unique_number",1);
  539. // $redis->close();
  540. // }
  541. }else{
  542. $cs = [
  543. 'SubType' => $typess,
  544. 'DeviceId' => $Data['device_code'],
  545. 'InsertId' => $Data['id'],
  546. 'Confirmed' => true,
  547. ];
  548. if ($typess == 1 || $typess == 2 || $typess == 3 || $typess == 7) {
  549. $url = 'http://47.98.201.187:55335/report';
  550. $cs3 = json_encode($cs);
  551. $result = http_post_advertise($url, $cs3);
  552. }
  553. if ($typess==1){
  554. $res_id = M()->query("select data3,data4 from sp_hj2017 where id=" . $Data['id']);
  555. if (!empty($res_id[0]['data4'])){
  556. $port=mb_substr($res_id[0]['data4'],4,1,'utf-8');
  557. // $port=substr($res_id[0]['data4'],3,1);
  558. }else{
  559. $port='';
  560. }
  561. if (!empty($res_id[0]['data3'])){
  562. $Source_code=str_replace(',','',$res_id[0]['data3']);
  563. }else{
  564. $Source_code='';
  565. }
  566. $unique_number=$Data['device_code'].$port.$Source_code;
  567. }else if ($typess==6){
  568. $port=$Data['port'];
  569. $Source_code=$Data['ncmd'];
  570. $unique_number=$Data['device_code'].$port.$Source_code.$Data['data4'].' '.$Data['data2'];
  571. }else if ($typess==7){
  572. $res_id = M()->query("select port from sp_ef2017 where id=" . $Data['id']);
  573. $port=$res_id[0]['port'];
  574. $unique_number=$Data['device_code'].$port;
  575. }else{
  576. $unique_number=$Data['device_code'];
  577. }
  578. //redis储存处理的设备
  579. // $redis = new \Redis();
  580. // $result = $redis->connect('127.0.0.1', 6379);
  581. // if ($result==1){
  582. // $redis->set("$unique_number",1);
  583. // $redis->close();
  584. // }
  585. }
  586. // $data = array("devicestatus" => 0);
  587. // $str_where = "deviceid='" . $Data['device_code'] . "'";
  588. // $str_sql_upd = M('devices_status')->where($str_where)->save($data);
  589. if ($R){
  590. $res['msg'] = '操作成功';
  591. $res['flag'] = true;
  592. echo json_encode($res);
  593. }else{
  594. $res['msg'] = '操作失败';
  595. $res['flag'] = 3002;
  596. echo json_encode($res);
  597. }
  598. }
  599. //获取消防栓设备编号
  600. public function getDeviceCode1($company)
  601. {
  602. $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.")");
  603. $str = "";
  604. foreach ($device as $val) {
  605. $str .= "'" . $val['owner_code'] . "',";
  606. }
  607. $newstr = substr($str, 0, strlen($str) - 1);
  608. return $newstr;
  609. }
  610. }