=',date('Y-m-d').' 00:00:00']; $map[] = ['eae.create_time','<=',date('Y-m-d').' 23:59:59']; }elseif ($type == 2){ $map[] = ['eae.create_time','>=',date('Y-m').'-01 00:00:00']; $map[] = ['eae.create_time','<=',date('Y-m').'-31 23:59:59']; }elseif($type == 3){ $map[] = ['eae.create_time','>=',date('Y').'-01-01 00:00:00']; $map[] = ['eae.create_time','<=',date('Y').'-12-31 23:59:59']; } $map[] = ['ea.org_id','=',$this->orgId]; $list = [ ['name'=>'严重警告','type'=>'高限报警'], ['name'=>'一般警告','type'=>'低限报警'], ]; $total = 0; foreach ($list as $k=>$v){ $value = Db::name('energy_alarm_event') ->alias('eae') ->join('energy_alarm ea','ea.id=eae.alarm_id') ->where('ea.alarm_type',$v['type']) ->where($map) ->count(); $total +=$value; $list[$k]['value'] = $value; } $data = [ 'total'=>$total, 'list'=>$list ]; HelpHander::success($data); } public function typeList(){ $type = input('type',''); if($type == 1){ $map[] = ['eae.create_time','>=',date('Y-m-d').' 00:00:00']; $map[] = ['eae.create_time','<=',date('Y-m-d').' 23:59:59']; }elseif ($type == 2){ $map[] = ['eae.create_time','>=',date('Y-m').'-01 00:00:00']; $map[] = ['eae.create_time','<=',date('Y-m').'-31 23:59:59']; }elseif($type == 3){ $map[] = ['eae.create_time','>=',date('Y').'-01-01 00:00:00']; $map[] = ['eae.create_time','<=',date('Y').'-12-31 23:59:59']; } $map[] = ['ea.org_id','=',$this->orgId]; $list = [ ['name'=>'严重警告','type'=>'高限报警'], ['name'=>'一般警告','type'=>'低限报警'], ]; $x = $y = []; foreach ($list as $k=>$v){ $value = Db::name('energy_alarm_event') ->alias('eae') ->join('energy_alarm ea','ea.id=eae.alarm_id') ->where('ea.alarm_type',$v['type']) ->where($map) ->count(); $x[] = $v['name']; $y[] = $value; } HelpHander::success(['x'=>$x,'y'=>$y]); } public function timeTrend(){ $x = $y = $y1 = []; $list = []; for ($i=1;$i<=24;$i++){ $x[] = $i; $t= $i-1; if($i < 10){ $i = '0'.$i; } if($t < 10){ $t = '0'.$i; } $list[$i-1]['st'] = date('Y-m-d').' '.$t.'00:00'; $list[$i-1]['et'] = date('Y-m-d').' '.$i.'00:00'; } foreach ($list as $k=>$v){ $jin = Db::name('energy_alarm_event') ->alias('eae') ->join('energy_alarm ea','ea.id=eae.alarm_id') ->where('ea.org_id',$this->orgId) ->where('eae.create_time','>=',$v['st']) ->where('eae.create_time','<=',$v['et']) ->count(); $y[] = $jin; $zuo = Db::name('energy_alarm_event') ->alias('eae') ->join('energy_alarm ea','ea.id=eae.alarm_id') ->where('ea.org_id',$this->orgId) ->where('eae.create_time','>=',date('Y-m-d H:i:s',strtotime($v['st'])-86400)) ->where('eae.create_time','<=',date('Y-m-d H:i:s',strtotime($v['et'])-86400)) ->count(); $y1[] = $zuo; } $data =[ 'x'=>$x, 'y'=>$y, 'y1'=>$y1 ]; HelpHander::success($data); } public function deviceRanking(){ $list = Db::name('energy_device') ->field('id,title,sn') ->where('org_id',$this->orgId) ->where('del',0) ->where('cate',5) ->limit(6) ->select(); $total = 0; foreach ($list as $k=>$v){ $value = Db::name('energy_alarm_event') ->alias('eae') ->join('energy_alarm ea','ea.id=eae.alarm_id') ->where('ea.device_sn',$v['sn']) ->where('org_id',$this->orgId) ->count(); $total +=$value; $list[$k]['value'] = $value; } if($list){ foreach ($list as $k=>$v){ $list[$k]['bl'] = 0; if($total > 0){ $list[$k]['bl'] = round($v['value']/$total*100,0); } } } $newList = list_sort_by($list,'value','desc'); $data = [ 'top1'=>isset($newList[0])&&!empty($newList[0]) ? $newList[0]:'', 'top2'=>isset($newList[1])&&!empty($newList[1]) ? $newList[1]:'', 'top3'=>isset($newList[2])&&!empty($newList[2]) ? $newList[2]:'', 'top4'=>isset($newList[3])&&!empty($newList[3]) ? $newList[3]:'', 'top5'=>isset($newList[4])&&!empty($newList[4]) ? $newList[4]:'', 'top6'=>isset($newList[5])&&!empty($newList[5]) ? $newList[5]:'', ]; HelpHander::success($data); } public function roomList(){ $list = Db::name('energy_room') ->where('org_id',$this->orgId) ->where('del',0) ->limit(5) ->select(); $x = $y = []; foreach ($list as $k=>$v){ $y[] = Db::name('energy_alarm_event') ->alias('eae') ->join('energy_alarm ea','ea.id=eae.alarm_id') ->join('energy_device ed','ed.sn=ea.device_sn') ->where('ed.room_id',$v['id']) ->where('ea.org_id',$this->orgId) ->where('ed.del',0) ->count(); $x[] = $v['title']; } HelpHander::success(['x'=>$x,'y'=>$y]); } //当前告警 public function warningInfoList(){ $num = Db::name('energy_alarm_event') ->alias('eae') ->join('energy_alarm ea','ea.id=eae.alarm_id') ->where('ea.org_id',$this->orgId) ->where('ea.alarm_type','高限报警') ->where('eae.status',0) ->count(); $num1 = Db::name('energy_alarm_event') ->alias('eae') ->join('energy_alarm ea','ea.id=eae.alarm_id') ->where('ea.org_id',$this->orgId) ->where('ea.alarm_type','低限报警') ->where('eae.status',0) ->count(); $count = $num + $num1; $list = Db::name('energy_alarm_event') ->alias('eae') ->field('ea.*,eae.create_time as waring_time') ->join('energy_alarm ea','ea.id=eae.alarm_id') ->where('ea.org_id',$this->orgId) ->where('ea.alarm_type','in',['低限报警','高限报警']) ->where('eae.status','=',0) ->select(); foreach ($list as $k=>$v){ $device = Db::name('energy_device') ->where('sn',$v['device_sn']) ->find(); $room = ''; if($device){ $room = Db::name('energy_room') ->where('id',$device['room_id']) ->value('title'); } $content = $v['point_label'].$v['alarm_type']; $list[$k]['room'] = $room; $list[$k]['device'] = $device ? $device['title']:''; $list[$k]['infos'] = $content; } $data = [ 'countinfo'=>[ 'count'=>$count, 'num'=>$num, 'num1'=>$num1 ], 'list'=>$list ]; HelpHander::success($data); } //事件记录 public function eventRecord(){ $page = input('page',1); $size = input('size',10); $date = input('date',''); $roomId = input('roomId',''); $cate = input('cate',''); $type = input('type',''); $deviceName = input('deviceName',''); if($date){ $st = $date[0]; $et = $date[1]; $map[] = ['alarm_time','>=',$st.' 00:00:00']; $map[] = ['alarm_time','<=',$et.' 23:59:59']; } $map[] = ['org_id','=',$this->orgId]; if($roomId !=''){ $rsns = Db::name('energy_device')->where('room_id',$roomId)->column('sn'); $map[] = ['device_sn','in',$rsns]; } if($cate !=''){ $rsns = Db::name('energy_device')->where('cate',$cate)->column('sn'); $map[] = ['device_sn','in',$rsns]; } if($type !=''){ $map[] = ['alarm_type','=',$type]; } if($deviceName !=''){ $rsns = Db::name('energy_device')->where('title','like','%'.$deviceName.'%')->column('sn'); $map[] = ['device_sn','in',$rsns]; } $lists = Db::name('energy_alarm') ->where($map) ->order('id desc') ->page($page,$size) ->select(); foreach ($lists as $k=>$v){ $deviceInfo = Db::name('energy_device') ->where('sn',$v['device_sn']) ->find(); $cate = $room = ''; if($deviceInfo){ $cate = Db::name('energy_device_cate') ->where('id',$deviceInfo['cate']) ->value('title'); $room = Db::name('energy_room') ->where('id',$v['room_id']) ->value('title'); } $content = $v['point_label'].$v['alarm_type']; $lists[$k]['room'] = $room; $lists[$k]['cate'] = $cate; $lists[$k]['device'] = $deviceInfo ?$deviceInfo['title']:''; $lists[$k]['content'] = $content; } $total = Db::name('energy_alarm') ->where($map) ->count(); $data = [ 'total'=>$total, 'list'=>$lists ]; HelpHander::success($data); } public function eventRecordExport(){ $ids = input('ids',''); $date = input('date',''); $roomId = input('roomId',''); $cate = input('cate',''); $type = input('type',''); $deviceName = input('deviceName',''); if($date){ $st = $date[0]; $et = $date[1]; $map[] = ['alarm_time','>=',$st.' 00:00:00']; $map[] = ['alarm_time','<=',$et.' 23:59:59']; } if($ids){ $map[] = ['id','in',explode(',',$ids)]; } $map[] = ['org_id','=',$this->orgId]; if($roomId !=''){ $rsns = Db::name('energy_device')->where('room_id',$roomId)->column('sn'); $map[] = ['device_sn','in',$rsns]; } if($cate !=''){ $rsns = Db::name('energy_device')->where('cate',$cate)->column('sn'); $map[] = ['device_sn','in',$rsns]; } if($type !=''){ $map[] = ['alarm_type','=',$type]; } if($deviceName !=''){ $rsns = Db::name('energy_device')->where('title','like','%'.$deviceName.'%')->column('sn'); $map[] = ['device_sn','in',$rsns]; } $lists = Db::name('energy_alarm') ->where($map) ->order('id desc') ->select(); foreach ($lists as $k=>$v){ $deviceInfo = Db::name('energy_device') ->where('sn',$v['device_sn']) ->find(); $cate = $room = ''; if($deviceInfo){ $cate = Db::name('energy_device_cate') ->where('id',$deviceInfo['cate']) ->value('title'); $room = Db::name('energy_room') ->where('id',$v['room_id']) ->value('title'); } $content = $v['point_label'].$v['alarm_type']; $lists[$k]['room'] = $room; $lists[$k]['cate'] = $cate; $lists[$k]['device'] = $deviceInfo ?$deviceInfo['title']:''; $lists[$k]['content'] = $content; } $columns = [ ["title" => "房间","key" => "room"], ["title" => "设备名称","key" => "device"], ["title" => "设备类型","key" => "cate"], ["title" => "事件信息","key" => "content"], ["title" => "发生时间","key" => "alarmTime"], ]; $dt = [ 'columns'=>$columns, 'list'=>$lists ]; HelpHander::success($dt); } public function htoricalAlarms(){ $page = input('page',1); $size = input('size',10); $date = input('date',''); $roomId = input('roomId',''); $cate = input('cate',''); $type = input('type',''); $deviceName = input('deviceName',''); if($date){ $st = $date[0]; $et = $date[1]; $map[] = ['ea.alarm_time','>=',$st.' 00:00:00']; $map[] = ['ea.alarm_time','<=',$et.' 23:59:59']; } $map[] = ['ea.org_id','=',$this->orgId]; if($roomId !=''){ $rsns = Db::name('energy_device')->where('room_id',$roomId)->column('sn'); $map[] = ['ea.device_sn','in',$rsns]; } if($cate !=''){ $rsns = Db::name('energy_device')->where('cate',$cate)->column('sn'); $map[] = ['ea.device_sn','in',$rsns]; } if($type !=''){ $map[] = ['ea.alarm_type','=',$type]; } if($deviceName !=''){ $rsns = Db::name('energy_device')->where('title','like','%'.$deviceName.'%')->column('sn'); $map[] = ['ea.device_sn','in',$rsns]; } $lists = Db::name('energy_alarm_event') ->alias('eae') ->field('ea.device_sn,ea.point_label,ea.alarm_type,ea.level,ea.alarm_time,eae.*') ->join('energy_alarm ea','ea.id=eae.alarm_id') ->where($map) ->order('eae.id desc') ->page($page,$size) ->select(); foreach ($lists as $k=>$v){ $deviceInfo = Db::name('energy_device') ->where('sn',$v['device_sn']) ->find(); $cate = $room = ''; if($deviceInfo){ $cate = Db::name('energy_device_cate') ->where('id',$deviceInfo['cate']) ->value('title'); $room = Db::name('energy_room') ->where('id',$v['room_id']) ->value('title'); } $content = $v['point_label'].$v['alarm_type']; $lists[$k]['room'] = $room; $lists[$k]['cate'] = $cate; $lists[$k]['device'] = $deviceInfo ?$deviceInfo['title']:''; $lists[$k]['content'] = $content; $lists[$k]['deal_user_name'] = Db::name('user')->where('id',$v['deal_user'])->value('real_name'); $lists[$k]['is_deal_text'] = $v['is_deal'] == 1 ? '是':'否'; $lists[$k]['is_finish_text'] = $v['is_finish'] == 1 ? '是':'否'; $lists[$k]['xytime'] = round($v['xytime']/60,1).'min'; $lists[$k]['hftime'] = round($v['hftime']/60,1).'min'; } $total = Db::name('energy_alarm_event') ->alias('eae') ->join('energy_alarm ea','ea.id=eae.alarm_id') ->where($map) ->count(); $data = [ 'total'=>$total, 'list'=>$lists ]; HelpHander::success($data); } public function htoricalAlarmsExport(){ $page = input('page',1); $size = input('size',10); $ids = input('ids',''); $date = input('date',''); $roomId = input('roomId',''); $cate = input('cate',''); $type = input('type',''); $deviceName = input('deviceName',''); if($ids){ $map[] = ['eae.id','in',explode(',',$ids)]; } if($date){ $st = $date[0]; $et = $date[1]; $map[] = ['ea.alarm_time','>=',$st.' 00:00:00']; $map[] = ['ea.alarm_time','<=',$et.' 23:59:59']; } $map[] = ['ea.org_id','=',$this->orgId]; if($roomId !=''){ $rsns = Db::name('energy_device')->where('room_id',$roomId)->column('sn'); $map[] = ['ea.device_sn','in',$rsns]; } if($cate !=''){ $rsns = Db::name('energy_device')->where('cate',$cate)->column('sn'); $map[] = ['ea.device_sn','in',$rsns]; } if($type !=''){ $map[] = ['ea.alarm_type','=',$type]; } if($deviceName !=''){ $rsns = Db::name('energy_device')->where('title','like','%'.$deviceName.'%')->column('sn'); $map[] = ['ea.device_sn','in',$rsns]; } $lists = Db::name('energy_alarm_event') ->alias('eae') ->field('ea.device_sn,ea.point_label,ea.alarm_type,ea.level,ea.alarm_time,eae.*') ->join('energy_alarm ea','ea.id=eae.alarm_id') ->where($map) ->order('eae.id desc') ->page($page,$size) ->select(); foreach ($lists as $k=>$v){ $deviceInfo = Db::name('energy_device') ->where('sn',$v['device_sn']) ->find(); $cate = $room = ''; if($deviceInfo){ $cate = Db::name('energy_device_cate') ->where('id',$deviceInfo['cate']) ->value('title'); $room = Db::name('energy_room') ->where('id',$v['room_id']) ->value('title'); } $content = $v['point_label'].$v['alarm_type']; $lists[$k]['room'] = $room; $lists[$k]['cate'] = $cate; $lists[$k]['device'] = $deviceInfo ?$deviceInfo['title']:''; $lists[$k]['content'] = $content; $lists[$k]['deal_user_name'] = Db::name('user')->where('id',$v['deal_user'])->value('real_name'); $lists[$k]['is_deal_text'] = $v['is_deal'] == 1 ? '是':'否'; $lists[$k]['is_finish_text'] = $v['is_finish'] == 1 ? '是':'否'; $lists[$k]['xytime'] = round($v['xytime']/60,1).'min'; $lists[$k]['hftime'] = round($v['hftime']/60,1).'min'; } $columns = [ ["title" => "房间","key" => "room"], ["title" => "设备名称","key" => "device"], ["title" => "设备类型","key" => "cate"], ["title" => "告警信息","key" => "pointLabel"], ["title" => "告警等级","key" => "alarmType"], ["title" => "告警时间","key" => "alarmTime"], ["title" => "处理时间","key" => "dealTime"], ["title" => "告警解除时间","key" => "finishTime"], ["title" => "处理人","key" => "dealUserName"], ["title" => "响应时长","key" => "xytime"], ["title" => "恢复时长","key" => "hftime"], ["title" => "及时处理","key" => "isDealText"], ["title" => "及时恢复","key" => "isFinishText"], ["title" => "告警原因","key" => "reason"], ]; $dt = [ 'columns'=>$columns, 'list'=>$lists ]; HelpHander::success($dt); } //房间列表 public function roomDataList(){ $list = Db::name('energy_room') ->where('del',0) ->where('org_id',$this->orgId) ->select(); HelpHander::success($list); } //设备列表 public function deviceDataList(){ $list = Db::name('energy_device') ->where('del',0) ->where('org_id',$this->orgId) ->select(); HelpHander::success($list); } //设备类型 public function deviceCateDataList(){ $list = Db::name('energy_device_cate') ->select(); HelpHander::success($list); } }