“djh”
3 天以前 dad64ab7b78563acaeb941f0a22dd383fe45ef38
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.gkhy.exam.system.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.exam.common.enums.StudentAnswerPassEnum;
import com.gkhy.exam.common.exception.ApiException;
import com.gkhy.exam.common.utils.SecurityUtils;
import com.gkhy.exam.system.domain.ExExerciseAnswer;
import com.gkhy.exam.system.domain.ExQuestion;
import com.gkhy.exam.system.domain.ExStudentAnswer;
import com.gkhy.exam.system.mapper.ExExerciseAnswerMapper;
import com.gkhy.exam.system.mapper.ExQuestionMapper;
import com.gkhy.exam.system.service.ExExerciseAnswerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
/**
 * <p>
 * 学员与练习题关系表 服务实现类
 * </p>
 *
 * @author kzy
 * @since 2024-06-20 09:42:25
 */
@Service
public class ExExerciseAnswerServiceImpl extends ServiceImpl<ExExerciseAnswerMapper, ExExerciseAnswer> implements ExExerciseAnswerService {
    @Autowired
    private ExQuestionMapper questionMapper;
 
    @Override
    public ExExerciseAnswer addExerciseAnswer(ExExerciseAnswer exerciseAnswer) {
        int row=0;
        exerciseAnswer.setStudentId(SecurityUtils.getUserId());
        ExQuestion question=questionMapper.selectById(exerciseAnswer.getQuestionId());
        if(exerciseAnswer.getAnswer().equals(question.getAnswer())){
            exerciseAnswer.setPassed(StudentAnswerPassEnum.CORRECT.getCode());
        }else{
            exerciseAnswer.setPassed(StudentAnswerPassEnum.ERROR.getCode());
        }
        ExExerciseAnswer existAnswer= baseMapper.getExerciseAnswer(exerciseAnswer);
        if(existAnswer!=null){
            exerciseAnswer.setId(existAnswer.getId());
            row=baseMapper.updateById(exerciseAnswer);
        }else{
            row=baseMapper.insert(exerciseAnswer);
        }
        if(row<1){
            throw new ApiException("提交答题失败");
        }
        exerciseAnswer.setRealAnswer(question.getAnswer());
        return exerciseAnswer;
    }
 
    @Override
    public ExStudentAnswer getExerciseAnswer(ExExerciseAnswer exerciseAnswer) {
        return null;
    }
 
 
}