package com.qmth.themis.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qmth.themis.business.dao.TMTencentVideoMessageMapper;
import com.qmth.themis.business.entity.TMTencentVideoMessage;
import com.qmth.themis.business.service.TMTencentVideoMessageService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 腾讯云视频回调消息 服务实现类
 * </p>
 *
 * @author wangliang
 * @since 2022-03-29
 */
@Service
public class TMTencentVideoMessageServiceImpl extends ServiceImpl<TMTencentVideoMessageMapper, TMTencentVideoMessage> implements TMTencentVideoMessageService {

    /**
     * 保存视频
     *
     * @param tencentVideoMessage
     */
    @Override
    public void saveAndCount(TMTencentVideoMessage tencentVideoMessage) {
        QueryWrapper<TMTencentVideoMessage> tencentVideoMessageQueryWrapper = new QueryWrapper<>();
        tencentVideoMessageQueryWrapper.lambda().eq(TMTencentVideoMessage::getExamRecordId, tencentVideoMessage.getExamRecordId())
                .eq(TMTencentVideoMessage::getVideoSource, tencentVideoMessage.getVideoSource())
                .eq(TMTencentVideoMessage::getStartTime, tencentVideoMessage.getStartTime())
                .eq(TMTencentVideoMessage::getEndTime, tencentVideoMessage.getEndTime());
        int count = this.count(tencentVideoMessageQueryWrapper);
        if (count == 0) {
            this.save(tencentVideoMessage);
        }
    }

    /**
     * 根据考试批次id查询视频信息
     *
     * @param examId
     * @return
     */
    @Override
    public List<TMTencentVideoMessage> videoQuery(Long examId) {
        return this.baseMapper.videoQuery(examId);
    }

    /**
     * 查询视频源
     *
     * @param examRecordId
     * @return
     */
    @Override
    public String videoSourceQuery(Long examRecordId) {
        return this.baseMapper.videoSourceQuery(examRecordId);
    }
}
