123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
- namespace catchAdmin\alarm\controller;
- use catcher\base\CatchRequest as Request;
- use catcher\CatchResponse;
- use catcher\base\CatchController;
- use catchAdmin\alarm\model\ControlAlarm as controlAlarmModel;
- use think\facade\Db;
- class ControlAlarm extends CatchController
- {
- protected $controlAlarmModel;
-
- public function __construct(controlAlarmModel $controlAlarmModel)
- {
- $this->controlAlarmModel = $controlAlarmModel;
- }
-
- /**
- * 列表
- * @time 2022年10月27日 15:33
- * @param Request $request
- */
- public function index(Request $request) : \think\Response
- {
- return CatchResponse::paginate($this->controlAlarmModel->getList());
- }
-
- /**
- * 保存信息
- * @time 2022年10月27日 15:33
- * @param Request $request
- */
- public function save(Request $request) : \think\Response
- {
- return CatchResponse::success($this->controlAlarmModel->storeBy($request->post()));
- }
-
- /**
- * 读取
- * @time 2022年10月27日 15:33
- * @param $id
- */
- public function read($id) : \think\Response
- {
- return CatchResponse::success($this->controlAlarmModel->findBy($id));
- }
-
- /**
- * 更新
- * @time 2022年10月27日 15:33
- * @param Request $request
- * @param $id
- */
- public function update(Request $request, $id) : \think\Response
- {
- return CatchResponse::success($this->controlAlarmModel->updateBy($id, $request->post()));
- }
-
- /**
- * 删除
- * @time 2022年10月27日 15:33
- * @param $id
- */
- public function delete($id) : \think\Response
- {
- return CatchResponse::success($this->controlAlarmModel->deleteBy($id));
- }
- /**
- * 获取今日告警列
- * @param Request $request
- */
- public function getTodayAlarmlist(Request $request){
- $start_time = date('Y-m-d 00:00:00',time()-7*24*3600);
- $end_time = date('Y-m-d 23:59:59',time());
- $xAxisData=[];
- $yAxisData=[];
- $list=$this->controlAlarmModel
- ->catchSearch()
- ->append(['state_text'])
- ->whereBetweenTime('created_at', $start_time,$end_time)
- ->order('created_at', 'desc')
- ->select();
-
- // $list=[
- // ['created_at'=>'2023-11-13 08:15:40','plate_no'=>'江北003931','address'=>'HS0577科创北路与布政东路交叉口'],
- // ['created_at'=>'2023-11-13 09:25:10','plate_no'=>'江北019216','address'=>'HS0086联丰中路如家酒店门口-FX1'],
- // ['created_at'=>'2023-11-13 09:32:13','plate_no'=>'江北028692','address'=>'JB287中官西路广汽丰田对面1'],
- // ['created_at'=>'2023-11-13 10:15:34','plate_no'=>'江北023166','address'=>'BL031学院路-学院南路东南-FX1'],
- // ['created_at'=>'2023-11-13 11:13:25','plate_no'=>'江北003931','address'=>'HZW兴慈三路——七塘公路'],
- // ['created_at'=>'2023-11-13 12:20:06','plate_no'=>'江北025106','address'=>'江北新增12月份JB38姚江花园门口1'],
- // ['created_at'=>'2023-11-13 12:21:20','plate_no'=>'江北003931','address'=>'JB新增点002长兴东路与洪都路2'],
- // ['created_at'=>'2023-11-13 13:15:12','plate_no'=>'江北003931','address'=>'FH27桥西岸路与岳林路1-FXQ'],
- // ];
- // return $rows;
- return CatchResponse::success($list);
- }
- /**
- * 报警点统计
- * @param Request $request
- */
- public function totalAlarmAddress(Request $request){
- $start_time = date('Y-m-d 00:00:00',time()-7*24*3600);
- $end_time = date('Y-m-d 23:59:59',time());
- $xAxisData=[];
- $yAxisData=[];
-
- $list=$this->controlAlarmModel
- ->field('address,count(*) as num')
- ->group('address')
- ->whereBetweenTime('created_at', $start_time,$end_time)
- ->order('num desc')
- ->select();
- foreach($list as $val){
- $xAxisData[]=$val['address'];
- $yAxisData[]=$val['num'];
- }
- // $xAxisData=['HS0577科创北路与布政东路交叉口','HS0086联丰中路如家酒店门口','JB287中官西路广汽丰田对面1','BL031学院路-学院南路东南-FX1','HZW兴慈三路——七塘公路','江北新增12月份JB38姚江花园门口1','JB新增点002长兴东路与洪都路2'];
- // $yAxisData=['70','65','47','40','35','20','9'];
- // return $rows;
- return CatchResponse::success(['xAxisData'=>$xAxisData,'yAxisData'=>$yAxisData]);
- }
-
- }
|