package com.example.service.impl; import com.example.dao.WzHouseContracDao; import com.example.entity.OtnAreaEntity; import com.example.entity.WzHouseContracEntity; import com.example.service.WzHouseContracService; import com.example.service.WzOtnAreaService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @Service public class WzHouseContracServiceImpl implements WzHouseContracService { @Autowired private WzOtnAreaService otnAreaService; @Autowired private WzHouseContracDao wzHouseContracDao; @Override public List queryList(Map map) { dealMap(map); return wzHouseContracDao.queryList(map); } //综合评价 public List dealHouseContracList(Map map){ dealMap(map); List wzHouseContracEntityList= wzHouseContracDao.queryList(map); Map> cityMap=new HashMap<>(); for (WzHouseContracEntity leaveUseVo : wzHouseContracEntityList) { List list; if(cityMap.get(leaveUseVo.getCity())!=null){ list=cityMap.get(leaveUseVo.getCity()); list.add(leaveUseVo); }else{ list=new ArrayList<>(); list.add(leaveUseVo); } cityMap.put(leaveUseVo.getCity(),list); } List resultList=new ArrayList<>(); List cityList=new ArrayList<>(); double allContractQuantity=0l; double allarrearsQuantity=0l; double allNoTaxContractAmount=0l; double allRentArea=0l; double allUnitPricePerSquareMeter=0l; int cityNum=0; for(Map.Entry> entry:cityMap.entrySet()){ List list=entry.getValue(); if (list.get(0).getCounty().equals("全省")) { continue; } //县的Map集合 Map> countyMap = new HashMap<>(); for (WzHouseContracEntity leaveUseVo : list) { if (leaveUseVo.getCounty() == null || leaveUseVo.getCounty().equals("")) { continue; } if (countyMap.get(leaveUseVo.getCounty()) != null) { list = countyMap.get(leaveUseVo.getCounty()); list.add(leaveUseVo); } else { list = new ArrayList<>(); list.add(leaveUseVo); } countyMap.put(leaveUseVo.getCounty(), list); } double cityContractQuantity=0l; double cityarrearsQuantity=0l; double cityNoTaxContractAmount=0l; double cityRentArea=0l; double cityUnitPricePerSquareMeter=0l; List countyList=new ArrayList<>(); for (Map.Entry> countyEntry : countyMap.entrySet()) { double contractQuantity=0l; double noTaxContractAmount=0l; double rentArea=0l; double unitPricePerSquareMeter=0l; double arrearsQuantity=0l; for (WzHouseContracEntity leaveUseVo : countyEntry.getValue()) { contractQuantity+=leaveUseVo.getContractQuantity(); arrearsQuantity+=leaveUseVo.getArrearsQuantity(); noTaxContractAmount+=leaveUseVo.getNoTaxContractAmount(); rentArea+=leaveUseVo.getRentArea(); unitPricePerSquareMeter+=leaveUseVo.getUnitPricePerSquareMeter(); cityContractQuantity+=leaveUseVo.getContractQuantity(); cityarrearsQuantity+=leaveUseVo.getArrearsQuantity(); cityNoTaxContractAmount+=leaveUseVo.getNoTaxContractAmount(); cityRentArea+=leaveUseVo.getRentArea(); cityUnitPricePerSquareMeter+=leaveUseVo.getUnitPricePerSquareMeter(); allContractQuantity+=leaveUseVo.getContractQuantity(); allarrearsQuantity+=leaveUseVo.getArrearsQuantity(); allNoTaxContractAmount+=leaveUseVo.getNoTaxContractAmount(); allRentArea+=leaveUseVo.getRentArea(); allUnitPricePerSquareMeter+=leaveUseVo.getUnitPricePerSquareMeter(); } double average=0l; if(contractQuantity==0){ average=0; }else{ average=arrearsQuantity/contractQuantity; average=formatDouble(average); } WzHouseContracEntity wzHouseInCustomerEntity = new WzHouseContracEntity(); wzHouseInCustomerEntity.setAverage(formatDouble1(average*100)); wzHouseInCustomerEntity.setContractQuantity(formatDouble(contractQuantity)); wzHouseInCustomerEntity.setCity(countyEntry.getKey()); wzHouseInCustomerEntity.setNoTaxContractAmount(formatDouble(noTaxContractAmount)); wzHouseInCustomerEntity.setRentArea(formatDouble(rentArea)); wzHouseInCustomerEntity.setUnitPricePerSquareMeter(formatDouble(unitPricePerSquareMeter)); countyList.add(wzHouseInCustomerEntity); } List orderCountyList=new ArrayList<>(); try{ //对countList 进行排序 String city=list.get(0).getCity(); if(city.contains("市")){ city=city.split("市")[0]; } OtnAreaEntity area=otnAreaService.queryObject(city); List countyAreaList=otnAreaService.getCityOption(area.getId()); int i=0; for (OtnAreaEntity otnAreaEntity : countyAreaList) { for (WzHouseContracEntity wzCity : countyList) { if(wzCity.getCity().contains(otnAreaEntity.getName())){ i++; wzCity.setFlag(i%2==0); orderCountyList.add(wzCity); } } } }catch (Exception e){ orderCountyList=countyList; e.printStackTrace(); } WzHouseContracEntity wzHouseInCustomerEntity = new WzHouseContracEntity(); wzHouseInCustomerEntity.setCity(entry.getKey()); wzHouseInCustomerEntity.setContractQuantity(formatDouble(cityContractQuantity)); wzHouseInCustomerEntity.setNoTaxContractAmount(formatDouble(cityNoTaxContractAmount)); wzHouseInCustomerEntity.setRentArea(formatDouble(cityRentArea)); double num=cityUnitPricePerSquareMeter/countyMap.size(); cityNum+=countyMap.size(); wzHouseInCustomerEntity.setUnitPricePerSquareMeter(formatDouble(num)); //出租欠费率 double average=0l; if(cityContractQuantity==0){ average=0; }else{ average=cityarrearsQuantity/cityContractQuantity; average=formatDouble(average); } wzHouseInCustomerEntity.setAverage(formatDouble1(average*100)); wzHouseInCustomerEntity.setChildren(orderCountyList); cityList.add(wzHouseInCustomerEntity); } //对cityList 进行排序 List areaList=otnAreaService.getCityOption("018"); List orderList=new ArrayList<>(); int i=0; for (OtnAreaEntity otnAreaEntity : areaList) { for (WzHouseContracEntity wzCity : cityList) { if(wzCity.getCity().contains(otnAreaEntity.getName())){ wzCity.setFlag(i%2==0); orderList.add(wzCity); i++; } } } WzHouseContracEntity province=new WzHouseContracEntity(); //出租欠费率 double average=0l; if(allContractQuantity==0){ average=0; }else{ average=allarrearsQuantity/allContractQuantity; average=formatDouble(average); } province.setAverage(formatDouble1(average*100)); province.setCity("全省"); province.setContractQuantity(formatDouble(allContractQuantity)); province.setNoTaxContractAmount(formatDouble(allNoTaxContractAmount)); province.setRentArea(formatDouble(allRentArea)); if(cityList.size()!=0){ province.setUnitPricePerSquareMeter(formatDouble(allUnitPricePerSquareMeter/cityNum )); } province.setChildren(orderList); if(orderList.size()>0){ resultList.add(province); } return resultList; } @Override public int queryTotal(Map map) { dealMap(map); return wzHouseContracDao.queryTotal(map); } public void dealMap(Map map){ if(map.get("city")!=null&&!map.get("city").toString().equals("全省")&&!map.get("city").toString().equals("")){ OtnAreaEntity city = otnAreaService.queryObjectById(map.get("city").toString()); map.put("city",city.getName()); } if(map.get("city")!=null&&map.get("city").toString().equals("全省")){ map.remove("city"); } if(map.get("city")!=null&&map.get("city").toString().equals("")){ map.remove("city"); } if(map.get("county")!=null&&!map.get("county").toString().equals("区县")&&!map.get("county").toString().equals("")){ OtnAreaEntity city = otnAreaService.queryObjectById(map.get("county").toString()); map.put("county",city.getName()); } if(map.get("county")!=null&&map.get("county").toString().equals("区县")){ map.remove("county"); } if(map.get("county")!=null&&map.get("county").toString().equals("")){ map.remove("county"); } if(map.get("statisticalMonth")!=null&&!map.get("statisticalMonth").toString().equals("")&&!map.get("statisticalMonth").toString().equals("账期")){ map.put("statisticalMonth",Integer.valueOf(map.get("statisticalMonth").toString())); }else{ map.remove("statisticalMonth"); } } public double formatDouble(double num){ double avera=0l; try{ DecimalFormat format2 = new DecimalFormat("#.0000"); String str2 = format2.format(num); avera = Double.parseDouble(str2); }catch (Exception e){ e.printStackTrace(); } return avera; } public double formatDouble1(double num) { if (num == 0) return 0; DecimalFormat format2 = new DecimalFormat("#.00"); String str2 = format2.format(num); double avera = Double.parseDouble(str2); return avera; } }