package com.xhkjedu.smarking.controller.papercheck;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.smarking.service.papercheck.MsPaperCheckTeacherProblemService;
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-21
 */
@RestController
@RequestMapping("/mproblem")
public class MsPaperCheckTeacherProblemController {
    @Resource
    private MsPaperCheckTeacherProblemService msPaperCheckTeacherProblemService;

    /**
     * @Description 疑难卷列表
     * @Date 2024/11/21 9:59
     * @Author YWX
     * @Param [param]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list_problem")
    public ResultVo listProblem(@RequestBody MsCheckParam param) {
        Integer mpid = param.getMpid();
        N_Utils.validation(new Object[]{param.getHandleid(), "操作人ID", 1, mpid, "试卷ID", 1});
        List<Map> list = msPaperCheckTeacherProblemService.listPendingProblem(mpid);
        return new ResultVo(0, "查询成功", list);
    }

    /**
     * @Description 获取疑难卷任务
     * @Date 2024/11/21 10:12
     * @Author YWX
     * @Param [param]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/get_correct_problem")
    public ResultVo getCorrectProblem(@RequestBody MsCheckParam param) {
        N_Utils.validation(new Object[]{param.getHandleid(), "操作人ID", 1, param.getMpid(), "试卷ID", 1});
        return msPaperCheckTeacherProblemService.getCorrectProblem(param);
    }

    /**
     * @Description 处理疑难卷
     * @Date 2024/11/21 11:17
     * @Author YWX
     * @Param [param]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/correct")
    public ResultVo correct(@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(1);
        msPaperCheckTeacherProblemService.correct(param);
        return new ResultVo(0, "处理成功");
    }

    /**
     * @Description 获取上一份疑难卷
     * @Date 2024/11/21 14:35
     * @Author YWX
     * @Param [param]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/get_pre_problem")
    public ResultVo getPreProblem(@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, "查询成功", msPaperCheckTeacherProblemService.getPreProblem(param));
    }

    /**
     * @Description 历史记录列表
     * @Date 2024/11/21 10:55
     * @Author YWX
     * @Param [param]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list_history")
    public ResultVo listHistory(@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 = msPaperCheckTeacherProblemService.listHistory(param);
        PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(list));
        return new ResultVo(0, "查询成功", pageResult);
    }

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

    /**
     * @Description 打回重阅
     * @Date 2024/11/21 15:19
     * @Author YWX
     * @Param [param]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/back_correct")
    public ResultVo backCorrect(@RequestBody MsPaperCheckVo param) {
        N_Utils.validation(new Object[]{
                param.getHandleid(), "操作人ID", 1
                , param.getMpid(), "试卷ID", 1
                , param.getMpsbid(), "任务ID", 1
                , param.getCorrecttype(), "批阅设置", 1
        });
        msPaperCheckTeacherProblemService.backCorrect(param);
        return new ResultVo(0, "打回成功");
    }
}
