package com.fs.erp.domain;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;

@Data
public class KbStockResponse {

    /**
     * true：请求成功；false：请求失败；
     */
    @JSONField(name = "IsSuccess")
    private Boolean success;

    /**
     * 提示消息
     */
    @JSONField(name = "errmsg")
    private String msg;

    /**
     * 返回数据
     */
    @JSONField(name = "data")
    private String data;

    /**
     * 库存
     */
    private Integer stock;

    public Integer getStock() {
        int stocks = 0;
        JSONArray dataArray = JSON.parseArray(this.data);
        for (int i = 0; i < dataArray.size(); i++) {
            JSONObject base = dataArray.getJSONObject(i);
            for (Object item : base.getJSONArray("base")) {
                JSONObject json = (JSONObject) item;
                stocks += json.getIntValue("fqty");
            }
        }

        return stocks;
    }
}
