package com.fs.app.mq;

import com.alibaba.fastjson.JSON;
import com.fs.ad.service.IAdHtmlClickLogService;
import com.fs.common.utils.StringUtils;
import com.fs.qw.domain.QwExternalContact;
import com.fs.qw.vo.AdUploadVo;
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;

@Slf4j
@Service
@AllArgsConstructor
@RocketMQMessageListener(topic = "${rocketmq.consumer.topic}", consumerGroup = "${rocketmq.consumer.group}")
public class RocketMQConsumerService implements RocketMQListener<String> {

    private final IAdHtmlClickLogService  adHtmlClickLogService;

    @Override
    public void onMessage(String message) {
        AdUploadVo adUploadVo = JSON.parseObject(message, AdUploadVo.class);
        if(adUploadVo == null  || StringUtils.isEmpty(adUploadVo.getState()) || "null".equals(adUploadVo.getState())){
            return;
        }
        adHtmlClickLogService.upload(adUploadVo.getState(), adUploadVo.getType());
    }
}
