Administrator 2 سال پیش
والد
کامیت
8e82dcdc85

+ 1 - 1
src/main/java/com/sysu/admin/api/crop/ApiLandController.java

@@ -43,7 +43,7 @@ public class ApiLandController extends BaseComponent {
     @RequestMapping("/list")
     public PaginationResult list(@RequestBody CommonVo commonVo){
         PaginationVo paginationVo = new PaginationVo(commonVo.getPage(), commonVo.getLimit(), commonVo.getLimit());
-        PaginationResult result  = landService.list(commonVo.getDistrict(),commonVo.getTown(), paginationVo, commonVo.getCrop_type());
+        PaginationResult result  = landService.list(commonVo.getSure(), commonVo.getDistrict(),commonVo.getTown(), paginationVo, commonVo.getCrop_type());
         ((List<Land>)result.data()).stream().forEach(land -> {
             land.setCropTypeName(CropAreaStat.castName(land.getCrop_type()));
             land.setParcelTypeName(LandAreaStat.castName(land.getParcelType()));

+ 61 - 2
src/main/java/com/sysu/admin/controller/aland/Land.java

@@ -14,6 +14,7 @@ import org.locationtech.jts.geom.Point;
 
 import javax.persistence.*;
 import java.util.Date;
+import java.util.HashMap;
 
 @Data
 @Accessors(chain = true)
@@ -43,9 +44,16 @@ gdp_pop——人均gdp
 hupo——离水源距离
 shengdao——离道路距离
 quxian——离城市中心距离
-TOC——土壤有机质
 Area——面积(平方米)
-     */
+TOC——土壤有机质
+ph -- 酸碱度
+c  -- 碳
+_2n -- 氮
+p -- 磷
+k -- 钾
+el_sure -- 元素可信度
+crop_sure -- 作物可信度
+ */
 
     public Land(){
     }
@@ -149,6 +157,57 @@ Area——面积(平方米)
     @Transient
     private String geojson;
 
+    /**
+     * 酸碱度
+     * 4.49 - 5.00
+     * 5.00 - 6.50
+     * 6.50 - 7.50
+     * 7.50 - 8.50
+     * 8.50 - 8.70
+     */
+    @Column()
+    private Double ph;
+
+    /**
+     *c  -- 碳
+     */
+    @Column()
+    private Double c;
+
+    /**
+     * _2n -- 氮
+     */
+    @Column()
+    private Double _2n;
+
+    /**
+     *p -- 磷
+     */
+    @Column()
+    private Double p;
+
+    /**
+     *k -- 钾
+     */
+    @Column()
+    private Double k;
+
+    /**
+     * 元素可信度
+     * 0到1之间的小数
+     */
+    @Column()
+    private Double elSure;
+
+    /**
+     * 作物类型可信度
+     * 0到1之间的小数
+     */
+    @Column()
+    private Double cropSure;
+
+
+
 
 
 

+ 5 - 7
src/main/java/com/sysu/admin/controller/aland/LandRepository.java

@@ -20,14 +20,12 @@ public interface LandRepository extends JpaPlusRepository<Land, Long> {
     List<Object[]> statDistrictParcelTypeAll(String likeCity);
 
 
-    @Query(value = "select count(1) from  leizhou_land where St_within(geom,st_geomfromtext(?1,4326))",nativeQuery = true)
-    int findCountByWkt(String wkt);
-    @Query(value = "select * from  leizhou_land where St_within(geom,st_geomfromtext(?1,4326)) limit ?2 OFFSET ?3",nativeQuery = true)
-    List<Land> findListByWkt(String wkt, Integer limit, Integer start);
-
-    @Query(value = "select count(1) from  leizhou_land where St_within(geom,st_geomfromtext(?1,4326)) and crop_type = ?2",nativeQuery = true)
+    @Query(value = "select count(1) from  leizhou_land where St_within(geom,st_geomfromtext(?1,4326)) " +
+            "and if ?2 = null then 1=1 else crop_type = ?2 )",nativeQuery = true)
     int findCountByWktAndCropType(String wkt, String cropType);
-    @Query(value = "select * from  leizhou_land where  St_within(geom,st_geomfromtext(?1,4326)) and crop_type = ?2 limit ?3 OFFSET ?4",nativeQuery = true)
+
+    @Query(value = "select * from  leizhou_land where  St_within(geom,st_geomfromtext(?1,4326)) " +
+            "and if ?2 = null then 1=1 else crop_type = ?2 endif limit ?3 OFFSET ?4",nativeQuery = true)
     List<Land> findListByWktAndCropType(String wkt, String cropType, Integer limit, Integer start);
 
     @Query(value = "select new Land(geom) from Land")

+ 31 - 24
src/main/java/com/sysu/admin/controller/aland/LandService.java

@@ -13,6 +13,7 @@ import com.xiesx.fastboot.base.pagination.PaginationHelper;
 import com.xiesx.fastboot.base.pagination.PaginationResult;
 import com.xiesx.fastboot.base.pagination.PaginationVo;
 import com.xiesx.fastboot.core.jpa.JpaPlusRepository;
+import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
@@ -175,38 +176,44 @@ public class LandService extends BaseService<Land,Long> {
         return townStatList;
     }
 
-    public PaginationResult list(String district, Integer townId, PaginationVo page, String cropType){
+    public PaginationResult list(Double[] sure,String district, Integer townId, PaginationVo page, String cropType){
         String wkt = null;
         if(townId != null) {
              wkt = townService.findWktById(townId);
         }else if(StringUtils.isNotBlank(district)) {
              wkt = districtRepository.findWktByCode(district);
         }
-        if(wkt == null) {
-            Predicate predicate = null;
-            Pageable pageable = PageRequest.of(page.getPage(), page.getLimit(), Sort.by(Land.FIELDS.id));
-            QLand qLand = QLand.land;
-            Page<Land> pageData = null;
-            if(StringUtils.isNotBlank(cropType)){
-                pageData = landRepository.findAll(qLand.crop_type.eq(cropType), pageable);
-            }else{
-                pageData = landRepository.findAll(pageable);
-            }
-            return PaginationHelper.create(pageData.getContent(), pageData.getTotalPages(), pageData.getPageable().getPageNumber());
-        }else{
-            List<Land> data = null;
-            int count;
-            int start = page.getLimit() * page.getPage();
-            if(StringUtils.isNotBlank(cropType)){
-                data = landRepository.findListByWktAndCropType(wkt, cropType, page.getLimit(), start);
-                count = landRepository.findCountByWktAndCropType(wkt, cropType);
-            }else{
-                data = landRepository.findListByWkt(wkt, page.getLimit(), start);
-                count = landRepository.findCountByWkt(wkt);
-            }
-            return PaginationHelper.create(data, count, page.page);
+        List<Land> data = null;
+        int count;
+        int start = page.getLimit() * page.getPage();
+        StringBuffer countSql = new StringBuffer(100);
+        StringBuffer sql = new StringBuffer(100);
+        countSql.append("select count(1) from  leizhou_land where 1=1");
+        sql.append("select * from  leizhou_land where 1=1");
+        if(wkt != null){
+            countSql.append(" and St_within(geom,st_geomfromtext('");
+            countSql.append(wkt).append("',4326))");
+            sql.append(" and St_within(geom,st_geomfromtext('");
+            sql.append(wkt).append("',4326))");
+        }
 
+        if(StringUtils.isNotBlank(cropType)) {
+            countSql.append(" and crop_type = '").append(cropType).append("'");
+            sql.append(" and crop_type = '").append(cropType).append("'");
         }
+
+        if(ArrayUtils.isNotEmpty(sure)){
+            countSql.append(" and crop_sure >= ").append(sure[0]);
+            countSql.append(" and crop_sure <= ").append(sure[1]);
+            sql.append(" and crop_sure >= ").append(sure[0]);
+            sql.append(" and crop_sure <= ").append(sure[1]);
+        }
+
+        sql.append(" limit ").append(page.getLimit()).append(" OFFSET ").append(start);
+        count = Integer.valueOf(mEntityManager.createNativeQuery(countSql.toString()).getSingleResult().toString());
+        data = mEntityManager.createNativeQuery(sql.toString(), Land.class).getResultList();
+        return PaginationHelper.create(data, count, page.page);
+
     }
 
     public Land findByPoint(Double[] point){

+ 1 - 2
src/main/java/com/sysu/admin/site/CommonVo.java

@@ -21,8 +21,7 @@ public class CommonVo {
     private Date date;
     private String crop_type;
     private Double[] point;
-
     public Integer page = 1;
-
     public Integer limit = 25;
+    public Double[] sure;
 }

+ 2 - 0
src/test/java/com/sysu/admin/utils/shape/postgis/Main.java

@@ -1,5 +1,6 @@
 package com.sysu.admin.utils.shape.postgis;
 
+import java.util.HashMap;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -20,5 +21,6 @@ public class Main {
 //        postGisUtilTest.ST_Extent();
 //        postGisUtilTest.createIndex();
 //        postGisUtilTest.createCOLUMN();
+
     }
 }