|
|
@ -14,8 +14,17 @@ import com.epmet.constant.CustomerGridConstant; |
|
|
|
import com.epmet.dao.IcBuildingDao; |
|
|
|
import com.epmet.dto.ImportHouseGeneralDTO; |
|
|
|
import com.epmet.dto.form.ImportInfoFormDTO; |
|
|
|
import com.epmet.entity.IcHouseEntity; |
|
|
|
import com.epmet.enums.HousePurposeEnums; |
|
|
|
import com.epmet.enums.HouseRentFlagEnums; |
|
|
|
import com.epmet.enums.HouseTypeEnums; |
|
|
|
import com.epmet.excel.IcNeighborHoodExcel; |
|
|
|
import com.epmet.redis.IcHouseRedis; |
|
|
|
import com.epmet.service.HouseService; |
|
|
|
import com.epmet.service.IcHouseService; |
|
|
|
import com.epmet.service.IcNeighborHoodService; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
import java.util.*; |
|
|
@ -34,8 +43,6 @@ public class ImportHouseInfoListener extends AnalysisEventListener<HouseInfoMode |
|
|
|
List<ImportHouseGeneralDTO> needDisposeList = new ArrayList<>(); |
|
|
|
List<ImportHouseGeneralDTO> needInsertList = new ArrayList<>(); |
|
|
|
|
|
|
|
String buildingName = null; |
|
|
|
String neighborHoodName = null; |
|
|
|
String gridName = null; |
|
|
|
String agencyName = null; |
|
|
|
|
|
|
@ -46,17 +53,22 @@ public class ImportHouseInfoListener extends AnalysisEventListener<HouseInfoMode |
|
|
|
ImportHouseGeneralDTO neighborHoodGeneralDTO = null; |
|
|
|
Map<String, Object> buildingInfos = null; |
|
|
|
List<ImportHouseGeneralDTO> buildingInfoDTOs = null; |
|
|
|
ImportHouseGeneralDTO buildingGeneralDTO = null; |
|
|
|
Map<String, Object> buildingUnitInfos = null; |
|
|
|
List<ImportHouseGeneralDTO> buildingUnitInfoDTOs = null; |
|
|
|
|
|
|
|
private ImportInfoFormDTO formDTO; |
|
|
|
private IcBuildingDao icBuildingDao; |
|
|
|
private IcHouseRedis icHouseRedis; |
|
|
|
private IcNeighborHoodService neighborHoodService; |
|
|
|
private IcHouseService icHouseService; |
|
|
|
|
|
|
|
public ImportHouseInfoListener(ImportInfoFormDTO formDTO,IcBuildingDao icBuildingDao, IcHouseRedis icHouseRedis){ |
|
|
|
public ImportHouseInfoListener(ImportInfoFormDTO formDTO,IcBuildingDao icBuildingDao, IcHouseRedis icHouseRedis,IcNeighborHoodService neighborHoodService, IcHouseService icHouseService){ |
|
|
|
this.formDTO = formDTO; |
|
|
|
this.icBuildingDao = icBuildingDao; |
|
|
|
this.icHouseRedis = icHouseRedis; |
|
|
|
this.neighborHoodService = neighborHoodService; |
|
|
|
this.icHouseService = icHouseService; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -67,6 +79,11 @@ public class ImportHouseInfoListener extends AnalysisEventListener<HouseInfoMode |
|
|
|
num = num + NumConstant.ONE; |
|
|
|
ImportHouseGeneralDTO dto = ConvertUtils.sourceToTarget(data, ImportHouseGeneralDTO.class); |
|
|
|
dto.setNum(num); |
|
|
|
dto.setCustomerId(formDTO.getCustomerId()); |
|
|
|
dto.setHouseType(HouseTypeEnums.getKeyByValue(dto.getHouseType())); |
|
|
|
dto.setPurpose(HousePurposeEnums.getKeyByValue(dto.getPurpose())); |
|
|
|
dto.setRentFlag(HouseRentFlagEnums.getCodeByName(dto.getRentFlagString())); |
|
|
|
dto.setHouseName(dto.getBuildingName()+"-"+dto.getBuildingUnit()+"-"+dto.getDoorName()); |
|
|
|
if (formDTO.getOrgType().equals(CustomerGridConstant.BUILDING)){ |
|
|
|
disposeBuildingHouse(dto); |
|
|
|
}else if (formDTO.getOrgType().equals(CustomerGridConstant.NEIGHBORHOOD)){ |
|
|
@ -76,6 +93,58 @@ public class ImportHouseInfoListener extends AnalysisEventListener<HouseInfoMode |
|
|
|
}else if (formDTO.getOrgType().equals(CustomerGridConstant.AGENCY)){ |
|
|
|
disposeAgencyHouse(dto); |
|
|
|
} |
|
|
|
// 数据筛选完毕,当num每满100条,处理一次
|
|
|
|
if (num%NumConstant.ONE_HUNDRED == NumConstant.ZERO){ |
|
|
|
finalDispose(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void finalDispose(){ |
|
|
|
List<ImportHouseGeneralDTO> importInfo = neighborHoodService.getImportInfo(formDTO, needDisposeList); |
|
|
|
needInsertList.addAll(importInfo); |
|
|
|
Map<String, Long> collect = needInsertList.stream().collect(Collectors.groupingBy(n -> n.getBuildingUnitId() + "_" + n.getDoorName(), Collectors.counting())); |
|
|
|
collect.forEach((k,v) -> { |
|
|
|
if (Integer.valueOf(v.toString()).compareTo(1) > 0){ |
|
|
|
for (ImportHouseGeneralDTO r : needInsertList) { |
|
|
|
if (k.equals(r.getBuildingUnitId()+"_"+r.getDoorName())){ |
|
|
|
// 集合里重复的
|
|
|
|
r.setExistStatus(true); |
|
|
|
nums.add(r.getNum()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
// 根据单元ID_doorName查询已存在的
|
|
|
|
List<String> ids = needInsertList.stream().map(m -> m.getBuildingUnitId() + "_" + m.getDoorName()).distinct().collect(Collectors.toList()); |
|
|
|
List<String> existHouses = icBuildingDao.selectExistHouse(ids); |
|
|
|
existHouses.forEach(e -> { |
|
|
|
for (ImportHouseGeneralDTO n : needInsertList) { |
|
|
|
if ((n.getBuildingUnitId()+"_"+n.getDoorName()).equals(e)){ |
|
|
|
// 库里存在的
|
|
|
|
n.setExistStatus(true); |
|
|
|
nums.add(n.getNum()); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
// 根据存在状态分组
|
|
|
|
Map<Boolean, List<ImportHouseGeneralDTO>> groupByExistStatus = needInsertList.stream().collect(Collectors.groupingBy(ImportHouseGeneralDTO::getExistStatus)); |
|
|
|
List<ImportHouseGeneralDTO> importHouseGeneralDTOS = groupByExistStatus.get(false); |
|
|
|
houseInsert(importHouseGeneralDTOS); |
|
|
|
// 清除
|
|
|
|
needDisposeList = new ArrayList<>(); |
|
|
|
needInsertList = new ArrayList<>(); |
|
|
|
gridName = null; |
|
|
|
agencyName = null; |
|
|
|
gridInfos = null; |
|
|
|
gridInfoDTOs = null; |
|
|
|
neighborHoodInfos = null; |
|
|
|
neighborHoodInfoDTOs = null; |
|
|
|
neighborHoodGeneralDTO = null; |
|
|
|
buildingInfos = null; |
|
|
|
buildingInfoDTOs = null; |
|
|
|
buildingGeneralDTO = null; |
|
|
|
buildingUnitInfos = null; |
|
|
|
buildingUnitInfoDTOs = null; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -85,12 +154,46 @@ public class ImportHouseInfoListener extends AnalysisEventListener<HouseInfoMode |
|
|
|
* @date 2022/2/14 3:23 下午 |
|
|
|
*/ |
|
|
|
public void disposeBuildingHouse(ImportHouseGeneralDTO dto){ |
|
|
|
buildingName = null == buildingName ? icBuildingDao.selectBuildingNameById(formDTO.getOrgId()) : buildingName; |
|
|
|
buildingGeneralDTO = null == buildingGeneralDTO ? icBuildingDao.selectBuildingById(formDTO.getOrgId()) : buildingGeneralDTO; |
|
|
|
// 排除不是本楼的
|
|
|
|
if (!dto.getBuildingName().equals(buildingName)){ |
|
|
|
if (!dto.getBuildingName().equals(buildingGeneralDTO.getBuildingName())){ |
|
|
|
nums.add(num); |
|
|
|
}else { |
|
|
|
|
|
|
|
GridInfoCache gridInfo = CustomerOrgRedis.getGridInfo(buildingGeneralDTO.getGridId()); |
|
|
|
if (null == gridInfo){ |
|
|
|
throw new EpmetException("查询网格失败..."); |
|
|
|
} |
|
|
|
// 排除 1、小区名不一样&&楼栋名一样 2、网格名不一样&&小区名一样&&楼名一样 3、组织名不一样&&网格名一样&&小区名一样&&楼名一样
|
|
|
|
if ((!buildingGeneralDTO.getNeighborHoodName().equals(dto.getNeighborHoodName()) && buildingGeneralDTO.getBuildingName().equals(dto.getBuildingName())) |
|
|
|
|| (!gridInfo.getGridName().equals(dto.getGridName())&&buildingGeneralDTO.getNeighborHoodName().equals(dto.getNeighborHoodName()) && buildingGeneralDTO.getBuildingName().equals(dto.getBuildingName())) |
|
|
|
|| (!gridInfo.getAgencyName().equals(dto.getAgencyName())&&gridInfo.getGridName().equals(dto.getGridName())&&buildingGeneralDTO.getNeighborHoodName().equals(dto.getNeighborHoodName()) && buildingGeneralDTO.getBuildingName().equals(dto.getBuildingName()))){ |
|
|
|
nums.add(num); |
|
|
|
return; |
|
|
|
} |
|
|
|
dto.setBuildingId(formDTO.getOrgId()); |
|
|
|
dto.setNeighborHoodId(buildingGeneralDTO.getNeighborHoodId()); |
|
|
|
dto.setGridId(buildingGeneralDTO.getGridId()); |
|
|
|
dto.setAgencyId(buildingGeneralDTO.getAgencyId()); |
|
|
|
AgencyInfoCache agencyInfo = CustomerOrgRedis.getAgencyInfo(dto.getAgencyId()); |
|
|
|
if (null == agencyInfo){ |
|
|
|
throw new EpmetException("查询组织信息失败..."); |
|
|
|
} |
|
|
|
dto.setPid(agencyInfo.getPid()); |
|
|
|
dto.setPids(agencyInfo.getPids()); |
|
|
|
dto.setType(buildingGeneralDTO.getType()); |
|
|
|
dto.setTotalHouseNum(buildingGeneralDTO.getTotalHouseNum()); |
|
|
|
dto.setTotalFloorNum(buildingGeneralDTO.getTotalFloorNum()); |
|
|
|
dto.setTotalUnitNum(buildingGeneralDTO.getTotalUnitNum()); |
|
|
|
// 补充单元ID
|
|
|
|
buildingUnitInfos = null == buildingUnitInfos ? getBuildingUnitInfos(dto.getBuildingId()) : buildingUnitInfos; |
|
|
|
Object cacheBuildingUnit = icHouseRedis.getTemporaryCacheBuildingUnit(formDTO.getCustomerId(), formDTO.getUserId(), dto.getBuildingId() + "_" + dto.getBuildingUnit()); |
|
|
|
dto.setBuildingUnitId(null == cacheBuildingUnit ? "" : cacheBuildingUnit.toString()); |
|
|
|
if (StringUtils.isNotBlank(dto.getBuildingUnitId())){ |
|
|
|
// 所有ID补充完毕,不需调用补用方法
|
|
|
|
needInsertList.add(dto); |
|
|
|
}else { |
|
|
|
needDisposeList.add(dto); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -110,14 +213,21 @@ public class ImportHouseInfoListener extends AnalysisEventListener<HouseInfoMode |
|
|
|
if (null == gridInfo){ |
|
|
|
throw new EpmetException("查询网格失败..."); |
|
|
|
} |
|
|
|
// 排除网格名不一样但小区名一样
|
|
|
|
if (!gridInfo.getGridName().equals(dto.getGridName()) && neighborHoodGeneralDTO.getNeighborHoodName().equals(dto.getNeighborHoodName())){ |
|
|
|
// 1.排除网格名不一样但小区名一样 2.排除组织不一样,网格一样,小区一样
|
|
|
|
if ((!gridInfo.getGridName().equals(dto.getGridName()) && neighborHoodGeneralDTO.getNeighborHoodName().equals(dto.getNeighborHoodName())) || |
|
|
|
(!gridInfo.getAgencyName().equals(dto.getAgencyName()) && gridInfo.getGridName().equals(dto.getGridName()) && neighborHoodGeneralDTO.getNeighborHoodName().equals(dto.getNeighborHoodName()))){ |
|
|
|
nums.add(num); |
|
|
|
return; |
|
|
|
} |
|
|
|
dto.setNeighborHoodId(formDTO.getOrgId()); |
|
|
|
dto.setGridId(neighborHoodGeneralDTO.getGridId()); |
|
|
|
dto.setAgencyId(neighborHoodGeneralDTO.getAgencyId()); |
|
|
|
AgencyInfoCache agencyInfo = CustomerOrgRedis.getAgencyInfo(dto.getAgencyId()); |
|
|
|
if (null == agencyInfo){ |
|
|
|
throw new EpmetException("查询组织信息失败..."); |
|
|
|
} |
|
|
|
dto.setPid(agencyInfo.getPid()); |
|
|
|
dto.setPids(agencyInfo.getPids()); |
|
|
|
// 填充各种ID
|
|
|
|
fillData(dto,CustomerGridConstant.NEIGHBORHOOD); |
|
|
|
} |
|
|
@ -280,26 +390,27 @@ public class ImportHouseInfoListener extends AnalysisEventListener<HouseInfoMode |
|
|
|
return buildingInfos; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 根据ID获取小区信息 |
|
|
|
* @param neighborHoodId |
|
|
|
* @author zxc |
|
|
|
* @date 2022/2/14 3:24 下午 |
|
|
|
*/ |
|
|
|
public ImportHouseGeneralDTO getNeighborHoodGeneralDTO(String neighborHoodId){ |
|
|
|
neighborHoodGeneralDTO = icBuildingDao.selectNeighborHoodById(neighborHoodId); |
|
|
|
return neighborHoodGeneralDTO; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
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()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 房屋信息插入 |
|
|
|
* @param houses |
|
|
|
* @author zxc |
|
|
|
* @date 2022/2/14 5:21 下午 |
|
|
|
*/ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void houseInsert(List<ImportHouseGeneralDTO> houses){ |
|
|
|
icHouseService.insertBatch(ConvertUtils.sourceToTarget(houses, IcHouseEntity.class)); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|