package cn.superdesk.uniorder.common.excel.converters.artificial;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.superdesk.uniorder.common.json.AnJsonUtils;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;


/**
 * @Description: Java类作用描述
 * @Author: linjinyu
 * @CreateDate: 2021/4/25 下午4:15
 * @UpdateUser: linjinyu
 * @UpdateDate: 2021/4/25 下午4:15
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
public class CustomStringDateConverter implements Converter<Date> {

	@Override
	public Class supportJavaTypeKey() {
		return Date.class;
	}

	@Override
	public CellDataTypeEnum supportExcelTypeKey() {
		return CellDataTypeEnum.STRING;
	}

	@Override
	public Date convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {

		log.info("Ecxel 读出来 日期换转\n{}\n{}\n{}\n", cellData.getStringValue(), AnJsonUtils.toJson(contentProperty), AnJsonUtils.toJson(globalConfiguration));

		String processTmp = cellData.getStringValue();

		if ("重新开票".equals(processTmp) || StrUtil.isEmpty(processTmp)) {

			log.info("Ecxel 读出来 日期换转 返回\n{}", "null");
			return null;
		} else {

//			log.info("Ecxel 读出来 日期换转 返回\n{}", (Date) cellData.getData());
//			return (Date) cellData.getData();

			log.info("Ecxel 读出来 日期换转 返回\n{}", DateUtil.parseDate(processTmp));
			return DateUtil.parseDate(processTmp);
		}

	}

	@Override
	public CellData convertToExcelData(Date value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
		return null;
	}
}
