package com.xhkjedu.sexam.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;

    @Value("${rabbitmq.examImgMergeQueue}")
    private String examImgMergeQueue;
    @Value("${rabbitmq.examBaseToPdfQueue}")
    private String examBaseToPdfQueue;
    @Value("${rabbitmq.examBaseToScanImgQueue}")
    private String examBaseToScanImgQueue;


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

    /**
     * @Description 答题卡图片合并为pdf
     * @Param [epid, imgs]
     * @Return void
     * @Author wn
     * @Date 2022/8/2 13:57
     **/
    public void base64ToPdf(Integer examid,Integer epid, List<String> imgs,String savefolder,Integer scantroncol,String filename) {
        Map map = new HashMap();
        map.put("examid", examid);
        map.put("epid",epid);
        map.put("imgs", imgs);
        map.put("scantroncol", scantroncol);
        map.put("savefolder",savefolder);
        map.put("filename",filename);

        rabbitTemplate.convertAndSend(examBaseToPdfQueue, JSON.toJSONString(map));
    }

    /**
     * @Description  扫码出错图片base64转图片
     * @Param [serrorid, imgs, savefolder]
     * @Return void
     * @Author wn
     * @Date 2022/9/19 9:40
     **/
    public void base64ToScanImg(Integer serrorid,Integer examid,List<String> imgs,String savefolder) {
        Map map = new HashMap();
        map.put("serrorid", serrorid);
        map.put("examid", examid);
        map.put("imgs", imgs);
        map.put("savefolder",savefolder);
        rabbitTemplate.convertAndSend(examBaseToScanImgQueue, JSON.toJSONString(map));
    }
}
