package com.example.controller.gdc; import com.example.config.annotation.IgnoreAuth; import com.example.pojo.gdc.OtnAreaEntity; import com.example.pojo.gdc.WzHouseArrearsManageEntity; import com.example.service.gdc.WzHouseArrearsManageService; import com.example.service.gdc.WzOtnAreaService; import com.example.utils.PageMap; import com.example.utils.PageUtils; import com.example.utils.Query; import com.example.utils.R; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 房屋出租(合同管理) */ @RestController @RequestMapping("/house-car/house/dist/api/wzHouseArrearsManage") public class WzHouseArrearsManageController { @Autowired private WzOtnAreaService otnAreaService; @Autowired private WzHouseArrearsManageService wzHouseArrearsManageService; @RequestMapping("/list") @IgnoreAuth public R list(@RequestBody PageMap pageMap) { //查询列表数据 Query query = new Query(pageMap); List list = wzHouseArrearsManageService.queryList(query); int total = wzHouseArrearsManageService.queryTotal(query); PageUtils pageUtil = new PageUtils(list, total, query.getLimit(), query.getPage()); return R.ok().put("page", pageUtil); } @RequestMapping("/echartList") @IgnoreAuth public R echartList(@RequestBody PageMap pageMap) { //查询列表数据 Query query = new Query(pageMap); List wzHouseContracEntityList = wzHouseArrearsManageService.queryList(query); WzHouseArrearsManageEntity province=new WzHouseArrearsManageEntity(); province.setCity("全省"); Map> map=new HashMap<>(); for (WzHouseArrearsManageEntity leaveUseVo : wzHouseContracEntityList) { List list; if(map.get(leaveUseVo.getCity())!=null){ list=map.get(leaveUseVo.getCity()); list.add(leaveUseVo); }else{ list=new ArrayList<>(); list.add(leaveUseVo); } map.put(leaveUseVo.getCity(),list); } List resultList=new ArrayList<>(); List cityList=new ArrayList<>(); double allAccumulateArrears=0l; double allmoreThanThreeMonths=0l; double allmoreThanOneYears=0l; double allyearCumulativeNewAdditions=0l; double allyearCumulativeWithdrawal=0l; for(Map.Entry> entry:map.entrySet()){ List list=entry.getValue(); //县的Map集合 Map> countyMap=new HashMap<>(); for (WzHouseArrearsManageEntity 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 cityaccumulateArrears=0l; double citymoreThanThreeMonths=0l; double citymoreThanOneYears=0l; double cityyearCumulativeNewAdditions=0l; double cityyearCumulativeWithdrawal=0l; List countyList=new ArrayList<>(); for (Map.Entry> countyEntry : countyMap.entrySet()) { double accumulateArrears=0l; double moreThanThreeMonths=0l; double moreThanOneYears=0l; double yearCumulativeNewAdditions=0l; double yearCumulativeWithdrawal=0l; for (WzHouseArrearsManageEntity leaveUseVo : countyEntry.getValue()) { if(leaveUseVo.getAccumulateArrears()!=null){ accumulateArrears+=leaveUseVo.getAccumulateArrears(); cityaccumulateArrears+=leaveUseVo.getAccumulateArrears(); allAccumulateArrears+=leaveUseVo.getAccumulateArrears(); } if(leaveUseVo.getMoreThanThreeMonths()!=null){ moreThanThreeMonths+=leaveUseVo.getMoreThanThreeMonths(); citymoreThanThreeMonths+=leaveUseVo.getMoreThanThreeMonths(); allmoreThanThreeMonths+=leaveUseVo.getMoreThanThreeMonths(); } if(leaveUseVo.getMoreThanOneYears()!=null){ moreThanOneYears+=leaveUseVo.getMoreThanOneYears(); citymoreThanOneYears+=leaveUseVo.getMoreThanOneYears(); allmoreThanOneYears+=leaveUseVo.getMoreThanOneYears(); } if(leaveUseVo.getYearCumulativeNewAdditions()!=null){ yearCumulativeNewAdditions+=leaveUseVo.getYearCumulativeNewAdditions(); cityyearCumulativeNewAdditions+=leaveUseVo.getYearCumulativeNewAdditions(); allyearCumulativeNewAdditions+=leaveUseVo.getYearCumulativeNewAdditions(); } if(leaveUseVo.getYearCumulativeWithdrawal()!=null){ yearCumulativeWithdrawal+=leaveUseVo.getYearCumulativeWithdrawal(); cityyearCumulativeWithdrawal+=leaveUseVo.getYearCumulativeWithdrawal(); allyearCumulativeWithdrawal+=leaveUseVo.getYearCumulativeWithdrawal(); } } WzHouseArrearsManageEntity countyEntity=new WzHouseArrearsManageEntity(); countyEntity.setAccumulateArrears(formatDouble(accumulateArrears)); countyEntity.setYearCumulativeNewAdditions(formatDouble(yearCumulativeNewAdditions)); countyEntity.setYearCumulativeWithdrawal(formatDouble(yearCumulativeWithdrawal)); countyEntity.setMoreThanOneYears(formatDouble(moreThanOneYears)); countyEntity.setMoreThanThreeMonths(formatDouble(moreThanThreeMonths)); countyEntity.setCity(countyEntry.getValue().get(0).getCounty()); countyList.add(countyEntity); } 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 (WzHouseArrearsManageEntity wzCity : countyList) { if(wzCity.getCity().contains(otnAreaEntity.getName())){ i++; wzCity.setFlag(i%2==0); orderCountyList.add(wzCity); } } } }catch (Exception e){ orderCountyList=countyList; e.printStackTrace(); } WzHouseArrearsManageEntity cityEntity=new WzHouseArrearsManageEntity(); cityEntity.setAccumulateArrears(formatDouble(cityaccumulateArrears)); cityEntity.setYearCumulativeNewAdditions(formatDouble(cityyearCumulativeNewAdditions)); cityEntity.setYearCumulativeWithdrawal(formatDouble(cityyearCumulativeWithdrawal)); cityEntity.setMoreThanOneYears(formatDouble(citymoreThanOneYears)); cityEntity.setMoreThanThreeMonths(formatDouble(citymoreThanThreeMonths)); cityEntity.setCity(list.get(0).getCity()); cityEntity.setChildren(orderCountyList); cityList.add(cityEntity); } //对cityList 进行排序 List areaList=otnAreaService.getCityOption("018"); List orderList=new ArrayList<>(); int i=0; for (OtnAreaEntity otnAreaEntity : areaList) { for (WzHouseArrearsManageEntity wzCity : cityList) { if(wzCity.getCity().contains(otnAreaEntity.getName())){ wzCity.setFlag(i%2==0); i++; orderList.add(wzCity); } } } province.setAccumulateArrears(formatDouble(allAccumulateArrears)); province.setMoreThanOneYears(formatDouble(allmoreThanOneYears)); province.setMoreThanThreeMonths(formatDouble(allmoreThanThreeMonths)); province.setYearCumulativeNewAdditions(formatDouble(allyearCumulativeNewAdditions)); province.setYearCumulativeWithdrawal(formatDouble(allyearCumulativeWithdrawal)); province.setChildren(orderList); if(orderList.size()>0){ resultList.add(province); } PageUtils pageUtil = new PageUtils(resultList, 0, query.getLimit(), query.getPage()); return R.ok().put("page", pageUtil); } public double formatDouble(double num){ double avera=0l; try{ DecimalFormat format2 = new DecimalFormat("#.00"); String str2 = format2.format(num); avera = Double.parseDouble(str2); }catch (Exception e){ e.printStackTrace(); } return avera; } }