| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springblade.common.utils.arg; |
| | | import org.springblade.modules.FTP.FtpUtil; |
| | | import org.springblade.modules.exam.entity.ExamAnswerRecord; |
| | | import org.springblade.modules.exam.entity.ExamSubjectChoices; |
| | | import org.springblade.modules.exam.entity.ExamSubjectOption; |
| | | import org.springblade.modules.exam.excel.ExamSubjectExcel; |
| | | import org.springblade.modules.exam.mapper.ExamSubjectChoicesMapper; |
| | | import org.springblade.modules.exam.service.ExamAnswerRecordService; |
| | | import org.springblade.modules.exam.service.ExamSubjectChoicesService; |
| | | import org.springblade.modules.exam.service.ExamSubjectOptionService; |
| | | import org.springblade.modules.exam.vo.ExamSubjectChoicesVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | |
| | | * @author zhongrj |
| | | */ |
| | | @Service |
| | | @AllArgsConstructor |
| | | public class ExamSubjectChoicesServiceImpl extends ServiceImpl<ExamSubjectChoicesMapper, ExamSubjectChoices> implements ExamSubjectChoicesService { |
| | | |
| | | private final ExamSubjectOptionService examSubjectOptionService; |
| | | @Autowired |
| | | private ExamSubjectOptionService examSubjectOptionService; |
| | | |
| | | @Autowired |
| | | private ExamAnswerRecordService examAnswerRecordService; |
| | | |
| | | |
| | | @Override |
| | | public IPage<ExamSubjectChoicesVO> selectExamSubjectChoicesPage(IPage<ExamSubjectChoicesVO> page, ExamSubjectChoicesVO examSubjectChoices) { |
| | |
| | | examSubjectOptionService.save(examSubjectOption4); |
| | | } |
| | | } |
| | | |
| | | //内网数据同步 |
| | | try { |
| | | // arg.test01(arg.url+"/examSubjectChoices/saveSubjectChoicesAndOption",examSubjectChoices); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | }); |
| | | |
| | | } |
| | |
| | | * 判断当前题目的答题结果 |
| | | * @param preSubJectId 题目Id |
| | | * @param preResult 提交的结果 |
| | | * @param scoreId 成绩id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Integer getAnswerResult(Long preSubJectId, String preResult) { |
| | | public Integer getAnswerResult(Long preSubJectId, String preResult,Long scoreId) { |
| | | //查询题目信息 |
| | | ExamSubjectChoices choices = this.getById(preSubJectId); |
| | | //对比答案 |
| | | if (choices.getChoicesType() == 2 || choices.getChoicesType() == 3){ |
| | | //保存答题记录 |
| | | boolean result = preResult.equals(choices.getAnswer()); |
| | | int status = 0; |
| | | //判断题逻辑 |
| | | if (preResult.equals(choices.getAnswer())) { |
| | | return 1; |
| | | if (result){ |
| | | status = 1; |
| | | }else { |
| | | return 2; |
| | | status = 2; |
| | | } |
| | | //新增答题记录 |
| | | saveExamAns(choices,preSubJectId,preResult,scoreId,result); |
| | | //返回 |
| | | return status; |
| | | }else if(choices.getChoicesType() == 0 || choices.getChoicesType() == 1){ |
| | | //处理多选题的答案排序 |
| | | String[] split = preResult.split(","); |
| | |
| | | Arrays.sort(arrayCh); |
| | | String sub0 = Arrays.toString(arrayCh); |
| | | String sub = sub0.substring(1,sub0.length()-1).replaceAll(" ",""); |
| | | if (sub.equals(choices.getAnswer())) { |
| | | return 1; |
| | | |
| | | //保存答题记录 |
| | | boolean result = sub.equals(choices.getAnswer()); |
| | | int status = 0; |
| | | //判断题逻辑 |
| | | if (result){ |
| | | status = 1; |
| | | }else { |
| | | return 2; |
| | | status = 2; |
| | | } |
| | | //新增答题记录 |
| | | saveExamAns(choices,preSubJectId,preResult,scoreId,result); |
| | | //返回 |
| | | return status; |
| | | } |
| | | return 2; |
| | | } |
| | | |
| | | /** |
| | | * 新增答题记录 |
| | | * @param choices 题目 |
| | | * @param preSubJectId 上一题题目id |
| | | * @param preResult 上一题答题结果 |
| | | * @param scoreId 成绩 id |
| | | * @param result 答题是否正确 |
| | | */ |
| | | private void saveExamAns(ExamSubjectChoices choices, Long preSubJectId, String preResult, Long scoreId,boolean result) { |
| | | ExamAnswerRecord examAnswerRecord = new ExamAnswerRecord(); |
| | | examAnswerRecord.setScoreId(scoreId); |
| | | examAnswerRecord.setAnswerOption(preResult); |
| | | examAnswerRecord.setSubjectChoicesId(preSubJectId); |
| | | examAnswerRecord.setAnswer(choices.getAnswer()); |
| | | examAnswerRecord.setSubjectChoicesType(choices.getChoicesType()); |
| | | examAnswerRecord.setAnswerTime(new Date()); |
| | | int status = 0; |
| | | //判断题逻辑 |
| | | if (result){ |
| | | status = 1; |
| | | examAnswerRecord.setAnswerScore(choices.getScore()); |
| | | }else { |
| | | status = 2; |
| | | examAnswerRecord.setAnswerScore(0); |
| | | } |
| | | examAnswerRecord.setAnswerResult(status); |
| | | //新增 |
| | | examAnswerRecordService.save(examAnswerRecord); |
| | | |
| | | //内网数据同步... |
| | | String s = "insert into exam_answer_record(id,subject_choices_id,subject_choices_type,answer_option,answer" + |
| | | ",answer_time,answer_score,answer_result,score_id) " + |
| | | "values(" + "'" + examAnswerRecord.getId() + "'" + |
| | | "," + "'" + examAnswerRecord.getSubjectChoicesId() + "'" + |
| | | "," + "'" + examAnswerRecord.getSubjectChoicesType() + "'" + |
| | | "," + "'" + examAnswerRecord.getAnswerOption() + "'" + |
| | | "," + "'" + examAnswerRecord.getAnswer() + "'" + |
| | | "," + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(examAnswerRecord.getAnswerTime()) + "'" + |
| | | "," + "'" + examAnswerRecord.getAnswerScore() + "'" + |
| | | "," + "'" + examAnswerRecord.getAnswerResult() + "'" + |
| | | "," + "'" + examAnswerRecord.getScoreId() + "'" + ")"; |
| | | FtpUtil.sqlFileUpload(s); |
| | | } |
| | | } |