XiaoRuby
2023-09-24 20956b0f05f81ca47cf6c3e8f9b3b426e9cfd035
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
package com.yuanchu.mom.utils.easyexcel;
 
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
/**
 * excel数据导入数据处理
 *
 * @param <T>
 * @author Zou, Yu
 */
@Slf4j
@Getter
@Setter
public class ExcelListener<T> extends AnalysisEventListener<T> {
 
    private List<T> dataList = new ArrayList<>();
 
    @Override
    public void invoke(T classType, AnalysisContext analysisContext) {
        dataList.add(classType);
    }
 
    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
    }
 
    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
        String templateHead = "";
 
        List<String> headList = new ArrayList<>();
        for (Integer i : headMap.keySet()) {
            headList.add(headMap.get(i));
        }
        String importHead = headMap.values().toString();
        log.info("importHead:{}", importHead);
        String templateName = context.getCurrentSheet().getClazz().getSimpleName();
        log.info("templateName:", templateName);
//        if ("CostModel".equals(templateName)) {
//            templateHead = templateHeadCost;
//        } else if ("StaffInfoTemplate".equals(templateName)) {
//            templateHead = templateHeadStaff;
//        } else if ("OrganizationTemplate".equals(templateName)) {
//            templateHead = templateHeadOrganization;
//        }else if ("StaffDictionaryTemplate".equals(templateName)) {
//            templateHead = templateHeadDictionary;
//        }else if ("StaffCtfTemplate".equals(templateName)){
//            templateHead = templateHeadCtf;
//        }else if ("IndustryLineTemplate".equals(templateName)){
//            templateHead = templateHeadIndustryLine;
//        }else if ("SubServiceLineTemplate".equals(templateName)){
//            templateHead = templateHeadSubServiceLine;
//        }else if ("StaffHealthTemplate".equals(templateName)){
//            templateHead = templateHeadHealth;
//        }else if ("AccountDataTemplate".equals(templateName)){
//            templateHead = templateAccountData;
//        }else if ("PlInfoTemplate".equals(templateName)){
//            templateHead = templatePlInfo;
//        }else if ("CodeDataTemplate".equals(templateName)){
//            templateHead = templateCodeData;
//        }else if ("CodeTbdDataTemplate".equals(templateName)){
//            templateHead = templateCodeTbdData;
//        }
 
        if (!templateHead.equals(importHead)) {
            throw new RuntimeException(ResponseResultEnum.EXCEL_MODEL_ERROR.getMessage());
        }
 
    }
 
}