Prechádzať zdrojové kódy

加入考生轨迹ip段

wangliang 2 rokov pred
rodič
commit
f188f30d07
17 zmenil súbory, kde vykonal 374 pridanie a 69 odobranie
  1. 23 2
      themis-business/src/main/java/com/qmth/themis/business/constant/SystemConstant.java
  2. 74 1
      themis-business/src/main/java/com/qmth/themis/business/dto/WarningDto.java
  3. 90 3
      themis-business/src/main/java/com/qmth/themis/business/entity/TEExamStudentLog.java
  4. 2 1
      themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamBreachLogServiceImpl.java
  5. 9 4
      themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamServiceImpl.java
  6. 2 1
      themis-business/src/main/java/com/qmth/themis/business/service/impl/TEMobileServiceImpl.java
  7. 16 25
      themis-business/src/main/java/com/qmth/themis/business/service/impl/TIpRegionServiceImpl.java
  8. 2 1
      themis-business/src/main/java/com/qmth/themis/business/service/impl/TOeExamRecordServiceImpl.java
  9. 10 8
      themis-business/src/main/java/com/qmth/themis/business/service/impl/WarningServiceImpl.java
  10. 5 1
      themis-common/src/main/java/com/qmth/themis/common/util/IpUtil.java
  11. 17 2
      themis-exam/src/main/java/com/qmth/themis/exam/api/TEExamController.java
  12. 6 1
      themis-exam/src/main/java/com/qmth/themis/exam/api/TEFaceController.java
  13. 6 1
      themis-exam/src/main/java/com/qmth/themis/exam/api/TELivenessController.java
  14. 5 2
      themis-exam/src/main/java/com/qmth/themis/exam/api/TEStudentController.java
  15. 33 3
      themis-exam/src/main/java/com/qmth/themis/exam/listener/service/impl/MqOeLogicServiceImpl.java
  16. 5 0
      themis-exam/src/main/java/com/qmth/themis/exam/start/StartRunning.java
  17. 69 13
      themis-mq/src/main/java/com/qmth/themis/mq/service/impl/MqLogicServiceImpl.java

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

@@ -13,8 +13,6 @@ import com.qmth.themis.business.cache.ExamRecordCacheUtil;
 import com.qmth.themis.business.cache.RedisKeyHelper;
 import com.qmth.themis.business.dto.ExpireTimeDTO;
 import com.qmth.themis.business.dto.cache.TEStudentCacheDto;
-import com.qmth.themis.business.dto.response.SysConfigBean;
-import com.qmth.themis.business.entity.SysConfig;
 import com.qmth.themis.business.entity.TOeExamRecord;
 import com.qmth.themis.business.enums.*;
 import com.qmth.themis.business.service.TEExamPaperService;
@@ -201,6 +199,7 @@ public class SystemConstant {
 //    public static final String REAL_EXEC_TIME = "realExecTime";
     public static final String INSERT = "insert";
     public static final String DELETE = "delete";
+    public static final String IP_ADDRESS = "ipAddress";
     //    public static final Long EXAM_AUDIO_BEFORE_TIME = 3000L;
     public static final Long BEFORE_AUDIO_ATTACHMENT_ID = 1L;
     public static final Long AFTER_AUDIO_ATTACHMENT_ID = 2L;
@@ -1166,4 +1165,26 @@ public class SystemConstant {
         }
         return stringJoiner;
     }
+
+    /**
+     * 获取ip信息
+     *
+     * @param ip
+     * @return
+     */
+    public static String[] getIpInfo(String ip) {
+        String[] strs = null;
+        if (Objects.nonNull(ip) && !Objects.equals(ip.trim(), "0:0:0:0:0:0:0:1") && !Objects.equals(ip.trim(), "127.0.0.1")
+                && !Objects.equals(ip.trim(), "localhost")) {
+            String region = IpUtil.getIpInfo(SystemConstant.SEARCHER, ip);
+            if (Objects.nonNull(region)) {
+                strs = region.split("\\|");
+                if (strs.length != 5) {
+                    log.error("ip region error:{}", region);
+                    throw new BusinessException("ip信息格式错误");
+                }
+            }
+        }
+        return strs;
+    }
 }

+ 74 - 1
themis-business/src/main/java/com/qmth/themis/business/dto/WarningDto.java

@@ -35,16 +35,89 @@ public class WarningDto implements Serializable {
     @ApiModelProperty(name = "随机数")
     private String random;
 
+    @ApiModelProperty(value = "ip地址")
+    private String ip;
+
+    @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;
+
     public WarningDto() {
 
     }
 
-    public WarningDto(VerifyExceptionEnum warningEnum, Integer faceCount, Double realness, Long recordId, String photoUrl) {
+    public WarningDto(VerifyExceptionEnum warningEnum, Integer faceCount, Double realness, Long recordId, String photoUrl, String ip,
+                      String country, String region, String province, String city, String isp) {
         this.warningEnum = warningEnum;
         this.faceCount = faceCount;
         this.realness = realness;
         this.recordId = recordId;
         this.photoUrl = photoUrl;
+        this.ip = ip;
+        this.country = country;
+        this.region = region;
+        this.province = province;
+        this.city = city;
+        this.isp = isp;
+    }
+
+    public String getIp() {
+        return ip;
+    }
+
+    public void setIp(String ip) {
+        this.ip = ip;
+    }
+
+    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 String getRandom() {

+ 90 - 3
themis-business/src/main/java/com/qmth/themis/business/entity/TEExamStudentLog.java

@@ -72,20 +72,46 @@ public class TEExamStudentLog implements Serializable {
     @TableField(value = "title")
     private String title;
 
+    @ApiModelProperty(value = "ip地址")
+    private String ip;
+
+    @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;
+
     public TEExamStudentLog() {
 
     }
 
-    public TEExamStudentLog(String type, String info, String remark, Long studentId) {
+    public TEExamStudentLog(String type, String info, String remark, Long studentId, String ip,
+                            String country, String region, String province, String city, String isp) {
         this.id = UidUtil.nextId();
         this.type = type;
         this.info = info;
         this.remark = remark;
         this.studentId = studentId;
+        this.ip = ip;
+        this.country = country;
+        this.region = region;
+        this.province = province;
+        this.city = city;
+        this.isp = isp;
     }
 
     public TEExamStudentLog(String type, String info, String remark, Long studentId, Long examStudentId,
-            Long examRecordId, String title) {
+                            Long examRecordId, String title, String ip,
+                            String country, String region, String province, String city, String isp) {
         this.id = UidUtil.nextId();
         this.type = type;
         this.info = info;
@@ -94,10 +120,17 @@ public class TEExamStudentLog implements Serializable {
         this.examStudentId = examStudentId;
         this.examRecordId = examRecordId;
         this.title = title;
+        this.ip = ip;
+        this.country = country;
+        this.region = region;
+        this.province = province;
+        this.city = city;
+        this.isp = isp;
     }
 
     public TEExamStudentLog(String type, String info, String remark, Long studentId, Long examStudentId,
-            Long examRecordId, Long objId, String title) {
+                            Long examRecordId, Long objId, String title, String ip,
+                            String country, String region, String province, String city, String isp) {
         this.id = UidUtil.nextId();
         this.type = type;
         this.info = info;
@@ -107,6 +140,60 @@ public class TEExamStudentLog implements Serializable {
         this.examRecordId = examRecordId;
         this.objId = objId;
         this.title = title;
+        this.ip = ip;
+        this.country = country;
+        this.region = region;
+        this.province = province;
+        this.city = city;
+        this.isp = isp;
+    }
+
+    public String getIp() {
+        return ip;
+    }
+
+    public void setIp(String ip) {
+        this.ip = ip;
+    }
+
+    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 String getTitle() {

+ 2 - 1
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamBreachLogServiceImpl.java

@@ -21,6 +21,7 @@ import com.qmth.themis.business.service.TOeExamRecordService;
 import com.qmth.themis.business.util.MqUtil;
 import com.qmth.themis.business.util.ServletUtil;
 import com.qmth.themis.common.exception.BusinessException;
+import com.qmth.themis.common.util.IpUtil;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
@@ -131,7 +132,7 @@ public class TEExamBreachLogServiceImpl extends ServiceImpl<TEExamBreachLogMappe
                 properties.put(SystemConstant.OBJ_ID, eb.getId());
                 properties.put(SystemConstant.BREACH_LOG_STATUS, status);
                 ExamStudentCacheBean examStudentCacheBean = teExamStudentService.getExamStudentCacheBean(eb.getExamStudentId());
-                MqDto mqDto = new MqDto(mqUtil.getTopic(), MqTagEnum.STUDENT.name(), eb.getStatus() == 0 ? SystemOperationEnum.BREACH_HANDLE : SystemOperationEnum.BREACH_REVOKE, MqTagEnum.STUDENT, String.valueOf(examStudentCacheBean.getStudentId()), properties, examStudentCacheBean.getIdentity());
+                MqDto mqDto = new MqDto(mqUtil.getTopic(), MqTagEnum.STUDENT.name(), eb.getStatus() == 0 ? SystemOperationEnum.BREACH_HANDLE : SystemOperationEnum.BREACH_REVOKE, MqTagEnum.STUDENT, String.valueOf(examStudentCacheBean.getStudentId()), properties, IpUtil.getRemoteIp(ServletUtil.getRequest()));
                 mqDtoService.assembleSendOneWayMsg(mqDto);
             }
             teExamBreachLogService.saveOrUpdateBatch(teExamBreachLogList);

+ 9 - 4
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamServiceImpl.java

@@ -371,9 +371,9 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
         //        ExamActivityRecordCacheUtil.setExamRecordStatus(activityId, recordId);
         //        ExamingDataCacheUtil.setUnFinishedRecordId(studentId, recordId);
         //mq发送消息start
-        //        TEStudentCacheDto teStudentCacheDto = (TEStudentCacheDto) redisUtil.getStudent(studentId);
-        //        MqDto mqDto = new MqDto(MqTopicEnum.THEMIS_TOPIC.getCode(), MqTagEnum.STUDENT.name(), SystemOperationEnum.FIRST_PREPARE, MqTagEnum.STUDENT, String.valueOf(teStudentCacheDto.getId()), teStudentCacheDto.getIdentity());
-        //        this.sendOeLogMessage(SystemOperationEnum.FIRST_PREPARE, examStudentId, recordId, mqDto);
+        TEStudentCacheDto teStudentCacheDto = themisCacheService.addStudentAccountCache(es.getStudentId());
+        MqDto mqDto = new MqDto(mqUtil.getTopic(), MqTagEnum.STUDENT.name(), SystemOperationEnum.FIRST_PREPARE, MqTagEnum.STUDENT, String.valueOf(teStudentCacheDto.getId()), IpUtil.getRemoteIp(ServletUtil.getRequest()));
+        this.sendOeLogMessage(SystemOperationEnum.FIRST_PREPARE, examStudentId, recordId, mqDto);
         //mq发送消息end
         return prepare;
     }
@@ -1030,6 +1030,11 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
             tgErrorService.saveExamTgError(recordId, "resume");
             throw new BusinessException(ExceptionResultEnum.EXAM_STATUS_UPDATE_ERROR);
         }
+        //mq发送消息start
+        TEStudentCacheDto teStudentCacheDto = themisCacheService.addStudentAccountCache(es.getStudentId());
+        MqDto mqDto = new MqDto(mqUtil.getTopic(), MqTagEnum.STUDENT.name(), SystemOperationEnum.RESUME_PREPARE, MqTagEnum.STUDENT, String.valueOf(teStudentCacheDto.getId()), IpUtil.getRemoteIp(ServletUtil.getRequest()));
+        this.sendOeLogMessage(SystemOperationEnum.RESUME_PREPARE, examStudentId, recordId, mqDto);
+        //mq发送消息end
         return ret;
     }
 
@@ -1248,7 +1253,7 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
         //mq发送消息start
         MqDto mqDto = new MqDto(mqUtil.getTopic(), MqTagEnum.STUDENT.name(),
                 SystemOperationEnum.FINISHED, MqTagEnum.STUDENT, String.valueOf(teStudentCacheDto.getId()),
-                teStudentCacheDto.getIdentity());
+                IpUtil.getRemoteIp(ServletUtil.getRequest()));
         this.sendOeLogMessage(SystemOperationEnum.FINISHED, examStudentId, recordId, mqDto);
         //mq发送消息end
 

+ 2 - 1
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEMobileServiceImpl.java

@@ -26,6 +26,7 @@ import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.enums.Platform;
 import com.qmth.themis.common.enums.Source;
 import com.qmth.themis.common.exception.BusinessException;
+import com.qmth.themis.common.util.IpUtil;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -112,7 +113,7 @@ public class TEMobileServiceImpl implements TEMobileService {
         MqDto mqDto = new MqDto(mqUtil.getTopic(), platform.name(), SystemOperationEnum.SESSION, sessionId);
         mqDtoService.assembleSendOneWayMsg(mqDto);
         MqDto mqDtoLog = new MqDto(mqUtil.getTopic(), MqTagEnum.STUDENT.name(),
-                SystemOperationEnum.LOGIN, MqTagEnum.STUDENT, String.valueOf(es.getStudentId()), es.getIdentity());
+                SystemOperationEnum.LOGIN, MqTagEnum.STUDENT, String.valueOf(es.getStudentId()), IpUtil.getRemoteIp(ServletUtil.getRequest()));
         mqDtoService.assembleSendOneWayMsg(mqDtoLog);
         //mq发送消息end
         //测试

+ 16 - 25
themis-business/src/main/java/com/qmth/themis/business/service/impl/TIpRegionServiceImpl.java

@@ -8,7 +8,6 @@ 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;
@@ -35,30 +34,22 @@ public class TIpRegionServiceImpl extends ServiceImpl<TIpRegionMapper, TIpRegion
     @Override
     public void saveIpRegion(Long examRecordId) {
         try {
-            String ip = ExamRecordCacheUtil.getClientCurrentIp(examRecordId);
-            if (Objects.nonNull(ip) && !Objects.equals(ip, "0:0:0:0:0:0:0:1")) {
-                String region = IpUtil.getIpInfo(SystemConstant.SEARCHER, ip);
-                if (Objects.nonNull(region)) {
-                    String[] strs = region.split("\\|");
-                    if (strs.length != 5) {
-                        log.error("ip region error:{}", region);
-                        throw new BusinessException("ip信息格式错误");
-                    }
-                    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);
-                        }
+            String[] strs = SystemConstant.getIpInfo(ExamRecordCacheUtil.getClientCurrentIp(examRecordId));
+            if (Objects.nonNull(strs) && strs.length > 0) {
+                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);
                     }
                 }
             }

+ 2 - 1
themis-business/src/main/java/com/qmth/themis/business/service/impl/TOeExamRecordServiceImpl.java

@@ -542,7 +542,8 @@ public class TOeExamRecordServiceImpl extends ServiceImpl<TOeExamRecordMapper, T
         try {
             if (Objects.nonNull(ServletUtil.getRequest())) {
                 String ip = IpUtil.getRemoteIp(ServletUtil.getRequest());
-                if (Objects.nonNull(ip)) {
+                if (Objects.nonNull(ip) && !Objects.equals(ip.trim(), "0:0:0:0:0:0:0:1") && !Objects.equals(ip.trim(), "127.0.0.1")
+                        && !Objects.equals(ip.trim(), "localhost")) {
                     ExamRecordCacheUtil.setClientCurrentIp(recordId, ip);
                 }
             }

+ 10 - 8
themis-business/src/main/java/com/qmth/themis/business/service/impl/WarningServiceImpl.java

@@ -87,7 +87,7 @@ public class WarningServiceImpl implements WarningService {
                     TIeInvigilateWarnInfo tIeInvigilateWarnInfo = new TIeInvigilateWarnInfo(examId, examActivityId, recordId, examStudentId, warningEnum.getLevel().get(1), WarningLevelEnum.valueOf(warningEnum.getLevel().get(1)).getTitle(), warningEnum, photoUrl, Objects.nonNull(ExamRecordCacheUtil.getBreachStatus(recordId)) ? ExamRecordCacheUtil.getBreachStatus(recordId) : 1);
                     tIeInvigilateWarnInfoService.saveOrUpdate(tIeInvigilateWarnInfo);
                     this.setWarningCount(recordId);
-                    this.setPhotoUrls(map, tIeInvigilateWarnInfo, examStudentCacheBean, recordId, teConfig.getMultipleFaceCountError());
+                    this.setPhotoUrls(map, tIeInvigilateWarnInfo, examStudentCacheBean, recordId, teConfig.getMultipleFaceCountError(), warningDto);
                 }
             }
         } else if (faceCount <= 0) {//未检测到人脸
@@ -99,7 +99,7 @@ public class WarningServiceImpl implements WarningService {
                     TIeInvigilateWarnInfo tIeInvigilateWarnInfo = new TIeInvigilateWarnInfo(examId, examActivityId, recordId, examStudentId, warningEnum.getLevel().get(0), WarningLevelEnum.valueOf(warningEnum.getLevel().get(0)).getTitle(), warningEnum, photoUrl, Objects.nonNull(ExamRecordCacheUtil.getBreachStatus(recordId)) ? ExamRecordCacheUtil.getBreachStatus(recordId) : 1);
                     tIeInvigilateWarnInfoService.saveOrUpdate(tIeInvigilateWarnInfo);
                     this.setWarningCount(recordId);
-                    this.setPhotoUrls(map, tIeInvigilateWarnInfo, examStudentCacheBean, recordId, teConfig.getNoFaceCountError());
+                    this.setPhotoUrls(map, tIeInvigilateWarnInfo, examStudentCacheBean, recordId, teConfig.getNoFaceCountError(), warningDto);
                 }
             }
         }
@@ -135,7 +135,7 @@ public class WarningServiceImpl implements WarningService {
                 TIeInvigilateWarnInfo tIeInvigilateWarnInfo = new TIeInvigilateWarnInfo(examId, examActivityId, recordId, examStudentId, warningEnum.getLevel().get(0), WarningLevelEnum.valueOf(warningEnum.getLevel().get(0)).getTitle(), warningEnum, photoUrl, Objects.nonNull(ExamRecordCacheUtil.getBreachStatus(recordId)) ? ExamRecordCacheUtil.getBreachStatus(recordId) : 1);
                 tIeInvigilateWarnInfoService.saveOrUpdate(tIeInvigilateWarnInfo);
                 this.setWarningCount(recordId);
-                this.setPhotoUrls(map, tIeInvigilateWarnInfo, examStudentCacheBean, recordId, teConfig.getTotalFaceCompareErrorCount());
+                this.setPhotoUrls(map, tIeInvigilateWarnInfo, examStudentCacheBean, recordId, teConfig.getTotalFaceCompareErrorCount(), warningDto);
             }
         }
     }
@@ -170,7 +170,7 @@ public class WarningServiceImpl implements WarningService {
                 TIeInvigilateWarnInfo tIeInvigilateWarnInfo = new TIeInvigilateWarnInfo(examId, examActivityId, recordId, examStudentId, warningEnum.getLevel().get(0), WarningLevelEnum.valueOf(warningEnum.getLevel().get(0)).getTitle(), warningEnum, photoUrl, Objects.nonNull(ExamRecordCacheUtil.getBreachStatus(recordId)) ? ExamRecordCacheUtil.getBreachStatus(recordId) : 1);
                 tIeInvigilateWarnInfoService.saveOrUpdate(tIeInvigilateWarnInfo);
                 this.setWarningCount(recordId);
-                this.setPhotoUrls(map, tIeInvigilateWarnInfo, examStudentCacheBean, recordId, teConfig.getTotalEyeCloseErrorCount());
+                this.setPhotoUrls(map, tIeInvigilateWarnInfo, examStudentCacheBean, recordId, teConfig.getTotalEyeCloseErrorCount(), warningDto);
             }
         }
     }
@@ -205,7 +205,7 @@ public class WarningServiceImpl implements WarningService {
                 TIeInvigilateWarnInfo tIeInvigilateWarnInfo = new TIeInvigilateWarnInfo(examId, examActivityId, recordId, examStudentId, WarningLevelEnum.D15.name(), WarningLevelEnum.D15.getTitle(), warningEnum, photoUrl, Objects.nonNull(ExamRecordCacheUtil.getBreachStatus(recordId)) ? ExamRecordCacheUtil.getBreachStatus(recordId) : 1);
                 tIeInvigilateWarnInfoService.saveOrUpdate(tIeInvigilateWarnInfo);
                 this.setWarningCount(recordId);
-                this.setPhotoUrls(map, tIeInvigilateWarnInfo, examStudentCacheBean, recordId, teConfig.getRealnessCount());
+                this.setPhotoUrls(map, tIeInvigilateWarnInfo, examStudentCacheBean, recordId, teConfig.getRealnessCount(), warningDto);
             }
         }
     }
@@ -235,7 +235,7 @@ public class WarningServiceImpl implements WarningService {
             TIeInvigilateWarnInfo tIeInvigilateWarnInfo = new TIeInvigilateWarnInfo(examId, examActivityId, recordId, examStudentId, VerifyExceptionEnum.LIVENESS_ACTION_ERROR.getLevel().get(0), VerifyExceptionEnum.LIVENESS_ACTION_ERROR.getTitle(), VerifyExceptionEnum.LIVENESS_ACTION_ERROR, photoUrl, Objects.nonNull(ExamRecordCacheUtil.getBreachStatus(recordId)) ? ExamRecordCacheUtil.getBreachStatus(recordId) : 1);
             tIeInvigilateWarnInfoService.saveOrUpdate(tIeInvigilateWarnInfo);
             this.setWarningCount(recordId);
-            this.setPhotoUrls(map, tIeInvigilateWarnInfo, examStudentCacheBean, recordId, 0);
+            this.setPhotoUrls(map, tIeInvigilateWarnInfo, examStudentCacheBean, recordId, 0, warningDto);
         }
     }
 
@@ -263,8 +263,9 @@ public class WarningServiceImpl implements WarningService {
      * @param examStudentCacheBean
      * @param recordId
      * @param count
+     * @param warningDto
      */
-    public void setPhotoUrls(Map<String, Object> map, TIeInvigilateWarnInfo tIeInvigilateWarnInfo, ExamStudentCacheBean examStudentCacheBean, Long recordId, Integer count) {
+    public void setPhotoUrls(Map<String, Object> map, TIeInvigilateWarnInfo tIeInvigilateWarnInfo, ExamStudentCacheBean examStudentCacheBean, Long recordId, Integer count, WarningDto warningDto) {
         List<String> photoUrls = new ArrayList();
         if (Objects.nonNull(map.get("photoUrls")) && !Objects.equals(map.get("photoUrls"), "")) {
             String[] s = String.valueOf(map.get("photoUrls")).split(",");
@@ -277,7 +278,8 @@ public class WarningServiceImpl implements WarningService {
         JSONObject jsonObject = new JSONObject();
         jsonObject.put("PHOTOS", photoUrls);
         jsonObject.put("MIN_CREATE_TIME", map.get(SystemConstant.CREATE_TIME));
-        TEExamStudentLog teExamStudentLog = new TEExamStudentLog(tIeInvigilateWarnInfo.getType().name(), WarningLevelEnum.valueOf(tIeInvigilateWarnInfo.getLevel()).getTitle(), jsonObject.toJSONString(), examStudentCacheBean.getStudentId(), examStudentCacheBean.getId(), recordId, WarningLevelEnum.valueOf(tIeInvigilateWarnInfo.getLevel()).getSecondTitle());
+        TEExamStudentLog teExamStudentLog = new TEExamStudentLog(tIeInvigilateWarnInfo.getType().name(), WarningLevelEnum.valueOf(tIeInvigilateWarnInfo.getLevel()).getTitle(), jsonObject.toJSONString(), examStudentCacheBean.getStudentId(), examStudentCacheBean.getId(), recordId, WarningLevelEnum.valueOf(tIeInvigilateWarnInfo.getLevel()).getSecondTitle(),
+                warningDto.getIp(), warningDto.getCountry(), warningDto.getRegion(), warningDto.getProvince(), warningDto.getCity(), warningDto.getIsp());
         teExamStudentLogService.saveOrUpdate(teExamStudentLog);
     }
 }

+ 5 - 1
themis-common/src/main/java/com/qmth/themis/common/util/IpUtil.java

@@ -32,7 +32,11 @@ public class IpUtil {
      * @return
      */
     public static String getRemoteIp(HttpServletRequest request) {
-        return getRemoteIp(request, true);
+        if (Objects.nonNull(request)) {
+            return getRemoteIp(request, true);
+        } else {
+            return null;
+        }
     }
 
     /**

+ 17 - 2
themis-exam/src/main/java/com/qmth/themis/exam/api/TEExamController.java

@@ -24,6 +24,7 @@ import com.qmth.themis.business.util.RedisUtil;
 import com.qmth.themis.business.util.ServletUtil;
 import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.exception.BusinessException;
+import com.qmth.themis.common.util.IpUtil;
 import com.qmth.themis.common.util.Result;
 import com.qmth.themis.common.util.ResultUtil;
 import com.qmth.themis.exam.config.ExamConstant;
@@ -111,7 +112,9 @@ public class TEExamController {
             if (param.getExamStudentId() == null) {
                 throw new BusinessException(ExceptionResultEnum.EXAM_STUDENT_ID_IS_NULL);
             }
-            return ResultUtil.ok(teExamService.prepare(teStudent.getId(), param.getExamStudentId()));
+            ExamPrepareBean examPrepareBean = teExamService.prepare(teStudent.getId(), param.getExamStudentId());
+            ExamRecordCacheUtil.setClientCurrentIp(examPrepareBean.getRecordId(), IpUtil.getRemoteIp(ServletUtil.getRequest()));
+            return ResultUtil.ok(examPrepareBean);
         } finally {
             redisUtil.releaseLock(lockKey);
         }
@@ -173,6 +176,7 @@ public class TEExamController {
             WebSocketOeServer webSocketOeServer = webSocketMap.get(clientWebsocketId);
             WebSocketOeServer.close(webSocketOeServer);
         }
+        ExamRecordCacheUtil.setClientCurrentIp(recordId, IpUtil.getRemoteIp(ServletUtil.getRequest()));
         return ResultUtil.ok(true);
     }
 
@@ -211,12 +215,13 @@ public class TEExamController {
                 //mq发送消息start
                 MqDto mqDto = new MqDto(mqUtil.getTopic(), MqTagEnum.STUDENT.name(),
                         SystemOperationEnum.ANSWERING, MqTagEnum.STUDENT, String.valueOf(teStudent.getId()),
-                        teStudent.getIdentity());
+                        IpUtil.getRemoteIp(ServletUtil.getRequest()));
                 teExamService.sendOeLogMessage(SystemOperationEnum.ANSWERING,
                         ExamRecordCacheUtil.getExamStudentId(param.getRecordId()), param.getRecordId(), mqDto);
                 //mq发送消息end
             }
             ExamConstant.sendExamStartMsg(param.getRecordId());
+            ExamRecordCacheUtil.setClientCurrentIp(param.getRecordId(), IpUtil.getRemoteIp(ServletUtil.getRequest()));
             return ResultUtil.ok(examStartBean);
         } finally {
             redisUtil.releaseLock(lockKey);
@@ -234,6 +239,7 @@ public class TEExamController {
         if (param.getContent() == null) {
             throw new BusinessException("试卷结构json字符串不能为空");
         }
+        ExamRecordCacheUtil.setClientCurrentIp(param.getRecordId(), IpUtil.getRemoteIp(ServletUtil.getRequest()));
         return ResultUtil
                 .ok(teExamService.studentPaperStruct(teStudent.getId(), param.getRecordId(), param.getContent()));
     }
@@ -277,6 +283,7 @@ public class TEExamController {
         AnswerSubmitBean ret = teExamService
                 .answerSubmit(teStudent.getId(), param.getRecordId(), param.getMainNumber(), param.getSubNumber(),
                         param.getSubIndex(), param.getAnswer(), param.getVersion(), param.getDurationSeconds());
+        ExamRecordCacheUtil.setClientCurrentIp(param.getRecordId(), IpUtil.getRemoteIp(ServletUtil.getRequest()));
         return ResultUtil.ok(ret);
         //        return ResultUtil.ok(true);
     }
@@ -295,6 +302,7 @@ public class TEExamController {
         if (param.getCount() == null) {
             throw new BusinessException("剩余播放次数不能为空");
         }
+        ExamRecordCacheUtil.setClientCurrentIp(param.getRecordId(), IpUtil.getRemoteIp(ServletUtil.getRequest()));
         return ResultUtil.ok(teExamService
                 .audioLeftPlayCountSubmit(teStudent.getId(), param.getRecordId(), param.getKey(), param.getCount()));
     }
@@ -307,6 +315,7 @@ public class TEExamController {
                              @ApiParam(value = "后缀名", required = true) @RequestParam String suffix,
                              @ApiParam(value = "md5", required = true) @RequestParam String md5) {
         TEStudentCacheDto teStudent = (TEStudentCacheDto) ServletUtil.getRequestStudentAccount();
+        ExamRecordCacheUtil.setClientCurrentIp(recordId, IpUtil.getRemoteIp(ServletUtil.getRequest()));
         return ResultUtil.ok(teExamService.fileUpload(teStudent.getId(), recordId, file, suffix, md5));
     }
 
@@ -324,6 +333,7 @@ public class TEExamController {
             if (Objects.isNull(param.getRecordId()) || Objects.equals(param.getRecordId(), "")) {
                 throw new BusinessException(ExceptionResultEnum.RECORD_ID_IS_NULL);
             }
+            ExamRecordCacheUtil.setClientCurrentIp(param.getRecordId(), IpUtil.getRemoteIp(ServletUtil.getRequest()));
             return ResultUtil.ok(teExamService.resume(teStudent.getId(), param.getRecordId()));
         } finally {
             redisUtil.releaseLock(lockKey);
@@ -350,6 +360,7 @@ public class TEExamController {
             if (param.getDurationSeconds() == null) {
                 throw new BusinessException("总用时秒数不能为空");
             }
+            ExamRecordCacheUtil.setClientCurrentIp(param.getRecordId(), IpUtil.getRemoteIp(ServletUtil.getRequest()));
             return ResultUtil.ok(teExamService
                     .finish(teStudent.getId(), param.getRecordId(), param.getType(), param.getDurationSeconds()));
         } finally {
@@ -379,6 +390,7 @@ public class TEExamController {
                         .equals(ExamRecordStatusEnum.RESUME_PREPARE, examRecordStatusEnum))) {
             throw new BusinessException(ExceptionResultEnum.EXAM_STATUS_ERROR);
         }
+        ExamRecordCacheUtil.setClientCurrentIp(param.getRecordId(), IpUtil.getRemoteIp(ServletUtil.getRequest()));
         return ResultUtil.ok(teExamService.result(param.getRecordId()));
     }
 
@@ -400,6 +412,7 @@ public class TEExamController {
                         .equals(ExamRecordStatusEnum.RESUME_PREPARE, examRecordStatusEnum))) {
             throw new BusinessException(ExceptionResultEnum.EXAM_STATUS_ERROR);
         }
+        ExamRecordCacheUtil.setClientCurrentIp(param.getRecordId(), IpUtil.getRemoteIp(ServletUtil.getRequest()));
         return ResultUtil.ok(teExamService.paperDownload(param.getRecordId()));
     }
 
@@ -428,6 +441,7 @@ public class TEExamController {
             ExamRecordCacheUtil.setPaperDownload(param.getRecordId(), 0);
             tOeExamRecordService.sendExamRecordDataSaveMq(param.getRecordId(), System.currentTimeMillis());
         }
+        ExamRecordCacheUtil.setClientCurrentIp(param.getRecordId(), IpUtil.getRemoteIp(ServletUtil.getRequest()));
         return ResultUtil.ok(Collections.singletonMap(SystemConstant.UPDATE_TIME, System.currentTimeMillis()));
     }
 
@@ -445,6 +459,7 @@ public class TEExamController {
         if (Objects.isNull(examRecordStatusEnum)) {
             examRecordStatusEnum = Objects.isNull(examRecordStatusEnum) ? SystemConstant.getExamStatus(param.getRecordId()) : examRecordStatusEnum;
         }
+        ExamRecordCacheUtil.setClientCurrentIp(param.getRecordId(), IpUtil.getRemoteIp(ServletUtil.getRequest()));
         return ResultUtil.ok(Collections.singletonMap(SystemConstant.STATUS, examRecordStatusEnum));
     }
 }

+ 6 - 1
themis-exam/src/main/java/com/qmth/themis/exam/api/TEFaceController.java

@@ -2,14 +2,17 @@ package com.qmth.themis.exam.api;
 
 import com.qmth.themis.business.bean.exam.FaceVerifyBean;
 import com.qmth.themis.business.bean.exam.FaceVerifyParamBean;
+import com.qmth.themis.business.cache.ExamRecordCacheUtil;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.MqDto;
 import com.qmth.themis.business.enums.MqTagEnum;
 import com.qmth.themis.business.service.MqDtoService;
 import com.qmth.themis.business.service.TOeFaceVerifyHistoryService;
 import com.qmth.themis.business.util.MqUtil;
+import com.qmth.themis.business.util.ServletUtil;
 import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.exception.BusinessException;
+import com.qmth.themis.common.util.IpUtil;
 import com.qmth.themis.common.util.Result;
 import com.qmth.themis.common.util.ResultUtil;
 import io.swagger.annotations.Api;
@@ -88,8 +91,10 @@ public class TEFaceController {
         transMap.put("realness", param.getRealness());
         transMap.put(SystemConstant.HEADER_TIME, param.getTime());
         transMap.put("exception", param.getException());
+        String ip = IpUtil.getRemoteIp(ServletUtil.getRequest());
+        ExamRecordCacheUtil.setClientCurrentIp(param.getRecordId(), ip);
         //mq发送消息start
-        MqDto mqDto = new MqDto(mqUtil.getTopic(), MqTagEnum.FACE_VERIFY_SAVE.name(), transMap, MqTagEnum.FACE_VERIFY_SAVE, param.getRecordId().toString(), param.getRecordId().toString());
+        MqDto mqDto = new MqDto(mqUtil.getTopic(), MqTagEnum.FACE_VERIFY_SAVE.name(), transMap, MqTagEnum.FACE_VERIFY_SAVE, param.getRecordId().toString(), ip);
         mqDtoService.assembleSendOneWayMsg(mqDto);
         return ResultUtil.ok(ret);
     }

+ 6 - 1
themis-exam/src/main/java/com/qmth/themis/exam/api/TELivenessController.java

@@ -2,14 +2,17 @@ package com.qmth.themis.exam.api;
 
 import com.qmth.themis.business.bean.exam.LivenessVerifyBean;
 import com.qmth.themis.business.bean.exam.LivenessVerifyParamBean;
+import com.qmth.themis.business.cache.ExamRecordCacheUtil;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.MqDto;
 import com.qmth.themis.business.enums.MqTagEnum;
 import com.qmth.themis.business.service.MqDtoService;
 import com.qmth.themis.business.service.TOeLivenessVerifyHistoryService;
 import com.qmth.themis.business.util.MqUtil;
+import com.qmth.themis.business.util.ServletUtil;
 import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.exception.BusinessException;
+import com.qmth.themis.common.util.IpUtil;
 import com.qmth.themis.common.util.Result;
 import com.qmth.themis.common.util.ResultUtil;
 import io.swagger.annotations.Api;
@@ -86,9 +89,11 @@ public class TELivenessController {
         transMap.put("startTime", param.getStartTime());
         transMap.put("finishTime", param.getFinishTime());
         transMap.put("exception", param.getException());
+        String ip = IpUtil.getRemoteIp(ServletUtil.getRequest());
+        ExamRecordCacheUtil.setClientCurrentIp(param.getRecordId(), ip);
         // mq发送消息start
         MqDto mqDto = new MqDto(mqUtil.getTopic(), MqTagEnum.LIVENESS_VERIFY_SAVE.name(), transMap,
-                MqTagEnum.LIVENESS_VERIFY_SAVE, param.getRecordId().toString(), param.getRecordId().toString());
+                MqTagEnum.LIVENESS_VERIFY_SAVE, param.getRecordId().toString(), ip);
         mqDtoService.assembleSendOneWayMsg(mqDto);
         return ResultUtil.ok(ret);
     }

+ 5 - 2
themis-exam/src/main/java/com/qmth/themis/exam/api/TEStudentController.java

@@ -1,5 +1,6 @@
 package com.qmth.themis.exam.api;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.qmth.themis.business.annotation.ApiJsonObject;
 import com.qmth.themis.business.annotation.ApiJsonProperty;
@@ -35,6 +36,7 @@ import com.qmth.themis.common.enums.Platform;
 import com.qmth.themis.common.enums.Source;
 import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.util.GsonUtil;
+import com.qmth.themis.common.util.IpUtil;
 import com.qmth.themis.common.util.Result;
 import com.qmth.themis.common.util.ResultUtil;
 import com.qmth.themis.exam.config.ExamConstant;
@@ -228,9 +230,10 @@ public class TEStudentController {
         MqDto mqDto = new MqDto(mqUtil.getTopic(), platform.name(), SystemOperationEnum.SESSION,
                 sessionId);
         mqDtoService.assembleSendOneWayMsg(mqDto);
+
         MqDto mqDtoLog = new MqDto(mqUtil.getTopic(), MqTagEnum.STUDENT.name(),
                 SystemOperationEnum.LOGIN, MqTagEnum.STUDENT, String.valueOf(teStudent.getId()),
-                teStudent.getIdentity());
+                IpUtil.getRemoteIp(ServletUtil.getRequest()));
         mqDtoService.assembleSendOneWayMsg(mqDtoLog);
         //mq发送消息end
         //测试
@@ -316,7 +319,7 @@ public class TEStudentController {
         //mq发送消息start
         MqDto mqDto = new MqDto(mqUtil.getTopic(), MqTagEnum.STUDENT.name(),
                 SystemOperationEnum.LOGOUT, MqTagEnum.STUDENT, String.valueOf(teStudent.getId()),
-                teStudent.getIdentity());
+                IpUtil.getRemoteIp(ServletUtil.getRequest()));
         mqDtoService.assembleSendOneWayMsg(mqDto);
         //mq发送消息end
         return ResultUtil.ok(true);

+ 33 - 3
themis-exam/src/main/java/com/qmth/themis/exam/listener/service/impl/MqOeLogicServiceImpl.java

@@ -90,7 +90,17 @@ public class MqOeLogicServiceImpl implements MqOeLogicService {
                 map.put(SystemConstant.WEB_SOCKET_OE_SERVER, webSocketOeServer);
                 map.put(SystemConstant.RECORD_ID, recordId);
                 map.put(SystemConstant.MESSAGE, FinishTypeEnum.valueOf(String.valueOf(mqDto.getProperties().get(SystemConstant.TYPE))).getCode());
-                TEExamStudentLog teExamStudentLog = new TEExamStudentLog(mqDto.getType().name(), "监考老师[" + mqDto.getObjName() + "]强制离线(交卷)", mqDto.getType().getCode(), examStudentCacheBean.getStudentId(), examStudentId, recordId, mqDto.getType().getCode());
+
+                String ip = ExamRecordCacheUtil.getClientCurrentIp(recordId), country = null, region = null, province = null, city = null, isp = null;
+                String[] strs = SystemConstant.getIpInfo(ip);
+                if (Objects.nonNull(strs) && strs.length > 0) {
+                    country = strs[0];
+                    region = strs[1];
+                    province = strs[2];
+                    city = strs[3];
+                    isp = strs[4];
+                }
+                TEExamStudentLog teExamStudentLog = new TEExamStudentLog(mqDto.getType().name(), "监考老师[" + mqDto.getObjName() + "]强制离线(交卷)", mqDto.getType().getCode(), examStudentCacheBean.getStudentId(), examStudentId, recordId, mqDto.getType().getCode(), ip, country, region, province, city, isp);
                 teExamStudentLogService.save(teExamStudentLog);
 
                 tmRocketMessageService.saveMqMessageSuccess(mqDto, key);
@@ -131,7 +141,17 @@ public class MqOeLogicServiceImpl implements MqOeLogicService {
                 map.put(SystemConstant.WEB_SOCKET_OE_SERVER, webSocketOeServer);
                 map.put(SystemConstant.RECORD_ID, recordId);
                 map.put(SystemConstant.BREACH_STATUS, FinishTypeEnum.valueOf(String.valueOf(mqDto.getProperties().get(SystemConstant.TYPE))).getCode());
-                TEExamStudentLog teExamStudentLog = new TEExamStudentLog(mqDto.getType().name(), mqDto.getType().getCode(), mqDto.getType().getCode(), examStudentCacheBean.getStudentId(), examStudentId, recordId, mqDto.getType().getCode());
+
+                String ip = ExamRecordCacheUtil.getClientCurrentIp(recordId), country = null, region = null, province = null, city = null, isp = null;
+                String[] strs = SystemConstant.getIpInfo(ip);
+                if (Objects.nonNull(strs) && strs.length > 0) {
+                    country = strs[0];
+                    region = strs[1];
+                    province = strs[2];
+                    city = strs[3];
+                    isp = strs[4];
+                }
+                TEExamStudentLog teExamStudentLog = new TEExamStudentLog(mqDto.getType().name(), mqDto.getType().getCode(), mqDto.getType().getCode(), examStudentCacheBean.getStudentId(), examStudentId, recordId, mqDto.getType().getCode(), ip, country, region, province, city, isp);
                 teExamStudentLogService.save(teExamStudentLog);
 
                 tmRocketMessageService.saveMqMessageSuccess(mqDto, key);
@@ -212,7 +232,17 @@ public class MqOeLogicServiceImpl implements MqOeLogicService {
                     && webSocketOeServer.getRecordId().longValue() == recordId.longValue()) {
                 map.put(SystemConstant.RECORD_ID, recordId);
                 map.put(SystemConstant.WEB_SOCKET_OE_SERVER, webSocketOeServer);
-                TEExamStudentLog teExamStudentLog = new TEExamStudentLog(mqDto.getType().name(), mqDto.getType().getCode(), mqDto.getType().getCode(), examStudentCacheBean.getStudentId(), examStudentId, recordId, mqDto.getType().getCode());
+
+                String ip = ExamRecordCacheUtil.getClientCurrentIp(recordId), country = null, region = null, province = null, city = null, isp = null;
+                String[] strs = SystemConstant.getIpInfo(ip);
+                if (Objects.nonNull(strs) && strs.length > 0) {
+                    country = strs[0];
+                    region = strs[1];
+                    province = strs[2];
+                    city = strs[3];
+                    isp = strs[4];
+                }
+                TEExamStudentLog teExamStudentLog = new TEExamStudentLog(mqDto.getType().name(), mqDto.getType().getCode(), mqDto.getType().getCode(), examStudentCacheBean.getStudentId(), examStudentId, recordId, mqDto.getType().getCode(), ip, country, region, province, city, isp);
                 teExamStudentLogService.save(teExamStudentLog);
 
                 tmRocketMessageService.saveMqMessageSuccess(mqDto, key);

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

@@ -17,6 +17,7 @@ import org.springframework.boot.CommandLineRunner;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
+import java.io.File;
 
 /**
  * @Description: 服务启动时初始化运行,哪个微服务模块需要则拿此模版去用
@@ -38,6 +39,9 @@ public class StartRunning implements CommandLineRunner {
     @Resource
     MqUtil mqUtil;
 
+    @Value("${spring.application.name}")
+    String applicationName;
+
     @Override
     public void run(String... args) throws Exception {
         log.info("服务器启动时执行 start");
@@ -48,6 +52,7 @@ public class StartRunning implements CommandLineRunner {
 //        rocketMessageConsumer.setRocketMQConsumer(nameServer, dictionaryConfig.mqConfigDomain().getMap().get(MqGroupEnum.WEBSOCKET_OE_MOBILE_GROUP.name()), dictionaryConfig.mqConfigDomain().getTopic(), MqTagEnum.EXAM_STOP.name() + "||" + MqTagEnum.EXAM_START.name() + "||" + MqTagEnum.EXAM_AUDIO_MOBILE.name(), MessageModel.BROADCASTING, SpringContextHolder.getBean(WebSocketMobileServer.class));
         rocketMessageConsumer.setRocketMQConsumer(nameServer, mqUtil.getMap().get(MqGroupEnum.WEBSOCKET_OE_MOBILE_GROUP.name()), mqUtil.getTopic(), MqTagEnum.EXAM_STOP.name() + "||" + MqTagEnum.EXAM_START.name(), MessageModel.BROADCASTING, SpringContextHolder.getBean(WebSocketMobileServer.class));
         SystemConstant.initTempFiles();
+        SystemConstant.getSearcher(SystemConstant.TEMP_FILES_DIR + File.separator + applicationName);
         log.info("服务器启动时执行 end");
     }
 }

+ 69 - 13
themis-mq/src/main/java/com/qmth/themis/mq/service/impl/MqLogicServiceImpl.java

@@ -162,7 +162,18 @@ public class MqLogicServiceImpl implements MqLogicService {
             teUserLogService.save(teUserLog);
         } else if (Objects.equals(MqTagEnum.STUDENT.name(), tag)) {
             TEExamStudentLog teExamStudentLog = null;
+            String ip = null, country = null, region = null, province = null, city = null, isp = null;
             if (Objects.nonNull(mqDto.getProperties())) {
+                Long recordId = Long.parseLong(String.valueOf(mqDto.getProperties().get(SystemConstant.EXAM_RECORD_ID)));
+                ip = Objects.nonNull(recordId) ? ExamRecordCacheUtil.getClientCurrentIp(recordId) : mqDto.getObjName();
+                String[] strs = SystemConstant.getIpInfo(ip);
+                if (Objects.nonNull(strs) && strs.length > 0) {
+                    country = strs[0];
+                    region = strs[1];
+                    province = strs[2];
+                    city = strs[3];
+                    isp = strs[4];
+                }
                 String type = Objects.nonNull(mqDto.getProperties().get(SystemConstant.TYPE)) ?
                         String.valueOf(mqDto.getProperties().get(SystemConstant.TYPE)) :
                         SystemOperationEnum.valueOf(String.valueOf(mqDto.getBody())).getCode();
@@ -201,17 +212,29 @@ public class MqLogicServiceImpl implements MqLogicService {
                 teExamStudentLog = new TEExamStudentLog(String.valueOf(mqDto.getBody()), info, remark,
                         Long.parseLong(String.valueOf(mqDto.getObjId())),
                         Long.parseLong(String.valueOf(mqDto.getProperties().get(SystemConstant.EXAM_STUDENT_ID))),
-                        Long.parseLong(String.valueOf(mqDto.getProperties().get(SystemConstant.EXAM_RECORD_ID))),
-                        title);
+                        recordId, title, ip, country, region, province, city, isp);
                 teExamStudentLog.setObjId(objId);
             } else {
+                if (Objects.nonNull(mqDto.getObjName())) {
+                    ip = mqDto.getObjName();
+                    String[] strs = SystemConstant.getIpInfo(ip);
+                    if (Objects.nonNull(strs) && strs.length > 0) {
+                        country = strs[0];
+                        region = strs[1];
+                        province = strs[2];
+                        city = strs[3];
+                        isp = strs[4];
+                    }
+                }
                 teExamStudentLog = new TEExamStudentLog(String.valueOf(mqDto.getBody()),
                         SystemOperationEnum.valueOf(String.valueOf(mqDto.getBody())).getCode(),
                         SystemOperationEnum.valueOf(String.valueOf(mqDto.getBody())).getCode(),
-                        Long.parseLong(String.valueOf(mqDto.getObjId())));
+                        Long.parseLong(String.valueOf(mqDto.getObjId())), ip, country, region, province, city, isp);
                 SystemOperationEnum systemOperationEnum = SystemOperationEnum.valueOf(String.valueOf(mqDto.getBody()));
-                if (systemOperationEnum == SystemOperationEnum.LOGOUT && Objects.nonNull(mqDto.getObjName())) {
-                    tbSessionService.removeById(mqDto.getObjName());
+                if (systemOperationEnum == SystemOperationEnum.LOGOUT && Objects.nonNull(mqDto.getObjId())) {
+                    QueryWrapper<TBSession> tbSessionQueryWrapper = new QueryWrapper<>();
+                    tbSessionQueryWrapper.lambda().eq(TBSession::getIdentity, String.valueOf(mqDto.getObjId()));
+                    tbSessionService.remove(tbSessionQueryWrapper);
                 }
             }
             teExamStudentLogService.save(teExamStudentLog);
@@ -436,18 +459,28 @@ public class MqLogicServiceImpl implements MqLogicService {
             TOeExamRecord tOeExamRecord = SystemConstant.getExamRecord(recordId);
             examStudentId = tOeExamRecord.getExamStudentId();
         }
+        String ip = null, country = null, region = null, province = null, city = null, isp = null;
+        ip = Objects.nonNull(recordId) ? ExamRecordCacheUtil.getClientCurrentIp(recordId) : mqDto.getObjName();
+        String[] strs = SystemConstant.getIpInfo(ip);
+        if (Objects.nonNull(strs) && strs.length > 0) {
+            country = strs[0];
+            region = strs[1];
+            province = strs[2];
+            city = strs[3];
+            isp = strs[4];
+        }
         ExamStudentCacheBean examStudentCacheBean = teExamStudentService.getExamStudentCacheBean(examStudentId);
         if (Objects.nonNull(photoUrl) && (Objects.equals(type.toUpperCase(), ExamTypeEnum.FIRST_START.name()) || Objects.equals(type.toUpperCase(), ExamTypeEnum.RESUME_START.name()))) {
             JSONObject jsonObject = new JSONObject();
             jsonObject.put(PhotoTypeEnum.FACE_VERIFY_PHOTO.name(), photoUrl);
             TEExamStudentLog teExamStudentLog = new TEExamStudentLog(type, ExamTypeEnum.valueOf(type).getCode(),
                     jsonObject.toJSONString(), examStudentCacheBean.getStudentId(), examStudentCacheBean.getId(),
-                    recordId, ExamTypeEnum.valueOf(type).getTitle());
+                    recordId, ExamTypeEnum.valueOf(type).getTitle(), ip, country, region, province, city, isp);
             faceVerifyHistoryService.save(id, recordId, type, photoUrl, faceCount, similarity, realness, time, exception, null);
             teExamStudentLogService.saveOrUpdate(teExamStudentLog);
         } else if (Objects.equals(type.toUpperCase(), ExamTypeEnum.IN_PROCESS.name())) {
             VerifyExceptionEnum warningEnum = VerifyExceptionEnum.valueOf(exception);
-            WarningDto warningDto = new WarningDto(warningEnum, faceCount, realness, recordId, photoUrl);
+            WarningDto warningDto = new WarningDto(warningEnum, faceCount, realness, recordId, photoUrl, ip, country, region, province, city, isp);
             if (Objects.equals(VerifyExceptionEnum.NONE, warningEnum)) {//无异常,往考生日志表里插一条
                 if (Objects.nonNull(realness) && realness.intValue() == 0) {//真实性异常
                     String realnessErrorRandom = ExamRecordCacheUtil.getRealnessErrorRandom(recordId);
@@ -556,6 +589,16 @@ public class MqLogicServiceImpl implements MqLogicService {
         Long startTime = (Long) param.get("startTime");
         Long finishTime = (Long) param.get("finishTime");
         String exception = (String) param.get("exception");
+        String ip = null, country = null, region = null, province = null, city = null, isp = null;
+        ip = Objects.nonNull(recordId) ? ExamRecordCacheUtil.getClientCurrentIp(recordId) : mqDto.getObjName();
+        String[] strs = SystemConstant.getIpInfo(ip);
+        if (Objects.nonNull(strs) && strs.length > 0) {
+            country = strs[0];
+            region = strs[1];
+            province = strs[2];
+            city = strs[3];
+            isp = strs[4];
+        }
         Long examStudentId = ExamRecordCacheUtil.getExamStudentId(recordId);
         if (Objects.isNull(examStudentId)) {
             TOeExamRecord tOeExamRecord = SystemConstant.getExamRecord(recordId);
@@ -574,7 +617,7 @@ public class MqLogicServiceImpl implements MqLogicService {
                     TEExamStudentLog teExamStudentLog = new TEExamStudentLog(type,
                             LivenessTypeEnum.valueOf(type).getCode(), object.toJSONString(),
                             examStudentCacheBean.getStudentId(), examStudentCacheBean.getId(), recordId,
-                            LivenessTypeEnum.valueOf(type).getTitle());
+                            LivenessTypeEnum.valueOf(type).getTitle(), ip, country, region, province, city, isp);
                     livenessVerifyHistoryService.save(id, recordId, type, actions, retry, startTime, finishTime, exception, null);
                     teExamStudentLogService.saveOrUpdate(teExamStudentLog);
                     break;
@@ -590,7 +633,7 @@ public class MqLogicServiceImpl implements MqLogicService {
                     livenessActionErrorRandom = SystemConstant.getNanoId();
                     ExamRecordCacheUtil.setLivenessActionErrorRandom(recordId, livenessActionErrorRandom);
                 }
-                WarningDto warningDto = new WarningDto(warningEnum, null, null, recordId, null);
+                WarningDto warningDto = new WarningDto(warningEnum, null, null, recordId, null, ip, country, region, province, city, isp);
                 warningDto.setRandom(livenessActionErrorRandom);
                 livenessVerifyHistoryService.save(id, recordId, type, actions, retry, startTime, finishTime, exception, livenessActionErrorRandom);
                 ExamRecordCacheUtil.setLivenessActionErrorRandom(recordId, SystemConstant.getNanoId());
@@ -724,13 +767,14 @@ public class MqLogicServiceImpl implements MqLogicService {
             ExceptionEnum exceptionEnum = ExceptionEnum.valueOf(
                     ExceptionEnum.convertToName(String.valueOf(jsonObject.getJSONObject("reason").get(SystemConstant.TYPE))));
             Long recordId = Long.parseLong(mqDto.getObjId());
+            Long lastPrepareTime = ExamRecordCacheUtil.getLastPrepareTime(recordId);
             Long breakId = ExamRecordCacheUtil.getLastBreakId(recordId);
             if (Objects.nonNull(breakId)) {
                 //获取断点时间
                 Long lastBreakTime = ExamRecordCacheUtil.getLastBreakTime(recordId);
                 Integer diff = 0;
                 if (Objects.nonNull(lastBreakTime)) {
-                    Long l = ((System.currentTimeMillis() - lastBreakTime) / 1000);
+                    Long l = ((lastPrepareTime - lastBreakTime) / 1000);
                     diff = l.intValue();
                 }
 
@@ -740,7 +784,7 @@ public class MqLogicServiceImpl implements MqLogicService {
                 tIeInvigilateExceptionInfoUpdateWrapper.lambda().set(TIeInvigilateExceptionInfo::getInfo, reason)
                         .set(TIeInvigilateExceptionInfo::getType, exceptionEnum)
                         .set(TIeInvigilateExceptionInfo::getDifference, diff)
-                        .set(TIeInvigilateExceptionInfo::getUpdateTime, System.currentTimeMillis())
+                        .set(TIeInvigilateExceptionInfo::getUpdateTime, lastPrepareTime)
                         .eq(TIeInvigilateExceptionInfo::getObjId, breakId);
                 tIeInvigilateExceptionInfoService.update(tIeInvigilateExceptionInfoUpdateWrapper);
 
@@ -749,7 +793,7 @@ public class MqLogicServiceImpl implements MqLogicService {
                 teExamStudentLogUpdateWrapper.lambda().set(TEExamStudentLog::getType, exceptionEnum.name())
                         .set(TEExamStudentLog::getInfo, exceptionEnum.getCode())
                         .set(TEExamStudentLog::getRemark, reason)
-                        .set(TEExamStudentLog::getUpdateTime, System.currentTimeMillis())
+                        .set(TEExamStudentLog::getUpdateTime, lastPrepareTime)
                         .eq(TEExamStudentLog::getObjId, breakId);
                 teExamStudentLogService.update(teExamStudentLogUpdateWrapper);
             }
@@ -844,10 +888,22 @@ public class MqLogicServiceImpl implements MqLogicService {
         //            tIeInvigilateExceptionInfo.setUpdateTime(startTime);
         //        }
         tIeInvigilateExceptionInfoService.saveOrUpdate(tIeInvigilateExceptionInfo);
+
+        String ip = ExamRecordCacheUtil.getClientCurrentIp(recordId), country = null, region = null, province = null, city = null, isp = null;
+        String[] strs = SystemConstant.getIpInfo(ip);
+        if (Objects.nonNull(strs) && strs.length > 0) {
+            country = strs[0];
+            region = strs[1];
+            province = strs[2];
+            city = strs[3];
+            isp = strs[4];
+        }
+
         TEExamStudentLog teExamStudentLog = new TEExamStudentLog(SystemOperationEnum.BREAK_OFF.name(),
                 SystemOperationEnum.BREAK_OFF.getCode(), SystemOperationEnum.BREAK_OFF.getCode(),
                 examStudentCacheBean.getStudentId(), examStudentId, recordId,
-                ExamRecordCacheUtil.getLastBreakId(recordId), SystemOperationEnum.BREAK_OFF.getTitle());
+                ExamRecordCacheUtil.getLastBreakId(recordId), SystemOperationEnum.BREAK_OFF.getTitle(),
+                ip, country, region, province, city, isp);
         teExamStudentLogService.save(teExamStudentLog);
 
         SystemConstant.clientMonitorStatusStop(recordId);