Administrator 2 yıl önce
ebeveyn
işleme
538f2c792b

+ 1 - 0
src/main/java/com/sysu/admin/controller/crop/CropLandService.java

@@ -94,6 +94,7 @@ public class CropLandService extends BaseService<CropLand, Long> {
     }
 
     public List<CropPoint> findCropLandNoGeomByTableNamesAndBBox(String tableNames, Double x1, Double y1, Double x2, Double y2){
+        这里的逻辑放在AutoTableNameInterceptor 处理 多表查询
         String wkt = bboxToWkt(x1, y1 , x2, y2);
         String sql = "";
         String[]  tableNameArray = TextUtil.split(tableNames, ",");

+ 12 - 2
src/main/java/com/sysu/admin/controller/crop/range/AutoTableNameInterceptor.java

@@ -1,5 +1,6 @@
 package com.sysu.admin.controller.crop.range;
 
+import com.sysu.admin.utils.TextUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.hibernate.EmptyInterceptor;
 
@@ -24,8 +25,17 @@ public class AutoTableNameInterceptor extends EmptyInterceptor {
                 sql = sql.replaceAll("p_crop", tableName);
             }
             if (sql.indexOf("select") > -1) {
-                /处理多表查询
-                sql = sql.replaceAll("p_crop", tableName);
+                String newSql = "";
+                String[] tableArray =  TextUtil.split(tableName,",");
+                int i=0;
+                for(String table : tableArray) {
+                    if (i > 0) {
+                        newSql += "\n union all \n";
+                    }
+                    newSql += sql.replaceAll("p_crop", table);
+                    i++;
+                }
+                return newSql;
             }
         }
         return sql;