SignInStatusConverter.java 1.57 KB
package com.ruoyi.pojo.converter;

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 static com.ruoyi.common.ConstSignInConstSignInProperties.*;

/**
 * @author 20412
 * 签到成功还是失败转换
 */
@SuppressWarnings(value = {"unchecked", "rawtypes"})
public class SignInStatusConverter implements Converter<Integer> {
    @Override
    public Class supportJavaTypeKey() {
        return Integer.class;
    }

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

    @Override
    public Integer convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        String value = cellData.getStringValue();
        if (SIGN_IN_SUCCESS_STRING.equals(value)){
            return 1;
        }
        if (SIGN_IN_FAIL_STRING.equals(value)){
            return 2;
        }
        return Integer.parseInt(value);
    }

    @Override
    public CellData convertToExcelData(Integer integer, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        String str = "";
        if (SIGN_IN_SUCCESS.equals(integer)){
            str = SIGN_IN_SUCCESS_STRING;
        }
        if (SIGN_IN_FAIL.equals(integer)){
            str = SIGN_IN_FAIL_STRING;
        }
        return new CellData(str);
    }
}