12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace catchAdmin\message\controller;
- use catcher\base\CatchRequest as Request;
- use catcher\CatchResponse;
- use catcher\base\CatchController;
- use catchAdmin\system\model\SysDictData;
- use think\facade\Db;
- use catchAdmin\permissions\model\DataRangScopeTrait;
- use catchAdmin\alarm\model\AlarmRecords as alarmRecordsModel;
- class Message extends CatchController
- {
- use DataRangScopeTrait;
- protected $alarmRecordsModel;
-
- public function __construct(AlarmRecordsModel $alarmRecordsModel)
- {
- $this->alarmRecordsModel = $alarmRecordsModel;
- }
-
- /**
- * 获取告警通知列表
- *
- */
- public function list(Request $request) : \think\Response
- {
- $condition = $request->param();
- if(!$condition['params']['query']['msgType'] || $condition['params']['query']['msgType'] == 'alarm'){
- $list = $this->alarmRecordsModel->dataRange()
- // ->field('id,state as title,department_name as content,created_at as createTime')
- ->field('id,state,alarm_reason,has_read,depart_id,device_type,asset_no,start_time,updated_at')
- ->where(['deleted_at'=>0,'has_read'=>0])->order('id', 'desc')->paginate($condition['params']['pageSize'])
- ->each(function($item, $key){
- $item['title'] = '告警'.(new SysDictData())->getValueByCode('AlarmState',$item['state']);
- $department_name = Db::table('departments')->where('id',$item['depart_id'])->value('department_name');
- $device_type = (new SysDictData())->getValueByCode('DeviceType',$item['device_type']);
- $alarm_reason = (new SysDictData())->getValueByCode('AlarmReason',$item['alarm_reason']);
- $item['content'] = $department_name."单位的".$item['asset_no'].'('.$device_type.')'.'发生了'.$alarm_reason;
- $item['hasRead'] = $item['has_read'];
- $item['start_time'] = strtotime($item['start_time']);
- $item['current_time'] = time();
- return $item;
- });
- return CatchResponse::paginate($list);
- }else{
- return CatchResponse::success();
- }
-
-
- }
-
- }
|