package com.xhkjedu.smarking.controller.papercheck;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.smarking.service.papercheck.MsPaperCheckTeacherArbitrateService;
import com.xhkjedu.smarking.vo.papercheck.MsCheckParam;
import com.xhkjedu.smarking.vo.papercheck.MsPaperCheckVo;
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-11-19
 */
@RestController
@RequestMapping("/marbitrate")
public class MsPaperCheckTeacherArbitrateController {
    @Resource
    private MsPaperCheckTeacherArbitrateService msPaperCheckTeacherArbitrateService;

    /**
     * @Description 教师阅卷-待/已仲裁列表
     * @Date 2024/11/15 16:00
     * @Author YWX
     * @Param [param]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list_arbitrate")
    public ResultVo listArbitrate(@RequestBody MsCheckParam param) {
        Integer page = param.getPage();
        Integer size = param.getPageSize();
        N_Utils.validation(new Object[]{
                page, "显示页码", 1
                , size, "显示条数", 1
                , param.getHandleid(), "操作人ID", 1
                , param.getChecktype(), "类型", 2
        });
        PageHelper.startPage(page, size);
        List<Map> list = msPaperCheckTeacherArbitrateService.listArbitrate(param);
        PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(list));
        return new ResultVo(0, "查询成功", pageResult);
    }

    /**
     * @Description 教师阅卷-待/已仲裁详情
     * @Date 2024/11/18 15:55
     * @Author YWX
     * @Param [param]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/detail_arbitrate")
    public ResultVo detailArbitrate(@RequestBody MsCheckParam param) {
        N_Utils.validation(new Object[]{param.getHandleid(), "操作人ID", 1, param.getMpid(), "试卷ID", 1});
        List<Map> list = msPaperCheckTeacherArbitrateService.detailArbitrate(param);
        return new ResultVo(0, "查询成功", list);
    }

    /**
     * @Description 获取待仲裁任务
     * @Date 2024/11/18 16:47
     * @Author YWX
     * @Param [param]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/get_correct_arbitrate")
    public ResultVo getCorrectArbitrate(@RequestBody MsCheckParam param) {
        N_Utils.validation(new Object[]{param.getHandleid(), "操作人ID", 1, param.getMpid(), "试卷ID", 1});
        return msPaperCheckTeacherArbitrateService.getCorrectArbitrate(param);
    }

    /**
     * @Description 教师阅卷-待仲裁-上一份
     * @Date 2024/11/19 9:27
     * @Author YWX
     * @Param [param]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/get_pre_arbitrate")
    public ResultVo getPreArbitrate(@RequestBody MsCheckParam param) {
        N_Utils.validation(new Object[]{
                param.getHandleid(), "操作人ID", 1
                , param.getMpid(), "试卷ID", 1
                , param.getMblockid(), "题块ID", 1
                , param.getCorrecttype(), "批阅设置", 1
                , param.getTaskorder(), "序号", 1
        });
        return new ResultVo(0, "查询成功", msPaperCheckTeacherArbitrateService.getPreArbitrate(param));
    }

    /**
     * @Description 教师阅卷-仲裁
     * @Date 2024/11/19 14:11
     * @Author YWX
     * @Param [param]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/arbitrate")
    public ResultVo arbitrate(@RequestBody MsPaperCheckVo param) {
        N_Utils.validation(new Object[]{
                param.getHandleid(), "操作人ID", 1
                , param.getMpid(), "试卷ID", 1
                , param.getMblockid(), "题块ID", 1
                , param.getMpsbid(), "任务ID", 1
                , param.getQscore(), "试题分值", 2
                , param.getCorrecttype(), "批阅设置", 1
        });
        param.setFinalreason(1);
        msPaperCheckTeacherArbitrateService.arbitrate(param);
        return new ResultVo(0, "仲裁成功");
    }

    /**
     * @Description 教师阅卷-学科组长仲裁
     * @Date 2024/11/19 14:59
     * @Author YWX
     * @Param [param]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/larbitrate")
    public ResultVo leaderArbitrate(@RequestBody MsPaperCheckVo param) {
        N_Utils.validation(new Object[]{
                param.getHandleid(), "操作人ID", 1
                , param.getMpid(), "试卷ID", 1
                , param.getMblockid(), "题块ID", 1
                , param.getMpsbid(), "任务ID", 1
                , param.getQscore(), "试题分值", 2
        });
        param.setFinalreason(2);
        msPaperCheckTeacherArbitrateService.arbitrate(param);
        return new ResultVo(0, "仲裁成功");
    }

    /**
     * @Description 教师阅卷-待仲裁列表
     * @Date 2024/11/19 15:52
     * @Author YWX
     * @Param [param]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list_tarbitrate")
    public ResultVo listTeacherArbitrate(@RequestBody MsCheckParam param) {
        Integer handleid = param.getHandleid();
        Integer mpid = param.getMpid();
        N_Utils.validation(new Object[]{handleid, "操作人ID", 1, mpid, "试卷ID", 1});
        List<Map> list = msPaperCheckTeacherArbitrateService.listPendingArbitrate(mpid, handleid, 1);
        return new ResultVo(0, "查询成功", list);
    }

    /**
     * @Description 学科组长-待仲裁列表
     * @Date 2024/11/19 15:57
     * @Author YWX
     * @Param [param]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list_larbitrate")
    public ResultVo listLeaderArbitrate(@RequestBody MsCheckParam param) {
        Integer handleid = param.getHandleid();
        Integer mpid = param.getMpid();
        N_Utils.validation(new Object[]{handleid, "操作人ID", 1, mpid, "试卷ID", 1});
        List<Map> list = msPaperCheckTeacherArbitrateService.listPendingArbitrate(mpid, handleid, 0);
        return new ResultVo(0, "查询成功", list);
    }

    /**
     * @Description 学科组长-获取待仲裁任务
     * @Date 2024/11/19 15:51
     * @Author YWX
     * @Param [param]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/get_correct_larbitrate")
    public ResultVo getCorrectLeaderArbitrate(@RequestBody MsCheckParam param) {
        N_Utils.validation(new Object[]{param.getHandleid(), "操作人ID", 1, param.getMpid(), "试卷ID", 1});
        return msPaperCheckTeacherArbitrateService.getCorrectLeaderArbitrate(param);
    }

    /**
     * @Description 仲裁历史
     * @Date 2024/11/19 16:42
     * @Author YWX
     * @Param [param]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list_arbitrate_history")
    public ResultVo listArbitrateHistory(@RequestBody MsCheckParam param) {
        Integer page = param.getPage();
        Integer size = param.getPageSize();
        N_Utils.validation(new Object[]{
                param.getHandleid(), "操作人ID", 1
                , param.getMpid(), "试卷ID", 1
                , param.getMblockid(), "题块ID", 1
                , param.getCorrecttype(), "批阅设置", 1
                , page, "显示页码", 1
                , size, "显示条数", 1
        });
        PageHelper.startPage(page, size);
        List<Map> list = msPaperCheckTeacherArbitrateService.listArbitrateHistory(param);
        PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(list));
        return new ResultVo(0, "查询成功", pageResult);
    }

    /**
     * @Description 仲裁历史详情
     * @Date 2024/11/20 9:14
     * @Author YWX
     * @Param [param]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/detail_history")
    public ResultVo detailHistory(@RequestBody MsCheckParam param) {
        N_Utils.validation(new Object[]{
                param.getMpctaid(), "任务ID", 1
                , param.getCorrecttype(), "批阅设置", 1
        });
        return new ResultVo(0, "查询成功", msPaperCheckTeacherArbitrateService.detailHistory(param));
    }

    /**
     * @Description 初评分
     * @Date 2024/11/20 9:31
     * @Author YWX
     * @Param [param]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/get_score")
    public ResultVo getScore(@RequestBody MsCheckParam param) {
        N_Utils.validation(new Object[]{
                param.getMpsbid(), "学生题块ID", 1
                , param.getCorrecttype(), "批阅设置", 1
        });
        return new ResultVo(0, "查询成功", msPaperCheckTeacherArbitrateService.getScore(param));
    }
}
