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

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/headerteacher")
public class HeaderTeacherController {

    @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("/classanalysis")
    public ModelAndView classAnalysis(HttpServletRequest request, HttpSession session) {
        ModelAndView view = new ModelAndView("/analysis/headerteacher/classanalysis");
        buildOptionValues(request, view);
        return view;
    }

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

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

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