package org.sky.scientific.excel.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.sky.core.tool.utils.DateUtil;
import org.sky.scientific.excel.CgKylwExcel;
import org.sky.scientific.utils.ValidationUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Data
@Slf4j
public class CgKylwImportListener implements ReadListener<Map<Integer, String>> {

 	private List<CgKylwExcel> dataList = new ArrayList<>();

	@Override
	public void invoke(Map<Integer, String> map, AnalysisContext analysisContext) {
		CgKylwExcel excel = new CgKylwExcel();
		excel.setXh(map.get(0));
		excel.setLwmc(map.get(1));
		excel.setZzxm(map.get(2));
		excel.setTxzz(map.get(3));
		excel.setDyzzdw(map.get(4));
		excel.setFbrq(ValidationUtils.safeParseDate(map.get(5), DateUtil.PATTERN_DATE));
		excel.setQkmc(map.get(6));
		excel.setKjh(map.get(7));
		excel.setQklx(map.get(8));
		excel.setQkjb(map.get(9));
		excel.setXmmc(map.get(10));
		excel.setXmbh(map.get(11));
		dataList.add(excel);
	}

	@Override
	public void doAfterAllAnalysed(AnalysisContext analysisContext) {
		log.info("解析科研成果-科研论文：{}条", dataList.size());
	}
}
