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.common.enums.YesOrNoEnum;

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

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

    @Override
    public YesOrNoEnum convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        try {
            if ("是".equals(cellData.getStringValue())) {
                return YesOrNoEnum.YES;
            } else {
                return YesOrNoEnum.NO;
            }
        } catch (Exception e) {
            return null;
        }
    }

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