
package com.tmerclub.cloud.user.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.tmerclub.cloud.user.constant.LevelTypeEnum;

import java.util.Objects;

/**
 * Excel导出转换器，会员类型转换器，将数值转为String
 * @author cl
 * @date 2021-05-11 11:03:06
 */
public class LevelTypeConverter implements Converter<Integer> {

    @Override
    public Class<Integer> supportJavaTypeKey() {
        return Integer.class;
    }

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

    @Override
    public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
        return LevelTypeEnum.valueOf(cellData.getStringValue()).value();
    }

    @Override
    public WriteCellData<?> convertToExcelData(Integer value, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) {
        return new WriteCellData<String>(Objects.requireNonNull(LevelTypeEnum.instance(value)).desc());
    }
}
