package org.dromara.eims.listener;
|
|
import com.alibaba.excel.context.AnalysisContext;
|
import com.alibaba.excel.event.AnalysisEventListener;
|
import lombok.Data;
|
import lombok.extern.slf4j.Slf4j;
|
import org.dromara.common.excel.core.ExcelListener;
|
import org.dromara.common.excel.core.ExcelResult;
|
import org.dromara.eims.domain.vo.MaintCheckItemVo;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* 保养点检项目导入监听器
|
*
|
* @author Lion Li
|
*/
|
@Data
|
@Slf4j
|
public class MaintCheckItemImportListener extends AnalysisEventListener<MaintCheckItemVo> implements ExcelListener<MaintCheckItemVo> {
|
|
/**
|
* 成功条数
|
*/
|
private Integer successCount = 0;
|
|
/**
|
* 失败条数
|
*/
|
private Integer failureCount = 0;
|
|
/**
|
* 导入成功数据列表
|
*/
|
private List<MaintCheckItemVo> successList = new ArrayList<>();
|
|
/**
|
* 导入失败数据列表
|
*/
|
private List<MaintCheckItemVo> failureList = new ArrayList<>();
|
|
public MaintCheckItemImportListener(Boolean isUpdateSupport) {
|
super();
|
}
|
|
@Override
|
public void invoke(MaintCheckItemVo data, AnalysisContext context) {
|
try {
|
// 数据校验
|
if (!validateData(data)) {
|
failureList.add(data);
|
failureCount++;
|
return;
|
}
|
successList.add(data);
|
successCount++;
|
} catch (Exception e) {
|
failureList.add(data);
|
failureCount++;
|
log.error("导入保养点检项目失败:", e);
|
}
|
}
|
|
@Override
|
public void doAfterAllAnalysed(AnalysisContext context) {
|
log.info("保养点检项目导入完成,成功:{}条,失败:{}条", successCount, failureCount);
|
}
|
|
/**
|
* 校验数据
|
*
|
* @param data 待校验数据
|
* @return 校验结果
|
*/
|
private boolean validateData(MaintCheckItemVo data) {
|
if (data.getItemName() == null || data.getItemName().trim().isEmpty()) {
|
return false;
|
}
|
if (data.getPeriod() == null || data.getPeriod().trim().isEmpty()) {
|
return false;
|
}
|
|
// 校验1-12月份状态值
|
return validateMonthStatus(data.getJanuary())
|
&& validateMonthStatus(data.getFebruary())
|
&& validateMonthStatus(data.getMarch())
|
&& validateMonthStatus(data.getApril())
|
&& validateMonthStatus(data.getMay())
|
&& validateMonthStatus(data.getJune())
|
&& validateMonthStatus(data.getJuly())
|
&& validateMonthStatus(data.getAugust())
|
&& validateMonthStatus(data.getSeptember())
|
&& validateMonthStatus(data.getOctober())
|
&& validateMonthStatus(data.getNovember())
|
&& validateMonthStatus(data.getDecember());
|
}
|
|
/**
|
* 校验月份状态值
|
*
|
* @param status 状态值
|
* @return 校验结果
|
*/
|
private boolean validateMonthStatus(String status) {
|
// 状态值可以为空
|
if (status == null || status.trim().isEmpty()) {
|
return true;
|
}
|
// 状态值必须符合规范(根据实际业务需求定义有效的状态值)
|
return true;
|
}
|
|
@Override
|
public ExcelResult<MaintCheckItemVo> getExcelResult() {
|
return null;
|
}
|
}
|