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

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/campus")
public class CampusAnalysisController {

    @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("user_id", user.getId());
        view.addObject("web_request_url", request.getRequestURI());
    }

    @RequestMapping("/totalanalysis")
    public ModelAndView totalAnalysis(HttpServletRequest request, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView("/analysis/school/totalanalysis");
        buildOptionValues(request, modelAndView);
        return modelAndView;
    }

    @RequestMapping("/excellentstudentanalysis")
    public ModelAndView excellentStudentAnalysis(HttpServletRequest request, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView("/analysis/school/excellentstudentanalysis");
        buildOptionValues(request, modelAndView);
        return modelAndView;
    }

    @RequestMapping("/maxmin")
    public ModelAndView maxMin(HttpServletRequest request, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView("/analysis/school/maxmin");
        buildOptionValues(request, modelAndView);
        return modelAndView;
    }

    @RequestMapping("/subjectanalysis")
    public ModelAndView subjectAnalysis(HttpServletRequest request, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView("/analysis/school/subjectanalysis");
        buildOptionValues(request, modelAndView);
        return modelAndView;
    }

    @RequestMapping("/qualityanalysis")
    public ModelAndView qualityAnalysis(HttpServletRequest request, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView("/analysis/school/qualityanalysis");
        buildOptionValues(request, modelAndView);
        return modelAndView;
    }

    @RequestMapping("/totalrange")
    public ModelAndView totalRange(HttpServletRequest request, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView("/analysis/school/totalrange");
        buildOptionValues(request, modelAndView);
        return modelAndView;
    }

    @RequestMapping("/subjectrange")
    public ModelAndView subjectRange(HttpServletRequest request, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView("/analysis/school/subjectrange");
        buildOptionValues(request, modelAndView);
        return modelAndView;
    }

    @RequestMapping("/subjectitemanalysis")
    public ModelAndView subjectItemAnalysis(HttpServletRequest request, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView("/analysis/school/subjectitemanalysis");
        buildOptionValues(request, modelAndView);
        return modelAndView;
    }

    @RequestMapping("/avgcompare")
    public ModelAndView avgCompare(HttpServletRequest request, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView("/analysis/school/avgcompare");
        buildOptionValues(request, modelAndView);
        return modelAndView;
    }

    @RequestMapping("/onlinedetail")
    public ModelAndView onLineDetail(HttpServletRequest request, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView("/analysis/school/onlinedetail");
        buildOptionValues(request, modelAndView);
        return modelAndView;
    }

    @RequestMapping("/subjectobjectiveanalysis")
    public ModelAndView subjectObjectiveAnalysis(HttpServletRequest request, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView("/analysis/school/subjectobjectiveanalysis");
        buildOptionValues(request, modelAndView);
        return modelAndView;
    }

    @RequestMapping("/subitemscored")
    public ModelAndView subItemScored(HttpServletRequest request, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView("/analysis/school/subitemscored");
        buildOptionValues(request, modelAndView);
        return modelAndView;
    }
}
