|  | @ -10,11 +10,17 @@ import com.epmet.commons.tools.redis.common.bean.GridInfoCache; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.commons.tools.utils.ConvertUtils; |  |  | import com.epmet.commons.tools.utils.ConvertUtils; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.constant.CustomerGridConstant; |  |  | import com.epmet.constant.CustomerGridConstant; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.dao.IcBuildingDao; |  |  | import com.epmet.dao.IcBuildingDao; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | import com.epmet.dao.IcPropertyManagementDao; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.dto.ImportGeneralDTO; |  |  | import com.epmet.dto.ImportGeneralDTO; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | import com.epmet.dto.NeighborHoodAndManagementDTO; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.dto.form.ImportInfoFormDTO; |  |  | import com.epmet.dto.form.ImportInfoFormDTO; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | import com.epmet.dto.result.ImportResultDTO; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | import com.epmet.entity.IcNeighborHoodPropertyEntity; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | import com.epmet.entity.IcPropertyManagementEntity; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.redis.IcHouseRedis; |  |  | import com.epmet.redis.IcHouseRedis; | 
			
		
	
		
		
			
				
					|  |  | import com.epmet.service.IcNeighborHoodService; |  |  | import com.epmet.service.IcNeighborHoodService; | 
			
		
	
		
		
			
				
					|  |  | import org.apache.commons.lang3.StringUtils; |  |  | import org.apache.commons.lang3.StringUtils; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | import org.springframework.util.CollectionUtils; | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | import java.util.ArrayList; |  |  | import java.util.ArrayList; | 
			
		
	
		
		
			
				
					|  |  | import java.util.Arrays; |  |  | import java.util.Arrays; | 
			
		
	
	
		
		
			
				
					|  | @ -48,12 +54,14 @@ public class ImportNeighborHoodInfoListener extends AnalysisEventListener<Neighb | 
			
		
	
		
		
			
				
					|  |  |     private IcHouseRedis icHouseRedis; |  |  |     private IcHouseRedis icHouseRedis; | 
			
		
	
		
		
			
				
					|  |  |     private IcBuildingDao icBuildingDao; |  |  |     private IcBuildingDao icBuildingDao; | 
			
		
	
		
		
			
				
					|  |  |     private IcNeighborHoodService neighborHoodService; |  |  |     private IcNeighborHoodService neighborHoodService; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     private IcPropertyManagementDao propertyManagementDao; | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |     public ImportNeighborHoodInfoListener(ImportInfoFormDTO formDTO, IcHouseRedis icHouseRedis,IcBuildingDao icBuildingDao,IcNeighborHoodService neighborHoodService){ |  |  |     public ImportNeighborHoodInfoListener(ImportInfoFormDTO formDTO, IcHouseRedis icHouseRedis,IcBuildingDao icBuildingDao,IcNeighborHoodService neighborHoodService, IcPropertyManagementDao propertyManagementDao){ | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |         this.formDTO = formDTO; |  |  |         this.formDTO = formDTO; | 
			
		
	
		
		
			
				
					|  |  |         this.icHouseRedis = icHouseRedis; |  |  |         this.icHouseRedis = icHouseRedis; | 
			
		
	
		
		
			
				
					|  |  |         this.icBuildingDao = icBuildingDao; |  |  |         this.icBuildingDao = icBuildingDao; | 
			
		
	
		
		
			
				
					|  |  |         this.neighborHoodService = neighborHoodService; |  |  |         this.neighborHoodService = neighborHoodService; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         this.propertyManagementDao = propertyManagementDao; | 
			
		
	
		
		
			
				
					|  |  |     } |  |  |     } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  | @ -71,6 +79,80 @@ public class ImportNeighborHoodInfoListener extends AnalysisEventListener<Neighb | 
			
		
	
		
		
			
				
					|  |  |         }else if (formDTO.getOrgType().equals(CustomerGridConstant.AGENCY)){ |  |  |         }else if (formDTO.getOrgType().equals(CustomerGridConstant.AGENCY)){ | 
			
		
	
		
		
			
				
					|  |  |             disposeAgencyNeighborHood(dto); |  |  |             disposeAgencyNeighborHood(dto); | 
			
		
	
		
		
			
				
					|  |  |         } |  |  |         } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         // 数据筛选完毕,当num每满100条,处理一次
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         if (num%NumConstant.ONE_HUNDRED == NumConstant.ZERO){ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             finalDispose(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     public void finalDispose(){ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         if (CollectionUtils.isEmpty(needDisposeList)){ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             return; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         Map<String, Long> groupByAllName = needDisposeList.stream().collect(Collectors.groupingBy( | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 n -> n.getAgencyName() + "_" + n.getGridName() + "_" + n.getNeighborHoodName(), Collectors.counting())); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         groupByAllName.forEach((k,v) -> { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             if (Integer.valueOf(v.toString()).compareTo(1) > 0){ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 for (ImportGeneralDTO r : needDisposeList) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     if (k.equals(r.getAgencyName() + "_" + r.getGridName() + "_" + r.getNeighborHoodName())){ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                         // 集合里重复的
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                         r.setExistStatus(true); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                         nums.add(r.getNum()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         }); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         Map<Boolean, List<ImportGeneralDTO>> groupByStatus = needDisposeList.stream().collect(Collectors.groupingBy(ImportGeneralDTO::getExistStatus)); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         List<ImportGeneralDTO> importGeneralDTOS = groupByStatus.get(false); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         if (!CollectionUtils.isEmpty(importGeneralDTOS)){ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             List<ImportGeneralDTO> importInfo = neighborHoodService.getImportInfo(formDTO, importGeneralDTOS); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             Map<Boolean, List<ImportGeneralDTO>> groupByBuildingExistStatus = importInfo.stream().collect(Collectors.groupingBy(ImportGeneralDTO::getNeighborHoodExistStatus)); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             List<ImportGeneralDTO> existList = groupByBuildingExistStatus.get(true); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             if (!CollectionUtils.isEmpty(existList)){ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 existList.forEach(e -> { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     nums.add(e.getNum()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 }); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             List<ImportGeneralDTO> notExistList = groupByBuildingExistStatus.get(false); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             if (!CollectionUtils.isEmpty(notExistList)){ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 // 物业表插入
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 List<String> propertyNames = notExistList.stream().map(m -> m.getPropertyName()).distinct().collect(Collectors.toList()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 List<String> disposePropertyNames = notExistList.stream().map(m -> m.getPropertyName()).distinct().collect(Collectors.toList()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 List<String> existPropertyNames = propertyManagementDao.selectExistNames(propertyNames); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 disposePropertyNames.removeAll(existPropertyNames); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 List<IcPropertyManagementEntity> propertyManagementEntities = new ArrayList<>(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(disposePropertyNames)){ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     disposePropertyNames.forEach(name -> { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                         IcPropertyManagementEntity e = new IcPropertyManagementEntity(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                         e.setName(name); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                         propertyManagementEntities.add(e); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     }); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 neighborHoodService.insertPropertyManagement(propertyManagementEntities); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 // 小区物业关系表插入
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 List<NeighborHoodAndManagementDTO> neighborHoodAndManagementDTOS = ConvertUtils.sourceToTarget(notExistList, NeighborHoodAndManagementDTO.class); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 List<IcPropertyManagementEntity> propertyManagementInfos = propertyManagementDao.selectIdByName(propertyNames); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 neighborHoodAndManagementDTOS.forEach(n -> propertyManagementInfos.stream().filter(p -> p.getName().equals(n.getPropertyName())) | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                         .forEach(p -> { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                             n.setPropertyId(p.getId()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                             n.setNeighborHoodId(n.getNeighborHoodId()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                         })); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 List<IcNeighborHoodPropertyEntity> icNeighborHoodPropertyEntities = ConvertUtils.sourceToTarget(neighborHoodAndManagementDTOS, IcNeighborHoodPropertyEntity.class); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 neighborHoodService.neighborHoodPropertyInsert(icNeighborHoodPropertyEntities); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         // 清除
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         needDisposeList = new ArrayList<>(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         needInsertList = new ArrayList<>(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         gridName = null; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         agencyName = null; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         gridInfos = null; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         gridInfoDTOs = null; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         neighborHoodInfos = null; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         neighborHoodInfoDTOs = null; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         neighborHoodGeneralDTO = null; | 
			
		
	
		
		
			
				
					|  |  |     } |  |  |     } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     /** |  |  |     /** | 
			
		
	
	
		
		
			
				
					|  | @ -86,7 +168,7 @@ public class ImportNeighborHoodInfoListener extends AnalysisEventListener<Neighb | 
			
		
	
		
		
			
				
					|  |  |             throw new EpmetException("查询网格失败..."); |  |  |             throw new EpmetException("查询网格失败..."); | 
			
		
	
		
		
			
				
					|  |  |         } |  |  |         } | 
			
		
	
		
		
			
				
					|  |  |         //排除不是本网格的 gridName不一样排除,gridName一样但是agencyName不一样也得排除
 |  |  |         //排除不是本网格的 gridName不一样排除,gridName一样但是agencyName不一样也得排除
 | 
			
		
	
		
		
			
				
					
					|  |  |         if (!dto.getGridName().equals(gridName) || (!dto.getAgencyName().equals(gridInfo.getAgencyName()) && dto.getGridName().equals(gridName))){ |  |  |         if (dto.getGridName().compareTo(gridName) != 0 || (!dto.getAgencyName().equals(gridInfo.getAgencyName()) && dto.getGridName().equals(gridName))){ | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |             nums.add(num); |  |  |             nums.add(num); | 
			
		
	
		
		
			
				
					|  |  |         }else { |  |  |         }else { | 
			
		
	
		
		
			
				
					|  |  |             //
 |  |  |             //
 | 
			
		
	
	
		
		
			
				
					|  | @ -186,6 +268,14 @@ public class ImportNeighborHoodInfoListener extends AnalysisEventListener<Neighb | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     @Override |  |  |     @Override | 
			
		
	
		
		
			
				
					|  |  |     public void doAfterAllAnalysed(AnalysisContext context) { |  |  |     public void doAfterAllAnalysed(AnalysisContext context) { | 
			
		
	
		
		
			
				
					
					|  |  | 
 |  |  |         finalDispose(); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  |         // 删除缓存
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         icHouseRedis.delTemporaryCacheGrids(formDTO.getCustomerId(), formDTO.getUserId()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         icHouseRedis.delTemporaryCacheNeighBorHood(formDTO.getCustomerId(), formDTO.getUserId()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         icHouseRedis.delTemporaryCacheBuilding(formDTO.getCustomerId(), formDTO.getUserId()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         icHouseRedis.delTemporaryCacheBuildingUnit(formDTO.getCustomerId(), formDTO.getUserId()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         icHouseRedis.delTemporaryCacheHouses(formDTO.getCustomerId(), formDTO.getUserId()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         // 放结果
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         icHouseRedis.setImportResultDTO(formDTO.getCustomerId(), formDTO.getUserId(), new ImportResultDTO(nums,num)); | 
			
		
	
		
		
			
				
					|  |  |     } |  |  |     } | 
			
		
	
		
		
			
				
					|  |  | } |  |  | } | 
			
		
	
	
		
		
			
				
					|  | 
 |