package com.gkhy.exam.system.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.exam.common.exception.ApiException;
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;
/**
*
* 学员与练习题关系表 服务实现类
*
*
* @author kzy
* @since 2024-06-20 09:42:25
*/
@Service
public class ExExerciseAnswerServiceImpl extends ServiceImpl implements ExExerciseAnswerService {
@Autowired
private ExQuestionMapper questionMapper;
@Override
public ExExerciseAnswer addExerciseAnswer(ExExerciseAnswer exerciseAnswer) {
int row=0;
ExQuestion question=questionMapper.selectById(exerciseAnswer.getQuestionId());
if(exerciseAnswer.getAnswer().equals(question.getAnswer())){
exerciseAnswer.setPassed(1);
}else{
exerciseAnswer.setPassed(0);
}
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;
}
}