Displacement.php
2.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
<?php
/**
* Created by PhpStorm.
* User: yrf
* Date: 2022/4/3
* Time: 9:24
* ResvRaninDate
* 水库安全运行监测大屏接口
*
*/
namespace app\api\controller\safeoperation;
use app\common\controller\Api;
use fast\Tree;
use think\Db;
use think\Request;
/**
* 坝体地表位移
*/
class Displacement extends Api
{
protected $id;
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
protected $model = null;
public function _initialize()
{
$this->id = $this->request->param('id');
if (!$this->id) {
$this->error("id不能为空");
}
parent::_initialize();
}
/**
* 4. 当前位移监测
* reservoir_list 水库表
* reservoir_equipment 硬件表
* reservoir_dam_displacement 坝体地表位移表
*/
public function current_data()
{
$where = [];
$where = [
"r.id" => $this->id,//水库id
"e.type" => 6 //硬件类型:1=水位计,2=渗流计,3=渗压计,4=GNSS,5=雨量计,6=位移检测,7=其他
];
//水库硬件设备
$data = Db::name("reservoir_list")->alias("r")
->join("reservoir_equipment e", "e.reservoir_id = r.id", "LEFT")
->where($where)
->field("e.status,e.deviceId,e.name as equip_name")
->order("e.id desc")
->select();
if (!empty($data)) {
foreach ($data as $k => $v) {
//在线不在线
$data[$k]["status_text"] = $v['status'] == 1 ? "在线" : "离线";
unset($data[$k]['status']);
//最新一条渗压数据
$current_value =Db::name("reservoir_dam_displacement")->where(["number" => $v['deviceId'], "reservoir_id" => $this->id])->order("createtime desc")->field("vertical,horizontal,horizontalY")->find();
$data[$k]["vertical"] =$current_value['vertical'];
$data[$k]["horizontal"] =$current_value['horizontal'];
$data[$k]["horizontalY"] =$current_value['horizontalY'];
}
}
$this->success("数据获取成功", $data);
}
}