123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- 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<WzHouseContracEntity> queryList(Map<String, Object> map) {
- dealMap(map);
- return wzHouseContracDao.queryList(map);
- }
- //综合评价
- public List<WzHouseContracEntity> dealHouseContracList(Map<String, Object> map){
- dealMap(map);
- List<WzHouseContracEntity> wzHouseContracEntityList= wzHouseContracDao.queryList(map);
- Map<String,List<WzHouseContracEntity>> cityMap=new HashMap<>();
- for (WzHouseContracEntity leaveUseVo : wzHouseContracEntityList) {
- List<WzHouseContracEntity> 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<WzHouseContracEntity> resultList=new ArrayList<>();
- List<WzHouseContracEntity> cityList=new ArrayList<>();
- double allContractQuantity=0l;
- double allarrearsQuantity=0l;
- double allNoTaxContractAmount=0l;
- double allRentArea=0l;
- double allUnitPricePerSquareMeter=0l;
- int cityNum=0;
- for(Map.Entry<String,List<WzHouseContracEntity>> entry:cityMap.entrySet()){
- List<WzHouseContracEntity> list=entry.getValue();
- if (list.get(0).getCounty().equals("全省")) {
- continue;
- }
- //县的Map集合
- Map<String, List<WzHouseContracEntity>> 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<WzHouseContracEntity> countyList=new ArrayList<>();
- for (Map.Entry<String, List<WzHouseContracEntity>> 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<WzHouseContracEntity> orderCountyList=new ArrayList<>();
- try{
- //对countList 进行排序
- String city=list.get(0).getCity();
- if(city.contains("市")){
- city=city.split("市")[0];
- }
- OtnAreaEntity area=otnAreaService.queryObject(city);
- List<OtnAreaEntity> 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<OtnAreaEntity> areaList=otnAreaService.getCityOption("018");
- List<WzHouseContracEntity> 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<String, Object> map) {
- dealMap(map);
- return wzHouseContracDao.queryTotal(map);
- }
- public void dealMap(Map<String, Object> 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;
- }
- }
|