package cn.com.qmth.stmms.analysis.teacher;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import cn.com.qmth.stmms.biz.exam.query.ExamSearchQuery;
import cn.com.qmth.stmms.biz.exam.service.ExamService;
import cn.com.qmth.stmms.biz.user.model.User;
import cn.com.qmth.stmms.biz.user.service.UserService;
import cn.com.qmth.stmms.common.enums.ExamStatus;
import cn.com.qmth.stmms.common.utils.RequestUtils;

@Controller
@RequestMapping("/analysis/teacher")
public class TeacherController {

    @Autowired
    private ExamService examService;

    @Autowired
    private UserService userService;

    private void buildOptionValues(HttpServletRequest request, ModelAndView view) {
        User user = RequestUtils.getWebUser(request).getUser();
        ExamSearchQuery query = new ExamSearchQuery();
        query.addStatus(ExamStatus.START);
        query.addStatus(ExamStatus.ENDED);
        query.setOrderByCreateTimeDesc(true);
        examService.findByQuery(query);
        view.addObject("examList", query.getResult());
        view.addObject("school_id", user.getSchoolId());
        view.addObject("user_id", user.getId());
        view.addObject("web_request_url", request.getRequestURI());
    }

    @RequestMapping("/wronganalysis")
    public ModelAndView wrongAnalysis(HttpServletRequest request) {
        ModelAndView modelAndView = new ModelAndView("/analysis/teacher/wronganalysis");
        buildOptionValues(request, modelAndView);
        return modelAndView;
    }

    @RequestMapping("/paperdifficult")
    public ModelAndView paperDifficult(HttpServletRequest request, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView("/analysis/teacher/paperdifficult");
        buildOptionValues(request, modelAndView);
        return modelAndView;
    }

    @RequestMapping("/questiontypescored")
    public ModelAndView questionTypeScored(HttpServletRequest request, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView("/analysis/teacher/questiontypescored");
        buildOptionValues(request, modelAndView);
        return modelAndView;
    }

    @RequestMapping("/questiontypedifficult")
    public ModelAndView questionTypeDifficult(HttpServletRequest request, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView("/analysis/teacher/questiontypedifficult");
        buildOptionValues(request, modelAndView);
        return modelAndView;
    }

    @RequestMapping("/knowledgescored")
    public ModelAndView knowledgeScored(HttpServletRequest request, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView("/analysis/teacher/knowledgescored");
        buildOptionValues(request, modelAndView);
        return modelAndView;
    }

    @RequestMapping("/knowledgedifficult")
    public ModelAndView knowledgeDifficult(HttpServletRequest request, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView("/analysis/teacher/knowledgedifficult");
        buildOptionValues(request, modelAndView);
        return modelAndView;
    }

    @RequestMapping("/classbalance")
    public ModelAndView classBalance(HttpServletRequest request, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView("/analysis/teacher/classbalance");
        buildOptionValues(request, modelAndView);
        return modelAndView;
    }

    @RequestMapping("/objectivescored")
    public ModelAndView objectiveScored(HttpServletRequest request, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView("/analysis/teacher/objectivescored");
        buildOptionValues(request, modelAndView);
        return modelAndView;
    }

    @RequestMapping("/subquestionknowledgeanalysis")
    public ModelAndView subQuestionKnowledgeAnalysis(HttpServletRequest request, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView("/analysis/teacher/subquestionknowledgeanalysis");
        buildOptionValues(request, modelAndView);
        return modelAndView;
    }

    @RequestMapping("/subjectcommonanalysis")
    public ModelAndView subjectCommonAnalysis(HttpServletRequest request, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView("/analysis/teacher/subjectcommonanalysis");
        buildOptionValues(request, modelAndView);
        return modelAndView;
    }
}
