dcb
2025-06-18 4c4d0f591f94428ed7e5d2f4ae5df5c5087d8c26
src/main/java/com/se/nsl/service/ResolveService.java
@@ -69,6 +69,8 @@
    @Resource
    TestService testService;
    private ObjectMapper mapper = new ObjectMapper();
    Integer DIGIT = 1000000;
    SimpleDateFormat YYYYMDHM = new SimpleDateFormat("yyyy M d H m ");
@@ -165,6 +167,7 @@
        AreaType at = AreaType.of(areaType);
        String terrainTif = config.getSourceDem();
        String landuseTif = config.getSourceLanduse();
        String stationTif = null;
        if (at == AreaType.KEY_DITCH) {
            File keyDitchDir = new File(config.getKeyDitch());
            String areaName = simu.getAreaName();
@@ -179,6 +182,9 @@
                    }
                    if (name.toLowerCase().contains("landuse")) {
                        landuseTif = file.getAbsolutePath();
                    }
                    if (name.toLowerCase().contains("station")) {
                        stationTif = file.getAbsolutePath();
                    }
                }
            }
@@ -203,9 +209,14 @@
        Dataset dsLanduse = gdal.Open(landuseTif, gdalconstConstants.GA_ReadOnly);
        ComHelper.Resample(dsLanduse, null, landuseFile, null, wkt, null, null);
        dsLanduse.delete();
        String stationFile = inPath + File.separator + "Station.tif";
        Dataset dsStation = gdal.Open(stationTif, gdalconstConstants.GA_ReadOnly);
        ComHelper.Resample(dsStation, null, stationFile, null, wkt, null, null);
        dsStation.delete();
    }
    public void updateTif(Simu simu, SimuData data2) throws IOException {
    public void updateTif(Simu simu, SimuData data2) {
        Dataset ds = gdal.Open(config.getSourceLanduse(), gdalconstConstants.GA_Update); // 以读写模式打开TIFF文件
        Band band = ds.GetRasterBand(1);
@@ -332,13 +343,13 @@
        Short type = simu.getType();
        SimulateType simulateType = SimulateType.of(type);
        String saveMode = simulateType.getSaveMode();
        ConfigVo vo = new ConfigVo(terrainFile, landuseFile, terrainFile, rainfallFile, saveName, duration, saveFrames, saveMode);
        String startTime = TimeFormatUtil.formatDate(data.getStartTime());
        ConfigVo vo = new ConfigVo(terrainFile, landuseFile, terrainFile, rainfallFile,
                saveName, duration, saveFrames, saveMode, startTime);
        String configFile = config.getInPath() + File.separator + data.getInPath() + File.separator + data.getInPath() + ".json";
        ComHelper.writeJson(configFile, JSON.toJSONString(vo));
//        ComHelper.writeJson(configFile, JSON.toJSONString(vo));
        mapper.writeValue(new File(configFile), vo);
        String cmd = String.format("%s \"%s\"", config.getUwSolverBat(), configFile);
        return callBat2(cmd);
    }
@@ -351,10 +362,9 @@
        String geotiffDir = inPath + File.separator + "depth";
        String terrainFile = inPath + File.separator + config.getTerrainFile();
        String jsonPath = inPath + File.separator + "zarr2tif.json";
        Zarr2Tif zarr2Tif = new Zarr2Tif(zarrFile, geotiffDir, terrainFile, data.getStartTime());
        ComHelper.writeJson(jsonPath, JSON.toJSONString(zarr2Tif));
        Zarr2Tif zarr2Tif = new Zarr2Tif(zarrFile, geotiffDir, terrainFile, Collections.emptyList());
//        ComHelper.writeJson(jsonPath, JSON.toJSONString(zarr2Tif));
        mapper.writeValue(new File(jsonPath), zarr2Tif);
        String cmd = String.format("%s \"%s\"", config.getZarr2tifBat(), jsonPath);
        return callBat2(cmd);
@@ -556,13 +566,12 @@
        return newLayerJsonName;
    }
    private static File generateNewZarr2TifJson(File serviceNameDir, long currentTime) throws IOException {
    private File generateNewZarr2TifJson(File serviceNameDir, long currentTime) throws IOException {
        File srcZarr2TifJson = new File(serviceNameDir, "zarr2tif.json");
        ObjectMapper mapper = new ObjectMapper();
        Zarr2Tif zarr2Tif = mapper.readValue(srcZarr2TifJson, Zarr2Tif.class);
        //修改zarr2tif对象中的字段
        String stamp = TimeFormatUtil.formatTime(currentTime, "yyyy-MM-dd HH:mm:ss");
        zarr2Tif.setStart_timestamp(stamp);
//        String stamp = TimeFormatUtil.formatTime(currentTime, "yyyy-MM-dd HH:mm:ss");
//        zarr2Tif.setStart_timestamp(stamp);
//        String newZarrPath = serviceNameDir + File.separator + "result_" + currentTime + ".zarr";
        String newZarrPath = serviceNameDir + File.separator + "result.zarr";
        zarr2Tif.setZarr_file(newZarrPath);
@@ -574,13 +583,16 @@
    private File generateNewZarrConfigFile(File serviceNameDir, String serviceName, long currentTime, File newDatFile) throws IOException {
        File configFile = new File(serviceNameDir, serviceName + ".json");
        ObjectMapper mapper = new ObjectMapper();
        ConfigVo configVo = mapper.readValue(configFile, ConfigVo.class);
        configVo.setDuration(configVo.getDuration() + 300); //固定为5min
        int simulateTime = 300; //模拟时间,默认为5min,即300s
        int intervalTime = 60; //每帧的间隔时间,默认为60s,60s生成一帧
        configVo.getRaingage().set(0, newDatFile.getAbsolutePath()); //raingage file
        ResultVo result = configVo.getResult();
        result.setSave_interval(60); //60s生成一帧
        result.setSave_frames(result.getSave_frames() + 5); //保留5帧,在原来的基础上增加5帧
        Integer oldDuration = configVo.getDuration();
//        result.setSave_start(oldDuration); //起始时间要在上次时间的基础上开始
        configVo.setDuration(oldDuration + simulateTime); //固定为5min
        result.setSave_interval(intervalTime);
        result.setSave_frames(result.getSave_frames() + (simulateTime / intervalTime)); //保留5帧,在原来的基础上增加5帧
//        String newZarrPath = serviceNameDir + File.separator + "result_" + currentTime + ".zarr";
        String newZarrPath = serviceNameDir + File.separator + "result.zarr";
        result.setSave_name(newZarrPath);