ErpBill.java 1.62 KB
package com.huaheng.api.general.domain;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import org.apache.commons.lang.StringEscapeUtils;

import java.util.List;

/**
 * ERP接口单据实体
 */
@Data
public class ErpBill {
    /**
     * ERP单据类型值
     * "ERP单据类型名称及值的对照表:
     * 生产入库 = 1,采购入库 = 2,其他入库 = 3,调拨入库 = 4,销售退货 = 5,盘盈单 = 6,
     * 销售出库 = 21,其他出库 = 22,调拨出库 = 23,采购退货 = 24,盘亏单 = 25"
     */
    @JSONField(name = "ErpBillType")
    public String ErpBillType;

    /**
     * 单据类型
     */
    @JSONField(name = "BillType")
    public String BillType;

    /**
     * 单据单号
     */
    @JSONField(name = "BillCode")
    public String BillCode;

    /**
     * 出入类型,入库=1, 出库=0
     */
    @JSONField(name = "InOrOut")
    public String InOrOut;

    @JSONField(name = "BillDetails")
    public List<ErpBillDetails> BillDetails;

    public boolean isReceipt(){
        return "1".equalsIgnoreCase(InOrOut);
    }

    public boolean isShipment(){
        return "2".equalsIgnoreCase(InOrOut);
    }

    public static ErpBill parse(String msg){
        String json = StringEscapeUtils.unescapeJava(msg);
        ErpBill obj = JSON.parseObject(json, ErpBill.class);
        return obj;
    }

    public String toRawJsonStr(){
        String s = JSON.toJSONString(this);
//        System.out.println(StringEscapeUtils.escapeJava(s));
        return s;
    }

    public String getReferCode(){
        return BillType + "-" + BillCode;
    }
}