package com.prolog.eis.dto.buildwave;

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

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Version: 1.0
 * @Author: wuhan
 * @Created: 2024/7/30 11:53
 */
@Getter
@Setter
public class BuildWaveDispatchDto {
    @ApiModelProperty("单个波次最大订单数")
    private int maxWaveOrderCount;

    @ApiModelProperty("尾波开关")
    private int tailWaveSwitch;

    @ApiModelProperty("所有订单集合")
    private List<PObOrderDto> orderList = new ArrayList<>();

    @ApiModelProperty("可用容器库存")
    private List<PObContainerStoreDto> containerStoreList = new ArrayList<>();

    //*****以下为计算得到*****

    @ApiModelProperty("AGV区可用品批库存")
    private Map<String, BigDecimal> storeMap = new HashMap<>();

    public void init() {
        this.storeMap.clear();
        for (PObContainerStoreDto containerStore : this.containerStoreList) {
            String storeKey = String.format("%s@@%s@@%s@@%s",
                    containerStore.getOwnerId(),
                    containerStore.getItemId(),
                    containerStore.getLotId(),
                    containerStore.getPackId());

            if (!this.storeMap.containsKey(storeKey)) {
                this.storeMap.put(storeKey, containerStore.getUseQty());
            } else {
                BigDecimal val = this.storeMap.get(storeKey);
                this.storeMap.put(storeKey, val.add(containerStore.getUseQty()));
            }
        }
    }
}
