From 75d5cf215a19c8f475d981bb3de2f6c485f17130 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期日, 29 九月 2024 15:23:02 +0800 Subject: [PATCH] 1 --- src/main/java/com/se/simu/config/PropertiesConfig.java | 10 +++++ src/main/java/com/se/simu/service/SimuService.java | 2 src/main/java/com/se/simu/service/UwService.java | 66 ++++++++++++++++++++++++++++++--- src/main/resources/application.yml | 4 + 4 files changed, 74 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/se/simu/config/PropertiesConfig.java b/src/main/java/com/se/simu/config/PropertiesConfig.java index e951b60..060a43c 100644 --- a/src/main/java/com/se/simu/config/PropertiesConfig.java +++ b/src/main/java/com/se/simu/config/PropertiesConfig.java @@ -56,6 +56,8 @@ private String flowUnits; + private String solverBat; + public String getVer() { return ver; } @@ -215,4 +217,12 @@ public void setBarrierName(String barrierName) { this.barrierName = barrierName; } + + public String getSolverBat() { + return solverBat; + } + + public void setSolverBat(String solverBat) { + this.solverBat = solverBat; + } } diff --git a/src/main/java/com/se/simu/service/SimuService.java b/src/main/java/com/se/simu/service/SimuService.java index 9fc3d18..76451c1 100644 --- a/src/main/java/com/se/simu/service/SimuService.java +++ b/src/main/java/com/se/simu/service/SimuService.java @@ -201,7 +201,7 @@ uwService.createConfig(data); update(simu, 6, null); - uwService.callExe(); + uwService.callExe(data); update(simu, 7, null); uwService.copeWaterFiles(); diff --git a/src/main/java/com/se/simu/service/UwService.java b/src/main/java/com/se/simu/service/UwService.java index 442c80c..6cda612 100644 --- a/src/main/java/com/se/simu/service/UwService.java +++ b/src/main/java/com/se/simu/service/UwService.java @@ -4,14 +4,12 @@ import com.se.simu.config.PropertiesConfig; import com.se.simu.domain.dto.ConfigDto; import com.se.simu.domain.po.DataPo; +import com.se.simu.helper.WebHelper; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; +import java.io.*; /** * 鍐呮稘姹傝В鍣ㄦ湇鍔$被 @@ -44,8 +42,64 @@ fw.close(); } - public void callExe() { - // + public String callExe(DataPo data) throws Exception { + String cmd = String.format("%s %d %s", config.getSolverBat(), WebHelper.getCpuCores(), data.getInPath() + ".json"); + + return exec(cmd); + } + + private String exec(String cmd) throws Exception { + Process process = null; + BufferedReader nr = null; + BufferedReader er = null; + try { + // new String[] { "/bin/sh", "-c", cmd } + process = Runtime.getRuntime().exec(cmd); + nr = new BufferedReader(new InputStreamReader(process.getInputStream())); + er = new BufferedReader(new InputStreamReader(process.getErrorStream())); + + String errorLine; + while ((errorLine = er.readLine()) != null) { + log.warn(errorLine); + } + + String line; + StringBuilder sb = new StringBuilder(); + while ((line = nr.readLine()) != null) { + sb.append(line); + } + + // 绛夊緟绋嬪簭鎵ц缁撴潫骞惰緭鍑虹姸鎬� + int exitCode = process.waitFor(); + + return sb.toString(); + } catch (Exception ex) { + throw ex; + } finally { + closeReader(er); + closeReader(nr); + closeProcess(process); + } + } + + private static void closeReader(Reader reader) { + if (null != reader) { + try { + reader.close(); + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + } + } + } + + private static void closeProcess(Process process) { + if (null != process) { + try { + process.destroy(); + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + } + } } public void copeWaterFiles() { diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 05e11f1..892c69e 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -95,7 +95,8 @@ ver: 0.2 # Gdal椹卞姩鐩綍 gdalPath: E:/terrait/TianJin/Zip/release-1928-x64-dev/release-1928-x64/bin - inPath: D:\simu\in + #inPath: D:\simu\in + inPath: D:\simu\uwsolver outPath: D:\simu\out host: http://106.120.22.26:8013/ user: WUWEIWEI @@ -118,3 +119,4 @@ raingage: RainGage.dat # 娴侀噺鍗曚綅锛孡PS锛堝崌/绉掞級銆丆MS锛堢珛鏂圭背/绉�)銆丆FS(绔嬫柟鑻卞昂/绉�) flowUnits: CMS + solverBat: D:\simu\uwsolver\run_solver.bat -- Gitblit v1.9.3