package com.prolog.eis.pallet_positioning;

import com.prolog.eis.dto.strategy.ContainerInfoDto;

import java.math.BigDecimal;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author wk
 * 库存定位策略   -->效率优先
 */
public class EfficiencyStrategy extends PositioningStrategy<ContainerInfoDto> {

    public EfficiencyStrategy(int order) {
        this.order = order;
    }

    @Override
    public List<ContainerInfoDto> sort(List<ContainerInfoDto> list, BigDecimal qty) {
        System.out.println("排序策略");
        List<ContainerInfoDto> collect = list.stream().filter(x -> x.getQty().compareTo(qty) == 0).collect(Collectors.toList());
        if (collect.isEmpty()) {
            list.sort(Comparator.comparing(ContainerInfoDto::getQty).reversed());
            ContainerInfoDto containerInfoDto = list.get(0);
            List<ContainerInfoDto> collect1 = list.stream().filter(x -> x.getQty().compareTo(containerInfoDto.getQty()) == 0).collect(Collectors.toList());
            return collect1;
        } else {
            return collect;
        }
    }
}
