package cn.superdesk.uniorder.common.excel.utils;


import cn.superdesk.uniorder.common.excel.model.ExcelRow;
import cn.superdesk.uniorder.common.excel.strategy.postil.ExcelImportExportAddPostilRowWriteHandler;
import cn.superdesk.uniorder.common.excel.strategy.postil.ExcelImportExportAddPostilSheetWriteHandler;
import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import com.alibaba.excel.EasyExcel;
import lombok.Builder;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.TreeMap;


/**
 * @Description: 对账 ExcelImportReader 用的 看要不要把名字改成 ExcelImportExport
 * @Author: linjinyu
 * @CreateDate: 2021/8/24 上午11:05
 * @UpdateUser: linjinyu
 * @UpdateDate: 2021/8/24 上午11:05
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@Builder
public class ExcelImportExport {

	private LoginSysUser loginSysUser;

	private String batchId;

	private String fileFullPath;


//	public ;

	//	public <T extends ExcelRow> List<T> read(Class<T> tClass)
	public <T extends ExcelRow> void write(List<T> excelData, Class<T> headClazz) {

//		EasyExcel.write(fileFullPath, headClazz)
//				.inMemory(Boolean.TRUE)
//				.registerWriteHandler(new ExcelImportExportAddPostilSheetWriteHandler(headClazz, batchId))
//				.registerWriteHandler(new ExcelImportExportAddPostilRowWriteHandler(headClazz, batchId))
//				.sheet("批注")
//				.doWrite(excelData);

		EasyExcel
				.write(fileFullPath, headClazz)
				.inMemory(Boolean.TRUE)
				.registerWriteHandler(
						ExcelImportExportAddPostilSheetWriteHandler.<T>builder()
								.headClazz(headClazz)
								.batchId(batchId)
								.convertAllFiled(false)
								.needIgnore(false)
								.sortedAllFiledMap(new TreeMap<Integer, Field>())
								.indexFiledMap(new TreeMap<Integer, Field>())
								.filedIndexMap(new HashMap<>())
								.loginSysUser(loginSysUser)
								.build()
				)
				.registerWriteHandler(
						ExcelImportExportAddPostilRowWriteHandler.<T>builder()
								.headClazz(headClazz)
								.batchId(batchId)
								.convertAllFiled(false)
								.needIgnore(false)
								.sortedAllFiledMap(new TreeMap<Integer, Field>())
								.indexFiledMap(new TreeMap<Integer, Field>())
								.filedIndexMap(new HashMap<>())
								.loginSysUser(loginSysUser)
								.build()
				)
				.sheet("批注")
				.doWrite(excelData);
	}

//	Annotation


}
