Administrator %!s(int64=2) %!d(string=hai) anos
pai
achega
5d1d61d363

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

@@ -10,6 +10,9 @@ import com.sysu.admin.controller.crop.images.ImageType;
 import com.sysu.admin.site.CommonVo;
 import com.sysu.admin.support.base.BaseComponent;
 import com.sysu.admin.utils.shape.GeoCastUtil;
+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.base.result.BaseResult;
 import com.xiesx.fastboot.base.result.R;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -37,13 +40,14 @@ public class ApiLandController extends BaseComponent {
     }
 
     @RequestMapping("/list")
-    public BaseResult list(@RequestBody CommonVo commonVo){
-        List<Land> landList = landService.list(commonVo.getDistrict(),commonVo.getTown(), commonVo.getLimit(), commonVo.getCrop_type());
-        landList.stream().forEach(land -> {
+    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());
+        ((List<Land>)result.data()).stream().forEach(land -> {
             land.setCropTypeName(CropAreaStat.castName(land.getCrop_type()));
             land.setGeojson(GeoCastUtil.gjson.toString(land.getGeom()));
         });
-        return R.succ(landList);
+        return result;
     }
 
     @RequestMapping("/info")

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

@@ -19,9 +19,14 @@ public interface LandRepository extends JpaPlusRepository<Land, Long> {
     @Query(value = "select district_code,parcel_type,sum(area),count(id) from leizhou_land where district_code is not null and district_code like ?1 group by district_code,parcel_type",nativeQuery = true)
     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",nativeQuery = true)
     List<Land> findListByWkt(String wkt,Integer limit);
 
+    @Query(value = "select count(1) from  leizhou_land where St_within(geom,st_geomfromtext(?1,4326)) and 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",nativeQuery = true)
     List<Land> findListByWktAndCropType(String wkt, String cropType, Integer limit);
 

+ 21 - 8
src/main/java/com/sysu/admin/controller/aland/LandService.java

@@ -9,9 +9,13 @@ import com.sysu.admin.controller.city.TownService;
 import com.sysu.admin.support.base.BaseService;
 import com.sysu.admin.utils.MySimpleDateFormat;
 import com.sysu.admin.utils.TextUtil;
+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.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.domain.Sort;
@@ -171,8 +175,7 @@ public class LandService extends BaseService<Land,Long> {
         return townStatList;
     }
 
-    public List<Land> list(String district, Integer townId, Integer limit, String cropType){
-        limit = limit == null ? 50 : limit;
+    public PaginationResult list(String district, Integer townId, PaginationVo page, String cropType){
         String wkt = null;
         if(townId != null) {
              wkt = townService.findWktById(townId);
@@ -181,17 +184,27 @@ public class LandService extends BaseService<Land,Long> {
         }
         if(wkt == null) {
             Predicate predicate = null;
-            Pageable pageable = PageRequest.of(1, limit, Sort.by(Land.FIELDS.id));
+            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)){
-                return landRepository.findAll(qLand.crop_type.eq(cropType), pageable).toList();
+                pageData = landRepository.findAll(qLand.crop_type.eq(cropType), pageable);
             }else{
-                return landRepository.findAll(pageable).toList();
+                pageData = landRepository.findAll(pageable);
             }
+            return PaginationHelper.create(pageData.getContent(), pageData.getTotalPages(), pageData.getPageable().getPageNumber());
         }else{
-            return StringUtils.isNotBlank(cropType) ?
-                    landRepository.findListByWktAndCropType(wkt, cropType, limit) :
-                    landRepository.findListByWkt(wkt, limit);
+            List<Land> data = null;
+            int count = 0;
+            if(StringUtils.isNotBlank(cropType)){
+                data = landRepository.findListByWktAndCropType(wkt, cropType, page.getLimit());
+                count = landRepository.findCountByWktAndCropType(wkt, cropType);
+            }else{
+                data = landRepository.findListByWkt(wkt, page.getLimit());
+                count = landRepository.findCountByWkt(wkt);
+            }
+            return PaginationHelper.create(data, count, page.getPage());
+
         }
     }
 

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

@@ -19,7 +19,10 @@ public class CommonVo {
     private String district;
     private Integer town;
     private Date date;
-    private Integer limit;
     private String crop_type;
     private Double[] point;
+
+    public Integer page = 1;
+
+    public Integer limit = 25;
 }