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

import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONArray;

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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.qmth.stmms.biz.campus.service.CampusService;
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.ExamSubjectService;

@Controller
@RequestMapping("/analysis/condition")
public class ConditionController {

    @Autowired
    private ExamService examService;

    @Autowired
    private ExamSubjectService subjectService;

    @Autowired
    private CampusService campusService;

    @RequestMapping("/classes")
    @ResponseBody
    public JSONArray getExamClasses(@RequestParam Integer examId, @RequestParam Integer campusId) {
        JSONArray list = new JSONArray();
        return list;
    }

    @RequestMapping("/subjects")
    @ResponseBody
    public JSONArray getSubjects(@RequestParam Integer examId, HttpServletRequest request) {
        // User user = RequestUtils.getWebUser(request);
        JSONArray list = new JSONArray();
        Exam exam = examService.findById(examId);
        if (exam != null) {
            /*
             * List<Integer> ids = exam.getSubjectIdList(); for (Integer id :
             * ids) { list.add(subjectService.findById(id)); }
             */
        }
        return list;
    }

    /**
     * json方法: 根据考试ID和角色ID，获取当前用户（教研员）能查看的考试学校列表
     * 
     * @param examId
     * @return
     */
    @RequestMapping(value = "/campuses")
    @ResponseBody
    public JSONArray getExamCampuses(HttpServletRequest request, @RequestParam Integer examId) {
        JSONArray list = new JSONArray();
        return list;
    }

    /**
     * json方法: 根据考试ID和角色ID，获取当前用户（老师）能查看的考试班级列表
     * 
     * @param examId
     * @return
     */
    /*
     * @RequestMapping(value = "/class-groups")
     * 
     * @ResponseBody public JSONArray getExamClassGroups(@RequestParam Integer
     * examId) { UserDO user = (UserDO)
     * session.getAttribute(WebConstants.WEB_SESSION_USER); Map<String, Object>
     * result = new HashMap<String, Object>(); Set<String> groupSet = new
     * LinkedHashSet<String>(); if (user.getUserType() == UserType.TEACHER) {
     * TeacherDO teacher = (TeacherDO) user; List<ExamClass> list =
     * examService.getExamClassList(examId, teacher.getSchool().getId()); if
     * (list != null && list.size() > 0) { for (ExamClass ec : list) { String
     * group = StringUtils.trimToNull(ec.getClassGroup()); if (group != null) {
     * groupSet.add(group); } } } } result.put("groupList", groupSet.toArray());
     * ModelAndView view = new ModelAndView("admin/exam/list", result); return
     * view; }
     */
}
