Hardware.php
7.6 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?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(""",'"',$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;
}
}