From a0991a129eb34bc395ab3db32ef92980a5bdab4e Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期四, 07 十一月 2024 11:33:29 +0800 Subject: [PATCH] 1 --- src/main/java/com/se/simu/controller/TestController.java | 16 ++++++-- src/main/java/com/se/simu/service/UwService.java | 71 ++++++++++++++++++++++++++++++++++- 2 files changed, 81 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/se/simu/controller/TestController.java b/src/main/java/com/se/simu/controller/TestController.java index af067d8..ed92dff 100644 --- a/src/main/java/com/se/simu/controller/TestController.java +++ b/src/main/java/com/se/simu/controller/TestController.java @@ -9,6 +9,8 @@ import com.se.simu.service.SimuService; import com.se.simu.service.UwService; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.GetMapping; @@ -48,11 +50,14 @@ } @ApiOperation(value = "testCallExe *") + @ApiImplicitParams({ + @ApiImplicitParam(name = "path", value = "璺緞", dataType = "String", paramType = "query", example = "20241010095328") + }) @GetMapping("/testCallExe") - public R<Object> testCallExe() { + public R<Object> testCallExe(String path) { try { DataPo data = new DataPo(); - data.setInPath("20241010095328"); + data.setInPath(path); String str = uwService.callExe(data); @@ -63,12 +68,15 @@ } @ApiOperation(value = "testResuslt *") + @ApiImplicitParams({ + @ApiImplicitParam(name = "path", value = "璺緞", dataType = "String", paramType = "query", example = "20241010095328") + }) @GetMapping("/testResuslt") - public R<Object> testResuslt() { + public R<Object> testResuslt(String path) { try { DataPo data = new DataPo(); data.setEpsg(4548); - data.setInPath("20241010095328"); + data.setInPath(path); data.setStartTime(StringHelper.YMDHMS_FORMAT.parse("2024-09-30 00:00:00")); resultService.process(data); diff --git a/src/main/java/com/se/simu/service/UwService.java b/src/main/java/com/se/simu/service/UwService.java index 19d48d8..ae0b607 100644 --- a/src/main/java/com/se/simu/service/UwService.java +++ b/src/main/java/com/se/simu/service/UwService.java @@ -6,6 +6,7 @@ import com.se.simu.domain.po.DataPo; import com.se.simu.helper.StringHelper; import com.se.simu.helper.WebHelper; +import com.sun.xml.internal.messaging.saaj.util.TeeInputStream; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import com.se.simu.Rainfall; @@ -79,7 +80,8 @@ public String callExe(DataPo data) throws Exception { String cmd = String.format("%s %d %s", config.getSolverBat(), WebHelper.getCpuCores(), data.getInPath() + ".json"); - return exec(cmd); + //return exec(cmd); + return execCmdLine(cmd); } private String exec(String cmd) throws Exception { @@ -96,11 +98,12 @@ StringBuilder sb = new StringBuilder(); while ((line = nr.readLine()) != null) { sb.append(line); + log.info(line); } String errorLine; while ((errorLine = er.readLine()) != null) { - log.warn(errorLine); + log.error(errorLine); } // 绛夊緟绋嬪簭鎵ц缁撴潫骞惰緭鍑虹姸鎬� @@ -136,6 +139,70 @@ } } + /** + * 鎵ц鍛戒护琛�,骞剁瓑寰呭懡浠ゆ墽琛屽畬姣� + * + * @param cmd 鍛戒护,window璁板緱瑕佷娇鐢╟md /c寮�澶�,濡俢md /c ipconfig + * @throws IOException + * @throws InterruptedException + */ + private String execCmdLine(String cmd) throws IOException, InterruptedException { + Process process = Runtime.getRuntime().exec(cmd); + + new Thread(() -> { + InputStreamReader ir = null; + BufferedReader br = null; + try { + ir = new InputStreamReader(process.getErrorStream(), "GBK"); + br = new BufferedReader(ir); + + String line; + while ((line = br.readLine()) != null) { + log.error(line); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + if (null != br) br.close(); + if (null != ir) ir.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + }).start(); + + StringBuilder sb = new StringBuilder(); + //new Thread(() -> { + InputStreamReader ir = null; + BufferedReader br = null; + try { + ir = new InputStreamReader(process.getInputStream(), "GBK"); + br = new BufferedReader(ir); + + String line; + while ((line = br.readLine()) != null) { + log.info(line); + sb.append(line); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + if (null != br) br.close(); + if (null != ir) ir.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + //}).start(); + + process.waitFor(); + process.destroy(); + + return sb.toString(); + } + public void copeWaterFiles() { // } -- Gitblit v1.9.3