车间能级提升-智能设备管理系统
baoshiwei
2025-04-12 beaed6d077e7c3e9abfad68acb8c587835b5a406
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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;
    }
}