2 changed files with 85 additions and 0 deletions
@ -0,0 +1,13 @@ |
|||||
|
import request from '@/utils/request'; |
||||
|
import {getToken} from "@/utils/auth"; |
||||
|
|
||||
|
export function dbDLC(data) { |
||||
|
return request({ |
||||
|
url: '/pythonJs/dbDLC', |
||||
|
method: 'post', |
||||
|
data:data, |
||||
|
headers: { |
||||
|
'Authorization': 'Bearer '+ getToken() // 将 token 放在请求头中
|
||||
|
} |
||||
|
}) |
||||
|
} |
||||
@ -0,0 +1,72 @@ |
|||||
|
package com.main.woka.Web.Controller; |
||||
|
|
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
import java.io.BufferedReader; |
||||
|
import java.io.InputStreamReader; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
@RestController |
||||
|
@RequestMapping("/pythonJs") |
||||
|
public class PythonController extends BaseController{ |
||||
|
|
||||
|
@PostMapping("/dbDLC") |
||||
|
public String dbDLC(@RequestBody Map<String, String> requestBody){ |
||||
|
// float a = Float.parseFloat(requestBody.get("a"));//方位角
|
||||
|
// float longtitude = Float.parseFloat(requestBody.get("longtitude"));//经度角
|
||||
|
// float latitude = Float.parseFloat(requestBody.get("latitude"));//纬度角
|
||||
|
|
||||
|
String a = requestBody.get("a"); |
||||
|
String longtitude = requestBody.get("longtitude"); |
||||
|
String latitude = requestBody.get("latitude"); |
||||
|
String fre = requestBody.get("fre"); |
||||
|
String N_m = requestBody.get("N_m"); |
||||
|
String r_m = requestBody.get("r_m"); |
||||
|
String r_b = requestBody.get("r_b"); |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
try { |
||||
|
// 定义 Python 解释器和脚本路径
|
||||
|
String pythonScriptPath = "D:\\pythonWork\\DBDLC\\run.py"; |
||||
|
String pythonExecutable = "D:\\python3.8\\python.exe"; // 或者 "python",取决于系统环境
|
||||
|
|
||||
|
// 创建 ProcessBuilder
|
||||
|
ProcessBuilder processBuilder = new ProcessBuilder(pythonExecutable, pythonScriptPath,a,longtitude,latitude,fre,N_m,r_m,r_b); |
||||
|
processBuilder.redirectErrorStream(true); |
||||
|
|
||||
|
// 启动进程
|
||||
|
Process process = processBuilder.start(); |
||||
|
|
||||
|
// 读取 Python 脚本的输出
|
||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); |
||||
|
String line; |
||||
|
while ((line = reader.readLine()) != null) { |
||||
|
System.out.println(line); |
||||
|
} |
||||
|
|
||||
|
// 等待进程结束
|
||||
|
int exitCode = process.waitFor(); |
||||
|
System.out.println("Python script exited with code: " + exitCode); |
||||
|
return "响应成功"; |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
return "响应失败"; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue