Hardware.php
2.5 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
<?php
namespace app\api\controller\reservoir\hkws;
use app\common\controller\Api;
use think\Request;
use think\Db;
/**
* Class Displacement
* @package app\api\controller
*/
class Hardware extends Api
{
protected $noNeedLogin = '*';
protected $noNeedRight = '*';
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\reservoir\hkws\Hardware;
}
public function getByType()
{
$type = input('get.type');
$id = input('get.id');
$list = Db::name('reservoir_hkws_hardware')->alias('h')->join('reservoir_list l', 'h.reservoir_id = l.id')->field('l.id,h.indexCode,l.name')->where('h.' . $type . '_id', $id)->select();
foreach ($list as $k => &$v) {
$v['rsvr'] = $this->getRsvrById($v['id']);
}
$this->success('', $list);
}
//根据水库id获取水位信息
public function getRsvrById($id)
{
$info = Db::name('st_rsvr_r')->where('RESERVOIR_ID', $id)->order('TM desc')->limit(1)->find();
return $info;
}
//根据县市id获取cameraindexcode
public function getListByCounty($id)
{
$reservoirids = Db::name('reservoir_list')->where('county_id', $id)->field('id')->select();
$ids = [];
foreach ($reservoirids as $k => $v) {
$ids[] = $v['id'];
}
$list = Db::name('reservoir_hkws_hardware')->field('id,name,indexCode')->where('reservoir_id', 'in', $ids)->select();
$this->success('', $list);
}
//根据水库id获取cameraindexcode
public function getListByReservoir()
{
$id=40;
$config = get_addon_config('qiniu');
$list = Db::name('reservoir_hkws_hardware')->field('id,play_type,haikang_code,type_child_name,name,indexCode,scode,channel_no,image')->where('reservoir_id', $id)->select();
foreach ($list as &$v) {
$v['image'] = $config['cdnurl'] . $v['image'];
$v['reservoir_name'] = Db::name("reservoir_list")->where("id", $id)->value("name");
//计算当前设备未读入侵条数
$monitoringCount = Db::name('reservoir_hkws_alarm_monitoring')
->where(['cameraIndexCode' => $v['indexCode'], 'status' => '0'])
->count();
$v['monitor_num'] = $monitoringCount ? $monitoringCount : 0;
}
usort($list, function ($a, $b) {
return $b['monitor_num'] - $a['monitor_num'];
});
$this->success('获取成功', $list);
}
}