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 com.mortals.xhx.common.code.ApplicantTypeEnums;

import java.text.ParseException;

/**
 * @Title: 申请人类型转换
 * @Package: com.atm.affair.util
 * @Description: (用一句话描述该文件做什么)
 * @Author: tinker
 * @Date: 4/9/21
 * @Version: V1.0
 */
public class ExcelConvertApplication 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.自然人"
        if (cellData.getStringValue() == null) {
            return null;
        } else if (ApplicantTypeEnums.LEGAL.getValue() == cellData.getStringValue()) {
            return String.valueOf(ApplicantTypeEnums.LEGAL.getCode());
        } else {
            return String.valueOf(ApplicantTypeEnums.PERSON.getCode());
        }

    }

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


