forked from luyan/epmet-cloud-lingshan
15 changed files with 1032 additions and 19 deletions
@ -0,0 +1,132 @@ |
|||
package com.epmet.excel.handler; |
|||
|
|||
import com.alibaba.excel.context.AnalysisContext; |
|||
import com.alibaba.excel.read.listener.ReadListener; |
|||
import com.epmet.commons.tools.exception.ExceptionUtils; |
|||
import com.epmet.commons.tools.exception.ValidateException; |
|||
import com.epmet.commons.tools.utils.ConvertUtils; |
|||
import com.epmet.commons.tools.validator.ValidatorUtils; |
|||
import com.epmet.dto.result.IcCoverageCategoryDictListResultDTO; |
|||
import com.epmet.entity.IcCityManagementEntity; |
|||
import com.epmet.excel.IcCityManagementExcel; |
|||
import com.epmet.service.CoverageService; |
|||
import com.epmet.service.impl.IcCityManagementServiceImpl; |
|||
import lombok.Data; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.stream.Collectors; |
|||
|
|||
/** |
|||
* 城市管理excel导入监听器 |
|||
*/ |
|||
@Data |
|||
@Slf4j |
|||
public class IcCityManagementExcelImportListener implements ReadListener<IcCityManagementExcel> { |
|||
|
|||
//最大条数阈值
|
|||
public static final int MAX_THRESHOLD = 200; |
|||
private String currentUserId; |
|||
private String currentCustomerId; |
|||
private String currentAgencyId; |
|||
private String currentAgencyPids; |
|||
|
|||
//数据
|
|||
private List<IcCityManagementEntity> datas = new ArrayList<>(); |
|||
//错误项列表
|
|||
private List<IcCityManagementExcel.RowRemarkMessage> errorRows = new ArrayList<>(); |
|||
//其他被标记出来的列表列表
|
|||
private List<IcCityManagementExcel.RowRemarkMessage> otherRows = new ArrayList<>(); |
|||
private IcCityManagementServiceImpl IcCityManagementServiceImpl; |
|||
private CoverageService coverageService; |
|||
|
|||
public IcCityManagementExcelImportListener(String currentUserId, String currentCustomerId, String currentAgencyId, String currentAgencyPids, IcCityManagementServiceImpl IcCityManagementServiceImpl, CoverageService coverageService) { |
|||
this.currentUserId = currentUserId; |
|||
this.currentCustomerId = currentCustomerId; |
|||
this.currentAgencyId = currentAgencyId; |
|||
this.currentAgencyPids = currentAgencyPids; |
|||
this.IcCityManagementServiceImpl = IcCityManagementServiceImpl; |
|||
this.coverageService = coverageService; |
|||
} |
|||
|
|||
@Override |
|||
public void invoke(IcCityManagementExcel data, AnalysisContext context) { |
|||
|
|||
try { |
|||
// 先校验数据
|
|||
ValidatorUtils.validateEntity(data); |
|||
|
|||
// 去除前后空格
|
|||
if (StringUtils.isNotBlank(data.getName())) { |
|||
data.setName(data.getName().trim()); |
|||
} |
|||
if (StringUtils.isNotBlank(data.getCategoryName())) { |
|||
data.setCategoryName(data.getCategoryName().trim()); |
|||
} |
|||
if (StringUtils.isNotBlank(data.getAddress())) { |
|||
data.setAddress(data.getAddress().trim()); |
|||
} |
|||
|
|||
IcCityManagementEntity IcCityManagementEntity = ConvertUtils.sourceToTarget(data, IcCityManagementEntity.class); |
|||
IcCityManagementEntity.setSourceType("import"); |
|||
IcCityManagementEntity.setCategory(data.getCategoryName()); |
|||
IcCityManagementEntity.setAreaCovered(data.getAreaCoveredName()); |
|||
IcCityManagementEntity.setCapacity(data.getCapacityName()); |
|||
datas.add(IcCityManagementEntity); |
|||
|
|||
if (datas.size() == MAX_THRESHOLD) { |
|||
execPersist(); |
|||
} |
|||
} catch (Exception e) { |
|||
String errorMsg = null; |
|||
if (e instanceof ValidateException) { |
|||
errorMsg = ((ValidateException) e).getMsg(); |
|||
} else { |
|||
errorMsg = "未知错误"; |
|||
log.error("【城市管理导入】出错:{}", ExceptionUtils.getErrorStackTrace(e)); |
|||
} |
|||
|
|||
IcCityManagementExcel.RowRemarkMessage errorRow = new IcCityManagementExcel.RowRemarkMessage(); |
|||
errorRow.setName(data.getName()); |
|||
errorRow.setCategoryName(data.getCategoryName()); |
|||
errorRow.setAddress(data.getAddress()); |
|||
errorRow.setErrorInfo(errorMsg); |
|||
errorRows.add(errorRow); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void doAfterAllAnalysed(AnalysisContext context) { |
|||
// 最后几条达不到阈值,这里必须再调用一次
|
|||
execPersist(); |
|||
} |
|||
|
|||
/** |
|||
* 执行持久化 |
|||
*/ |
|||
private void execPersist() { |
|||
try { |
|||
List<IcCoverageCategoryDictListResultDTO> dictList = coverageService.dictMap(currentCustomerId, "city_management"); |
|||
Map<String, String> dictMap = dictList.stream().collect(Collectors.toMap(IcCoverageCategoryDictListResultDTO::getCategoryKey, IcCoverageCategoryDictListResultDTO::getCategoryName)); |
|||
datas.forEach(d -> { |
|||
d.setCategory(dictMap.get(d.getCategory())); |
|||
}); |
|||
IcCityManagementServiceImpl.insertBatch(datas); |
|||
|
|||
} finally { |
|||
datas.clear(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 获取错误行 |
|||
* |
|||
* @return |
|||
*/ |
|||
public List<IcCityManagementExcel.RowRemarkMessage> getErrorRows() { |
|||
return errorRows; |
|||
} |
|||
} |
@ -0,0 +1,132 @@ |
|||
package com.epmet.excel.handler; |
|||
|
|||
import com.alibaba.excel.context.AnalysisContext; |
|||
import com.alibaba.excel.read.listener.ReadListener; |
|||
import com.epmet.commons.tools.exception.ExceptionUtils; |
|||
import com.epmet.commons.tools.exception.ValidateException; |
|||
import com.epmet.commons.tools.utils.ConvertUtils; |
|||
import com.epmet.commons.tools.validator.ValidatorUtils; |
|||
import com.epmet.dto.result.IcCoverageCategoryDictListResultDTO; |
|||
import com.epmet.entity.IcPublicServiceEntity; |
|||
import com.epmet.excel.IcPublicServiceExcel; |
|||
import com.epmet.service.CoverageService; |
|||
import com.epmet.service.impl.IcPublicServiceServiceImpl; |
|||
import lombok.Data; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.stream.Collectors; |
|||
|
|||
/** |
|||
* 公共服务管理excel导入监听器 |
|||
*/ |
|||
@Data |
|||
@Slf4j |
|||
public class IcPublicServiceExcelImportListener implements ReadListener<IcPublicServiceExcel> { |
|||
|
|||
//最大条数阈值
|
|||
public static final int MAX_THRESHOLD = 200; |
|||
private String currentUserId; |
|||
private String currentCustomerId; |
|||
private String currentAgencyId; |
|||
private String currentAgencyPids; |
|||
|
|||
//数据
|
|||
private List<IcPublicServiceEntity> datas = new ArrayList<>(); |
|||
//错误项列表
|
|||
private List<IcPublicServiceExcel.RowRemarkMessage> errorRows = new ArrayList<>(); |
|||
//其他被标记出来的列表列表
|
|||
private List<IcPublicServiceExcel.RowRemarkMessage> otherRows = new ArrayList<>(); |
|||
private IcPublicServiceServiceImpl IcPublicServiceServiceImpl; |
|||
private CoverageService coverageService; |
|||
|
|||
public IcPublicServiceExcelImportListener(String currentUserId, String currentCustomerId, String currentAgencyId, String currentAgencyPids, IcPublicServiceServiceImpl IcPublicServiceServiceImpl, CoverageService coverageService) { |
|||
this.currentUserId = currentUserId; |
|||
this.currentCustomerId = currentCustomerId; |
|||
this.currentAgencyId = currentAgencyId; |
|||
this.currentAgencyPids = currentAgencyPids; |
|||
this.IcPublicServiceServiceImpl = IcPublicServiceServiceImpl; |
|||
this.coverageService = coverageService; |
|||
} |
|||
|
|||
@Override |
|||
public void invoke(IcPublicServiceExcel data, AnalysisContext context) { |
|||
|
|||
try { |
|||
// 先校验数据
|
|||
ValidatorUtils.validateEntity(data); |
|||
|
|||
// 去除前后空格
|
|||
if (StringUtils.isNotBlank(data.getName())) { |
|||
data.setName(data.getName().trim()); |
|||
} |
|||
if (StringUtils.isNotBlank(data.getCategoryName())) { |
|||
data.setCategoryName(data.getCategoryName().trim()); |
|||
} |
|||
if (StringUtils.isNotBlank(data.getAddress())) { |
|||
data.setAddress(data.getAddress().trim()); |
|||
} |
|||
|
|||
IcPublicServiceEntity IcPublicServiceEntity = ConvertUtils.sourceToTarget(data, IcPublicServiceEntity.class); |
|||
IcPublicServiceEntity.setSourceType("import"); |
|||
IcPublicServiceEntity.setCategory(data.getCategoryName()); |
|||
IcPublicServiceEntity.setAreaCovered(data.getAreaCoveredName()); |
|||
IcPublicServiceEntity.setCapacity(data.getCapacityName()); |
|||
datas.add(IcPublicServiceEntity); |
|||
|
|||
if (datas.size() == MAX_THRESHOLD) { |
|||
execPersist(); |
|||
} |
|||
} catch (Exception e) { |
|||
String errorMsg = null; |
|||
if (e instanceof ValidateException) { |
|||
errorMsg = ((ValidateException) e).getMsg(); |
|||
} else { |
|||
errorMsg = "未知错误"; |
|||
log.error("【公共服务管理导入】出错:{}", ExceptionUtils.getErrorStackTrace(e)); |
|||
} |
|||
|
|||
IcPublicServiceExcel.RowRemarkMessage errorRow = new IcPublicServiceExcel.RowRemarkMessage(); |
|||
errorRow.setName(data.getName()); |
|||
errorRow.setCategoryName(data.getCategoryName()); |
|||
errorRow.setAddress(data.getAddress()); |
|||
errorRow.setErrorInfo(errorMsg); |
|||
errorRows.add(errorRow); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void doAfterAllAnalysed(AnalysisContext context) { |
|||
// 最后几条达不到阈值,这里必须再调用一次
|
|||
execPersist(); |
|||
} |
|||
|
|||
/** |
|||
* 执行持久化 |
|||
*/ |
|||
private void execPersist() { |
|||
try { |
|||
List<IcCoverageCategoryDictListResultDTO> dictList = coverageService.dictMap(currentCustomerId, "public_service"); |
|||
Map<String, String> dictMap = dictList.stream().collect(Collectors.toMap(IcCoverageCategoryDictListResultDTO::getCategoryKey, IcCoverageCategoryDictListResultDTO::getCategoryName)); |
|||
datas.forEach(d -> { |
|||
d.setCategory(dictMap.get(d.getCategory())); |
|||
}); |
|||
IcPublicServiceServiceImpl.insertBatch(datas); |
|||
|
|||
} finally { |
|||
datas.clear(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 获取错误行 |
|||
* |
|||
* @return |
|||
*/ |
|||
public List<IcPublicServiceExcel.RowRemarkMessage> getErrorRows() { |
|||
return errorRows; |
|||
} |
|||
} |
@ -0,0 +1,134 @@ |
|||
package com.epmet.excel.handler; |
|||
|
|||
import com.alibaba.excel.context.AnalysisContext; |
|||
import com.alibaba.excel.read.listener.ReadListener; |
|||
import com.epmet.commons.tools.exception.ExceptionUtils; |
|||
import com.epmet.commons.tools.exception.ValidateException; |
|||
import com.epmet.commons.tools.utils.ConvertUtils; |
|||
import com.epmet.commons.tools.validator.ValidatorUtils; |
|||
import com.epmet.dto.result.IcCoverageCategoryDictListResultDTO; |
|||
import com.epmet.dto.result.IcSuperiorResourceListResultDTO; |
|||
import com.epmet.entity.IcSuperiorResourceEntity; |
|||
import com.epmet.excel.IcSuperiorResourceExcel; |
|||
import com.epmet.service.CoverageService; |
|||
import com.epmet.service.impl.IcSuperiorResourceServiceImpl; |
|||
import lombok.Data; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.stream.Collectors; |
|||
|
|||
/** |
|||
* 优势资源管理excel导入监听器 |
|||
*/ |
|||
@Data |
|||
@Slf4j |
|||
public class IcSuperiorResourceExcelImportListener implements ReadListener<IcSuperiorResourceExcel> { |
|||
|
|||
//最大条数阈值
|
|||
public static final int MAX_THRESHOLD = 200; |
|||
private String currentUserId; |
|||
private String currentCustomerId; |
|||
private String currentAgencyId; |
|||
private String currentAgencyPids; |
|||
|
|||
//数据
|
|||
private List<IcSuperiorResourceEntity> datas = new ArrayList<>(); |
|||
//错误项列表
|
|||
private List<IcSuperiorResourceExcel.RowRemarkMessage> errorRows = new ArrayList<>(); |
|||
//其他被标记出来的列表列表
|
|||
private List<IcSuperiorResourceExcel.RowRemarkMessage> otherRows = new ArrayList<>(); |
|||
private IcSuperiorResourceServiceImpl icSuperiorResourceServiceImpl; |
|||
private CoverageService coverageService; |
|||
|
|||
public IcSuperiorResourceExcelImportListener(String currentUserId, String currentCustomerId, String currentAgencyId, String currentAgencyPids, IcSuperiorResourceServiceImpl icSuperiorResourceServiceImpl, CoverageService coverageService) { |
|||
this.currentUserId = currentUserId; |
|||
this.currentCustomerId = currentCustomerId; |
|||
this.currentAgencyId = currentAgencyId; |
|||
this.currentAgencyPids = currentAgencyPids; |
|||
this.icSuperiorResourceServiceImpl = icSuperiorResourceServiceImpl; |
|||
this.coverageService = coverageService; |
|||
} |
|||
|
|||
@Override |
|||
public void invoke(IcSuperiorResourceExcel data, AnalysisContext context) { |
|||
|
|||
try { |
|||
// 先校验数据
|
|||
ValidatorUtils.validateEntity(data); |
|||
|
|||
// 去除前后空格
|
|||
if (StringUtils.isNotBlank(data.getName())) { |
|||
data.setName(data.getName().trim()); |
|||
} |
|||
if (StringUtils.isNotBlank(data.getCategoryName())) { |
|||
data.setCategoryName(data.getCategoryName().trim()); |
|||
} |
|||
if (StringUtils.isNotBlank(data.getAddress())) { |
|||
data.setAddress(data.getAddress().trim()); |
|||
} |
|||
|
|||
IcSuperiorResourceEntity icSuperiorResourceEntity = ConvertUtils.sourceToTarget(data, IcSuperiorResourceEntity.class); |
|||
icSuperiorResourceEntity.setSourceType("import"); |
|||
icSuperiorResourceEntity.setCategory(data.getCategoryName()); |
|||
icSuperiorResourceEntity.setAreaCovered(data.getAreaCoveredName()); |
|||
icSuperiorResourceEntity.setCapacity(data.getCapacityName()); |
|||
datas.add(icSuperiorResourceEntity); |
|||
|
|||
if (datas.size() == MAX_THRESHOLD) { |
|||
execPersist(); |
|||
} |
|||
} catch (Exception e) { |
|||
String errorMsg = null; |
|||
if (e instanceof ValidateException) { |
|||
errorMsg = ((ValidateException) e).getMsg(); |
|||
} else { |
|||
errorMsg = "未知错误"; |
|||
log.error("【优势资源管理导入】出错:{}", ExceptionUtils.getErrorStackTrace(e)); |
|||
} |
|||
|
|||
IcSuperiorResourceExcel.RowRemarkMessage errorRow = new IcSuperiorResourceExcel.RowRemarkMessage(); |
|||
errorRow.setName(data.getName()); |
|||
errorRow.setCategoryName(data.getCategoryName()); |
|||
errorRow.setAddress(data.getAddress()); |
|||
errorRow.setErrorInfo(errorMsg); |
|||
errorRows.add(errorRow); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void doAfterAllAnalysed(AnalysisContext context) { |
|||
// 最后几条达不到阈值,这里必须再调用一次
|
|||
execPersist(); |
|||
} |
|||
|
|||
/** |
|||
* 执行持久化 |
|||
*/ |
|||
private void execPersist() { |
|||
try { |
|||
List<IcCoverageCategoryDictListResultDTO> dictList = coverageService.dictMap(currentCustomerId, "superior_resource"); |
|||
Map<String, String> dictMap = dictList.stream().collect(Collectors.toMap(IcCoverageCategoryDictListResultDTO::getCategoryKey, IcCoverageCategoryDictListResultDTO::getCategoryName)); |
|||
datas.forEach(d -> { |
|||
d.setCategory(dictMap.get(d.getCategory())); |
|||
}); |
|||
icSuperiorResourceServiceImpl.insertBatch(datas); |
|||
|
|||
} finally { |
|||
datas.clear(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 获取错误行 |
|||
* |
|||
* @return |
|||
*/ |
|||
public List<IcSuperiorResourceExcel.RowRemarkMessage> getErrorRows() { |
|||
return errorRows; |
|||
} |
|||
} |
Loading…
Reference in new issue