Administrator 2 年之前
父節點
當前提交
ea841064fa

+ 4 - 7
src/main/java/com/sysu/admin/controller/crop/CropLandService.java

@@ -94,7 +94,7 @@ public class CropLandService extends BaseService<CropLand, Long> {
     }
 
     public List<CropPoint> findCropLandNoGeomByTableNamesAndBBox(String tableNames, Double x1, Double y1, Double x2, Double y2){
-        String wkt = "POLYGON (("+x1+" "+y1+", "+x1+" "+y2+", "+x2+" "+y2+", "+x2+" "+y1+", "+x1+" "+y1+"))";
+        String wkt = bboxToWkt(x1, y1 , x2, y2);
         String sql = "";
         String[]  tableNameArray = TextUtil.split(tableNames, ",");
         int i=0;
@@ -102,7 +102,7 @@ public class CropLandService extends BaseService<CropLand, Long> {
             if(i > 0){
                 sql+="\n union all \n";
             }
-            sql += " select id,gridcode,crop_type,st_asgeojson(center_point) as geojson,status,receiver,name,address,growing_period ";
+            sql += " select  "+ CropPoint.selectColumns;
             sql += "from " + table;
             sql += " where ST_Intersects(geom,st_geomfromtext('"+wkt+"',4326)) ";
             i++;
@@ -191,11 +191,8 @@ public class CropLandService extends BaseService<CropLand, Long> {
     }
 
 
-
-
-    @Transactional
-    public void exec(StringBuffer sql){
-            mEntityManager.createNativeQuery(sql.toString()).executeUpdate();
+    public static String bboxToWkt(Double x1, Double y1, Double x2, Double y2){
+        return "POLYGON (("+x1+" "+y1+", "+x1+" "+y2+", "+x2+" "+y2+", "+x2+" "+y1+", "+x1+" "+y1+"))";
     }
 
     @Override

+ 4 - 0
src/main/java/com/sysu/admin/controller/crop/CropPoint.java

@@ -66,4 +66,8 @@ public class CropPoint {
     private Integer status;
 
 
+    @Transient
+    public static String selectColumns = "id,gridcode,crop_type,st_asgeojson(center_point) as geojson,status,receiver,name,address,growing_period";
+
+
 }

+ 4 - 1
src/main/java/com/sysu/admin/controller/crop/range/AutoTableNameInterceptor.java

@@ -20,7 +20,10 @@ public class AutoTableNameInterceptor extends EmptyInterceptor {
             if (sql.indexOf("delete") > -1 || sql.indexOf("insert") > -1) {
                 return sql;
             }
-            if (sql.indexOf("select") > -1 || sql.indexOf("update") > -1) {
+            if(sql.indexOf("update") > -1){
+                sql = sql.replaceAll("p_crop", tableName);
+            }
+            if (sql.indexOf("select") > -1) {
                 sql = sql.replaceAll("p_crop", tableName);
             }
         }