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

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

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

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

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

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