package com.prolog.eis.strategy.store;

import com.prolog.eis.constants.cache.EisCache;
import com.prolog.eis.dto.strategy.ContainerInfoDto;
import com.prolog.eis.dto.strategy.InitDto;
import com.prolog.eis.dto.strategy.OrderDto;
import com.prolog.eis.outbound_dispatch.DispatchStrategy;
import com.prolog.eis.service.container.ContainerInfoService;
import com.prolog.eis.service.outbound.BizOutboundTaskService;
import com.prolog.eis.store_init.StoreInitStrategy;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author wk
 */
@Component
@RequiredArgsConstructor
public class BasicStationStoreStrategy extends StoreInitStrategy {

    private final ContainerInfoService containerInfoService;

    private final BizOutboundTaskService bizOutboundTaskService;

    private final BasicStoreStrategyService storeStrategyService;

    @Override
    public InitDto getInitDto(String billType, String warehouseArea, DispatchStrategy dispatchStrategy) throws Exception {
        InitDto initDto = new InitDto();
        //获取订单
        List<OrderDto> orderDtoList = bizOutboundTaskService.getOutboundTaskByBillType(billType, warehouseArea, dispatchStrategy);
        if (orderDtoList.isEmpty()) {
            throw new Exception("无可用订单");
        }
        initDto.setOrderList(orderDtoList);
        //获取库存
        List<ContainerInfoDto> containerInfoDtoList = containerInfoService.getContainerInfoDto(warehouseArea,billType);
        if (containerInfoDtoList.isEmpty()) {
            throw new Exception("无可用库存");
        }
        storeStrategyService.getContainerLocation(containerInfoDtoList,warehouseArea);
        storeStrategyService.getAreaTask(containerInfoDtoList);
        initDto.setContainerInfoDtoList(containerInfoDtoList);

        //获取排序策略
        initDto.setStrategyMap(EisCache.PALLET_POSITIONING_STRATEGY_MAP);

        return initDto;
    }

}
