Preview.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. namespace catchAdmin\screen\controller;
  3. use catcher\base\CatchRequest as Request;
  4. use catcher\CatchResponse;
  5. use catcher\base\CatchController;
  6. use catchAdmin\system\model\SysDictData;
  7. use catchAdmin\permissions\model\SysConfig;
  8. use think\facade\Db;
  9. use catchAdmin\permissions\model\DataRangScopeTrait;
  10. use catchAdmin\alarm\model\AlarmRecords as alarmRecordsModel;
  11. use catchAdmin\alarm\model\AlarmReport as alarmReportModel;
  12. use catchAdmin\stations\model\Station as stationModel;
  13. use catchAdmin\permissions\model\Users as usersModel;
  14. class Preview extends CatchController
  15. {
  16. use DataRangScopeTrait;
  17. protected $alarmRecordsModel;
  18. protected $alarmReportModel;
  19. protected $stationModel;
  20. protected $usersModel;
  21. public function __construct(alarmReportModel $alarmReportModel,alarmRecordsModel $alarmRecordsModel,stationModel $stationModel,usersModel $usersModel)
  22. {
  23. $this->alarmReportModel = $alarmReportModel;
  24. $this->alarmRecordsModel = $alarmRecordsModel;
  25. $this->stationModel = $stationModel;
  26. $this->usersModel = $usersModel;
  27. }
  28. /**
  29. * 获取智能插座统计
  30. *
  31. */
  32. public function getSocketStationTotal(){
  33. // $deviceList=$this->mainDevice->select()->toArray();
  34. $request_interval=Db::table("sys_config")->where('type','station_config')->where('field','request_interval')->value('fieldValue');
  35. $online_time=date('Y-m-d H:i:s',time()-$request_interval);
  36. $res=[];
  37. $res['tatol']=$this->stationModel->dataRange()->where('station_type',3)->count();
  38. $res['online']=$this->stationModel->dataRange()->where('station_type',3)->where('online_time','>',$online_time)->count();
  39. $res['offline']=$res['tatol']-$res['online'];
  40. $yAxisData[]=$res['tatol'];
  41. $yAxisData[]=$res['online'];
  42. $yAxisData[]=$res['offline'];
  43. $xAxisData=["总数", "在线", "离线"];//X轴坐标
  44. $total=array('yAxisData'=>$yAxisData,'xAxisData'=>$xAxisData);
  45. return CatchResponse::success($total);
  46. }
  47. /**
  48. * 电子校徽统计
  49. *
  50. */
  51. public function getSchoolBadgeTotal(){
  52. $online_time=date('Y-m-d',time()).' 00:00:00';
  53. $res=[];
  54. $res['tatol']=$this->usersModel->dataRange()->where('card_type',2)->count();
  55. $res['online']=$this->usersModel->dataRange()->where('card_type',2)->where('online_time','>',$online_time)->count();
  56. $res['offline']=$res['tatol']-$res['online'];
  57. $yAxisData[]=$res['tatol'];
  58. $yAxisData[]=$res['online'];
  59. $yAxisData[]=$res['offline'];
  60. $yAxisData[]=0;
  61. $xAxisData=["总数", "在线", "离线",'围栏内'];//X轴坐标
  62. $total=array('yAxisData'=>$yAxisData,'xAxisData'=>$xAxisData);
  63. return CatchResponse::success($total);
  64. }
  65. /**
  66. * 设备月告警统计
  67. *
  68. */
  69. public function deviceMonthAlarmData(){
  70. $xAxisData = [];
  71. $yAxisData = [];
  72. for ($i=1; $i<=30; $i++){
  73. $day = date('Y-m-d' ,strtotime( '+' . $i-30 .' days', time()));
  74. array_push($xAxisData,$day);
  75. $count=$this->alarmReportModel->dataRange()->where('alarm_time','between',[$day." 00:00:00",$day." 23:59:59"])->count();
  76. array_push($yAxisData,$count);
  77. }
  78. $res=array('yAxisData'=>$yAxisData,'xAxisData'=>$xAxisData);
  79. return CatchResponse::success($res);
  80. }
  81. /**
  82. *围栏告警统计
  83. *
  84. */
  85. public function realTimeAlarmData(){
  86. $time=date("Y-m-d"." 00:00:00",time());
  87. $alarm_list = $this->alarmReportModel
  88. ->dataRange()
  89. ->field('id,active_rfid,created_at,alarm_type,alarm_time')
  90. ->where('alarm_time','>',$time)
  91. ->whereIn('alarm_type','fence_in,fence_out')
  92. ->select()->toArray();
  93. $type_id = Db::table("sys_dict_type")->where('code','AlarmType')->value('id');
  94. $scrollData=[];
  95. foreach($alarm_list as $val){
  96. $alarm_type = Db::table("sys_dict_data")->where(['type_id'=>$type_id,'code'=>$val['alarm_type']])->value('value');
  97. $scrollItem=array('date'=>$val['alarm_time'],'title'=>'学生'.substr($val['active_rfid'],-5).'发生了'.$alarm_type);
  98. array_push($scrollData,$scrollItem);
  99. }
  100. $res=array('scrollData'=>$scrollData);
  101. return CatchResponse::success($res);
  102. }
  103. /**
  104. *SOS告警统计
  105. *
  106. */
  107. public function getSosScrollAlarmData(){
  108. $time=date("Y-m-d"." 00:00:00",time());
  109. $alarm_list = $this->alarmReportModel->dataRange()->where('alarm_time','>',$time)->where('alarm_type','press')->select()->toArray();
  110. foreach($alarm_list as &$val){
  111. $urgent_list=Db::table('kq_urgent')->where('student_id',$val['student_id'])->column('name,phone');
  112. $urgent_text='';
  113. foreach($urgent_list as $item){
  114. $urgent_text .=$item['name'].'('.$item['phone'].'),';
  115. }
  116. $urgent_text=trim($urgent_text,',');
  117. $val['urgent_text']=$urgent_text;
  118. }
  119. return CatchResponse::success($alarm_list);
  120. }
  121. }