From 8aa79d9913374a471c80f5855a773850b87f601c Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期五, 04 十一月 2022 10:41:31 +0800
Subject: [PATCH] 1

---
 src/main/java/com/lf/server/service/all/BaseQueryService.java |   38 ++++++++++++++++++++++++++++++++++----
 1 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/lf/server/service/all/BaseQueryService.java b/src/main/java/com/lf/server/service/all/BaseQueryService.java
index bf20e0a..40a1769 100644
--- a/src/main/java/com/lf/server/service/all/BaseQueryService.java
+++ b/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 鐖禡apper
      * @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

--
Gitblit v1.9.3