Hardware.php 7.6 KB
<?php
/***
 * 千寻数据采集
 */

namespace app\api\controller\reservoir;

use app\common\controller\Api;
use think\Request;
use think\Db;
use qx\Qx;
use addons\alisms\controller\Index;

/**
 * Class Equipment
 * @package app\api\controller\reservoir
 */
class Hardware extends Api
{
    protected $model = '';
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = '*';
    protected $url = "https://api.njgn.com/api/";

    public function test(){
        $db2 = Db::connect(config('database.db2'));
        $result=$db2->name('pptn_r')->select();
        $res=Db::name("user")->select();
        print_r($res);

    }
    public function getgnss(){
        $data= $this->request->param("data");
        $new_res=str_replace("&quot;",'"',$data);
        $new_res=json_decode($new_res,true);
        $insertdata=[
            'base_imei'=>$new_res['base_imei'],
            'rover_imei'=>$new_res['rover_imei'],
            'calc_time'=>$new_res['calc_time'],
            'calc_type'=>$new_res['calc_type'],
            'sat_num'=>$new_res['sat_num'],
            'e'=>$new_res['e'],
            'n'=>$new_res['n'],
            'u'=>$new_res['u'],
            'x'=>$new_res['x'],
            'y'=>$new_res['y'],
            'z'=>$new_res['z'],
            'vx'=>$new_res['vx'],
            'vy'=>$new_res['vy'],
            'vz'=>$new_res['vz'],
            'accx'=>$new_res['accx'],
            'accy'=>$new_res['accy'],
            'accz'=>$new_res['accz'],
            'isOriginEnu'=>$new_res['isOriginEnu'],
            'datum_e'=>$new_res['datum_e'],
            'datum_n'=>$new_res['datum_n'],
            'datum_u'=>$new_res['datum_u'],
            'datum_x'=>$new_res['datum_x'],
            'datum_y'=>$new_res['datum_y'],
            'datum_z'=>$new_res['datum_z'],
            'fft'=>$new_res['fft'],
            'sat_info'=>$new_res['sat_info']
        ];
        Db::name('reservoir_displacement')->insert($insertdata);
        //wrp_reservoir_dam_displacement
        $damdata=[
            'number'=>$new_res['rover_imei'],
            'horizontal'=>bcsub(bcmul($new_res['datum_e'],1000,2),bcmul($new_res['e'],1000,2),2),
            'horizontalY'=>bcsub(bcmul($new_res['datum_n'],1000,2),bcmul($new_res['n'],1000,2),2),
            'vertical'=>bcsub(bcmul($new_res['datum_u'],1000,2),bcmul($new_res['u'],1000,2),2),
            'reservoir_id'=>40,
            'status'=>0,
            'warning'=>0,
            'actual'=>0,
            'predictive'=>0,
            'risk'=>'',
            'createtime'=>time(),
            'reporttime'=>$new_res['calc_time'],
            'issend'=>0,
            'updatetime'=>time(),
        ];
        Db::name("reservoir_dam_displacement")->insert($damdata);

//        file_put_contents("33333333.txt",date("Y-m-d H:i:s").":".($data)."\r\n",FILE_APPEND);
        return "ok";
    }

    public function getrainfall(){
        $data= $this->request->param("data");
        $data=strip_tags(htmlspecialchars_decode($data));
        $data=json_decode($data,true);
        if(empty($data)){
            return "ok";
        }
        $res=[];
        foreach ($data as $k=>$v){
            $res[$k]=[
                "number"=>$data[$k]["STCD"],
                "rainfall"=>$data[$k]["DRP"],
                "total_rainfall"=>0,
                "reservoir_id"=>40,
                "createtime"=>strtotime($data[$k]["TM"]),
                "reporttime"=>strtotime($data[$k]["TM"]),
            ];
        }
        if($res){
            Db::name("reservoir_rain_rainfall")->insertAll($res);
        }
        //file_put_contents("333333334444.txt",date("Y-m-d H:i:s").":".(json_encode($res))."\r\n",FILE_APPEND);
        return "ok";
    }

    /**
     * 获取渗压信息
     * @return void
     */
    public function select_sensor_point_by_project(){
        $url="get_data/select_last_data_by_project?projectId=1254";
        $res=$this->postgenanurl($url);
        $res=json_decode($res,true);
        foreach ($res['result'] as $k=>$v) {
            if($res['result'][$k]['sensorId']!='274165'){
                //通过水面高程计算渗压
                //获取设备信息
                $equipment=Db::name("reservoir_equipment")->where("deviceId",$res['result'][$k]['sensorId'])->find();
                $ress=gn_dam_isotonic_attr_data($equipment['orifice_elevation'],$equipment['hole_depth'],$res['result'][$k]['temporary']);
                $data=[
                    'equipment_id'=>$res['result'][$k]['sensorId'],
                    'water_elevation'=>$res['result'][$k]['temporary'],
                    'reporttime'=>time(),
                    'value'=>$ress*9.8,
                    'dx_value'=>$ress,
                    'reservoir_id'=>40,
                    'createtime'=>time()
                ];

                Db::name('reservoir_dam_isotonic')->insert($data);
            }
        }
        print_r("请求成功");
    }


    /**
     * 获取渗流信息
     * @return void
     */
    public function select_transfusion(){
        $url="get_data/select_last_data_by_project?projectId=1254";
        $res=$this->postgenanurl($url);
        $res=json_decode($res,true);
        foreach ($res['result'] as $k=>$v) {
            if($res['result'][$k]['sensorId']=='274165'){
                $data=[
                    'equipment_id'=>$res['result'][$k]['sensorId'],
                    'value'=>bcmul($res['result'][$k]['temporary'],1000,4),
                    'reservoir_id'=>40,
                    'reporttime'=>time(),
                    'createtime'=>time()
                ];
                Db::name('reservoir_dam_seepage')->insert($data);
            }
        }
        print_r("请求成功");
    }
    /**
     * 数据请求接口
     * @return void
     */
    public function posturl($url){
        $token = $this->getToken();
        $headerArray =array("Content-Type: application/json","cookie:generator=$token");
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $this->url.$url);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
        curl_setopt($curl, CURLINFO_HEADER_OUT, true);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }

    /**
     * 获取token
     * @return mixed
     */
    public function getgenanToken(){
        $appId = '896126276027285504';
        $appSecret = 'e2eff0c7c0674daad4dde6bdab44be18';
        $data=["appId"=>$appId,"appSecret"=>$appSecret];
        $res=send_post("https://api.njgn.com/common_api/api_access_token/get_access_token",$data);
        $res=json_decode($res,true);
        return $res['result'];
    }


    /**
     * 数据请求接口
     * @return void
     */
    public function postgenanurl($url){
        $token = $this->getgenanToken();
        $headerArray =array("Content-Type: application/json","cookie:generator=$token");
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $this->url.$url);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
        curl_setopt($curl, CURLINFO_HEADER_OUT, true);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }
}