package com.prolog.cs.biz.outbound.service.impl.mq;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSONObject;
import com.prolog.cs.biz.outbound.model.tms.TmsShipBill;
import com.prolog.cs.biz.outbound.model.tms.TmsShipBillPackage;
import com.prolog.cs.biz.outbound.service.MqOutBoundProducer;
import com.prolog.entity.vo.*;
import com.prolog.upcloud.base.wh.operate.model.EisLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

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

import static com.prolog.constant.RabbitMqConstant.*;
import static com.prolog.cs.biz.outbound.model.tms.TmsConstant.*;

@Slf4j
@Service
public class RabbitMqOutBoundProducerImpl implements MqOutBoundProducer {

    @Resource
    private RabbitTemplate rabbitTemplate;

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

    @Override
    public void upgradePriority(List<UpdatePriorityVO> list) {
        if (CollUtil.isEmpty(list)) {
            return;
        }
        rabbitTemplate.convertAndSend(WMS2EIS_UPGRADE_PRIORITY_EXCHANGE, WMS2EIS_UPGRADE_PRIORITY_ROUTING_KEY, JSONObject.toJSONString(list));

    }

    @Override
    public void cancelTasks(List<CancelTasksVO> list) {
        if (CollUtil.isEmpty(list)) {
            return;
        }
        rabbitTemplate.convertAndSend(WMS2EIS_CANCEL_TASKS_EXCHANGE, WMS2EIS_CANCEL_TASKS_ROUTING_KEY, JSONObject.toJSONString(list));

    }

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

    }

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

    @Override
    public void tmsShipBill(TmsShipBill dto) {
        if (dto == null) {
            return;
        }
        rabbitTemplate.convertAndSend(WMS2TMS_SAVE_SHIP_BILL_EXCHANGE, WMS2TMS_SAVE_SHIP_BILL_ROUTING_KEY, JSONObject.toJSONString(dto));
    }

    @Override
    public void tmsShipBillPackage(TmsShipBillPackage dto) {
        if (dto == null) {
            return;
        }
        rabbitTemplate.convertAndSend(WMS2TMS_SAVE_SHIP_BILL_PACKAGE_EXCHANGE, WMS2TMS_SAVE_SHIP_BILL_PACKAGE_ROUTING_KEY, JSONObject.toJSONString(dto));
    }

    @Override
    public void containerTailgatingRequest(List<ContainerTailgatingRequestVO> list) {
        if (CollUtil.isEmpty(list)) {
            return;
        }
        rabbitTemplate.convertAndSend(WMS2EIS_CONTAINER_TAILGATING_REQUEST_EXCHANGE, WMS2EIS_CONTAINER_TAILGATING_REQUEST_ROUTING_KEY, JSONObject.toJSONString(list));

    }
}
