1
13693261870
2024-10-30 5826bfa3f502f47f46b37b2e18f0b2f90af691a0
src/main/java/com/se/simu/service/ResultService.java
@@ -23,6 +23,10 @@
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;
@@ -61,6 +65,7 @@
            copeWater(dto, layer);
            copeFlow(dto, layer);
            copeLayerJson(dto, layer);
            copeRainFallJson(dto, layer);
        } finally {
            File dir = new File(dto.getTemp());
            if (dir.exists()) {
@@ -343,6 +348,7 @@
                if (null == ds || 0 == ds.getRasterCount()) return;
                createWaterPng(dto, ds, layer, layer.getWaters().getData().get(i));
                copyWaterTif(dto, ds, layer.getWaters().getData().get(i));
            } finally {
                if (null != ds) ds.delete();
            }
@@ -363,6 +369,12 @@
            String png = waterPath + File.separator + sizes[0] + "_" + sizes[1] + ".png";
            water2Png(dto, layer, tif, png, sizes[0], sizes[1]);
        }
    }
    private static void copyWaterTif(ResultDto dto, Dataset ds, long ticks) {
        String source = ds.GetDescription();
        String target = dto.getOutPath() + File.separator + "waters" + File.separator + ticks + File.separator + "water.tif";
        FileUtil.copyFile(source, target);
    }
    private static String getNameWithExt(String file) {
@@ -525,4 +537,37 @@
        bw.close();
        fw.close();
    }
    /**
     * 处理降水曲线文件曲线图
     */
    public void copeRainFallJson(ResultDto dto, LayerDto layer) throws IOException, ParseException {
        String rainGageFilePath = config.getInPath() + File.separator + dto.getServiceName() + File.separator + "RainGage.dat";
        String filePath = dto.getOutPath() + File.separator + "rainfall.json";
        String line;
        Map<String, Double> rainFallJsons = new LinkedHashMap<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        BufferedReader br = new BufferedReader(new FileReader(rainGageFilePath));
        // 处理第一行数据
        if ((line = br.readLine()) != null) {
            while ((line = br.readLine()) != null) {
                // 处理每一行数据
                String[] rainFall = line.split(" ");
                if (rainFall.length < 7) continue;
                String sdt = rainFall[1] + "-" + rainFall[2] + "-" + rainFall[3] + " " + rainFall[4] + ":" + rainFall[5];
                BigDecimal num = new BigDecimal(rainFall[6]);
                rainFallJsons.put("" + sdf.parse(sdt).getTime(), num.setScale(2, RoundingMode.HALF_UP).doubleValue());
            }
        }
        FileWriter fw = new FileWriter(filePath);
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(JSON.toJSONString(rainFallJsons));
        bw.close();
        fw.close();
    }
}