AlarmMonitoring.php
13.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<?php
namespace app\api\controller\reservoir\hkws;
use app\api\controller\getui\JgPush;
use app\api\controller\getui\XjPush;
use app\common\controller\Api;
use fast\Tree;
use think\Request;
use think\Db;
/**
* 报警监测
* Class AlarmMonitoring
* @package app\api\controller
*/
class AlarmMonitoring extends Api
{
protected $noNeedLogin = ["alarmList"];
protected $noNeedRight = '*';
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\reservoir\hkws\AlarmMonitoring;
}
/**
* 7. 获取登录用户未读消息数(水库区分)
*/
public function unReadList()
{
//查询当前用户所属部门id
$id = $this->auth->id;
$depart_id = Db::name("inspection_staff")->where("user_id", $id)->value("depart_id");
if (!empty($depart_id)) {
//获取下级所有子部门ID
$tree = Tree::instance();
$departModel = new \app\admin\model\inspection\Depart();
$tree->init(collection($departModel->order('weigh asc,id asc')->select())->toArray(), 'pid');
$depart_ids = $tree->getChildrenIds($depart_id, true);
}
$where = [];
if (!empty($depart_ids)) {
$where["inspection_depart_id"] = ["IN", $depart_ids];
}
$reservoir_list_ids = Db::name("reservoir_list")->where($where)->column("id");
$where2 = [];
$data = [];
if (!empty($reservoir_list_ids)) {
$where2["a.reservoir_list_id"] = ["IN", $reservoir_list_ids];
}
$where2["r.user_id"] = ["=", $this->auth->id];
$where2["r.is_read"] = ["=", "0"];
$data = Db::name("reservoir_hkws_alarm_monitoring_read")->alias("r")
->join("reservoir_hkws_alarm_monitoring a", "a.id=r.reservoir_hkws_alarm_monitoring_id")
->join("reservoir_list l", "l.id=a.reservoir_list_id")
->where($where2)
->field("count(*) as total,l.name,a.reservoir_list_id,l.lat,l.lng")
->group("a.reservoir_list_id")
->select();
$this->success("数据获取成功", $data);
}
/**
* 8. 根据大屏登陆账号查看某个水库对应报警列表
*/
public function getAlarmListBySkid()
{
$skid = $this->request->param("skid");
$uid = $this->auth->id;
$curPage = $this->request->param("curPage", 1);
$pageSize = $this->request->param("pageSize", 10);
$where2 = [];
$where2["a.reservoir_list_id"] = ["=", $skid];
$where2["r.user_id"] = ["=", $this->auth->id];
$where2["r.is_read"] = ["=", "0"];
$data = Db::name("reservoir_hkws_alarm_monitoring_read")->alias("r")
->join("reservoir_hkws_alarm_monitoring a", "a.id=r.reservoir_hkws_alarm_monitoring_id")
->join("reservoir_list l", "l.id=a.reservoir_list_id")
->join("reservoir_hkws_hardware h", "h.indexCode=a.cameraIndexCode", "LEFT")
->where($where2)
->field("h.name as jk_name,l.name,a.id,a.cameraIndexCode,a.alarm_type,a.alarmimage,a.reservoir_list_id,a.createtime,a.status,r.is_read,r.readtime")
->order("a.createtime desc")
->page($curPage, $pageSize)
->select();
$model = new \app\admin\model\reservoir\hkws\AlarmMonitoring();
$typeList = $model->getAlarmTypeList();
$colorList = ['LINE_CROSSING_DETECTION' => "color:#ffdb5c;", 'REGION_ENTRANCE_DETECTION' => "color:#32c5e9;", 'INTRUSION_DETECTION' => "color:#ff9f7f;"];
$statusList = $model->getStatusList();
$return_data = [];
$return_data["head"] = ["报警时间", "报警类型", "水库名称", "处理状态"];
if (!empty($data)) {
foreach ($data as $k => $v) {
$data[$k]['alarmimage'] = $v['alarmimage'] ? "https://qiniu.ynzhsk.cn" . $v['alarmimage'] : $v['alarmimage'];
$data[$k]['createtime'] = date("Y-m-d H:i:s", $v['createtime']);
$data[$k]['alarm_type'] = "<span style=\"" . $colorList[$v['alarm_type']] . "\">" . $typeList[$v['alarm_type']] . "</span>";
$data[$k]['status'] = $statusList[$v['status']];
}
}
$this->success("数据获取成功", $data);
}
/**
* 9. 根据监控点返回入侵信息
*/
public function alarmList()
{
$cameraIndexCode = $this->request->param("cameraIndexCode");//监控点编号
$data = [];
if (!empty($cameraIndexCode)) {
$data = $this->model->where("cameraIndexCode", $cameraIndexCode)->order("createtime desc")->select();
}
$return_data = [];
if (!empty($data)) {
foreach ($data as $k => $v) {
$pic = $v['alarmimage'] ? "https://qiniu.ynzhsk.cn" . $v['alarmimage'] : $v['alarmimage'];
$return_data[$k]["id"] = $v['id'];
$return_data[$k]['alarm_type'] = $v['alarm_type'];
$return_data[$k]['alarm_type_text'] = $v['alarm_type_text'];
$return_data[$k]['status_text'] = $v['status_text'];
$return_data[$k]['alarmimage'] = $pic;
$return_data[$k]['createtime'] = date("Y-m-d H:i:s", $v['createtime']);
}
}
$this->success("入侵记录获取成功", $return_data);
}
/**
* 9. 最新一条报警数据(根据登陆者账号判断)
*/
public function lastAlarmData()
{
//查询当前用户所属部门id
$id = $this->auth->id;
$depart_id = Db::name("inspection_staff")->where("user_id", $id)->value("depart_id");
if (!empty($depart_id)) {
//获取下级所有子部门ID
$tree = Tree::instance();
$departModel = new \app\admin\model\inspection\Depart();
$tree->init(collection($departModel->order('weigh asc,id asc')->select())->toArray(), 'pid');
$depart_ids = $tree->getChildrenIds($depart_id, true);
}
$where = [];
if (!empty($depart_ids)) {
$where["inspection_depart_id"] = ["IN", $depart_ids];
}
$reservoir_list_ids = Db::name("reservoir_list")->where($where)->column("id");
$where2 = [];
$data = [];
if (!empty($reservoir_list_ids)) {
$where2["a.reservoir_list_id"] = ["IN", $reservoir_list_ids];
}
$where2["r.user_id"] = ["=", $this->auth->id];
$where2["r.is_read"] = ["=", "0"];
$data = Db::name("reservoir_hkws_alarm_monitoring_read")->alias("r")
->join("reservoir_hkws_alarm_monitoring a", "a.id=r.reservoir_hkws_alarm_monitoring_id")
->join("reservoir_list l", "l.id=a.reservoir_list_id")
->join("reservoir_hkws_hardware h", "h.indexCode=a.cameraIndexCode", "LEFT")
->where($where2)
->field("h.name as jk_name,l.name,l.lat,l.lng,a.cameraIndexCode,a.alarm_type,a.alarmimage,a.reservoir_list_id,a.createtime,a.status,r.is_read,r.readtime")
->order("r.id desc")
->find();
if (!empty($data)) {
$model = new \app\admin\model\reservoir\hkws\AlarmMonitoring();
$typeList = $model->getAlarmTypeList();
$statusList = $model->getStatusList();
$data['alarmimage'] = $data['alarmimage'] ? "https://qiniu.ynzhsk.cn" . $data['alarmimage'] : $data['alarmimage'];
$data['createtime'] = date("Y-m-d H:i:s", $data['createtime']);
$data['alarm_type'] = $typeList[$data['alarm_type']];
$data['status'] = $statusList[$data['status']];
}
$this->success("", $data);
//
// $model = new \app\admin\model\reservoir\hkws\AlarmMonitoring();
// $typeList = $model->getAlarmTypeList();
// $colorList = ['LINE_CROSSING_DETECTION' => "color:#ffdb5c;", 'REGION_ENTRANCE_DETECTION' => "color:#32c5e9;", 'INTRUSION_DETECTION' => "color:#ff9f7f;"];
//
// $statusList = $model->getStatusList();
//
// if (!empty($data)) {
// $pic = "";
// $pic = $data['alarmimage'] ? "https://qiniu.ynzhsk.cn" . $data['alarmimage'] : $data['alarmimage'];
// $return_data[] = date("Y-m-d H:i:s", $data['createtime']);
// $return_data[] = "<span style=\"" . $colorList[$data['alarm_type']] . "\">" . $typeList[$data['alarm_type']] . "</span>";
// $return_data[] = $data['name'];
// $return_data[] = $statusList[$data['status']];
//
// $return_data["attr"][$k] = ["cameraIndexCode" => $data['cameraIndexCode'], "alarmimage" => $pic, "jk_name" => $data['jk_name']];
// }
}
/**
* 10. 获取某个水库巡检人员列表
*/
public function getReservoirStaffList()
{
$reservoir_id = $this->request->param("reservoir_id");
if (empty($reservoir_id)) {
$this->error("水库id不能为空");
}
$where = [];
$where = [
"reservoir_id" => $reservoir_id,
"is_screen_mng" => "0",
"is_regulatory_mng" => "0"
];
$field = "id,user_id,staff_code,staff_name,mobile,duty,reservoir_id";
$staff = Db::name("inspection_staff")->where($where)->field($field)->select();
if (!empty($staff)) {
$this->success("水库巡检人员获取成功", $staff);
} else {
$this->error("此水库暂无巡检人员,请联系管理员配置水库巡检员");
}
}
/**
* 11. 确认指派巡检人处理异常
*/
public function appointStaffDealAlarm()
{
$param = $this->request->param();
if (empty($param['reservoir_id'])) {
$this->error("水库id不能为空");
}
if (empty($param['alarm_id'])) {
$this->error("报警记录id不能为空");
}
$alarm = Db::name("reservoir_hkws_alarm_monitoring")->where("id", $param['alarm_id'])->find();
if (empty($alarm)) {
$this->error("未获取到报警记录");
} elseif ($alarm['status'] != "0") {
$this->error("此报警已处理过,无需重复操作");
}
//处理类型(1:当前大屏登陆者自己已处理 2:派给巡检员处理)
if (!in_array($param['deal_type'], [1, 2])) {
$this->error("请选择有效的处理类型");
}
if ($param['deal_type'] == 2) {
//派给巡检员处理
if (empty($param['staff_id'])) {
$this->error("请选择巡检员");
} else {
$w_staff = [
"id" => $param['staff_id'],
"is_screen_mng" => "0",
"is_regulatory_mng" => "0"
];
$staff = Db::name("inspection_staff")->where($w_staff)->count();
if ($staff == 0) {
$this->error("无效的巡检员");
}
}
}
if ($param['deal_type'] == 1) {
$staff_id = Db::name("inspection_staff")->where("user_id", $this->auth->id)->value("id");
} else {
$staff_id = $param['staff_id'];
}
$update_data = [
"status" => 1,
"deal_type" => $param['deal_type'],
"inspection_staff_id" => $staff_id,
"deal_time" => time()
];
$res = Db::name("reservoir_hkws_alarm_monitoring")->where("id", $param['alarm_id'])->update($update_data);
if ($res) {
Db::name("reservoir_hkws_alarm_monitoring_read")
->where(["reservoir_hkws_alarm_monitoring_id" => $param['alarm_id'], "user_id" => $this->auth->id])
->update(["is_read" => "1", "readtime" => time()]);
if ($param['deal_type'] == 2) {
//插入数据到隐患表
$rr = Db::name("reservoir_hkws_alarm_monitoring")->where("id", $param['alarm_id'])->find();
$AlarmMonitoringModel = new \app\admin\model\reservoir\hkws\AlarmMonitoring();
$alarm_type_list = $AlarmMonitoringModel->getAlarmTypeList();
$yh_data = [
"title" => $alarm_type_list[$rr['alarm_type']],
"message" => $alarm_type_list[$rr['alarm_type']],
// "area_id" => null,
"staff_id" => $staff_id,
"status" => "1",
"createtime" => time(),
"cover_images" => $rr['alarmimage'],
];
$new_id = Db::name("inspection_warning")->insertGetId($yh_data);
if ($new_id) {
//发送推送通知
$pushApi = new XjPush();
$res2 = $pushApi->pushPitfall($new_id);
// file_put_contents("1111.log", date("Y-m-d H:i:s") . json_encode($res2, JSON_UNESCAPED_UNICODE) . PHP_EOL, FILE_APPEND);
}
}
$msg = $param['deal_type'] == 1 ? "报警处理成功" : "报警指派处理成功";
$this->success($msg);
} else {
$this->error("报警处理失败,请刷新后重试");
}
}
}