Administrator 2 years ago
parent
commit
937648ae78

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

@@ -60,6 +60,11 @@ public class ApiLandController extends BaseComponent {
         return R.succ(res);
     }
 
+    @RequestMapping("/estimate_stat")
+    public BaseResult getEstimate(@RequestBody CommonVo commonVo){
+        return R.succ(landService.getEstimate(commonVo.getDistrict(), commonVo.getCity(), commonVo.getCrop_type()));
+    }
+
 
     @RequestMapping("/list")
     public PaginationResult list(@RequestBody CommonVo commonVo){

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

@@ -19,6 +19,12 @@ 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 district_code, sum(area * dan_chan) from leizhou_land where district_code is not null and district_code like ?1 and crop_type = ?2 group by district_code",nativeQuery = true)
+    List<Object[]> statDistrictEstimate(String likeCity, String crop_type);
+
+    @Query(value = "select town_id,sum(area * dan_chan) from  leizhou_land where district_code = ?1 and town_id is not null and crop_type = ?2 group by town_id",nativeQuery = true)
+    List<Object[]> statTownEstimate(String districtCode, String crop_type);
+
 
 
 

+ 27 - 0
src/main/java/com/sysu/admin/controller/aland/LandService.java

@@ -261,6 +261,33 @@ public class LandService extends BaseService<Land,Long> {
         return townStatSoilList;
     }
 
+    public List<StatEstimate> getEstimate(String districtCode, String city, String cropType){
+        List<Object[]> res = null;
+        Map<Integer,String> namesMap = null;
+        if(StringUtils.isNotBlank(districtCode)){
+            namesMap = townService.getNames(districtCode);
+            res = landRepository.statTownEstimate(districtCode, cropType);
+            return getEstimate(res, namesMap);
+        }
+        if(StringUtils.isNotBlank(city)){
+            namesMap = districtService.getNames(city);
+            res = landRepository.statDistrictEstimate(city.substring(0,4) + "%", cropType);
+            return getEstimate(res, namesMap);
+        }
+        throw new RuntimeException("district 和 city 至少需要一个");
+    }
+
+    public List<StatEstimate> getEstimate(List<Object[]> res, Map<Integer,String> namesMap){
+        List<StatEstimate> list = new ArrayList<>();
+        for(Object[] objects : res){
+            StatEstimate statEstimate = new StatEstimate();
+            statEstimate.setTownId(Integer.valueOf(objects[0].toString()));
+            statEstimate.setTownName(namesMap.get(statEstimate.getTownId()));
+            statEstimate.setValue(Double.valueOf(objects[1].toString()));
+            list.add(statEstimate);
+        }
+        return list;
+    }
 
 
 

+ 18 - 0
src/main/java/com/sysu/admin/controller/aland/StatEstimate.java

@@ -0,0 +1,18 @@
+package com.sysu.admin.controller.aland;
+
+import com.alibaba.fastjson.annotation.JSONField;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class StatEstimate {
+
+    @JSONField(ordinal = 0)
+    private Integer townId;
+    @JSONField(ordinal = 1)
+    private String townName;
+    @JSONField(ordinal = 2)
+    private Double value;
+
+}