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

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

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

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

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

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