forked from luyan/epmet-cloud-lingshan
7 changed files with 368 additions and 5 deletions
@ -0,0 +1,113 @@ |
|||||
|
package com.epmet.model; |
||||
|
|
||||
|
import com.alibaba.excel.context.AnalysisContext; |
||||
|
import com.alibaba.excel.event.AnalysisEventListener; |
||||
|
import com.epmet.commons.tools.constant.NumConstant; |
||||
|
import com.epmet.commons.tools.enums.DictTypeEnum; |
||||
|
import com.epmet.commons.tools.exception.EpmetException; |
||||
|
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.dto.result.IcCoverageCategoryDictListResultDTO; |
||||
|
import com.epmet.entity.IcDangerousChemicalsEntity; |
||||
|
import com.epmet.feign.EpmetAdminOpenFeignClient; |
||||
|
import com.epmet.service.CoverageService; |
||||
|
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 java.util.ArrayList; |
||||
|
import java.util.HashMap; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
/** |
||||
|
* @Author zxc |
||||
|
* @DateTime 2022/6/20 10:31 |
||||
|
* @DESC |
||||
|
*/ |
||||
|
@Data |
||||
|
@Slf4j |
||||
|
public class DangerousChemicalsImportListener extends AnalysisEventListener<DangerousChemicalsModel> { |
||||
|
|
||||
|
private IcDangerousChemicalsService icDangerousChemicalsService; |
||||
|
private EpmetAdminOpenFeignClient adminOpenFeignClient; |
||||
|
private CoverageService coverageService; |
||||
|
private AgencyInfoCache agencyInfo; |
||||
|
|
||||
|
private List<DangerousChemicalsModel.RowRemarkMessage> errorRows = new ArrayList<>(); |
||||
|
private List<DangerousChemicalsModel.RowRemarkMessage> otherRows = new ArrayList<>(); |
||||
|
private List<IcDangerousChemicalsEntity> insertList = new ArrayList<>(); |
||||
|
|
||||
|
public DangerousChemicalsImportListener(AgencyInfoCache agencyInfo, IcDangerousChemicalsService icDangerousChemicalsService, CoverageService coverageService,EpmetAdminOpenFeignClient adminOpenFeignClient){ |
||||
|
this.agencyInfo = agencyInfo; |
||||
|
this.icDangerousChemicalsService = icDangerousChemicalsService; |
||||
|
this.coverageService = coverageService; |
||||
|
this.adminOpenFeignClient = adminOpenFeignClient; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void invoke(DangerousChemicalsModel data, AnalysisContext context) { |
||||
|
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(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void doAfterAllAnalysed(AnalysisContext context) { |
||||
|
execPersist(); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 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(), "dangerous_chemicals"); |
||||
|
Map<String, String> dictMap = dictList.stream().collect(Collectors.toMap(IcCoverageCategoryDictListResultDTO::getCategoryKey, IcCoverageCategoryDictListResultDTO::getCategoryName)); |
||||
|
insertList.forEach(i -> { |
||||
|
statusMap.forEach((k,v) -> { |
||||
|
if (i.getDangerTypeName().equals(v)){ |
||||
|
i.setDangerType(k); |
||||
|
} |
||||
|
}); |
||||
|
dictMap.forEach((k,v) -> { |
||||
|
if (i.getCategoryName().equals(v)){ |
||||
|
i.setCategory(k); |
||||
|
} |
||||
|
}); |
||||
|
}); |
||||
|
icDangerousChemicalsService.insertBatch(insertList); |
||||
|
} |
||||
|
} finally { |
||||
|
insertList.clear(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 获取错误行 |
||||
|
* @return |
||||
|
*/ |
||||
|
public List<DangerousChemicalsModel.RowRemarkMessage> getErrorRows() { |
||||
|
return errorRows; |
||||
|
} |
||||
|
} |
@ -0,0 +1,56 @@ |
|||||
|
package com.epmet.model; |
||||
|
|
||||
|
import com.alibaba.excel.annotation.ExcelProperty; |
||||
|
import com.alibaba.excel.annotation.write.style.ColumnWidth; |
||||
|
import com.epmet.commons.tools.constant.NumConstant; |
||||
|
import lombok.Data; |
||||
|
import org.hibernate.validator.constraints.Length; |
||||
|
|
||||
|
import javax.validation.constraints.NotBlank; |
||||
|
|
||||
|
/** |
||||
|
* @Author zxc |
||||
|
* @DateTime 2022/6/20 10:33 |
||||
|
* @DESC |
||||
|
*/ |
||||
|
@Data |
||||
|
public class DangerousChemicalsModel { |
||||
|
|
||||
|
@NotBlank(message = "企业名称为必填项") |
||||
|
@Length(max = 50,message = "企业名称长度超出50字限制") |
||||
|
@ExcelProperty(value = "企业名称") |
||||
|
private String name; |
||||
|
|
||||
|
@NotBlank(message = "企业类型为必填项") |
||||
|
@ExcelProperty(value = "企业类型") |
||||
|
private String categoryName; |
||||
|
|
||||
|
@ExcelProperty(value = "周边安全间距(公里)") |
||||
|
private String safeDistance = NumConstant.ZERO_STR; |
||||
|
|
||||
|
@ExcelProperty(value = "危化品种类") |
||||
|
private String dangerTypeName; |
||||
|
|
||||
|
@ExcelProperty(value = "负责人") |
||||
|
private String principalName; |
||||
|
|
||||
|
@Length(max = 50,message = "联系电话长度超出50字限制") |
||||
|
@ExcelProperty(value = "联系电话") |
||||
|
private String principalMobile; |
||||
|
|
||||
|
@Length(max = 50,message = "经营地址长度超出50字限制") |
||||
|
@ExcelProperty(value = "经营地址") |
||||
|
private String address; |
||||
|
|
||||
|
@ExcelProperty(value = "备注") |
||||
|
private String remark; |
||||
|
|
||||
|
@Data |
||||
|
public static class RowRemarkMessage { |
||||
|
|
||||
|
@ColumnWidth(60) |
||||
|
@ExcelProperty("错误信息") |
||||
|
private String errorInfo; |
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue