瀏覽代碼

新增ip统计相关信息功能

wangliang 2 年之前
父節點
當前提交
2d40941fe7
共有 17 個文件被更改,包括 305 次插入45 次删除
  1. 0 1
      themis-business/src/main/java/com/qmth/themis/business/cache/ExamRecordCacheUtil.java
  2. 1 1
      themis-business/src/main/java/com/qmth/themis/business/constant/SystemConstant.java
  3. 16 0
      themis-business/src/main/java/com/qmth/themis/business/dao/TIpRegionMapper.java
  4. 152 0
      themis-business/src/main/java/com/qmth/themis/business/entity/TIpRegion.java
  5. 1 1
      themis-business/src/main/java/com/qmth/themis/business/enums/ExamRecordFieldEnum.java
  6. 22 0
      themis-business/src/main/java/com/qmth/themis/business/service/TIpRegionService.java
  7. 1 3
      themis-business/src/main/java/com/qmth/themis/business/service/impl/TEStudentServiceImpl.java
  8. 70 0
      themis-business/src/main/java/com/qmth/themis/business/service/impl/TIpRegionServiceImpl.java
  9. 15 4
      themis-business/src/main/java/com/qmth/themis/business/service/impl/TOeExamRecordServiceImpl.java
  10. 1 1
      themis-business/src/main/java/com/qmth/themis/business/util/ServletUtil.java
  11. 5 13
      themis-business/src/main/java/com/qmth/themis/business/util/WebsocketUtil.java
  12. 5 0
      themis-business/src/main/resources/mapper/TIpRegionMapper.xml
  13. 0 1
      themis-exam/src/main/java/com/qmth/themis/exam/start/StartRunning.java
  14. 7 9
      themis-exam/src/main/java/com/qmth/themis/exam/websocket/WebSocketMobileServer.java
  15. 4 11
      themis-exam/src/main/java/com/qmth/themis/exam/websocket/WebSocketOeServer.java
  16. 4 0
      themis-mq/src/main/java/com/qmth/themis/mq/service/impl/MqLogicServiceImpl.java
  17. 1 0
      themis-task/src/main/java/com/qmth/themis/task/start/StartRunning.java

+ 0 - 1
themis-business/src/main/java/com/qmth/themis/business/cache/ExamRecordCacheUtil.java

@@ -1026,7 +1026,6 @@ public class ExamRecordCacheUtil {
                 .get(RedisKeyHelper.examRecordCacheKey(recordId), ExamRecordFieldEnum.update_time.getCode());
     }
 
-
     /**
      * 更新考试记录缓存
      *

+ 1 - 1
themis-business/src/main/java/com/qmth/themis/business/constant/SystemConstant.java

@@ -85,7 +85,7 @@ public class SystemConstant {
     /**
      * 系统相关
      */
-    public static volatile Searcher SEARCHER = null;
+    public volatile static Searcher SEARCHER = null;
     public static final String SYS_CONFIG_KEY_CHARSETS = "sys.txt.charset";
     public static final String METHOD = "post";
     public static final int PAGE_SIZE_MIN = 10;

+ 16 - 0
themis-business/src/main/java/com/qmth/themis/business/dao/TIpRegionMapper.java

@@ -0,0 +1,16 @@
+package com.qmth.themis.business.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.qmth.themis.business.entity.TIpRegion;
+
+/**
+ * <p>
+ * ip信息表 Mapper 接口
+ * </p>
+ *
+ * @author wangliang
+ * @since 2022-08-18
+ */
+public interface TIpRegionMapper extends BaseMapper<TIpRegion> {
+
+}

+ 152 - 0
themis-business/src/main/java/com/qmth/themis/business/entity/TIpRegion.java

@@ -0,0 +1,152 @@
+package com.qmth.themis.business.entity;
+
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.themis.business.util.UidUtil;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+
+/**
+ * <p>
+ * ip信息表
+ * </p>
+ *
+ * @author wangliang
+ * @since 2022-08-18
+ */
+@ApiModel(value = "TIpRegion对象", description = "ip信息表")
+public class TIpRegion implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "主键")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long id;
+
+    @ApiModelProperty(value = "考试记录id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long examRecordId;
+
+    @ApiModelProperty(value = "国家")
+    private String country;
+
+    @ApiModelProperty(value = "地区")
+    private String region;
+
+    @ApiModelProperty(value = "省份")
+    private String province;
+
+    @ApiModelProperty(value = "城市")
+    private String city;
+
+    @ApiModelProperty(value = "运营商")
+    private String isp;
+
+    @ApiModelProperty(value = "创建时间")
+    @TableField(value = "create_time", fill = FieldFill.INSERT)//新增执行
+    private Long createTime;
+
+    @TableField(value = "update_Time", fill = FieldFill.INSERT_UPDATE) // 新增和更新执行
+    @ApiModelProperty(value = "更新时间")
+    private Long updateTime;
+
+    public TIpRegion() {
+
+    }
+
+    public TIpRegion(Long examRecordId, String country, String region, String province, String city, String isp) {
+        this.id = UidUtil.nextId();
+        this.examRecordId = examRecordId;
+        this.country = country;
+        this.region = region;
+        this.province = province;
+        this.city = city;
+        this.isp = isp;
+        this.createTime = System.currentTimeMillis();
+    }
+
+    public void updateInfo(String country, String region, String province, String city, String isp) {
+        this.country = country;
+        this.region = region;
+        this.province = province;
+        this.city = city;
+        this.isp = isp;
+        this.updateTime = System.currentTimeMillis();
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getExamRecordId() {
+        return examRecordId;
+    }
+
+    public void setExamRecordId(Long examRecordId) {
+        this.examRecordId = examRecordId;
+    }
+
+    public String getCountry() {
+        return country;
+    }
+
+    public void setCountry(String country) {
+        this.country = country;
+    }
+
+    public String getRegion() {
+        return region;
+    }
+
+    public void setRegion(String region) {
+        this.region = region;
+    }
+
+    public String getProvince() {
+        return province;
+    }
+
+    public void setProvince(String province) {
+        this.province = province;
+    }
+
+    public String getCity() {
+        return city;
+    }
+
+    public void setCity(String city) {
+        this.city = city;
+    }
+
+    public String getIsp() {
+        return isp;
+    }
+
+    public void setIsp(String isp) {
+        this.isp = isp;
+    }
+
+    public Long getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Long createTime) {
+        this.createTime = createTime;
+    }
+
+    public Long getUpdateTime() {
+        return updateTime;
+    }
+
+    public void setUpdateTime(Long updateTime) {
+        this.updateTime = updateTime;
+    }
+}

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

@@ -135,7 +135,7 @@ public enum ExamRecordFieldEnum {
 
     tencent_video_url("tencentVideoUrl"),
 
-    update_time("updateTime"),;
+    update_time("updateTime");
 
     private String code;
 

+ 22 - 0
themis-business/src/main/java/com/qmth/themis/business/service/TIpRegionService.java

@@ -0,0 +1,22 @@
+package com.qmth.themis.business.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.themis.business.entity.TIpRegion;
+
+/**
+ * <p>
+ * ip信息表 服务类
+ * </p>
+ *
+ * @author wangliang
+ * @since 2022-08-18
+ */
+public interface TIpRegionService extends IService<TIpRegion> {
+
+    /**
+     * 保存ip信息
+     *
+     * @param examRecordId
+     */
+    public void saveIpRegion(Long examRecordId);
+}

+ 1 - 3
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEStudentServiceImpl.java

@@ -8,7 +8,6 @@ import com.google.common.reflect.TypeToken;
 import com.google.gson.Gson;
 import com.qmth.themis.business.bean.StudentParams;
 import com.qmth.themis.business.bean.admin.StudentPhotoUploadResponseBean;
-import com.qmth.themis.business.constant.SpringContextHolder;
 import com.qmth.themis.business.dao.TEStudentMapper;
 import com.qmth.themis.business.dto.response.TEStudentDto;
 import com.qmth.themis.business.dto.response.TEStudentExamRecordDto;
@@ -141,8 +140,7 @@ public class TEStudentServiceImpl extends ServiceImpl<TEStudentMapper, TEStudent
         TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
         teStudent.setPassword(studentParams.getPassword());
         teStudent.setUpdateId(Objects.nonNull(tbUser) ? tbUser.getId() : -1);
-        TEStudentService teStudentService = SpringContextHolder.getBean(TEStudentService.class);
-        teStudentService.updateById(teStudent);
+        this.updateById(teStudent);
         cacheService.updateStudentAccountCache(teStudent.getId());
     }
 }

+ 70 - 0
themis-business/src/main/java/com/qmth/themis/business/service/impl/TIpRegionServiceImpl.java

@@ -0,0 +1,70 @@
+package com.qmth.themis.business.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.themis.business.cache.ExamRecordCacheUtil;
+import com.qmth.themis.business.constant.SystemConstant;
+import com.qmth.themis.business.dao.TIpRegionMapper;
+import com.qmth.themis.business.entity.TIpRegion;
+import com.qmth.themis.business.service.TIpRegionService;
+import com.qmth.themis.common.exception.BusinessException;
+import com.qmth.themis.common.util.IpUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import java.util.Objects;
+
+/**
+ * <p>
+ * ip信息表 服务实现类
+ * </p>
+ *
+ * @author wangliang
+ * @since 2022-08-18
+ */
+@Service
+public class TIpRegionServiceImpl extends ServiceImpl<TIpRegionMapper, TIpRegion> implements TIpRegionService {
+    private final static Logger log = LoggerFactory.getLogger(TIpRegionServiceImpl.class);
+
+    /**
+     * 保存ip信息
+     *
+     * @param examRecordId
+     */
+    @Override
+    public void saveIpRegion(Long examRecordId) {
+        try {
+            String ip = ExamRecordCacheUtil.getClientCurrentIp(examRecordId);
+            if (Objects.nonNull(ip)) {
+                String region = IpUtil.getIpInfo(SystemConstant.SEARCHER, ip);
+                if (Objects.nonNull(region)) {
+                    String[] strs = region.split("\\|");
+                    QueryWrapper<TIpRegion> tIpRegionQueryWrapper = new QueryWrapper<>();
+                    tIpRegionQueryWrapper.lambda().eq(TIpRegion::getExamRecordId, examRecordId);
+                    TIpRegion tIpRegion = this.getOne(tIpRegionQueryWrapper);
+                    if (Objects.isNull(tIpRegion)) {
+                        tIpRegion = new TIpRegion(examRecordId, strs[0], strs[1], strs[2], strs[3], strs[4]);
+                        this.save(tIpRegion);
+                    } else {
+                        if (!Objects.equals(tIpRegion.getCountry(), strs[0])
+                                || !Objects.equals(tIpRegion.getRegion(), strs[1])
+                                || !Objects.equals(tIpRegion.getProvince(), strs[2])
+                                || !Objects.equals(tIpRegion.getCity(), strs[3])
+                                || !Objects.equals(tIpRegion.getIsp(), strs[4])) {
+                            tIpRegion.updateInfo(strs[0], strs[1], strs[2], strs[3], strs[4]);
+                            this.updateById(tIpRegion);
+                        }
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+            if (e instanceof BusinessException) {
+                throw new BusinessException(e.getMessage());
+            } else {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+}

+ 15 - 4
themis-business/src/main/java/com/qmth/themis/business/service/impl/TOeExamRecordServiceImpl.java

@@ -18,7 +18,6 @@ import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dao.TOeExamRecordMapper;
 import com.qmth.themis.business.dto.MqDto;
 import com.qmth.themis.business.dto.response.MarkResultDto;
-import com.qmth.themis.business.dto.response.TEExamUnFinishDto;
 import com.qmth.themis.business.entity.TOeExamAnswer;
 import com.qmth.themis.business.entity.TOeExamRecord;
 import com.qmth.themis.business.entity.TSyncExamStudentScore;
@@ -29,6 +28,7 @@ import com.qmth.themis.common.contanst.Constants;
 import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.util.FileUtil;
+import com.qmth.themis.common.util.IpUtil;
 import com.qmth.themis.common.util.SimpleBeanUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
@@ -614,9 +614,20 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
      */
     @Override
     public void sendExamRecordDataSaveMq(Long recordId, Long timestamp) {
-        ExamRecordCacheUtil.setUpdateTime(recordId, timestamp);
-        MqDto mqDto = new MqDto(mqUtil.getMqGroupDomain().getTopic(), MqTagEnum.EXAM_RECORD_UPDATE.name(), recordId.toString(), timestamp);
-        mqDtoService.assembleSendOneWayMsg(mqDto);
+        try {
+            if (Objects.nonNull(ServletUtil.getRequest())) {
+                String ip = IpUtil.getRemoteIp(ServletUtil.getRequest());
+                if (Objects.nonNull(ip)) {
+                    ExamRecordCacheUtil.setClientCurrentIp(recordId, ip);
+                }
+            }
+        } catch (Exception e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+        } finally {
+            ExamRecordCacheUtil.setUpdateTime(recordId, timestamp);
+            MqDto mqDto = new MqDto(mqUtil.getMqGroupDomain().getTopic(), MqTagEnum.EXAM_RECORD_UPDATE.name(), recordId.toString(), timestamp);
+            mqDtoService.assembleSendOneWayMsg(mqDto);
+        }
     }
 
     /**

+ 1 - 1
themis-business/src/main/java/com/qmth/themis/business/util/ServletUtil.java

@@ -234,7 +234,7 @@ public class ServletUtil {
     public static HttpServletRequest getRequest() {
         ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder
                 .getRequestAttributes();
-        return servletRequestAttributes.getRequest();
+        return Objects.nonNull(servletRequestAttributes) ? servletRequestAttributes.getRequest() : null;
     }
 
     /**

+ 5 - 13
themis-business/src/main/java/com/qmth/themis/business/util/WebsocketUtil.java

@@ -53,15 +53,13 @@ public class WebsocketUtil {
      * 更新websocket状态
      *
      * @param recordId
-     * @param ip
      * @param websocketSessionId
      * @param websocketStatusEnum
      */
-    public static void updateExamRecordWebsocketStatus(Long recordId, String ip, String websocketSessionId,
-            WebsocketStatusEnum websocketStatusEnum) {
+    public static void updateExamRecordWebsocketStatus(Long recordId, String websocketSessionId,
+                                                       WebsocketStatusEnum websocketStatusEnum) {
         Long timestamp = System.currentTimeMillis();
         ExamRecordCacheUtil.setClientWebsocketStatus(recordId, websocketStatusEnum, timestamp);
-        ExamRecordCacheUtil.setClientCurrentIp(recordId, ip);
         ExamRecordCacheUtil.setClientWebsocketId(recordId, websocketSessionId);
         Long clientLastSyncTime = System.currentTimeMillis();
         ExamRecordCacheUtil.setClientLastSyncTime(recordId, clientLastSyncTime);
@@ -77,7 +75,7 @@ public class WebsocketUtil {
      * @param websocketStatusEnum
      */
     public static void updateExamRecordMobileFirstWebsocketStatus(Long recordId, String websocketSessionId,
-            WebsocketStatusEnum websocketStatusEnum) {
+                                                                  WebsocketStatusEnum websocketStatusEnum) {
         Long timestamp = System.currentTimeMillis();
         ExamRecordCacheUtil.setMobileFirstWebsocketStatus(recordId, websocketStatusEnum, timestamp);
         ExamRecordCacheUtil.setMobileFirstWebsocketId(recordId, websocketSessionId);
@@ -93,7 +91,7 @@ public class WebsocketUtil {
      * @param websocketStatusEnum
      */
     public static void updateExamRecordMobileSecondWebsocketStatus(Long recordId, String websocketSessionId,
-            WebsocketStatusEnum websocketStatusEnum) {
+                                                                   WebsocketStatusEnum websocketStatusEnum) {
         Long timestamp = System.currentTimeMillis();
         ExamRecordCacheUtil.setMobileSecondWebsocketStatus(recordId, websocketStatusEnum, timestamp);
         ExamRecordCacheUtil.setMobileSecondWebsocketId(recordId, websocketSessionId);
@@ -105,22 +103,16 @@ public class WebsocketUtil {
      * 初始化websocket
      *
      * @param recordId
-     * @param userId
      * @param deviceId
-     * @param ip
      * @param updateTime
      * @return
      */
-    public static Map<String, Object> initWebsocket(Long recordId, Long userId, String deviceId, String ip,
-            Long updateTime) {
+    public static Map<String, Object> initWebsocket(Long recordId, String deviceId, Long updateTime) {
         Map<String, Object> tranMap = new HashMap<>();
         if (Objects.nonNull(recordId)) {
             tranMap.put(SystemConstant.RECORD_ID, recordId);
-        } else if (Objects.nonNull(userId)) {
-            tranMap.put(SystemConstant.USER_ID, userId);
         }
         tranMap.put("deviceId", deviceId);
-        tranMap.put("ip", ip);
         tranMap.put(SystemConstant.UPDATE_TIME, updateTime);
         return tranMap;
     }

+ 5 - 0
themis-business/src/main/resources/mapper/TIpRegionMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.qmth.themis.business.dao.TIpRegionMapper">
+
+</mapper>

+ 0 - 1
themis-exam/src/main/java/com/qmth/themis/exam/start/StartRunning.java

@@ -49,7 +49,6 @@ public class StartRunning implements CommandLineRunner {
 //        rocketMessageConsumer.setRocketMQConsumer(nameServer, dictionaryConfig.mqConfigDomain().getMap().get(MqGroupEnum.WEBSOCKET_OE_GROUP.name()), dictionaryConfig.mqConfigDomain().getTopic(), MqTagEnum.OE_IM_BROADCASTING.name() + "||" + MqTagEnum.OE_IM_CLUSTERING.name() + "||" + MqTagEnum.OE_LIVENESS_VERIFY.name() + "||" + MqTagEnum.OE_MONITOR_FINISH.name() + "||" + MqTagEnum.OE_WARNING_FINISH.name() + "||" + MqTagEnum.OE_WEBSOCKET_MOBILE_ANSWER_READY.name() + "||" + MqTagEnum.OE_WEBSOCKET_MOBILE_ANSWER_UPLOAD.name() + "||" + MqTagEnum.OE_WEBSOCKET_EXAM_STOP.name() + "||" + MqTagEnum.MONITOR_START.name() + "||" + MqTagEnum.MONITOR_STOP.name() + "||" + MqTagEnum.OE_WEBSOCKET_MOBILE_MONITOR_STATUS.name(), MessageModel.CLUSTERING, SpringContextHolder.getBean(WebSocketOeServer.class));
 //        rocketMessageConsumer.setRocketMQConsumer(nameServer, dictionaryConfig.mqConfigDomain().getMap().get(MqGroupEnum.WEBSOCKET_OE_MOBILE_GROUP.name()), dictionaryConfig.mqConfigDomain().getTopic(), MqTagEnum.EXAM_STOP.name() + "||" + MqTagEnum.EXAM_START.name(), MessageModel.CLUSTERING, SpringContextHolder.getBean(WebSocketMobileServer.class));
         SystemConstant.initTempFiles();
-        SystemConstant.getSearcher();
         log.info("服务器启动时执行 end");
     }
 }

+ 7 - 9
themis-exam/src/main/java/com/qmth/themis/exam/websocket/WebSocketMobileServer.java

@@ -31,7 +31,6 @@ import javax.websocket.*;
 import javax.websocket.server.ServerEndpoint;
 import java.io.IOException;
 import java.lang.reflect.Method;
-import java.net.InetSocketAddress;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -58,7 +57,7 @@ public class WebSocketMobileServer implements Concurrently {
      */
     private Session session = null;
 
-    private String sessionId = null, ip = null, deviceId = null, websocketSessionId = null;
+    private String deviceId = null, websocketSessionId = null;
 
     private Long recordId = null, updateTime = null;
 
@@ -80,7 +79,6 @@ public class WebSocketMobileServer implements Concurrently {
         this.source = (MonitorVideoSourceEnum) session.getUserProperties().get(Constants.HEADER_SOURCE);
         this.session = session;
         session.setMaxIdleTimeout(SystemConstant.WEBSOCKET_MAX_TIME_OUT);
-        this.sessionId = tbSession.getId();
         this.websocketSessionId = String.valueOf(UidUtil.nextId());
         if (webSocketMap.containsKey(this.websocketSessionId)) {
             throw new BusinessException(ExceptionResultEnum.REPEAT_CONNECT_ERROR);
@@ -89,10 +87,10 @@ public class WebSocketMobileServer implements Concurrently {
             addOnlineCount();
         }
         log.info("考试记录:{},WS连接创建:{},在线人数:{}", this.recordId, this.websocketSessionId, getOnlineCount());
-        InetSocketAddress addr = (InetSocketAddress) WebsocketUtil
-                .getFieldInstance(this.session.getAsyncRemote(), "base#socketWrapper#socket#sc#remoteAddress");
-        this.ip = addr.toString().replace("/", "").split(":")[0];
-        log.info("ip[:{}]连接成功", this.ip);
+//        InetSocketAddress addr = (InetSocketAddress) WebsocketUtil
+//                .getFieldInstance(this.session.getAsyncRemote(), "base#socketWrapper#socket#sc#remoteAddress");
+//        this.ip = addr.toString().replace("/", "").split(":")[0];
+//        log.info("ip[:{}]连接成功", this.ip);
         //修改record相关状态需要强制上锁
         String lockKey = SystemConstant.REDIS_LOCK_WEBSOCKET_PREFIX + ":" + this.source.name() + ":" + recordId;
         redisUtil.waitLock(lockKey, SystemConstant.REDIS_LOCK_WEBSOCKET_TIME_OUT);
@@ -108,7 +106,7 @@ public class WebSocketMobileServer implements Concurrently {
             redisUtil.releaseLock(lockKey);
         }
         this.updateTime = System.currentTimeMillis();
-        tranMap = WebsocketUtil.initWebsocket(recordId, null, deviceId, ip, updateTime);
+        tranMap = WebsocketUtil.initWebsocket(recordId, deviceId, updateTime);
     }
 
     /**
@@ -286,7 +284,7 @@ public class WebSocketMobileServer implements Concurrently {
 
     @Override
     public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
-            ConsumeConcurrentlyContext consumeConcurrentlyContext) {
+                                                    ConsumeConcurrentlyContext consumeConcurrentlyContext) {
         MqOeLogicService mqOeLogicService = SpringContextHolder.getBean(MqOeLogicService.class);
         try {
             long threadId = Thread.currentThread().getId();

+ 4 - 11
themis-exam/src/main/java/com/qmth/themis/exam/websocket/WebSocketOeServer.java

@@ -33,7 +33,6 @@ import javax.websocket.*;
 import javax.websocket.server.ServerEndpoint;
 import java.io.IOException;
 import java.lang.reflect.Method;
-import java.net.InetSocketAddress;
 import java.security.NoSuchAlgorithmException;
 import java.util.HashMap;
 import java.util.List;
@@ -61,7 +60,7 @@ public class WebSocketOeServer implements Concurrently {
      */
     private Session session = null;
 
-    private String sessionId = null, ip = null, deviceId = null, websocketSessionId = null;
+    private String deviceId = null, websocketSessionId = null;
 
     private Long recordId = null, updateTime = null;
 
@@ -80,7 +79,6 @@ public class WebSocketOeServer implements Concurrently {
         TBSession tbSession = (TBSession) session.getUserProperties().get(Constants.HEADER_TB_SESSION);
         this.session = session;
         session.setMaxIdleTimeout(SystemConstant.WEBSOCKET_MAX_TIME_OUT);
-        this.sessionId = tbSession.getId();
         websocketSessionId = String.valueOf(UidUtil.nextId());
         if (webSocketMap.containsKey(this.websocketSessionId)) {
             throw new BusinessException(ExceptionResultEnum.REPEAT_CONNECT_ERROR);
@@ -89,21 +87,17 @@ public class WebSocketOeServer implements Concurrently {
             addOnlineCount();
         }
         log.info("考试记录:{},WS连接创建:{},在线人数:{}", this.recordId, this.websocketSessionId, getOnlineCount());
-        InetSocketAddress addr = (InetSocketAddress) WebsocketUtil
-                .getFieldInstance(this.session.getAsyncRemote(), "base#socketWrapper#socket#sc#remoteAddress");
-        this.ip = addr.toString().replace("/", "").split(":")[0];
-        log.info("ip[:{}]连接成功", this.ip);
         //修改record相关状态需要强制上锁
         String lockKey = SystemConstant.REDIS_LOCK_WEBSOCKET_PREFIX + ":client:" + recordId;
         redisUtil.waitLock(lockKey, SystemConstant.REDIS_LOCK_WEBSOCKET_TIME_OUT);
         try {
-            WebsocketUtil.updateExamRecordWebsocketStatus(this.recordId, this.ip, this.websocketSessionId,
+            WebsocketUtil.updateExamRecordWebsocketStatus(this.recordId, this.websocketSessionId,
                     WebsocketStatusEnum.ON_LINE);
         } finally {
             redisUtil.releaseLock(lockKey);
         }
         this.updateTime = System.currentTimeMillis();
-        tranMap = WebsocketUtil.initWebsocket(this.recordId, null, this.deviceId, this.ip, this.updateTime);
+        tranMap = WebsocketUtil.initWebsocket(this.recordId, this.deviceId, this.updateTime);
         MqUtil mqUtil = SpringContextHolder.getBean(MqUtil.class);
         MqDtoService mqDtoService = SpringContextHolder.getBean(MqDtoService.class);
         Map mqMap = new HashMap<>();
@@ -135,8 +129,7 @@ public class WebSocketOeServer implements Concurrently {
                 String currentId = ExamRecordCacheUtil.getClientWebsocketId(recordId);
                 if (this.websocketSessionId != null && this.websocketSessionId.equals(currentId)) {
                     long timestamp = System.currentTimeMillis();
-                    WebsocketUtil.updateExamRecordWebsocketStatus(this.recordId, this.ip, this.websocketSessionId,
-                            WebsocketStatusEnum.OFF_LINE);
+                    WebsocketUtil.updateExamRecordWebsocketStatus(this.recordId, this.websocketSessionId, WebsocketStatusEnum.OFF_LINE);
                     //判断是否是正常退出
                     TOeExamRecordService tOeExamRecordService = SpringContextHolder.getBean(TOeExamRecordService.class);
                     tOeExamRecordService.sendExamRecordDataSaveMq(this.recordId, timestamp);

+ 4 - 0
themis-mq/src/main/java/com/qmth/themis/mq/service/impl/MqLogicServiceImpl.java

@@ -124,6 +124,9 @@ public class MqLogicServiceImpl implements MqLogicService {
     @Resource
     TOeExamRecordService tOeExamRecordService;
 
+    @Resource
+    TIpRegionService tIpRegionService;
+
     /**
      * mq最大重试次数逻辑
      *
@@ -715,6 +718,7 @@ public class MqLogicServiceImpl implements MqLogicService {
         if (Objects.isNull(updateTime) || (Objects.nonNull(updateTime) &&
                 mqDto.getTimestamp().longValue() >= updateTime.longValue())) {
             examRecordService.examRecordDataSave(recordId);
+            tIpRegionService.saveIpRegion(recordId);
         }
         tmRocketMessageService.saveMqMessageSuccess(mqDto, key);
     }

+ 1 - 0
themis-task/src/main/java/com/qmth/themis/task/start/StartRunning.java

@@ -124,6 +124,7 @@ public class StartRunning implements CommandLineRunner {
          */
         rocketMessageConsumer.setRocketMQConsumer(nameServer, dictionaryConfig.mqConfigDomain().getMap().get(MqGroupEnum.TENCENT_VIDEO_GROUP.name()), dictionaryConfig.mqConfigDomain().getTopic(), MqTagEnum.TENCENT_VIDEO.name(), MessageModel.CLUSTERING, SpringContextHolder.getBean(TencentVideoConcurrentlyImpl.class));
         SystemConstant.initTempFiles();
+        SystemConstant.getSearcher();
         log.info("服务器启动时执行 end");
     }
 }