浏览代码

创建白板时返回随机字符串,前端需求

zouxuan 2 年之前
父节点
当前提交
eac870f5f5

+ 21 - 2
mec-im/src/main/java/com/ym/controller/HereWhiteController.java

@@ -1,19 +1,28 @@
 package com.ym.controller;
 
 import com.ym.mec.common.controller.BaseController;
+import com.ym.pojo.HereWhite;
 import com.ym.service.HereWhiteService;
+import freemarker.cache.StringTemplateLoader;
+import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.Objects;
+import java.util.concurrent.TimeUnit;
+
 @RestController
 @RequestMapping("/hereWhite")
 public class HereWhiteController  extends BaseController {
 
     @Autowired
     private HereWhiteService hereWhiteService;
+    @Autowired
+    private RedisTemplate<String,String> redisTemplate;
 
     /**
      * 创建白板,默认全部采用零时白板
@@ -28,7 +37,12 @@ public class HereWhiteController  extends BaseController {
         if(StringUtils.isEmpty(name) || userNum == null || courseScheduleId == null){
             return failed("参数校验失败");
         }
-        return succeed(hereWhiteService.create(name, userNum,courseScheduleId));
+        HereWhite hereWhite = hereWhiteService.create(name, userNum, courseScheduleId);
+        String joinSuccessKey = "createHereWhite:" + courseScheduleId;
+        String randomNumeric = RandomStringUtils.randomNumeric(22);
+        redisTemplate.opsForValue().set(joinSuccessKey,randomNumeric,2, TimeUnit.HOURS);
+        hereWhite.setRandomNumeric(randomNumeric);
+        return succeed(hereWhite);
     }
 
     /**
@@ -39,7 +53,12 @@ public class HereWhiteController  extends BaseController {
      */
     @RequestMapping(value = "get", method = RequestMethod.GET)
     public Object join(Integer courseScheduleId){
-        return succeed(hereWhiteService.getByClassId(courseScheduleId));
+        HereWhite hereWhite = hereWhiteService.getByClassId(courseScheduleId);
+        if(Objects.nonNull(hereWhite)){
+            String joinSuccessKey = "createHereWhite:" + courseScheduleId;
+            hereWhite.setRandomNumeric(redisTemplate.opsForValue().get(joinSuccessKey));
+        }
+        return succeed(hereWhite);
     }
 
 }

+ 2 - 0
mec-im/src/main/java/com/ym/pojo/HereWhite.java

@@ -45,4 +45,6 @@ public class HereWhite implements Serializable {
     @Column(name = "created_at_")
     private @Getter @Setter Date createdAt;
 
+    private @Getter @Setter String randomNumeric;
+
 }

+ 1 - 2
mec-im/src/main/java/com/ym/service/Impl/HereWhiteServiceImpl.java

@@ -10,7 +10,6 @@ import com.ym.service.RoomService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Isolation;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.Date;
@@ -31,7 +30,7 @@ public class HereWhiteServiceImpl implements HereWhiteService {
     private RoomService roomService;
 
     @Override
-    @Transactional(rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
+    @Transactional(rollbackFor = Exception.class)
     public HereWhite create(String name, Integer userNum,Integer courseScheduleId) throws Exception {
         courseScheduleId = roomService.getCurrentCourseId(courseScheduleId.toString());
         JSONObject json = new JSONObject();