管道基础大数据平台系统开发-【后端】-Server
13693261870
2023-08-27 126a156beabb3e61bc5ba888f8915adc8e974c2a
添加检查栅格数据的坐标系ID功能
已添加1个文件
已修改5个文件
149 ■■■■■ 文件已修改
src/main/java/com/lf/server/controller/data/PublishController.java 63 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/entity/all/StaticData.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/mapper/data/MetaMapper.java 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/data/MetaService.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/data/RasterService.java 58 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/data/MetaMapper.xml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/data/PublishController.java
@@ -3,14 +3,19 @@
import com.lf.server.annotation.SysLog;
import com.lf.server.controller.all.BaseController;
import com.lf.server.entity.all.ResponseMsg;
import com.lf.server.entity.all.StaticData;
import com.lf.server.entity.ctrl.PubEntity;
import com.lf.server.entity.data.MetaEntity;
import com.lf.server.entity.data.MetaFileEntity;
import com.lf.server.entity.data.PublishEntity;
import com.lf.server.entity.sys.UserEntity;
import com.lf.server.helper.PathHelper;
import com.lf.server.helper.StringHelper;
import com.lf.server.helper.WebHelper;
import com.lf.server.service.data.LayerService;
import com.lf.server.service.data.MetaService;
import com.lf.server.service.data.PublishService;
import com.lf.server.service.data.RasterService;
import com.lf.server.service.sys.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
@@ -20,6 +25,8 @@
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -39,6 +46,15 @@
    @Resource
    LayerService layerService;
    @Resource
    MetaService metaService;
    @Resource
    RasterService rasterService;
    @Resource
    PathHelper pathHelper;
    @SysLog()
    @ApiOperation(value = "分页查询元数据")
@@ -231,6 +247,53 @@
    }
    @SysLog()
    @ApiOperation(value = "查询栅格数据的坐标系ID")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "元数据ID集合", dataType = "Integer[]", paramType = "query", example = "10531,10527,10526")
    })
    @GetMapping(value = "/selectRasterCs")
    public ResponseMsg<Object> selectRasterCs(Integer[] ids, HttpServletRequest req) {
        try {
            if (null == ids || ids.length == 0) {
                return fail("元数据ID集合不能为空");
            }
            List<MetaEntity> list = metaService.selectByIds(StringHelper.join(Arrays.asList(ids), ","));
            if (null == list || list.isEmpty()) {
                return fail("查无数据");
            }
            String basePath = pathHelper.getConfig().getUploadPath() + File.separator;
            List<MetaEntity> errList = new ArrayList<>();
            for (MetaEntity me : list) {
                if (!StaticData.RASTER_EXT.contains("." + me.getType())) {
                    me.setBak("不是栅格数据");
                    errList.add(me);
                    continue;
                }
                String filePath = basePath + me.getPath();
                File f = new File(filePath);
                if (!f.exists() || f.isDirectory()) {
                    me.setBak("文件不存在");
                    errList.add(me);
                    continue;
                }
                Integer epsg = rasterService.getRaterEpsg(filePath);
                if (null == epsg || epsg < 1) {
                    me.setBak("坐标系ID无效");
                    errList.add(me);
                }
            }
            return success(errList.size(), errList);
        } catch (Exception ex) {
            return fail(ex.getMessage(), null);
        }
    }
    @SysLog()
    @ApiOperation(value = "插入发布数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "entity", value = "实体类", dataType = "PubEntity", paramType = "body")
src/main/java/com/lf/server/entity/all/StaticData.java
@@ -210,6 +210,11 @@
    public static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
    /**
     * æ …格数据扩展名
     */
    public final static List<String> RASTER_EXT = new ArrayList<>(Arrays.asList(".img", ".tif", ".tiff", "jpg", "jp2"));
    /**
     * å¯†ç æ­£åˆ™è¡¨è¾¾å¼
     */
    public final static String PWD_REG = "^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\\W!@#$%^&*`~()\\-_+=,.?;<>]+$)(?![a-z0-9]+$)(?![a-z\\W!@#$%^&*`~()\\-_+=,.?;<>]+$)(?![0-9\\W!@#$%^&*`~()\\-_+=,.?;<>]+$)[a-zA-Z0-9\\W!@#$%^&*`~()\\-_+=,.?;<>]{12,20}$";
src/main/java/com/lf/server/mapper/data/MetaMapper.java
@@ -130,12 +130,20 @@
    /**
     * æ ¹æ®å¤šä¸ªID查询元数据(数据表)
     *
     * @param ids
     * @return
     * @param ids ID字符串
     * @return å…ƒæ•°æ®é›†åˆ
     */
    public List<MetaEntity> selectByIdsForTab(String ids);
    /**
     * æ ¹æ®å¤šä¸ªID查询元数据
     *
     * @param ids ID字符串
     * @return å…ƒæ•°æ®é›†åˆ
     */
    public List<MetaEntity> selectByIds(String ids);
    /**
     * æŸ¥è¯¢å…ƒæ•°æ®æ–‡ä»¶
     *
     * @param ids å…ƒæ•°æ®ID集合
src/main/java/com/lf/server/service/data/MetaService.java
@@ -130,6 +130,11 @@
    }
    @Override
    public List<MetaEntity> selectByIds(String ids) {
        return metaMapper.selectByIds(ids);
    }
    @Override
    public List<MetaEntity> selectMetaFiles(List<Integer> ids) {
        return metaMapper.selectMetaFiles(ids);
    }
src/main/java/com/lf/server/service/data/RasterService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,58 @@
package com.lf.server.service.data;
import com.lf.server.helper.StringHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.gdal.gdal.Dataset;
import org.gdal.gdal.gdal;
import org.gdal.gdalconst.gdalconst;
import org.springframework.stereotype.Service;
import java.io.File;
/**
 * æ …格服务
 * @author WWW
 * @date 2023-08-27
 */
@Service
public class RasterService {
    private final static Log log = LogFactory.getLog(RasterService.class);
    /**
     * èŽ·å–æ …æ ¼æ•°æ®çš„EPSG编码
     */
    public Integer getRaterEpsg(String file) {
        Dataset ds = null;
        try {
            File f = new File(file);
            if (!f.exists() || f.isDirectory()) {
                return null;
            }
            ds = gdal.Open(file, gdalconst.GA_ReadOnly);
            if (null == ds || 0 == ds.getRasterCount()) {
                return null;
            }
            if (null == ds.GetSpatialRef()) {
                return null;
            }
            // PROJCS、 GEOGCS、GEOGCS æˆ– NULL
            String code = ds.GetSpatialRef().GetAuthorityCode(null);
            if (StringHelper.isEmpty(code)) {
                return null;
            }
            return Integer.parseInt(code);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            return null;
        } finally {
            if (null != ds) {
                ds.delete();
            }
        }
    }
}
src/main/resources/mapper/data/MetaMapper.xml
@@ -162,6 +162,12 @@
        order by a.tab;
    </select>
    <select id="selectByIds" resultType="com.lf.server.entity.data.MetaEntity">
        select a.* from lf.sys_meta a
        where id in (${ids})
        order by id desc;
    </select>
    <select id="selectMetaFiles" resultType="com.lf.server.entity.data.MetaEntity">
        select a.*,fn_uname(a.create_user) uname,fn_get_fullname(a.depcode, 1) depName,fn_ver(a.verid) verName,fn_get_fullname(a.dircode, 2) dirName
        from lf.sys_meta a