package com.mortals.xhx.common.utils;

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 java.text.ParseException;

/**
 * @Title: 机构类型转换
 * @Package: com.atm.affair.util
 * @Description: (用一句话描述该文件做什么)
 * @Author: tinker
 * @Date: 4/9/21
 * @Version: V1.0
 */
public class ExcelConvertMainProperty implements Converter<String> {
    @Override
    public Class supportJavaTypeKey() {
        return String.class;
    }

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

    @Override
    public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
                                    GlobalConfiguration globalConfiguration) throws ParseException {
        //        1	国家行政机关
//        2	事业单位
//        3	企业
//        4	其他
        if (cellData.getStringValue() == null) {
            return "";
        } else if ("国家行政机关".equals(cellData.getStringValue())) {
            return "1";
        } else if ("事业单位".equals(cellData.getStringValue())) {
            return "2";
        } else if ("企业".equals(cellData.getStringValue())) {
            return "3";
        } else if ("其他".equals(cellData.getStringValue())) {
            return "4";
        } else {
            return "4";
        }
    }

    @Override
    public CellData convertToExcelData(String value, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return null;
    }

}
