package cn.com.qmth.stmms.admin.basic;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.com.qmth.stmms.admin.exam.BaseExamController;
import cn.com.qmth.stmms.biz.exam.service.CheckStudentService;
import cn.com.qmth.stmms.biz.exam.service.ExamStudentService;
import cn.com.qmth.stmms.biz.exam.service.ExamSubjectService;
import cn.com.qmth.stmms.biz.file.service.FileService;
import cn.com.qmth.stmms.common.enums.CheckType;

@Controller
@RequestMapping("/admin/basic")
public class BasicController extends BaseExamController {

    @Autowired
    private FileService fileService;

    @Autowired
    private ExamStudentService examStudentService;

    @Autowired
    private ExamSubjectService examSubjectService;

    @Autowired
    private CheckStudentService checkStudentService;

    @RequestMapping("overview")
    public String roleLise(Model model, HttpServletRequest request) {
        int examId = getSessionExamId(request);
        long studentCount = examStudentService.countByExamId(examId);
        model.addAttribute("studentCount", studentCount);
        model.addAttribute("subjectCount", examSubjectService.count(examId));
        if (studentCount > 0
                && checkStudentService.countByExamIdAndCheckedAndType(examId, false, CheckType.MANUAL) == 0) {
            model.addAttribute("checkStudentOk", true);
        } else {
            model.addAttribute("checkStudentOk", false);
        }
        model.addAttribute("checkSubjectOk", studentCount > 0 && examSubjectService.checkSubjectForExport(examId));
        model.addAttribute("checkAbsentOk", studentCount > 0 && examSubjectService.checkSubjectAbsentForExport(examId));
        return "modules/basic/overview";
    }

    @RequestMapping("video")
    public String video(Model model, HttpServletRequest request, String type) {
        String server = fileService.getFileServer();
        String spe = "";
        if (!server.endsWith("/")) {
            spe = "/";
        }
        if ("group-edit".equals(type)) {
            model.addAttribute("videoTitle", "分组修改");
            model.addAttribute("videoUrl", server + spe + "video/group-edit.mp4");
        } else if ("marker-batch-create".equals(type)) {
            model.addAttribute("videoTitle", "批量创建评卷员导出");
            model.addAttribute("videoUrl", server + spe + "video/marker-batch-create.mp4");
        } else if ("inspect-reject".equals(type)) {
            model.addAttribute("videoTitle", "全卷复核打回");
            model.addAttribute("videoUrl", server + spe + "video/inspect-reject.mp4");
        }
        return "modules/basic/video";
    }
}
