package com.xhkjedu.smarking.listener;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ywx
 * @className MessageSender
 * @description
 * @date 2021/10/25 14:28
 **/
@Component
@Slf4j
public class MessageSender {
    @Autowired
    private AmqpTemplate rabbitTemplate;
    //负载一生产者mq
    @Value("${rabbitmq.markingImgMergeQueue}")
    private String markingImgMergeQueue;
    @Value("${rabbitmq.markingImgToPdfQueue}")
    private String markingImgToPdfQueue;
    @Value("${rabbitmq.markingHtmlToPdfQueue}")
    private String markingHtmlToPdfQueue;
    //负载二生产者mq
    @Value("${rabbitmq.markingImgMergeQueue2}")
    private String markingImgMergeQueue2;
    @Value("${rabbitmq.markingImgToPdfQueue2}")
    private String markingImgToPdfQueue2;
    //负载二节点名称
    private final String node2="node02/";

    /**
     * @Description 学生答案合并
     * @Param [mpsqid, userAnswers]
     * @Return void
     * @Author wn
     * @Date 2022/7/28 16:46
     **/
    public void imgMerge(Integer mpsqid, List<String> userAnswers) {
        Map map = new HashMap();
        map.put("mpsqid", mpsqid);
        map.put("stuanswers", userAnswers);
        if (userAnswers.toString().contains(node2)) {
            rabbitTemplate.convertAndSend(markingImgMergeQueue2, JSON.toJSONString(map));
        } else {
            rabbitTemplate.convertAndSend(markingImgMergeQueue, JSON.toJSONString(map));
        }
    }

    /**
     * @Description 考试附件试卷图片转pdf
     * @Param [imgs, epid]
     * @Return void
     * @Author wn
     * @Date 2022/11/1 10:43
     **/
    public void ImgToPdf(List<String> imgs,Integer mpid,Integer filetype) {
        Map map = new HashMap();
        map.put("mpid",mpid);
        map.put("imgs", imgs);
        map.put("filetype",filetype);
        if (imgs.toString().contains(node2)) {
            rabbitTemplate.convertAndSend(markingImgToPdfQueue2, JSON.toJSONString(map));
        } else {
            rabbitTemplate.convertAndSend(markingImgToPdfQueue, JSON.toJSONString(map));
        }
    }

    /**
     * @Description 考试报告html转pdf
     * @Param [map]
     * @Author ywx
     * @Date 2023/2/14 11:24
     * @return void
     **/
    public void htmlToPdf(Map map) {
        rabbitTemplate.convertAndSend(markingHtmlToPdfQueue, JSON.toJSONString(map));
    }
}
