package com.ssj.service.rabbitmq;

import com.alibaba.fastjson.JSONObject;
import com.ssj.framework.core.rabbitmq.TopicRabbitConfig;
import com.ssj.service.ai.model.ProblemPicturePreDeal;
import com.ssj.service.sys.picturepredeal.service.ProblemSimilarPreDealService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: chchen
 * @Description
 * @Date Create in 15:20 2019/10/23
 * @Modified By
 */
@Component
public class TopicTabbitProblemSimilarConsumer {

    private static Logger logger = LoggerFactory.getLogger(TopicRabbitHomeworkConsumer.class);

    @Autowired
    private ProblemSimilarPreDealService problemSimilarPreDealService;

    private static Long num=0L;

    @RabbitListener(queues = {TopicRabbitConfig.topic_problem_similar_query})
    @RabbitHandler
    public void handleMessage(Message message){
        try {
            num = num + 1;
            logger.debug("难题识别答案消息队列开始消费...");
            ProblemPicturePreDeal problemPicturePreDeal = JSONObject.parseObject(message.getBody(), ProblemPicturePreDeal.class);
            logger.debug("开始消费推送信息队列数据："+JSONObject.toJSONString(problemPicturePreDeal));
            problemSimilarPreDealService.postRequest2AI(problemPicturePreDeal);
            logger.debug("作业图片识别答案消息队列完成消费..." + num);
        } catch (Exception e){
            logger.error("消费队列消费异常" + e);
        }
    }
}
