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

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


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

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

	@Override
	public void invoke(Map<Integer, String> map, AnalysisContext analysisContext) {
		CgJsbzExcel excel = new CgJsbzExcel();
		excel.setXh(map.get(0));
		excel.setZbh(map.get(1));
		excel.setZbmc(map.get(2));
		excel.setBzlb(map.get(3));
		excel.setBbbm(map.get(4));
		excel.setQcdw(map.get(5));
		excel.setCyr(map.get(6));
		excel.setSsrq(ValidationUtils.safeParseDate(map.get(7), DateUtil.PATTERN_DATE));
		excel.setState(map.get(8));
		excel.setCyZc(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());
	}
}
