package com.xhkjedu.sexam.controller.report;

import com.xhkjedu.sexam.service.report.EReportStudentService;
import com.xhkjedu.sexam.vo.report.ReportParamsVo;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.vo.ResultVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ywx
 * @classname EReportStudentController
 * @description 学生报告
 * @date 2022/8/8 9:44
 **/
@RestController
@RequestMapping("erstu")
public class EReportStudentController {
    @Resource
    private EReportStudentService eReportStudentService;

    //获取考试基础信息
    @PostMapping("/exam")
    public ResultVo getExamSubjectClass(@RequestBody ReportParamsVo params) {
        Integer examid = params.getExamid();
        N_Utils.validation(new Object[]{examid, "考试id", 1});
        Map map = eReportStudentService.getExamSubjectClass(examid);
        return new ResultVo(0, "获取成功", map);
    }

    //报告概况--成绩单
    @PostMapping("/rep")
    public ResultVo listStudentSubjectScoreByExamid(@RequestBody ReportParamsVo params) {
        Integer examid = params.getExamid();
        Integer studentid = params.getStudentid();
        N_Utils.validation(new Object[]{examid, "考试id", 1, studentid, "学生id", 1});
        Integer showRank = eReportStudentService.getShowRank(examid, params.getTeacherid());
        Map map = eReportStudentService.listStudentSubjectScoreByExamid(examid, studentid, showRank);
        return new ResultVo(0, "获取报告概况成绩单成功", map);
    }

    //报告概况--历史名次变化
    @PostMapping("/hr")
    public ResultVo listStudentRankHistory(@RequestBody ReportParamsVo params) {
        Integer studentid = params.getStudentid();
        N_Utils.validation(new Object[]{studentid, "学生id", 1, params.getExamid(), "考试id", 1});
        Integer showRank = eReportStudentService.getShowRank(params.getExamid(), params.getTeacherid());
        List<Map> list = eReportStudentService.listStudentRankHistory(studentid, showRank);
        return new ResultVo(0, "获取报告概况历史名次成功", list);
    }

    //学科分析--学科排名和历史排名
    @PostMapping("/srank")
    public ResultVo getSubjectScoreByStudentid(@RequestBody ReportParamsVo params) {
        Integer studentid = params.getStudentid();
        Integer exmaid = params.getExamid();
        String subjectid = params.getSubjectid();
        N_Utils.validation(new Object[]{exmaid, "考试id", 1, studentid, "学生id", 1, subjectid, "科目id", 3});
        Integer showRank = eReportStudentService.getShowRank(exmaid, params.getTeacherid());
        Map map = eReportStudentService.getSubjectScoreByStudentid(exmaid, studentid, subjectid, showRank);
        return new ResultVo(0, "获取科目排名成功", map);
    }

    //学科分析--知识点分析
    @PostMapping("/spoint")
    public ResultVo listSubjectPoints(@RequestBody ReportParamsVo params) {
        Integer studentid = params.getStudentid();
        Integer exmaid = params.getExamid();
        String subjectid = params.getSubjectid();
        N_Utils.validation(new Object[]{exmaid, "考试id", 1, studentid, "学生id", 1, subjectid, "科目id", 3});
        Integer showRank = eReportStudentService.getShowRank(exmaid, params.getTeacherid());
        List<Map> map = eReportStudentService.listSubjectPoints(exmaid, studentid, subjectid, showRank);
        return new ResultVo(0, "获取科目知识点分析成功", map);
    }

    //学科分析--难易度分析
    @PostMapping("/scomp")
    public ResultVo listSubjectComplexitys(@RequestBody ReportParamsVo params) {
        Integer studentid = params.getStudentid();
        Integer exmaid = params.getExamid();
        String subjectid = params.getSubjectid();
        N_Utils.validation(new Object[]{exmaid, "考试id", 1, studentid, "学生id", 1, subjectid, "科目id", 3});
        Integer showRank = eReportStudentService.getShowRank(exmaid, params.getTeacherid());
        List<Map> map = eReportStudentService.listSubjectComplexitys(exmaid, studentid, subjectid, showRank);
        return new ResultVo(0, "获取科目难易度分析成功", map);
    }
    //学科分析--题型分析
    @PostMapping("/sqtype")
    public ResultVo listSubjectqtypes(@RequestBody ReportParamsVo params) {
        Integer studentid = params.getStudentid();
        Integer exmaid = params.getExamid();
        String subjectid = params.getSubjectid();
        N_Utils.validation(new Object[]{exmaid, "考试id", 1, studentid, "学生id", 1, subjectid, "科目id", 3});
        Integer showRank = eReportStudentService.getShowRank(exmaid, params.getTeacherid());
        List<Map> map = eReportStudentService.listSubjectQtypes(exmaid, studentid, subjectid, showRank);
        return new ResultVo(0, "获取科目题型分析成功", map);
    }
    //学科分析--试题分析
    @PostMapping("/sques")
    public ResultVo listSubjectQuestions(@RequestBody ReportParamsVo params) {
        Integer studentid = params.getStudentid();
        Integer exmaid = params.getExamid();
        String subjectid = params.getSubjectid();
        N_Utils.validation(new Object[]{exmaid, "考试id", 1, studentid, "学生id", 1, subjectid, "科目id", 3});
        Integer showRank = eReportStudentService.getShowRank(exmaid, params.getTeacherid());
        List<Map> map = eReportStudentService.listSubjectQuestions(exmaid, studentid, subjectid, showRank);
        return new ResultVo(0, "获取科目试题分析成功", map);
    }

    //试卷分析
    @PostMapping("/spaper")
    public ResultVo getStudentPaper(@RequestBody ReportParamsVo params) {
        Integer studentid = params.getStudentid();
        Integer exmaid = params.getExamid();
        String subjectid = params.getSubjectid();
        N_Utils.validation(new Object[]{exmaid, "考试id", 1, studentid, "学生id", 1, subjectid, "科目id", 3});
        Integer showRank = eReportStudentService.getShowRank(exmaid, params.getTeacherid());
        Map map = eReportStudentService.getStudentPaperQuestions(exmaid, studentid, subjectid, showRank);
        return new ResultVo(0, "获取科目试卷分析成功", map);
    }

    //错题集--科目错题数量
    @PostMapping("/serrornum")
    public ResultVo listStudentSubjectErrorQues(@RequestBody ReportParamsVo params) {
        Integer studentid = params.getStudentid();
        Integer exmaid = params.getExamid();
        N_Utils.validation(new Object[]{exmaid,"考试id",1,studentid,"学生id",1});
        List<Map> map = eReportStudentService.listStudentSubjectErrorQues(exmaid,studentid,params.getTeacherid());
        return new ResultVo(0, "获取科目错题数量成功", map);
    }

    //学生报告-错题集-学生科目下错题（附件）
    @PostMapping("/serrorfj")
    public ResultVo listStudentErrorQuesForFj(@RequestBody ReportParamsVo params) {
        Integer studentid = params.getStudentid();
        Integer exmaid = params.getExamid();
        String subjectid = params.getSubjectid();
        N_Utils.validation(new Object[]{exmaid, "考试id", 1, studentid, "学生id", 1, subjectid, "科目id", 3});
        Integer showRank = eReportStudentService.getShowRank(exmaid, params.getTeacherid());
        List<Map> map = eReportStudentService.listStudentErrorQuestionsFj(exmaid, studentid, subjectid, showRank);
        return new ResultVo(0, "获取科目错题成功", map);
    }

    //学生报告-错题集-学生科目下错题（题库）
    @PostMapping("/serrorq")
    public ResultVo listStudentErrorQuesForTK(@RequestBody ReportParamsVo params) {
        Integer studentid = params.getStudentid();
        Integer exmaid = params.getExamid();
        String subjectid = params.getSubjectid();
        N_Utils.validation(new Object[]{exmaid, "考试id", 1, studentid, "学生id", 1, subjectid, "科目id", 3});
        Integer showRank = eReportStudentService.getShowRank(exmaid, params.getTeacherid());
        Map map = eReportStudentService.listStudentErrorQuestionsTk(exmaid, studentid, subjectid, showRank);
        return new ResultVo(0, "获取科目错题成功", map);
    }


    //获取考试基础--班级教师权限下班级
    @PostMapping("/examt")
    public ResultVo getExamSubjectClassForTeacher(@RequestBody ReportParamsVo params) {
        Integer examid = params.getExamid();
        N_Utils.validation(new Object[]{examid, "考试id", 1,params.getUserid(),"用户id",1});
        Map map = eReportStudentService.getExamSubjectClassForTeacher(examid,params.getUserid());
        return new ResultVo(0, "获取成功", map);
    }

    //获取考试基础--学生报告
    @PostMapping("/exams")
    public ResultVo getExamSubjectClassForStudent(@RequestBody ReportParamsVo params) {
        Integer examid = params.getExamid();
        N_Utils.validation(new Object[]{examid, "考试id", 1,params.getUserid(),"用户id",1});
        Map map = eReportStudentService.getExamSubjectClassForStudent(examid,params.getUserid());
        return new ResultVo(0, "获取成功", map);
    }

    //学生报告-监控照片--科目数量
    @PostMapping("/bnums")
    public ResultVo listExamSubjectBadNums(@RequestBody ReportParamsVo params) {
        Integer examid = params.getExamid();
        Integer studentid = params.getStudentid();
        N_Utils.validation(new Object[]{examid, "考试id", 1,studentid,"学生id",1});
        List<Map> list = eReportStudentService.listExamSubjectBadNums(examid,studentid);
        return new ResultVo(0, "获取成功", list);
    }

    //学生报告-监控照片-科目图片
    @PostMapping("/bimgs")
    public ResultVo listExamSubjectBadimgs(@RequestBody ReportParamsVo params) {
        Integer esid = params.getEsid();
        Integer studentid = params.getStudentid();
        N_Utils.validation(new Object[]{esid, "考试科目id", 1, studentid, "学生id", 1});
        List<Map> list = eReportStudentService.listExamSubjectBadimgs(esid, studentid);
        return new ResultVo(0, "获取成功", list);
    }

    /**
     * pdf报告
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [params]
     * @Author ywx
     * @Date 2022/12/8 14:29
     **/
    @PostMapping("/pdf")
    public ResultVo toPdf(@RequestBody ReportParamsVo params) {
        Integer examid = params.getExamid();
        Integer studentid = params.getStudentid();
        N_Utils.validation(new Object[]{examid, "考试id", 1, studentid, "学生id", 1});
        Integer showRank = eReportStudentService.getShowRank(params.getExamid(), null);
        Map map = new HashMap();
        Map ksgk = eReportStudentService.getPdfKsGk(examid, studentid);
        map.put("ksgk", ksgk);//考试概况
        List<Map> fsdjtj = eReportStudentService.listFsDjTj(examid);
        map.put("fsdjtj", fsdjtj);//分数等级统计
        Map bggk = eReportStudentService.listStudentSubjectScoreByExamid(examid, studentid, showRank);
        map.put("bggk", bggk);//报告概况
        List<Map> subjects = eReportStudentService.listKmGg(examid, studentid, showRank);
        map.put("subjects", subjects);//科目概况
        List<Map> lspm = eReportStudentService.listStudentRankHistory(studentid, showRank);
        map.put("lspm", lspm);//历史排名
        map.put("showRank", showRank);//显示排名得分0保密1分数2分数+班排名3分数+班/校排名
        return new ResultVo(0, "获取成功", map);
    }

    /**
     * @Description 获取考试PDF报告基础信息
     * @Param [params]
     * @Author ywx
     * @Date 2023/3/2 15:52
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/pdf_info")
    public ResultVo getPdfInfo(@RequestBody ReportParamsVo params) {
        Integer examid = params.getExamid();
        Integer studentid = params.getStudentid();
        N_Utils.validation(new Object[]{examid, "考试id", 1, studentid, "学生id", 1});
        Map map = eReportStudentService.getPdfInfo(examid, studentid);
        return new ResultVo(0, "获取成功", map);
    }


    /*
    * @Description 学生报告-pdf报告状态和学生报告地址
    * @Author WN
    * @Date 2023/2/28 17:11
    */
    @PostMapping("/rstate")
    public ResultVo getExamReportClassstate(@RequestBody ReportParamsVo rbase) {
        Integer examid = rbase.getExamid();
        Integer studentid = rbase.getStudentid();
        N_Utils.validation(new Object[]{examid, "考试id", 1,studentid, "学生id", 1});
        Map map = eReportStudentService.getReportStuState(examid,studentid);
        return new ResultVo(0, "获取成功", map);
    }

}
