Waterhead.php 10.9 KB
<?php

namespace app\api\controller\v7\waterdetection;

use app\common\controller\Api;
use think\Db;

/**
 * p5 雨水情相关接口
 * Class Network
 * @package app\api\controller\v7\pipes
 */
class Waterhead extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * 水源管理
     * @return void
     */
    public function water_manage(){
        $data['current_value']=[//当前供水
            '123.21',
            '222.23',
            '323.51',
            '322.51',
            '132.11',
            '112.25',
            '121.17',
            '253.12'
        ];
        $data['max_current_value'] = max($data['current_value']);
        $data['min_current_value'] = min($data['current_value']);
        $data['max_value']=[//max供水
            '123.21',
            '222.23',
            '323.51',
            '322.51',
            '132.11',
            '112.25',
            '121.17',
            '253.12'
        ];
        $data['max_max_value'] = max($data['max_value']);
        $data['min_min_value'] = min($data['max_value']);
        $data['expect_value']=[//预计供水
            '123.21',
            '222.23',
            '323.51',
            '322.51',
            '132.11',
            '112.25',
            '121.17',
            '253.12'
        ];
        $data['max_expect_value'] = max($data['expect_value']);
        $data['min_expect_value'] = min($data['expect_value']);
        $this->success("请求成功",$data);
    }

    /**
     * 流量
     * @return void
     */
    public function water_flow(){
        $reservoir_id = $this->request->param("reservoir_id");
        $newtime=strtotime(date("Y-m-d H:00:00"));//当前时间戳 年-月-日-时
        //获取到八小时前时间戳
        $starttime=$newtime;
        $endtime=bcsub($starttime,3600);
        $whileindex=0;
        $data=[];

        while ($whileindex<8){
            $res[$whileindex]=Db::name("reservoir_flow")
                ->where("reservoir_id",$reservoir_id)
                ->where("createtime","<",$starttime)
                ->where("createtime",">",$endtime)
                ->find();
            $data['time'][$whileindex]=date("H:i",$starttime);
            $data['in_value'][$whileindex]=$res[$whileindex]["value"];
            $data['out_value'][$whileindex]=$res[$whileindex]["value"];
            $whileindex++;
            $starttime=bcsub($starttime,3600);
            $endtime=bcsub($endtime,3600);
        }
        $data['in_value']=[
            '123.21',
            '222.23',
            '323.51',
            '322.51',
            '132.11',
            '112.25',
            '121.17',
            '253.12'
        ];
        $data['out_value']=[
            '423.64',
            '123.12',
            '112.16',
            '332.14',
            '151.16',
            '164.17',
            '156.18',
            '112.53'
        ];
        $data['max_in_value'] = max($data['in_value']);
        $data['min_in_value'] = min($data['in_value']);
        $data['max_out_value'] = max($data['out_value']);
        $data['min_out_value'] = min($data['out_value']);
        $this->success("请求成功",$data);
    }


    /**
     * 当日降雨量 目前是测试数据 水位不够库容最低值 所以水位加了580 正式数据记得删除
     * @return void
     */
    public function day_rainfall(){
        $reservoir_id = $this->request->param("reservoir_id");
        $newtime=strtotime(date("Y-m-d H:00:00"));//当前时间戳 年-月-日-时
        //获取到八小时前时间戳
        $starttime=$newtime;
        $endtime=bcsub($starttime,3600);
        $whileindex=0;
        $data=[];

        while ($whileindex<8){
            $res[$whileindex]=Db::name("reservoir_rain_water_level")
                ->where("reservoir_id",$reservoir_id)
                ->where("createtime","<",$starttime)
                ->where("createtime",">",$endtime)
                ->find();
            $data['time'][$whileindex]=date("H:i",$starttime);
            if(!$res[$whileindex]["water_level"]){
                $res[$whileindex]["water_level"]=rand(1264.32,1272.32);
            }
            $res[$whileindex]["water_level"]=$res[$whileindex]["water_level"]+580;
            $data['water_level'][$whileindex]=$res[$whileindex]["water_level"];
            $data['capacityof'][$whileindex]=getWarterdataCapacityof($reservoir_id, $res[$whileindex]["water_level"]);
            $whileindex++;
            $starttime=bcsub($starttime,3600);
            $endtime=bcsub($endtime,3600);
        }
        $data['max_value'] = max($data['water_level']);
        $data['min_value'] = min($data['water_level']);
        $data['max_capacityof'] = max($data['capacityof']);
        $data['min_capacityof'] = min($data['capacityof']);
        $this->success("请求成功",$data);
    }

    /**
     * 服务中心工单
     * @return void
     */
    public function service_center(){
        $waterhead_id = $this->request->param("waterhead_id");
        $data=[
            "temperature"=>rand(10,35),
            "co2"=>rand(10,20)."%",
            "ph"=>rand(4,8),
        ];
        $this->success("请求成功",$data);
    }

    /**
     * 获取水质类型
     * @return void
     */
    public function getwaterquality_list(){
        $data=[
            [
                "id"=>"ammoniaNitrogen",
                "name"=>"氨氮(mg/L)"
            ],
            ["waterhead"=>"blueGreenAlgae","name"=>"蓝绿藻"],
            ["waterhead"=>"chlorophyllA","name"=>"叶绿素 a "],
            ["waterhead"=>"conductivity","name"=>"电导率"],
            ["waterhead"=>"dissolvedOxygen","name"=>"溶解氧"],
            ["waterhead"=>"nitrogen","name"=>"总氮"],
            ["waterhead"=>"permanganate","name"=>"高锰酸盐"],
            ["waterhead"=>"phValue","name"=>"ph值"],
            ["waterhead"=>"phosphorus","name"=>"总磷"],
            ["waterhead"=>"turbidity","name"=>"浊度"],
            ["waterhead"=>"waterTemperature","name"=>"水温"]
        ];
        $this->success("请求成功",$data);
    }

    /**
     * 水质列表
     * @return void
     */
    public function waterquality_list(){
        $waterhead = $this->request->param("waterhead");
        $reservoir_id = $this->request->param("reservoir_id");
        $newtime=strtotime(date("Y-m-d H:00:00"));//当前时间戳 年-月-日-时
        //获取到八小时前时间戳
        $starttime=$newtime;
        $endtime=bcsub($starttime,86400);
        $whileindex=0;
        $data=[];
        while ($whileindex<8){
            $data['time'][$whileindex]=date("m-d",$starttime);
            $whileindex++;
            $starttime=bcsub($starttime,86400);
            $endtime=bcsub($endtime,86400);
        }
        $type = $this->request->param("type");
        $data['value']=[
            rand(10,100),
            rand(10,100),
            rand(10,100),
            rand(10,100),
            rand(10,100),
            rand(10,100),
            rand(10,100),
            rand(10,100),
        ];
        $data['max_value'] = max($data['value']);
        $data['min_value'] = min($data['value']);
        $this->success("请求成功",$data);
    }

    /**
     * 获取断面
     * @return void
     */
    public function getsection(){
        $data=[
            "0"=>["id"=>"1","name"=>"S1-1断面"],
            "1"=>["id"=>"2","name"=>"S1-2断面"],
            "2"=>["id"=>"3","name"=>"S1-3断面"],
            "3"=>["id"=>"4","name"=>"S2-4断面"],
            "4"=>["id"=>"5","name"=>"S2-2断面"]
        ];
        $this->success("请求成功",$data);
    }

    /**
     * 获取渗压计
     * @return void
     */
    public function getosmotic(){
        $data=[
            "0"=>["id"=>"1","name"=>"渗压计1号"],
            "1"=>["id"=>"1","name"=>"渗压计2号"],
            "2"=>["id"=>"1","name"=>"渗压计3号"],
            "3"=>["id"=>"1","name"=>"渗压计4号"],
            "4"=>["id"=>"1","name"=>"渗压计5号"],
            "5"=>["id"=>"1","name"=>"渗压计6号"]
        ];
        $this->success("请求成功",$data);
    }

    /**
     * 获取渗压检测
     * @return void
     */
    public function getosmoticlist(){
        $reservoir_id = $this->request->param("reservoir_id");
        $section_name = $this->request->param("section_name");
        $newtime=strtotime(date("Y-m-d H:00:00"));//当前时间戳 年-月-日-时
        //获取到八小时前时间戳
        $starttime=$newtime;
        $endtime=bcsub($starttime,86400);
        $whileindex=0;
        $data=[];
        while ($whileindex<6){
            $time[$whileindex]=date("m-d",$starttime);
            $whileindex++;
            $starttime=bcsub($starttime,86400);
            $endtime=bcsub($endtime,86400);
        }
        $data=[
           [
                "0"=>mt_rand(12,24),
                "1"=>mt_rand(12,24),
                "2"=>mt_rand(12,24),
                "3"=>mt_rand(12,24),
                "4"=>mt_rand(12,24),
                "5"=>mt_rand(12,24),

            ],
            [
                "0"=>mt_rand(15,40),
                "1"=>mt_rand(15,40),
                "2"=>mt_rand(15,40),
                "3"=>mt_rand(15,40),
                "4"=>mt_rand(15,40),
                "5"=>mt_rand(15,40),
            ],
            [
                "0"=>mt_rand(13,20),
                "1"=>mt_rand(13,20),
                "2"=>mt_rand(13,20),
                "3"=>mt_rand(13,20),
                "4"=>mt_rand(13,20),
                "5"=>mt_rand(13,20),
            ],
            [
                "0"=>mt_rand(15,25),
                "1"=>mt_rand(15,25),
                "2"=>mt_rand(15,25),
                "3"=>mt_rand(15,25),
                "4"=>mt_rand(15,25),
                "5"=>mt_rand(15,25),
            ],
            [
                "0"=>mt_rand(17,25),
                "1"=>mt_rand(17,25),
                "2"=>mt_rand(17,25),
                "3"=>mt_rand(17,25),
                "4"=>mt_rand(17,25),
                "5"=>mt_rand(17,25),
            ],
            [
                "0"=>mt_rand(27,35),
                "1"=>mt_rand(27,35),
                "2"=>mt_rand(27,35),
                "3"=>mt_rand(27,35),
                "4"=>mt_rand(27,35),
                "5"=>mt_rand(27,35),
            ]

        ];
        $osmoticname=[
            "渗压计1号",
            "渗压计2号",
            "渗压计3号",
            "渗压计4号",
            "渗压计5号",
            "渗压计6号",
        ];
        $data=[
            "value"=>$data,
            "time"=>$time,
            "osmoticname"=>$osmoticname
        ];

        $data['max_value'] = max( $data['value']);
        $data['min_value'] = min($data['value']);

        $data['max_value'] = max( $data['max_value']);
        $data['min_value'] = min($data['min_value']);
        $this->success("请求成功",$data);
    }

    public function getwaterhead(){
        $res=Db::name("pipes_waterhead")->select();
        $this->success("请求成功",$res);

    }
}