package com.prolog.eis.service.inbound.impl;

import com.prolog.eis.feign.InventoryFeign;
import com.prolog.eis.service.inbound.InventoryService;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.upcloud.base.inventory.model.BatchNumberSync;
import com.prolog.upcloud.base.inventory.model.WmsInvBatchNumbers;
import com.prolog.upcloud.base.inventory.vo.batchInfo.BatchNumberSyncQueryVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Slf4j
@Service
public class InventoryServiceImpl implements InventoryService {

    @Autowired
    InventoryFeign inventoryFeign;

    @Override
    public List<BatchNumberSync> getBatchNumberSync(List<String> batchIdList) throws Exception {
        BatchNumberSyncQueryVO batchNumberSyncQueryVO = new BatchNumberSyncQueryVO();
        batchNumberSyncQueryVO.setPkIds(batchIdList);
        RestMessage<List<BatchNumberSync>> result = inventoryFeign.findAllBatch(batchNumberSyncQueryVO);
        if (result.isSuccess()) {
            if (result.getData().isEmpty()) {
                throw new Exception("未找到批次对应的信息");
            }
            return result.getData();
        }
        return null;
    }

    @Override
    public List<WmsInvBatchNumbers> getListByManufacturerLotNums(String manufacturerLotNums) throws Exception {
        RestMessage<List<WmsInvBatchNumbers>> result = inventoryFeign.getListByManufacturerLotNums(manufacturerLotNums);
        if (result.isSuccess()) {
            if (result.getData().isEmpty()) {
                throw new Exception("未找到批次对应的信息");
            }
            return result.getData();
        }
        return null;
    }
}
