wuww
2025-05-04 73ca802381bd76cc1a5bd608e4a1e5ef12de88a2
src/main/java/com/se/nsl/service/ResolveService.java
@@ -13,6 +13,7 @@
import com.se.nsl.helper.WebHelper;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.axis.utils.StringUtils;
import org.gdal.ogr.Geometry;
import org.gdal.ogr.ogr;
import org.springframework.beans.factory.annotation.Autowired;
@@ -27,6 +28,8 @@
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -40,8 +43,12 @@
    @Resource
    PropertiesConfig config;
    @Autowired
    private UwService uwService;
    @Resource
    UwService uwService;
    @Resource
    TestService testService;
    public int start(Simu simu) {
        Date now = new Date();
@@ -90,17 +97,17 @@
        try {
            DataPo data = JSONUtil.toBean(simu.getData(), DataPo.class);
            update(simu, 1, "开始");
            update(simu, 1, "初始化参数");
            initArgs(data);
            String rs = callUwSolver(data);
            //gedbService.copeVectors(token, data, db);
            //update(simu, 3, null);
            //gedbService.copeDem(token, data);
            update(simu, 2, "调用求解器");
            callUwSolver(data);
            //update(simu, 4, null);
            //uwService.createRainFile(data);
            update(simu, 3, "调用Zarr转Tif");
            callZarr2tif(data);
            update(simu, 4, "解析数据");
            createNsl(data);
            update(simu, 10, "完成");
        } catch (Exception ex) {
@@ -158,8 +165,17 @@
        return callBat(cmd);
    }
    /**
     * 调用zarr2tif
     */
    private String callZarr2tif(DataPo data) throws Exception {
        String cmd = "";
        File uwBat = new File(config.getUwSolverBat());
        String zarrFile = uwBat.getParent() + File.separator + "result.zarr";
        String inPath = config.getInPath() + File.separator + data.getInPath();
        String terrainFile = inPath + File.separator + config.getDemFile();
        String waterPath = inPath + File.separator + "depth";
        String cmd = String.format("%s \"%s\" \"%s\" \"%s\" \"%s\"", config.getZarr2tifBat(), "depth", zarrFile, terrainFile, waterPath);
        return callBat(cmd);
    }
@@ -189,4 +205,32 @@
            return null;
        }
    }
    private void createNsl(DataPo data) throws Exception {
        String inPath = config.getInPath() + File.separator + data.getInPath() + File.separator + "depth";
        procTifs(inPath, inPath, data.getStartTime());
        testService.test(data);
    }
    private void procTifs(String tifPath, String outPath, Date startTime) {
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(startTime);
        for (File file : new File(tifPath).listFiles()) {
            if (!file.exists() || !file.isDirectory()) continue;
            File tif = new File(tifPath + "\\" + file.getName() + File.separator + "depth.tif");
            if (!tif.exists() || tif.isDirectory()) continue;
            calendar.add(Calendar.SECOND, 1);
            String newName = df.format(calendar.getTime());
            String newFile = outPath + File.separator + newName + ".tif";
            System.out.println(newFile);
            tif.renameTo(new File(newFile));
            file.delete();
        }
    }
}