package com.ssj.service.rabbitmq;

import com.ssj.service.ai.model.HomeworkPicturePreDeal;
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;

import com.alibaba.fastjson.JSONObject;
import com.ssj.framework.core.rabbitmq.TopicRabbitConfig;
import com.ssj.service.sys.picturepredeal.service.PicturePreDealService;

@Component
public class TopicRabbitHomeworkConsumer {
	
	  private static Logger logger = LoggerFactory.getLogger(TopicRabbitHomeworkConsumer.class);
		
	  @Autowired
	  private PicturePreDealService picturePreDealService;
	  
	  private static Long num=0L;
	  
	  @RabbitListener(queues = {TopicRabbitConfig.topic_homework_discern})
	  @RabbitHandler
	  public void handleMessage(Message message){
	  	  try {
			  num = num + 1;
			  logger.info("作业图片识别答案消息队列开始消费...");
			  HomeworkPicturePreDeal homeworkPicturePreDeal = JSONObject.parseObject(message.getBody(), HomeworkPicturePreDeal.class);
			  logger.error("开始消费推送信息队列数据："+JSONObject.toJSONString(homeworkPicturePreDeal));
			  picturePreDealService.postRequest2AIV1(homeworkPicturePreDeal);
			  logger.info("作业图片识别答案消息队列完成消费..." + num);
		  } catch (Exception e){
	  	  	  logger.error("消费队列消费异常" + e);
		  }
	  }
}


