Răsfoiți Sursa

加入交卷逻辑

wangliang 4 ani în urmă
părinte
comite
6ec79f4b76

+ 77 - 0
themis-business/src/main/java/com/qmth/themis/business/dto/cache/TEStudentCacheDto.java

@@ -0,0 +1,77 @@
+package com.qmth.themis.business.dto.cache;
+
+import java.io.Serializable;
+
+/** 
+* @Description: 学生缓存 dto
+* @Param:  
+* @return:  
+* @Author: wangliang
+* @Date: 2020/8/4 
+*/ 
+public class TEStudentCacheDto implements Serializable {
+
+    private Long id;
+    private Long orgId;
+    private String identity;
+    private String name;
+    private String basePhotoPath;
+    private Long examingRecordId;
+    private Long unFinishedRecordId;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getOrgId() {
+        return orgId;
+    }
+
+    public void setOrgId(Long orgId) {
+        this.orgId = orgId;
+    }
+
+    public String getIdentity() {
+        return identity;
+    }
+
+    public void setIdentity(String identity) {
+        this.identity = identity;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getBasePhotoPath() {
+        return basePhotoPath;
+    }
+
+    public void setBasePhotoPath(String basePhotoPath) {
+        this.basePhotoPath = basePhotoPath;
+    }
+
+    public Long getExamingRecordId() {
+        return examingRecordId;
+    }
+
+    public void setExamingRecordId(Long examingRecordId) {
+        this.examingRecordId = examingRecordId;
+    }
+
+    public Long getUnFinishedRecordId() {
+        return unFinishedRecordId;
+    }
+
+    public void setUnFinishedRecordId(Long unFinishedRecordId) {
+        this.unFinishedRecordId = unFinishedRecordId;
+    }
+}

+ 12 - 5
themis-business/src/main/java/com/qmth/themis/business/util/RedisUtil.java

@@ -7,6 +7,7 @@ import org.springframework.stereotype.Component;
 import javax.annotation.Resource;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
 
@@ -106,8 +107,12 @@ public class RedisUtil {
      * @param studentId
      * @param o
      */
-    public void setStudent(Long studentId, Object o) {
-        redisTemplate.opsForValue().set(SystemConstant.STUDENT + studentId, o, SystemConstant.REDIS_EXPIRE_TIME, TimeUnit.SECONDS);
+    public void setStudent(Long studentId, Object o, Long time, TimeUnit timeUnit) {
+        if (Objects.nonNull(time) && Objects.nonNull(timeUnit)) {
+            redisTemplate.opsForValue().set(SystemConstant.STUDENT + studentId, o, time, timeUnit);
+        } else {
+            redisTemplate.opsForValue().set(SystemConstant.STUDENT + studentId, o);
+        }
     }
 
     /**
@@ -277,12 +282,14 @@ public class RedisUtil {
     public void delete(String key) {
         redisTemplate.expire(key, 0, TimeUnit.SECONDS);
     }
-    
-    /**保存hash结构
+
+    /**
+     * 保存hash结构
+     *
      * @param key
      * @param map
      */
-    public void setForHash(String key,Map<String,Object> map) {
+    public void setForHash(String key, Map<String, Object> map) {
         redisTemplate.opsForHash().putAll(key, map);
     }
 }

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

@@ -1,11 +1,13 @@
 package com.qmth.themis.exam.api;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.google.gson.Gson;
 import com.qmth.themis.business.annotation.ApiJsonObject;
 import com.qmth.themis.business.annotation.ApiJsonProperty;
 import com.qmth.themis.business.cache.ExamRecordCacheUtil;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.AuthDto;
+import com.qmth.themis.business.dto.cache.TEStudentCacheDto;
 import com.qmth.themis.business.dto.response.TEExamDto;
 import com.qmth.themis.business.dto.response.TEExamResultDto;
 import com.qmth.themis.business.dto.response.TEExamUnFinishDto;
@@ -83,7 +85,7 @@ public class TEStudentController {
     public Result login(@ApiJsonObject(name = "loginAccount", value = {
             @ApiJsonProperty(key = "identity", description = "证件号"),
             @ApiJsonProperty(key = "password", description = "密码"),
-            @ApiJsonProperty(key = "orgId",type = "long",example = "1",description = "机构id")
+            @ApiJsonProperty(key = "orgId", type = "long", example = "1", description = "机构id")
     }) @ApiParam(value = "学生信息", required = true) @RequestBody Map<String, Object> mapParameter) throws NoSuchAlgorithmException {
         if (Objects.isNull(mapParameter)) {
             throw new BusinessException(ExceptionResultEnum.STUDENT_IS_NULL);
@@ -144,8 +146,13 @@ public class TEStudentController {
         AuthDto authDto = cacheService.addStudentCache(teStudent.getId());
         //生成token
         String token = RandomStringUtils.randomAlphanumeric(32);
+        TEStudentCacheDto teStudentCacheDto = (TEStudentCacheDto) redisUtil.getStudent(teStudent.getId());
+        if (Objects.isNull(teStudentCacheDto)) {
+            Gson gson = new Gson();
+            teStudentCacheDto = gson.fromJson(gson.toJson(teStudent), TEStudentCacheDto.class);
+        }
         //添加用户缓存
-        redisUtil.setStudent(teStudent.getId(), teStudent);
+        redisUtil.setStudent(teStudent.getId(), teStudentCacheDto, null, null);
         String source = null;
         if (Objects.equals(platform.name(), Platform.win.name()) || Objects.equals(platform.name(), Platform.mac.name())) {
             source = platform.getSource().split(",")[1];

+ 10 - 5
themis-exam/src/main/java/com/qmth/themis/exam/interceptor/AuthInterceptor.java

@@ -1,8 +1,10 @@
 package com.qmth.themis.exam.interceptor;
 
 import cn.hutool.http.HttpStatus;
+import com.google.gson.Gson;
 import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.AuthDto;
+import com.qmth.themis.business.dto.cache.TEStudentCacheDto;
 import com.qmth.themis.business.entity.TBSession;
 import com.qmth.themis.business.entity.TEStudent;
 import com.qmth.themis.business.enums.RoleEnum;
@@ -16,6 +18,7 @@ import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.signature.SignatureInfo;
 import com.qmth.themis.common.signature.SignatureType;
 import com.qmth.themis.exam.config.DictionaryConfig;
+import org.apache.poi.ss.formula.functions.T;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.web.servlet.HandlerInterceptor;
@@ -92,14 +95,16 @@ public class AuthInterceptor implements HandlerInterceptor {
                     if (expireTime.getTime() <= System.currentTimeMillis()) {//先判断时间是否过期
                         throw new BusinessException(ExceptionResultEnum.LOGIN_NO);
                     }
-                    TEStudent teStudent = (TEStudent) redisUtil.getStudent(userId);
-                    if (Objects.isNull(teStudent)) {
-                        teStudent = teStudentService.getById(userId);
-                        redisUtil.setStudent(teStudent.getId(), teStudent);
+                    TEStudentCacheDto teStudentCacheDto = (TEStudentCacheDto) redisUtil.getStudent(userId);
+                    if (Objects.isNull(teStudentCacheDto)) {
+                        TEStudent teStudent = teStudentService.getById(userId);
+                        Gson gson = new Gson();
+                        teStudentCacheDto = gson.fromJson(gson.toJson(teStudent), TEStudentCacheDto.class);
+                        redisUtil.setStudent(teStudent.getId(), teStudentCacheDto, null, null);
                     }
 
                     request.setAttribute(SystemConstant.SESSION, tbSession);
-                    request.setAttribute(SystemConstant.STUDENT_ACCOUNT, teStudent);
+                    request.setAttribute(SystemConstant.STUDENT_ACCOUNT, teStudentCacheDto);
 
                     AuthDto authDto = (AuthDto) redisUtil.get(SystemConstant.studentOauth + "::" + userId);
                     //验证权限