| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -2,6 +2,7 @@ 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; | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -12,6 +13,7 @@ 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; | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -43,23 +45,34 @@ 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; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        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()); | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -78,7 +91,6 @@ public class DangerousChemicalsImportListener extends AnalysisEventListener<Dang | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                log.error("【重点危化品企业导入】出错:{}", ExceptionUtils.getErrorStackTrace(e)); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            DangerousChemicalsModel.RowRemarkMessage errorRow = ConvertUtils.sourceToTarget(data, DangerousChemicalsModel.RowRemarkMessage.class); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            errorRow.setRowNum(rowNum); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            errorRow.setErrorInfo(errorMsg); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            errorRows.add(errorRow); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -89,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: 数据库插入 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     */ | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -116,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.clear(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  |