package com.prolog.upcloud.base.wh.operate.service.impl.mq;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSONObject;
import com.prolog.entity.vo.*;
import com.prolog.framework.core.exception.BizException;
import com.prolog.upcloud.base.wh.operate.model.EisLog;
import com.prolog.upcloud.base.wh.operate.service.MqOperateProducer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

import static com.prolog.constant.EisBusinessConstant.EIS;
import static com.prolog.constant.RabbitMqConstant.*;

@Service
@Slf4j
public class RabbitMqOperateProducerImpl implements MqOperateProducer {

    @Resource
    private RabbitTemplate rabbitTemplate;

    @Override
    public void outBoundRequest(List<OutBoundRequestVO> list) {
        if (CollUtil.isNotEmpty(list)) {
            rabbitTemplate.convertAndSend(WMS2EIS_OUTBOUND_REQUEST_EXCHANGE, WMS2EIS_OUTBOUND_REQUEST_ROUTING_KEY, JSONObject.toJSONString(list));
        }
    }

    @Override
    public void operationComplete(List<OperationCompleteVO> list) {
        if (CollUtil.isNotEmpty(list)) {
            rabbitTemplate.convertAndSend(WMS2EIS_OPERATION_COMPLETE_EXCHANGE, WMS2EIS_OPERATION_COMPLETE_ROUTING_KEY, JSONObject.toJSONString(list));
        }
    }

    @Override
    public void outboundTaskCallback(OutboundTaskCallbackVO vo) {
        if (vo != null) {
            rabbitTemplate.convertAndSend(EIS2WMS_OUTBOUND_TASK_CALLBACK_EXCHANGE, EIS2WMS_OUTBOUND_TASK_CALLBACK_ROUTING_KEY, JSONObject.toJSONString(vo));
        }
    }

    @Override
    public void completeTask(List<CompleteTaskVO> list) {
        if (CollUtil.isNotEmpty(list)) {
            rabbitTemplate.convertAndSend(EIS2WMS_COMPLETE_TASK_EXCHANGE, EIS2WMS_COMPLETE_TASK_ROUTING_KEY, JSONObject.toJSONString(list));
        }
    }

    @Override
    public void gspTaskCallback(OutboundTaskCallbackVO vo) {
        if (vo != null) {
            rabbitTemplate.convertAndSend(EIS2WMS_GSP_TASK_CALLBACK_EXCHANGE, EIS2WMS_GSP_TASK_CALLBACK_ROUTING_KEY, JSONObject.toJSONString(vo));
        }
    }

    @Override
    public void containerTailgatingFeedback(ContainerTailgatingFeedbackVO vo) {
        if (vo != null) {
            rabbitTemplate.convertAndSend(EIS2WMS_CONTAINER_TAILGATING_FEEDBACK_EXCHANGE, EIS2WMS_CONTAINER_TAILGATING_FEEDBACK_ROUTING_KEY, JSONObject.toJSONString(vo));
        }
    }

    @Override
    public void orderBindingGridFeedback(OrderBindingGridFeedbackVO vo) {
        if (vo != null) {
            rabbitTemplate.convertAndSend(EIS2WMS_ORDER_BINDING_GRID_FEEDBACK_EXCHANGE, EIS2WMS_ORDER_BINDING_GRID_FEEDBACK_ROUTING_KEY, JSONObject.toJSONString(vo));
        }
    }

    @Override
    public void outboundCheckResultCallback(OutboundCheckResultCallbackVO vo) {
        if (vo != null) {
            rabbitTemplate.convertAndSend(EIS2WMS_OUTBOUND_CHECK_RESULT_CALLBACK_EXCHANGE, EIS2WMS_OUTBOUND_CHECK_RESULT_CALLBACK_ROUTING_KEY, JSONObject.toJSONString(vo));
        }
    }

    @Override
    public void applyForDocumentPrinting(ApplyForDocumentPrintingVO vo) {
        if (vo != null) {
            rabbitTemplate.convertAndSend(EIS2WMS_APPLY_FOR_DOCUMENT_PRINTING_EXCHANGE, EIS2WMS_APPLY_FOR_DOCUMENT_PRINTING_ROUTING_KEY, JSONObject.toJSONString(vo));
        }
    }

    @Override
    public void applyForContainerReturnChange(ApplyForContainerReturnChangeVO vo) {
        if (vo != null) {
            rabbitTemplate.convertAndSend(EIS2WMS_APPLY_FOR_CONTAINER_RETURN_CHANGE_EXCHANGE, EIS2WMS_APPLY_FOR_CONTAINER_RETURN_CHANGE_ROUTING_KEY, JSONObject.toJSONString(vo));
        }
    }

    @Override
    public void applyForPickSlide(ApplyForPickSlideVO vo) {
        if (vo != null) {
            rabbitTemplate.convertAndSend(EIS2WMS_APPLY_FOR_PICK_SLIDE_EXCHANGE, EIS2WMS_APPLY_FOR_PICK_SLIDE_ROUTING_KEY, JSONObject.toJSONString(vo));
        }
    }

    @Override
    public void inventoryAudit(List<InventoryAuditVO> list) {
        if (CollUtil.isNotEmpty(list)) {
            rabbitTemplate.convertAndSend(WMS2EIS_INVENTORY_AUDIT_EXCHANGE, WMS2EIS_INVENTORY_AUDIT_ROUTING_KEY, JSONObject.toJSONString(list));
        }
    }

    @Override
    public void saveEisLog(EisLog eisLog) {
        if (eisLog != null) {
            rabbitTemplate.convertAndSend(WMS2EIS_SAVE_LOG_EXCHANGE, WMS2EIS_SAVE_LOG_ROUTING_KEY, JSONObject.toJSONString(eisLog));
        }
    }

    @Override
    public void inventoryLock(List<InventoryLockVO> list) {
        if (CollUtil.isNotEmpty(list)) {
            rabbitTemplate.convertAndSend(WMS2EIS_INVENTORY_LOCK_EXCHANGE, WMS2EIS_INVENTORY_LOCK_ROUTING_KEY, JSONObject.toJSONString(list));
        }
    }
}
