package com.izouma.wenlvju.utils.excel;

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;

public class BooleanConverter implements Converter<Boolean> {
    @Override
    public Class supportJavaTypeKey() {
        return Boolean.class;
    }

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

    @Override
    public Boolean convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        String stringValue = cellData.getStringValue();
        if ("是".equals(stringValue)) {
            stringValue = "TRUE";
        } else if ("否".equals(stringValue)) {
            stringValue = "FALSE";
        }
        return Boolean.valueOf(stringValue);
    }

    @Override
    public CellData convertToExcelData(Boolean booleanValue, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        String str = "";
        if (booleanValue != null) {
            str = booleanValue ? "是" : "否";
        }
        return new CellData(str);
    }
}
