package com.muchinfo.mtp3pojos.exportconverter;

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;

public class WrTradeOrderStatusConverter implements Converter<Integer> {

    private static final String TYPE_1 = "委托请求";
    private static final String TYPE_2 = "待冻结";
    private static final String TYPE_3 = "委托成功";
    private static final String TYPE_4 = "委托失败";
    private static final String TYPE_5 = "配对成功";
    private static final String TYPE_6 = "已撤销";
    private static final String TYPE_7 = "部成";
    private static final String TYPE_8 = "已成";
    private static final String TYPE_9 = "部成部撤";
    private static final String TYPE_10 = "成交失败";
    private static final String TYPE_11 = "委托拒绝";
    private static final String TYPE_12 = "经过摘牌";
    private static final String TYPE_13 = "冻结成功(通道交易专用)";
    private static final String TYPE_14 = "通道已撤";
    private static final String TYPE_15 = "通道部成部撤";
    private static final String TYPE_16 = "成交失败违约(荷兰式竞拍专用)";
    private static final String TYPE_17 = "冻结PD成功";
    private static final String TYPE_18 = "冻结PD失败";
    private static final String TYPE_19 = "冻结能量成功";
    private static final String TYPE_20 = "冻结能量失败";
    private static final String TYPE_21 = "预约已报价";
    private static final String TYPE_22 = "过期未付";
    private static final String TYPE_23 = "优惠券处理中";
    private static final String TYPE_24 = "仓单生成失败";
    private static final String TYPE_25 = "首付扣款失败";
    private static final String TYPE_26 = "履约失败";
    private static final String TYPE_27 = "撤单解冻货款失败";

    @Override
    public Class<?> supportJavaTypeKey() {
        // 实体类中对象属性类型
        return Integer.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        // Excel中对应的CellData属性类型
        return CellDataTypeEnum.STRING;
    }

    @Override
    public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        // 从Cell中读取数据
        String gender = cellData.getStringValue();
        // 判断Excel中的值，将其转换为预期的数值
        if (TYPE_1.equals(gender)) {
            return 1;
        } else if (TYPE_2.equals(gender)) {
            return 2;
        } else if (TYPE_3.equals(gender)) {
            return 3;
        } else if (TYPE_4.equals(gender)) {
            return 4;
        } else if (TYPE_5.equals(gender)) {
            return 5;
        } else if (TYPE_6.equals(gender)) {
            return 6;
        } else if (TYPE_7.equals(gender)) {
            return 7;
        } else if (TYPE_8.equals(gender)) {
            return 8;
        } else if (TYPE_9.equals(gender)) {
            return 9;
        } else if (TYPE_10.equals(gender)) {
            return 10;
        } else if (TYPE_11.equals(gender)) {
            return 11;
        } else if (TYPE_12.equals(gender)) {
            return 12;
        } else if (TYPE_13.equals(gender)) {
            return 13;
        } else if (TYPE_14.equals(gender)) {
            return 14;
        } else if (TYPE_15.equals(gender)) {
            return 15;
        } else if (TYPE_16.equals(gender)) {
            return 16;
        } else if (TYPE_17.equals(gender)) {
            return 17;
        } else if (TYPE_18.equals(gender)) {
            return 18;
        } else if (TYPE_19.equals(gender)) {
            return 19;
        } else if (TYPE_20.equals(gender)) {
            return 20;
        } else if (TYPE_21.equals(gender)) {
            return 21;
        } else if (TYPE_22.equals(gender)) {
            return 22;
        } else if (TYPE_23.equals(gender)) {
            return 23;
        } else if (TYPE_24.equals(gender)) {
            return 24;
        } else if (TYPE_25.equals(gender)) {
            return 25;
        } else if (TYPE_26.equals(gender)) {
            return 26;
        } else if (TYPE_27.equals(gender)) {
            return 27;
        }
        return null;
    }

    @Override
    public WriteCellData<?> convertToExcelData(Integer integer, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        // 判断实体类中获取的值，转换为Excel预期的值，并封装为CellData对象
        if (integer == null) {
            return new WriteCellData<>("");
        } else if (integer == 1) {
            return new WriteCellData<>(TYPE_1);
        } else if (integer == 2) {
            return new WriteCellData<>(TYPE_2);
        } else if (integer == 3) {
            return new WriteCellData<>(TYPE_3);
        } else if (integer == 4) {
            return new WriteCellData<>(TYPE_4);
        } else if (integer == 5) {
            return new WriteCellData<>(TYPE_5);
        } else if (integer == 6) {
            return new WriteCellData<>(TYPE_6);
        } else if (integer == 7) {
            return new WriteCellData<>(TYPE_7);
        } else if (integer == 8) {
            return new WriteCellData<>(TYPE_8);
        } else if (integer == 9) {
            return new WriteCellData<>(TYPE_9);
        } else if (integer == 10) {
            return new WriteCellData<>(TYPE_10);
        } else if (integer == 11) {
            return new WriteCellData<>(TYPE_11);
        } else if (integer == 12) {
            return new WriteCellData<>(TYPE_12);
        } else if (integer == 13) {
            return new WriteCellData<>(TYPE_13);
        } else if (integer == 14) {
            return new WriteCellData<>(TYPE_14);
        } else if (integer == 15) {
            return new WriteCellData<>(TYPE_15);
        } else if (integer == 16) {
            return new WriteCellData<>(TYPE_16);
        } else if (integer == 17) {
            return new WriteCellData<>(TYPE_17);
        } else if (integer == 18) {
            return new WriteCellData<>(TYPE_18);
        } else if (integer == 19) {
            return new WriteCellData<>(TYPE_19);
        } else if (integer == 20) {
            return new WriteCellData<>(TYPE_20);
        } else if (integer == 21) {
            return new WriteCellData<>(TYPE_21);
        } else if (integer == 22) {
            return new WriteCellData<>(TYPE_22);
        } else if (integer == 23) {
            return new WriteCellData<>(TYPE_23);
        } else if (integer == 24) {
            return new WriteCellData<>(TYPE_24);
        } else if (integer == 25) {
            return new WriteCellData<>(TYPE_25);
        } else if (integer == 26) {
            return new WriteCellData<>(TYPE_25);
        } else if (integer == 27) {
            return new WriteCellData<>(TYPE_27);
        }
        return new WriteCellData<>("");
    }
}
