123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- <?php
- namespace catchAdmin\screen\controller;
- use catcher\base\CatchRequest as Request;
- use catcher\CatchResponse;
- use catcher\base\CatchController;
- use catchAdmin\system\model\SysDictData;
- use catchAdmin\permissions\model\SysConfig;
- use think\facade\Db;
- use catchAdmin\permissions\model\DataRangScopeTrait;
- use catchAdmin\alarm\model\AlarmRecords as alarmRecordsModel;
- use catchAdmin\alarm\model\AlarmReport as alarmReportModel;
- use catchAdmin\stations\model\Station as stationModel;
- use catchAdmin\permissions\model\Users as usersModel;
- class Preview extends CatchController
- {
- use DataRangScopeTrait;
- protected $alarmRecordsModel;
- protected $alarmReportModel;
- protected $stationModel;
- protected $usersModel;
-
- public function __construct(alarmReportModel $alarmReportModel,alarmRecordsModel $alarmRecordsModel,stationModel $stationModel,usersModel $usersModel)
- {
- $this->alarmReportModel = $alarmReportModel;
- $this->alarmRecordsModel = $alarmRecordsModel;
- $this->stationModel = $stationModel;
- $this->usersModel = $usersModel;
- }
-
- function randFloat($min=0, $max=1){
- return $min + mt_rand()/mt_getrandmax() * ($max-$min);
- }
- /**
- * 获取地图上所有设备地址 以及信号统计 井类型统计
- *
- */
- public function getDeviceAddressList(){
- // $deviceList=$this->mainDevice->select()->toArray();
- $start=$_REQUEST['start']?$_REQUEST['start']*10000:0;
- $limit=$_REQUEST['limit']?:10000;
-
- // $deviceList=$this->deviceModel->dataRange()->limit($start,$limit)->cache(60)->column('id,point_x,point_y,addr,well_type');
- // var_dump($deviceList);
- $addrList=array();
- for($i=0;$i<50;$i++){
- $a=mt_rand();
- $b=mt_getrandmax();
- $c=$a/$b;
- $lng=mt_rand(100, 118)+$c;
- $lat=mt_rand(25, 35)+$c;
- // var_dump($lng);
- // var_dump($lat);
- $item=array('value'=>[$lng, $lat],'name'=>"测试风场".$i,'address'=>'风场位置'.$i,'number'=>mt_rand(0, 20));
- array_push($addrList,$item);
- }
- // foreach($deviceList as $val){
- // $item=array('value'=>[$val['point_y'], $val['point_x']],'name'=>$val['addr']);
- // array_push($addrList,$item);
- // }
- $res['addrList']=$addrList;
- // $res['total']=$this->deviceModel->dataRange()->count();
- $res['total']=80;
- return CatchResponse::success($res);
-
- }
-
- /**
- * 获取智能插座统计
- *
- */
- public function getSocketStationTotal(){
- // $deviceList=$this->mainDevice->select()->toArray();
- $request_interval=Db::table("sys_config")->where('type','station_config')->where('field','request_interval')->value('fieldValue');
- $online_time=date('Y-m-d H:i:s',time()-$request_interval);
- $res=[];
- $res['tatol']=$this->stationModel->dataRange()->where('station_type',3)->count();
- $res['online']=$this->stationModel->dataRange()->where('station_type',3)->where('online_time','>',$online_time)->count();
- $res['offline']=$res['tatol']-$res['online'];
- $yAxisData[]=$res['tatol'];
- $yAxisData[]=$res['online'];
- $yAxisData[]=$res['offline'];
- $xAxisData=["总数", "在线", "离线"];//X轴坐标
- $total=array('yAxisData'=>$yAxisData,'xAxisData'=>$xAxisData);
- return CatchResponse::success($total);
-
- }
- /**
- * 电子校徽统计
- *
- */
- public function getSchoolBadgeTotal(){
- $online_time=date('Y-m-d',time()).' 00:00:00';
- $res=[];
- $res['tatol']=$this->usersModel->dataRange()->where('card_type',2)->count();
- $res['online']=$this->usersModel->dataRange()->where('card_type',2)->where('online_time','>',$online_time)->count();
- $res['offline']=$res['tatol']-$res['online'];
- $yAxisData[]=$res['tatol'];
- $yAxisData[]=$res['online'];
- $yAxisData[]=$res['offline'];
- $yAxisData[]=0;
- $xAxisData=["总数", "在线", "离线",'围栏内'];//X轴坐标
- $total=array('yAxisData'=>$yAxisData,'xAxisData'=>$xAxisData);
- return CatchResponse::success($total);
- }
-
-
- /**
- * 设备月告警统计
- *
- */
- public function deviceMonthAlarmData(){
- $xAxisData = [];
- $yAxisData = [];
- for ($i=1; $i<=30; $i++){
- $day = date('Y-m-d' ,strtotime( '+' . $i-30 .' days', time()));
- array_push($xAxisData,$day);
- $count=$this->alarmReportModel->dataRange()->where('alarm_time','between',[$day." 00:00:00",$day." 23:59:59"])->count();
- //模拟数量
- $count+=mt_rand(0,10);
- array_push($yAxisData,$count);
- }
- $res=array('yAxisData'=>$yAxisData,'xAxisData'=>$xAxisData);
- return CatchResponse::success($res);
- }
- /**
- *围栏告警统计
- *
- */
- public function realTimeAlarmData(){
- $time=date("Y-m-d"." 00:00:00",time());
- $alarm_list = $this->alarmReportModel
- ->dataRange()
- ->field('id,active_rfid,created_at,alarm_type,alarm_time')
- ->where('alarm_time','>',$time)
- ->whereIn('alarm_type','fence_in,fence_out')
- ->select()->toArray();
- $type_id = Db::table("sys_dict_type")->where('code','AlarmReason')->value('id');
-
- $scrollData=[];
- foreach($alarm_list as $val){
- $alarm_type = Db::table("sys_dict_data")->where(['type_id'=>$type_id,'code'=>$val['alarm_type']])->value('value');
- $scrollItem=array('date'=>$val['alarm_time'],'title'=>'学生'.substr($val['active_rfid'],-5).'发生了'.$alarm_type);
- array_push($scrollData,$scrollItem);
- }
- $res=array('scrollData'=>$scrollData);
- return CatchResponse::success($res);
- }
- /**
- *SOS告警统计
- *
- */
- public function getSosScrollAlarmData(){
- $time=date("Y-m-d"." 00:00:00",time());
- $alarm_list = $this->alarmReportModel->dataRange()->where('alarm_time','>',$time)->where('alarm_type','press')->select()->toArray();
-
- foreach($alarm_list as &$val){
- $urgent_list=Db::table('kq_urgent')->where('student_id',$val['student_id'])->column('name,phone');
- $urgent_text='';
- foreach($urgent_list as $item){
- $urgent_text .=$item['name'].'('.$item['phone'].'),';
- }
- $urgent_text=trim($urgent_text,',');
- $val['urgent_text']=$urgent_text;
- }
-
- return CatchResponse::success($alarm_list);
- }
-
-
-
-
- }
|