root 1 year ago
parent
commit
92b4c05b27

+ 1 - 1
Modules/Admin/Http/Controllers/LoginController.php

@@ -39,7 +39,7 @@ class LoginController extends Controller
             return redirect('/admin');
             return redirect('/admin');
         }
         }
 
 
-        return view('admin::login');
+        // return view('admin::login');
     }
     }
 
 
     //登录动作
     //登录动作

+ 106 - 0
app/Http/Controllers/TestsController.php

@@ -24,6 +24,8 @@ use Modules\Mine\Entities\MineListExt;
 use Modules\Mine\Services\MineServices;
 use Modules\Mine\Services\MineServices;
 use Modules\Mine\Enum\MineEnum;
 use Modules\Mine\Enum\MineEnum;
 
 
+use GuzzleHttp\Client;
+
 class TestsController {
 class TestsController {
 
 
     public function test()
     public function test()
@@ -244,4 +246,108 @@ class TestsController {
         $repeat_arr = array_diff_assoc ( $aa, $unique_arr );
         $repeat_arr = array_diff_assoc ( $aa, $unique_arr );
         return $repeat_arr;
         return $repeat_arr;
     }
     }
+    
+    public function getDcsApiData() {
+        $apiUrl = "http://7.250.4.3:4300/v1/common/GetPointRealDataByPageV3";
+        
+        $client = new Client();
+        
+        $r = request()->all();
+        
+        if(isset($r['p'])) {
+            $p = $r['p'];
+            $k = $r['k'];
+        } else {
+            $p = $r;
+        }
+        
+        
+        $body =  [
+            'headers' => [
+                'Authorization' => 'Bearer appkey_100100',
+                'Content-Type'=>'application/json; charset=utf-8',
+                // 其他头部信息
+            ],
+            'json' =>[
+                'PageNum'=>"-1",
+                "PointIds"=>$p
+            ]
+        ];
+        // 发送 HTTP POST 请求
+        $response = $client->post($apiUrl, $body);
+        
+
+        // 获取 API 响应的 JSON 数据
+        $res = json_decode($response->getBody(), true);
+        
+        if($res['IsSuccessful'] == 0) {
+            return $res;
+        }
+
+        $data = isset($res['Data'])? $res['Data']: null;
+        
+        $transformedData['data']=[];
+        for ($i = 0; $i < count($data); $i++) {
+            $dic = $data[$i];
+            $trans['v'][] = $dic['V'];
+            $trans['list'][$i] = [
+                'id'=>$dic['ID'],
+                'nm'=>$dic['PointName'],
+                'v'=>$dic['V'],
+                ];
+            $trans['kv'][$dic['ID']] = $dic['V'];
+        }
+        
+        if (!empty($k) && isset($trans[$k])) {
+            return $trans[$k];
+        }
+        
+        return $trans;
+        
+    }
+    
+    
+
+    public function getDcsOpcData() {
+                
+        // $shell = "echo 'success' ";
+        // $shellExec = shell_exec($shell);
+        // // var_dump($shellExec);
+        // if($shellExec){echo 'ok';} else {echo 'error'}
+        
+        $pids = [
+            "ns=12380;s=九八零变电所80Z004照明回路_Ia",
+            "ns=12380;s=九八零变电所5105_IA",
+            "ns=12380;s=九八零变电所5101_UB",
+            # 添加其他节点地址...
+        ];
+        
+        $pyPath = "/home/python_proj/python_custom_script/zaoquan/dcs/";
+        $pyFName = "test1.py";
+        $pyKeyWord = "/usr/bin/python311";
+        
+        $pidsJson = json_encode($pids);
+
+        $command = "$pyKeyWord {$pyPath}{$pyFName}". ' ' . escapeshellarg("{$pidsJson}");
+        // $output = shell_exec($command);
+
+        // return shell_exec($command);
+        
+        try {
+            // 调用Python脚本
+            $output = shell_exec($command);
+            
+            // 解析Python脚本返回的JSON数据
+            $data = json_decode($output, true);
+            // $data['a'] = 'aaa';
+            // 返回JSON格式的数据给前端
+            header('Content-Type: application/json');
+            echo json_encode($data);
+        } catch (Exception $e) {
+            // 返回错误消息给前端
+            header('Content-Type: application/json');
+            echo json_encode(array("error" => $e->getMessage()));
+        }
+
+    }
 }
 }

+ 4 - 0
routes/web.php

@@ -20,3 +20,7 @@ Auth::routes();
 Route::get('/home', 'HomeController@index')->name('home');
 Route::get('/home', 'HomeController@index')->name('home');
 
 
 Route::any('test', ['as' => 'test', 'uses' => 'TestsController@test']);
 Route::any('test', ['as' => 'test', 'uses' => 'TestsController@test']);
+
+Route::any('dcsapi', ['as' => 'dcsapi', 'uses' => 'TestsController@getDcsApiData']);
+
+Route::any('dcsopc', ['as' => 'dcsopc', 'uses' => 'TestsController@getDcsOpcData']);