|
|
@ -17,30 +17,45 @@ |
|
|
|
|
|
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; |
|
|
|
import com.epmet.commons.tools.dto.result.OptionResultDTO; |
|
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.redis.common.CustomerOrgRedis; |
|
|
|
import com.epmet.commons.tools.redis.common.CustomerStaffRedis; |
|
|
|
import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache; |
|
|
|
import com.epmet.commons.tools.redis.common.bean.GridInfoCache; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.constant.CustomerGridConstant; |
|
|
|
import com.epmet.dao.CustomerGridDao; |
|
|
|
import com.epmet.dao.IcNeighborHoodDao; |
|
|
|
import com.epmet.dto.IcNeighborHoodDTO; |
|
|
|
import com.epmet.dto.form.ImportInfoFormDTO; |
|
|
|
import com.epmet.dto.result.InfoByNamesResultDTO; |
|
|
|
import com.epmet.entity.IcNeighborHoodEntity; |
|
|
|
import com.epmet.excel.IcBuildingExcel; |
|
|
|
import com.epmet.excel.IcNeighborHoodExcel; |
|
|
|
import com.epmet.service.IcNeighborHoodService; |
|
|
|
import com.epmet.util.ExcelPoiUtils; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
import org.apache.commons.collections4.ListUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.io.IOException; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
@ -53,6 +68,8 @@ import java.util.stream.Collectors; |
|
|
|
@Service |
|
|
|
public class IcNeighborHoodServiceImpl extends BaseServiceImpl<IcNeighborHoodDao, IcNeighborHoodEntity> implements IcNeighborHoodService { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private CustomerGridDao customerGridDao; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<IcNeighborHoodDTO> page(Map<String, Object> params) { |
|
|
@ -160,4 +177,152 @@ public class IcNeighborHoodServiceImpl extends BaseServiceImpl<IcNeighborHoodDao |
|
|
|
return ConvertUtils.sourceToTarget(list, IcNeighborHoodDTO.class); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 小区信息导入 |
|
|
|
* @param formDTO |
|
|
|
* @param file |
|
|
|
* @author zxc |
|
|
|
* @date 2022/2/12 11:11 上午 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Result neighborhoodImport(ImportInfoFormDTO formDTO, MultipartFile file) throws IOException { |
|
|
|
ExcelImportResult<IcNeighborHoodExcel> importResult = ExcelPoiUtils.importExcelMore(file, 0, 1, IcNeighborHoodExcel.class); |
|
|
|
List<IcNeighborHoodExcel> failList = importResult.getFailList(); |
|
|
|
//存放错误数据行号
|
|
|
|
List<Integer> numList = new ArrayList<>(); |
|
|
|
if(CollectionUtils.isNotEmpty(failList)){ |
|
|
|
for ( IcNeighborHoodExcel entity : failList) { |
|
|
|
//打印失败的行 和失败的信息
|
|
|
|
log.error("第{}行,{}",entity.getRowNum(),entity.getErrorMsg()); |
|
|
|
numList.add(entity.getRowNum()); |
|
|
|
} |
|
|
|
} |
|
|
|
List<IcNeighborHoodExcel> result =importResult.getList(); |
|
|
|
return disposeImportNeighborhood(formDTO,result); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 根据左侧树选中的层级,可导入对应数据: |
|
|
|
* 1. 选中社区可导入该社区下所有小区信息、楼宇信息、房屋信息(没有匹配的小区、楼宇均新增,网格没有对应的不新增); |
|
|
|
* 2. 选中网格可导入该网格下所有小区信息、楼宇信息、房屋信息(没有匹配的小区、楼宇均新增); |
|
|
|
* 3. 选中小区可导入该小区下所有楼宇信息、房屋信息(没有匹配的楼宇均新增); |
|
|
|
* 4. 选中楼宇可导入该楼宇下所有房屋信息。 |
|
|
|
* @param formDTO |
|
|
|
* @param result |
|
|
|
* @author zxc |
|
|
|
* @date 2022/2/12 2:02 下午 |
|
|
|
*/ |
|
|
|
public Result disposeImportNeighborhood(ImportInfoFormDTO formDTO, List<IcNeighborHoodExcel> result){ |
|
|
|
if (CollectionUtils.isEmpty(result)){ |
|
|
|
return new Result().error(9999,"excel表格内没有数据"); |
|
|
|
} |
|
|
|
List<Integer> nums = new ArrayList<>(); |
|
|
|
List<String> gridNames = result.stream().map(m -> m.getGridName()).collect(Collectors.toList()); |
|
|
|
// 1. 查询数据网格是否存在
|
|
|
|
List<InfoByNamesResultDTO> gridInfos = customerGridDao.selectGridInfoByNames(gridNames, formDTO.getCustomerId()); |
|
|
|
if (CollectionUtils.isEmpty(gridInfos)){ |
|
|
|
// 网格没有对应的不新增
|
|
|
|
for (int i = NumConstant.ONE; i <= result.size(); i++) { |
|
|
|
nums.add(i); |
|
|
|
} |
|
|
|
String str = String.format("共%s条,成功导入%s条。",result.size(),0); |
|
|
|
return new Result().error(9999,str + "第"+nums.stream().map(String::valueOf).collect(Collectors.joining("、"))+"行未成功!"); |
|
|
|
} |
|
|
|
result.forEach(r -> { |
|
|
|
for (InfoByNamesResultDTO g : gridInfos) { |
|
|
|
if (r.getGridName().equals(g.getGridName())){ |
|
|
|
r.setStatus(true); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
Map<Boolean, List<IcNeighborHoodExcel>> groupStatus = result.stream().collect(Collectors.groupingBy(IcNeighborHoodExcel::getStatus)); |
|
|
|
// 只获取能查询到的网格
|
|
|
|
List<IcNeighborHoodExcel> neighborHoods = groupStatus.get(true); |
|
|
|
// 2. 查询组织选中组织下存在的小区
|
|
|
|
List<String> existNames = baseDao.selectNeighborhoodNameByNames(neighborHoods.stream().map(m -> m.getNeighborHoodName()).collect(Collectors.toList()), formDTO.getCustomerId()); |
|
|
|
// 为了显示多少行插入成功,未成功
|
|
|
|
result.forEach(r -> { |
|
|
|
for (String s : existNames) { |
|
|
|
if (r.getNeighborHoodName().equals(s)){ |
|
|
|
r.setExistNameStatus(true); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
Map<Boolean, List<IcNeighborHoodExcel>> groupByExistName = neighborHoods.stream().collect(Collectors.groupingBy(IcNeighborHoodExcel::getExistNameStatus)); |
|
|
|
// 获取需要插入的数据
|
|
|
|
List<IcNeighborHoodExcel> needInsert = groupByExistName.get(false); |
|
|
|
if (CollectionUtils.isEmpty(needInsert)){ |
|
|
|
for (int i = NumConstant.ONE; i <= result.size(); i++) { |
|
|
|
nums.add(i); |
|
|
|
} |
|
|
|
String str = String.format("共%s条,成功导入%s条。",result.size(),0); |
|
|
|
return new Result().error(9999,str + "第"+nums.stream().map(String::valueOf).collect(Collectors.joining("、"))+"行未成功!"); |
|
|
|
} |
|
|
|
if (formDTO.getOrgType().equals(CustomerGridConstant.AGENCY)){ |
|
|
|
AgencyInfoCache agencyInfo = CustomerOrgRedis.getAgencyInfo(formDTO.getOrgId()); |
|
|
|
if (null == agencyInfo){ |
|
|
|
throw new EpmetException("未查询到组织信息..."); |
|
|
|
} |
|
|
|
needInsert.forEach(n -> { |
|
|
|
if (agencyInfo.getOrganizationName().equals(n.getAgencyName())){ |
|
|
|
n.setAgencyNameStatus(true); |
|
|
|
} |
|
|
|
}); |
|
|
|
}else { |
|
|
|
GridInfoCache gridInfo = CustomerOrgRedis.getGridInfo(formDTO.getOrgId()); |
|
|
|
if (null == gridInfo){ |
|
|
|
throw new EpmetException("未查询到网格信息..."); |
|
|
|
} |
|
|
|
needInsert.forEach(n -> { |
|
|
|
if (gridInfo.getGridName().equals(n.getGridName())){ |
|
|
|
n.setAgencyNameStatus(true); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
Map<Boolean, List<IcNeighborHoodExcel>> groupByAgencyNameStatus = needInsert.stream().collect(Collectors.groupingBy(IcNeighborHoodExcel::getAgencyNameStatus)); |
|
|
|
List<IcNeighborHoodExcel> finalNeedInsert = groupByAgencyNameStatus.get(true); |
|
|
|
if (CollectionUtils.isEmpty(finalNeedInsert)){ |
|
|
|
for (int i = NumConstant.ONE; i <= result.size(); i++) { |
|
|
|
nums.add(i); |
|
|
|
} |
|
|
|
String str = String.format("共%s条,成功导入%s条。",result.size(),0); |
|
|
|
return new Result().error(9999,str +"第"+nums.stream().map(String::valueOf).collect(Collectors.joining("、"))+"行未成功!"); |
|
|
|
} |
|
|
|
List<IcNeighborHoodEntity> entities = ConvertUtils.sourceToTarget(finalNeedInsert, IcNeighborHoodEntity.class); |
|
|
|
entities.forEach(e -> { |
|
|
|
for (InfoByNamesResultDTO g : gridInfos) { |
|
|
|
if (e.getGridName().equals(g.getGridName())){ |
|
|
|
e.setAgencyId(g.getAgencyId()); |
|
|
|
e.setAgencyPids(g.getAgencyPids()); |
|
|
|
e.setCustomerId(formDTO.getCustomerId()); |
|
|
|
e.setGridId(g.getGridId()); |
|
|
|
e.setParentAgencyId(g.getParentAgencyId()); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
importInsert(entities); |
|
|
|
for (int i = NumConstant.ZERO; i < result.size(); i++) { |
|
|
|
if (result.get(i).getStatus() == false || result.get(i).getExistNameStatus() == true || result.get(i).getAgencyNameStatus() == false){ |
|
|
|
nums.add(i + NumConstant.ONE); |
|
|
|
} |
|
|
|
} |
|
|
|
String str = String.format("共%s条,成功导入%s条。",result.size(),entities.size()); |
|
|
|
if (CollectionUtils.isNotEmpty(nums)){ |
|
|
|
return new Result().error(9999,str + "第"+nums.stream().map(String::valueOf).collect(Collectors.joining("、"))+"行未成功!"); |
|
|
|
} |
|
|
|
return new Result().ok(str); |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void importInsert(List<IcNeighborHoodEntity> entities){ |
|
|
|
List<List<IcNeighborHoodEntity>> partition = ListUtils.partition(entities, NumConstant.ONE_HUNDRED); |
|
|
|
partition.forEach(p -> { |
|
|
|
insertBatch(p); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
} |