Hardware.php
4.4 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
<?php
namespace app\api\controller\reservoir\hkws;
use app\common\controller\Api;
use isc\Api as Iscapi;
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)
{
$config = get_addon_config('qiniu');
$list = Db::name('reservoir_hkws_hardware')
->field('id,name,scode as indexCode,image,video_type')
->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;
if($v['video_type']==1){
$cameraUrl=$this->getCameraUrlisc($v['indexCode']);
}else{
$cameraUrl=$this->getCameraUrl($v['indexCode']);
}
$v['cameraUrl']=$cameraUrl['camera'];
}
usort($list, function ($a, $b) {
return $b['monitor_num'] - $a['monitor_num'];
});
$this->success('获取成功', $list);
}
public function getCameraUrl($cameraIndexCode){
$protocol =1;
$streamType = 1;
//获得监控视频地址
$api = new \app\api\controller\Ysyun();
$token = $api->getaccessToken();
//请求数据
$post_data = [
'accessToken' => $token,
'deviceSerial' => $cameraIndexCode,
'expireTime' => 600,//过期时间
'protocol' => $protocol,//流播放协议,1-ezopen、2-hls、3-rtmp、4-flv,默认为1
'quality' => $streamType,//视频清晰度,1-高清(主码流)、2-流畅(子码流)
];
$res = $api->getHkAddress($post_data);
//获得监控信息,经纬度查询天气预报
$info = Db::name('reservoir_hkws_hardware')
->where(['scode' => $cameraIndexCode])
->field('id,latitude,longitude,indexCode')
->find();
$res['data']['latitude'] = $info['latitude'];
$res['data']['longitude'] = $info['longitude'];
$data['camera'] = $res;
return $data;
}
public function getCameraUrlisc($cameraIndexCode){
$this->api = new Iscapi();
$protocol =1;
$streamType = 1;
$res = $this->api->getPreviewUrl($cameraIndexCode, $protocol, $streamType);
$data['talk'] = $res;
//获得监控信息,经纬度查询天气预报
$info = Db::name('reservoir_hkws_hardware')
->where(['scode' => $cameraIndexCode])
->field('id,latitude,longitude,indexCode')
->find();
$res['data']['latitude'] = $info['latitude'];
$res['data']['longitude'] = $info['longitude'];
$data['camera'] = $res;
return $data;
}
}