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 DeliveryOrderStatusConverter 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 = "买方付款失败";

    @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;
        }
        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);
        }
        return new WriteCellData<>("");
    }
}
