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

/**
 * Description
 *
 * @author liujunchi
 * @date 2022-05-20
 */
public class ChargeTypeConverter implements Converter<ChargeTypeEnum> {
    @Override
    public Class supportJavaTypeKey() {
        return AudioTypeEnum.class;
    }

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

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

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