package com.xhkjedu.smarking.controller.exam;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.smarking.model.exam.MsClassStudent;
import com.xhkjedu.smarking.service.exam.MsClassStudentService;
import com.xhkjedu.smarking.vo.exam.CStudentVo;
import com.xhkjedu.smarking.vo.exam.SCStudentVo;
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.*;

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

/**
 * @Description 阅卷考试学生表相关操作
 * @Author auto
 * @Date 2024-10-15
 */
@RestController
@RequestMapping("/mstudent")
public class MsClassStudentController {
    @Resource
    private MsClassStudentService msClassStudentService;

    /**
     * @Description 新增考生-按学生
     * @Date 2024/10/22 9:36
     * @Author YWX
     * @Param [cs]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/save_by_student")
    public ResultVo saveByStudent(@RequestBody SCStudentVo cs) {
        N_Utils.validation(new Object[]{
                cs.getExamid(), "考试id", 1
                , cs.getSubjectids(), "科目", 3
                , cs.getStudents(), "学生", 3
        });
        msClassStudentService.saveByStudent(cs);
        return new ResultVo(0, "保存成功！");
    }

    /**
     * @Description 新增考生-按班级
     * @Date 2024/10/22 11:42
     * @Author YWX
     * @Param [cs]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/save_by_class")
    public ResultVo saveByClass(@RequestBody SCStudentVo cs) {
        N_Utils.validation(new Object[]{
                cs.getExamid(), "考试id", 1
                , cs.getSubjectids(), "科目", 3
                , cs.getClassids(), "班级", 3
        });
        msClassStudentService.saveByClass(cs);
        return new ResultVo(0, "保存成功！");
    }

    /**
     * @return com.xhkjedu.vo.ResultVo
     * @Description 列表
     * @Param [msClassStudent]
     * @Author auto
     * @Date 2024-10-15
     **/
    @PostMapping("/list")
    public ResultVo queryList(@RequestBody MsClassStudent msClassStudent) {
        Integer examid = msClassStudent.getExamid();
        Integer schoolid = msClassStudent.getSchoolid();
        Integer page = msClassStudent.getPage();
        Integer size = msClassStudent.getPageSize();
        N_Utils.validation(new Object[]{examid, "考试id", 1, schoolid, "学校id", 1});
        if (N_Utils.isEmptyInteger(page)) {
            List<Map> list = msClassStudentService.queryList(msClassStudent);
            return new ResultVo(0, "查询成功！", list);
        } else {
            PageHelper.startPage(page, size);
            List<Map> list = msClassStudentService.queryList(msClassStudent);
            PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(list));
            return new ResultVo(0, "查询成功！", pageResult);
        }
    }

    /**
     * @Description 移除单个科目学生
     * @Date 2024/10/22 14:13
     * @Author YWX
     * @Param [cs]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/delete_by_student")
    public ResultVo deleteByStudent(@RequestBody CStudentVo cs) {
        N_Utils.validation(new Object[]{
                cs.getMcsid(), "阅卷考试学生ID", 1
        });
        msClassStudentService.deleteByStudent(cs);
        return new ResultVo(0, "移除成功！");
    }

    /**
     * @Description 移除班级学生
     * @Date 2024/10/22 14:17
     * @Author YWX
     * @Param [cs]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/delete_by_class")
    public ResultVo deleteByClass(@RequestBody CStudentVo cs) {
        N_Utils.validation(new Object[]{
                cs.getExamid(), "考试id", 1
                , cs.getClassid(), "班级", 1
        });
        msClassStudentService.deleteByClass(cs);
        return new ResultVo(0, "移除成功！");
    }

    /**
     * @Description 考试班级列表
     * @Date 2024/10/22 16:49
     * @Author YWX
     * @Param [cs]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list_class")
    public ResultVo listClass(@RequestBody CStudentVo cs) {
        N_Utils.validation(new Object[]{
                cs.getExamid(), "考试id", 1
        });
        return new ResultVo(0, "查询成功！", msClassStudentService.listClass(cs));
    }

    /**
     * @Description 班级搜索列表
     * @Date 2024/10/22 16:53
     * @Author YWX
     * @Param [cs]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/search_class")
    public ResultVo searchClass(@RequestBody CStudentVo cs) {
        N_Utils.validation(new Object[]{
                cs.getExamid(), "考试id", 1
                , cs.getSchoolid(), "学校id", 1
                , cs.getClasstype(), "班级类型", 1
        });
        return new ResultVo(0, "查询成功！", msClassStudentService.searchClass(cs));
    }

    /**
     * @Description 学生搜索列表
     * @Date 2024/10/22 17:05
     * @Author YWX
     * @Param [cs]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/search_student")
    public ResultVo searchStudent(@RequestBody CStudentVo cs) {
        Integer page = cs.getPage();
        Integer size = cs.getPageSize();
        N_Utils.validation(new Object[]{
                cs.getExamid(), "考试id", 1
                , cs.getSchoolid(), "学校id", 1
                , cs.getClasstype(), "班级类型", 1
                , page, "页码", 1
                , size, "条数", 1
        });
        msClassStudentService.setParam(cs);
        PageHelper.startPage(page, size);
        List<Map> list = msClassStudentService.searchStudent(cs);
        PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(list));
        return new ResultVo(0, "查询成功！", pageResult);
    }
}
