Hardware.php
3.3 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
<?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;
$hkid = [192, 193, 186];
$config = get_addon_config('qiniu');
$list = Db::name('reservoir_hkws_hardware')
->field('id,name,type_child_name,indexCode,scode,image,type_child_name')
->where('reservoir_id', $id)
->where(['id' => ['not in', $hkid]])
->order("id desc")
->whereNotNull("image")
->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;
//判断摄像头是否在线 code=200在线 其余不在线
//获得监控视频地址
$api = new \app\api\controller\Ysyun();
$token = $api->getaccessToken();
//请求数据
$post_data = [
'accessToken' => $token,
'deviceSerial' => $v['indexCode'],
'expireTime' => 600,//过期时间
];
$res = $api->getHkAddress($post_data);
if($res["code"]=="200"){
$v['status']=1;
}else{
$v['status']=2;
}
}
usort($list, function ($a, $b) {
return $b['monitor_num'] - $a['monitor_num'];
});
$this->success('获取成功', $list);
}
}