package com.xhkjedu.sexam.controller.report;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.sexam.model.reportstu.ERstudent;
import com.xhkjedu.sexam.model.reportstu.ERstudentAction;
import com.xhkjedu.sexam.service.report.EReportClassService;
import com.xhkjedu.sexam.utils.ExamUtil;
import com.xhkjedu.sexam.vo.report.ERankParamVo;
import com.xhkjedu.sexam.vo.report.ReportParamsVo;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.utils.PageUtil;
import com.xhkjedu.vo.PageResult;
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.List;
import java.util.Map;

/**
 * @author ywx
 * @classname EReportClassController
 * @description 班级报告
 * @date 2022/8/8 9:44
 **/
@RestController
@RequestMapping("erc")
public class EReportClassController {
    @Resource
    private EReportClassService eReportClassService;

    /**
     * 考试概况--科目
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [rank]
     * @Author ywx
     * @Date 2022/8/30 9:20
     **/
    @PostMapping("/list_xkcj")
    public ResultVo listXkCj(@RequestBody ERankParamVo rank) {
        Integer examid = rank.getExamid();
        Integer classid = rank.getClassid();
        N_Utils.validation(new Object[]{examid, "考试id", 1, classid, "班级id", 1});
        List<Map> list = eReportClassService.listXkCj(examid, classid);
        return new ResultVo(0, "获取成功", list);
    }

    /**
     * 成绩单
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [stu]
     * @Author ywx
     * @Date 2022/8/30 9:36
     **/
    @PostMapping("/list_cjd")
    public ResultVo listCjd(@RequestBody ERstudent stu) {
        Integer examid = stu.getExamid();
        Integer page = stu.getPage();
        N_Utils.validation(new Object[]{examid, "考试id", 1, stu.getClassid(), "班级id", 1});
        if (N_Utils.isEmptyInteger(page)) {
            List<Map> list = eReportClassService.listCjd(stu);
            return new ResultVo(0, "获取成功", list);
        } else {
            List<Map> list = eReportClassService.listCjd(stu);
            PageResult pageResult = ExamUtil.getCjdPageResult(stu, list);
            return new ResultVo(0, "获取成功", pageResult);
        }
    }

    /*
     * 成绩分析-搜索
     * @Param [rank]
     * @Author ywx
     * @Date 2022/8/30 9:55
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/cjfx_ss")
    public ResultVo listCjFxForSearch(@RequestBody ERankParamVo rank) {
        N_Utils.validation(new Object[]{rank.getExamid(), "考试id", 1, rank.getClassid(), "班级id", 1});
        List<Map> map = eReportClassService.listCjFxForSearch(rank);
        return new ResultVo(0, "获取成功", map);
    }

    /*
     * 成绩分析-设置
     * @Param [rank]
     * @Author ywx
     * @Date 2022/8/30 10:07
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/cjfx_sz")
    public ResultVo listCjFxForSet(@RequestBody ERankParamVo rank) {
        N_Utils.validation(new Object[]{rank.getExamid(), "考试id", 1, rank.getCreateid(), "操作人id", 1, rank.getSubjectid(), "科目id", 2});
        List<Map> map = eReportClassService.listCjFxForSet(rank);
        return new ResultVo(0, "获取成功", map);
    }

    /*
     * 单科概况
     * @Param [rank]
     * @Author ywx
     * @Date 2022/8/31 10:28
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/get_dkgk")
    public ResultVo getDkGk(@RequestBody ERankParamVo rank) {
        N_Utils.validation(new Object[]{rank.getExamid(), "考试id", 1, rank.getClassid(), "班级id", 1
                , rank.getSubjectid(), "科目id", 2});
        Map map = eReportClassService.getDkGk(rank);
        return new ResultVo(0, "获取成功", map);
    }

    /**
     * 单科概况-平均分
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [rank]
     * @Author ywx
     * @Date 2022/9/7 14:41
     **/
    @PostMapping("/list_pjf")
    public ResultVo listPjf(@RequestBody ERankParamVo rank) {
        N_Utils.validation(new Object[]{rank.getExamid(), "考试id", 1, rank.getClassid(), "班级id", 1
                , rank.getSubjectid(), "科目id", 2});
        List<Map> list = eReportClassService.listPjf(rank);
        return new ResultVo(0, "获取成功", list);
    }

    /**
     * 单科概况-高频错题
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [rank]
     * @Author ywx
     * @Date 2022/9/7 14:41
     **/
    @PostMapping("/list_gpct")
    public ResultVo listGpCt(@RequestBody ERankParamVo rank) {
        N_Utils.validation(new Object[]{rank.getExamid(), "考试id", 1, rank.getClassid(), "班级id", 1
                , rank.getSubjectid(), "科目id", 2});
        List<Map> list = eReportClassService.listGpCt(rank);
        return new ResultVo(0, "获取成功", list);
    }

    /*
     * 单科概况-需关注学生
     * @Param [rank]
     * @Author ywx
     * @Date 2022/8/31 18:02
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list_gzxs")
    public ResultVo listGzXs(@RequestBody ERankParamVo rank) {
        N_Utils.validation(new Object[]{rank.getExamid(), "考试id", 1, rank.getClassid(), "班级id", 1
                , rank.getSubjectid(), "科目id", 2, rank.getRanktype(), "类型", 1});
        List<Map> list = eReportClassService.listGzXs(rank);
        return new ResultVo(0, "获取成功", list);
    }

    /**
     * 单科概况-等级统计
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [rank]
     * @Author ywx
     * @Date 2022/9/9 10:40
     **/
    @PostMapping("/dkgk_djtj")
    public ResultVo listDkGkDjTj(@RequestBody ERankParamVo rank) {
        N_Utils.validation(new Object[]{rank.getExamid(), "考试id", 1, rank.getClassid(), "班级id", 1
                , rank.getSubjectid(), "科目id", 2});
        List<Map> map = eReportClassService.listDkGkDjTj(rank);
        return new ResultVo(0, "获取成功", map);
    }

    /*
     * 试卷概况
     * @Param [rank]
     * @Author ywx
     * @Date 2022/9/1 8:36
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list_sjgk")
    public ResultVo listSjGk(@RequestBody ERankParamVo rank) {
        N_Utils.validation(new Object[]{rank.getExamid(), "考试id", 1, rank.getClassid(), "班级id", 1
                , rank.getSubjectid(), "科目id", 2});
        Map list = eReportClassService.listSjGk(rank);
        return new ResultVo(0, "获取成功", list);
    }

    /*
     * 试卷分析
     * @Param [rank]
     * @Author ywx
     * @Date 2022/9/1 10:59
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/get_sjfx")
    public ResultVo getSjFx(@RequestBody ERankParamVo rank) {
        N_Utils.validation(new Object[]{rank.getExamid(), "考试id", 1, rank.getClassid(), "班级id", 1
                , rank.getSubjectid(), "科目id", 2});
        Map map = eReportClassService.getSjFx(rank);
        return new ResultVo(0, "获取成功", map);
    }

    /*
     * 行为分析-科目
     * @Param [rank]
     * @Author ywx
     * @Date 2022/9/2 11:36
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list_xw_km")
    public ResultVo listXwKm(@RequestBody ERstudentAction rank) {
        N_Utils.validation(new Object[]{rank.getExamid(), "考试id", 1, rank.getActiontype(), "类型", 1
                , rank.getClassid(), "班级id", 1});
        List<Map> map = eReportClassService.listXwKm(rank);
        return new ResultVo(0, "获取成功", map);
    }

    /*
     * 行为分析-学生
     * @Param [rank]
     * @Author ywx
     * @Date 2022/9/2 13:43
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list_xw_xs")
    public ResultVo listXwXs(@RequestBody ERstudentAction rank) {
        Integer page = rank.getPage();
        Integer pageSize = rank.getPageSize();
        N_Utils.validation(new Object[]{rank.getExamid(), "考试id", 1, rank.getActiontype(), "类型", 1
                , rank.getClassid(), "班级id", 1});
        if (N_Utils.isEmptyInteger(page)) {
            List<Map> list = eReportClassService.listXwXs(rank);
            return new ResultVo(0, "获取成功", list);
        } else {
            PageHelper.startPage(page, pageSize);
            List<Map> list = eReportClassService.listXwXs(rank);
            PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(list));
            return new ResultVo(0, "获取成功", pageResult);
        }
    }

    /*
     * 优秀试卷分析-详情
     * @Param [rank]
     * @Author ywx
     * @Date 2022/9/2 13:52
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/get_sjxq")
    public ResultVo getSjXq(@RequestBody ERankParamVo rank) {
        N_Utils.validation(new Object[]{rank.getExamid(), "考试id", 1
                , rank.getSubjectid(), "科目id", 2, rank.getCreateid(), "学生id", 1});
        Map map = eReportClassService.getSjXq(rank);
        return new ResultVo(0, "获取成功", map);
    }

    /**
     * 试卷概况-优秀卷
     *
     * @return com.xhkjedu.vo.ResultVo
     * @Param [rank]
     * @Author ywx
     * @Date 2022/9/13 9:54
     **/
    @PostMapping("/sjgk_yxj")
    public ResultVo listSjGkYxj(@RequestBody ERankParamVo rank) {
        N_Utils.validation(new Object[]{rank.getEpid(), "试卷id", 1, rank.getClassid(), "班级id", 1, rank.getQorder(), "试题排序", 1});
        List<Map> list = eReportClassService.listSjGkYxj(rank);
        return new ResultVo(0, "获取成功", list);
    }

    /**
     * @Description 教师权限班级已结束考试列表
     * @Param [paramsVo]
     * @Return com.xhkjedu.vo.ResultVo
     * @Author wn
     * @Date 2022/9/21 9:47
     **/
    @PostMapping("/ends")
    public ResultVo listEndExamsForClass(@RequestBody ReportParamsVo paramsVo) {
        Integer page = paramsVo.getPage();
        Integer pageSize = paramsVo.getPageSize();
        int userid = paramsVo.getUserid();
        N_Utils.validation(new Object[]{userid, "用户id", 1
                , page, "显示页码", 1, pageSize, "显示条数", 1});
        PageHelper.startPage(page, pageSize);
        List<Map> list = eReportClassService.listEndExamsForClassTeacher(paramsVo);
        PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(list));
        return new ResultVo(0, "获取成功", pageResult);
    }

    /**
     * @Description 获取考试关联的教师权限下班级
     * @Param [paramsVo]
     * @Return com.xhkjedu.vo.ResultVo
     * @Author wn
     * @Date 2022/9/22 11:20
     **/
    @PostMapping("/ecl")
    public ResultVo listExamQxClassTeacher(@RequestBody ReportParamsVo paramsVo) {
        N_Utils.validation(new Object[]{paramsVo.getUserid(), "用户id", 1,paramsVo.getExamid(),"考试id",1});
        List<Map> list = eReportClassService.listExamQxClassTeacher(paramsVo);
        return new ResultVo(0, "获取成功", list);
    }
}
