1
13693261870
2024-11-02 ee26ff7331614b14c9f156c5590724e29e99dc06
src/main/java/com/se/simu/service/WaterService.java
@@ -1,18 +1,20 @@
package com.se.simu.service;
import cn.hutool.core.io.FileUtil;
import cn.hutool.json.JSONUtil;
import com.se.simu.config.PropertiesConfig;
import com.se.simu.domain.po.DataPo;
import com.se.simu.domain.po.SimuPo;
import com.se.simu.domain.vo.*;
import com.se.simu.helper.GdalHelper;
import com.se.simu.helper.StringHelper;
import lombok.extern.slf4j.Slf4j;
import org.gdal.gdal.Dataset;
import org.gdal.gdal.gdal;
import org.gdal.gdalconst.gdalconst;
import org.gdal.osr.SpatialReference;
import org.gdal.osr.osr;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.io.File;
@@ -20,6 +22,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
 * 内涝服务类
@@ -37,9 +40,9 @@
    /**
     * 获取元数据信息
     */
    public byte[] getLayerJson(String serviceName) {
    public byte[] getson(String serviceName, String json) {
        try {
            String filePath = config.getOutPath() + File.separator + serviceName + File.separator + "layer.json";
            String filePath = config.getOutPath() + File.separator + serviceName + File.separator + json;
            File dat = new File(filePath);
            if (!dat.exists()) {
@@ -54,6 +57,7 @@
            return bytes;
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            return null;
        }
    }
@@ -104,30 +108,6 @@
    }
    /**
     * 获取降水曲线文件曲线图
     */
    public byte[] getRainfall(String serviceName) {
        try {
            String filePath = config.getOutPath() + File.separator + serviceName + File.separator + "rainfall.json";
            File rainfall = new File(filePath);
            if (!rainfall.exists()) {
                return null;
            }
            byte[] bytes = new byte[(int) rainfall.length()];
            FileInputStream fs = new FileInputStream(filePath);
            fs.read(bytes);
            fs.close();
            return bytes;
        } catch (Exception ex) {
            return null;
        }
    }
    /**
     * 根据坐标查询积水深度:gdalconst.GA_Update
     */
    public Double getWaterHeight(SimuPo simu, double x, double y, Long timestamp) {
@@ -167,11 +147,7 @@
    private SpatialReference getSpatialRef(SimuPo simu) {
        DataPo data = JSONUtil.toBean(simu.getData(), DataPo.class);
        SpatialReference sr = new SpatialReference();
        sr.ImportFromEPSG(data.getEpsg());
        sr.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER);
        return sr;
        return data.getSpatialReference();
    }
    /**
@@ -194,4 +170,42 @@
    public static boolean isValid(double val) {
        return !Double.isNaN(val) && val > Integer.MIN_VALUE;
    }
    public List<BuildingDepthVo> getBuildingDepthBySeid(String serviceName, String seid) {
        List<BuildingDepthVo> list = readBuildingJson(serviceName);
        if (CollectionUtils.isEmpty(list)) return null;
        return list.parallelStream()
                .filter(b -> seid.equals(b.getId()))
                .sorted((a, b) -> a.getTimestamp().compareTo(b.getTimestamp()))
                .collect(Collectors.toList());
    }
    public List<BuildingDepthVo> getBuildingDepthByTime(String serviceName, Long timestamp) {
        List<BuildingDepthVo> list = readBuildingJson(serviceName);
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        return list.parallelStream().filter(b -> timestamp.equals(b.getTimestamp())).collect(Collectors.toList());
    }
    private List<BuildingDepthVo> readBuildingJson(String serviceName) {
        String filePath = config.getOutPath() + File.separator + serviceName + File.separator + "building.json";
        String json = getText(filePath);
        if (StringHelper.isEmpty(json)) {
            return null;
        }
        return JSONUtil.toList(json, BuildingDepthVo.class);
    }
    private String getText(String filePath) {
        File file = new File(filePath);
        if (!file.exists()) {
            return null;
        }
        return FileUtil.readUtf8String(file);
    }
}