Browse Source

Merge remote-tracking branch 'origin/lingshan_master' into lingshan_master

master
wxz 2 years ago
parent
commit
bdf2eb1812
  1. 92
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/model/DangerousChemicalsImportListener.java
  2. 29
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcDangerousChemicalsServiceImpl.java

92
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/model/DangerousChemicalsImportListener.java

@ -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);
}

29
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcDangerousChemicalsServiceImpl.java

@ -8,15 +8,14 @@ import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult;
import com.epmet.commons.tools.enums.CoveragePlaceTypeEnum;
import com.epmet.commons.tools.enums.DictTypeEnum;
import com.epmet.commons.tools.enums.OrgTypeEnum;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.EpmetException;
import com.epmet.commons.tools.exception.ExceptionUtils;
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.security.dto.TokenDto;
import com.epmet.commons.tools.utils.*;
import com.epmet.constants.ImportTaskConstants;
@ -86,7 +85,7 @@ public class IcDangerousChemicalsServiceImpl extends BaseServiceImpl<IcDangerous
@Autowired
private OssFeignClient ossFeignClient;
@Autowired
private IcDangerousChemicalsDao icDangerousChemicalsDao;
private CustomerGridService customerGridService;
@Override
public PageData<IcDangerousChemicalsListResultDTO> list(IcDangerousChemicalsListFormDTO formDTO) {
@ -237,15 +236,31 @@ public class IcDangerousChemicalsServiceImpl extends BaseServiceImpl<IcDangerous
@Async
public void dangerousChemicalsImport(Path filePath, String importTaskId, TokenDto tokenDto) {
try {
// 获取当前登录用户所属组织id、组织全路径
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(tokenDto.getCustomerId(), tokenDto.getUserId());
if (null == staffInfo){
throw new EpmetException("查询工作人员信息失败:"+tokenDto.getUserId());
}
AgencyInfoCache agencyInfo = CustomerOrgRedis.getAgencyInfo(staffInfo.getAgencyId());
if (null == agencyInfo){
throw new EpmetException("查询所属组织失败:"+staffInfo.getAgencyId());
CustomerAgencyDTO staffAgencyInfo=SpringContextUtils.getBean(CustomerAgencyService.class).get(staffInfo.getAgencyId());
String staffAgencyPath=PidUtils.convertPid2OrgIdPath(staffInfo.getAgencyId(),staffAgencyInfo.getPids());
//危化品种类字典
Result<Map<String, String>> statusRes = adminOpenFeignClient.dictMap(DictTypeEnum.IC_DANGER_TYPE.getCode());
if (!statusRes.success() || MapUtils.isNotEmpty(statusRes.getData())) {
throw new EpmetException("获取IC_DANGER_TYPE字典表失败");
}
DangerousChemicalsImportListener listener = new DangerousChemicalsImportListener(tokenDto.getUserId(), agencyInfo,this,coverageService,adminOpenFeignClient,icDangerousChemicalsDao);
Map<String, String> dangerTypeMap = statusRes.getData();
//企业类别字典数据
List<IcCoverageCategoryDictListResultDTO> dictList = coverageService.dictMap(tokenDto.getCustomerId(), CoveragePlaceTypeEnum.DANGEROUS_CHEMICALS.getCode());
Map<String, String> categoryDictMap = dictList.stream().collect(Collectors.toMap(IcCoverageCategoryDictListResultDTO::getValue, IcCoverageCategoryDictListResultDTO::getLabel));
DangerousChemicalsImportListener listener = new DangerousChemicalsImportListener(tokenDto.getUserId(), tokenDto.getCustomerId(),
staffInfo.getAgencyId(),staffAgencyPath,
this,
coverageService,
customerGridService,
dangerTypeMap,
categoryDictMap);
EasyExcel.read(filePath.toFile(), DangerousChemicalsModel.class, listener).headRowNumber(1).sheet(0).doRead();
String errorDesFileUrl = null;
List<DangerousChemicalsModel.RowRemarkMessage> errorRows = listener.getErrorRows();

Loading…
Cancel
Save