wangliang 4 жил өмнө
parent
commit
aaf88c3397

+ 11 - 10
themis-business/src/main/java/com/qmth/themis/business/cache/ExamRecordCacheUtil.java

@@ -10,6 +10,7 @@ import com.qmth.themis.business.service.TOeExamRecordService;
 import com.qmth.themis.business.util.RedisUtil;
 
 import java.util.Objects;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * 考试记录缓存hash值操作
@@ -652,24 +653,24 @@ public class ExamRecordCacheUtil {
         return (String) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "realnessErrorRandom");
     }
 
-    public static Integer getMultipleFaceCountErrorNum(Long recordId) {
-        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "multipleFaceCountErrorNum")) ? (Integer) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "multipleFaceCountErrorNum") : 0;
+    public static AtomicInteger getMultipleFaceCountErrorNum(Long recordId) {
+        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "multipleFaceCountErrorNum")) ? new AtomicInteger((Integer) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "multipleFaceCountErrorNum")) : new AtomicInteger(0);
     }
 
-    public static Integer getNoFaceCountErrorNum(Long recordId) {
-        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "noFaceCountErrorNum")) ? (Integer) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "noFaceCountErrorNum") : 0;
+    public static AtomicInteger getNoFaceCountErrorNum(Long recordId) {
+        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "noFaceCountErrorNum")) ? new AtomicInteger((Integer) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "noFaceCountErrorNum")) : new AtomicInteger(0);
     }
 
-    public static Integer getFaceCompareErrorNum(Long recordId) {
-        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "faceCompareErrorNum")) ? (Integer) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "faceCompareErrorNum") : 0;
+    public static AtomicInteger getFaceCompareErrorNum(Long recordId) {
+        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "faceCompareErrorNum")) ? new AtomicInteger((Integer) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "faceCompareErrorNum")) : new AtomicInteger(0);
     }
 
-    public static Integer getEyeCloseErrorNum(Long recordId) {
-        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "eyeCloseErrorNum")) ? (Integer) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "eyeCloseErrorNum") : 0;
+    public static AtomicInteger getEyeCloseErrorNum(Long recordId) {
+        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "eyeCloseErrorNum")) ? new AtomicInteger((Integer) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "eyeCloseErrorNum")) : new AtomicInteger(0);
     }
 
-    public static Integer getRealnessErrorNum(Long recordId) {
-        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "realnessErrorNum")) ? (Integer) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "realnessErrorNum") : 0;
+    public static AtomicInteger getRealnessErrorNum(Long recordId) {
+        return Objects.nonNull(redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "realnessErrorNum")) ? new AtomicInteger((Integer) redisUtil.get(RedisKeyHelper.examRecordCacheKey(recordId), "realnessErrorNum")) : new AtomicInteger(0);
     }
 
     public static Integer getHasAnswerFile(Long recordId) {

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

@@ -18,6 +18,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * @Description: 预警规则公用
@@ -229,4 +230,13 @@ public class WarningServiceImpl implements WarningService {
         TEExamStudentLog teExamStudentLog = new TEExamStudentLog(tIeInvigilateWarnInfo.getType().name(), WarningLevelEnum.valueOf(tIeInvigilateWarnInfo.getLevel()).getTitle(), jsonObject.toJSONString(), examStudentCacheBean.getStudentId(), examStudentCacheBean.getId(), recordId, WarningLevelEnum.valueOf(tIeInvigilateWarnInfo.getLevel()).getSecondTitle());
         teExamStudentLogService.saveOrUpdate(teExamStudentLog);
     }
+
+    public static void main(String[] args){
+        AtomicInteger atomicInteger = new AtomicInteger(0);
+        atomicInteger.incrementAndGet();
+        System.out.println(atomicInteger.get());
+        AtomicInteger atomicInteger1 = new AtomicInteger(0);
+        atomicInteger1.getAndIncrement();
+        System.out.println(atomicInteger1.get());
+    }
 }

+ 33 - 33
themis-business/src/main/java/com/qmth/themis/business/util/AuthUtil.java

@@ -127,45 +127,45 @@ public class AuthUtil {
                                     String method,
                                     String url) {
         RedisUtil redisUtil = SpringContextHolder.getBean(RedisUtil.class);
-//        if (SystemConstant.expire(time)) {
-//            log.warn("Authorization faile: time expired, server time=" + System.currentTimeMillis());
-//            throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
-//        }
+        if (SystemConstant.expire(time)) {
+            log.warn("Authorization faile: time expired, server time=" + System.currentTimeMillis());
+            throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
+        }
         //测试
 //        final SignatureInfo info = SignatureInfo.parse(authorization);
         //校验签名信息
         final SignatureInfo info = SignatureInfo.parse(method.toLowerCase(), url, time, authorization);
-//        if (info == null) {
-//            log.warn("Authorization faile: signature decode error");
-//            throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
-//        }
-//        if (SignatureType.TOKEN != info.getType()) {
-//            log.warn("Authorization faile: signature type is not Token");
-//            throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
-//        }
-//        //校验session
+        if (info == null) {
+            log.warn("Authorization faile: signature decode error");
+            throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
+        }
+        if (SignatureType.TOKEN != info.getType()) {
+            log.warn("Authorization faile: signature type is not Token");
+            throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
+        }
+        //校验session
         String sessionId = info.getInvoker();
         TBSession tbSession = (TBSession) redisUtil.getUserSession(sessionId);
-//        if (Objects.isNull(tbSession)) {
-//            log.warn("Authorization faile: session id not exists: " + sessionId);
-//            throw new BusinessException(ExceptionResultEnum.LOGIN_NO);
-//        }
-//        if (tbSession.getExpireTime() <= System.currentTimeMillis() || info.getTimestamp() > tbSession.getExpireTime()) {
-//            log.warn("Authorization faile: session has expired, expire time=" + tbSession.getExpireTime());
-//            throw new BusinessException(ExceptionResultEnum.LOGIN_NO);
-//        }
-//        if (!info.validate(tbSession.getAccessToken())) {
-//            log.warn("Authorization faile: access token invalid, session token is " + tbSession.getAccessToken());
-//            throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
-//        }
-//        if (!tbSession.getPlatform().equalsIgnoreCase(platform.name())) {
-//            log.warn("Authorization faile: platform invalid, session platform is " + tbSession.getPlatform());
-//            throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
-//        }
-//        if (!tbSession.getDeviceId().equalsIgnoreCase(deviceId)) {
-//            log.warn("Authorization faile: deviceId invalid, session deviceId is " + tbSession.getDeviceId());
-//            throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
-//        }
+        if (Objects.isNull(tbSession)) {
+            log.warn("Authorization faile: session id not exists: " + sessionId);
+            throw new BusinessException(ExceptionResultEnum.LOGIN_NO);
+        }
+        if (tbSession.getExpireTime() <= System.currentTimeMillis() || info.getTimestamp() > tbSession.getExpireTime()) {
+            log.warn("Authorization faile: session has expired, expire time=" + tbSession.getExpireTime());
+            throw new BusinessException(ExceptionResultEnum.LOGIN_NO);
+        }
+        if (!info.validate(tbSession.getAccessToken())) {
+            log.warn("Authorization faile: access token invalid, session token is " + tbSession.getAccessToken());
+            throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
+        }
+        if (!tbSession.getPlatform().equalsIgnoreCase(platform.name())) {
+            log.warn("Authorization faile: platform invalid, session platform is " + tbSession.getPlatform());
+            throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
+        }
+        if (!tbSession.getDeviceId().equalsIgnoreCase(deviceId)) {
+            log.warn("Authorization faile: deviceId invalid, session deviceId is " + tbSession.getDeviceId());
+            throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
+        }
         return tbSession;
     }