package com.xhkjedu.smarking.controller.stupaper;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.smarking.model.exam.MsClassStudent;
import com.xhkjedu.smarking.service.stupaper.MsPaperStudentQuestionScoreService;
import com.xhkjedu.smarking.vo.stupaper.PaperStuScoreVo;
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.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;
import java.util.Map;

/**
 * @Description 阅卷学生分数修改历史表相关操作
 * @Author auto
 * @Date 2024-10-15
 */
@RestController
@RequestMapping("/mstuqc")
public class MsPaperStudentQuestionScoreController {
    @Resource
    private MsPaperStudentQuestionScoreService msPaperStudentQuestionScoreService;

    /**
     * @Description 新增
     * @Param [msPaperStudentQuestionScore]
     * @Author auto
     * @Date 2024-10-15
     * @return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/save")
    public ResultVo save(@RequestBody PaperStuScoreVo stuscore) {
        N_Utils.validation(new Object[]{stuscore.getMpsid(), "学生试卷id", 1});
        if(N_Utils.isListEmpty(stuscore.getQuescores())){
            return new ResultVo(1, "试题不能为空");
        }
        try {
            msPaperStudentQuestionScoreService.add(stuscore);
            return new ResultVo(0, "保存成功");
        }catch (Exception e){
            String message = e.getMessage();
            if(!message.contains("无法修改分数")){
                message = "保存失败";
            }
            return new ResultVo(1, message);
        }
    }

    /*
     * @Description 修改分数-班级学生成绩
     * @Date 2024/11/13 10:09:35
     * @Author WN
     * @Param [cs]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list_stu")
    public ResultVo listClassStudentScore(@RequestBody MsClassStudent cs) {
        N_Utils.validation(new Object[]{cs.getExamid(), "考试id", 1, cs.getSubjectid(), "科目id", 2,cs.getClass(),"班级id",1});
        List<Map<String, Object>> list = msPaperStudentQuestionScoreService.listClassStudentScores(cs);
        return new ResultVo(0, "获取成功", list);
    }

    /*
     * @Description 修改分数-修改历史
     * @Date 2024/11/11 17:57:01
     * @Author WN
     * @Param [cs]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list_history")
    public ResultVo queryList(@RequestBody MsClassStudent cs) {
        Integer page = cs.getPage();
        Integer size = cs.getPageSize();
        N_Utils.validation(new Object[]{page, "显示页码", 1, size, "显示条数", 1,cs.getExamid(),"考试id",1});
        PageHelper.startPage(page, size);
        List<Map<String, Object>> list = msPaperStudentQuestionScoreService.listStuQuestionScore(cs);
        PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(list));
        return new ResultVo(0, "获取成功", pageResult);
    }
}
