|
@@ -3,7 +3,7 @@ package com.sysu.admin.controller.aland;
|
|
|
import com.querydsl.core.types.Predicate;
|
|
|
import com.sysu.admin.controller.city.CityRepository;
|
|
|
import com.sysu.admin.controller.city.DistrictRepository;
|
|
|
-import com.sysu.admin.controller.city.TownRepository;
|
|
|
+import com.sysu.admin.controller.city.DistrictService;
|
|
|
import com.sysu.admin.controller.city.TownService;
|
|
|
import com.sysu.admin.support.base.BaseService;
|
|
|
import com.sysu.admin.utils.MySimpleDateFormat;
|
|
@@ -25,21 +25,38 @@ public class LandService extends BaseService<Land,Long> {
|
|
|
@Autowired
|
|
|
TownService townService;
|
|
|
@Autowired
|
|
|
+ DistrictService districtService;
|
|
|
+ @Autowired
|
|
|
DistrictRepository districtRepository;
|
|
|
@Autowired
|
|
|
CityRepository cityRepository;
|
|
|
|
|
|
-
|
|
|
- public List<TownStat> getLandAreaStat(Date date, String districtCode){
|
|
|
+ public List<TownStat> getLandAreaStat(Date date, String districtCode, String city){
|
|
|
Double percent = getPercent(date);
|
|
|
- List<Object[]> res = landRepository.statParcelTypeAll();
|
|
|
+ List<Object[]> res = null;
|
|
|
+ Map<Integer,String> namesMap = null;
|
|
|
+ if(districtCode != null){
|
|
|
+ namesMap = townService.getNames(districtCode);
|
|
|
+ res = landRepository.statTownParcelTypeAll(districtCode);
|
|
|
+ return getLandAreaStat(res,percent,namesMap);
|
|
|
+ }
|
|
|
+ if(city != null){
|
|
|
+ namesMap = districtService.getNames(city);
|
|
|
+ res = landRepository.statDistrictParcelTypeAll(city.substring(0,4) + "%");
|
|
|
+ return getLandAreaStat(res,percent,namesMap);
|
|
|
+ }
|
|
|
+ throw new RuntimeException("district 和 city 至少需要一个");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public List<TownStat> getLandAreaStat(List<Object[]> res ,Double percent, Map<Integer,String> namesMap){
|
|
|
List<TownStat> townStatList = new ArrayList<>(30);
|
|
|
- Integer currentTownId = null;
|
|
|
- TownStat townStat = null;
|
|
|
- Map<Integer,String> namesMap = townService.getNames(districtCode);
|
|
|
TownStat sumStat = new TownStat();
|
|
|
sumStat.setTownName("汇总信息");
|
|
|
townStatList.add(sumStat);
|
|
|
+ Integer currentTownId = null;
|
|
|
+ TownStat townStat = null;
|
|
|
+
|
|
|
HashMap<String,LandAreaStat > sumMap = new HashMap<>();
|
|
|
|
|
|
for(Object[] o : res){
|
|
@@ -90,21 +107,38 @@ public class LandService extends BaseService<Land,Long> {
|
|
|
return percent;
|
|
|
}
|
|
|
|
|
|
- public List<TownStatCrop> getCropAreaStat(Date date, String districtCode) {
|
|
|
+
|
|
|
+
|
|
|
+ public List<TownStatCrop> getCropAreaStat(Date date, String districtCode, String city){
|
|
|
Double percent = getPercent(date);
|
|
|
- List<Object[]> res = landRepository.statParcelTypeAll();
|
|
|
- List<TownStat> townStatList = new ArrayList<>(30);
|
|
|
- Integer currentTownId = null;
|
|
|
- TownStat townStat = null;
|
|
|
- Map<Integer,String> namesMap = townService.getNames(districtCode);
|
|
|
- TownStat sumStat = new TownStat();
|
|
|
+ List<Object[]> res = null;
|
|
|
+ Map<Integer,String> namesMap = null;
|
|
|
+ if(districtCode != null){
|
|
|
+ namesMap = townService.getNames(districtCode);
|
|
|
+ res = landRepository.statTownCropTypeAll(districtCode);
|
|
|
+ return getCropAreaStat(res,percent,namesMap);
|
|
|
+ }
|
|
|
+ if(city != null){
|
|
|
+ namesMap = districtService.getNames(city);
|
|
|
+ res = landRepository.statDistrictCropTypeAll(city.substring(0,4) + "%");
|
|
|
+ return getCropAreaStat(res,percent,namesMap);
|
|
|
+ }
|
|
|
+ throw new RuntimeException("district 和 city 至少需要一个");
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<TownStatCrop> getCropAreaStat(List<Object[]> res ,Double percent, Map<Integer,String> namesMap){
|
|
|
+ List<TownStatCrop> townStatList = new ArrayList<>(30);
|
|
|
+ TownStatCrop sumStat = new TownStatCrop();
|
|
|
sumStat.setTownName("汇总信息");
|
|
|
-// sumStat.setSumMap(new HashMap<>());
|
|
|
townStatList.add(sumStat);
|
|
|
+ Integer currentTownId = null;
|
|
|
+ TownStatCrop townStat = null;
|
|
|
+
|
|
|
+ HashMap<String,CropAreaStat > sumMap = new HashMap<>();
|
|
|
|
|
|
for(Object[] o : res){
|
|
|
if(currentTownId == null || !o[0].toString().equals(currentTownId.toString())){
|
|
|
- townStat = new TownStat();
|
|
|
+ townStat = new TownStatCrop();
|
|
|
townStat.setList(new ArrayList<>());
|
|
|
currentTownId = Integer.valueOf(o[0].toString());
|
|
|
townStat.setTownId(currentTownId);
|
|
@@ -112,28 +146,36 @@ public class LandService extends BaseService<Land,Long> {
|
|
|
townStatList.add(townStat);
|
|
|
}
|
|
|
|
|
|
- LandAreaStat bean = new LandAreaStat();
|
|
|
- bean.setParcelType(Integer.valueOf(o[1].toString()));
|
|
|
- bean.setColor(LandAreaStat.castColor(bean.getParcelType()));
|
|
|
- bean.setName(LandAreaStat.castName(bean.getParcelType()));
|
|
|
+ CropAreaStat bean = new CropAreaStat();
|
|
|
+ bean.setCropType(o[1].toString());
|
|
|
+ bean.setColor(CropAreaStat.castColor(bean.getCropType()));
|
|
|
+ bean.setName(CropAreaStat.castName(bean.getCropType()));
|
|
|
Double area = (Double)o[2];
|
|
|
bean.setArea((area + area / 2) / 1000);
|
|
|
bean.setArea(bean.getArea() * percent);
|
|
|
bean.setCount(Integer.valueOf(o[3].toString()));
|
|
|
townStat.getList().add(bean);
|
|
|
//汇总信息
|
|
|
-// LandAreaStat sum = sumStat.getSumMap().get(bean.getParcelType());
|
|
|
-// if(sum == null){
|
|
|
-// sum = new LandAreaStat(bean.getParcelType(), bean.getName(), bean.getColor());
|
|
|
-// sumStat.getSumMap().put(bean.getParcelType().toString(), sum);
|
|
|
-// }
|
|
|
-// sum.setArea(sum.getArea() + bean.getArea());
|
|
|
-// sum.setCount(sum.getCount() + bean.getCount());
|
|
|
+ CropAreaStat sum = sumMap.get(bean.getCropType());
|
|
|
+ if(sum == null){
|
|
|
+ sum = new CropAreaStat(bean.getCropType(), bean.getName(), bean.getColor());
|
|
|
+ sumMap.put(bean.getCropType(), sum);
|
|
|
+ }
|
|
|
+ sum.setArea(sum.getArea() + bean.getArea());
|
|
|
+ sum.setCount(sum.getCount() + bean.getCount());
|
|
|
}
|
|
|
|
|
|
- return null;
|
|
|
+ //组装汇总List
|
|
|
+ CropAreaStat[] sumArrays = new CropAreaStat[sumMap.size()];
|
|
|
+ for(String key : sumMap.keySet()){
|
|
|
+ sumArrays[CropAreaStat.getCropTypeIndex(key)] = sumMap.get(key);
|
|
|
+ }
|
|
|
+ sumStat.setList(Arrays.asList(sumArrays));
|
|
|
+ return townStatList;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
public List<Land> list(String district, Integer townId, Integer limit, String cropType){
|
|
|
limit = limit == null ? 50 : limit;
|
|
|
String wkt = null;
|