Displacement.php 2.8 KB
<?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" => 4 //硬件类型: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);
    }


    /**
     * 查询最新一条流量信息
     * @return void
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function find_river_flow()
    {
    $isotonic = Db::name("reservoir_rain_river_flow")
        ->alias("a")
        ->join("reservoir_equipment b", 'a.number=b.deviceId')
        ->order('a.id desc')
        ->field("a.*,b.orifice_elevation")
        ->find();
        if ($isotonic) {
        $isotonic['createtime'] = date("m-d H:i", $isotonic['createtime']);
        }
    $this->success("获取最新流量数据成功", $isotonic);
    }
}