package com.xhkjedu.sapi.listener;

import com.alibaba.fastjson.JSON;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ywx
 * @className MessageSender
 * @description
 * @date 2021/10/25 14:28
 **/
@Component
public class MessageSender {
    @Autowired
    private AmqpTemplate rabbitTemplate;
    //负载一生产者mq
    @Value("${rabbitmq.researchTransferQueue}")
    private String researchTransferQueue;
    @Value("${rabbitmq.resourceDelQueue}")
    private String resourceDelQueue;
    //负载二生产者mq
    @Value("${rabbitmq.researchTransferQueue2}")
    private String researchTransferQueue2;
    @Value("${rabbitmq.resourceDelQueue2}")
    private String resourceDelQueue2;
    //负载二节点名称
    private final String node2="node02/";

    //教研视频转换mq
    public void convertVideo(Integer resourceid, String resourceurl) {
        Map map = new HashMap();
        map.put("resourceid",resourceid);
        map.put("resourceurl",resourceurl);
        if (resourceurl.contains(node2)) {
            rabbitTemplate.convertAndSend(researchTransferQueue2, JSON.toJSONString(map));
        } else {
            rabbitTemplate.convertAndSend(researchTransferQueue, JSON.toJSONString(map));
        }
    }

    //资源删除mq
    public void resourceDel(List<String> resourceurls) {
        if (resourceurls.toString().contains(node2)) {
            rabbitTemplate.convertAndSend(resourceDelQueue2, JSON.toJSONString(resourceurls));
        } else {
            rabbitTemplate.convertAndSend(resourceDelQueue, JSON.toJSONString(resourceurls));
        }
    }
}
