Administrator il y a 2 ans
Parent
commit
199728f086

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

@@ -110,6 +110,11 @@ public class ApiLandController extends BaseComponent {
         return result;
     }
 
+    @RequestMapping("/allLandStat")
+    public BaseResult allLandStat(@RequestBody CommonVo commonVo){
+        return R.succ(landService.allLandStat(commonVo));
+    }
+
     @RequestMapping("/info")
     public BaseResult info(@RequestBody CommonVo commonVo){
         Land bean = null;

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

@@ -0,0 +1,27 @@
+package com.sysu.admin.controller.aland;
+
+import lombok.Data;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
+@Data
+@Entity
+public class AllLandStatVo {
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    private Long all_count;
+    private Double sum_area;
+    private Double zong_chan;
+    private Double avg_toc;
+    private Double avg_ph;
+    private Double avg_c;
+    private Double avg_2n;
+    private Double avg_p;
+    private Double avg_k;
+
+
+}

+ 19 - 1
src/main/java/com/sysu/admin/controller/aland/LandService.java

@@ -15,6 +15,7 @@ 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.base.result.BaseResult;
 import com.xiesx.fastboot.core.jpa.JpaPlusRepository;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.ObjectUtils;
@@ -301,6 +302,24 @@ public class LandService extends BaseService<Land,Long> {
 
 
 
+    public AllLandStatVo allLandStat(CommonVo commonVo){
+        String wkt = null;
+        if(commonVo.getTown() != null) {
+            wkt = townService.findWktById(commonVo.getTown());
+        }else if(StringUtils.isNotBlank(commonVo.getDistrict())) {
+            wkt = districtRepository.findWktByCode(commonVo.getDistrict());
+        }
+        StringBuffer sql = new StringBuffer(100);
+        String col = "count(1) as all_count, sum(area) as sum_area, sum(dan_chan * area) as zong_chan ,avg(toc) as avg_toc,avg(ph) as avg_ph,avg(c) as avg_c,avg(_2n) as avg_2n,avg(p) as avg_p,avg(k) as avg_k";
+        sql.append("select "+col+" from  leizhou_land where 1=1");
+        StringBuffer append = appendWhere(commonVo, wkt);
+        sql.append(append);
+        System.out.println(sql.toString());
+        AllLandStatVo allLandStatVo = (AllLandStatVo)mEntityManager.createNativeQuery(sql.toString(), AllLandStatVo.class).getSingleResult();
+        return allLandStatVo;
+    }
+
+
     public PaginationResult list(CommonVo commonVo,PaginationVo page){
         String wkt = null;
         if(commonVo.getTown() != null) {
@@ -315,7 +334,6 @@ public class LandService extends BaseService<Land,Long> {
         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");
-
         StringBuffer append = appendWhere(commonVo, wkt);
         sql.append(append);
         countSql.append(append);