dcb
2025-07-07 97629da6a002b534da10f828187fd6cd65941aa4
src/main/java/com/se/nsl/service/ResolveService.java
@@ -334,14 +334,15 @@
        String rainfallFile = (inPath + File.separator + "rainfall.dat");
        String saveName = inPath + File.separator + "result.zarr";
//        ConfigVo vo = new ConfigVo(terrainFile, landuseFile, terrainFile, rainfallFile, saveName, duration, config.getSaveFrames());
        Integer saveFrameInterval = config.getSaveFrameInterval();
        int saveFrames = duration / 60 / saveFrameInterval;
        Double saveFrameInterval = config.getSaveFrameInterval();
        int saveFrames = (int) (duration / saveFrameInterval);
        Short type = simu.getType();
        SimulateType simulateType = SimulateType.of(type);
        String saveMode = simulateType.getSaveMode();
        String startTime = TimeFormatUtil.formatDate(data.getStartTime());
        ConfigVo vo = new ConfigVo(terrainFile, landuseFile, terrainFile, rainfallFile,
                saveName, duration, saveFrames, saveMode, startTime);
        vo.setEvaporation(config.getEvaporation());
        vo.getResult().setSave_filter(config.getSaveFilter());
        String configFile = config.getInPath() + File.separator + data.getInPath() + File.separator + data.getInPath() + ".json";
//        ComHelper.writeJson(configFile, JSON.toJSONString(vo));
@@ -517,115 +518,17 @@
        Files.write(Paths.get(dat), list, StandardCharsets.UTF_8);
    }
    //实时模拟
//    public String realTimeSimulate(RealTimeInput input) throws IOException {
//        long currentTime = System.currentTimeMillis();
//        //根据服务找到指定的文件夹
//        String serviceName = input.getServiceName();
//        File serviceNameDir = new File(config.getInPath(), serviceName);
//        //生成一个新的雨量文件,需要原先雨量文件的一些信息,所以需要先读取旧的
//        String[] values = readTheOldFirstLineRainfallValue(serviceNameDir);
//        File newDatFile = generateNewRainfallFile(input, values, serviceNameDir, currentTime);
//
//        //生成一个新的生成zarr的配置文件
//        File newConfigFile = generateNewZarrConfigFile(serviceNameDir, serviceName, currentTime, newDatFile);
//        //执行求解器运算
//        String cmd = String.format("%s \"%s\"", config.getUwSolverBat(), newConfigFile);
//        callBat2(cmd);
//
//        //生成一个新的zarr转tif的json文件
//        File newZarr2TifJson = generateNewZarr2TifJson(serviceNameDir, currentTime);
//        //执行zarr转tif
//        String zarr2TifCmd = String.format("%s \"%s\"", config.getZarr2tifBat(), newZarr2TifJson);
//        callBat2(zarr2TifCmd);
//        //返回新的layer.json名称
//        return generateLayerJsonAndPng(serviceName, serviceNameDir, currentTime);
//
//    }
//    private String generateLayerJsonAndPng(String serviceName, File serviceNameDir, long currentTime) throws IOException {
//        ResultDto resultDto = new ResultDto();
//        resultDto.setServiceName(serviceName);
//        File temp = Paths.get(config.getOutPath(), serviceName, "temp").toFile();
//        if (!temp.exists()) temp.mkdir();
//        resultDto.setTemp(temp.getAbsolutePath());
//        resultDto.setOutPath(Paths.get(config.getOutPath(), serviceName).toString());
//        File dem = new File(serviceNameDir, "DEM.tif");
//        resultDto.setTerrainFile(dem.getAbsolutePath());
//        File newDepthDir = new File(serviceNameDir + File.separator + "depth_" + currentTime);
//        resultDto.setWaterPath(newDepthDir.getAbsolutePath());
//        LayerDto layerDto = new LayerDto(config.getVer(), 4548, config.getSizes());
//        String newLayerJsonName = "layer_" + currentTime + ".json";
//        layerDto.setName(newLayerJsonName);
//        testService.processRealTime(resultDto, layerDto);
//        return newLayerJsonName;
//    }
//    private File generateNewZarr2TifJson(File serviceNameDir, long currentTime) throws IOException {
//        File srcZarr2TifJson = new File(serviceNameDir, "zarr2tif.json");
//        Zarr2Tif zarr2Tif = mapper.readValue(srcZarr2TifJson, Zarr2Tif.class);
//        //修改zarr2tif对象中的字段
////        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);
//        zarr2Tif.setGeotiff_dir(serviceNameDir + File.separator + "depth_" + currentTime);
//        File newZarr2TifJson = new File(serviceNameDir, "zarr2tif_" + currentTime + ".json");
//        mapper.writeValue(newZarr2TifJson, zarr2Tif);
//        return newZarr2TifJson;
//    }
//    private File generateNewZarrConfigFile(File serviceNameDir, String serviceName, long currentTime, File newDatFile) throws IOException {
//        File configFile = new File(serviceNameDir, serviceName + ".json");
//        ConfigVo configVo = mapper.readValue(configFile, ConfigVo.class);
//        int simulateTime = 300; //模拟时间,默认为5min,即300s
//        int intervalTime = 60; //每帧的间隔时间,默认为60s,60s生成一帧
//        configVo.getRaingage().set(0, newDatFile.getAbsolutePath()); //raingage file
//        ResultVo result = configVo.getResult();
//        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);
//        File newConfigFile = new File(serviceNameDir, currentTime + ".json");
//        mapper.writeValue(newConfigFile, configVo);
//        return newConfigFile;
//    }
//    private File generateNewRainfallFile(RealTimeInput input, String[] values, File serviceNameDir, long currentTime) throws IOException {
//        String station = values[0];
//        double lon = Double.parseDouble(values[1]);
//        double lat = Double.parseDouble(values[2]);
//        String title = config.getRainfallTitle();
//        List<String> newLines = new ArrayList<>();
//        newLines.add(title);
//        List<RealTimeInput.RealTimeData> data = input.getData();
//        for (RealTimeInput.RealTimeData rd : data) {
//            LocalDateTime dateTime = rd.getDateTime();
//            int year = dateTime.getYear();
//            int month = dateTime.getMonthValue();
//            int day = dateTime.getDayOfMonth();
//            int hour = dateTime.getHour();
//            int minute = dateTime.getMinute();
//            double intensity = rd.getIntensity(); //保留指定位数小数
//            String l = String.format("%s %s %s %s %s %s %s %s %s",
//                    station, lon, lat, year, month, day, hour, minute, String.format("%.6f", intensity));
//            newLines.add(l);
//        }
//        File newDatFile = new File(serviceNameDir, "rainfall_" + currentTime + ".dat");
//        if (!newDatFile.exists()) newDatFile.createNewFile();
//        Files.write(newDatFile.toPath(), newLines, StandardOpenOption.TRUNCATE_EXISTING);
//        return newDatFile;
//    }
//    private static String[] readTheOldFirstLineRainfallValue(File serviceNameDir) throws IOException {
//        File srcRailfallFile = new File(serviceNameDir, "rainfall.dat");
//        List<String> lines = Files.readAllLines(srcRailfallFile.toPath());
//        String secondLine = lines.get(1);
//        return secondLine.split(" ");
//    }
    public List<String> simulationResults(String serviceName) {
        String outPath = config.getOutPath();
        File serviceNameDir = new File(outPath, serviceName);
        List<String> res = new ArrayList<>();
        File[] files = serviceNameDir.listFiles();
        for (File file : files) {
            String name = file.getName();
            if (name.startsWith("layer")) {
                res.add(name);
            }
        }
        return res;
    }
}