package com.fs.app.mq;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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 com.fs.repeat.service.RepeatService;
import com.fs.repeat.vo.RepeatUploadVo;
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 java.util.List;
import java.util.function.Function;

@Slf4j
@Service
@AllArgsConstructor
@RocketMQMessageListener(topic = "repeat-upload", consumerGroup = "common-group")
public class RocketMQConsumerService implements RocketMQListener<String> {

    private final RepeatService repeatService;
    private final Function<RepeatUploadVo, String> type = e -> {
        switch (e.getType()) {
            case 0:
                return "企微";
            case 1:
                return "个微";
        }
        return "错误类型！";
    };

    @Override
    public void onMessage(String message) {
        if(StringUtils.isEmpty(message)) return;
        RepeatUploadVo vo = JSON.parseObject(message, RepeatUploadVo.class);
        if(vo == null) return;
        if(vo.getType() == 0){
            log.info("企微重粉判断：{}", type.apply(vo));
            repeatService.repeatQw(vo);
        }
        if(vo.getType() == 1){
            log.info("看课重粉判断：{}", type.apply(vo));
            repeatService.repeatFsUser(vo);
        }
        if(vo.getType() == 2){
            log.info("已购订单判断：{}", type.apply(vo));
            repeatService.userAddOrder(vo);
        }
    }
}
