|
@@ -1,15 +1,19 @@
|
|
|
package com.qmth.themis.business.service.impl;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
@@ -19,18 +23,25 @@ import com.qmth.themis.business.cache.ExamRecordCacheUtil;
|
|
|
import com.qmth.themis.business.cache.RedisKeyHelper;
|
|
|
import com.qmth.themis.business.cache.bean.ExamCacheBean;
|
|
|
import com.qmth.themis.business.cache.bean.ExamStudentAnswerCacheBean;
|
|
|
+import com.qmth.themis.business.cache.bean.ExamStudentPaperStructCacheBean;
|
|
|
import com.qmth.themis.business.cache.bean.ObjectiveAnswerCacheBean;
|
|
|
+import com.qmth.themis.business.config.SystemConfig;
|
|
|
+import com.qmth.themis.business.constant.SpringContextHolder;
|
|
|
import com.qmth.themis.business.constant.SystemConstant;
|
|
|
import com.qmth.themis.business.dao.TOeExamRecordMapper;
|
|
|
import com.qmth.themis.business.dto.response.TEExamUnFinishDto;
|
|
|
+import com.qmth.themis.business.entity.TOeExamAnswer;
|
|
|
import com.qmth.themis.business.entity.TOeExamRecord;
|
|
|
import com.qmth.themis.business.enums.ExamRecordStatusEnum;
|
|
|
import com.qmth.themis.business.enums.ObjectiveScorePolicyEnum;
|
|
|
import com.qmth.themis.business.service.TEExamPaperService;
|
|
|
import com.qmth.themis.business.service.TEExamService;
|
|
|
+import com.qmth.themis.business.service.TOeExamAnswerService;
|
|
|
import com.qmth.themis.business.service.TOeExamRecordService;
|
|
|
+import com.qmth.themis.business.util.OssUtil;
|
|
|
import com.qmth.themis.business.util.RedisUtil;
|
|
|
import com.qmth.themis.common.contanst.Constants;
|
|
|
+import com.qmth.themis.common.util.FileUtil;
|
|
|
import com.qmth.themis.common.util.SimpleBeanUtil;
|
|
|
|
|
|
/**
|
|
@@ -44,7 +55,7 @@ import com.qmth.themis.common.util.SimpleBeanUtil;
|
|
|
public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, TOeExamRecord> implements TOeExamRecordService {
|
|
|
private final static Logger log = LoggerFactory.getLogger(TOeExamRecordServiceImpl.class);
|
|
|
|
|
|
-
|
|
|
+ private SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
|
|
|
@Resource
|
|
|
TOeExamRecordMapper tOeExamRecordMapper;
|
|
|
|
|
@@ -59,6 +70,12 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
|
|
|
|
|
|
@Resource
|
|
|
TEExamService teExamService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ SystemConfig systemConfig;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TOeExamAnswerService examAnswerService;
|
|
|
|
|
|
/**
|
|
|
* 获取考试未完列表
|
|
@@ -160,7 +177,7 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
|
|
|
}
|
|
|
|
|
|
if (cb.getStructType().intValue() == 1) {
|
|
|
- if (checkSingleChoice(answer.getContent(), cb.getChoiceAnswer())) {
|
|
|
+ if (checkSingleChoice(answer.getAnswer(), cb.getChoiceAnswer())) {
|
|
|
answer.setScore(cb.getScore());
|
|
|
} else {
|
|
|
answer.setScore(0.0);
|
|
@@ -168,7 +185,7 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
|
|
|
}
|
|
|
if (cb.getStructType().intValue() == 2) {
|
|
|
ExamCacheBean ec = examService.getExamCacheBean(ExamRecordCacheUtil.getExamId(recordId));
|
|
|
- int r = checkMultipleChoice(answer.getContent(), cb.getChoiceAnswer());
|
|
|
+ int r = checkMultipleChoice(answer.getAnswer(), cb.getChoiceAnswer());
|
|
|
if (ec.getObjectiveScorePolicy().equals(ObjectiveScorePolicyEnum.EQUAL)) {// 全对给分
|
|
|
if (r == 1) {
|
|
|
answer.setScore(cb.getScore());
|
|
@@ -188,7 +205,7 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
|
|
|
}
|
|
|
}
|
|
|
if (cb.getStructType().intValue() == 3) {
|
|
|
- if (Boolean.parseBoolean(answer.getContent()) == cb.getBoolAnswer().booleanValue()) {
|
|
|
+ if (Boolean.parseBoolean(answer.getAnswer()) == cb.getBoolAnswer().booleanValue()) {
|
|
|
answer.setScore(cb.getScore());
|
|
|
} else {
|
|
|
answer.setScore(0.0);
|
|
@@ -272,6 +289,7 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
|
|
|
/**
|
|
|
*考试记录数据持久化
|
|
|
*/
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
@Override
|
|
|
public void persisted(Long recordId) {
|
|
|
String lockKey = SystemConstant.REDIS_LOCK_EXAM_RECORD_PERSISTED_PREFIX + recordId;
|
|
@@ -279,10 +297,46 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
|
|
|
if (!lock) {
|
|
|
log.debug("persisted doing,request ignore");
|
|
|
}
|
|
|
+ String tempDir = systemConfig.getProperty("sys.config.tempDataDir");
|
|
|
+ String dir = tempDir + "/" + uuid() + "/";
|
|
|
+ File dfile = new File(dir);
|
|
|
try {
|
|
|
- //TODO
|
|
|
+ dfile.mkdirs();
|
|
|
+ String structFilePath = sdf.format(new Date()) + "/" + uuid() + ".json";
|
|
|
+
|
|
|
+ //保存考试记录
|
|
|
+ Map<String,Object> record=redisUtil.getHashEntries(RedisKeyHelper.examRecordCacheKey(recordId));
|
|
|
+ TOeExamRecord er=SimpleBeanUtil.mapToObject(record, TOeExamRecord.class);
|
|
|
+ er.setStatus(ExamRecordStatusEnum.PERSISTED);
|
|
|
+ er.setPaperStruct(structFilePath);
|
|
|
+ er.setPaperStructUpload(1);
|
|
|
+ saveOrUpdate(er);
|
|
|
+ //保存作答
|
|
|
+ Map<String,ExamStudentAnswerCacheBean> answerMap=redisUtil.getHashEntries(RedisKeyHelper.examAnswerKey(recordId));
|
|
|
+ for(ExamStudentAnswerCacheBean answerCache:answerMap.values()) {
|
|
|
+ TOeExamAnswer answer=new TOeExamAnswer();
|
|
|
+ BeanUtils.copyProperties(answerCache, answer);
|
|
|
+ answer.setId(Constants.idGen.next());
|
|
|
+ answer.setExamRecordId(recordId);
|
|
|
+ examAnswerService.saveOrUpdate(answer);
|
|
|
+ }
|
|
|
+ //上传个人试卷结构
|
|
|
+ ExamStudentPaperStructCacheBean struct=(ExamStudentPaperStructCacheBean)redisUtil.get(RedisKeyHelper.studentPaperStructKey(recordId));
|
|
|
+ File structFile = new File(dir+"struct.json");
|
|
|
+ FileUtil.saveAsFile(structFile.getAbsolutePath(), struct.getContent());
|
|
|
+ SystemConfig systemConfig = SpringContextHolder.getBean(SystemConfig.class);
|
|
|
+ OssUtil.ossUpload(systemConfig.getOssEnv(3), structFilePath, structFile);
|
|
|
+
|
|
|
+ //清除缓存
|
|
|
+ redisUtil.delete(RedisKeyHelper.examRecordCacheKey(recordId));
|
|
|
+ redisUtil.delete(RedisKeyHelper.examAnswerKey(recordId));
|
|
|
+ redisUtil.delete(RedisKeyHelper.audioLeftPlayCountKey(recordId));
|
|
|
} finally {
|
|
|
redisUtil.releaseLock(lockKey);
|
|
|
+ FileUtil.deleteFolder(dir);
|
|
|
}
|
|
|
}
|
|
|
+ private String uuid() {
|
|
|
+ return UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
+ }
|
|
|
}
|