package com.yonge.cooleshow.biz.dal.convert;

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 com.yonge.cooleshow.biz.dal.enums.OrderTypeEnum;

/**
 * @Author: liweifan
 * @Data: 2022/4/15 15:36
 */
public class OrderTypeConvert implements Converter<OrderTypeEnum> {

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

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

    @Override
    public OrderTypeEnum convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        try {
            return OrderTypeEnum.valueOf(cellData.getStringValue());
        }catch (Exception e){
            return null;
        }
    }

    @Override
    public CellData convertToExcelData(OrderTypeEnum statusEnum, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        if(null != statusEnum){
            return new CellData(statusEnum.getCode());
        }
        return new CellData("异常数据");
    }
}
