|
|
@ -2,15 +2,21 @@ package com.epmet.model; |
|
|
|
|
|
|
|
import com.alibaba.excel.context.AnalysisContext; |
|
|
|
import com.alibaba.excel.event.AnalysisEventListener; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.enums.CoveragePlaceTypeEnum; |
|
|
|
import com.epmet.commons.tools.enums.DictTypeEnum; |
|
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
|
import com.epmet.commons.tools.exception.ExceptionUtils; |
|
|
|
import com.epmet.commons.tools.exception.ValidateException; |
|
|
|
import com.epmet.commons.tools.redis.common.bean.AgencyInfoCache; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
|
import com.epmet.dao.IcDangerousChemicalsDao; |
|
|
|
import com.epmet.dto.result.IcCoverageCategoryDictListResultDTO; |
|
|
|
import com.epmet.entity.IcDangerousChemicalsEntity; |
|
|
|
import com.epmet.excel.IcCityManagementExcel; |
|
|
|
import com.epmet.feign.EpmetAdminOpenFeignClient; |
|
|
|
import com.epmet.service.CoverageService; |
|
|
|
import com.epmet.service.IcDangerousChemicalsService; |
|
|
@ -39,73 +45,55 @@ public class DangerousChemicalsImportListener extends AnalysisEventListener<Dang |
|
|
|
private EpmetAdminOpenFeignClient adminOpenFeignClient; |
|
|
|
private CoverageService coverageService; |
|
|
|
private AgencyInfoCache agencyInfo; |
|
|
|
private IcDangerousChemicalsDao icDangerousChemicalsDao; |
|
|
|
|
|
|
|
private List<DangerousChemicalsModel.RowRemarkMessage> errorRows = new ArrayList<>(); |
|
|
|
private List<DangerousChemicalsModel.RowRemarkMessage> otherRows = new ArrayList<>(); |
|
|
|
private List<IcDangerousChemicalsEntity> insertList = new ArrayList<>(); |
|
|
|
private Map<String,String> existMap = null; |
|
|
|
|
|
|
|
public DangerousChemicalsImportListener(AgencyInfoCache agencyInfo, IcDangerousChemicalsService icDangerousChemicalsService, CoverageService coverageService,EpmetAdminOpenFeignClient adminOpenFeignClient){ |
|
|
|
public DangerousChemicalsImportListener(AgencyInfoCache agencyInfo, IcDangerousChemicalsService icDangerousChemicalsService, CoverageService coverageService, EpmetAdminOpenFeignClient adminOpenFeignClient, IcDangerousChemicalsDao icDangerousChemicalsDao){ |
|
|
|
this.agencyInfo = agencyInfo; |
|
|
|
this.icDangerousChemicalsService = icDangerousChemicalsService; |
|
|
|
this.coverageService = coverageService; |
|
|
|
this.adminOpenFeignClient = adminOpenFeignClient; |
|
|
|
this.icDangerousChemicalsDao = icDangerousChemicalsDao; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void invoke(DangerousChemicalsModel data, AnalysisContext context) { |
|
|
|
Integer rowNum = context.readRowHolder().getRowIndex() + NumConstant.ONE; |
|
|
|
if (StringUtils.isBlank(data.getName())){ |
|
|
|
DangerousChemicalsModel.RowRemarkMessage row = ConvertUtils.sourceToTarget(data, DangerousChemicalsModel.RowRemarkMessage.class); |
|
|
|
row.setRowNum(rowNum); |
|
|
|
row.setErrorInfo("企业名称不能为空"); |
|
|
|
errorRows.add(row); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(data.getCategoryName())){ |
|
|
|
DangerousChemicalsModel.RowRemarkMessage row = ConvertUtils.sourceToTarget(data, DangerousChemicalsModel.RowRemarkMessage.class); |
|
|
|
row.setRowNum(rowNum); |
|
|
|
row.setErrorInfo("企业类型不能为空"); |
|
|
|
errorRows.add(row); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(data.getAddress())){ |
|
|
|
DangerousChemicalsModel.RowRemarkMessage row = ConvertUtils.sourceToTarget(data, DangerousChemicalsModel.RowRemarkMessage.class); |
|
|
|
row.setRowNum(rowNum); |
|
|
|
row.setErrorInfo("经营地址不能为空"); |
|
|
|
errorRows.add(row); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (data.getName().trim().length() > NumConstant.FIFTY){ |
|
|
|
DangerousChemicalsModel.RowRemarkMessage row = ConvertUtils.sourceToTarget(data, DangerousChemicalsModel.RowRemarkMessage.class); |
|
|
|
row.setRowNum(rowNum); |
|
|
|
row.setErrorInfo("企业名称长度超出50字限制"); |
|
|
|
errorRows.add(row); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (data.getPrincipalMobile().trim().length() > NumConstant.FIFTY){ |
|
|
|
DangerousChemicalsModel.RowRemarkMessage row = ConvertUtils.sourceToTarget(data, DangerousChemicalsModel.RowRemarkMessage.class); |
|
|
|
row.setRowNum(rowNum); |
|
|
|
row.setErrorInfo("联系电话长度超出50字限制"); |
|
|
|
errorRows.add(row); |
|
|
|
return; |
|
|
|
} |
|
|
|
if (data.getAddress().trim().length() > NumConstant.FIFTY){ |
|
|
|
DangerousChemicalsModel.RowRemarkMessage row = ConvertUtils.sourceToTarget(data, DangerousChemicalsModel.RowRemarkMessage.class); |
|
|
|
row.setRowNum(rowNum); |
|
|
|
row.setErrorInfo("经营地址长度超出50字限制"); |
|
|
|
errorRows.add(row); |
|
|
|
return; |
|
|
|
} |
|
|
|
IcDangerousChemicalsEntity e = ConvertUtils.sourceToTarget(data, IcDangerousChemicalsEntity.class); |
|
|
|
e.setSourceType("import"); |
|
|
|
e.setAgencyId(agencyInfo.getId()); |
|
|
|
e.setCustomerId(agencyInfo.getCustomerId()); |
|
|
|
e.setAgencyIdPath(agencyInfo.getPids().equals(NumConstant.ZERO_STR) || agencyInfo.getPids().equals("") ? agencyInfo.getId() : agencyInfo.getPids().concat(":").concat(agencyInfo.getId())); |
|
|
|
insertList.add(e); |
|
|
|
if (insertList.size() == NumConstant.ONE_HUNDRED){ |
|
|
|
execPersist(); |
|
|
|
data.setRowNum(rowNum); |
|
|
|
try { |
|
|
|
existMap = null == existMap ? getExistMap(agencyInfo.getId()) : existMap; |
|
|
|
ValidatorUtils.validateEntity(data); |
|
|
|
if (StringUtils.isNotBlank(existMap.get(data.getName()))){ |
|
|
|
DangerousChemicalsModel.RowRemarkMessage errorRow = ConvertUtils.sourceToTarget(data, DangerousChemicalsModel.RowRemarkMessage.class); |
|
|
|
errorRow.setErrorInfo("数据库存在该条数据"); |
|
|
|
errorRows.add(errorRow); |
|
|
|
return; |
|
|
|
} |
|
|
|
IcDangerousChemicalsEntity e = ConvertUtils.sourceToTarget(data, IcDangerousChemicalsEntity.class); |
|
|
|
e.setSourceType("import"); |
|
|
|
e.setAgencyId(agencyInfo.getId()); |
|
|
|
e.setCustomerId(agencyInfo.getCustomerId()); |
|
|
|
e.setAgencyIdPath(agencyInfo.getPids().equals(NumConstant.ZERO_STR) || agencyInfo.getPids().equals("") ? agencyInfo.getId() : agencyInfo.getPids().concat(":").concat(agencyInfo.getId())); |
|
|
|
insertList.add(e); |
|
|
|
if (insertList.size() == NumConstant.ONE_HUNDRED){ |
|
|
|
execPersist(); |
|
|
|
} |
|
|
|
}catch (Exception e){ |
|
|
|
String errorMsg = null; |
|
|
|
if (e instanceof ValidateException) { |
|
|
|
errorMsg = ((ValidateException) e).getMsg(); |
|
|
|
} else { |
|
|
|
errorMsg = "未知错误"; |
|
|
|
log.error("【重点危化品企业导入】出错:{}", ExceptionUtils.getErrorStackTrace(e)); |
|
|
|
} |
|
|
|
DangerousChemicalsModel.RowRemarkMessage errorRow = ConvertUtils.sourceToTarget(data, DangerousChemicalsModel.RowRemarkMessage.class); |
|
|
|
errorRow.setErrorInfo(errorMsg); |
|
|
|
errorRows.add(errorRow); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -113,6 +101,16 @@ public class DangerousChemicalsImportListener extends AnalysisEventListener<Dang |
|
|
|
execPersist(); |
|
|
|
} |
|
|
|
|
|
|
|
public Map<String,String> getExistMap(String agencyId){ |
|
|
|
LambdaQueryWrapper<IcDangerousChemicalsEntity> tWrapper = new LambdaQueryWrapper<>(); |
|
|
|
tWrapper.eq(IcDangerousChemicalsEntity::getAgencyId, agencyId); |
|
|
|
List<IcDangerousChemicalsEntity> entityList = icDangerousChemicalsDao.selectList(tWrapper); |
|
|
|
Map<String,String> existMap = new HashMap<>(16); |
|
|
|
if (CollectionUtils.isNotEmpty(entityList)){ |
|
|
|
existMap = entityList.stream().collect(Collectors.toMap(IcDangerousChemicalsEntity::getName,IcDangerousChemicalsEntity::getId,(v1,v2) -> v1)); |
|
|
|
} |
|
|
|
return existMap; |
|
|
|
} |
|
|
|
/** |
|
|
|
* Desc: 数据库插入 |
|
|
|
*/ |
|
|
@ -126,7 +124,7 @@ public class DangerousChemicalsImportListener extends AnalysisEventListener<Dang |
|
|
|
} |
|
|
|
Map<String, String> statusMap = statusRes.success() && MapUtils.isNotEmpty(statusRes.getData()) ? statusRes.getData() : new HashMap<>(16); |
|
|
|
//企业类别字典数据
|
|
|
|
List<IcCoverageCategoryDictListResultDTO> dictList = coverageService.dictMap(agencyInfo.getCustomerId(), "dangerous_chemicals"); |
|
|
|
List<IcCoverageCategoryDictListResultDTO> dictList = coverageService.dictMap(agencyInfo.getCustomerId(), CoveragePlaceTypeEnum.DANGEROUS_CHEMICALS.getCode()); |
|
|
|
Map<String, String> dictMap = dictList.stream().collect(Collectors.toMap(IcCoverageCategoryDictListResultDTO::getValue, IcCoverageCategoryDictListResultDTO::getLabel)); |
|
|
|
insertList.forEach(i -> { |
|
|
|
statusMap.forEach((k,v) -> { |
|
|
@ -140,10 +138,31 @@ public class DangerousChemicalsImportListener extends AnalysisEventListener<Dang |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
icDangerousChemicalsService.insertBatch(insertList); |
|
|
|
Map<String, Long> groupByName = insertList.stream().collect(Collectors.groupingBy(IcDangerousChemicalsEntity::getName, Collectors.counting())); |
|
|
|
groupByName.forEach((k,v) -> { |
|
|
|
if (v.compareTo(NumConstant.ONE_L) != NumConstant.ZERO){ |
|
|
|
insertList.forEach(i -> { |
|
|
|
if (i.getName().equals(k)){ |
|
|
|
i.setExistStatus(true); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
Map<Boolean, List<IcDangerousChemicalsEntity>> groupByStatus = insertList.stream().collect(Collectors.groupingBy(IcDangerousChemicalsEntity::getExistStatus)); |
|
|
|
if (CollectionUtils.isNotEmpty(groupByStatus.get(true))){ |
|
|
|
groupByStatus.get(true).forEach(t -> { |
|
|
|
DangerousChemicalsModel.RowRemarkMessage errorRow = ConvertUtils.sourceToTarget(t, DangerousChemicalsModel.RowRemarkMessage.class); |
|
|
|
errorRow.setErrorInfo("表格中存在重复数据"); |
|
|
|
errorRows.add(errorRow); |
|
|
|
}); |
|
|
|
} |
|
|
|
if (CollectionUtils.isNotEmpty(groupByStatus.get(false))){ |
|
|
|
icDangerousChemicalsService.insertBatch(groupByStatus.get(false)); |
|
|
|
} |
|
|
|
} |
|
|
|
} finally { |
|
|
|
insertList.clear(); |
|
|
|
existMap = null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|