package com.ynfy.buss.exam.userexamquestion.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ynfy.buss.exam.userexamquestion.entity.UserExamQuestion;
import com.ynfy.buss.exam.userexamquestion.mapper.UserExamQuestionMapper;
import com.ynfy.buss.exam.userexamquestion.service.IUserExamQuestionService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 用户考试试题
 * @Author: jeecg-boot
 * @Date: 2023-03-05
 * @Version: V1.0
 */
@Service
public class UserExamQuestionServiceImpl extends ServiceImpl<UserExamQuestionMapper, UserExamQuestion> implements IUserExamQuestionService {


    @Override
    public List<UserExamQuestion> listByUserExamId(String userExamId) {
        LambdaQueryWrapper<UserExamQuestion> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserExamQuestion::getUserExamId, userExamId).orderByAsc(UserExamQuestion::getQuestionType).orderByAsc(UserExamQuestion::getSort);
        return this.list(wrapper);
    }

    @Override
    public List<UserExamQuestion> listByUserExamIds(List<String> userExamIds) {
        LambdaQueryWrapper<UserExamQuestion> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(UserExamQuestion::getUserExamId, userExamIds);
        return this.list(wrapper);
    }

    /**
     * 检查题目是否已经在考试使用
     *
     * @param questionIds
     * @return
     */
    @Override
    public boolean checkIsUsedInExam(String[] questionIds) {
        LambdaQueryWrapper<UserExamQuestion> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(UserExamQuestion::getQuestionId, questionIds);
        return this.count(wrapper) > 0 ? true : false;
    }
}
