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.CgQtExcel;
import org.sky.scientific.utils.ValidationUtils;

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


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

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

	@Override
	public void invoke(Map<Integer, String> map, AnalysisContext analysisContext) {
		CgQtExcel excel = new CgQtExcel();
		excel.setXh(map.get(0));
		excel.setCgbh(map.get(1));
		excel.setCgmc(map.get(2));
		excel.setCmlx(map.get(3));
		excel.setBbbm(map.get(4));
		excel.setQlr(map.get(5));
		excel.setFmr(map.get(6));
		excel.setShenqingRq(ValidationUtils.safeParseDate(map.get(7), DateUtil.PATTERN_DATE));
		excel.setShouquanRq(ValidationUtils.safeParseDate(map.get(8), DateUtil.PATTERN_DATE));
		excel.setCanyunZhuchi(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());
	}
}
