package com.prolog.cs.base.gsp.service.impl.mq;

import com.alibaba.fastjson.JSONObject;
import com.prolog.cs.base.gsp.service.MqGspProducer;
import com.prolog.entity.vo.OperationCompleteVO;
import com.prolog.entity.vo.OutBoundRequestVO;
import com.prolog.upcloud.base.wh.operate.model.EisLog;
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.*;

@Service
public class RabbitMqGspProducerImpl implements MqGspProducer {

    @Resource
    private RabbitTemplate rabbitTemplate;

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

    @Override
    public void operationComplete(List<OperationCompleteVO> list) {
        rabbitTemplate.convertAndSend(WMS2EIS_OPERATION_COMPLETE_EXCHANGE, WMS2EIS_OPERATION_COMPLETE_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));
        }
    }
}
