管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2022-11-04 8aa79d9913374a471c80f5855a773850b87f601c
src/main/java/com/lf/server/service/all/BaseQueryService.java
@@ -2,6 +2,7 @@
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lf.server.entity.all.RedisCacheKey;
import com.lf.server.entity.ctrl.IdNameEntity;
import com.lf.server.entity.ctrl.TabEntity;
import com.lf.server.entity.data.DictEntity;
@@ -13,11 +14,13 @@
import com.lf.server.mapper.all.BasicMapper;
import com.lf.server.mapper.all.GeomBaseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.cache.RedisCache;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
 * 父查询服务类
@@ -27,6 +30,9 @@
public class BaseQueryService implements BaseQueryMapper {
    @Autowired
    BaseQueryMapper baseQueryMapper;
    @Autowired
    RedisService redisService;
    /**
     * 表名Map
@@ -161,17 +167,41 @@
     * @param basicMapper 父Mapper
     * @param wrapper     QueryWrapper
     * @param wkt         WKT(著名文本)
     * @param srid        空间引用标识符
     * @throws Exception 异常
     */
    public void addGeomWrapper(BasicMapper basicMapper, QueryWrapper wrapper, String wkt, Integer srid) throws Exception {
        if (basicMapper instanceof GeomBaseMapper && !StringHelper.isEmpty(wkt) && srid != null) {
    public void addGeomWrapper(BasicMapper basicMapper, QueryWrapper wrapper, String wkt) throws Exception {
        if (basicMapper instanceof GeomBaseMapper && !StringHelper.isEmpty(wkt)) {
            wkt = AesHelper.decrypt(wkt);
            wrapper.apply(String.format("ST_Intersects(geom, ST_PolygonFromText('%s', %d))", wkt, srid));
            Integer srid = getSrid((GeomBaseMapper) basicMapper);
            wrapper.apply(String.format("ST_Intersects(ST_PolygonFromText('%s', %d), geom)", wkt, srid));
        }
    }
    /**
     * 获取几何对象的空间参考
     *
     * @param basicMapper 空间基础Mapper
     * @return SRID
     */
    private Integer getSrid(GeomBaseMapper basicMapper) {
        String tab = getTabName(basicMapper);
        String key = RedisCacheKey.sridKey(tab);
        Object obj = redisService.get(key);
        if (obj instanceof Integer) {
            return (Integer) obj;
        }
        Integer srid = basicMapper.selectSrid(tab);
        if (srid != null) {
            redisService.put(key, srid, 5, TimeUnit.MINUTES);
        }
        return srid;
    }
    /**
     * 根据Mapper获取表名
     *
     * @param basicMapper Mapper