package com.xhkjedu.smarking.controller.paper;

import com.xhkjedu.smarking.model.paper.MsPaper;
import com.xhkjedu.smarking.model.paper.MsPaperBlock;
import com.xhkjedu.smarking.service.paper.MsPaperBlockService;
import com.xhkjedu.smarking.vo.paper.MsPaperParams;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.vo.ResultVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * @Description 阅卷试卷题块相关操作
 * @Author auto
 * @Date 2024-10-15
 */
@RestController
@RequestMapping("/mpblock")
public class MsPaperBlockController {
    @Resource
    private MsPaperBlockService msPaperBlockService;

    /*
     * @Description 试卷题块试题
     * @Date 2024/10/21 14:37:21
     * @Author WN
     * @Param [msPaper]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list")
    public ResultVo listPaperBlocks(@RequestBody MsPaper msPaper) {
        N_Utils.validation(new Object[]{msPaper.getMpid(), "考试id",1});
        List<MsPaperBlock> list = msPaperBlockService.listPaperBlockQuestions(msPaper.getMpid());
        return new ResultVo(0, "查询成功", list);
    }

    /*
     * @Description 保存题块
     * @Date 2024/10/21 15:38:52
     * @Author WN
     * @Param [params]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/save")
    public ResultVo save(@RequestBody MsPaperParams params) {
        N_Utils.validation(new Object[]{params.getMpid(), "试卷id",1});
        if (params.getBlocks() == null || params.getBlocks().isEmpty()) {
            return new ResultVo(1, "题块不能为空！");
        }
        Integer mpid = msPaperBlockService.save(params);
        return new ResultVo(0, "保存成功", mpid);
    }


}
