package com.yida.data.school.exam.controller;

import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.CurrentUser;
import com.yida.data.common.core.entity.exam.CoreExaminationStudent;
import com.yida.data.common.core.entity.exam.CoreExaminationTeacher;
import com.yida.data.common.core.utils.FebsUtil;
import com.yida.data.school.exam.service.CoreExaminationStudentService;
import com.yida.data.school.exam.service.CoreExaminationTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "成绩-后台-考试人员")
@RestController
@RequestMapping(value = "/exam/person")
public class CoreExaminationPersonController{

    @Autowired
    private CoreExaminationTeacherService coreExaminationTeacherService;

    @Autowired
    private CoreExaminationStudentService coreExaminationStudentService;


    @ApiOperation("查询本次考试对应的监考老师列表数据")
    @ResponseBody
    @GetMapping("/findExaminationTeacherPageList")
    public ResultBean findExaminationTeacherPageList(@ApiParam("考试id") Integer coreExaminationId,
                                                     @ApiParam("监考老师名称") String teachaerName,
                                                     @ApiParam("当前页码") @RequestParam(defaultValue = "1") Integer pageNum,
                                                     @ApiParam("页面大小") @RequestParam(defaultValue = "10") Integer pageSize) {
        //查询分页数据
        return ResultBean.buildSuccess(coreExaminationTeacherService.findExaminationTeacherPageList(pageNum,pageSize,coreExaminationId, teachaerName));
    }

    @ApiOperation("保存考试监考老师信息 新增或编辑")
    @ResponseBody
    @PostMapping("/saveExaminationTeacher")
    public ResultBean saveExaminationTeacher(@RequestBody CoreExaminationTeacher coreExaminationTeacher) {

        //获得登录用户的信息
        CurrentUser currentUser = FebsUtil.getCurrentUser();
        //保存监考老师信息
        coreExaminationTeacherService.saveExaminationTeacher(coreExaminationTeacher, currentUser);


        return ResultBean.buildSuccess();
    }

    @ApiOperation("根据监考老师id查询监考老师详细信息")
    @ResponseBody
    @GetMapping("/findExaminationTeacher")
    public ResultBean findExaminationTeacher(@ApiParam("监考老师id") Integer examinationTeacherId) {

        return ResultBean.buildSuccess(coreExaminationTeacherService.findExaminationTeacher(examinationTeacherId));

    }


    @ApiOperation("批量删除监考老师信息")
    @ResponseBody
    @PostMapping("/delExaminationTeacherBatch")
    public ResultBean delExaminationTeacherBatch(@RequestBody List<Integer> examinationTeacherIds) {

        //批量删除监考老师信息
        coreExaminationTeacherService.delExaminationTeacherBatch(examinationTeacherIds);

        return ResultBean.buildSuccess();
    }

    @ApiOperation("查询本次考试对应的考试学生列表数据")
    @ResponseBody
    @GetMapping("/findExaminationStudentPageList")
    public ResultBean findExaminationStudentPageList(@ApiParam("考试id") Long coreExaminationId,
                                                     @ApiParam("学生姓名") String searchName,
                                                     @ApiParam("班级id") Long classId,
                                                     @ApiParam("当前页码") @RequestParam(defaultValue = "1") Integer pageNum,
                                                     @ApiParam("页面大小") @RequestParam(defaultValue = "10") Integer pageSize
    ) {
        //查询分页数据
        return ResultBean.buildSuccess(coreExaminationStudentService.findExaminationStudentPageList(pageNum,pageSize,coreExaminationId, searchName, classId));
    }

    @ApiOperation("保存考生信息 新增或编辑")
    @ResponseBody
    @PostMapping("/saveExaminationStudent")
    public ResultBean saveExaminationStudent(@RequestBody CoreExaminationStudent coreExaminationStudent) {


        //获得登录用户的信息
        CurrentUser currentUser = FebsUtil.getCurrentUser();
        //保存考生信息
        coreExaminationStudentService.saveExaminationStudent(coreExaminationStudent, currentUser);

        return ResultBean.buildSuccess();
    }

    @ApiParam("根据考生id查询考生详细信息")
    @ResponseBody
    @GetMapping("/findExaminationStudent")
    public ResultBean findExaminationStudent(@ApiParam("考生id") Long examinationStudentId) {

        return ResultBean.buildSuccess(coreExaminationStudentService.findExaminationStudent(examinationStudentId));

    }

    @ApiParam("批量删除考生信息")
    @ResponseBody
    @PostMapping("/delExaminationStudentBatch")
    public ResultBean delExaminationStudentBatch(@RequestBody List<Long> examinationStudentIds) {

        //批量删除考生信息
        coreExaminationStudentService.delRankBatchIds(examinationStudentIds);
        return ResultBean.buildSuccess();
    }

}
