浏览代码

考生端websocket

wangliang 4 年之前
父节点
当前提交
43a5852151

+ 3 - 0
themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskExamStudentImportTemplete.java

@@ -28,6 +28,7 @@ import com.qmth.themis.common.util.Result;
 import com.qmth.themis.common.util.ResultUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.LinkedMultiValueMap;
 
@@ -157,6 +158,8 @@ public class TaskExamStudentImportTemplete implements TaskImportTemplete {
                                 teExamStudent.setStudentId(teStudent.getId());
                                 teExamStudent.setCreateId(taskImportCommon.getCreateId());
                             } else {
+                                TEExamStudent teExamStudentUpdate = new TEExamStudent();
+                                BeanUtils.copyProperties(teExamStudent, teExamStudentUpdate);
                                 teExamStudentUpdateList.add(teExamStudent);
                                 teExamStudent.setUpdateId(taskImportCommon.getCreateId());
                                 teExamStudent.setName(examStudentImportDto.getName());

+ 1 - 0
themis-exam/src/main/java/com/qmth/themis/exam/api/TEStudentController.java

@@ -25,6 +25,7 @@ import com.qmth.themis.common.util.Result;
 import com.qmth.themis.common.util.ResultUtil;
 import com.qmth.themis.exam.config.DictionaryConfig;
 import com.qmth.themis.exam.util.ServletUtil;
+import com.qmth.themis.mq.dto.MqDto;
 import com.qmth.themis.mq.service.MqDtoService;
 import io.swagger.annotations.*;
 import org.apache.commons.lang3.RandomStringUtils;

+ 14 - 2
themis-mq/src/main/java/com/qmth/themis/mq/listener/RocketWebsocketUnNormalLogConsumer.java

@@ -28,6 +28,7 @@ import org.apache.rocketmq.spring.core.RocketMQListener;
 import org.apache.rocketmq.spring.core.RocketMQPushConsumerLifecycleListener;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -67,6 +68,9 @@ public class RocketWebsocketUnNormalLogConsumer implements MessageListenerConcur
     @Transactional
     public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext consumeConcurrentlyContext) {
         MqDto mqDto = null;
+        TOeExamRecord tOeExamRecord = null;
+        TOeExamBreakHistory tOeExamBreakHistory = null;
+        TOeExamRecord tOeExamRecordUpdate = null;
         try {
             long threadId = Thread.currentThread().getId();
             String threadName = Thread.currentThread().getName();
@@ -96,7 +100,9 @@ public class RocketWebsocketUnNormalLogConsumer implements MessageListenerConcur
                         Long updateTime = Long.parseLong(String.valueOf(tranMap.get("updateTime")));
                         Date date = new Date();
                         date.setTime(updateTime);
-                        TOeExamRecord tOeExamRecord = tOeExamRecordService.getById(recordId);
+                        tOeExamRecord = tOeExamRecordService.getById(recordId);
+                        tOeExamRecordUpdate = new TOeExamRecord();
+                        BeanUtils.copyProperties(tOeExamRecord, tOeExamRecordUpdate);
                         Integer breakCount = tOeExamRecord.getLeftBreakResumeCount();
                         if (Objects.isNull(breakCount) || breakCount == 0) {
                             //todo 没有断点次数,则强制交卷
@@ -105,7 +111,7 @@ public class RocketWebsocketUnNormalLogConsumer implements MessageListenerConcur
                         } else {
                             breakCount--;
                             //增加断点记录
-                            TOeExamBreakHistory tOeExamBreakHistory = new TOeExamBreakHistory(recordId, new Date(), WebsocketExceptionEnum.NET_TIME_OUT.ordinal(), WebsocketExceptionEnum.NET_TIME_OUT.name());
+                            tOeExamBreakHistory = new TOeExamBreakHistory(recordId, new Date(), WebsocketExceptionEnum.NET_TIME_OUT.ordinal(), WebsocketExceptionEnum.NET_TIME_OUT.name());
                             tOeExamBreakHistoryService.save(tOeExamBreakHistory);
                             //更新考试记录状态
                             tOeExamRecord.setClientCurrentIp(ip);
@@ -131,6 +137,12 @@ public class RocketWebsocketUnNormalLogConsumer implements MessageListenerConcur
             }
         } catch (Exception e) {
             e.printStackTrace();
+            if (Objects.nonNull(tOeExamRecordUpdate)) {
+                tOeExamRecordService.updateById(tOeExamRecordUpdate);
+            }
+            if (Objects.nonNull(tOeExamBreakHistory)) {
+                tOeExamBreakHistoryService.removeById(tOeExamBreakHistory.getId());
+            }
             return ConsumeConcurrentlyStatus.RECONSUME_LATER;//重试
         } finally {
             if (Objects.nonNull(mqDto)) {

+ 8 - 0
themis-mq/src/main/java/com/qmth/themis/mq/service/MqDtoService.java

@@ -43,4 +43,12 @@ public interface MqDtoService {
      * @return
      */
     public MqDto assembleSendSyncDelayMsg(MqDto mqDto);
+
+    /**
+     * 组装事务消息
+     *
+     * @param mqDto
+     * @return
+     */
+    public MqDto assembleSendTranMsg(MqDto mqDto);
 }

+ 22 - 0
themis-mq/src/main/java/com/qmth/themis/mq/service/impl/MqDtoServiceImpl.java

@@ -133,6 +133,28 @@ public class MqDtoServiceImpl implements MqDtoService {
         return null;
     }
 
+    /**
+     * 组装事务消息
+     *
+     * @param mqDto
+     * @return
+     */
+    @Override
+    public MqDto assembleSendTranMsg(MqDto mqDto) {
+        mqDto.setAck(SystemConstant.DELIVERED_ACK_TYPE);
+        try {
+            producerServer.sendMsgTran(mqDto);
+        } catch (Exception e) {
+            e.printStackTrace();
+            if (Objects.nonNull(mqDto)) {
+                mqDto.setAck(SystemConstant.UNSEND_ACK_TYPE);
+            }
+        } finally {
+            setTopic(mqDto);
+        }
+        return null;
+    }
+
     void setTopic(MqDto mqDto) {
         if (Objects.nonNull(mqDto)) {
             switch (mqDto.getType().ordinal()) {