package com.xhkjedu.sexam.controller.paperstudent;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.sexam.model.paperstudent.EPaperStudentQuestionHistory;
import com.xhkjedu.sexam.service.paperstudent.EPaperStudentQuestionHistoryService;
import com.xhkjedu.sexam.vo.paperstudent.PaperStudentParamsVo;
import com.xhkjedu.sexam.vo.paperstudent.QuestionScoreVo;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.utils.PageUtil;
import com.xhkjedu.vo.PageResult;
import com.xhkjedu.vo.ResultVo;
import lombok.extern.slf4j.Slf4j;
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;

@RestController
@RequestMapping("/psqh")
@Slf4j
public class EPaperStudentQuestionHistoryController {
    @Resource
    private EPaperStudentQuestionHistoryService ePaperStudentQuestionHistoryService;

    //更改学生试题得分
    @PostMapping("/upstus")
    public ResultVo updateQuestionStuscore(@RequestBody PaperStudentParamsVo psh) {
        try {
            List<QuestionScoreVo> queslist = psh.getQuestions();
            N_Utils.validation(new Object[]{psh.getTeacherid(),"教师id",1});
            if(N_Utils.isListEmpty(queslist)){
                return new ResultVo(1,"试题不能为空");
            }
            ePaperStudentQuestionHistoryService.updateQuestionStuscore(psh);
            return new ResultVo(0, "成功保存学生试题得分");
        } catch (Exception e) {
            log.error("保存学生试题得分失败：" + e.getMessage());
            return new ResultVo(1, "保存学生试题得分失败");
        }
    }

    //修改分值历史
    @PostMapping("/list")
    public ResultVo listHistorys(@RequestBody EPaperStudentQuestionHistory psh) {
        Integer page = psh.getPage();
        Integer pageSize = psh.getPageSize();
        N_Utils.validation(new Object[]{psh.getExamid(), "考试id", 1,page,"当前页",1,pageSize,"每页条数",1});
        PageHelper.startPage(page, pageSize);
        List<Map> rtnlst = ePaperStudentQuestionHistoryService.listExamStuQuestionHistory(psh.getExamid(),psh.getSubjectid());
        PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(rtnlst));
        return new ResultVo(0, "成功获取修改分值历史信息",pageResult);
    }

}
