package com.xhkjedu.sexam.service.paperstudent;

import com.xhkjedu.sexam.mapper.paperstudent.EPaperStudentMapper;
import com.xhkjedu.sexam.mapper.paperstudent.EPaperStudentQuestionHistoryMapper;
import com.xhkjedu.sexam.mapper.paperstudent.EPaperStudentQuestionMapper;
import com.xhkjedu.sexam.model.paperstudent.EPaperStudentQuestion;
import com.xhkjedu.sexam.model.paperstudent.EPaperStudentQuestionHistory;
import com.xhkjedu.utils.N_Utils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

@Service
public class EPaperStudentQuestionHistoryService {

    @Resource
    private EPaperStudentMapper ePaperStudentMapper;
    @Resource
    private EPaperStudentQuestionMapper ePaperStudentQuestionMapper;
    @Resource
    private EPaperStudentQuestionHistoryMapper ePaperStudentQuestionHistoryMapper;


    /**
     * @Description 更改学生试题得分
     * @Param [sqh]
     * @Return void
     * @Author wn
     * @Date 2022/8/10 16:17
     **/
    @Transactional(rollbackFor = Exception.class)
    public void updateQuestionStuscore(EPaperStudentQuestionHistory sqh){
        //学生试题详情
        EPaperStudentQuestion q = ePaperStudentQuestionMapper.getExamPaperStudntQuestionbyEpsqid(sqh.getEpsqid());
        sqh.setExamid(q.getExamid());
        sqh.setSubjectid(q.getSubjectid());
        sqh.setEpid(q.getEpid());
        sqh.setClassid(q.getClassid());
        sqh.setStudentid(q.getStudentid());
        sqh.setCreatetime(N_Utils.getSecondTimestamp());
        sqh.setStuscore(q.getStuscore());
        sqh.setQn(q.getQn());

        //修改学生单个试题得分
        ePaperStudentQuestionMapper.updateStuScoreByepsqid(sqh.getUpscore(),sqh.getEpsqid());
        //修改学生试卷分值
        ePaperStudentMapper.updateStuPaperscoreEpsid(q.getEpsid());
        //保存更改学生分值记录
        ePaperStudentQuestionHistoryMapper.insertSelective(sqh);
    }

    /**
     * @Description 更改学生试题得分
     * @Param [sqh]
     * @Return void
     * @Author wn
     * @Date 2022/8/10 15:07
     **/
    public List<Map> listExamStuQuestionHistory(Integer examid, String subjectid){
        return ePaperStudentQuestionHistoryMapper.listExamStuQuestionHistory(examid,subjectid);
    }
}
