package com.xhkjedu.smarking.controller.report;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.smarking.model.exam.MsSubject;
import com.xhkjedu.smarking.model.report.reportclass.MsrClassSubjectGrade;
import com.xhkjedu.smarking.model.report.reportstu.MsrStudentAction;
import com.xhkjedu.smarking.model.report.reportsubject.MsrSubject;
import com.xhkjedu.smarking.service.report.report.*;
import com.xhkjedu.smarking.vo.report.reportother.ExamReportParams;
import com.xhkjedu.smarking.vo.report.reportstu.StudentParams;
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;

/**
 * @Description：综合报告
 * @Author: WN
 * @Date: 2024/12/24 9:25:37
 **/
@RestController
@RequestMapping("/rzh")
public class ZhReportController {

    @Resource
    private MsrStudentService msrStudentService;
    @Resource
    private MsrClassQuestionService msrClassQuestionService;
    @Resource
    private MsrSubjectService msrSubjectService;
    @Resource
    private MsrActionService msrActionService;
    @Resource
    private MsrClassService msrClassService;

    /**
     * @Description 总概览
     * @Date 2025/1/3 14:59
     * @Author YWX
     * @Param [subject]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/zgl")
    public ResultVo listSubjectForZgl(@RequestBody MsrSubject subject) {
        N_Utils.validation(new Object[]{subject.getExamid(), "考试id", 1});
        return new ResultVo(0, "获取成功", msrSubjectService.listSubjectForZgl(subject));
    }

    /**
     * @Description 排行榜-指标
     * @Date 2025/1/10 14:49
     * @Author YWX
     * @Param []
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/phb_zb")
    public ResultVo listPhbZb() {
        return new ResultVo(0, "获取成功", msrStudentService.listPhbZb());
    }

    /**
     * @Description 排行榜-列表
     * @Date 2025/1/6 9:11
     * @Author YWX
     * @Param [params]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/phb")
    public ResultVo listStudentForPhb(@RequestBody StudentParams params) {
        N_Utils.validation(new Object[]{
                params.getExamid(), "考试id", 1
                , params.getSubjectid(), "科目", 2
                , params.getClassids(), "班级", 3
                , params.getLabels(), "指标", 3
        });
        return new ResultVo(0, "获取成功", msrStudentService.listStudentForPhb(params));
    }

    /*
     * @Description 小分表-列表
     * @Date 2024/12/24 10:25:06
     * @Author WN
     * @Param [subject]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/xfb")
    public ResultVo listStudentForxfb(@RequestBody MsSubject subject){
        Integer page = subject.getPage();
        Integer pageSize = subject.getPageSize();
        N_Utils.validation(new Object[]{subject.getExamid(),"考试id",1,subject.getSubjectid(),"科目id",2,page,"显示页码",1,pageSize,"显示条数",1});
        PageHelper.startPage(page, pageSize);
        List<Map<String,Object>> rtnlst = msrStudentService.listStuScoreAndRank(subject.getExamid(), subject.getSubjectid());
        PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(rtnlst));
        return new ResultVo(0,"获取成功",pageResult);
    }

    /**
     * @Description 班级对比表-指标列表
     * @Date 2025/1/8 9:01
     * @Author YWX
     * @Param [params]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/bjdb_zb")
    public ResultVo listBjDbZb(@RequestBody StudentParams params) {
        N_Utils.validation(new Object[]{
                params.getExamid(), "考试id", 1
                , params.getSubjectid(), "科目", 2
        });
        return new ResultVo(0, "获取成功", msrClassService.listBjDbZb(params));
    }

    /**
     * @Description 班级对比表-列表
     * @Date 2025/1/6 16:53
     * @Author YWX
     * @Param [params]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/bjdb")
    public ResultVo listClassForBjDb(@RequestBody StudentParams params) {
        List<Integer> classids = params.getClassids();
        N_Utils.validation(new Object[]{
                params.getExamid(), "考试id", 1
                , params.getSubjectid(), "科目", 2
                , classids, "班级", 3
                , params.getLabels(), "指标", 3
        });
        classids.add(0);
        return new ResultVo(0, "获取成功", msrClassService.listClassForBjDb(params));
    }

    /**
     * @Description 分数段统计-指标
     * @Date 2025/1/8 16:24
     * @Author YWX
     * @Param [params]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/fsd_zb")
    public ResultVo getFsdZb(@RequestBody StudentParams params) {
        N_Utils.validation(new Object[]{
                params.getExamid(), "考试id", 1
                , params.getSubjectid(), "科目", 2
        });
        return new ResultVo(0, "获取成功", msrClassService.getFsdZb(params));
    }

    /**
     * @Description 分数段统计-列表
     * @Date 2025/1/8 16:47
     * @Author YWX
     * @Param [params]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/fsd")
    public ResultVo listClassForFsd(@RequestBody StudentParams params) {
        List<Integer> classids = params.getClassids();
        N_Utils.validation(new Object[]{
                params.getExamid(), "考试id", 1
                , params.getSubjectid(), "科目", 2
                , classids, "班级", 3
                , params.getType(), "分段类型", 1
        });
        classids.add(0);
        params.setReportcode("zh");
        return new ResultVo(0, "获取成功", msrClassService.listClassForFsd(params));
    }

    /*
     * @Description 试题汇总-全部班-科目情况
     * @Date 2024/12/24 14:47:43
     * @Author WN
     * @Param [subject]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/sthz_qbb_km")
    public ResultVo getSubjectSummary(@RequestBody MsrClassSubjectGrade subject){
        N_Utils.validation(new Object[]{subject.getExamid(),"考试id",1,subject.getSubjectid(),"科目id",2});
        Map<String,Object> rtnMap = msrClassQuestionService.getSubjectForAllSmall(subject);
        return new ResultVo(0,"获取成功",rtnMap);
    }

    /*
     * @Description 试题汇总表-全部分类-按小题分析
     * @Date 2024/12/24 15:46:14
     * @Author WN
     * @Param [params]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/sthz_q")
    public ResultVo listQuestionForAllSmall(@RequestBody ExamReportParams params){
        N_Utils.validation(new Object[]{params.getExamid(),"考试id",1,params.getSubjectid(),"科目id",2});
        return new ResultVo(0,"获取成功",msrClassQuestionService.listQuestionForAllSmall(params));
    }

    /*
     * @Description 试题汇总表-全部分类-按大题分析
     * @Date 2024/12/24 17:19:02
     * @Author WN
     * @Param [params]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/sthz_qt")
    public ResultVo listQuestionForAllQtype(@RequestBody ExamReportParams params){
        N_Utils.validation(new Object[]{params.getExamid(),"考试id",1,params.getSubjectid(),"科目id",2});
        return new ResultVo(0,"获取成功",msrClassQuestionService.listQuestionForAllQtype(params));
    }

    /*
     * @Description 试题汇总表-全部分类-按主(客)题分析
     * @Date 2024/12/24 17:27:44
     * @Author WN
     * @Param [params]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/sthz_os")
    public ResultVo listQuestionForAllObjsub(@RequestBody ExamReportParams params){
        N_Utils.validation(new Object[]{params.getExamid(),"考试id",1,params.getSubjectid(),"科目id",2});
        return new ResultVo(0,"获取成功",msrClassQuestionService.listQuestionForAllObjsub(params));
    }

    /**
     * @Description 名次和比例分析-列表
     * @Date 2025/1/9 16:50
     * @Author YWX
     * @Param [params]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/mcbl")
    public ResultVo listClassForMcBl(@RequestBody StudentParams params) {
        List<Integer> classids = params.getClassids();
        N_Utils.validation(new Object[]{
                params.getExamid(), "考试id", 1
                , params.getSubjectid(), "科目", 2
                , classids, "班级", 3
                , params.getType(), "类型", 1
        });
        classids.add(0);
        return new ResultVo(0, "获取成功", msrClassService.listClassForMcBl(params));
    }

    /**
     * @Description 总分分档上线-列表
     * @Date 2025/1/10 9:26
     * @Author YWX
     * @Param [params]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/fdsx_zf")
    public ResultVo listClassForFdSxZf(@RequestBody StudentParams params) {
        List<Integer> classids = params.getClassids();
        N_Utils.validation(new Object[]{
                params.getExamid(), "考试id", 1
                , classids, "班级", 3
        });
        classids.add(0);
        params.setSubjectid("zf");
        return new ResultVo(0, "获取成功", msrClassService.listClassForFdSxZf(params));
    }

    /**
     * @Description 学科分档上线-列表
     * @Date 2025/1/10 11:35
     * @Author YWX
     * @Param [params]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/fdsx_xk")
    public ResultVo listClassForFdSxXk(@RequestBody StudentParams params) {
        List<Integer> classids = params.getClassids();
        N_Utils.validation(new Object[]{
                params.getExamid(), "考试id", 1
                , classids, "班级", 3
                ,params.getDworder(), "档位序号", 1
        });
        classids.add(0);
        return new ResultVo(0, "获取成功", msrClassService.listClassForFdSxXk(params));
    }

    /**
     * @Description 违纪优秀-班级统计
     * @Date 2025/1/3 14:47
     * @Author YWX
     * @Param [action]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/wjyx_bj")
    public ResultVo listXwBj(@RequestBody MsrStudentAction action) {
        N_Utils.validation(new Object[]{action.getExamid(), "考试id", 1, action.getActiontype(), "类型", 1});
        return new ResultVo(0, "获取成功", msrActionService.listXwBj(action));
    }

    /**
     * @Description 违纪优秀-学生统计
     * @Date 2025/1/3 14:49
     * @Author YWX
     * @Param [action]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/wjyx_xs")
    public ResultVo listXwXs(@RequestBody MsrStudentAction action) {
        N_Utils.validation(new Object[]{action.getExamid(), "考试id", 1, action.getActiontype(), "类型", 1});
        Integer page = action.getPage();
        if (N_Utils.isEmptyInteger(page)) {
            return new ResultVo(0, "获取成功", msrActionService.listXwXs(action));
        } else {
            PageHelper.startPage(page, action.getPageSize());
            List<Map> list = msrActionService.listXwXs(action);
            PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(list));
            return new ResultVo(0, "获取成功", pageResult);
        }
    }

}
