|
|
@ -2,32 +2,20 @@ 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.CustomerGridService; |
|
|
|
import com.epmet.service.IcDangerousChemicalsService; |
|
|
|
import lombok.Data; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
import org.apache.commons.collections4.MapUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.stream.Collectors; |
|
|
@ -42,24 +30,48 @@ import java.util.stream.Collectors; |
|
|
|
public class DangerousChemicalsImportListener extends AnalysisEventListener<DangerousChemicalsModel> { |
|
|
|
|
|
|
|
private IcDangerousChemicalsService icDangerousChemicalsService; |
|
|
|
private EpmetAdminOpenFeignClient adminOpenFeignClient; |
|
|
|
private CoverageService coverageService; |
|
|
|
private AgencyInfoCache agencyInfo; |
|
|
|
private IcDangerousChemicalsDao icDangerousChemicalsDao; |
|
|
|
private CustomerGridService customerGridService; |
|
|
|
private String currentUserId; |
|
|
|
|
|
|
|
private String customerId; |
|
|
|
private String staffAgencyId; |
|
|
|
private String staffAgencyPath; |
|
|
|
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; |
|
|
|
/** |
|
|
|
* 危化品种类 |
|
|
|
*/ |
|
|
|
private Map<String, String> dangerTypeMap; |
|
|
|
/** |
|
|
|
* 企业类别 |
|
|
|
*/ |
|
|
|
private Map<String, String> categoryDictMap; |
|
|
|
/** |
|
|
|
* key:网格id |
|
|
|
* value:网格名称 |
|
|
|
*/ |
|
|
|
private Map<String, String> gridMap; |
|
|
|
|
|
|
|
public DangerousChemicalsImportListener(String currentUserId, AgencyInfoCache agencyInfo, IcDangerousChemicalsService icDangerousChemicalsService, CoverageService coverageService, EpmetAdminOpenFeignClient adminOpenFeignClient, IcDangerousChemicalsDao icDangerousChemicalsDao){ |
|
|
|
public DangerousChemicalsImportListener(String currentUserId, |
|
|
|
String customerId, |
|
|
|
String staffAgencyId, |
|
|
|
String staffAgencyPath, |
|
|
|
IcDangerousChemicalsService icDangerousChemicalsService, |
|
|
|
CoverageService coverageService, |
|
|
|
CustomerGridService customerGridService, |
|
|
|
Map<String, String> dangerTypeMap, |
|
|
|
Map<String, String> categoryDictMap){ |
|
|
|
this.currentUserId = currentUserId; |
|
|
|
this.agencyInfo = agencyInfo; |
|
|
|
this.customerId=customerId; |
|
|
|
this.staffAgencyId=staffAgencyId; |
|
|
|
this.staffAgencyPath=staffAgencyPath; |
|
|
|
this.icDangerousChemicalsService = icDangerousChemicalsService; |
|
|
|
this.coverageService = coverageService; |
|
|
|
this.adminOpenFeignClient = adminOpenFeignClient; |
|
|
|
this.icDangerousChemicalsDao = icDangerousChemicalsDao; |
|
|
|
this.customerGridService=customerGridService; |
|
|
|
this.dangerTypeMap=dangerTypeMap; |
|
|
|
this.categoryDictMap=categoryDictMap; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -68,18 +80,13 @@ public class DangerousChemicalsImportListener extends AnalysisEventListener<Dang |
|
|
|
data.setRowNum(rowNum); |
|
|
|
try { |
|
|
|
ValidatorUtils.validateEntity(data); |
|
|
|
/*existMap = null == existMap ? getExistMap(agencyInfo.getId()) : existMap; |
|
|
|
if (StringUtils.isNotBlank(existMap.get(data.getName()))){ |
|
|
|
DangerousChemicalsModel.RowRemarkMessage errorRow = ConvertUtils.sourceToTarget(data, DangerousChemicalsModel.RowRemarkMessage.class); |
|
|
|
errorRow.setErrorInfo("数据库存在该条数据"); |
|
|
|
errorRows.add(errorRow); |
|
|
|
return; |
|
|
|
}*/ |
|
|
|
//todo
|
|
|
|
// 所属组织,orgIdPath等等。。。。
|
|
|
|
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())); |
|
|
|
e.setAgencyId(staffAgencyId); |
|
|
|
e.setCustomerId(customerId); |
|
|
|
e.setAgencyIdPath(staffAgencyPath); |
|
|
|
e.setCreatedBy(currentUserId); |
|
|
|
e.setUpdatedBy(currentUserId); |
|
|
|
insertList.add(e); |
|
|
@ -105,38 +112,19 @@ 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: 数据库插入 |
|
|
|
*/ |
|
|
|
private void execPersist() { |
|
|
|
try { |
|
|
|
if (CollectionUtils.isNotEmpty(insertList)) { |
|
|
|
//危化品种类字典
|
|
|
|
Result<Map<String, String>> statusRes = adminOpenFeignClient.dictMap(DictTypeEnum.IC_DANGER_TYPE.getCode()); |
|
|
|
if (!statusRes.success()){ |
|
|
|
throw new EpmetException("获取IC_DANGER_TYPE字典表失败"); |
|
|
|
} |
|
|
|
Map<String, String> statusMap = statusRes.success() && MapUtils.isNotEmpty(statusRes.getData()) ? statusRes.getData() : new HashMap<>(16); |
|
|
|
//企业类别字典数据
|
|
|
|
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) -> { |
|
|
|
dangerTypeMap.forEach((k,v) -> { |
|
|
|
if (i.getDangerTypeName().equals(v)){ |
|
|
|
i.setDangerType(k); |
|
|
|
} |
|
|
|
}); |
|
|
|
dictMap.forEach((k,v) -> { |
|
|
|
categoryDictMap.forEach((k,v) -> { |
|
|
|
if (i.getCategoryName().equals(v)){ |
|
|
|
i.setCategory(k); |
|
|
|
} |
|
|
|