Browse Source

问题修改

wangliang 2 years ago
parent
commit
c8f9afd5bc

+ 40 - 23
themis-admin/src/main/java/com/qmth/themis/admin/api/TEExamActivityController.java

@@ -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);
     }
     }
 
 

+ 2 - 0
themis-business/src/main/java/com/qmth/themis/business/entity/TEAudio.java

@@ -1,5 +1,6 @@
 package com.qmth.themis.business.entity;
 package com.qmth.themis.business.entity;
 
 
+import com.baomidou.mybatisplus.annotation.FieldStrategy;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
@@ -50,6 +51,7 @@ public class TEAudio extends BaseEntity implements Serializable {
     private AudioTypeEnum type;
     private AudioTypeEnum type;
 
 
     @ApiModelProperty(value = "是否启用,0:停用,1:启用")
     @ApiModelProperty(value = "是否启用,0:停用,1:启用")
+    @TableField(value = "enable", updateStrategy = FieldStrategy.IGNORED)
     private Boolean enable = true;
     private Boolean enable = true;
 
 
     @ApiModelProperty(value = "是否默认,SYS:系统内置,CUSTOM:自定义")
     @ApiModelProperty(value = "是否默认,SYS:系统内置,CUSTOM:自定义")

+ 3 - 1
themis-business/src/main/resources/mapper/TEAudioMapper.xml

@@ -9,7 +9,7 @@
         t.activityId,
         t.activityId,
         t.content,
         t.content,
         t.`type`,
         t.`type`,
-        t.enable,
+        IFNULL(t.enable, false) as enable,
         t.audioDefault,
         t.audioDefault,
         t.attachmentId,
         t.attachmentId,
         if(t.updateName is not null,
         if(t.updateName is not null,
@@ -88,6 +88,8 @@
         <if test="activityId != null and activityId != ''">
         <if test="activityId != null and activityId != ''">
             and tea.activity_id = #{activityId}
             and tea.activity_id = #{activityId}
         </if>
         </if>
+        and teea.enable = 1
+        and tea.enable = 1
     </where>
     </where>
     order by tea.create_time
     order by tea.create_time
 </select>
 </select>