package cn.com.qmth.stmms.student.controller;

import javax.servlet.http.HttpServletRequest;

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

import cn.com.qmth.stmms.biz.exam.model.Exam;
import cn.com.qmth.stmms.biz.exam.service.ExamService;
import cn.com.qmth.stmms.biz.exam.service.ExamStudentService;
import cn.com.qmth.stmms.common.domain.WebUser;
import cn.com.qmth.stmms.common.utils.RequestUtils;

@Controller
@RequestMapping("/student/analysis")
public class StudentAnalysisController {

    @Autowired
    private ExamService examService;

    @Autowired
    private ExamStudentService examStudentService;

    @RequestMapping("/scoreinfo")
    public ModelAndView scoreInfo(HttpServletRequest request) {
        ModelAndView view = new ModelAndView("/student/scoreinfo");
        buildOptionValues(request, view);
        return view;
    }

    @RequestMapping("/scoredetail")
    public ModelAndView scoreDetail(HttpServletRequest request) {
        ModelAndView view = new ModelAndView("/student/scoredetail");
        buildOptionValues(request, view);
        return view;
    }

    @RequestMapping("/scorehistory")
    public ModelAndView scoreHistory(HttpServletRequest request) {
        ModelAndView view = new ModelAndView("/student/scorehistory");
        buildOptionValues(request, view);
        return view;
    }

    @RequestMapping(value = "/scorereport", method = RequestMethod.GET)
    public ModelAndView scoreReport(HttpServletRequest request) {
        request.getSession().setAttribute("menuNo", 4);
        ModelAndView view = new ModelAndView("student/scorereport");
        buildOptionValues(request, view);
        return view;
    }

    private void buildOptionValues(HttpServletRequest request, ModelAndView view) {
        WebUser wu = RequestUtils.getWebStudent(request);
        //Integer schoolId = wu.getExamStudent().getSchoolId();
        String examNumber = wu.getExamStudent().getExamNumber();
        //String class_id = wu.getExamStudent().getClassCode();
        Exam exam = examService.findById(wu.getExamStudent().getExamId());
        if (exam.getStatus().getValue() == 2) {
            view.addObject("exam", exam);
        }
        view.addObject("student_code", examNumber);
        //view.addObject("school_id", schoolId);
        //view.addObject("class_id", class_id);
        view.addObject("web_request_url", request.getRequestURI());
    }
}
