ErpGenerateBill.java 1.73 KB
package com.huaheng.api.general.domain;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import lombok.Data;
import org.apache.commons.lang.StringEscapeUtils;

import java.util.ArrayList;
import java.util.List;

@Data
public class ErpGenerateBill {
    /**ERP单据类型**/
    @JSONField(name = "ErpBillType")
    String ErpBillType;

    /**仓库编号**/
    @JSONField(name = "StockCode")
    String StockCode;

    /**单据单别**/
    @JSONField(name = "BillType")
    String BillType;

    @JSONField(name = "GenBillDetails")
    List<ErpGenBillDetail> GenBillDetails;

    public static ErpGenerateBill transformate(ReceiptHeader header, List<ReceiptDetail> list){
        ErpGenerateBill bill = new ErpGenerateBill();
        bill.setErpBillType(header.getReceiptType());
        bill.setBillType(header.getBillType());
        bill.setStockCode(header.getWarehouseCode());
        List<ErpGenBillDetail> bills = new ArrayList<>();
        for(ReceiptDetail d: list){
            ErpGenBillDetail b = new ErpGenBillDetail();
            b.setBarcode(d.getBarCode());
            b.setQuantity(d.getQty());
            bills.add(b);
        }
        bill.setGenBillDetails(bills);
        return bill;
    }

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

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