query("select dwtype,count(*) as count from sp_owner where company='".$company_code."' group by dwtype order by dwtype"); foreach ($data as $key=>$value){ if ($data[$key]['dwtype']==1){ $types_count[0]['pass_on_device_count']=(int)$data[$key]['count']; }elseif ($data[$key]['dwtype']==2){ $types_count[0]['water_meter_device_count']=(int)$data[$key]['count']; }elseif ($data[$key]['dwtype']==3){ $types_count[0]['smoke_sensation_device_count']=(int)$data[$key]['count']; }elseif ($data[$key]['dwtype']==4){ $types_count[0]['fire_hydrant_device_count']=(int)$data[$key]['count']; }elseif ($data[$key]['dwtype']==5){ $types_count[0]['level_device_count']=(int)$data[$key]['count']; }elseif ($data[$key]['dwtype']==6){ $types_count[0]['rtu_device_count']=(int)$data[$key]['count']; }elseif ($data[$key]['dwtype']==7){ $types_count[0]['electrical_fire_device_count']=(int)$data[$key]['count']; }elseif ($data[$key]['dwtype']==16){ $types_count[0]['video_device_count']=(int)$data[$key]['count']; }elseif ($data[$key]['dwtype']==17){ $types_count[0]['elevator_device_count']=(int)$data[$key]['count']; }elseif ($data[$key]['dwtype']==128){ $types_count[0]['manhole_cover_device_count']=(int)$data[$key]['count']; }elseif ($data[$key]['dwtype']==129){ $types_count[0]['geomagnetism_device_count']=(int)$data[$key]['count']; }elseif ($data[$key]['dwtype']==130){ $types_count[0]['access_control_device_count']=(int)$data[$key]['count']; }elseif ($data[$key]['dwtype']==131){ $types_count[0]['gsa_device_count']=(int)$data[$key]['count']; } } $res['msg'] = '操作成功'; $res['flag'] = true; $res['data'] = $types_count; echo json_encode($res); } public function getDeviceList(){ $Data=I(''); // print_r($Data); $company_code=$Data['company_code']; $dwtype=$Data['dwtype']; $start_time = $Data['start_time']; $end_time = $Data['end_time']; $where=''; if (!empty($start_time)){ $where.=" and a.install_time>='".$start_time."' "; } if (!empty($end_time)){ $where.=" and a.install_time<'".$end_time."' "; } if ($dwtype==1){ $device_list=M()->query("SELECT a.id,a.owner_code,a.owner_name,a.dwtype,b.true_status,IF(b.true_status=0,'在线','离线') as device_state,a.install_time,a.unitinfo FROM sp_owner AS a JOIN sp_devices_status AS b ON a.owner_code=b.deviceid WHERE a.company='".$company_code."' AND a.dwtype=1 ".$where." order by a.id DESC"); }else{ $device_list=M()->query("SELECT a.id,a.owner_code,a.owner_name,a.dwtype,IF(timestampdiff(HOUR,max(`b`.`data_time`),now())<12,'在线','离线') AS device_state,a.install_time,a.unitinfo FROM sp_owner AS a left JOIN sp_owner_status AS b ON a.owner_code=b.device_id WHERE a.company='".$company_code."' AND a.dwtype=".$dwtype." ".$where." GROUP BY a.owner_code ORDER BY a.id DESC"); } // print_r("SELECT a.id,a.owner_code,a.owner_name,a.dwtype,b.true_status,IF(b.true_status=0,'在线','离线') as device_state,a.install_time,a.unitinfo FROM sp_owner AS a JOIN sp_devices_status AS b ON a.owner_code=b.deviceid WHERE a.company='".$company_code."' AND a.dwtype=1 ".$where." order by a.id DESC"); $res['msg'] = '操作成功'; $res['flag'] = true; $res['data'] = $device_list; echo json_encode($res); } // public function getDeviceList(){ // $Data=I(''); // $company_code=$Data['company_code']; // $dwtype=$Data['dwtype']; // if ($dwtype==1){ // $device_list=M()->query("SELECT a.id,a.owner_code,a.owner_name,a.dwtype,b.true_status,IF(b.true_status=0,'在线','离线') as device_state,a.install_time,a.unitinfo FROM sp_owner AS a JOIN sp_devices_status AS b ON a.owner_code=b.deviceid WHERE a.company='".$company_code."' AND a.dwtype=1 order by a.install_time DESC"); // }else{ // $device_list=M()->query("SELECT a.id,a.owner_code,a.owner_name,a.dwtype,IF(timestampdiff(HOUR,max(`b`.`data_time`),now())<12,'在线','离线') AS device_state,a.install_time,a.unitinfo FROM sp_owner AS a left JOIN sp_owner_status AS b ON a.owner_code=b.device_id WHERE a.company='".$company_code."' AND a.dwtype=".$dwtype." GROUP BY a.owner_code ORDER BY a.install_time DESC"); // } // // $res['msg'] = '操作成功'; // $res['flag'] = true; // $res['data'] = $device_list; // echo json_encode($res); // } public function getDeviceDetails(){ $Data=I(''); $id=$Data['id']; $device_details=M()->query("SELECT a.company,a.id,a.owner_code,a.owner_name,a.sim,a.unitinfo,a.install_time,b.owner_address,a.dwtype FROM sp_owner AS a JOIN sp_owner_company AS b ON a.company=b.owner_id WHERE a.id=".$id); switch ($device_details[0]['dwtype']) { case '1'://报警主机 $device_details[0]['type_name']='报警主机'; $misinformation=M()->query("SELECT count(*) as count FROM sp_hj2017 WHERE device_code='".$device_details[0]['owner_code']."' AND clwb=1"); $real_alarm=M()->query("SELECT count(*) as count FROM sp_hj2017 WHERE device_code='".$device_details[0]['owner_code']."' AND clwb=0"); $unprocessed=M()->query("SELECT count(*) as count FROM sp_hj2017 WHERE device_code='".$device_details[0]['owner_code']."' AND clzt=0;"); $device_details[0]['misinformation']=(int)$misinformation[0]['count']; $device_details[0]['real_alarm']=(int)$real_alarm[0]['count']; $device_details[0]['unprocessed']=(int)$unprocessed[0]['count']; break; case '2'://水表 $device_details[0]['type_name']='水表'; $water_data=M()->query("select * from sp_owner_sync_data where device_id='".$device_details[0]['owner_code']."' and point_code=4 order by data_time desc"); $battery_data=M()->query("select point_data,data_time from sp_owner_sync_data where device_id='".$device_details[0]['owner_code']."' and point_code=2 order by data_time desc"); $signal_data=M()->query("select point_data from sp_owner_sync_data where device_id='".$device_details[0]['owner_code']."' and point_code=3 order by data_time desc"); // print_r($water_data); foreach ($water_data as $key=>$value){ $data[]=$value['point_data']; $time[]=$value['data_time']; } foreach ($battery_data as $key=>$value){ $battery[]=$value['point_data']; } foreach ($signal_data as $key=>$value){ $signal[]=$value['point_data']; } $device_details[0]['stiem']=$time; $device_details[0]['water_data']=$data; $device_details[0]['battery_data']=$battery; $device_details[0]['signal_data']=$signal; break; case '3'://烟感 $device_details[0]['type_name']='烟感'; $fume = M()->query("select RSRQ, DeviceStatus, BatteryLevel, storeTime, device_id from sp_y".$device_details[0]['owner_code']." ORDER BY storeTime DESC limit 1"); if (empty($fume)){ $device_details[0]['device_status']=''; }else{ if ($fume[0]['DeviceStatus']==7){ $device_details[0]['device_status']='正常'; }else if ($fume[0]['DeviceStatus']==5){ $device_details[0]['device_status']='故障'; }else if ($fume[0]['DeviceStatus']==4){ $device_details[0]['device_status']='低压'; }else if ($fume[0]['DeviceStatus']==2){ $device_details[0]['device_status']='报警静音'; }else if ($fume[0]['DeviceStatus']==1){ $device_details[0]['device_status']='报警'; } } $device_details[0]['battery_level']=$fume[0]['BatteryLevel']; $device_details[0]['rsrq']=$fume[0]['RSRQ']; $device_details[0]['stime']=$fume[0]['storeTime']; break; case '4'://消防栓 $device_details[0]['type_name']='消防栓'; $R=M()->query("select data4, data3, data2, data1, time, device_code from sp_d".$device_details[0]['owner_code']." ORDER BY time DESC limit 1"); $device_details[0]['stime']; $device_details[0]['battery_level']; $device_details[0]['rsrq']; if ($R[0]['data1']=='WP1'){ $device_details[0]['device_status']='低压'; }elseif($R[0]['data1']=='WP2'){ $device_details[0]['device_status']='高压'; }elseif($R[0]['data1']=='WP3'){ $device_details[0]['device_status']='故障'; }else{ $device_details[0]['device_status']=$R[0]['data1']; } $device_details[0]['device_data']=$R[0]['data1']; $device_details[0]['stime']=$R[0]['time']; break; case '5'://液位 $device_details[0]['type_name']='液位'; $water_data=M()->query("select * from sp_owner_sync_data where device_id='".$device_details[0]['owner_code']."' and point_code=4 order by data_time desc"); foreach ($water_data as $value) { $time[]=$value['data_time']; $device_data[]=$value['point_data']; } $device_details[0]['stiem']=$time; $device_details[0]['water_data']=$device_data; break; case '6'://RTU $device_details[0]['type_name']='RTU'; $rtu=M()->query("SELECT id,data4,ncmd,`time`,data1,data2,CASE WHEN `port`='E6' THEN '模拟量' WHEN `port`='E3' THEN '开关量' END as types FROM sp_d".$device_details[0]['owner_code']." WHERE id in(SELECT MAX(id) FROM sp_d".$device_details[0]['owner_code']." GROUP BY `port`,ncmd) AND ncmd !='' " .(($device_details[0]['owner_code']=='4023363030303635')?" AND (ncmd !='02' OR `port`!='E6') ": (($device_details[0]['owner_code']=='4023363030303639')?" AND (ncmd !='03' OR `port`!='E6') ": (($device_details[0]['owner_code']=='4023363030303434')?" AND (ncmd !='04' OR `port`!='E3') AND (ncmd !='05' OR `port`!='E3')": (($device_details[0]['owner_code']=='4023363030303336')? " AND (ncmd !='01' OR `port`!='E6') ": (($device_details[0]['owner_code']=='4023363030303733')?" AND (ncmd !='05' AND ncmd !='06' )":"")))))//山海大酒店B1楼水泵房02端口模拟量因设备故障,暂时屏蔽 ); foreach ($rtu as $key=>$value){ if ($rtu[$key]['ncmd']=='01'|| $rtu[$key]['ncmd']=='02'|| $rtu[$key]['ncmd']=='03'|| $rtu[$key]['ncmd']=='04'|| $rtu[$key]['ncmd']=='05' ||$rtu[$key]['ncmd']=='06'||$rtu[$key]['ncmd']=='07'|| $rtu[$key]['ncmd']=='07'|| $rtu[$key]['ncmd']=='08'||$rtu[$key]['ncmd']=='09'){ $rtu[$key]['ncmd']='0'.hexdec($rtu[$key]['ncmd']); }else{ $rtu[$key]['ncmd']=hexdec($rtu[$key]['ncmd']); } } $device_details[0]['rtu_data']=$rtu; break; case '7'://电气火灾 $device_details[0]['type_name']='电气火灾'; $R=M()->query("select * from sp_owner_status where device_id='".$device_details[0]['owner_code']."'"); $tiem=M()->query("select max(data_time) as time from sp_owner_status where device_id='".$device_details[0]['owner_code']."'"); foreach ($R as $key=>$value){ $R[$key]['time']=$tiem[0]['time']; } $device_details[0]['electric_data']=$R; break; case '16'://视频监测 $device_details[0]['type_name']='视频监测'; $video=M()->query("select data4,time from sp_video2017 where device_code='".$device_details[0]['owner_code']."' order by time desc limit 1"); $device_details[0]['video_data']=$video; break; case '17'://电梯监测 $device_details[0]['type_name']='电梯监测'; $elevator=M()->query("select data4,time from sp_lifter2017 where device_code='".$device_details[0]['owner_code']."' order by time desc limit 1"); $device_details[0]['elevator_data']=$elevator; break; case '128'://井盖 $device_details[0]['type_name']='井盖监测'; $MC=M()->query("select device_status,time from sp_iw2017 where device_code='".$device_details[0]['owner_code']."' order by time desc limit 1"); if ($MC[0]['device_status']){ $MC[0]['data4']='正常'; }else{ $MC[0]['data4']='打开告警'; } $MC[0]['time']=$MC[0]['time']; $device_details[0]['mc_data']=$MC; break; case '129'://地磁 $device_details[0]['type_name']='地磁'; break; case '130'://门禁 $device_details[0]['type_name']='门禁'; break; case '131'://可燃气体 $device_details[0]['type_name']='可燃气体'; break; default: $res['msg'] = '操作失败,设备类型尚未定义,请联系管理员'; $res['flag'] = 3002; echo json_encode($res); exit(); break; } $res['msg'] = '操作成功'; $res['flag'] = true; $res['data'] = $device_details; echo json_encode($res); } }