package cn.com.qmth.examcloud.tool.controller;

import cn.com.qmth.examcloud.tool.enums.TaskStatus;
import cn.com.qmth.examcloud.tool.enums.TaskType;
import cn.com.qmth.examcloud.tool.service.CommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletResponse;

@Controller
public class IndexController extends BaseController {

    @Autowired
    private CommonService commonService;

    @GetMapping(value = "/")
    public String index() {
        return "index";
    }

    @GetMapping(value = "/admin/workspace")
    public String workspace() {
        return "admin/workspace";
    }

    /**
     * 任务列表
     */
    @GetMapping(value = "/admin/taskList")
    public String taskList(Model model) {
        model.addAttribute("menuIndex", 2);
        model.addAttribute("taskTypes", TaskType.values());
        model.addAttribute("taskStatuses", TaskStatus.values());
        return "admin/taskList";
    }

    /**
     * 导出考生试题作答和得分明细
     */
    @GetMapping(value = "/admin/exportStudentAnswerAndScoreDetail")
    public String exportStudentAnswerAndScoreDetail() {
        return "admin/exportStudentAnswerAndScoreDetail";
    }

    /**
     * 重新算分
     */
    @GetMapping(value = "/admin/updateCorrectAnswerAndReFixScore")
    public String updateCorrectAnswerAndReFixScore() {
        return "admin/updateCorrectAnswerAndReFixScore";
    }

    /**
     * 批量配置考试调卷规则
     */
    @GetMapping(value = "/admin/configExamPaper")
    public String configExamPaper() {
        return "admin/configExamPaper";
    }

    /**
     * 批量创建随机抽卷模板
     */
    @GetMapping(value = "/admin/createRandomPaperTemplate")
    public String createRandomPaperTemplate() {
        return "admin/createRandomPaperTemplate";
    }

    /**
     * 批量创建用户
     */
    @GetMapping(value = "/admin/batchCreateUser")
    public String batchCreateUser() {
        return "admin/batchCreateUser";
    }

    /**
     * 批量导入考生
     */
    @GetMapping(value = "/admin/batchImportExamStudent")
    public String batchImportExamStudent() {
        return "admin/batchImportExamStudent";
    }

    @GetMapping("/admin/downloadTemplate/importExamStudent")
    public void downloadTemplate1(HttpServletResponse response) {
        byte[] bytes = super.getSourceFile("templates/import_exam_student.xlsx");
        super.download(response, bytes, "批量导入考生模板.xlsx");
    }

    @GetMapping("/admin/downloadTemplate/importUser")
    public void downloadTemplate2(HttpServletResponse response) {
        byte[] bytes = super.getSourceFile("templates/import_user.xlsx");
        super.download(response, bytes, "批量创建用户模板.xlsx");
    }

}
