package com.xhkjedu.sclass.controller.classroom;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.annotation.Action;
import com.xhkjedu.sclass.mapper.system.UserMapper;
import com.xhkjedu.sclass.model.classroom.*;
import com.xhkjedu.sclass.model.paperstudent.TPaperStudent;
import com.xhkjedu.sclass.model.paperstudent.TPaperStudentScantron;
import com.xhkjedu.sclass.service.classroom.ClassroomPaperService;
import com.xhkjedu.sclass.service.classroom.ClassroomService;
import com.xhkjedu.sclass.vo.classroom.*;
import com.xhkjedu.sclass.vo.paper.CheckClassVo;
import com.xhkjedu.sclass.vo.paperstudent.StudentVo;
import com.xhkjedu.sclass.vo.room.DirectorVo;
import com.xhkjedu.sclass.vo.room.RoomPVo;
import com.xhkjedu.sclass.vo.room.RoomParamVo;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.utils.PageUtil;
import com.xhkjedu.vo.PageResult;
import com.xhkjedu.vo.ResultVo;
import com.xhkjedu.vo.system.UserVo;
import lombok.extern.slf4j.Slf4j;
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.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("room")
@Slf4j
public class ClassroomController {

    @Resource
    private ClassroomService classroomService;
    @Resource
    private ClassroomPaperService classroomPaperService;
    @Resource
    private UserMapper userMapper;

    /**
     * 批量保存课堂数据
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [rooms]
     * @Author ywx
     * @Date 2022/6/29 10:31
     **/
    @PostMapping("/saveclass")
    @Action("课堂管理-增加")
    public ResultVo saveClass(@RequestBody List<RoomPVo> rooms) {
        List<TClassroom> startclassList = new ArrayList<>();//开始课堂集合
        List<TClassroom> stopclassList = new ArrayList<>();//结束课堂集合
        List<TClassroomFile> savefileList = new ArrayList<>();//结束课堂集合
        List<TClassroomAskteacher> askteacherList = new ArrayList<>();//结束课堂集合
        List<TClassroomAskstudent> askstudentList = new ArrayList<>();//结束课堂集合
        List<TClassroomSign> signList = new ArrayList<>();//结束课堂集合
        List<TClassroomPaper> paperList = new ArrayList<>();//结束课堂集合
        List<TClassroomPaperStudent> stupaperList = new ArrayList<>();//结束课堂集合
        List<TClassroomPaperFile> paperFileList = new ArrayList<>();//堂测附件集合
        List<TClassroomPaperQtype> paperQtypeList = new ArrayList<>();//堂测答题卡集合
        List<TClassroomPaperScantron> paperScantronList = new ArrayList<>();//堂测答题卡--题型试题集合
        List<TClassroomVote> voteList = new ArrayList<>();//课堂投票集合
        List<TClassroomVoteStudent> votestuList = new ArrayList<>();//课堂投票--学生投票
        List<TClassroomProfile> profileList = new ArrayList<>();//资料
        List<TClassroomProfileStudent> profileStudentList = new ArrayList<>();//资料--学生

        if(N_Utils.isListEmpty(rooms)) return new ResultVo(0,"保存成功");
        String nodename = rooms.get(0).getNodename();
        Map<Integer,Integer> schoolmap = new HashMap<>();
        rooms.forEach(r -> {
            List<RoomParamVo> params = r.getParams();
            params.forEach(param -> {
                String rtype = param.getRtype();
                String jsonstr = param.getJsonstr();
                N_Utils.validation(new Object[]{rtype, "请求类型", 2, jsonstr, "请求json", 2});
                if (rtype.equals("startclass")) {//课堂--开始
                    TClassroom room = JSON.parseObject(jsonstr, TClassroom.class);
                    Integer schoolyear = null;
                    if(!schoolmap.isEmpty() && schoolmap.containsKey(room.getSchoolid())){
                        schoolyear = schoolmap.get(room.getSchoolid());
                    }else{
                        schoolyear = classroomService.getSchoolYearBySchoolid(room.getSchoolid());
                        schoolmap.put(room.getSchoolid(),schoolyear);
                    }
                    room.setYear(schoolyear);
                    startclassList.add(room);
                } else if (rtype.equals("stopclass")) {//课堂--结束
                    TClassroom room = JSON.parseObject(jsonstr, TClassroom.class);
                    stopclassList.add(room);
                } else if (rtype.equals("savefile")) {//课堂--保存图片
                    TClassroomFile file = JSON.parseObject(jsonstr, TClassroomFile.class);
                    if (N_Utils.isNotEmpty(file.getRfpath())) {
                        if(N_Utils.isNotEmpty(nodename)) {
                            file.setRfpath(nodename + "/" + file.getRfpath());
                        }
                        savefileList.add(file);
                    }
                } else if (rtype.equals("askteacher")) {//互动--发起
                    TClassroomAskteacher teacher = JSON.parseObject(jsonstr, TClassroomAskteacher.class);
                    String teacherpic = teacher.getTeacherpic();
                    if (N_Utils.isNotEmpty(nodename) && N_Utils.isNotEmpty(teacherpic)) {
                        teacher.setTeacherpic(nodename + "/" + teacherpic);
                    }
                    askteacherList.add(teacher);
                } else if (rtype.equals("askstudent")) {//互动--保存学生作答情况
                    TClassroomAskstudent student = JSON.parseObject(jsonstr, TClassroomAskstudent.class);
                    String studentpic = student.getStudentpic();
                    if (N_Utils.isNotEmpty(nodename) && N_Utils.isNotEmpty(studentpic)) {
                        student.setStudentpic(nodename + "/" + studentpic);
                    }
                    askstudentList.add(student);
                } else if (rtype.equals("sign")) {//学生--签到
                    TClassroomSign sign = JSON.parseObject(jsonstr, TClassroomSign.class);
                    signList.add(sign);
                } else if (rtype.equals("paperteacher") || "paper".equals(rtype)) {//堂测--发布
                    TClassroomPaper paper = JSON.parseObject(jsonstr, TClassroomPaper.class);

                    //堂测附件
                    List<TClassroomPaperFile> lst = paper.getPfiles();
                    for (TClassroomPaperFile pf : lst) {
                        if (N_Utils.isEmpty(pf.getFilepath())) continue;//地址为空不处理
                        pf.setCreateid(paper.getCreateid());
                        pf.setCreatetime(paper.getCreatetime());
                        pf.setSchoolid(paper.getSchoolid());
                        pf.setPaperid(paper.getPaperid());
                        if(N_Utils.isNotEmpty(nodename)) {
                            pf.setFilepath(nodename + "/" + pf.getFilepath());
                        }
                        paperFileList.add(pf);
                    }

                    //答题卡信息
                    int sorder = 1;//答题卡试题序号
                    int qtypeorder = 1;//答题卡题型序号
                    //处理答题卡--题型--试题
                    List<TClassroomPaperQtype> qtypes = paper.getQtypes();
                    for (TClassroomPaperQtype qtype : qtypes) {
                        List<TClassroomPaperScantron> scanlst = qtype.getScantrons();//题型下试题
                        qtype.setCreateid(paper.getCreateid());
                        qtype.setCreatetime(paper.getCreatetime());
                        qtype.setSchoolid(paper.getSchoolid());
                        qtype.setPqnum(scanlst.size());
                        Double qtypescore = scanlst.stream().collect(Collectors.summingDouble(TClassroomPaperScantron::getPsscore));
                        qtype.setPqscore(qtypescore);
                        qtype.setPaperid(paper.getPaperid());
                        qtype.setPqorder(qtypeorder);
                        paperQtypeList.add(qtype);
                        qtypeorder++;
                        Integer optionnum = qtype.getOptionnum();
                        for (TClassroomPaperScantron sc : scanlst) {
                            sc.setCreateid(paper.getCreateid());
                            sc.setCreatetime(paper.getCreatetime());
                            sc.setSchoolid(paper.getSchoolid());
                            sc.setPaperid(paper.getPaperid());
                            sc.setPsorder(sorder);
                            if(N_Utils.isTrueInteger(optionnum)) {
                                sc.setOptionnum(optionnum);
                            }else {
                                sc.setOptionnum(0);
                            }
                            paperScantronList.add(sc);
                            sorder++;
                        }
                    }
                    paperList.add(paper);
                } else if (rtype.equals("paperstudent") || "stupaper".equals(rtype)) {//堂测--学生作答详情
                    TClassroomPaperStudent student = JSON.parseObject(jsonstr, TClassroomPaperStudent.class);
                    stupaperList.add(student);
                } else if (rtype.equals("voteteacher")){//投票
                    TClassroomVote vote = JSON.parseObject(jsonstr,TClassroomVote.class);
                    vote.setOptions(JSON.toJSONString(vote.getOptionlist()));
                    voteList.add(vote);
                } else if(rtype.equals("votestudent")){//投票--学生投票
                    TClassroomVoteStudent stuvote = JSON.parseObject(jsonstr,TClassroomVoteStudent.class);
                    votestuList.add(stuvote);
                } else if("profileteacher".equals(rtype)){//资料
                    TClassroomProfile profile = JSON.parseObject(jsonstr,TClassroomProfile.class);
                    if(N_Utils.isEmpty(profile.getProfilesuffix())){
                        profile.setProfilesuffix("doc");
                    }
                    profileList.add(profile);
                } else if("profilestudent".equals(rtype)){//资料--学生
                    TClassroomProfileStudent stuProfile = JSON.parseObject(jsonstr,TClassroomProfileStudent.class);
                    profileStudentList.add(stuProfile);
                }
            });
        });
        return classroomService.batchSaveClass(rooms,startclassList, stopclassList, savefileList
                , askteacherList, askstudentList, signList
                , paperList, nodename, stupaperList, paperFileList, paperQtypeList, paperScantronList, voteList, votestuList,profileList,profileStudentList);
    }

    /**
     * 保存单个课堂数据
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [r]
     * @Author ywx
     * @Date 2022/6/30 11:23
     **/
    @PostMapping("/save_class")
    @Action("课堂管理-增加")
    public ResultVo saveOneClass(@RequestBody RoomPVo r) {
        List<RoomParamVo> params = r.getParams();
        if(!classroomService.isSave(params, r.getRoomid())) return new ResultVo(0, "无需保存");
        String roomname = classroomService.getNameById(r.getRoomid());
        //课堂数据已经存在直接返回保存成功
        if (N_Utils.isNotEmpty(roomname)) return new ResultVo(0, "保存成功");

        TClassroom startclass = new TClassroom();//开始课堂
        TClassroom stopclass = new TClassroom();//结束课堂
        List<TClassroomFile> savefileList = new ArrayList<>();//结束课堂集合
        List<TClassroomAskteacher> askteacherList = new ArrayList<>();//结束课堂集合
        List<TClassroomAskstudent> askstudentList = new ArrayList<>();//结束课堂集合
        List<TClassroomSign> signList = new ArrayList<>();//结束课堂集合
        List<TClassroomPaper> paperList = new ArrayList<>();//结束课堂集合
        List<TClassroomPaperStudent> stupaperList = new ArrayList<>();//结束课堂集合
        List<TClassroomPaperFile> paperFileList = new ArrayList<>();//堂测附件集合
        List<TClassroomPaperQtype> paperQtypeList = new ArrayList<>();//堂测答题卡集合
        List<TClassroomPaperScantron> paperScantronList = new ArrayList<>();//堂测答题卡--题型试题集合
        List<TClassroomVote> voteList = new ArrayList<>();//课堂投票
        List<TClassroomVoteStudent> votestuList = new ArrayList<>();//课堂投票--学生投票
        List<TClassroomProfile> profileList = new ArrayList<>();//资料
        List<TClassroomProfileStudent> profileStudentList = new ArrayList<>();//资料--学生

        String nodename = r.getNodename();
        for (RoomParamVo param : params) {
            String rtype = param.getRtype();
            String jsonstr = param.getJsonstr();
            N_Utils.validation(new Object[]{rtype, "请求类型", 2, jsonstr, "请求json", 2});
            if ("startclass".equals(rtype)) {//课堂--开始
                startclass = JSON.parseObject(jsonstr, TClassroom.class);
                int schoolyear = classroomService.getSchoolYearBySchoolid(startclass.getSchoolid());
                startclass.setYear(schoolyear);
            } else if ("stopclass".equals(rtype)) {//课堂--结束
                stopclass = JSON.parseObject(jsonstr, TClassroom.class);
            } else if ("savefile".equals(rtype)) {//课堂--保存图片
                TClassroomFile file = JSON.parseObject(jsonstr, TClassroomFile.class);
                if (N_Utils.isNotEmpty(file.getRfpath())) {
                    if(N_Utils.isNotEmpty(nodename)) {
                        file.setRfpath(nodename + "/" + file.getRfpath());
                    }
                    savefileList.add(file);
                }
            } else if ("askteacher".equals(rtype)) {//互动--发起
                TClassroomAskteacher teacher = JSON.parseObject(jsonstr, TClassroomAskteacher.class);
                String teacherpic = teacher.getTeacherpic();
                if (N_Utils.isNotEmpty(nodename) && N_Utils.isNotEmpty(teacherpic)) {
                    teacher.setTeacherpic(nodename + "/" + teacherpic);
                }
                askteacherList.add(teacher);
            } else if ("askstudent".equals(rtype)) {//互动--保存学生作答情况
                TClassroomAskstudent student = JSON.parseObject(jsonstr, TClassroomAskstudent.class);
                String studentpic = student.getStudentpic();
                if (N_Utils.isNotEmpty(nodename) && N_Utils.isNotEmpty(studentpic)) {
                    student.setStudentpic(nodename + "/" + studentpic);
                }
                askstudentList.add(student);
            } else if ("sign".equals(rtype)) {//学生--签到
                TClassroomSign sign = JSON.parseObject(jsonstr, TClassroomSign.class);
                signList.add(sign);
            } else if ("paperteacher".equals(rtype) || "paper".equals(rtype)) {//堂测--发布
                TClassroomPaper paper = JSON.parseObject(jsonstr, TClassroomPaper.class);
                if(N_Utils.isEmpty(paper.getPapername())){
                    paper.setPapername("课堂测试");
                }

                //堂测附件
                List<TClassroomPaperFile> lst = paper.getPfiles();
                for (TClassroomPaperFile pf : lst) {
                    if (N_Utils.isEmpty(pf.getFilepath())) continue;//地址为空不处理
                    pf.setCreateid(paper.getCreateid());
                    pf.setCreatetime(paper.getCreatetime());
                    pf.setSchoolid(paper.getSchoolid());
                    pf.setPaperid(paper.getPaperid());
                    if(N_Utils.isNotEmpty(nodename)) {
                        pf.setFilepath(nodename + "/" + pf.getFilepath());
                    }
                    paperFileList.add(pf);
                }

                //答题卡信息
                int sorder = 1;//答题卡试题序号
                int qtypeorder = 1;//答题卡题型序号
                //处理答题卡--题型--试题
                List<TClassroomPaperQtype> qtypes = paper.getQtypes();
                for (TClassroomPaperQtype qtype : qtypes) {
                    List<TClassroomPaperScantron> scanlst = qtype.getScantrons();//题型下试题
                    qtype.setCreateid(paper.getCreateid());
                    qtype.setCreatetime(paper.getCreatetime());
                    qtype.setSchoolid(paper.getSchoolid());
                    qtype.setPqnum(scanlst.size());
                    Double qtypescore = scanlst.stream().collect(Collectors.summingDouble(TClassroomPaperScantron::getPsscore));
                    qtype.setPqscore(qtypescore);
                    qtype.setPaperid(paper.getPaperid());
                    qtype.setPqorder(qtypeorder);
                    paperQtypeList.add(qtype);
                    qtypeorder++;

                    Integer optionnum = qtype.getOptionnum();
                    for (TClassroomPaperScantron sc : scanlst) {
                        sc.setCreateid(paper.getCreateid());
                        sc.setCreatetime(paper.getCreatetime());
                        sc.setSchoolid(paper.getSchoolid());
                        sc.setPaperid(paper.getPaperid());
                        if(sc.getPqtypeid()==null || sc.getPqtypeid() == 0){
                            sc.setPqtypeid(qtype.getPqtypeid());
                        }
                        sc.setPsorder(sorder);
                        if(N_Utils.isTrueInteger(optionnum)) {
                            sc.setOptionnum(optionnum);
                        }else {
                            sc.setOptionnum(0);
                        }

                        paperScantronList.add(sc);
                        sorder++;
                    }
                }
                paperList.add(paper);
            } else if ("paperstudent".equals(rtype) || "stupaper".equals(rtype)) {//堂测--学生作答详情
                TClassroomPaperStudent student = JSON.parseObject(jsonstr, TClassroomPaperStudent.class);
                stupaperList.add(student);
            } else if ("voteteacher".equals(rtype)){//投票
                TClassroomVote vote = JSON.parseObject(jsonstr,TClassroomVote.class);
                vote.setOptions(JSON.toJSONString(vote.getOptionlist()));
                voteList.add(vote);
            } else if("votestudent".equals(rtype)){//投票--学生投票
                TClassroomVoteStudent stuvote = JSON.parseObject(jsonstr,TClassroomVoteStudent.class);
                votestuList.add(stuvote);
            } else if("profileteacher".equals(rtype)){//资料
                TClassroomProfile profile = JSON.parseObject(jsonstr,TClassroomProfile.class);
                if(N_Utils.isEmpty(profile.getProfilesuffix())){
                    profile.setProfilesuffix("doc");
                }

                if(N_Utils.isNotEmpty(nodename)) {
                    profile.setProfileurl(nodename + "/" + profile.getProfileurl());
                }
                profileList.add(profile);
            } else if("profilestudent".equals(rtype)){//资料--学生
                TClassroomProfileStudent stuProfile = JSON.parseObject(jsonstr,TClassroomProfileStudent.class);
                profileStudentList.add(stuProfile);
            }
        }
        return classroomService.saveClass(r,startclass, stopclass, savefileList
                , askteacherList, askstudentList, signList
                , paperList, nodename, stupaperList, paperFileList, paperQtypeList, paperScantronList, voteList, votestuList, profileList, profileStudentList);
    }

    @PostMapping("/list_correct")
    public ResultVo listCorrect(@RequestBody RoomVo room) {
        Long roomid = room.getRoomid();
        N_Utils.validation(new Object[]{roomid, "课堂id", 1});
        RoomCorrectVo correct = classroomService.listCorrect(roomid);
        return new ResultVo(0, "获取批阅信息成功", correct);
    }

    @PostMapping("/check_students_call")
    public ResultVo listStudentsByAskTid(@RequestBody RoomCorrectCallVo call) {
        Long asktid = call.getAsktid();
        N_Utils.validation(new Object[]{asktid, "互动id", 1});
        CheckClassVo checkVo = classroomService.listStudentsByAskTid(asktid);
        return new ResultVo(0, "获取提问批改学生列表成功", checkVo);
    }

    @PostMapping("/check_students_exam")
    public ResultVo listStudentsByPaperId(@RequestBody RoomCorrectExamVo exam) {
        Long paperid = exam.getPaperid();
        N_Utils.validation(new Object[]{paperid, "考试id", 1});
        CheckClassVo checkVo = classroomService.listStudentsByPaperId(paperid);
        return new ResultVo(0, "获取考试批改学生列表成功", checkVo);
    }

    @PostMapping("call_objective")
    public ResultVo callObjective(@RequestBody RoomCorrectCallVo call) {
        Long asktid = call.getAsktid();
        N_Utils.validation(new Object[]{asktid, "互动id", 1});
        try {
            ObjectiveVo objective = classroomService.callObjective(asktid, call.getRealstunum());
            return new ResultVo(0, "获取课堂提问客观题详情成功", objective);
        } catch (Exception e) {
            log.error("获取课堂提问客观题详情失败：" + e.getMessage());
            return new ResultVo(1, "获取课堂提问客观题详情失败");
        }
    }

    @PostMapping("exam_objective")
    public ResultVo examObjective(@RequestBody ReportEQuestionVo question) {
        Long pscaid = question.getPscaid();
        N_Utils.validation(new Object[]{pscaid, "答题卡id", 1});
        try {
            ObjectiveVo objective = classroomService.examObjective(pscaid, question.getRealstunum());
            return new ResultVo(0, "获取课堂考试客观题详情成功", objective);
        } catch (Exception e) {
            log.error("获取课堂考试客观题详情失败：" + e.getMessage());
            return new ResultVo(1, "获取课堂考试客观题详情失败");
        }
    }

    @PostMapping("call_subjective")
    public ResultVo callSubjective(@RequestBody RoomCorrectCallVo call) {
        Long asktid = call.getAsktid();
        N_Utils.validation(new Object[]{asktid, "互动id", 1});
        try {
            SubjectiveVo subjective = classroomService.callSubjective(asktid, call.getRealstunum());
            return new ResultVo(0, "获取课堂提问主观题详情成功", subjective);
        } catch (Exception e) {
            log.error("获取课堂提问客观题详情失败：" + e.getMessage());
            return new ResultVo(1, "获取课堂提问主观题详情失败");
        }
    }

    @PostMapping("exam_subjective")
    public ResultVo examSubjective(@RequestBody ReportEQuestionVo question) {
        Long pscaid = question.getPscaid();
        N_Utils.validation(new Object[]{pscaid, "答题卡id", 1});
        try {
            SubjectiveVo subjective = classroomService.examSubjective(pscaid, question.getRealstunum());
            return new ResultVo(0, "获取课堂考试主观题详情成功", subjective);
        } catch (Exception e) {
            log.error("获取课堂考试客观题详情失败：" + e.getMessage());
            return new ResultVo(1, "获取课堂考试主观题详情失败");
        }
    }

    @PostMapping("/correct_call")
    public ResultVo correctCall(@RequestBody StudentVo student) {
        Integer psid = student.getPsid();
        Integer pschecked = student.getPschecked();
        N_Utils.validation(new Object[]{psid, "互动学生id", 1, pschecked, "批改结果", 1});
        classroomService.correctCall(psid, pschecked);
        return new ResultVo(0, "批阅成功");
    }

    @PostMapping("/correct_exam")
    public ResultVo correctExam(@RequestBody TPaperStudent ps) {
        Integer psid = ps.getPsid();
        Integer checkid = ps.getCreateid();
        String questionResult = ps.getQuestionResult();
        N_Utils.validation(new Object[]{psid, "试卷学生id", 1, checkid, "批改人id", 1});
        try {
            int result = classroomPaperService.correctExam(psid, checkid, questionResult);
            if (result > 0) {
                return new ResultVo(0, "批阅成功", 0);
            } else {
                return new ResultVo(0, "批阅完成", 1);
            }
        } catch (Exception e) {
            return new ResultVo(1, "批阅失败");
        }
    }

    @PostMapping("/list_correct_question")
    public ResultVo listCorrectQuestion(@RequestBody TPaperStudent paperStudent) {
        Integer psid = paperStudent.getPsid();
        N_Utils.validation(new Object[]{psid, "考试学生id", 1});
        //根据考试学生id获取考试是否完成批阅
        /*Integer checked = roomPaperService.getCheckedByPsId(psid);
        if (checked == 1){
            return new ResultVo(1,"考试已结束批阅");
        }*/
        List<Map> paperQuestions = classroomPaperService.listCorrectQuestion(psid);
        return new ResultVo(0, "获取考试学生待批改试题列表成功！", paperQuestions);
    }

    @PostMapping("/mark_call")
    public ResultVo markCall(@RequestBody StudentVo student) {
        Integer psid = student.getPsid();
        String studentpic = student.getStudentpic();
        N_Utils.validation(new Object[]{psid, "互动学生id", 1, studentpic, "批改结果", 1});
        classroomService.updateStudentpic(psid, studentpic);
        return new ResultVo(0, "保存成功");
    }

    @PostMapping("/mark_question")
    public ResultVo markQuestion(@RequestBody TPaperStudentScantron ps) {
        Integer pssid = ps.getPssid();
        String useranswer = ps.getUseranswer();
        N_Utils.validation(new Object[]{pssid, "考试学生试题id", 1, useranswer, "批改结果", 2});
        classroomPaperService.updateScantronUseranswer(pssid, useranswer);
        return new ResultVo(0, "保存成功");
    }

    //学生app 课堂回顾列表
    @PostMapping("list_class_stu")
    public ResultVo listStuClass(@RequestBody TClassroom room) {
        Integer studentid = room.getStudentid();
        Integer page = room.getPage();
        Integer pageSize = room.getPageSize();
        N_Utils.validation(new Object[]{studentid, "学生id", 1
                , page, "显示页码", 1, pageSize, "显示条数", 1});
        try {

            //获取所选章节信息
            if(N_Utils.isNotEmpty(room.getDirectorid()) && !"0".equals(room.getDirectorid())){
                DirectorVo director = classroomService.getDirectorById(room.getDirectorid());
                room.setDirectorLeaf(director.getLeaf());
                //leaf 是否是叶子节点0不是1是
                if(director.getLeaf() == 0){
                    //说明不是叶子节点，需要获取其子章节所有信息
                    room.setDirectorall(director.getDirectorall());
                }
            }

            PageHelper.startPage(page, pageSize);
            List<Map> list = classroomService.listStuClass(room);
            PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(list));
            return new ResultVo(0, "获取学生课堂回顾列表成功", pageResult);
        } catch (Exception e) {
            log.error("获取学生课堂回顾列表失败：" + e.getMessage());
            return new ResultVo(1, "获取学生课堂回顾列表失败");
        }
    }

    @PostMapping("/report_stu")
    public ResultVo reportStu(@RequestBody TClassroom room) {
        Long roomid = room.getRoomid();
        Integer createid = room.getCreateid();
        N_Utils.validation(new Object[]{roomid, "课堂id", 1, createid, "学生id", 1});
        return classroomService.getReportStu(roomid, createid);
    }

    /**
     * 获取课堂回顾列表（教师网页端）
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [room]
     * @Author ywx
     * @Date 2020/6/15 10:57
     **/
    @PostMapping("list_class_directorid")
    public ResultVo listClassByDirectorId(@RequestBody TClassroom room) {
        Integer teacherid = room.getTeacherid();
        Integer page = room.getPage();
        Integer pageSize = room.getPageSize();
        N_Utils.validation(new Object[]{teacherid, "教师id", 1, page, "显示页码", 1, pageSize, "显示条数", 1});
        try {
            UserVo userVo = userMapper.getUserInfoForHandleLog(teacherid);

            //获取所选章节信息
            if(N_Utils.isNotEmpty(room.getDirectorid()) && !"0".equals(room.getDirectorid())){
                DirectorVo director = classroomService.getDirectorById(room.getDirectorid());
                room.setDirectorLeaf(director.getLeaf());
                //leaf 是否是叶子节点0不是1是
                if(director.getLeaf() == 0){
                    //说明不是叶子节点，需要获取其子章节所有信息
                    room.setDirectorall(director.getDirectorall());
                }
            }

            PageHelper.startPage(page, pageSize);
            List<Map> list = classroomService.listClassByDirectorId(room, userVo);
            PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(list));
            return new ResultVo(0, "获取课堂回顾列表成功", pageResult);
        } catch (Exception e) {
            log.error("获取课堂回顾列表失败：" + e.getMessage());
            return new ResultVo(1, "获取课堂回顾列表失败");
        }
    }

    /**
     * @Description 删除
     * @Date 2023/11/17 14:26
     * @Author YWX
     * @Param [room]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/delete")
    public ResultVo delete(@RequestBody TClassroom room) {
        Long roomid = room.getRoomid();
        N_Utils.validation(new Object[]{roomid, "课堂id", 1});
        classroomService.deleteById(roomid);
        return new ResultVo(0, "删除成功");
    }

    /**
     * 课堂回顾详情
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [room]
     * @Author ywx
     * @Date 2020/6/26 9:36
     **/
    @PostMapping("/report")
    public ResultVo report(@RequestBody TClassroom room) {
        N_Utils.validation(new Object[]{room.getRoomid(), "课堂id", 1});
        return classroomService.getReport(room.getRoomid());
    }

    @PostMapping("/del_file")
    public ResultVo delFile(@RequestBody TClassroomFile file) {
        N_Utils.validation(new Object[]{file.getRfid(), "课堂图片id", 1});
        classroomService.delFile(file.getRfid());
        return new ResultVo(0, "删除成功");
    }

    @PostMapping("/list_student")
    public ResultVo listStudent(@RequestBody TClassroom room) {
        N_Utils.validation(new Object[]{room.getClassid(), "班级id", 1, room.getLsbid(), "教材关联id", 2});
        List<Map> list = classroomService.listStudent(room.getClassid(), room.getLsbid());
        return new ResultVo(0, "获取班级学生列表成功", list);
    }

    @PostMapping("/list_estudent")
    public ResultVo listEStudent(@RequestBody TClassroomPaper paper) {
        Long paperid = paper.getPaperid();
        Integer page = paper.getPage();
        Integer pageSize = paper.getPageSize();
        N_Utils.validation(new Object[]{paperid, "考试id", 1, page, "显示页码", 1, pageSize, "显示条数", 1});
        PageHelper.startPage(page, pageSize);
        List<Map> list = classroomPaperService.listEStudent(paperid);
        PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(list));
        return new ResultVo(0, "获取考试按人统计列表成功", pageResult);
    }

    /*
     * @Description 投票详情
     * @Date 2024/6/11 14:33:12
     * @Author WN
     * @Param [vote]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/detail_vote")
    public ResultVo detailVote(@RequestBody TClassroomVote vote) {
        Long voteid = vote.getVoteid();
        N_Utils.validation(new Object[]{voteid, "投票id", 1});
        List<Map<String,Object>> votes = classroomService.getVoteDetail(voteid);
        return new ResultVo(0, "获取投票详情成功", votes);
    }
}
