Administrator 2 lat temu
rodzic
commit
86588b324e

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

@@ -40,6 +40,12 @@ public class ApiLandController extends BaseComponent {
         return R.succ(landService.getCropAreaStat(commonVo.getDate(),commonVo.getDistrict(), commonVo.getCity()));
     }
 
+    @RequestMapping("/soil_stat")
+    public BaseResult getStatSoil(@RequestBody CommonVo commonVo){
+        return R.succ(landService.getStatSoil(commonVo.getDistrict(), commonVo.getCity(), commonVo.getStatType()));
+    }
+
+
     @RequestMapping("/list")
     public PaginationResult list(@RequestBody CommonVo commonVo){
         PaginationVo paginationVo = new PaginationVo(commonVo.getPage(), commonVo.getLimit(), commonVo.getLimit());

+ 10 - 5
src/main/java/com/sysu/admin/controller/aland/Land.java

@@ -159,16 +159,21 @@ crop_sure -- 作物可信度
 
     /**
      * 酸碱度
-     * 4.49 - 5.00
-     * 5.00 - 6.50
-     * 6.50 - 7.50
-     * 7.50 - 8.50
-     * 8.50 - 8.70
      */
     @Column()
     private Double ph;
 
     /**
+     *      * 4.49 - 5.00 0
+     *      * 5.00 - 6.50 1
+     *      * 6.50 - 7.50 2
+     *      * 7.50 - 8.50 3
+     *      * 8.50 - 8.70 4
+     */
+    @Column
+    private Integer phLevel;
+
+    /**
      *c  -- 碳
      */
     @Column()

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

@@ -20,13 +20,7 @@ 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)) " +
-            "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 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")
     List<Land> findAllGeom();

+ 93 - 13
src/main/java/com/sysu/admin/controller/aland/LandService.java

@@ -1,7 +1,5 @@
 package com.sysu.admin.controller.aland;
 
-import com.querydsl.core.types.Predicate;
-import com.querydsl.core.types.dsl.BooleanExpression;
 import com.sysu.admin.controller.city.CityRepository;
 import com.sysu.admin.controller.city.DistrictRepository;
 import com.sysu.admin.controller.city.DistrictService;
@@ -16,10 +14,6 @@ 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;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.domain.Pageable;
-import org.springframework.data.domain.Sort;
 import org.springframework.stereotype.Service;
 
 import java.util.*;
@@ -37,7 +31,14 @@ public class LandService extends BaseService<Land,Long> {
     @Autowired
     CityRepository cityRepository;
 
-    public List<TownStat> getLandAreaStat(Date date, String districtCode, String city){
+    /**
+     * 农业地块统计
+     * @param date
+     * @param districtCode
+     * @param city
+     * @return
+     */
+    public List<TownStatLand> getLandAreaStat(Date date, String districtCode, String city){
         Double percent = getPercent(date);
         List<Object[]> res = null;
         Map<Integer,String> namesMap = null;
@@ -53,20 +54,19 @@ public class LandService extends BaseService<Land,Long> {
         }
         throw new RuntimeException("district 和 city 至少需要一个");
     }
-
-    public List<TownStat> getLandAreaStat(List<Object[]> res ,Double percent, Map<Integer,String> namesMap){
-        List<TownStat> townStatList = new ArrayList<>(30);
-        TownStat sumStat = new TownStat();
+    public List<TownStatLand> getLandAreaStat(List<Object[]> res , Double percent, Map<Integer,String> namesMap){
+        List<TownStatLand> townStatList = new ArrayList<>(30);
+        TownStatLand sumStat = new TownStatLand();
         sumStat.setTownName("汇总信息");
         townStatList.add(sumStat);
         Integer currentTownId = null;
-        TownStat townStat = null;
+        TownStatLand townStat = null;
 
         HashMap<String,LandAreaStat > sumMap = new HashMap<>();
 
         for(Object[] o : res){
             if(currentTownId == null || !o[0].toString().equals(currentTownId.toString())){
-                townStat = new TownStat();
+                townStat = new TownStatLand();
                 townStat.setList(new ArrayList<>());
                 currentTownId = Integer.valueOf(o[0].toString());
                 townStat.setTownId(currentTownId);
@@ -102,6 +102,11 @@ public class LandService extends BaseService<Land,Long> {
         return townStatList;
     }
 
+    /**
+     * 根据月份得到一个1到 1.5的系数
+     * @param date
+     * @return
+     */
     public Double getPercent(Date date){
         if(date == null){
             return 1.0;
@@ -111,6 +116,10 @@ public class LandService extends BaseService<Land,Long> {
         return percent;
     }
 
+    /**
+     * 种植类型统计
+     * @return
+     */
     public List<TownStatCrop> getCropAreaStat(Date date, String districtCode, String city){
         Double percent = getPercent(date);
         List<Object[]> res = null;
@@ -176,6 +185,77 @@ public class LandService extends BaseService<Land,Long> {
         return townStatList;
     }
 
+    public List<TownStatSoil> getStatSoil(String districtCode, String city, String type){
+        List<Object[]> res = null;
+        Map<Integer,String> namesMap = null;
+        String appendWhere = "";
+        String groupField = "";
+        if(districtCode != null){
+            namesMap = townService.getNames(districtCode);
+            appendWhere += " and district_code = '" +districtCode+"'";
+            groupField += "town_id";
+        }else if(city != null){
+            namesMap = districtService.getNames(city);
+            appendWhere += " and district_code like '" + city.substring(0,4) + "%'";
+            groupField += "district_code";
+        }
+        if(namesMap == null){
+            throw new RuntimeException("district 和 city 至少需要一个");
+        }
+        String[] fields = StatItemData.typeMap.get(type);
+        String sql = "select " + groupField + ", "+fields[1]+", sum(area), count(id) from leizhou_land where town_id is not null "+appendWhere+" group by "+groupField+","+fields[1];
+
+        //最大值最小值平均值
+        String sql2 = "select min("+fields[0]+"),avg("+fields[0]+"), max("+fields[0]+") from leizhou_land where town_id is not null" + appendWhere;
+
+        //城市数据的分组统计信息
+        res = mEntityManager.createNativeQuery(sql).getResultList();
+
+        //最小值最大值平均值的统计信息
+        Object[] objects = (Object[])mEntityManager.createNativeQuery(sql2).getSingleResult();
+
+        List<TownStatSoil> list = getStatSoil(res, namesMap, type);
+        TownStatSoil townStatSoilSum = new TownStatSoil();
+        townStatSoilSum.setTownName("汇总信息");
+        List<StatSoil> sumItemList = new ArrayList<>(3);
+        townStatSoilSum.setList(sumItemList);
+        sumItemList.add(new StatSoil("最小值",Double.valueOf(objects[0].toString())));
+        sumItemList.add(new StatSoil("平均值",Double.valueOf(objects[1].toString())));
+        sumItemList.add(new StatSoil("最大值",Double.valueOf(objects[2].toString())));
+        list.set(0, townStatSoilSum);
+        return list;
+    }
+
+    public List<TownStatSoil> getStatSoil(List<Object[]> res, Map<Integer,String> namesMap, String type){
+        List<TownStatSoil> townStatSoilList = new ArrayList<>(30);
+        townStatSoilList.add(null);
+        Integer currentTownId = null;//当前城市id
+        TownStatSoil townStatSoil = null;//当前城市对象
+        for(Object[] o : res){
+            Double area = Double.valueOf(o[2].toString());
+            Integer level = Integer.valueOf(o[1].toString());
+            Integer townId = Integer.valueOf(o[0].toString());
+            if(currentTownId == null || !townId.equals(currentTownId)){
+                townStatSoil = new TownStatSoil();
+                townStatSoil.setList(new ArrayList<>());
+                currentTownId = townId;
+                townStatSoil.setTownId(currentTownId);
+                townStatSoil.setTownName(namesMap.get(currentTownId));
+                townStatSoilList.add(townStatSoil);
+            }
+            StatSoil bean = new StatSoil();
+            bean.setValue(area);
+            bean.setColor(StatItemData.get(type, "Colors")[level]);
+            bean.setName(StatItemData.get(type, "Names")[level]);
+            bean.setValue((area + area / 2) / 1000);
+            townStatSoil.getList().add(bean);
+        }
+        return townStatSoilList;
+    }
+
+
+
+
     public PaginationResult list(Double[] sure,String district, Integer townId, PaginationVo page, String cropType){
         String wkt = null;
         if(townId != null) {

+ 44 - 0
src/main/java/com/sysu/admin/controller/aland/StatItemData.java

@@ -0,0 +1,44 @@
+package com.sysu.admin.controller.aland;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 统计的枚举数据
+ */
+public class StatItemData {
+
+    public static String[] phNames = {"4.49-5.00","5.00-6.50","6.50-7.50","7.50-8.50","8.50-8.70"};
+    public static String[] phColors = {"#FF0101","#FFC902","#A2FF71","#34C2FE","#4141FF"};
+    public static Map<String, String[]> typeMap = new HashMap<String, String[]>(){{
+        put("ph",new String[]{"ph","ph_level"});
+    }};
+    public static String[] tocNames = {};
+    public static String[] tocColors = {};
+    public static String[] cNames = {};
+    public static String[] cColors = {};
+    public static String[] _2nNames = {};
+    public static String[] _2nColors = {};
+    public static String[] pNames = {};
+    public static String[] pColors = {};
+    public static String[] kNames = {};
+    public static String[] kColors = {};
+
+
+    public static String[] get(String fieldStart, String colors){
+        try {
+            return (String[])StatItemData.class.getField(fieldStart+colors).get(null);
+        } catch (IllegalAccessException e) {
+            e.printStackTrace();
+        } catch (NoSuchFieldException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+
+
+
+
+
+}

+ 17 - 0
src/main/java/com/sysu/admin/controller/aland/StatSoil.java

@@ -0,0 +1,17 @@
+package com.sysu.admin.controller.aland;
+
+import lombok.Data;
+
+@Data
+public class StatSoil {
+    public StatSoil(){}
+    public StatSoil(String name, Double value){
+        this.name = name;
+        this.value = value;
+    }
+
+
+    private String name;
+    private Double value;
+    private String color;
+}

+ 1 - 1
src/main/java/com/sysu/admin/controller/aland/TownStat.java → src/main/java/com/sysu/admin/controller/aland/TownStatLand.java

@@ -7,7 +7,7 @@ import java.util.List;
 import java.util.Map;
 
 @Data
-public class TownStat {
+public class TownStatLand {
     @JSONField(ordinal = 0)
     private Integer townId;
     @JSONField(ordinal = 1)

+ 17 - 0
src/main/java/com/sysu/admin/controller/aland/TownStatSoil.java

@@ -0,0 +1,17 @@
+package com.sysu.admin.controller.aland;
+
+import com.alibaba.fastjson.annotation.JSONField;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class TownStatSoil {
+    @JSONField(ordinal = 0)
+    private Integer townId;
+    @JSONField(ordinal = 1)
+    private String townName;
+    @JSONField(ordinal = 2)
+    List<StatSoil> list;
+
+}

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

@@ -24,4 +24,5 @@ public class CommonVo {
     public Integer page = 1;
     public Integer limit = 25;
     public Double[] sure;
+    public String statType;
 }