|
|
@ -4,6 +4,9 @@ import com.alibaba.excel.context.AnalysisContext; |
|
|
|
import com.alibaba.excel.event.AnalysisEventListener; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
|
import com.epmet.commons.tools.redis.common.CustomerOrgRedis; |
|
|
|
import com.epmet.commons.tools.redis.common.bean.GridInfoCache; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.dao.IcBuildingDao; |
|
|
|
import com.epmet.dto.ImportHouseGeneralDTO; |
|
|
@ -12,10 +15,7 @@ import com.epmet.redis.IcHouseRedis; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@ -26,17 +26,24 @@ import java.util.stream.Collectors; |
|
|
|
public class ImportHouseInfoListener extends AnalysisEventListener<HouseInfoModel> { |
|
|
|
|
|
|
|
List<Integer> nums = new ArrayList<>(); |
|
|
|
Integer num = NumConstant.ZERO; |
|
|
|
|
|
|
|
List<ImportHouseGeneralDTO> needDisposeList = new ArrayList<>(); |
|
|
|
List<ImportHouseGeneralDTO> needInsertList = new ArrayList<>(); |
|
|
|
Integer num = NumConstant.ZERO; |
|
|
|
|
|
|
|
String buildingName = null; |
|
|
|
String neighborHoodName = null; |
|
|
|
String gridName = null; |
|
|
|
String agencyName = null; |
|
|
|
|
|
|
|
Map<String, Object> gridInfos = null; |
|
|
|
List<ImportHouseGeneralDTO> gridInfoDTOs = null; |
|
|
|
Map<String, Object> neighborHoodInfos = null; |
|
|
|
List<ImportHouseGeneralDTO> neighborHoodInfoDTOs = null; |
|
|
|
Map<String, Object> buildingInfos = null; |
|
|
|
List<ImportHouseGeneralDTO> buildingInfoDTOs = null; |
|
|
|
Map<String, Object> buildingUnitInfos = null; |
|
|
|
List<ImportHouseGeneralDTO> buildingUnitInfoDTOs = null; |
|
|
|
|
|
|
|
private ImportInfoFormDTO formDTO; |
|
|
|
private IcBuildingDao icBuildingDao; |
|
|
@ -53,8 +60,9 @@ public class ImportHouseInfoListener extends AnalysisEventListener<HouseInfoMode |
|
|
|
if (null == data){ |
|
|
|
return; |
|
|
|
} |
|
|
|
ImportHouseGeneralDTO dto = ConvertUtils.sourceToTarget(data, ImportHouseGeneralDTO.class); |
|
|
|
num = num + NumConstant.ONE; |
|
|
|
ImportHouseGeneralDTO dto = ConvertUtils.sourceToTarget(data, ImportHouseGeneralDTO.class); |
|
|
|
dto.setNum(num); |
|
|
|
if (formDTO.getOrgType().equals("building")){ |
|
|
|
buildingName = null == buildingName ? icBuildingDao.selectBuildingNameById(formDTO.getOrgId()) : buildingName; |
|
|
|
// 不是本楼的
|
|
|
@ -78,43 +86,104 @@ public class ImportHouseInfoListener extends AnalysisEventListener<HouseInfoMode |
|
|
|
}); |
|
|
|
} |
|
|
|
}else if (formDTO.getOrgType().equals("neighborHood")){ |
|
|
|
neighborHoodName = null == neighborHoodName ? icBuildingDao.selectNeighborHoodNameById(formDTO.getOrgId()) : neighborHoodName; |
|
|
|
//不是本小区的
|
|
|
|
if (!data.getNeighborHoodName().equals(neighborHoodName)){ |
|
|
|
nums.add(num); |
|
|
|
}else { |
|
|
|
|
|
|
|
} |
|
|
|
disposeNeighborHoodHouse(dto); |
|
|
|
}else if (formDTO.getOrgType().equals("grid")){ |
|
|
|
gridName = null == gridName ? icBuildingDao.selectGridNameById(formDTO.getOrgId()) : gridName; |
|
|
|
//不是本网格的
|
|
|
|
if (!data.getGridName().equals(gridName)){ |
|
|
|
disposeGridHouse(dto); |
|
|
|
}else if (formDTO.getOrgType().equals("agency")){ |
|
|
|
disposeAgencyHouse(dto); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void disposeNeighborHoodHouse(ImportHouseGeneralDTO dto){ |
|
|
|
neighborHoodName = null == neighborHoodName ? icBuildingDao.selectNeighborHoodNameById(formDTO.getOrgId()) : neighborHoodName; |
|
|
|
//不是本小区的
|
|
|
|
if (!dto.getNeighborHoodName().equals(neighborHoodName)){ |
|
|
|
nums.add(num); |
|
|
|
}else { |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 左侧树点击网格时调用 |
|
|
|
* @param dto |
|
|
|
* @author zxc |
|
|
|
* @date 2022/2/14 2:14 下午 |
|
|
|
*/ |
|
|
|
public void disposeGridHouse(ImportHouseGeneralDTO dto){ |
|
|
|
gridName = null == gridName ? icBuildingDao.selectGridNameById(formDTO.getOrgId()) : gridName; |
|
|
|
GridInfoCache gridInfo = CustomerOrgRedis.getGridInfo(formDTO.getOrgId()); |
|
|
|
if (null == gridInfo){ |
|
|
|
throw new EpmetException("查询网格失败..."); |
|
|
|
} |
|
|
|
//排除不是本网格的 gridName不一样排除,gridName一样但是agencyName不一样也得排除
|
|
|
|
if (!dto.getGridName().equals(gridName) || (!dto.getAgencyName().equals(gridInfo.getAgencyName()) && dto.getGridName().equals(gridName))){ |
|
|
|
nums.add(num); |
|
|
|
}else { |
|
|
|
//
|
|
|
|
dto.setGridId(formDTO.getOrgId()); |
|
|
|
dto.setAgencyId(gridInfo.getPid()); |
|
|
|
fillData(dto); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 左侧树点击组织时调用 |
|
|
|
* @param dto |
|
|
|
* @author zxc |
|
|
|
* @date 2022/2/14 1:35 下午 |
|
|
|
*/ |
|
|
|
public void disposeAgencyHouse(ImportHouseGeneralDTO dto){ |
|
|
|
agencyName = null == agencyName ? icBuildingDao.selectAgencyNameById(formDTO.getOrgId()) : agencyName; |
|
|
|
//排除不是本组织的
|
|
|
|
if (!dto.getAgencyName().equals(agencyName)){ |
|
|
|
nums.add(num); |
|
|
|
}else { |
|
|
|
// 根据组织查询出所有网格,甩出不是本组织下的网格
|
|
|
|
gridInfos = null == gridInfos ? getGridInfos(formDTO.getOrgId()) : gridInfos; |
|
|
|
if (null == gridInfos){ |
|
|
|
// 组织下确实不存在网格
|
|
|
|
nums.add(num); |
|
|
|
}else { |
|
|
|
//
|
|
|
|
return; |
|
|
|
} |
|
|
|
}else if (formDTO.getOrgType().equals("agency")){ |
|
|
|
agencyName = null == agencyName ? icBuildingDao.selectAgencyNameById(formDTO.getOrgId()) : agencyName; |
|
|
|
//不是本组织的
|
|
|
|
if (!data.getAgencyName().equals(agencyName)){ |
|
|
|
// 根据网格名对比,没有找到的就把行号加入到未执行成功队列中
|
|
|
|
Object cacheGridName = icHouseRedis.getTemporaryCacheGrid(formDTO.getCustomerId(), formDTO.getUserId(), dto.getGridName()); |
|
|
|
if (null == cacheGridName){ |
|
|
|
nums.add(num); |
|
|
|
}else { |
|
|
|
// 根据组织查询出所有网格,甩出不是本组织下的网格
|
|
|
|
gridInfos = null == gridInfos ? getGridInfos(formDTO.getOrgId()) : gridInfos; |
|
|
|
if (null == gridInfos){ |
|
|
|
// 组织下确实不存在网格
|
|
|
|
return; |
|
|
|
} |
|
|
|
// 根据网格名对比,没有找到的就把行号加入到未执行成功队列中
|
|
|
|
Object cacheGridName = icHouseRedis.getTemporaryCacheGrid(formDTO.getCustomerId(), formDTO.getUserId(), dto.getGridName()); |
|
|
|
if (null == cacheGridName){ |
|
|
|
nums.add(num); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
dto.setGridId(cacheGridName.toString()); |
|
|
|
dto.setAgencyId(formDTO.getOrgId()); |
|
|
|
fillData(dto); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void fillData(ImportHouseGeneralDTO dto){ |
|
|
|
neighborHoodInfos = null == neighborHoodInfos ? getNeighborHoodInfos(Arrays.asList(formDTO.getOrgId())) : neighborHoodInfos; |
|
|
|
Object cacheNeighBorHood = icHouseRedis.getTemporaryCacheNeighBorHood(formDTO.getCustomerId(), formDTO.getUserId(), formDTO.getOrgId() + "_" + dto.getNeighborHoodName()); |
|
|
|
// 赋值小区ID
|
|
|
|
dto.setNeighborHoodId(null == cacheNeighBorHood ? "" : cacheNeighBorHood.toString()); |
|
|
|
if (StringUtils.isNotBlank(dto.getNeighborHoodId())){ |
|
|
|
//小区ID不为空赋值楼栋ID
|
|
|
|
buildingInfos = null == buildingInfos ? getBuildingInfos(dto.getNeighborHoodId()) : buildingInfos; |
|
|
|
Object cacheBuilding = icHouseRedis.getTemporaryCacheBuilding(formDTO.getCustomerId(), formDTO.getUserId(), dto.getNeighborHoodId() + "_" + dto.getBuildingName()); |
|
|
|
dto.setBuildingId(null == cacheBuilding ? "" : cacheBuilding.toString()); |
|
|
|
if (StringUtils.isNotBlank(dto.getBuildingId())){ |
|
|
|
// 楼栋ID不为空赋值单元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); |
|
|
|
} |
|
|
|
dto.setGridId(cacheGridName.toString()); |
|
|
|
dto.setAgencyId(formDTO.getOrgId()); |
|
|
|
}else { |
|
|
|
needDisposeList.add(dto); |
|
|
|
} |
|
|
|
}else { |
|
|
|
needDisposeList.add(dto); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -144,6 +213,32 @@ public class ImportHouseInfoListener extends AnalysisEventListener<HouseInfoMode |
|
|
|
return neighborHoodInfos; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 获取小区下的楼栋 |
|
|
|
* @param neighborHoodId |
|
|
|
* @author zxc |
|
|
|
* @date 2022/2/14 1:32 下午 |
|
|
|
*/ |
|
|
|
public Map<String,Object> getBuildingInfos(String neighborHoodId){ |
|
|
|
buildingInfoDTOs = icBuildingDao.selectAllBuildingByNeighborHoodId(neighborHoodId); |
|
|
|
buildingInfos = buildingInfoDTOs.stream().collect(Collectors.toMap(n -> n.getNeighborHoodId() + "_" + n.getBuildingName(), n -> n.getBuildingId())); |
|
|
|
icHouseRedis.setTemporaryCacheBuilding(formDTO.getCustomerId(), buildingInfos, formDTO.getUserId()); |
|
|
|
return buildingInfos; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 获取楼栋下的单元 |
|
|
|
* @param buildingId |
|
|
|
* @author zxc |
|
|
|
* @date 2022/2/14 2:04 下午 |
|
|
|
*/ |
|
|
|
public Map<String,Object> getBuildingUnitInfos(String buildingId){ |
|
|
|
buildingUnitInfoDTOs = icBuildingDao.selectAllBuildingUnitByBuildingId(buildingId); |
|
|
|
buildingUnitInfos = buildingInfoDTOs.stream().collect(Collectors.toMap(n -> n.getBuildingId() + "_" + n.getBuildingUnit(), n -> n.getBuildingUnitId())); |
|
|
|
icHouseRedis.setTemporaryCacheBuildingUnit(formDTO.getCustomerId(), buildingUnitInfos, formDTO.getUserId()); |
|
|
|
return buildingInfos; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void doAfterAllAnalysed(AnalysisContext context) { |
|
|
|
|
|
|
@ -151,6 +246,7 @@ public class ImportHouseInfoListener extends AnalysisEventListener<HouseInfoMode |
|
|
|
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()); |
|
|
|
} |
|
|
|
|
|
|
|