|
@@ -6,6 +6,7 @@ use App\Http\Controllers\Api\BaseController;
|
|
|
use Illuminate\Contracts\Support\Renderable;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Routing\Controller;
|
|
|
+use Illuminate\Support\Facades\Redis;
|
|
|
|
|
|
class OPCDataTurboController extends BaseController
|
|
|
{
|
|
@@ -17,7 +18,8 @@ class OPCDataTurboController extends BaseController
|
|
|
}
|
|
|
|
|
|
$db_conf = config('database');
|
|
|
- $api_url = 'http://'.$db_conf['python_api'][$sys_key]['url'].'/get/?sys_key='.$sys_key.'&sys_name='.$sys_name;
|
|
|
+ $api_key = 'get';
|
|
|
+ $api_url = 'http://'.$db_conf['python_api'][$sys_key]['url'].'/'.$api_key.'/?sys_key='.$sys_key.'&sys_name='.$sys_name;
|
|
|
|
|
|
$response = $this->request_post($api_url);
|
|
|
|
|
@@ -34,20 +36,21 @@ class OPCDataTurboController extends BaseController
|
|
|
$error_info = '未知错误:'.$response;
|
|
|
}
|
|
|
return $this->error($response, $error_info);
|
|
|
- } else {
|
|
|
- $data = json_decode($response);
|
|
|
-// $data = $this->data_process($data);
|
|
|
-// dd($data);
|
|
|
-// return $data;
|
|
|
+ } else if($data = json_decode($response, true)){
|
|
|
+
|
|
|
if ($data == null) {
|
|
|
return $this->error(500, preg_replace('/<[^>]*>/','',$response));
|
|
|
} else {
|
|
|
- return $this->success($data);
|
|
|
+ $arr = $this->data_handling($data);
|
|
|
+ return $this->success($arr);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ return $this->error(500, '接口服务错误');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
+ // 取OPC数据接口
|
|
|
private function request_post($url = '', $param = '') {
|
|
|
if (empty($url)) {
|
|
|
return false;
|
|
@@ -63,7 +66,6 @@ class OPCDataTurboController extends BaseController
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
|
|
|
-// curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
|
|
|
$data = curl_exec($curl);//运行curl
|
|
|
$errno = curl_errno($curl);
|
|
|
curl_close($curl);
|
|
@@ -72,50 +74,27 @@ class OPCDataTurboController extends BaseController
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
- private function data_process($data) {
|
|
|
- $data = is_object($data) ? get_object_vars($data) : $data;
|
|
|
- $data_arr = [];
|
|
|
- foreach ($data as $key => $val) {
|
|
|
- $arr = is_object($val) ? get_object_vars($val) : $val;
|
|
|
- if (is_array($arr)) {
|
|
|
- $arr = $this->data_process(($arr));
|
|
|
-// dd($arr);
|
|
|
- }
|
|
|
-// $arr[$key] = round($val, 2);
|
|
|
- $data_arr[$key] = $arr;
|
|
|
- if (isset($data_arr['val']) && $data_arr['val'] != '') {
|
|
|
- $data_arr[$key] = round($data_arr['val'], 2);
|
|
|
+ private function data_handling($data) {
|
|
|
+// $redis = new Redis();
|
|
|
+// $redis->connect();
|
|
|
+
|
|
|
+ $redis = Redis::connection('default'); //指定连接user配置节点信息
|
|
|
+
|
|
|
+ foreach ($data['sys_point'] as $key => $val) {
|
|
|
+ foreach ($val as $k => $v) {
|
|
|
+ $data_value = $v['val'];
|
|
|
+ $data_key = $v['key'];
|
|
|
+ if ($data_value) {
|
|
|
+ $userData = $redis->get($data_key);
|
|
|
+ $data['sys_point'][$key][$k]['val'] = round($userData, 2);
|
|
|
+ # 数据持久化
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- return $data_arr;
|
|
|
-
|
|
|
-// dd($arr);
|
|
|
-// $data = (array)$data;
|
|
|
-// $process_arr = [];
|
|
|
-// foreach ($data as $key=>$val ) {
|
|
|
-// if ($val)
|
|
|
-// if ($val == 'val') {
|
|
|
-// $data[$key] = round($val);
|
|
|
-// return;
|
|
|
-// }
|
|
|
-//// foreach ($val as $k=>$v) {
|
|
|
-//// $this->data_process($v);
|
|
|
-//// $vv = (array)$v;
|
|
|
-//// dd($vv['val']);
|
|
|
-//// }
|
|
|
-//// $dd = (array)$val;
|
|
|
-//// $process_arr[$key] = $this->data_process($val);
|
|
|
-//// print(gettype($this->data_process($val)));
|
|
|
-//
|
|
|
-//// if ($child_data['val']) {
|
|
|
-//// $child_data['val'] = round($child_data, 2);
|
|
|
-//// }
|
|
|
-//// dd($data[$key]);
|
|
|
-//// dd(round($data[$key]['val'], 2));
|
|
|
-// }
|
|
|
-// return $process_arr;
|
|
|
+ return $data;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* Display a listing of the resource.
|
|
|
* @return Renderable
|