package lingtao.net.service;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import lingtao.net.bean.Msg;
import lingtao.net.bean.Question;
import lingtao.net.bean.SysUser;
import lingtao.net.dao.QuestionMapper;

@Service
public class QuestionService {

	@Autowired
	private QuestionMapper questionMapper;

	public List<Question> questions(Question question) {
		return questionMapper.questions(question);
	}

	public Msg addQuestion(Question question, HttpSession session) {
		SysUser user = (SysUser) session.getAttribute("USER_SESSION");
		question.setCreateBy(user.getRealname());
		try {
			questionMapper.addQuestion(question);
			return Msg.success();
		} catch (Exception e) {
			return Msg.fail();
		}
	}

	// 修改
	public Msg updateQuestionById(Question question, HttpSession session) {
		SysUser user = (SysUser) session.getAttribute("USER_SESSION");
		question.setUpdateBy(user.getRealname());
		try {
			questionMapper.updateQuestionById(question);
			return Msg.success();
		} catch (Exception e) {
			return Msg.fail();
		}
	}

	public Msg deleteQuestionById(Integer id) {
		try {
			questionMapper.deleteQuestionById(id);
			return Msg.success();
		} catch (Exception e) {
			return Msg.fail();
		}
	}

	public List<Question> getSingleQuestions() {
		return questionMapper.getSingleQuestions();
	}

	public List<Question> getMultipleQuestions() {
		return questionMapper.getMultipleQuestions();
	}

	public List<Question> getFillQuestions() {
		return questionMapper.getFillQuestions();
	}
}
