21 changed files with 943 additions and 52 deletions
@ -0,0 +1,118 @@ |
|||||
|
package com.epmet.dto; |
||||
|
|
||||
|
import com.epmet.commons.tools.constant.NumConstant; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
/** |
||||
|
* @Author zxc |
||||
|
* @DateTime 2022/2/13 4:32 下午 |
||||
|
* @DESC |
||||
|
*/ |
||||
|
@Data |
||||
|
public class ImportHouseGeneralDTO implements Serializable { |
||||
|
|
||||
|
private static final long serialVersionUID = -345610717773879687L; |
||||
|
|
||||
|
/** |
||||
|
* 组织名、ID |
||||
|
*/ |
||||
|
private String agencyName; |
||||
|
private String agencyId; |
||||
|
|
||||
|
/** |
||||
|
* agencyId的pid |
||||
|
*/ |
||||
|
private String pid; |
||||
|
private String pids; |
||||
|
|
||||
|
/** |
||||
|
* 网格名、ID |
||||
|
*/ |
||||
|
private String gridName; |
||||
|
private String gridId; |
||||
|
|
||||
|
/** |
||||
|
* 小区名、ID |
||||
|
*/ |
||||
|
private String neighborHoodName; |
||||
|
private String neighborHoodId; |
||||
|
|
||||
|
/** |
||||
|
* 所属楼栋、ID |
||||
|
*/ |
||||
|
private String buildingName; |
||||
|
private String buildingId; |
||||
|
|
||||
|
/** |
||||
|
* 房屋类型 |
||||
|
*/ |
||||
|
private String type; |
||||
|
|
||||
|
/** |
||||
|
* 单元数 |
||||
|
*/ |
||||
|
private Integer totalUnitNum = NumConstant.ONE; |
||||
|
|
||||
|
/** |
||||
|
* 层数 |
||||
|
*/ |
||||
|
private Integer totalFloorNum; |
||||
|
|
||||
|
/** |
||||
|
* 户数 |
||||
|
*/ |
||||
|
private Integer totalHouseNum; |
||||
|
|
||||
|
/** |
||||
|
* 单元号、ID |
||||
|
*/ |
||||
|
private Integer buildingUnit; |
||||
|
private String buildingUnitId; |
||||
|
|
||||
|
/** |
||||
|
* 门牌号 |
||||
|
*/ |
||||
|
private String doorName; |
||||
|
|
||||
|
/** |
||||
|
* 房屋类型 |
||||
|
*/ |
||||
|
private String houseType; |
||||
|
|
||||
|
/** |
||||
|
* 房屋用途 |
||||
|
*/ |
||||
|
private String purpose; |
||||
|
|
||||
|
/** |
||||
|
* 是否出租 |
||||
|
*/ |
||||
|
private String rentFlag; |
||||
|
|
||||
|
/** |
||||
|
* 姓名 |
||||
|
*/ |
||||
|
private String ownerName; |
||||
|
|
||||
|
/** |
||||
|
* 电话 |
||||
|
*/ |
||||
|
private String ownerPhone; |
||||
|
|
||||
|
/** |
||||
|
* 身份证 |
||||
|
*/ |
||||
|
private String ownerIdCard; |
||||
|
|
||||
|
/** |
||||
|
* 行号 |
||||
|
*/ |
||||
|
private Integer num; |
||||
|
|
||||
|
/** |
||||
|
* 房屋ID |
||||
|
*/ |
||||
|
private String houseId; |
||||
|
} |
@ -0,0 +1,52 @@ |
|||||
|
package com.epmet.model; |
||||
|
|
||||
|
import com.alibaba.excel.annotation.ExcelProperty; |
||||
|
import lombok.Data; |
||||
|
import org.hibernate.validator.constraints.Length; |
||||
|
|
||||
|
/** |
||||
|
* @Author zxc |
||||
|
* @DateTime 2022/2/13 1:26 下午 |
||||
|
* @DESC |
||||
|
*/ |
||||
|
@Data |
||||
|
public class HouseInfoModel { |
||||
|
|
||||
|
@ExcelProperty(value = "所属组织") |
||||
|
private String agencyName; |
||||
|
|
||||
|
@ExcelProperty(value = "所属网格") |
||||
|
private String gridName; |
||||
|
|
||||
|
@ExcelProperty(value = "所属小区") |
||||
|
@Length(max=50,message = "不能超过50个字") |
||||
|
private String neighborHoodName; |
||||
|
|
||||
|
@ExcelProperty(value = "所属楼栋") |
||||
|
private String buildingName; |
||||
|
|
||||
|
@ExcelProperty(value = "单元号") |
||||
|
private Integer buildingUnit; |
||||
|
|
||||
|
@ExcelProperty(value = "门牌号") |
||||
|
private String doorName; |
||||
|
|
||||
|
@ExcelProperty(value = "房屋类型") |
||||
|
private String houseType; |
||||
|
|
||||
|
@ExcelProperty(value = "房屋用途") |
||||
|
private String purpose; |
||||
|
|
||||
|
@ExcelProperty(value = "出租") |
||||
|
private String rentFlag; |
||||
|
|
||||
|
@ExcelProperty(value = "房主姓名") |
||||
|
private String ownerName; |
||||
|
|
||||
|
@ExcelProperty(value = "房主电话") |
||||
|
private String ownerPhone; |
||||
|
|
||||
|
@ExcelProperty(value = "房主身份证") |
||||
|
private String ownerIdCard; |
||||
|
|
||||
|
} |
@ -0,0 +1,41 @@ |
|||||
|
package com.epmet.model; |
||||
|
|
||||
|
import com.alibaba.excel.annotation.ExcelProperty; |
||||
|
import lombok.Data; |
||||
|
import org.hibernate.validator.constraints.Length; |
||||
|
|
||||
|
/** |
||||
|
* @Author zxc |
||||
|
* @DateTime 2022/2/13 1:26 下午 |
||||
|
* @DESC |
||||
|
*/ |
||||
|
@Data |
||||
|
public class HouseInfoModelDTO { |
||||
|
|
||||
|
private String agencyName; |
||||
|
|
||||
|
private String gridName; |
||||
|
|
||||
|
private String neighborHoodName; |
||||
|
|
||||
|
private String buildingName; |
||||
|
|
||||
|
private Integer buildingUnit; |
||||
|
|
||||
|
private String doorName; |
||||
|
|
||||
|
private String houseType; |
||||
|
|
||||
|
private String purpose; |
||||
|
|
||||
|
private String rentFlag; |
||||
|
|
||||
|
private String ownerName; |
||||
|
|
||||
|
private String ownerPhone; |
||||
|
|
||||
|
private String ownerIdCard; |
||||
|
|
||||
|
private Integer num; |
||||
|
|
||||
|
} |
@ -0,0 +1,253 @@ |
|||||
|
package com.epmet.model; |
||||
|
|
||||
|
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; |
||||
|
import com.epmet.dto.form.ImportInfoFormDTO; |
||||
|
import com.epmet.redis.IcHouseRedis; |
||||
|
import org.apache.commons.lang3.StringUtils; |
||||
|
import org.springframework.util.CollectionUtils; |
||||
|
|
||||
|
import java.util.*; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
/** |
||||
|
* @Author zxc |
||||
|
* @DateTime 2022/2/13 1:25 下午 |
||||
|
* @DESC |
||||
|
*/ |
||||
|
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<>(); |
||||
|
|
||||
|
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; |
||||
|
private IcHouseRedis icHouseRedis; |
||||
|
|
||||
|
public ImportHouseInfoListener(ImportInfoFormDTO formDTO,IcBuildingDao icBuildingDao, IcHouseRedis icHouseRedis){ |
||||
|
this.formDTO = formDTO; |
||||
|
this.icBuildingDao = icBuildingDao; |
||||
|
this.icHouseRedis = icHouseRedis; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void invoke(HouseInfoModel data, AnalysisContext context) { |
||||
|
if (null == data){ |
||||
|
return; |
||||
|
} |
||||
|
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; |
||||
|
// 不是本楼的
|
||||
|
if (!data.getBuildingName().equals(buildingName)){ |
||||
|
nums.add(num); |
||||
|
}else { |
||||
|
/** |
||||
|
* 1。根据楼宇查询 |
||||
|
*/ |
||||
|
needDisposeList.add(dto); |
||||
|
Map<String, Object> collect = needDisposeList.stream().collect(Collectors.toMap(n -> n.getBuildingId() + "_" + n.getBuildingUnitId() + "_" + n.getDoorName(), n -> StringUtils.isNotBlank(n.getHouseId()) ? n.getHouseId() : "")); |
||||
|
icHouseRedis.setTemporaryCacheHouse(formDTO.getCustomerId(), collect, formDTO.getUserId()); |
||||
|
// Map<String, Object> temporaryCacheHouses = icHouseRedis.getTemporaryCacheHouses(formDTO.getCustomerId(), formDTO.getUserId());
|
||||
|
// TODO 等待方法
|
||||
|
List<ImportHouseGeneralDTO> result = new ArrayList<>(); |
||||
|
//把房屋ID不为空的行号加入nums,说明已存在
|
||||
|
result.forEach(r -> { |
||||
|
if (StringUtils.isNotBlank(r.getHouseId())){ |
||||
|
nums.add(r.getNum()); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
}else if (formDTO.getOrgType().equals("neighborHood")){ |
||||
|
disposeNeighborHoodHouse(dto); |
||||
|
}else if (formDTO.getOrgType().equals("grid")){ |
||||
|
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); |
||||
|
return; |
||||
|
} |
||||
|
// 根据网格名对比,没有找到的就把行号加入到未执行成功队列中
|
||||
|
Object cacheGridName = icHouseRedis.getTemporaryCacheGrid(formDTO.getCustomerId(), formDTO.getUserId(), dto.getGridName()); |
||||
|
if (null == cacheGridName){ |
||||
|
nums.add(num); |
||||
|
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); |
||||
|
} |
||||
|
}else { |
||||
|
needDisposeList.add(dto); |
||||
|
} |
||||
|
}else { |
||||
|
needDisposeList.add(dto); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @Description 获取网格信息 |
||||
|
* @param orgId |
||||
|
* @author zxc |
||||
|
* @date 2022/2/14 9:57 上午 |
||||
|
*/ |
||||
|
public Map<String,Object> getGridInfos(String orgId){ |
||||
|
gridInfoDTOs = icBuildingDao.selectAllGridByOrgId(orgId); |
||||
|
gridInfos = gridInfoDTOs.stream().collect(Collectors.toMap(n -> n.getGridName(), n -> n.getGridId())); |
||||
|
icHouseRedis.setTemporaryCacheGrid(formDTO.getCustomerId(), gridInfos, formDTO.getUserId()); |
||||
|
return gridInfos; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* @Description 获取网格下的小区 |
||||
|
* @param gridIds |
||||
|
* @author zxc |
||||
|
* @date 2022/2/14 10:16 上午 |
||||
|
*/ |
||||
|
public Map<String,Object> getNeighborHoodInfos(List<String> gridIds){ |
||||
|
neighborHoodInfoDTOs = icBuildingDao.selectAllNeighborHoodByGridIds(gridIds); |
||||
|
neighborHoodInfos = neighborHoodInfoDTOs.stream().collect(Collectors.toMap(n -> n.getGridId() + "_" + n.getNeighborHoodName(), n -> n.getNeighborHoodId())); |
||||
|
icHouseRedis.setTemporaryCacheNeighBorHood(formDTO.getCustomerId(), neighborHoodInfos, formDTO.getUserId()); |
||||
|
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) { |
||||
|
|
||||
|
// 删除缓存
|
||||
|
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()); |
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue