Message.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace catchAdmin\message\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 think\facade\Db;
  8. use catchAdmin\permissions\model\DataRangScopeTrait;
  9. use catchAdmin\alarm\model\AlarmRecords as alarmRecordsModel;
  10. class Message extends CatchController
  11. {
  12. use DataRangScopeTrait;
  13. protected $alarmRecordsModel;
  14. public function __construct(AlarmRecordsModel $alarmRecordsModel)
  15. {
  16. $this->alarmRecordsModel = $alarmRecordsModel;
  17. }
  18. /**
  19. * 获取告警通知列表
  20. *
  21. */
  22. public function list(Request $request) : \think\Response
  23. {
  24. $condition = $request->param();
  25. if(!$condition['params']['query']['msgType'] || $condition['params']['query']['msgType'] == 'alarm'){
  26. $list = $this->alarmRecordsModel->dataRange()
  27. // ->field('id,state as title,department_name as content,created_at as createTime')
  28. ->field('id,state,alarm_reason,has_read,depart_id,device_type,asset_no,start_time,updated_at')
  29. ->where(['deleted_at'=>0,'has_read'=>0])->order('id', 'desc')->paginate($condition['params']['pageSize'])
  30. ->each(function($item, $key){
  31. $item['title'] = '告警'.(new SysDictData())->getValueByCode('AlarmState',$item['state']);
  32. $department_name = Db::table('departments')->where('id',$item['depart_id'])->value('department_name');
  33. $device_type = (new SysDictData())->getValueByCode('DeviceType',$item['device_type']);
  34. $alarm_reason = (new SysDictData())->getValueByCode('AlarmReason',$item['alarm_reason']);
  35. $item['content'] = $department_name."单位的".$item['asset_no'].'('.$device_type.')'.'发生了'.$alarm_reason;
  36. $item['hasRead'] = $item['has_read'];
  37. $item['start_time'] = strtotime($item['start_time']);
  38. $item['current_time'] = time();
  39. return $item;
  40. });
  41. return CatchResponse::paginate($list);
  42. }else{
  43. return CatchResponse::success();
  44. }
  45. }
  46. }