1
13693261870
2024-09-29 75d5cf215a19c8f475d981bb3de2f6c485f17130
1
已修改4个文件
82 ■■■■■ 文件已修改
src/main/java/com/se/simu/config/PropertiesConfig.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/service/SimuService.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/se/simu/service/UwService.java 66 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application.yml 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
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;
    }
}
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();
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() {
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
  # 流量单位,LPS(升/秒)、CMS(立方米/秒)、CFS(立方英尺/秒)
  flowUnits: CMS
  solverBat: D:\simu\uwsolver\run_solver.bat