package com.xhkjedu.smarking.controller.papercheck;

import com.xhkjedu.smarking.model.papercheck.MsPaperCheck;
import com.xhkjedu.smarking.service.papercheck.MsPaperCheckService;
import com.xhkjedu.utils.N_Utils;
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("/mcheck")
public class MsPaperCheckController {
    @Resource
    private MsPaperCheckService msPaperCheckService;

    /**
     * @Description 设置评卷方式
     * @Date 2024/10/24 14:16
     * @Author YWX
     * @Param [msPaperCheck]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/set_check_type")
    public ResultVo setCheckType(@RequestBody MsPaperCheck msPaperCheck) {
        N_Utils.validation(new Object[]{
                msPaperCheck.getMpid(), "试卷id", 1
                , msPaperCheck.getMsid(), "考试科目id", 1
                , msPaperCheck.getMblockid(), "题块id", 1
                , msPaperCheck.getChecktype(), "评卷方式", 1
                , msPaperCheck.getCreateid(), "创建人id", 1
        });
        msPaperCheckService.add(msPaperCheck);
        return new ResultVo(0, "设置成功");
    }

    /**
     * @Description 阅卷分配-按题块列表（线下）
     * @Date 2024/10/24 14:19
     * @Author YWX
     * @Param [msPaperCheck]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list_paper_check")
    public ResultVo listPaperCheck(@RequestBody MsPaperCheck msPaperCheck) {
        Integer mpid = msPaperCheck.getMpid();
        N_Utils.validation(new Object[]{
                mpid, "试卷id", 1
        });
        List<Map> list = msPaperCheckService.listPaperCheck(mpid);
        return new ResultVo(0, "查询成功", list);
    }

    /**
     * @Description 设置仲裁教师
     * @Date 2024/10/24 14:40
     * @Author YWX
     * @Param [msPaperCheck]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/set_arbitrate")
    public ResultVo setArbitrate(@RequestBody MsPaperCheck msPaperCheck) {
        N_Utils.validation(new Object[]{
                msPaperCheck.getMpid(), "试卷id", 1
                , msPaperCheck.getMsid(), "考试科目id", 1
                , msPaperCheck.getMblockid(), "题块id", 1
                , msPaperCheck.getArbitrateid(), "仲裁教师id", 1
                , msPaperCheck.getCreateid(), "创建人id", 1
        });
        msPaperCheckService.setArbitrate(msPaperCheck);
        return new ResultVo(0, "设置成功");
    }

    /**
     * @Description 设置阅卷教师
     * @Date 2024/10/24 15:24
     * @Author YWX
     * @Param [msPaperCheck]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/set_check_teacher")
    public ResultVo setCheckTeacher(@RequestBody MsPaperCheck msPaperCheck) {
        N_Utils.validation(new Object[]{
                msPaperCheck.getMpid(), "试卷id", 1
                , msPaperCheck.getMsid(), "考试科目id", 1
                , msPaperCheck.getMblockid(), "题块id", 1
                , msPaperCheck.getTeachers(), "阅卷教师", 3
                , msPaperCheck.getCorrecttype(), "批阅设置", 1
                , msPaperCheck.getCreateid(), "创建人id", 1
        });
        msPaperCheckService.setCheckTeacher(msPaperCheck);
        return new ResultVo(0, "设置成功");
    }

    /**
     * @Description 删除阅卷教师
     * @Date 2024/11/5 10:48
     * @Author YWX
     * @Param [msPaperCheck]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/delete_check_teacher")
    public ResultVo deleteCheckTeacher(@RequestBody MsPaperCheck msPaperCheck) {
        Integer mblockid = msPaperCheck.getMblockid();
        Integer teacherid = msPaperCheck.getTeacherid();
        N_Utils.validation(new Object[]{
                mblockid, "题块id", 1
                , teacherid, "教师id", 1
        });
        msPaperCheckService.deleteCheckTeacher(mblockid, teacherid);
        return new ResultVo(0, "删除成功");
    }

    /**
     * @Description 设置分配方式
     * @Date 2024/10/24 15:42
     * @Author YWX
     * @Param [msPaperCheck]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/set_dispense_way")
    public ResultVo setDispenseWay(@RequestBody MsPaperCheck msPaperCheck) {
        Integer dispenseway = msPaperCheck.getDispenseway();
        N_Utils.validation(new Object[]{
                msPaperCheck.getMpid(), "试卷id", 1
                , msPaperCheck.getMsid(), "考试科目id", 1
                , msPaperCheck.getMblockid(), "题块id", 1
                , dispenseway, "分配方式", 1
                , msPaperCheck.getCreateid(), "创建人id", 1
                , msPaperCheck.getCorrecttype(), "批阅设置", 1
        });
        if (!dispenseway.equals(2) && !N_Utils.isTrueInteger(msPaperCheck.getNumtype())) {
            return new ResultVo(1, "请选择分配总数");
        }
        msPaperCheckService.setDispenseWay(msPaperCheck);
        return new ResultVo(0, "设置成功");
    }

    /**
     * @Description 题块阅卷教师列表
     * @Date 2024/10/25 9:05
     * @Author YWX
     * @Param [msPaperCheck]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list_check_teacher")
    public ResultVo listCheckTeacher(@RequestBody MsPaperCheck msPaperCheck) {
        Integer mpid = msPaperCheck.getMpid();
        Integer mblockid = msPaperCheck.getMblockid();
        N_Utils.validation(new Object[]{
                mpid, "试卷id", 1
                , mblockid, "题块id", 1
        });
        List<Map> list = msPaperCheckService.listCheckTeacher(mpid, mblockid);
        return new ResultVo(0, "查询成功", list);
    }

    /**
     * @Description 获取试卷分配总数
     * @Date 2024/10/25 11:29
     * @Author YWX
     * @Param [msPaperCheck]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/get_dispense_num")
    public ResultVo getDispenseNum(@RequestBody MsPaperCheck msPaperCheck) {
        Integer mpid = msPaperCheck.getMpid();
        Integer mblockid = msPaperCheck.getMblockid();
        N_Utils.validation(new Object[]{
                mpid, "试卷id", 1
                , mblockid, "题块id", 1
        });
        return new ResultVo(0, "获取成功", msPaperCheckService.getDispenseNum(mpid, mblockid));
    }

    /**
     * @Description 添加任务
     * @Date 2024/10/25 17:45
     * @Author YWX
     * @Param [msPaperCheck]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/add_task_to_teacher")
    public ResultVo addTaskToTeacher(@RequestBody MsPaperCheck msPaperCheck) {
        N_Utils.validation(new Object[]{
                msPaperCheck.getMblockid(), "题块id", 1
                , msPaperCheck.getMpid(), "试卷id", 1
                , msPaperCheck.getTeacherid(), "教师id", 1
                , msPaperCheck.getTeachers(), "任务教师", 3
        });
        msPaperCheckService.addTaskToTeacher(msPaperCheck);
        return new ResultVo(0, "添加任务成功");
    }

    /**
     * @Description 分解任务
     * @Date 2024/10/28 9:56
     * @Author YWX
     * @Param [msPaperCheck]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/fetch_task_to_teacher")
    public ResultVo fetchTaskToTeacher(@RequestBody MsPaperCheck msPaperCheck) {
        N_Utils.validation(new Object[]{
                msPaperCheck.getMblockid(), "题块id", 1
                , msPaperCheck.getMpid(), "试卷id", 1
                , msPaperCheck.getTeacherid(), "教师id", 1
                , msPaperCheck.getTeachers(), "任务教师", 3
        });
        msPaperCheckService.fetchTaskToTeacher(msPaperCheck);
        return new ResultVo(0, "分解任务成功");
    }

    /**
     * @Description 题块-开始阅卷
     * @Date 2024/10/30 10:03
     * @Author YWX
     * @Param [msPaperCheck]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/start_check")
    public ResultVo startCheck(@RequestBody MsPaperCheck msPaperCheck) {
        Integer mpid = msPaperCheck.getMpid();
        Integer mblockid = msPaperCheck.getMblockid();
        N_Utils.validation(new Object[]{
                mpid, "试卷id", 1
                , mblockid, "题块id", 1
        });
        msPaperCheckService.updateCheckState(mpid, mblockid, 1);
        return new ResultVo(0, "开始成功");
    }

    /**
     * @Description 题块-暂停阅卷
     * @Date 2024/10/30 10:03
     * @Author YWX
     * @Param [msPaperCheck]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/stop_check")
    public ResultVo stopCheck(@RequestBody MsPaperCheck msPaperCheck) {
        Integer mpid = msPaperCheck.getMpid();
        Integer mblockid = msPaperCheck.getMblockid();
        N_Utils.validation(new Object[]{
                mpid, "试卷id", 1
                , mblockid, "题块id", 1
        });
        msPaperCheckService.updateCheckState(mpid, mblockid, 2);
        return new ResultVo(0, "暂停成功");
    }

    /**
     * @Description 阅卷分配-按班级列表（线上）
     * @Date 2024/11/6 10:30
     * @Author YWX
     * @Param [msSubject]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list_class")
    public ResultVo listClass(@RequestBody MsPaperCheck check) {
        Integer mpid = check.getMpid();
        N_Utils.validation(new Object[]{
                mpid, "试卷id", 1
        });
        return new ResultVo(0, "查询成功", msPaperCheckService.listClass(mpid));
    }

    /**
     * @Description 阅卷分配-按试题列表（线上）
     * @Date 2024/11/6 14:42
     * @Author YWX
     * @Param [check]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list_question")
    public ResultVo listQuestion(@RequestBody MsPaperCheck check) {
        Integer mpid = check.getMpid();
        N_Utils.validation(new Object[]{
                mpid, "试卷id", 1
        });
        return new ResultVo(0, "查询成功", msPaperCheckService.listQuestion(mpid));
    }

    /**
     * @Description 复制阅卷任务
     * @Date 2024/11/6 15:51
     * @Author YWX
     * @Param [check]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/copy_task")
    public ResultVo copyTask(@RequestBody MsPaperCheck check) {
        Integer mpcid = check.getMpcid();
        List<Integer> mblockids = check.getMblockids();
        N_Utils.validation(new Object[]{
                mpcid, "阅卷方式ID", 1
                , mblockids, "题块/试题/班级IDS", 3
        });
        msPaperCheckService.copyTask(mpcid, mblockids);
        return new ResultVo(0, "复制成功");
    }
}
