Warningv2.php
20.1 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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
<?php
namespace app\api\controller\reservoir\warning;
use app\common\controller\Api;
use think\Request;
use think\Db;
/**
* Class Waterlevel
* @package app\api\controller
*/
class Warningv2 extends Api
{
protected $noNeedLogin = ['*'];
public function getWarningCountbyday()
{
$count = [];
//当日
$time = 1;
$lasttime = strtotime(date('Y-m-d 23:59:59')) - $time * 60 * 60 * 24;
$cond['reservoir_id'] = ['in', '4,6,9'];
$cond['createtime'] = ['between', [$lasttime, strtotime(date('Y-m-d 23:59:59'))]];
$crack = Db::name('reservoir_warning_crack')->where($cond)->count();
//$displacement = Db::name('reservoir_warning_displacement')->where($cond)->count();
$rainfall = Db::name('reservoir_warning_rainfall')->where($cond)->count();
$settlement = Db::name('reservoir_warning_settlement')->where($cond)->count();
$waterlevel = Db::name('reservoir_warning_waterlevel')->where($cond)->count();
$waterseepage = Db::name('reservoir_warning_waterseepage')->where($cond)->count();
$weather = Db::name('reservoir_warning_weather')->where($cond)->count();
$count['day'] = $crack + $rainfall + $settlement + $waterlevel + $waterseepage + $weather;
//$count['day'] = $crack+$displacement+$rainfall+$settlement+$waterlevel+$waterseepage+$weather;
//当月
$time = 30;
$lasttime = strtotime(date('Y-m-d 23:59:59')) - $time * 60 * 60 * 24;
$cond['reservoir_id'] = ['in', '4,6,9'];
$cond['createtime'] = ['between', [$lasttime, strtotime(date('Y-m-d 23:59:59'))]];
$crack = Db::name('reservoir_warning_crack')->where($cond)->count();
//$displacement = Db::name('reservoir_warning_displacement')->where($cond)->count();
$rainfall = Db::name('reservoir_warning_rainfall')->where($cond)->count();
$settlement = Db::name('reservoir_warning_settlement')->where($cond)->count();
$waterlevel = Db::name('reservoir_warning_waterlevel')->where($cond)->count();
$waterseepage = Db::name('reservoir_warning_waterseepage')->where($cond)->count();
$weather = Db::name('reservoir_warning_weather')->where($cond)->count();
$count['month'] = $crack + $rainfall + $settlement + $waterlevel + $waterseepage + $weather;
//$count['month'] = $crack+$displacement+$rainfall+$settlement+$waterlevel+$waterseepage+$weather;
//当季
$time = 90;
$lasttime = strtotime(date('Y-m-d 23:59:59')) - $time * 60 * 60 * 24;
$cond['reservoir_id'] = ['in', '4,6,9'];
$cond['createtime'] = ['between', [$lasttime, strtotime(date('Y-m-d 23:59:59'))]];
$crack = Db::name('reservoir_warning_crack')->where($cond)->count();
//$displacement = Db::name('reservoir_warning_displacement')->where($cond)->count();
$rainfall = Db::name('reservoir_warning_rainfall')->where($cond)->count();
$settlement = Db::name('reservoir_warning_settlement')->where($cond)->count();
$waterlevel = Db::name('reservoir_warning_waterlevel')->where($cond)->count();
$waterseepage = Db::name('reservoir_warning_waterseepage')->where($cond)->count();
$weather = Db::name('reservoir_warning_weather')->where($cond)->count();
//$count['quarter'] = $crack+$displacement+$rainfall+$settlement+$waterlevel+$waterseepage+$weather;
$count['quarter'] = $crack + $rainfall + $settlement + $waterlevel + $waterseepage + $weather;
//当年
$time = 365;
$lasttime = strtotime(date('Y-m-d 23:59:59')) - $time * 60 * 60 * 24;
$cond['reservoir_id'] = ['in', '4,6,9'];
$cond['createtime'] = ['between', [$lasttime, strtotime(date('Y-m-d 23:59:59'))]];
$crack = Db::name('reservoir_warning_crack')->where($cond)->count();
//$displacement = Db::name('reservoir_warning_displacement')->where($cond)->count();
$rainfall = Db::name('reservoir_warning_rainfall')->where($cond)->count();
$settlement = Db::name('reservoir_warning_settlement')->where($cond)->count();
$waterlevel = Db::name('reservoir_warning_waterlevel')->where($cond)->count();
$waterseepage = Db::name('reservoir_warning_waterseepage')->where($cond)->count();
$weather = Db::name('reservoir_warning_weather')->where($cond)->count();
//$count['year'] = $crack+$displacement+$rainfall+$settlement+$waterlevel+$waterseepage+$weather;
$count['year'] = $crack + $rainfall + $settlement + $waterlevel + $waterseepage + $weather;
$this->success('成功', $count);
}
public function getWarningCountbyday1()
{
$time = 1;
$lasttime = strtotime(date('Y-m-d 23:59:59')) - $time * 60 * 60 * 24;
$cond['reservoir_id'] = ['in', '4,6,9'];
$cond['createtime'] = ['between', [$lasttime, strtotime(date('Y-m-d 23:59:59'))]];
$crack = Db::name('reservoir_warning_crack')->where($cond)->count();
$displacement = Db::name('reservoir_warning_displacement')->where($cond)->count();
$rainfall = Db::name('reservoir_warning_rainfall')->where($cond)->count();
$settlement = Db::name('reservoir_warning_settlement')->where($cond)->count();
$waterlevel = Db::name('reservoir_warning_waterlevel')->where($cond)->count();
$waterseepage = Db::name('reservoir_warning_waterseepage')->where($cond)->count();
$weather = Db::name('reservoir_warning_weather')->where($cond)->count();
$count = $crack + $displacement + $rainfall + $settlement + $waterlevel + $waterseepage + $weather;
$this->success('成功', $count);
}
//获取预警总数
public function getWarningCount()
{
$id = input('get.id');//水库id
$crack = Db::name('reservoir_warning_crack')->where('reservoir_id', $id)->count();
$displacement = Db::name('reservoir_warning_displacement')->where('reservoir_id', $id)->count();
$rainfall = Db::name('reservoir_warning_rainfall')->where('reservoir_id', $id)->count();
$settlement = Db::name('reservoir_warning_settlement')->where('reservoir_id', $id)->count();
$waterlevel = Db::name('reservoir_warning_waterlevel')->where('reservoir_id', $id)->count();
$waterseepage = Db::name('reservoir_warning_waterseepage')->where('reservoir_id', $id)->count();
$weather = Db::name('reservoir_warning_weather')->where('reservoir_id', $id)->count();
$count = $crack + $displacement + $rainfall + $settlement + $waterlevel + $waterseepage + $weather;
$this->success('成功', $count);
}
//获取预警条数
public function getWarningList()
{
$id = input('get.id');//水库id
$res['crack'] = Db::name('reservoir_warning_crack')->where('reservoir_id', $id)->order('createtime desc')->limit(1)->select();
$res['displacement'] = Db::name('reservoir_warning_displacement')->where('reservoir_id', $id)->order('createtime desc')->limit(1)->select();
$res['rainfall'] = Db::name('reservoir_warning_rainfall')->where('reservoir_id', $id)->order('createtime desc')->limit(1)->select();
$res['settlement'] = Db::name('reservoir_warning_settlement')->where('reservoir_id', $id)->order('createtime desc')->limit(1)->select();
$res['waterlevel'] = Db::name('reservoir_warning_waterlevel')->where('reservoir_id', $id)->order('createtime desc')->limit(1)->select();
$res['waterseepage'] = Db::name('reservoir_warning_waterseepage')->where('reservoir_id', $id)->order('createtime desc')->limit(1)->select();
$res['weather'] = Db::name('reservoir_warning_weather')->where('reservoir_id', $id)->order('createtime desc')->limit(1)->select();
$this->success('成功', $res);
}
//通过县市id获取降水量正常异常座数
public function getRainWarningByCounty($id)
{
$reservoirids = Db::name('reservoir_list')->where('county_id', $id)->field('id')->select();
$ids = [];
foreach ($reservoirids as $k => $v) {
$ids[] = $v['id'];
}
$res['abnormal'] = Db::name('reservoir_warning_rainfall')->where('reservoir_id', 'in', $ids)->where('deal', 1)->group('reservoir_id')->count();
$res['normal'] = count($ids) - $res['abnormal'];
$this->success('', $res);
}
public function getReservoirWaterlevel($id)
{
$list = Db::name('reservoir_warning_waterlevel')
->alias('w')
->join('reservoir_list l', 'l.id=w.reservoir_id', 'LEFT')
->field('l.name,w.value,from_unixtime(w.createtime,"%Y-%m-%d") as crts')
->where('l.county_id', $id)
->order('w.createtime desc')
->limit(10)
->select();
$arr = [];
foreach ($list as $key => $item) {
$arr[$key] = [$item['name'], $item['value'], $item['crts']];
}
$this->success('', $arr);
}
//县市预警数量
public function getCountyWarningCount($id)
{
$reservoirids = Db::name('reservoir_list')->where('county_id', $id)->field('id')->select();
$ids = [];
foreach ($reservoirids as $k => $v) {
$ids[] = $v['id'];
}
$res['crack'] = Db::name('reservoir_warning_crack')->where('reservoir_id', 'in', $ids)->where('deal', 1)->count();
$res['displacement'] = Db::name('reservoir_warning_displacement')->where('reservoir_id', 'in', $ids)->where('deal', 1)->count();
$res['rainfall'] = Db::name('reservoir_warning_rainfall')->where('reservoir_id', 'in', $ids)->where('deal', 1)->count();
$res['settlement'] = Db::name('reservoir_warning_settlement')->where('reservoir_id', 'in', $ids)->where('deal', 1)->count();
$res['waterlevel'] = Db::name('reservoir_warning_waterlevel')->where('reservoir_id', 'in', $ids)->where('deal', 1)->count();
$res['waterseepage'] = Db::name('reservoir_warning_waterseepage')->where('reservoir_id', 'in', $ids)->where('deal', 1)->count();
$res['weather'] = Db::name('reservoir_warning_weather')->where('reservoir_id', 'in', $ids)->where('deal', 1)->count();
$this->success('', $res);
}
//近七天县市预警趋势 $id 县市id
public function getCountyWarningCountWeek($id)
{
$reservoirids = Db::name('reservoir_list')->where('county_id', $id)->field('id')->select();
$ids = [];
foreach ($reservoirids as $k => $v) {
$ids[] = $v['id'];
}
for ($i = 6; $i >= 1; $i--) {
$k = $i - 1;
${'predaystart' . $i} = strtotime(date('Y-m-d', strtotime("-$i day")));
${'predayend' . $i} = strtotime(date('Y-m-d', strtotime("-$k day")));
${'predaycount' . $i} = Db::name('reservoir_warning_rainfall')->where('createtime', '>=', ${'predaystart' . $i})->where('createtime', '<', ${'predayend' . $i})->where('reservoir_id', 'in', $ids)->count();
$res['date'][] = date('Y-m-d', strtotime("-$i day"));
$res['count'][] = ${'predaycount' . $i};
}
$today = strtotime(date("Y-m-d", time()));
$todaylist = Db::name('reservoir_warning_rainfall')->where('createtime', '>=', $today)->where('reservoir_id', 'in', $ids)->count();
$res['date'][] = date("Y-m-d", time());
$res['count'][] = $todaylist;
$this->success('', $res);
}
public function getRainfallValueWeek($id)
{
for ($i = 6; $i >= 1; $i--) {
$k = $i - 1;
${'predaystart' . $i} = strtotime(date('Y-m-d', strtotime("-$i day")));
${'predayend' . $i} = strtotime(date('Y-m-d', strtotime("-$k day")));
${'predayvalue' . $i} = Db::name('reservoir_warning_rainfall')
->where('createtime', '>=', ${'predaystart' . $i})
->where('createtime', '<', ${'predayend' . $i})
->where('reservoir_id', $id)
->order('createtime desc')
->value('value');
${'predayvalue' . $i} = ${'predayvalue' . $i} ? ${'predayvalue' . $i} : 0;
$res['date'][] = date('Y-m-d', strtotime("-$i day"));
$res['value'][] = ${'predayvalue' . $i};
}
$today = strtotime(date("Y-m-d", time()));
$todaylist = Db::name('reservoir_warning_rainfall')->where('createtime', '>=', $today)->where('reservoir_id', $id)->order('createtime desc')->value('value');
$res['date'][] = date("Y-m-d", time());
$res['value'][] = $todaylist;
$this->success('', $res);
}
public function getWaterlevelValueWeek($id)
{
for ($i = 6; $i >= 1; $i--) {
$k = $i - 1;
${'predaystart' . $i} = strtotime(date('Y-m-d', strtotime("-$i day")));
${'predayend' . $i} = strtotime(date('Y-m-d', strtotime("-$k day")));
${'predayvalue' . $i} = Db::name('reservoir_warning_waterlevel')
->where('createtime', '>=', ${'predaystart' . $i})
->where('createtime', '<', ${'predayend' . $i})
->where('reservoir_id', $id)
->order('createtime desc')
->value('value');
${'predayvalue' . $i} = ${'predayvalue' . $i} ? ${'predayvalue' . $i} : 0;
$res['date'][] = date('Y-m-d', strtotime("-$i day"));
$res['value'][] = ${'predayvalue' . $i};
}
$today = strtotime(date("Y-m-d", time()));
$todaylist = Db::name('reservoir_warning_waterlevel')->where('createtime', '>=', $today)->where('reservoir_id', $id)->order('createtime desc')->value('value');
$res['date'][] = date("Y-m-d", time());
$res['value'][] = $todaylist;
$this->success('', $res);
}
//县市预警状态
public function getCountyWarningList($id)
{
$reservoirids = Db::name('reservoir_list')->where('county_id', $id)->field('id,name')->select();
foreach ($reservoirids as $k => $v) {
$res[$k]['crack'] = Db::name('reservoir_warning_crack')->where('reservoir_id', $v['id'])->where('deal', 1)->count();
$res[$k]['displacement'] = Db::name('reservoir_warning_displacement')->where('reservoir_id', $v['id'])->where('deal', 1)->count();
$res[$k]['rainfall'] = Db::name('reservoir_warning_rainfall')->where('reservoir_id', $v['id'])->where('deal', 1)->count();
$res[$k]['settlement'] = Db::name('reservoir_warning_settlement')->where('reservoir_id', $v['id'])->where('deal', 1)->count();
$res[$k]['waterlevel'] = Db::name('reservoir_warning_waterlevel')->where('reservoir_id', $v['id'])->where('deal', 1)->count();
$res[$k]['waterseepage'] = Db::name('reservoir_warning_waterseepage')->where('reservoir_id', $v['id'])->where('deal', 1)->count();
$res[$k]['weather'] = Db::name('reservoir_warning_weather')->where('reservoir_id', $v['id'])->where('deal', 1)->count();
$res[$k]['name'] = $v['name'];
$res[$k]['time'] = date('Y-m-d', time());
if (($res[$k]['crack'] + $res[$k]['displacement'] + $res[$k]['rainfall'] + $res[$k]['settlement'] + $res[$k]['waterlevel'] + $res[$k]['waterseepage'] + $res[$k]['weather']) == 0) {
$res[$k]['status'] = '正常';
} else {
$res[$k]['status'] = '异常';
}
}
$this->success('', $res);
}
//实时水位数据
public function getWarningListtime()
{
$data = Db::name('reservoir_warning_waterlevel')->order('createtime desc')->limit(10)->select();
$this->success('成功', $data);
}
/**
* 7、【右中1】入侵动态
*/
public function alarm_monitoring_count()
{
$count = [];
//当日未处理
$time = 1;
$lasttime = strtotime(date('Y-m-d 23:59:59')) - $time * 60 * 60 * 24;
$cond['createtime'] = ['between', [$lasttime, strtotime(date('Y-m-d 23:59:59'))]];
$crack = Db::name('reservoir_warning_crack')->where($cond)->count();
$displacement = Db::name('reservoir_warning_displacement')->where($cond)->count();
$rainfall = Db::name('reservoir_warning_rainfall')->where($cond)->count();
$settlement = Db::name('reservoir_warning_settlement')->where($cond)->count();
$waterlevel = Db::name('reservoir_warning_waterlevel')->where($cond)->count();
$waterseepage = Db::name('reservoir_warning_waterseepage')->where($cond)->count();
$weather = Db::name('reservoir_warning_weather')->where($cond)->count();
$hkday = Db::name('reservoir_hkws_alarm_monitoring')
->where(['status' => '0'])
->whereTime('createtime', 'today')
->count();
$count['day'] = $crack + $displacement + $rainfall + $settlement + $waterlevel + $waterseepage + $weather + $hkday;
//总预警
$crack = Db::name('reservoir_warning_crack')->count();
$displacement = Db::name('reservoir_warning_displacement')->count();
$rainfall = Db::name('reservoir_warning_rainfall')->count();
$settlement = Db::name('reservoir_warning_settlement')->count();
$waterlevel = Db::name('reservoir_warning_waterlevel')->count();
$waterseepage = Db::name('reservoir_warning_waterseepage')->count();
$weather = Db::name('reservoir_warning_weather')->count();
$hkall = Db::name('reservoir_hkws_alarm_monitoring')->count();
$count['all'] = $crack + $displacement + $rainfall + $settlement + $waterlevel + $waterseepage + $weather + $hkall;
$return_data['warning'] = $count;
$crackres = Db::name('reservoir_warning_crack')->order("id desc")->find();
$displacementres = Db::name('reservoir_warning_displacement')->order("id desc")->find();
$rainfallres = Db::name('reservoir_warning_rainfall')->order("id desc")->find();
$settlementres = Db::name('reservoir_warning_settlement')->order("id desc")->find();
$waterlevelres = Db::name('reservoir_warning_waterlevel')->order("id desc")->find();
$waterseepageres = Db::name('reservoir_warning_waterseepage')->order("id desc")->find();
$weatherres = Db::name('reservoir_warning_weather')->order("id desc")->find();
$hknew = Db::name('reservoir_hkws_alarm_monitoring')
->field('id,reservoir_list_id as reservoir_id,alarm_type,createtime,status,deal_time')
->order("id desc")
->find();
$warninginfo['info'] = $crackres;
$warninginfo['type'] = "warning_crack";
//warning_displacement 坝体位移
if ($warninginfo['info']['createtime'] < $displacementres['createtime']) {
$warninginfo['info'] = $displacementres;
$warninginfo['type'] = "warning_displacement";
}
//warning_rainfall 降雨量
if ($warninginfo['info']['createtime'] < $rainfallres['createtime']) {
$warninginfo['info'] = $rainfallres;
$warninginfo['type'] = "warning_rainfall";
}
//warning_settlement 坝体沉降
if ($warninginfo['info']['createtime'] < $settlementres['createtime']) {
$warninginfo['info'] = $settlementres;
$warninginfo['type'] = "warning_settlement";
}
//warning_waterlevel 水位预警
if ($warninginfo['info']['createtime'] < $waterlevelres['createtime']) {
$warninginfo['info'] = $waterlevelres;
$warninginfo['type'] = "warning_waterlevel";
}
//warning_waterseepage 坝体渗水
if ($warninginfo['info']['createtime'] < $waterseepageres['createtime']) {
$warninginfo['info'] = $waterseepageres;
$warninginfo['type'] = "warning_waterseepage";
}
//warning_weather 极端天气
if ($warninginfo['info']['createtime'] < $weatherres['createtime']) {
$warninginfo['info'] = $weatherres;
$warninginfo['type'] = "warning_weather";
}
//$hknew hkws_alarm
if ($warninginfo['info']['createtime'] < $hknew['createtime']) {
$warninginfo['info'] = $hknew;
$warninginfo['type'] = "hkws_alarm";
}
$warninginfo['info']['createtime'] = date("Y-m-d H:i:s", $warninginfo['info']['createtime']);
$reservoir = Db::name("reservoir_list")->where($warninginfo['info']['reservoir_id'])->find();
$warninginfo['info']['reservoir_name'] = $reservoir['name'];
$return_data['warninginfo'] = $warninginfo;
$this->success("", $return_data);
}
}