Preview.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. function randFloat($min=0, $max=1){
  29. return $min + mt_rand()/mt_getrandmax() * ($max-$min);
  30. }
  31. /**
  32. * 获取地图上所有设备地址 以及信号统计 井类型统计
  33. *
  34. */
  35. public function getDeviceAddressList(){
  36. // $deviceList=$this->mainDevice->select()->toArray();
  37. $start=$_REQUEST['start']?$_REQUEST['start']*10000:0;
  38. $limit=$_REQUEST['limit']?:10000;
  39. // $deviceList=$this->deviceModel->dataRange()->limit($start,$limit)->cache(60)->column('id,point_x,point_y,addr,well_type');
  40. // var_dump($deviceList);
  41. $addrList=array();
  42. $addrList1=array();
  43. $addrList2=array();
  44. for($i=0;$i<15;$i++){
  45. $a=mt_rand();
  46. $b=mt_getrandmax();
  47. $c=$a/$b;
  48. $lng=mt_rand(100, 118)+$c;
  49. $lat=mt_rand(25, 35)+$c;
  50. // var_dump($lng);
  51. // var_dump($lat);
  52. $item=array('value'=>[$lng, $lat],'name'=>"测试风场".$i,'address'=>'风场位置'.$i,'number'=>mt_rand(0, 20));
  53. array_push($addrList,$item);
  54. $a=mt_rand();
  55. $b=mt_getrandmax();
  56. $c=$a/$b;
  57. $lng=mt_rand(100, 118)+$c;
  58. $lat=mt_rand(25, 35)+$c;
  59. // var_dump($lng);
  60. // var_dump($lat);
  61. $item=array('value'=>[$lng, $lat],'name'=>"测试风场".$i,'address'=>'风场位置'.$i,'number'=>mt_rand(0, 20));
  62. array_push($addrList1,$item);
  63. $a=mt_rand();
  64. $b=mt_getrandmax();
  65. $c=$a/$b;
  66. $lng=mt_rand(100, 118)+$c;
  67. $lat=mt_rand(25, 35)+$c;
  68. // var_dump($lng);
  69. // var_dump($lat);
  70. $item=array('value'=>[$lng, $lat],'name'=>"测试风场".$i,'address'=>'风场位置'.$i,'number'=>mt_rand(0, 20));
  71. array_push($addrList2,$item);
  72. }
  73. // foreach($deviceList as $val){
  74. // $item=array('value'=>[$val['point_y'], $val['point_x']],'name'=>$val['addr']);
  75. // array_push($addrList,$item);
  76. // }
  77. $res['addrList']=$addrList;
  78. $res['addrList1']=$addrList1;
  79. $res['addrList2']=$addrList2;
  80. // $res['total']=$this->deviceModel->dataRange()->count();
  81. $res['total']=80;
  82. return CatchResponse::success($res);
  83. }
  84. /**
  85. * 获取智能插座统计
  86. *
  87. */
  88. public function getSocketStationTotal(){
  89. // $deviceList=$this->mainDevice->select()->toArray();
  90. $request_interval=Db::table("sys_config")->where('type','station_config')->where('field','request_interval')->value('fieldValue');
  91. $online_time=date('Y-m-d H:i:s',time()-$request_interval);
  92. $res=[];
  93. $res['tatol']=$this->stationModel->dataRange()->where('station_type',3)->count();
  94. $res['online']=$this->stationModel->dataRange()->where('station_type',3)->where('online_time','>',$online_time)->count();
  95. $res['offline']=$res['tatol']-$res['online'];
  96. $yAxisData[]=$res['tatol'];
  97. $yAxisData[]=$res['online'];
  98. $yAxisData[]=$res['offline'];
  99. $xAxisData=["总数", "在线", "离线"];//X轴坐标
  100. $total=array('yAxisData'=>$yAxisData,'xAxisData'=>$xAxisData);
  101. return CatchResponse::success($total);
  102. }
  103. /**
  104. * 电子校徽统计
  105. *
  106. */
  107. public function getSchoolBadgeTotal(){
  108. $online_time=date('Y-m-d',time()).' 00:00:00';
  109. $res=[];
  110. $res['tatol']=$this->usersModel->dataRange()->where('card_type',2)->count();
  111. $res['online']=$this->usersModel->dataRange()->where('card_type',2)->where('online_time','>',$online_time)->count();
  112. $res['offline']=$res['tatol']-$res['online'];
  113. $yAxisData[]=$res['tatol'];
  114. $yAxisData[]=$res['online'];
  115. $yAxisData[]=$res['offline'];
  116. $yAxisData[]=0;
  117. $xAxisData=["总数", "在线", "离线",'围栏内'];//X轴坐标
  118. $total=array('yAxisData'=>$yAxisData,'xAxisData'=>$xAxisData);
  119. return CatchResponse::success($total);
  120. }
  121. /**
  122. * 设备月告警统计
  123. *
  124. */
  125. public function deviceMonthAlarmData(){
  126. $xAxisData = [];
  127. $yAxisData = [];
  128. for ($i=0; $i<=11; $i++){
  129. $day = date('Y-m' ,strtotime( '-' . $i .' Months', time()));
  130. // $nextday = date('Y-m' ,strtotime( '-' . $i-1 .' Months', time()));
  131. array_unshift($xAxisData,$day);
  132. // $count=$this->alarmReportModel->dataRange()->where('alarm_time','between',[$day."-01 00:00:00",$nextday."-01 00:00:00"])->count();
  133. //模拟数量
  134. $count=mt_rand(0,10);
  135. array_unshift($yAxisData,$count);
  136. }
  137. $res=array('yAxisData'=>$yAxisData,'xAxisData'=>$xAxisData);
  138. return CatchResponse::success($res);
  139. }
  140. /**
  141. *围栏告警统计
  142. *
  143. */
  144. public function realTimeAlarmData(){
  145. $time=date("Y-m-d"." 00:00:00",time());
  146. $alarm_list = $this->alarmReportModel
  147. ->dataRange()
  148. ->field('id,active_rfid,created_at,alarm_type,alarm_time')
  149. ->where('alarm_time','>',$time)
  150. ->whereIn('alarm_type','fence_in,fence_out')
  151. ->select()->toArray();
  152. $type_id = Db::table("sys_dict_type")->where('code','AlarmReason')->value('id');
  153. $scrollData=[];
  154. foreach($alarm_list as $val){
  155. $alarm_type = Db::table("sys_dict_data")->where(['type_id'=>$type_id,'code'=>$val['alarm_type']])->value('value');
  156. $scrollItem=array('date'=>$val['alarm_time'],'title'=>'学生'.substr($val['active_rfid'],-5).'发生了'.$alarm_type);
  157. array_push($scrollData,$scrollItem);
  158. }
  159. $res=array('scrollData'=>$scrollData);
  160. return CatchResponse::success($res);
  161. }
  162. /**
  163. *SOS告警统计
  164. *
  165. */
  166. public function getSosScrollAlarmData(){
  167. $time=date("Y-m-d"." 00:00:00",time());
  168. $alarm_list = $this->alarmReportModel->dataRange()->where('alarm_time','>',$time)->where('alarm_type','press')->select()->toArray();
  169. foreach($alarm_list as &$val){
  170. $urgent_list=Db::table('kq_urgent')->where('student_id',$val['student_id'])->column('name,phone');
  171. $urgent_text='';
  172. foreach($urgent_list as $item){
  173. $urgent_text .=$item['name'].'('.$item['phone'].'),';
  174. }
  175. $urgent_text=trim($urgent_text,',');
  176. $val['urgent_text']=$urgent_text;
  177. }
  178. return CatchResponse::success($alarm_list);
  179. }
  180. }