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

import com.prolog.eis.feign.InventoryFeign;
import com.prolog.eis.service.shelves.InventoryService;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.upcloud.base.inventory.model.BatchNumberSync;
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.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<BatchNumberSync> findByBatchNum(String batchNum) throws Exception {
        RestMessage<List<BatchNumberSync>> restMessage = inventoryFeign.findByBatchNum(batchNum);
        if (!restMessage.isSuccess()) {
            throw new Exception("根据批号查询批次异常：" + restMessage.getMessage());
        }
        return restMessage.getData();
    }
}
