EasyExcel 导入判断表头是否一致

package com.shimu.mes.base.services.export;
 
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
 
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.util.ListUtils;
import com.shimu.mes.base.commons.ApiException;
import com.shimu.mes.base.commons.ResCodeCache;
import com.shimu.mes.base.entities.dto.OaSalarySlip3ImportData;
import com.shimu.mes.base.models.TOaSalarySlip3;
import com.shimu.mes.base.models.TUser;
import com.shimu.mes.base.services.TOaSalarySlip3Service;
import com.shimu.mes.base.services.TUserService;
 
import lombok.extern.slf4j.Slf4j;
 
import java.util.List;
import java.util.Map;
 
@Slf4j
public class XXXListener implements ReadListener<XXX> {
 
 
    @Override
    public void invokeHead(Map<Integer, ReadCellData<?>> headMap, AnalysisContext context) {
        log.info("管理:解析到一条头数据:{}", JSONUtil.toJsonStr(headMap));
        if (context.readRowHolder().getRowIndex() == 0) {
            String[] headList = {
                "工号",
                "姓名",
                "月工龄工资",
                "月基本工资",
                "岗位津贴",
                "保密津贴",
                "周六加班费",
                "5S&安全专项考核工资",
                "月绩效考核",
                "满勤",
                "申请费用(病假工资补贴)",
                "疫情在岗激励方案出勤补贴",
                "缺勤扣款",
                "水电费扣款",
                "应税所得",
                "社保企业",
                "社保个人",
                "公积金企业",
                "公积金个人",
                "本月应缴个税",
                "实得工资",
                "人工成本"
            };
            for (int i = 0; i < headList.length; i++) {
                if (!headMap.get(i).getStringValue().equals(headList[i])) {
                    throw new ApiException("5013");
                }
            }
        }
    }
}

你可能感兴趣的:(java,easyexcel)