|
|
@ -2,7 +2,21 @@ 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.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.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Author zxc |
|
|
@ -11,23 +25,133 @@ import com.epmet.dto.form.ImportInfoFormDTO; |
|
|
|
*/ |
|
|
|
public class ImportHouseInfoListener extends AnalysisEventListener<HouseInfoModel> { |
|
|
|
|
|
|
|
List<Integer> nums = new ArrayList<>(); |
|
|
|
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; |
|
|
|
|
|
|
|
private ImportInfoFormDTO formDTO; |
|
|
|
private IcBuildingDao icBuildingDao; |
|
|
|
private IcHouseRedis icHouseRedis; |
|
|
|
|
|
|
|
public ImportHouseInfoListener(ImportInfoFormDTO formDTO){ |
|
|
|
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) { |
|
|
|
System.out.println("aaa"); |
|
|
|
if (null == data){ |
|
|
|
return; |
|
|
|
} |
|
|
|
ImportHouseGeneralDTO dto = ConvertUtils.sourceToTarget(data, ImportHouseGeneralDTO.class); |
|
|
|
num = num + NumConstant.ONE; |
|
|
|
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")){ |
|
|
|
neighborHoodName = null == neighborHoodName ? icBuildingDao.selectNeighborHoodNameById(formDTO.getOrgId()) : neighborHoodName; |
|
|
|
//不是本小区的
|
|
|
|
if (!data.getNeighborHoodName().equals(neighborHoodName)){ |
|
|
|
nums.add(num); |
|
|
|
}else { |
|
|
|
|
|
|
|
} |
|
|
|
}else if (formDTO.getOrgType().equals("grid")){ |
|
|
|
gridName = null == gridName ? icBuildingDao.selectGridNameById(formDTO.getOrgId()) : gridName; |
|
|
|
//不是本网格的
|
|
|
|
if (!data.getGridName().equals(gridName)){ |
|
|
|
nums.add(num); |
|
|
|
}else { |
|
|
|
//
|
|
|
|
} |
|
|
|
}else if (formDTO.getOrgType().equals("agency")){ |
|
|
|
agencyName = null == agencyName ? icBuildingDao.selectAgencyNameById(formDTO.getOrgId()) : agencyName; |
|
|
|
//不是本组织的
|
|
|
|
if (!data.getAgencyName().equals(agencyName)){ |
|
|
|
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; |
|
|
|
} |
|
|
|
dto.setGridId(cacheGridName.toString()); |
|
|
|
dto.setAgencyId(formDTO.getOrgId()); |
|
|
|
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; |
|
|
|
} |
|
|
|
|
|
|
|
@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.delTemporaryCacheHouses(formDTO.getCustomerId(), formDTO.getUserId()); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|