Explorar el Código

更新音频剩余播放次数

xiatian hace 4 años
padre
commit
e893cc5d5e

+ 11 - 0
themis-business/src/main/java/com/qmth/themis/business/cache/RedisKeyHelper.java

@@ -8,6 +8,7 @@ public class RedisKeyHelper {
 	private static String examRecordKeyPrefix = "exam_record::";
 	private static String studentPaperStructKeyPrefix = "student_paper_struct::";
 	private static String studentAnswerKeyPrefix = "student_answer::";
+	private static String audioLeftPlayCountKeyPrefix = "audio_left_play_count::";
 
 	/**
 	 * 场次
@@ -74,5 +75,15 @@ public class RedisKeyHelper {
 			return mainNumber + underLine + subNumber + underLine + subIndex + underLine;
 		}
 	}
+	
+	/**
+	 * 音频剩余播放次数
+	 * 
+	 * @param examRecordId
+	 * @return
+	 */
+	public static String audioLeftPlayCountKey(Long examRecordId) {
+		return audioLeftPlayCountKeyPrefix + examRecordId;
+	}
 
 }

+ 9 - 0
themis-business/src/main/java/com/qmth/themis/business/service/TEExamService.java

@@ -85,4 +85,13 @@ public interface TEExamService extends IService<TEExam> {
 	 */
 	public Long answerSubmit(Long studentId, Long recordId, Integer mainNumber, Integer subNumber, Integer subIndex,
 			String answer, Long version, Integer durationSeconds);
+
+	/**更新音频剩余播放次数
+	 * @param id
+	 * @param recordId
+	 * @param key
+	 * @param count
+	 * @return
+	 */
+	public Integer audioLeftPlayCountSubmit(Long studentId, Long recordId, String key, Integer count);
 }

+ 24 - 4
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamServiceImpl.java

@@ -1,6 +1,5 @@
 package com.qmth.themis.business.service.impl;
 
-import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -46,7 +45,6 @@ import com.qmth.themis.common.exception.BusinessException;
  */
 @Service
 public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> implements TEExamService {
-    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
     @Resource
     TEExamMapper teExamMapper;
 
@@ -314,7 +312,7 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
 			throw new BusinessException("考试记录的学生Id和当前登录用户不一致");
 		}
 		ExamStudentAnswerCacheBean answerCache = (ExamStudentAnswerCacheBean) redisUtil
-				.get(RedisKeyHelper.examAnswerKey(er.getExamStudentId()),RedisKeyHelper.examAnswerHashKey(mainNumber, subNumber, subIndex));
+				.get(RedisKeyHelper.examAnswerKey(recordId),RedisKeyHelper.examAnswerHashKey(mainNumber, subNumber, subIndex));
 		if (answerCache == null) {
 			answerCache = new ExamStudentAnswerCacheBean();
 			answerCache.setContent(answer);
@@ -329,7 +327,29 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
 			answerCache.setDuration(durationSeconds);
 		}
 		// 更新考生作答
-		redisUtil.set(RedisKeyHelper.examAnswerKey(er.getExamStudentId()),RedisKeyHelper.examAnswerHashKey(mainNumber, subNumber, subIndex), answerCache);
+		redisUtil.set(RedisKeyHelper.examAnswerKey(recordId),RedisKeyHelper.examAnswerHashKey(mainNumber, subNumber, subIndex), answerCache);
 		return version;
 	}
+
+	@Transactional
+	@Override
+	public Integer audioLeftPlayCountSubmit(Long studentId, Long recordId, String key, Integer count) {
+		ExamRecordCacheBean er = (ExamRecordCacheBean) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId));
+		if (er == null) {
+			throw new BusinessException("未找到考试记录");
+		}
+		ExamStudentCacheBean es = (ExamStudentCacheBean) redisUtil
+				.get(RedisKeyHelper.examStudentCacheKey(er.getExamStudentId()));
+		if (es == null) {
+			throw new BusinessException("未找到考生");
+		}
+		if (studentId.equals(es.getStudentId())) {
+			throw new BusinessException("考试记录的学生Id和当前登录用户不一致");
+		}
+		// 音频剩余播放次数缓存
+		redisUtil.set(RedisKeyHelper.audioLeftPlayCountKey(recordId),key, count);
+				
+		return count;
+	}
+	
 }

+ 22 - 3
themis-exam/src/main/java/com/qmth/themis/exam/api/TEExamController.java

@@ -80,7 +80,7 @@ public class TEExamController {
 	@ApiOperation(value = "开始考试")
 	@RequestMapping(value = "/start", method = RequestMethod.POST)
 	@ApiResponses({ @ApiResponse(code = 200, message = "试卷信息") })
-	public ExamStartBean start(@ApiParam(value = "考ID", required = true) @RequestParam Long recordId,
+	public ExamStartBean start(@ApiParam(value = "考试记录ID", required = true) @RequestParam Long recordId,
 			@ApiParam(value = "断点续考原因", required = false) @RequestParam String reason) {
 		TEStudent teStudent = (TEStudent) ServletUtil.getRequestStudentAccount();
 		String lockKey = SystemConstant.REDIS_LOCK_STUDENT_PREFIX + teStudent.getId();
@@ -98,7 +98,7 @@ public class TEExamController {
 	@ApiOperation(value = "上传个人试卷结构")
 	@RequestMapping(value = "/student_paper_struct/upload", method = RequestMethod.POST)
 	@ApiResponses({ @ApiResponse(code = 200, message = "试卷信息") })
-	public Long studentPaperStruct(@ApiParam(value = "考ID", required = true) @RequestParam Long recordId,
+	public Long studentPaperStruct(@ApiParam(value = "考试记录ID", required = true) @RequestParam Long recordId,
 			@ApiParam(value = "试卷结构json字符串", required = true) @RequestParam String content) {
 		TEStudent teStudent = (TEStudent) ServletUtil.getRequestStudentAccount();
 		String lockKey = SystemConstant.REDIS_LOCK_STUDENT_PREFIX + teStudent.getId();
@@ -116,7 +116,7 @@ public class TEExamController {
 	@ApiOperation(value = "提交作答结果")
 	@RequestMapping(value = "/answer/submit", method = RequestMethod.POST)
 	@ApiResponses({ @ApiResponse(code = 200, message = "试卷信息") })
-	public Long answerSubmit(@ApiParam(value = "考ID", required = true) @RequestParam Long recordId,
+	public Long answerSubmit(@ApiParam(value = "考试记录ID", required = true) @RequestParam Long recordId,
 			@ApiParam(value = "大题号", required = true) @RequestParam Integer mainNumber,
 			@ApiParam(value = "小题号", required = true) @RequestParam Integer subNumber,
 			@ApiParam(value = "套题子题序号", required = false) @RequestParam Integer subIndex,
@@ -136,4 +136,23 @@ public class TEExamController {
 		}
 	}
 	
+	@ApiOperation(value = "更新音频剩余播放次数")
+	@RequestMapping(value = "/audio_left_play_count/submit", method = RequestMethod.POST)
+	@ApiResponses({ @ApiResponse(code = 200, message = "试卷信息") })
+	public Integer audioLeftPlayCountSubmit(@ApiParam(value = "考试记录ID", required = true) @RequestParam Long recordId,
+			@ApiParam(value = "音频标识", required = true) @RequestParam String key,
+			@ApiParam(value = "剩余播放次数", required = true) @RequestParam Integer count) {
+		TEStudent teStudent = (TEStudent) ServletUtil.getRequestStudentAccount();
+		String lockKey = SystemConstant.REDIS_LOCK_STUDENT_PREFIX + teStudent.getId();
+		Boolean lock = redisUtil.lock(lockKey, SystemConstant.REDIS_CACHE_TIME_OUT);
+		if (!lock) {
+			throw new BusinessException(ExceptionResultEnum.REQUEST_AWAIT);
+		}
+		try {
+			return teExamService.audioLeftPlayCountSubmit(teStudent.getId(), recordId,key,count);
+		} finally {
+			redisUtil.releaseLock(lockKey);
+		}
+	}
+	
 }