package com.liquidnet.service.platform.utils;

import com.liquidnet.common.cache.redis.util.RedisDataSourceUtil;
import com.liquidnet.commons.lang.util.CollectionUtil;
import com.liquidnet.service.base.constant.MQConst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.stream.StreamRecords;
import org.springframework.stereotype.Component;

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

@Component
public class QueueUtils {

    //    @Autowired
//    private RabbitTemplate rabbitTemplate;
    @Autowired
    RedisDataSourceUtil redisDataSourceUtil;

    /**
     * 发送 SqlMapping Json 字符串
     *
     * @param exchange 交换机
     * @param route    路径
     * @param sqlStr   Json字符串
     */
//    public void sendSqlRabbit(String exchange, String route, String sqlStr) {
//        rabbitTemplate.convertAndSend(exchange, route, sqlStr);
//    }


    /**
     * 发送消息 - REDIS
     *
     * @param streamKey Redis消费Key
     * @param jsonMsg   Json字符串
     */
    public void sendMsgByRedis(String streamKey, String jsonMsg) {
        HashMap<String, String> map = CollectionUtil.mapStringString();
        map.put(MQConst.QUEUE_MESSAGE_KEY, jsonMsg);
        redisDataSourceUtil.getRedisKylinUtil().getStringRedisTemplate().opsForStream().add(StreamRecords.mapBacked(map).withStreamKey(streamKey));
    }

    /**
     * 发送消息 - REDIS
     *
     * @param streamKey Redis消费Key
     * @param jsonMsg   Json字符串
     */
    public void sendMsgByCandyRedis(String streamKey, String jsonMsg) {
        HashMap<String, String> map = CollectionUtil.mapStringString();
        map.put(MQConst.QUEUE_MESSAGE_KEY, jsonMsg);
        redisDataSourceUtil.getRedisCandyUtil().getStringRedisTemplate().opsForStream().add(StreamRecords.mapBacked(map).withStreamKey(streamKey));
    }

    /**
     * 发送消息 - REDIS
     *
     * @param streamKey Redis消费Key
     * @param jsonMsg   Json字符串
     */
    public void sendMsgByGoblinRedis(String streamKey, String jsonMsg) {
        HashMap<String, String> map = CollectionUtil.mapStringString();
        map.put(MQConst.QUEUE_MESSAGE_KEY, jsonMsg);
        redisDataSourceUtil.getRedisGoblinUtil().getStringRedisTemplate().opsForStream().add(StreamRecords.mapBacked(map).withStreamKey(streamKey));
    }

    /**
     * 发送消息 -REDIS
     *
     * @param
     */
    public void sendMssPhoneCodeRedis(Map<String,String> map) {
        redisDataSourceUtil.getRedisGoblinUtil().getStringRedisTemplate().opsForStream().add(StreamRecords.mapBacked(map).withStreamKey(MQConst.GoblinQueue.GOBLIN_PHONE_CODE_OPERA.getKey()));
    }

}
