package com.fs.app.mq;

import com.alibaba.fastjson.JSON;
import com.fs.ad.service.IAdHtmlClickLogService;
import com.fs.common.annotation.DataSource;
import com.fs.common.core.redis.RedisCacheT;
import com.fs.common.enums.DataSourceType;
import com.fs.common.utils.PubFun;
import com.fs.qw.result.QwFilterSopCustomersResult;
import com.fs.qw.vo.AdUploadVo;
import com.fs.sop.domain.QwSop;
import com.fs.sop.domain.QwSopTempContent;
import com.fs.sop.domain.QwSopTempDay;
import com.fs.sop.mapper.QwSopMapper;
import com.fs.sop.mapper.QwSopTempContentMapper;
import com.fs.sop.params.QwSopTagsParam;
import com.fs.sop.service.IQwSopTempDayService;
import com.fs.sop.service.IQwSopTempVoiceService;
import com.fs.sop.vo.VoiceVo;
import com.fs.voice.utils.StringUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
@AllArgsConstructor
@RocketMQMessageListener(topic = "${rocketmq.consumer.topic}", consumerGroup = "${rocketmq.consumer.group}")
public class RocketMQConsumerService implements RocketMQListener<String> {
    private final RedisCacheT<VoiceVo> redisCache;
    public final static String VOICE_CACHE_KEY = "voice:cache:";

    @Override
    @DataSource(DataSourceType.SOP)
    public void onMessage(String message) {
        log.info("消息队列接收到消息：{}",  message);
        VoiceVo vo = JSON.parseObject(message, VoiceVo.class);
        vo.setGenerated(0);
        redisCache.setCacheObject(VOICE_CACHE_KEY + vo.getType() + ":" + vo.getId(), vo);
    }

}
