|
@@ -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) {
|