package com.yida.data.school.transaction.listener;

import cc.mrbird.febs.common.redis.service.RedisService;
import cn.hutool.core.collection.CollUtil;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yida.data.common.core.entity.apply.EduStudentApply;
import com.yida.data.common.service.CommonService;
import com.yida.data.school.transaction.service.EduStudentApplyService;
import com.yida.data.school.vo.transcation.StudentApplyImportVO;
import com.yida.data.user.dto.ImportStudentDormDTO;
import java.util.ArrayList;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RequiredArgsConstructor
public class importStudentApplyListener extends AnalysisEventListener<StudentApplyImportVO> {


    private EduStudentApplyService eduStudentApplyService;


    private List<StudentApplyImportVO> list = new ArrayList<>();

    private String key;


    public importStudentApplyListener(EduStudentApplyService eduStudentApplyService, String key) {
        this.eduStudentApplyService = eduStudentApplyService;
        this.key = key;
    }

    @Override
    public void invoke(StudentApplyImportVO data, AnalysisContext context) {
        if (null == data) {
            log.info("excel导入失败:{}", data.toString());
        }
        list.add(data);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        saveData();
    }

    public void saveData() {
        eduStudentApplyService.insertStudentApplyData(list, key);
    }

}
