|
@@ -186,32 +186,49 @@ public class TEExamActivityController {
|
|
@Transactional
|
|
@Transactional
|
|
public Result audioEnable(@ApiParam(value = "考试场次语音id", required = true) @RequestParam Long audioId,
|
|
public Result audioEnable(@ApiParam(value = "考试场次语音id", required = true) @RequestParam Long audioId,
|
|
@ApiParam(value = "启用/禁用", required = true) @RequestParam Boolean enable) {
|
|
@ApiParam(value = "启用/禁用", required = true) @RequestParam Boolean enable) {
|
|
- TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
|
|
|
|
- TEAudio teAudio = teAudioService.getById(audioId);
|
|
|
|
- Optional.ofNullable(teAudio).orElseThrow(() -> new BusinessException("语音信息不存在"));
|
|
|
|
- ExamActivityCacheBean examActivityCacheBean = teExamActivityService.getExamActivityCacheBean(teAudio.getActivityId());
|
|
|
|
- ExamCacheBean examCacheBean = teExamService.getExamCacheBean(examActivityCacheBean.getExamId());
|
|
|
|
- if (enable) {
|
|
|
|
- if (Objects.nonNull(examCacheBean) && examCacheBean.getMode() == ExamModeEnum.ANYTIME) {
|
|
|
|
- throw new BusinessException("只有集中统一的考试才能使用语音播报");
|
|
|
|
- }
|
|
|
|
- if (Objects.nonNull(examCacheBean.getForceFinish()) && examCacheBean.getForceFinish().intValue() == 0) {
|
|
|
|
- throw new BusinessException("考试未启用集中收卷");
|
|
|
|
- }
|
|
|
|
- if (Objects.nonNull(examCacheBean.getMonitorRecord()) && (!examCacheBean.getMonitorRecord().contains(MonitorVideoSourceEnum.MOBILE_FIRST.name())
|
|
|
|
- && !examCacheBean.getMonitorRecord().contains(MonitorVideoSourceEnum.MOBILE_SECOND.name()))) {
|
|
|
|
- throw new BusinessException("考试未启用手机直播");
|
|
|
|
|
|
+ ExamActivityCacheBean examActivityCacheBean = null;
|
|
|
|
+ TEAudio teAudio = null;
|
|
|
|
+ try {
|
|
|
|
+ TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
|
|
|
|
+ teAudio = teAudioService.getById(audioId);
|
|
|
|
+ Optional.ofNullable(teAudio).orElseThrow(() -> new BusinessException("语音信息不存在"));
|
|
|
|
+ examActivityCacheBean = teExamActivityService.getExamActivityCacheBean(teAudio.getActivityId());
|
|
|
|
+ ExamCacheBean examCacheBean = teExamService.getExamCacheBean(examActivityCacheBean.getExamId());
|
|
|
|
+ if (enable) {
|
|
|
|
+ if (Objects.nonNull(examCacheBean) && examCacheBean.getMode() == ExamModeEnum.ANYTIME) {
|
|
|
|
+ throw new BusinessException("只有集中统一的考试才能使用语音播报");
|
|
|
|
+ }
|
|
|
|
+ if (Objects.nonNull(examCacheBean.getForceFinish()) && examCacheBean.getForceFinish().intValue() == 0) {
|
|
|
|
+ throw new BusinessException("考试未启用集中收卷");
|
|
|
|
+ }
|
|
|
|
+ if (Objects.nonNull(examCacheBean.getMonitorRecord()) && (!examCacheBean.getMonitorRecord().contains(MonitorVideoSourceEnum.MOBILE_FIRST.name())
|
|
|
|
+ && !examCacheBean.getMonitorRecord().contains(MonitorVideoSourceEnum.MOBILE_SECOND.name()))) {
|
|
|
|
+ throw new BusinessException("考试未启用手机直播");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ Integer examCount = tOeExamRecordService.findByExamIdOrExamActivityIdCount(examCacheBean.getId(), teAudio.getActivityId());
|
|
|
|
+ if (Objects.nonNull(examCount) && examCount.intValue() > 0) {
|
|
|
|
+ throw new BusinessException("已有考试记录不能禁用");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- Integer examCount = tOeExamRecordService.findByExamIdOrExamActivityIdCount(examCacheBean.getId(), teAudio.getActivityId());
|
|
|
|
- if (Objects.nonNull(examCount) && examCount.intValue() > 0) {
|
|
|
|
- throw new BusinessException("已有考试记录不能禁用");
|
|
|
|
|
|
+ teAudio.setEnable(!enable ? null : enable);
|
|
|
|
+ teAudio.updateInfo(tbUser.getId());
|
|
|
|
+ teAudioService.updateById(teAudio);
|
|
|
|
+// cacheService.updateExamAudioCache(teAudio.getId());
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
|
+ if (e instanceof DuplicateKeyException) {
|
|
|
|
+ String errorColumn = e.getCause().toString();
|
|
|
|
+ String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length())
|
|
|
|
+ .replaceAll("'", "");
|
|
|
|
+ String s = enable ? "启用" : "禁用";
|
|
|
|
+ throw new BusinessException("场次[" + examActivityCacheBean.getCode() + "]下的" + teAudio.getType().getTitle() + teAudio.getPlayTime() / 60 + "分钟" + FieldUniqueEnum.convertToCode(columnStr) + "已有一条被" + s);
|
|
|
|
+ } else if (e instanceof BusinessException) {
|
|
|
|
+ throw new BusinessException(e.getMessage());
|
|
|
|
+ } else {
|
|
|
|
+ throw new RuntimeException(e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- teAudio.setEnable(enable);
|
|
|
|
- teAudio.updateInfo(tbUser.getId());
|
|
|
|
- teAudioService.updateById(teAudio);
|
|
|
|
-// cacheService.updateExamAudioCache(teAudio.getId());
|
|
|
|
return ResultUtil.ok(true);
|
|
return ResultUtil.ok(true);
|
|
}
|
|
}
|
|
|
|
|