浏览代码

新增云阅卷成绩同步功能

wangliang 2 年之前
父节点
当前提交
3067ae839b

+ 41 - 20
themis-admin/src/main/java/com/qmth/themis/admin/api/TEExamActivityController.java

@@ -11,6 +11,7 @@ import com.qmth.themis.business.entity.TBUser;
 import com.qmth.themis.business.entity.TEAudio;
 import com.qmth.themis.business.entity.TEExamActivity;
 import com.qmth.themis.business.enums.ExamModeEnum;
+import com.qmth.themis.business.enums.FieldUniqueEnum;
 import com.qmth.themis.business.enums.MonitorVideoSourceEnum;
 import com.qmth.themis.business.service.*;
 import com.qmth.themis.business.service.impl.TEExamActivityServiceImpl;
@@ -22,6 +23,7 @@ import com.qmth.themis.common.util.ResultUtil;
 import io.swagger.annotations.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.dao.DuplicateKeyException;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 import org.springframework.validation.BindingResult;
@@ -135,27 +137,46 @@ public class TEExamActivityController {
         if (bindingResult.hasErrors()) {
             return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
         }
-        TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
-        teAudio.setOrgId(Objects.nonNull(tbUser.getOrgId()) ? tbUser.getOrgId() : -1L);
-        ExamActivityCacheBean examActivityCacheBean = teExamActivityService.getExamActivityCacheBean(teAudio.getActivityId());
-        ExamCacheBean examCacheBean = teExamService.getExamCacheBean(examActivityCacheBean.getExamId());
-        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("考试未启用手机直播");
-        }
-        if (Objects.isNull(teAudio.getId())) {
-            teAudio.insertInfo(tbUser.getId());
-        } else {
-            teAudio.updateInfo(tbUser.getId());
-        }
-        teAudioService.saveOrUpdate(teAudio);
+        ExamActivityCacheBean examActivityCacheBean = null;
+        try {
+            TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
+            teAudio.setOrgId(Objects.nonNull(tbUser.getOrgId()) ? tbUser.getOrgId() : -1L);
+            examActivityCacheBean = teExamActivityService.getExamActivityCacheBean(teAudio.getActivityId());
+            ExamCacheBean examCacheBean = teExamService.getExamCacheBean(examActivityCacheBean.getExamId());
+            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("考试未启用手机直播");
+            }
+            if (Objects.isNull(teAudio.getId())) {
+                teAudio.insertInfo(tbUser.getId());
+            } else {
+                Integer examCount = tOeExamRecordService.findByExamIdOrExamActivityIdCount(examCacheBean.getId(), teAudio.getActivityId());
+                if (Objects.nonNull(examCount) && examCount.intValue() > 0) {
+                    throw new BusinessException("已有考试记录不能修改");
+                }
+                teAudio.updateInfo(tbUser.getId());
+            }
+            teAudioService.saveOrUpdate(teAudio);
 //        teAudioService.sendAudioMessage(teAudio);
+        } 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("'", "");
+                throw new BusinessException("场次[" + examActivityCacheBean.getCode() + "]下的" + teAudio.getType().getTitle() + teAudio.getPlayTime() / 60 + "分钟" + FieldUniqueEnum.convertToCode(columnStr) + "不允许重复插入");
+            } else if (e instanceof BusinessException) {
+                throw new BusinessException(e.getMessage());
+            } else {
+                throw new RuntimeException(e);
+            }
+        }
         return ResultUtil.ok(true);
     }
 

+ 2 - 2
themis-business/src/main/java/com/qmth/themis/business/enums/AudioTypeEnum.java

@@ -11,9 +11,9 @@ import java.util.Objects;
  */
 public enum AudioTypeEnum {
 
-    BEFORE("开考前语音"),
+    BEFORE("开考前"),
 
-    AFTER("考试结束前语音");
+    AFTER("考试结束前");
 
     AudioTypeEnum(String title) {
         this.title = title;

+ 3 - 1
themis-business/src/main/java/com/qmth/themis/business/enums/FieldUniqueEnum.java

@@ -37,7 +37,9 @@ public enum FieldUniqueEnum {
 
     union_identity_index("考生证件号"),
 
-    room_code_index("该考试批次下考场编码");
+    room_code_index("该考试批次下考场编码"),
+
+    activity_idx("语音消息");
 
     private String code;
 

+ 10 - 4
themis-exam/src/main/java/com/qmth/themis/exam/api/TEMobileController.java

@@ -208,11 +208,17 @@ public class TEMobileController {
     @ApiOperation(value = "查询考试语音信息")
     @RequestMapping(value = "/exam/audio/query", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "语音信息", response = TEAudioResult.class)})
-    public Result examAudioQuery(@ApiParam(value = "考试id", required = true) @RequestParam Long recordId) {
+    public Result examAudioQuery(@RequestBody MobileAnswerSubmitParamBean param) {
+        if (Objects.isNull(param)) {
+            throw new BusinessException(ExceptionResultEnum.PARAMS_ILLEGALITY);
+        }
+        if (Objects.isNull(param.getRecordId())) {
+            throw new BusinessException(ExceptionResultEnum.RECORD_ID_IS_NULL);
+        }
         List<TEAudioResult> teAudioList = null;
-        ExamRecordStatusEnum examRecordStatusEnum = ExamRecordCacheUtil.getStatus(recordId);
+        ExamRecordStatusEnum examRecordStatusEnum = ExamRecordCacheUtil.getStatus(param.getRecordId());
         if (Objects.nonNull(examRecordStatusEnum)) {
-            teAudioList = teAudioService.query(ExamRecordCacheUtil.getExamActivityId(recordId));
+            teAudioList = teAudioService.query(ExamRecordCacheUtil.getExamActivityId(param.getRecordId()));
             if (!CollectionUtils.isEmpty(teAudioList)) {
                 for (TEAudioResult t : teAudioList) {
                     if (Objects.nonNull(t.getAttachmentId())) {
@@ -227,6 +233,6 @@ public class TEMobileController {
                 }
             }
         }
-        return ResultUtil.ok(teAudioList);
+        return ResultUtil.ok(Collections.singletonMap("audios", teAudioList));
     }
 }