123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850 |
- <?php
- namespace Home\Controller;
- use Think\Controller;
- include '../Common/function.php';
- include '../../../../USKYZHAF/Public/vendor/phpMQTT/phpMQTT.php';
- class ComprehensiveAlarmController extends ComController
- {
- //综合告警各类型数据统计
- public function getAlarmStatistics()
- {
- $Date = I();
- $company_code = $Date['company_code'];
- if (empty($company_code)) {
- $res['msg'] = '操作失败,缺少关键参数company_code';
- $res['flag'] = false;
- echo json_encode($res);
- exit();
- }
- $device_list = $this->getDeviceCode($company_code);
- $device_list1 = $this->getDeviceCode1($company_code);
- $where2['company_code'] = $company_code;
- $data_statistics = M('company_sync')->where($where2)->find();
- if(!empty($data_statistics)){
- //报警主机未处理数量统计
- $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'];
- //消防水未处理数量统计
- $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'])
- +$data_statistics['device_00_out']-$data_statistics['device_00_out_confirm']+$data_statistics['device_02_out']-$data_statistics['device_02_out_confirm'];
- //RTU未处理数量统计
- $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'];
- //电气火灾未处理数量统计
- $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'];
- //视频监测未处理数量统计
- $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'];
- $data[0]['untreated_alarm_host_count'] = (int)$untreated_alarm_host_count;
- $data[0]['untreated_fire_water_count'] = (int)$untreated_fire_water_count1;
- $data[0]['untreated_rtu_count'] = (int)$untreated_rtu_count;
- $data[0]['untreated_electrical_fire_count'] = (int)$untreated_electrical_fire_count;
- $data[0]['untreated_video_monitoring_count'] = (int)$untreated_video_monitoring_count;
- }else{
- $data[0]['untreated_alarm_host_count'] = 0;
- $data[0]['untreated_fire_water_count'] = 0;
- $data[0]['untreated_rtu_count'] = 0;
- $data[0]['untreated_electrical_fire_count'] = 0;
- $data[0]['untreated_video_monitoring_count'] = 0;
- }
- if (!empty($device_list)){
- // //报警主机未处理数量统计
- // $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."'");
- //// $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 . ")");
- // //消防水未处理数量统计
- //// $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 . ")");
- // $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."'");
- //
- // //$untreated_fire_water_count = (int)$untreated_fire_water_count1[0]['untreated_fire_water_count'] - (int)$untreated_fire_hydrant_count[0]['untreated_fire_hydrant_count'];
- // //电气火灾未处理数量统计
- // $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 . ")");
- // //视频监测未处理数量统计
- // $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 . ")");
- //井盖未处理数量统计
- $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 . ")");
- //门禁未处理数量统计
- $untreated_door_count = M()->query("select count(*) as untreated_door_count from sp_door2020 where clzt=0 and device_code in(" . $device_list . ")");
- //可燃气体未处理数量统计
- $untreated_gas_count = M()->query("select count(*) as untreated_gas_count from sp_gas2020 where clzt=0 and device_code in(" . $device_list . ")");
- //地磁未处理数量统计
- $untreated_geomagnetism_count = M()->query("select count(*) as untreated_geomagnetism_count from sp_dc2020 where clzt=0 and device_code in(" . $device_list . ")");
- // //RTU未处理数量统计
- // $untreated_rtu_count = M()->query("select count(*) as untreated_rtu_count from sp_rtu2017 where clzt=0 and device_code in(" . $device_list . ")");
- //电梯未处理数量统计
- $untreated_elevator_count = M()->query("select count(*) as untreated_elevator_count from sp_lifter2017 where clzt=0 and device_code in(" . $device_list . ")");
- // $data[0]['untreated_alarm_host_count'] = (int)$untreated_alarm_host_count[0]['untreated_alarm_host_count'];
- // $data[0]['untreated_fire_water_count'] = (int)$untreated_fire_water_count1[0]['untreated_fire_water_count'];
- // $data[0]['untreated_electrical_fire_count'] = (int)$untreated_electrical_fire_count[0]['untreated_electrical_fire_count'];
- // $data[0]['untreated_video_monitoring_count'] = (int)$untreated_video_monitoring_count[0]['untreated_video_monitoring_count'];
- $data[0]['untreated_manhole_cover_count'] = (int)$untreated_manhole_cover_count[0]['untreated_manhole_cover_count'];
- $data[0]['untreated_door_count'] = (int)$untreated_door_count[0]['untreated_door_count'];
- $data[0]['untreated_gas_count'] = (int)$untreated_gas_count[0]['untreated_gas_count'];
- $data[0]['untreated_geomagnetism_count'] = (int)$untreated_geomagnetism_count[0]['untreated_geomagnetism_count'];
- // $data[0]['untreated_rtu_count'] = (int)$untreated_rtu_count[0]['untreated_rtu_count'];
- $data[0]['untreated_elevator_count'] = (int)$untreated_elevator_count[0]['untreated_elevator_count'];
- }else{
- // $data[0]['untreated_alarm_host_count'] = 0;
- // $data[0]['untreated_fire_water_count'] = 0;
- // $data[0]['untreated_electrical_fire_count'] = 0;
- // $data[0]['untreated_video_monitoring_count'] = 0;
- $data[0]['untreated_manhole_cover_count'] = 0;
- $data[0]['untreated_door_count'] = 0;
- $data[0]['untreated_gas_count'] = 0;
- $data[0]['untreated_geomagnetism_count'] = 0;
- // $data[0]['untreated_rtu_count'] = 0;
- $data[0]['untreated_elevator_count'] = 0;
- }
- if (!empty($device_list1)){
- //消火栓未处理统计
- $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 . ")");
- $data[0]['untreated_fire_hydrant_count'] = (int)$untreated_fire_hydrant_count[0]['untreated_fire_hydrant_count'];
- }else{
- $data[0]['untreated_fire_hydrant_count'] = 0;
- }
- $data[0]['company_code'] = $company_code;
- $res['msg'] = '操作成功';
- $res['flag'] = true;
- $res['data'] = $data;
- echo json_encode($res);
- }
- public function getIntegratedAlarmList()
- {
- $Date = I();
- $company_code = $Date['company_code'];
- $type = $Date['type'];
- $processing_status = $Date['processing_status'];
- $start_time = $Date['start_time'];
- $end_time = $Date['end_time'];
- if (empty($company_code) && empty($type)) {
- $res['msg'] = '操作失败,缺少关键参数';
- $res['flag'] = false;
- echo json_encode($res);
- exit();
- }
- $where = '';
- if (!empty($start_time)) {
- $where .= " and a.time>='" . $start_time . "' ";
- }
- if (isset($processing_status)) {
- $where .= " and a.clzt='" . $processing_status . "' ";
- }
- if (!empty($start_time)) {
- $where .= " and a.time<'" . $end_time . "' ";
- }
- switch ($type) {
- case '1'://报警主机
- $table = 'sp_hj2017';
- $types = '1';
- break;
- case '2'://水表和液位
- $table = 'sp_sj2017';
- $types = '2,5';
- break;
- case '3'://烟感
- $table = 'sp_hj2017';
- $types = '3';
- break;
- case '4'://消防栓
- $table = 'sp_sj2017';
- $types = $type;
- break;
- case '5'://液位
- $table = 'sp_sj2017';
- $types = '5';
- break;
- case '6'://RTU
- $table = 'sp_rtu2017';
- $types = $type;
- break;
- case '7'://电气火灾
- $table = 'sp_ef2017';
- $types = $type;
- break;
- case '16'://视频监测
- $table = 'sp_video2017';
- $types = $type;
- break;
- case '17'://电梯监测
- $table = 'sp_lifter2017';
- $types = $type;
- break;
- case '128'://井盖
- $table = 'sp_iw2017';
- $types = $type;
- break;
- case '129'://地磁
- $table = 'sp_dc2020';
- $types = $type;
- break;
- case '130'://门禁
- $table = 'sp_door2020';
- $types = $type;
- break;
- case '131'://可燃气体
- $table = 'sp_gas2020';
- $types = $type;
- break;
- default:
- $res['msg'] = '操作失败,设备类型尚未定义,请联系管理员';
- $res['flag'] = 3002;
- echo json_encode($res);
- exit();
- break;
- }
- $start=($Date['page']-1)*$Date['pageSize'];
- if (!empty($Date['pageSize'])){
- $LIMIT=" LIMIT ".$start.",".$Date['pageSize'];
- }
- if ($type==1||$type==2||$type==6||$type==7||$type==16){
- $where2['company_code'] = $company_code;
- $data_statistics = M('company_sync')->where($where2)->find();
- if(!empty($data_statistics)){
- switch ($type) {
- case '1'://报警主机
- if ($processing_status==0){
- $alarm_count = $data_statistics['device_01_alarm']-$data_statistics['device_01_alarm_confirm']+$data_statistics['device_01_out']-$data_statistics['device_01_out_confirm'];
- }else{
- $alarm_count = $data_statistics['device_01_alarm_confirm']+$data_statistics['device_01_out_confirm'];
- }
- break;
- case '2'://水表和液位
- if ($processing_status==0){
- $alarm_count=$data_statistics['device_02_alarm']+$data_statistics['device_00_alarm']-($data_statistics['device_02_alarm_confirm']+$data_statistics['device_00_alarm_confirm'])
- +$data_statistics['device_00_out']-$data_statistics['device_00_out_confirm']+$data_statistics['device_02_out']-$data_statistics['device_02_out_confirm'];
- }else{
- $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'];
- }
- break;
- case '5'://液位和水表
- if ($processing_status==0){
- $alarm_count=$data_statistics['device_02_alarm']+$data_statistics['device_00_alarm']-($data_statistics['device_02_alarm_confirm']+$data_statistics['device_00_alarm_confirm'])
- +$data_statistics['device_00_out']-$data_statistics['device_00_out_confirm']+$data_statistics['device_02_out']-$data_statistics['device_02_out_confirm'];
- }else{
- $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'];
- }
- break;
- case '6'://RTU未处理数量统计
- if ($processing_status==0){
- $alarm_count=$data_statistics['device_06_alarm'] - $data_statistics['device_06_alarm_confirm']+$data_statistics['device_06_out']-$data_statistics['device_06_out_confirm'];
- }else{
- $alarm_count=$data_statistics['device_06_alarm_confirm']+$data_statistics['device_06_out_confirm'];
- }
- break;
- case '7'://电气火灾未处理数量统计
- if ($processing_status==0){
- $alarm_count= $data_statistics['device_07_alarm'] - $data_statistics['device_07_alarm_confirm']+$data_statistics['device_07_out']-$data_statistics['device_07_out_confirm'];
- }else{
- $data_statistics['device_07_alarm_confirm']+$data_statistics['device_07_out_confirm'];
- }
- break;
- case '16'://视频监测未处理数量统计
- if ($processing_status==0){
- $alarm_count=$data_statistics['device_16_alarm'] - $data_statistics['device_16_alarm_confirm']+$data_statistics['device_16_out']-$data_statistics['device_16_out_confirm'];
- }else{
- $alarm_count=$data_statistics['device_16_alarm_confirm']+$data_statistics['device_16_out_confirm'];
- }
- break;
- default:
- break;
- }
- }else{
- $alarm_count = 0;
- }
- }else{
- $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);
- $alarm_count = $alarm_list[0]['alarm_count'];
- }
- // $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);
- if ($type==1){
- $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.company='" . $company_code . "' " . $where . " ORDER BY a.id DESC ".$LIMIT);
- }elseif ($type==2){
- $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(2,5) AND b.company='" . $company_code . "' " . $where . " ORDER BY a.id DESC ".$LIMIT);
- }else{
- $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);
- }
- // $alarm_count =sizeof($alarm_list);
- if ($type == 2 || $type == 4) {
- foreach ($alarm_list as $key => $value) {
- switch ($alarm_list[$key]['data1']) {
- case 'WP1':
- $alarm_list[$key]['data4'] = '低压';
- break;
- case 'WP2':
- $alarm_list[$key]['data4'] = '高压';
- break;
- case 'WP3':
- $alarm_list[$key]['data4'] = '故障';
- break;
- case 'WP4':
- $alarm_list[$key]['data4'] = '离线';
- break;
- case 'LL1':
- $alarm_list[$key]['data4'] = '低水位';
- break;
- case 'LL2':
- $alarm_list[$key]['data4'] = '高水位';
- break;
- default:
- $alarm_list[$key]['data4'] = '其他' . $alarm_list[$key]['data1'];
- break;
- }
- }
- } else if ($type == 7) {
- foreach ($alarm_list as $key => $value) {
- if ($alarm_list[$key]['data1'] == 'EF1') {
- $alarm_list[$key]['data4'] = '欠压报警';
- } elseif ($alarm_list[$key]['data1'] == 'EF2') {
- $alarm_list[$key]['data4'] = '过压报警';
- } elseif ($alarm_list[$key]['data1'] == 'EF3') {
- $alarm_list[$key]['data4'] = '过流报警';
- } elseif ($alarm_list[$key]['data1'] == 'EF4') {
- $alarm_list[$key]['data4'] = '漏电报警';
- } elseif ($alarm_list[$key]['data1'] == 'EF5') {
- $alarm_list[$key]['data4'] = '回路1温度超限报警';
- } elseif ($alarm_list[$key]['data1'] == 'EF6') {
- $alarm_list[$key]['data4'] = '回路2温度超限报警';
- } elseif ($alarm_list[$key]['data1'] == 'EF7') {
- $alarm_list[$key]['data4'] = '回路3温度超限报警';
- } elseif ($alarm_list[$key]['data1'] == 'EF8') {
- $alarm_list[$key]['data4'] = '回路4温度超限报警';
- } elseif ($alarm_list[$key]['data1'] == 'EF9') {
- $alarm_list[$key]['data4'] = '离线';
- } else {
- $alarm_list[$key]['data4'] = '其他' . $alarm_list[$key]['data1'];
- }
- }
- }
- $res['msg'] = '操作成功';
- $res['flag'] = true;
- $res['alarm_count'] = (int)$alarm_count;
- $res['data'] = $alarm_list;
- echo json_encode($res);
- }
- public function getAlarmDetails()
- {
- $Date = I();
- // print_r($Date);
- $id = $Date['id'];
- $type = $Date['type'];
- // $processing_status = $Date['processing_status'];
- if (empty($id) && empty($type)) {
- $res['msg'] = '操作失败,缺少关键参数';
- $res['flag'] = 3001;
- echo json_encode($res);
- exit();
- }
- switch ($type) {
- case '1'://报警主机
- $table = 'sp_hj2017';
- $types = '1';
- break;
- case '2'://水表和液位
- $table = 'sp_sj2017';
- $types = '2,';
- break;
- case '3'://烟感
- $table = 'sp_hj2017';
- $types = '3';
- break;
- case '4'://消防栓
- $table = 'sp_sj2017';
- $types = $type;
- break;
- case '5'://液位
- $table = 'sp_sj2017';
- $types = '5';
- break;
- case '6'://RTU
- $table = 'sp_rtu2017';
- $types = $type;
- break;
- case '7'://电气火灾
- $table = 'sp_ef2017';
- $types = $type;
- break;
- case '16'://视频监测
- $table = 'sp_video2017';
- $types = $type;
- break;
- case '17'://电梯监测
- $table = 'sp_lifter2017';
- $types = $type;
- break;
- case '128'://井盖
- $table = 'sp_iw2017';
- $types = $type;
- break;
- case '129'://地磁
- $table = 'sp_dc2020';
- $types = $type;
- break;
- case '130'://门禁
- $table = 'sp_door2020';
- $types = $type;
- break;
- case '131'://可燃气体
- $table = 'sp_gas2020';
- $types = $type;
- break;
- default:
- $res['msg'] = '操作失败,设备类型尚未定义,请联系管理员';
- $res['flag'] = 3002;
- echo json_encode($res);
- exit();
- break;
- }
- if ($type == 128){
- $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);
- }elseif($type == 130||$type == 131){
- $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);
- }else{
- // 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);
- $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);
- }
- if($type == 1){
- $list[0]['alarm_information'] = $list[0]['data2'];
- }elseif ($type == 2 || $type == 4) {
- switch ($list[0]['data1']) {
- case 'WP1':
- $list[0]['alarm_information'] = '低压';
- break;
- case 'WP2':
- $list[0]['alarm_information'] = '高压';
- break;
- case 'WP3':
- $list[0]['alarm_information'] = '故障';
- break;
- case 'WP4':
- $list[0]['alarm_information'] = '离线';
- break;
- case 'LL1':
- $list[0]['alarm_information'] = '低水位';
- break;
- case 'LL2':
- $list[0]['alarm_information'] = '高水位';
- break;
- default:
- $list[0]['alarm_information'] = '其他' . $list[0]['data1'];
- break;
- }
- if ($list[0]['dwtype'] == 5) {
- $list[0]['numerical_value'] = '水位值:' . $list[0]['data4'] . 'M';
- } else {
- $list[0]['numerical_value'] = '水压值:' . $list[0]['data4'] . 'Mpa';
- }
- }else if ($type == 6){
- $list[0]['alarm_information'] =$list[0]['data2'];
- if ($list[0]['port'] == 'E6') {
- if ($list[0]['data2'] == '低压' || $list[0]['data2'] == '高压') {
- $list[0]['numerical_value'] = '水压值:' . $list[0]['data1'] . 'Mpa';
- } elseif ($list[0]['data2'] == '低水位' || $list[0]['data2'] == '高水位') {
- $list[0]['numerical_value'] = '水位:' . $list[0]['data1'] . 'M';
- } elseif ($list[0]['data2'] == '低温' || $list[0]['data2'] == '高温') {
- $list[0]['numerical_value'] = '温度:' . $list[0]['data1'] . '℃';
- } elseif ($list[0]['data2'] == '低湿度' || $list[0]['data2'] == '高湿度') {
- $list[0]['numerical_value'] = '湿度:' . $list[0]['data1'] . '%';
- }else if ($list[0]['data2'] == '设备异常'){
- $list[0]['numerical_value'] = $list[0]['data4'].':'.$list[0]['data1'];
- } else {
- $list[0]['numerical_value'] = $list[0]['data4'];
- }
- } else {
- $list[0]['numerical_value'] = $list[0]['data4'];
- }
- }else if ($type == 7) {
- if ($list[0]['data1'] == 'EF1') {
- $list[0]['alarm_information'] = '欠压报警';
- $list[0]['numerical_value'] = 'A相欠压值:' . $list[0]['data2'] . 'V B相欠压值:' . $list[0]['data3'] . 'V C相欠压值:' . $list[0]['data4'] . 'V';
- } elseif ($list[0]['data1'] == 'EF2') {
- $list[0]['alarm_information'] = '过压报警';
- $list[0]['numerical_value'] = 'A相过压值:' . $list[0]['data2'] . 'V B相过压值:' . $list[0]['data3'] . 'V C相过压值:' . $list[0]['data4'] . 'V';
- } elseif ($list[0]['data1'] == 'EF3') {
- $list[0]['alarm_information'] = '过流报警';
- $list[0]['numerical_value'] = 'A相过流值:' . $list[0]['data2'] . 'mA B相过流值:' . $list[0]['data3'] . 'mA C相过流值:' . $list[0]['data4'] . 'mA';
- } elseif ($list[0]['data1'] == 'EF4') {
- $list[0]['alarm_information'] = '漏电报警';
- $list[0]['numerical_value'] = '漏电流值:' . $list[0]['data2'] . 'mA';
- } elseif ($list[0]['data1'] == 'EF5') {
- $list[0]['alarm_information'] = '回路1温度超限报警';
- $list[0]['numerical_value'] = '温度1值:' . $list[0]['data2'] . '℃';
- } elseif ($list[0]['data1'] == 'EF6') {
- $list[0]['alarm_information'] = '回路2温度超限报警';
- $list[0]['numerical_value'] = '温度2值:' . $list[0]['data2'] . '℃';
- } elseif ($list[0]['data1'] == 'EF7') {
- $list[0]['alarm_information'] = '回路3温度超限报警';
- $list[0]['numerical_value'] = '温度3值:' . $list[0]['data2'] . '℃';
- } elseif ($list[0]['data1'] == 'EF8') {
- $list[0]['alarm_information'] = '回路4温度超限报警';
- $list[0]['numerical_value'] = '温度4值:' . $list[0]['data2'] . '℃';
- } elseif ($list[0]['data1'] == 'EF9') {
- $list[0]['alarm_information'] = '离线';
- $list[0]['numerical_value'] = '设备离线';
- } else {
- $list[0]['alarm_information'] = '其他' . $list[0]['data1'];
- }
- }elseif($type == 128){
- if ($list[0]['device_status']==1){
- $list[0]['alarm_information'] = "设备异常";
- }else{
- $list[0]['alarm_information'] = "设备正常";
- }
- }else{
- $list[0]['alarm_information'] = $list[0]['data4'];
- }
- $res['msg'] = '操作成功';
- $res['flag'] = true;
- $res['data'] = $list;
- echo json_encode($res);
- }
- public function setAlarmHandling(){
- $Data = I();
- $id = $Data['id'];
- $type = $Data['type'];
- $device_code = $Data['device_code'];
- $if_batch = $Data['if_batch'];
- $clwb = $Data['clwb'];
- $clnr = $Data['clnr'];
- $clr = $_SESSION['phone'];
- $port = $Data['port'];
- $Source_code=$Data['ncmd'];
- if (empty($id) && empty($type)&& empty($device_code)&& empty($clwb)&& empty($Data['data2'])&& empty($Data['data5'])&& empty($Data['data1'])&& empty($Source_code)) {
- $res['msg'] = '操作失败,缺少关键参数';
- $res['flag'] = false;
- echo json_encode($res);
- exit();
- }
- switch ($type) {
- case '1'://报警主机
- $table = 'sp_hj2017';
- $Tabs = M('hj2017');
- $types = '1';
- // $where['data2'] = $Data['data2'];
- $where['data3'] = $Data['data3'];
- $where['data5'] = $Data['data5'];
- break;
- case '2'://水表和液位
- $table = 'sp_sj2017';
- $Tabs = M('sj2017');
- $types = '2';
- $where['data1'] = $Data['data1'];
- break;
- case '3'://烟感
- $table = 'sp_hj2017';
- $Tabs = M('hj2017');
- $types = '3';
- $where['data2'] = $Data['data2'];
- break;
- case '4'://消防栓
- $table = 'sp_sj2017';
- $Tabs = M('sj2017');
- $types = $type;
- break;
- case '5'://液位
- $table = 'sp_sj2017';
- $Tabs = M('sj2017');
- $types = '5';
- break;
- case '6'://RTU
- $table = 'sp_rtu2017';
- $Tabs = M('rtu2017');
- $types = $type;
- $where['ncmd'] = $Data['ncmd'];
- $where['data2'] = $Data['data2'];
- $where['data4'] = $Data['data4'];
- break;
- case '7'://电气火灾
- $table = 'sp_ef2017';
- $Tabs = M('ef2017');
- $types = $type;
- $where['data1'] = $Data['data1'];
- break;
- case '16'://视频监测
- $table = 'sp_video2017';
- $Tabs = M('video2017');
- $types = $type;
- break;
- case '17'://电梯监测
- $table = 'sp_lifter2017';
- $Tabs = M('lifter2017');
- $types = $type;
- break;
- case '128'://井盖
- $table = 'sp_iw2017';
- $Tabs = M('iw2017');
- $types = $type;
- break;
- case '129'://地磁
- $table = 'sp_dc2020';
- $Tabs = M('dc2020');
- $types = $type;
- break;
- case '130'://门禁
- $table = 'sp_door2020';
- $Tabs = M('door2020');
- $types = $type;
- break;
- case '131'://可燃气体
- $table = 'sp_gas2020';
- $Tabs = M('gas2020');
- $types = $type;
- break;
- default:
- $res['msg'] = '操作失败,设备类型尚未定义,请联系管理员';
- $res['flag'] = false;
- echo json_encode($res);
- exit();
- break;
- }
- //修改条件
- $data['clzt']=1;
- $data['clwb']=$clwb;
- $data['clnr']=$clnr;
- $data['cldh']=$clr;
- $data['clr']=$clr;
- $data['clsj']=date("Y-m-d H:i:s");
- $types_data=M()->query("select dwtype,company from sp_owner where owner_code='".$Data['device_code']."'");
- $typess=$types_data[0]['dwtype'];
- $company_data=ytapi_query("select * from corps_company where company_code='".$types_data[0]['company']."' and status=1");
- if (!empty($company_data)){
- switch ($types_data[0]['dwtype']) {
- case '1':
- $RESS = M()->query("select data3,data5 from sp_hj2017 where id=".$id);
- $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");
- break;
- case '2':
- case '5':
- $RESS = M()->query("select data1 from sp_sj2017 where id=".$id);
- $res_id = M()->query("select id from sp_sj2017 where device_code='" . $Data['device_code'] . "' and data1='" . $RESS[0]['data1'] . "' and clzt=0");
- break;
- case '3':
- $RESS = M()->query("select data2 from sp_hj2017 where id=".$id);
- $res_id = M()->query("select id from sp_hj2017 where device_code='" . $Data['device_code'] . "' and data2='" . $RESS[0]['data2'] . "' and clzt=0");
- break;
- case '7':
- $RESS = M()->query("select data2 from sp_ef2017 where id=".$id);
- $res_id = M()->query("select * from sp_ef2017 where device_code='" . $Data['device_code'] . "' and data1='" . $RESS[0]['data1'] . "' and clzt=0");
- break;
- default:
- $cs66 = '';
- break;
- }
- if (!empty($res_id)){
- foreach ($res_id as $key=>$value){
- $cs66[$key] = [
- 'SubType' => $types_data[0]['dwtype'],
- 'DeviceId' => $Data['device_code'],
- 'InsertId' => $res_id[$key]['id'],
- 'Confirmed' => true,
- ];
- }
- }
- }
- //告警处理
- if ($if_batch==1){//批量处理
- $where['device_code']=$device_code;
- $where['clzt']=0;
- $R=$Tabs->where($where)->save($data);
- }else{
- $where['id']=$id;
- $R=$Tabs->where($where)->save($data);
- }
- $url1 = 'http://47.98.201.187:55335/report';
- if ($if_batch==1){//批量个处理
- //总队推送
- if ($typess==1||$typess==2||$typess==3||$typess==7||$typess==5){
- if (!empty($cs66)){
- foreach ($cs66 as $key=>$value){
- $cs88 = json_encode($cs66[$key]);
- http_post_advertise($url1, $cs88);
- }
- }
- }
- //Redis储存
- if ($typess==1){
- if (!empty($res_id[0]['data4'])){
- $port=mb_substr($res_id[0]['data4'],4,1,'utf-8');
- // $port=substr($res_id[0]['data4'],3,1);
- }else{
- $port='';
- }
- if (!empty($res_id[0]['data3'])){
- $Source_code=str_replace(',','',$res_id[0]['data3']);
- }else{
- $Source_code='';
- }
- $unique_number=$Data['device_code'].$port.$Source_code;
- }elseif ($typess==2){
- $unique_number=$Data['device_code'];
- }elseif ($typess==3){
- $unique_number=$Data['device_code'];
- }elseif ($typess==6){
- $unique_number=$Data['device_code'].$port.$Source_code.$Data['data4'].' '.$Data['data2'];
- }elseif ($typess==7){
- $port=$res_id[0]['port'];
- $unique_number=$Data['device_code'].$port;
- }else{
- $unique_number=$Data['device_code'];
- }
- $this->setRedisData($unique_number);
- }else{//单个处理
- //消防总队推送
- if (!empty($company_data)){
- if ($typess == 1 || $typess == 2 || $typess == 3 || $typess == 7|| $typess == 5|| $typess == 6) {
- $cs = [
- 'SubType' => $typess,
- 'DeviceId' => $Data['device_code'],
- 'InsertId' => $Data['id'],
- 'Confirmed' => true,
- ];
- $cs3 = json_encode($cs);
- http_post_advertise($url1, $cs3);
- }
- }
- //MQTT推送
- if ($typess == 2) {
- $MQTT_RESS = M("sj2017")->where("id",$id)->find();
- switch ($MQTT_RESS['data1']) {
- case 'WP1':
- $ftypewtype='低压';
- break;
- case 'WP2':
- $ftypewtype='高压';
- break;
- }
- if ($ftypewtype=='低压'||$ftypewtype=="高压"){
- $device = ytapi_query("SELECT * FROM yt_t_mhwater WHERE device_code='".$Data['device_code']."' AND push_status=1");
- if (!empty($device)){
- $tiem_data = date('Y-m-d H:i:s', time());
- $json_data_four=$this->date_array_turn_json($Data['id'],$device[0],strtotime($tiem_data),$ftypewtype,1,'','');
- if (!empty($json_data_four)){
- $this->message_push_mh("mh/water/statistics",$json_data_four,0);
- }
- }
- }
- }
- //Redis储存
- if ($typess==1){
- $res_id = M()->query("select data3,data4 from sp_hj2017 where id=" . $Data['id']);
- if (!empty($res_id[0]['data4'])){
- $port=mb_substr($res_id[0]['data4'],4,1,'utf-8');
- // $port=substr($res_id[0]['data4'],3,1);
- }else{
- $port='';
- }
- if (!empty($res_id[0]['data3'])){
- $Source_code=str_replace(',','',$res_id[0]['data3']);
- }else{
- $Source_code='';
- }
- $unique_number=$Data['device_code'].$port.$Source_code;
- }else if ($typess==6){
- $port=$Data['port'];
- $Source_code=$Data['ncmd'];
- $unique_number=$Data['device_code'].$port.$Source_code.$Data['data4'].' '.$Data['data2'];
- }else if ($typess==7){
- $res_id = M()->query("select port from sp_ef2017 where id=" . $Data['id']);
- $port=$res_id[0]['port'];
- $unique_number=$Data['device_code'].$port;
- }else{
- $unique_number=$Data['device_code'];
- }
- $this->setRedisData($unique_number);
- }
- if ($R){
- $res['msg'] = '操作成功';
- $res['flag'] = true;
- echo json_encode($res);
- }else{
- $res['msg'] = '操作失败';
- $res['flag'] = false;
- echo json_encode($res);
- }
- }
- //Redis
- public function setRedisData($unique_number){
- //redis储存处理的设备
- $redis = new \Redis();
- $result = $redis->connect('47.98.201.73', 6379);
- $redis->auth("usky2021");
- if ($result==1){
- $redis->set("$unique_number",1);
- $redis->close();
- }
- }
- //MQTT
- public function message_push_mh($topic,$msg,$qos){
- // vendor('phpMQTT.phpMQTT');
- $server = '47.98.201.73'; // 服务器IP
- $port = 1883; // 服务器端口
- $username = 'usky'; // 用户名
- $password = 'usky'; // 密码
- $client_id = 'pub_' . uniqid();
- $mqtt = new \phpMQTT($server, $port, $client_id);
- if ($mqtt->connect(true, NULL, $username, $password)) {
- $mqtt->publish($topic, $msg, $qos);
- usleep(100000);
- $mqtt->close();
- // Log::record('MH—4G-MQTT-Push success!('.$topic.')['.date('Y-m-d H:i:s').']:'.json_encode($msg));
- } else {
- // Log::record('MH—4G-MQTT-Time out!('.$topic.')['.date('Y-m-d H:i:s').']:'.json_encode($msg));
- }
- }
- //获取消防栓设备编号
- public function getDeviceCode1($company)
- {
- $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.")");
- $str = "";
- foreach ($device as $val) {
- $str .= "'" . $val['owner_code'] . "',";
- }
- $newstr = substr($str, 0, strlen($str) - 1);
- return $newstr;
- }
- }
|