| | |
| | | package com.se.nsl.service; |
| | | |
| | | import cn.hutool.core.io.FileUtil; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.se.nsl.config.PropertiesConfig; |
| | | import com.se.nsl.domain.po.DataPo; |
| | | import com.se.nsl.domain.po.Simu; |
| | | import com.se.nsl.domain.po.SimuData; |
| | | import com.se.nsl.domain.vo.ConfigVo; |
| | | import com.se.nsl.helper.ComHelper; |
| | | import com.se.nsl.helper.StringHelper; |
| | | import com.se.nsl.helper.WebHelper; |
| | | import lombok.SneakyThrows; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.gdal.ogr.Geometry; |
| | | import org.gdal.ogr.ogr; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.BufferedReader; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStreamReader; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Paths; |
| | | import java.nio.file.StandardCopyOption; |
| | | import java.sql.Timestamp; |
| | | import java.util.Date; |
| | | import java.util.concurrent.ExecutorService; |
| | |
| | | |
| | | @Resource |
| | | PropertiesConfig config; |
| | | @Autowired |
| | | private UwService uwService; |
| | | |
| | | public int start(Simu simu) { |
| | | Date now = new Date(); |
| | |
| | | try { |
| | | DataPo data = JSONUtil.toBean(simu.getData(), DataPo.class); |
| | | |
| | | update(simu, 1, null); |
| | | update(simu, 1, "开始"); |
| | | |
| | | initArgs(data); |
| | | String rs = callUwSolver(data); |
| | | //gedbService.copeVectors(token, data, db); |
| | | |
| | | //update(simu, 3, null); |
| | |
| | | simuService.updateById(simu); |
| | | } |
| | | |
| | | private void initArgs(){ |
| | | /** |
| | | * 初始化参数 |
| | | */ |
| | | private void initArgs(DataPo data) throws IOException { |
| | | String inPath = config.getInPath() + File.separator + data.getInPath(); |
| | | createDir(inPath); |
| | | createDir(inPath + File.separator + "depth"); |
| | | createDir(inPath + File.separator + "velocity"); |
| | | createDir(config.getOutPath() + File.separator + data.getOutPath()); |
| | | |
| | | // 临时复制高程tif,以后需要自行切割 |
| | | File uwBat = new File(config.getUwSolverBat()); |
| | | String sourceTif = uwBat.getParent() + File.separator + "data" + File.separator + "Hillzone.tif"; |
| | | String targetTif = inPath + File.separator + config.getDemFile(); |
| | | Files.copy(Paths.get(sourceTif), Paths.get(targetTif), StandardCopyOption.REPLACE_EXISTING); |
| | | } |
| | | |
| | | private void createDir(String path) { |
| | | File f = new File(path); |
| | | if (f.exists() && f.isDirectory()) { |
| | | FileUtil.del(f); |
| | | } |
| | | f.mkdirs(); |
| | | } |
| | | |
| | | /** |
| | | * 调用UWSolver |
| | | */ |
| | | private String callUwSolver(DataPo data) throws Exception { |
| | | File uwBat = new File(config.getUwSolverBat()); |
| | | |
| | | ConfigVo vo = new ConfigVo(data.getDuration(), config.getSaveFrames()); |
| | | //String configFile = uwBat.getParent() + File.separator + data.getInPath() + ".json"; |
| | | String configFile = config.getInPath() + File.separator + data.getInPath() + File.separator + data.getInPath() + ".json"; |
| | | ComHelper.writeJson(configFile, JSON.toJSONString(vo)); |
| | | |
| | | String cmd = String.format("%s %s", config.getUwSolverBat(), configFile); |
| | | |
| | | return callBat(cmd); |
| | | } |
| | | |
| | | private String callZarr2tif(DataPo data) throws Exception { |
| | | String cmd = ""; |
| | | |
| | | return callBat(cmd); |
| | | } |
| | | |
| | | private String callBat(String cmd) { |
| | | try { |
| | | ProcessBuilder pb = new ProcessBuilder("cmd", "/c", cmd); |
| | | pb.redirectErrorStream(true); // 合并错误流到标准输出 |
| | | |
| | | Process process = pb.start(); |
| | | process.getOutputStream().close(); |
| | | |
| | | /*StringBuilder sb = new StringBuilder(); |
| | | try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), "GBK"))) { |
| | | String line; |
| | | while ((line = reader.readLine()) != null) { |
| | | System.out.println(line); |
| | | sb.append(line); |
| | | } |
| | | }*/ |
| | | |
| | | int exitCode = process.waitFor(); |
| | | |
| | | return "ok"; // sb.toString(); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | return null; |
| | | } |
| | | } |
| | | } |