package com.prolog.eis.dto.buildwave;

import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.*;

@Getter
@Setter
public class PObOrderDto {
    @ApiModelProperty("运单号")
    private int orderId;

    @ApiModelProperty("体积")
    private BigDecimal volume = new BigDecimal(0);

    @ApiModelProperty("商品集合")
    private List<PObOrderDetailDto> detailList = new ArrayList<>();
    //*****以下非查询*****
    @ApiModelProperty("库存需求（合并同itemNo订单明细得到）")
    private Map<String, BigDecimal> detailStoreMap = new HashMap<>();

    @ApiModelProperty("匹配数量")
    private int matchCount;

    @ApiModelProperty("不匹配数量")
    private int notMatchCount;

    public void init() {
        this.initDetailStore();
    }

    private void initDetailStore() {
        this.detailStoreMap.clear();

        for (PObOrderDetailDto detail : detailList) {
            if (detailStoreMap.containsKey(detail.getItemNo())) {
                BigDecimal val = detailStoreMap.get(detail.getItemNo());
                detailStoreMap.put(detail.getItemNo(), val.add(detail.getPlanNum()));
            } else {
                detailStoreMap.put(detail.getItemNo(), detail.getPlanNum());
            }
        }
    }

    public String toString() {
        return String.format("NO:%s,品类数:%s,匹配:%s,不匹配:%s",
                this.getOrderId(), this.getDetailStoreMap().size(), this.getMatchCount(), this.getNotMatchCount());
    }
}
