From f550f1fcb9134e5cbb5c9253fe4bb3dfe0bd5502 Mon Sep 17 00:00:00 2001 From: yinzuomei <576302893@qq.com> Date: Sun, 23 Apr 2023 16:09:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E6=B2=A1=E6=94=B9=E5=AE=8C?= =?UTF-8?q?=EF=BC=8C=E9=9C=80=E6=B1=82=E5=8F=98=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DangerousChemicalsImportListener.java | 92 ++++++++----------- .../impl/IcDangerousChemicalsServiceImpl.java | 29 ++++-- 2 files changed, 62 insertions(+), 59 deletions(-) diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/model/DangerousChemicalsImportListener.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/model/DangerousChemicalsImportListener.java index 0511f8f6fc..015f932c46 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/model/DangerousChemicalsImportListener.java +++ b/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 { 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 errorRows = new ArrayList<>(); private List otherRows = new ArrayList<>(); private List insertList = new ArrayList<>(); private Map existMap = null; + /** + * 危化品种类 + */ + private Map dangerTypeMap; + /** + * 企业类别 + */ + private Map categoryDictMap; + /** + * key:网格id + * value:网格名称 + */ + private Map 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 dangerTypeMap, + Map 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 getExistMap(String agencyId){ - LambdaQueryWrapper tWrapper = new LambdaQueryWrapper<>(); - tWrapper.eq(IcDangerousChemicalsEntity::getAgencyId, agencyId); - List entityList = icDangerousChemicalsDao.selectList(tWrapper); - Map 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> statusRes = adminOpenFeignClient.dictMap(DictTypeEnum.IC_DANGER_TYPE.getCode()); - if (!statusRes.success()){ - throw new EpmetException("获取IC_DANGER_TYPE字典表失败"); - } - Map statusMap = statusRes.success() && MapUtils.isNotEmpty(statusRes.getData()) ? statusRes.getData() : new HashMap<>(16); - //企业类别字典数据 - List dictList = coverageService.dictMap(agencyInfo.getCustomerId(), CoveragePlaceTypeEnum.DANGEROUS_CHEMICALS.getCode()); - Map 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); } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcDangerousChemicalsServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcDangerousChemicalsServiceImpl.java index e8fa1a32ed..9ec9cf922f 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcDangerousChemicalsServiceImpl.java +++ b/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 list(IcDangerousChemicalsListFormDTO formDTO) { @@ -237,15 +236,31 @@ public class IcDangerousChemicalsServiceImpl extends BaseServiceImpl> 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 dangerTypeMap = statusRes.getData(); + //企业类别字典数据 + List dictList = coverageService.dictMap(tokenDto.getCustomerId(), CoveragePlaceTypeEnum.DANGEROUS_CHEMICALS.getCode()); + Map 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 errorRows = listener.getErrorRows();