|
@ -2,22 +2,24 @@ package com.epmet.excel.handler; |
|
|
|
|
|
|
|
|
import com.alibaba.excel.context.AnalysisContext; |
|
|
import com.alibaba.excel.context.AnalysisContext; |
|
|
import com.alibaba.excel.read.listener.ReadListener; |
|
|
import com.alibaba.excel.read.listener.ReadListener; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.epmet.commons.tools.exception.ExceptionUtils; |
|
|
import com.epmet.commons.tools.exception.ExceptionUtils; |
|
|
import com.epmet.commons.tools.exception.ValidateException; |
|
|
import com.epmet.commons.tools.exception.ValidateException; |
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
|
|
|
import com.epmet.dao.IcSuperiorResourceDao; |
|
|
import com.epmet.dto.result.IcCoverageCategoryDictListResultDTO; |
|
|
import com.epmet.dto.result.IcCoverageCategoryDictListResultDTO; |
|
|
import com.epmet.dto.result.IcSuperiorResourceListResultDTO; |
|
|
|
|
|
import com.epmet.entity.IcSuperiorResourceEntity; |
|
|
import com.epmet.entity.IcSuperiorResourceEntity; |
|
|
import com.epmet.excel.IcSuperiorResourceExcel; |
|
|
import com.epmet.excel.IcSuperiorResourceExcel; |
|
|
import com.epmet.service.CoverageService; |
|
|
import com.epmet.service.CoverageService; |
|
|
import com.epmet.service.impl.IcSuperiorResourceServiceImpl; |
|
|
import com.epmet.service.impl.IcSuperiorResourceServiceImpl; |
|
|
import lombok.Data; |
|
|
import lombok.Data; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
|
|
|
import java.util.HashMap; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
@ -44,14 +46,20 @@ public class IcSuperiorResourceExcelImportListener implements ReadListener<IcSup |
|
|
private List<IcSuperiorResourceExcel.RowRemarkMessage> otherRows = new ArrayList<>(); |
|
|
private List<IcSuperiorResourceExcel.RowRemarkMessage> otherRows = new ArrayList<>(); |
|
|
private IcSuperiorResourceServiceImpl icSuperiorResourceServiceImpl; |
|
|
private IcSuperiorResourceServiceImpl icSuperiorResourceServiceImpl; |
|
|
private CoverageService coverageService; |
|
|
private CoverageService coverageService; |
|
|
|
|
|
private IcSuperiorResourceDao icSuperiorResourceDao; |
|
|
|
|
|
//存放当前组织下已存在的场所信息
|
|
|
|
|
|
private Map<String, String> existMap = null; |
|
|
|
|
|
|
|
|
public IcSuperiorResourceExcelImportListener(String currentUserId, String currentCustomerId, String currentAgencyId, String currentAgencyPids, IcSuperiorResourceServiceImpl icSuperiorResourceServiceImpl, CoverageService coverageService) { |
|
|
|
|
|
|
|
|
public IcSuperiorResourceExcelImportListener(String currentUserId, String currentCustomerId, String currentAgencyId, String currentAgencyPids, |
|
|
|
|
|
IcSuperiorResourceServiceImpl icSuperiorResourceServiceImpl, CoverageService coverageService, IcSuperiorResourceDao icSuperiorResourceDao) { |
|
|
this.currentUserId = currentUserId; |
|
|
this.currentUserId = currentUserId; |
|
|
this.currentCustomerId = currentCustomerId; |
|
|
this.currentCustomerId = currentCustomerId; |
|
|
this.currentAgencyId = currentAgencyId; |
|
|
this.currentAgencyId = currentAgencyId; |
|
|
this.currentAgencyPids = currentAgencyPids; |
|
|
this.currentAgencyPids = currentAgencyPids; |
|
|
this.icSuperiorResourceServiceImpl = icSuperiorResourceServiceImpl; |
|
|
this.icSuperiorResourceServiceImpl = icSuperiorResourceServiceImpl; |
|
|
this.coverageService = coverageService; |
|
|
this.coverageService = coverageService; |
|
|
|
|
|
this.icSuperiorResourceDao = icSuperiorResourceDao; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@ -61,6 +69,15 @@ public class IcSuperiorResourceExcelImportListener implements ReadListener<IcSup |
|
|
// 先校验数据
|
|
|
// 先校验数据
|
|
|
ValidatorUtils.validateEntity(data); |
|
|
ValidatorUtils.validateEntity(data); |
|
|
|
|
|
|
|
|
|
|
|
existMap = null == existMap ? getExistMap(currentAgencyId) : existMap; |
|
|
|
|
|
ValidatorUtils.validateEntity(data); |
|
|
|
|
|
if (StringUtils.isNotBlank(existMap.get(data.getName()))) { |
|
|
|
|
|
IcSuperiorResourceExcel.RowRemarkMessage errorRow = ConvertUtils.sourceToTarget(data, IcSuperiorResourceExcel.RowRemarkMessage.class); |
|
|
|
|
|
errorRow.setErrorInfo("数据库存在当前场所数据"); |
|
|
|
|
|
errorRows.add(errorRow); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 去除前后空格
|
|
|
// 去除前后空格
|
|
|
if (StringUtils.isNotBlank(data.getName())) { |
|
|
if (StringUtils.isNotBlank(data.getName())) { |
|
|
data.setName(data.getName().trim()); |
|
|
data.setName(data.getName().trim()); |
|
@ -109,6 +126,20 @@ public class IcSuperiorResourceExcelImportListener implements ReadListener<IcSup |
|
|
execPersist(); |
|
|
execPersist(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 查询当前组织下已存在场所数据 |
|
|
|
|
|
*/ |
|
|
|
|
|
public Map<String, String> getExistMap(String agencyId) { |
|
|
|
|
|
LambdaQueryWrapper<IcSuperiorResourceEntity> tWrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
|
tWrapper.eq(IcSuperiorResourceEntity::getAgencyId, agencyId); |
|
|
|
|
|
List<IcSuperiorResourceEntity> entityList = icSuperiorResourceDao.selectList(tWrapper); |
|
|
|
|
|
Map<String, String> existMap = new HashMap<>(16); |
|
|
|
|
|
if (CollectionUtils.isNotEmpty(entityList)) { |
|
|
|
|
|
existMap = entityList.stream().collect(Collectors.toMap(IcSuperiorResourceEntity::getName, IcSuperiorResourceEntity::getId, (v1, v2) -> v1)); |
|
|
|
|
|
} |
|
|
|
|
|
return existMap; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 执行持久化 |
|
|
* 执行持久化 |
|
|
*/ |
|
|
*/ |
|
|