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.OrderStatusEnum;

/**
 * @Author: liweifan
 * @Data: 2022/4/15 15:45
 */
public class OrderStatusConvert implements Converter<OrderStatusEnum> {

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

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

    /***
     * WAIT_PAY("WAIT_PAY","待支付"),
     *     PAYING("PAYING","支付中"),
     *     PAID("PAID","已付款"),
     *     CLOSE("CLOSE","已关闭")
     */
    @Override
    public OrderStatusEnum convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        try {
            return OrderStatusEnum.valueOf(cellData.getStringValue());
        }catch (Exception e){
            return null;
        }
    }

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