package cn.com.qmth.examcloud.core.questions.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import cn.com.qmth.examcloud.core.questions.dao.entity.RandomPaperQuestion;
import cn.com.qmth.examcloud.core.questions.service.RandomPaperQuestionService;

@Service
public class RandomPaperQuestionServiceImpl implements RandomPaperQuestionService {
	@Autowired
	private MongoTemplate mongoTemplate;
	
	@Override
	public boolean existQuestion(String questionId) {
		Query query = new Query();
		query.addCriteria(Criteria.where("questionId").is(questionId));
		RandomPaperQuestion rp=mongoTemplate.findOne(query,RandomPaperQuestion.class);
		return rp!=null;
	}
	
	@Override
	public boolean existQuestion(List<String> questionIds) {
		Query query = new Query();
		query.addCriteria(Criteria.where("questionId").in(questionIds));
		long count=mongoTemplate.count(query,RandomPaperQuestion.class);
		return count>0;
	}

}