123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- <?php
- namespace Home\Controller;
- use Think\Controller;
- class IndexController extends ComController
- {
- //首页统计图数据
- public function getHomePageData(){
- $Date=I();
- $phone=$Date['phone'];
- $company_code = $Date['company_code'];
- if (!empty($_SESSION['phone'])) {
- $phone = $_SESSION['phone'];
- }
- if (!empty($company_code)){
- $device_list = $this->getDeviceCode($company_code);
- }else{
- $company_code1=M()->query("select owner_code from sp_owner_phone WHERE phone='".$phone."' GROUP BY owner_code limit 1");
- $company_code=$company_code1[0]['owner_code'];
- $device_list = $this->getDeviceCode($company_code);
- }
- $end_time = date("Y-m-d");
- $start_time = date("Y-m-d", strtotime("-1 months", strtotime($end_time)));
- //时间段
- $statisticalPeriod = $start_time . '~' . $end_time;
- //报警信息统计开始
- if (!empty($device_list)){
- //报警主机报警总数
- $alarm_host_count=M()->query("select count(*) as alarm_host_count from sp_hj2017 where time between '".$start_time." 00:00:00' and '".$end_time." 23:59:59' and device_code in(".$device_list.")");
- //消防水系统报警总数
- $fire_water_count=M()->query("select count(*) as fire_water_count from sp_sj2017 where time between '".$start_time." 00:00:00' and '".$end_time." 23:59:59' and device_code in(".$device_list.")");
- //电气火灾报警总数
- $electrical_fire_count=M()->query("select count(*) as electrical_fire_count from sp_ef2017 where time between '".$start_time." 00:00:00' and '".$end_time." 23:59:59' and device_code in(".$device_list.")");
- //视频监测报警总数
- $video_monitoring_count=M()->query("select count(*) as video_monitoring_count from sp_video2017 where time between '".$start_time." 00:00:00' and '".$end_time." 23:59:59' and device_code in(".$device_list.")");
- //井盖
- $manhole_cover_count=M()->query("select count(*) as manhole_cover_count from sp_iw2017 where time between '".$start_time." 00:00:00' and '".$end_time." 23:59:59' and device_code in(".$device_list.")");
- //门禁
- $door_count=M()->query("select count(*) as door_count from sp_door2020 where time between '".$start_time." 00:00:00' and '".$end_time." 23:59:59' and device_code in(".$device_list.")");
- //可燃气体
- $gas_count=M()->query("select count(*) as gas_count from sp_gas2020 where time between '".$start_time." 00:00:00' and '".$end_time." 23:59:59' and device_code in(".$device_list.")");
- //地磁
- $geomagnetism_count=M()->query("select count(*) as geomagnetism_count from sp_dc2020 where time between '".$start_time." 00:00:00' and '".$end_time." 23:59:59' and device_code in(".$device_list.")");
- //RTU
- $rtu_count=M()->query("select count(*) as rtu_count from sp_rtu2017 where time between '".$start_time." 00:00:00' and '".$end_time." 23:59:59' and device_code in(".$device_list.")");
- //电梯
- $elevator_count=M()->query("select count(*) as elevator_count from sp_lifter2017 where time between '".$start_time." 00:00:00' and '".$end_time." 23:59:59' and device_code in(".$device_list.")");
- //正常
- $normal_fire_water_device_count=M()->query("select count(*) as normal_fire_water_device_count from sp_v_device_status where device_status='在线' and device_id in(".$device_list.") ");
- //离线
- $off_linefire_water_device_count=M()->query("select count(*) as off_linefire_water_device_count from sp_v_device_status where device_status='离线' and device_id in(".$device_list.") ");
- //真实告警
- $real_alarm_count=M()->query("select count(*) as real_alarm_count from sp_hj2017 where time between '".$start_time." 00:00:00' and '".$end_time." 23:59:59' and device_code in(".$device_list.") and data2='火警'");
- }
- //其他类型一个月报警总数
- $other_count=(int)$manhole_cover_count[0]['manhole_cover_count']+(int)$door_count[0]['door_count']+(int)$gas_count[0]['gas_count']+(int)$geomagnetism_count[0]['geomagnetism_count']+(int)$rtu_count[0]['rtu_count']
- +(int)$elevator_count[0]['elevator_count'];
- //报警信息统计结束
- //数据等级统计开始
- //告警总数
- $alarm_count=(int)$other_count+(int)$video_monitoring_count[0]['video_monitoring_count']+(int)$electrical_fire_count[0]['electrical_fire_count']+(int)$fire_water_count[0]['fire_water_count']
- + (int)$alarm_host_count[0]['alarm_host_count'];
- //隐患告警
- $hidden_danger_count=(int)$alarm_count-(int)$real_alarm_count[0]['real_alarm_count'];
- //事件告警
- $event_count=0;
- //数据等级统计结束
- //设备运行状态开始
- //离线
- $off_linealarm_host_device_count=M()->query("SELECT COUNT(*) as off_linealarm_host_device_count FROM sp_devices_status AS a JOIN sp_owner AS b ON a.deviceid=b.owner_code WHERE b.dwtype=1 AND a.true_status in(75,300) AND b.company='".$company_code."' ");
- $off_line_device_count=(int)$off_linefire_water_device_count[0]['off_linefire_water_device_count']+(int)$off_linealarm_host_device_count[0]['off_linealarm_host_device_count'];
- //故障
- $fault_device_count=0;
- //预警
- $early_warning_device_count=0;
- //其他
- $other_device_count=0;
- //正常
- $normal_alarm_host_device_count=M()->query("SELECT COUNT(*) as normal_alarm_host_device_count FROM sp_devices_status AS a JOIN sp_owner AS b ON a.deviceid=b.owner_code WHERE b.dwtype=1 AND a.true_status='0' AND b.company='".$company_code."' ");
- $normal_device_count=(int)$normal_fire_water_device_count[0]['normal_fire_water_device_count']+(int)$normal_alarm_host_device_count[0]['normal_alarm_host_device_count'];;
- //设备运行状态结束
- $data[0]['owner_name']=$this->owner_name;
- $data[0]['statisticalPeriod']=$statisticalPeriod;
- $data[0]['alarm_host_count'] = (int)$alarm_host_count[0]['alarm_host_count'];
- $data[0]['fire_water_count'] = (int)$fire_water_count[0]['fire_water_count'];
- $data[0]['electrical_fire_count'] = (int)$electrical_fire_count[0]['electrical_fire_count'];
- $data[0]['video_monitoring_count'] = (int)$video_monitoring_count[0]['video_monitoring_count'];
- $data[0]['other_count'] = $other_count;
- $data[0]['alarm_count'] = $alarm_count;
- $data[0]['real_alarm_count'] = (int)$real_alarm_count[0]['real_alarm_count'];
- $data[0]['hidden_danger_count'] = $hidden_danger_count;
- $data[0]['event_count'] = $event_count;
- $data[0]['off_line_device_count'] = $off_line_device_count;
- $data[0]['fault_device_count'] = $fault_device_count;
- $data[0]['early_warning_device_count'] = $early_warning_device_count;
- $data[0]['normal_device_count'] = $normal_device_count;
- $data[0]['other_device_count'] = $other_device_count;
- $data[0]['company_code'] = $company_code;
- $res['msg'] = '操作成功';
- $res['flag'] = true;
- $res['data'] = $data;
- echo json_encode($res);
- }
- public function getCompanyList(){
- $Date=I();
- if (!empty($_SESSION['phone'])) {
- $phone = $_SESSION['phone'];
- }else{
- $res['msg'] = '操作失败,缓存中参数缺失';
- $res['flag'] = 3002;
- echo json_encode($res);
- exit();
- }
- $company=M()->query("select a.owner_code,b.owner_name from sp_owner_phone as a join sp_owner_company as b on a.owner_code=b.owner_id where a.phone='".$phone."' GROUP BY owner_code");
- $res['msg'] = '操作成功';
- $res['flag'] = true;
- $res['data'] = $company;
- echo json_encode($res);
- }
- public function getFunctionalModuleStatistics(){
- $Date=I();
- $phone=$Date['phone'];
- $company_code = $Date['company_code'];
- if (!empty($_SESSION['phone'])) {
- $phone = $_SESSION['phone'];
- }
- $where2['company_code'] = $company_code;
- if (!empty($company_code)){
- $device_list = $this->getDeviceCode($company_code);
- }else{
- $company_code1=M()->query("select owner_code from sp_owner_phone WHERE phone='".$phone."' GROUP BY owner_code limit 1");
- $company_code=$company_code1[0]['owner_code'];
- $device_list = $this->getDeviceCode($company_code);
- }
- $data_statistics = M('company_sync')->where($where2)->find();
- if(!empty($data_statistics)){
- //报警主机未处理数量统计
- $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'];
- //消防水未处理数量统计
- $fire_water_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'];
- //RTU未处理数量统计
- $rtu_count=$data_statistics['device_06_alarm'] - $data_statistics['device_06_alarm_confirm']+$data_statistics['device_06_out']-$data_statistics['device_06_out_confirm'];
- //电气火灾未处理数量统计
- $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'];
- //视频监测未处理数量统计
- $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'];
- }else{
- $alarm_host_count = 0;
- $fire_water_count = 0;
- $rtu_count = 0;
- $electrical_fire_count = 0;
- $video_monitoring_count = 0;
- }
- if (!empty($device_list)){
- // //报警主机未处理数量统计
- // $alarm_host_count=M()->query("select count(*) as alarm_host_count from sp_hj2017 where clzt=0 and device_code in(".$device_list.")");
- //消防水未处理数量统计
- // $fire_water_count=M()->query("select count(*) as fire_water_count from sp_sj2017 where clzt=0 and device_code in(".$device_list.")");
- //电气火灾未处理数量统计
- // $electrical_fire_count=M()->query("select count(*) as electrical_fire_count from sp_ef2017 where clzt=0 and device_code in(".$device_list.")");
- //视频监测未处理数量统计
- // $video_monitoring_count=M()->query("select count(*) as video_monitoring_count from sp_video2017 where clzt=0 and device_code in(".$device_list.")");
- //井盖未处理数量统计
- $manhole_cover_count=M()->query("select count(*) as manhole_cover_count from sp_iw2017 where clzt=0 and device_code in(".$device_list.")");
- //门禁未处理数量统计
- $door_count=M()->query("select count(*) as door_count from sp_door2020 where clzt=0 and device_code in(".$device_list.")");
- //可燃气体未处理数量统计
- $gas_count=M()->query("select count(*) as gas_count from sp_gas2020 where clzt=0 and device_code in(".$device_list.")");
- //地磁未处理数量统计
- $geomagnetism_count=M()->query("select count(*) as geomagnetism_count from sp_dc2020 where clzt=0 and device_code in(".$device_list.")");
- //RTU未处理数量统计
- // $rtu_count=M()->query("select count(*) as rtu_count from sp_rtu2017 where clzt=0 and device_code in(".$device_list.")");
- //电梯未处理数量统计
- $elevator_count=M()->query("select count(*) as elevator_count from sp_lifter2017 where clzt=0 and device_code in(".$device_list.")");
- }
- //综合告警统计
- $comprehensive_alarm_count=(int)$manhole_cover_count[0]['manhole_cover_count']+(int)$door_count[0]['door_count']+(int)$gas_count[0]['gas_count']+(int)$geomagnetism_count[0]['geomagnetism_count']+(int)$rtu_count
- +(int)$elevator_count[0]['elevator_count']+(int)$video_monitoring_count+(int)$electrical_fire_count+(int)$fire_water_count
- + (int)$alarm_host_count;
- //人员督察单
- $personnel_inspection_list = query_187_ytapi("select count(*) as personnel_inspection_list_count from person_data where clzt='0' and company_code='" . $company_code."'");
- //电子督察单
- $electronic_inspection_sheet = query_187_ytapi("select count(*) as electronic_inspection_sheet_count from jingan_analysis_data where status=0 and clzt='0' and content != '设备离线' and company_code='" . $company_code."'");
- //消防支队督察单未处理数量统计
- $fire_brigade_inspector_count=$personnel_inspection_list[0]['personnel_inspection_list_count']+$electronic_inspection_sheet[0]['electronic_inspection_sheet_count'];
- $data[0]['comprehensive_alarm_count']=$comprehensive_alarm_count;
- $data[0]['fire_brigade_inspector_count']=$fire_brigade_inspector_count;
- $res['msg'] = '操作成功';
- $res['flag'] = true;
- $res['data'] = $data;
- echo json_encode($res);
- }
- }
|