Jelajahi Sumber

创建聊天群

liujc 1 tahun lalu
induk
melakukan
ee1097789c

+ 37 - 0
cooleshow-app/src/main/java/com/yonge/cooleshow/teacher/controller/ImGroupController.java

@@ -32,8 +32,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.validation.Valid;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Objects;
+import java.util.Set;
 
 /**
  * 即时通讯群组(ImGroup)表控制层
@@ -73,6 +75,41 @@ public class ImGroupController extends BaseController {
         return succeed();
     }
 
+    @ApiOperation("创建群聊")
+    @PostMapping(value = "/create/v2")
+    public HttpResponseResult createV2(@Valid @RequestBody ImGroupWrapper.ImGroup imGroup, BindingResult bindingResult) throws Exception {
+
+        // 将imUserId 转为userId
+        Set<String> imUserIdList = imGroup.getImUserIdList();
+
+        Set<Long> studentIdList = new HashSet<>();
+        for (String imUserId : imUserIdList) {
+            studentIdList.add(Long.parseLong(imGroupService.analysisImUserId(imUserId)));
+        }
+        imGroup.setStudentIdList(studentIdList);
+
+        ValidationKit.ignoreFields(bindingResult,"id");
+        imGroup.setCreateBy(sysUserService.getUserId());
+        imGroupService.create(imGroup);
+        return succeed();
+    }
+
+    @ApiOperation("添加群成员")
+    @PostMapping(value = "/addGroupMember/v2")
+    public HttpResponseResult addGroupMemberV2(@Valid @RequestBody ImGroupWrapper.ImGroup imGroup,
+                                               BindingResult bindingResult) throws Exception {
+        // 将imUserId 转为userId
+        Set<String> imUserIdList = imGroup.getImUserIdList();
+
+        Set<Long> studentIdList = new HashSet<>();
+        for (String imUserId : imUserIdList) {
+            studentIdList.add(Long.parseLong(imGroupService.analysisImUserId(imUserId)));
+        }
+        imGroup.setStudentIdList(studentIdList);
+
+        imGroupService.addGroupMember(imGroup.getGroupId(), imGroup.getStudentIdList());
+        return succeed();
+    }
     @ApiOperation("解散群聊")
     @PostMapping(value = "/dismiss/{groupId}")
     public HttpResponseResult dismiss(@ApiParam(value = "群编号", required = true) @PathVariable("groupId") String groupId) throws Exception {

+ 4 - 2
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/ImGroupServiceImpl.java

@@ -298,8 +298,10 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
         imGroup.setUpdateTime(now);
         imGroup.setImg(sysConfigService.findConfigValue(SysConfigConstant.ICON_FANS_GROUP_DEFAULT));
         ImGroup group = JSON.parseObject(JSON.toJSONString(imGroup), ImGroup.class);
-        createImGroup(group);
-
+        String groupId = createImGroup(group);
+        if (!imGroup.getStudentIdList().isEmpty()) {
+            addGroupMember(groupId,imGroup.getStudentIdList());
+        }
 
 //        String imGroupId = UUID.randomUUID() + imGroup.getType().getCode();
 //        imGroup.setId(imGroupId);

+ 5 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/im/ImGroupWrapper.java

@@ -122,6 +122,8 @@ public class ImGroupWrapper {
 
         private Set<Long> studentIdList = new HashSet<>();
 
+        private Set<String> imUserIdList = new HashSet<>();
+
         public static ImGroup from(String json) {
             return JSON.parseObject(json, ImGroup.class);
         }
@@ -166,3 +168,6 @@ public class ImGroupWrapper {
         }
     }
 }
+
+
+

+ 36 - 2
cooleshow-user/user-teacher/src/main/java/com/yonge/cooleshow/teacher/controller/ImGroupController.java

@@ -32,8 +32,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.validation.Valid;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
 
 /**
  * 即时通讯群组(ImGroup)表控制层
@@ -73,6 +72,41 @@ public class ImGroupController extends BaseController {
         return succeed();
     }
 
+    @ApiOperation("创建群聊")
+    @PostMapping(value = "/create/v2")
+    public HttpResponseResult createV2(@Valid @RequestBody ImGroupWrapper.ImGroup imGroup, BindingResult bindingResult) throws Exception {
+
+        // 将imUserId 转为userId
+        Set<String> imUserIdList = imGroup.getImUserIdList();
+
+        Set<Long> studentIdList = new HashSet<>();
+        for (String imUserId : imUserIdList) {
+            studentIdList.add(Long.parseLong(imGroupService.analysisImUserId(imUserId)));
+        }
+        imGroup.setStudentIdList(studentIdList);
+
+        ValidationKit.ignoreFields(bindingResult,"id");
+        imGroup.setCreateBy(sysUserService.getUserId());
+        imGroupService.create(imGroup);
+        return succeed();
+    }
+
+    @ApiOperation("添加群成员")
+    @PostMapping(value = "/addGroupMember/v2")
+    public HttpResponseResult addGroupMemberV2(@Valid @RequestBody ImGroupWrapper.ImGroup imGroup,
+                                             BindingResult bindingResult) throws Exception {
+        // 将imUserId 转为userId
+        Set<String> imUserIdList = imGroup.getImUserIdList();
+
+        Set<Long> studentIdList = new HashSet<>();
+        for (String imUserId : imUserIdList) {
+            studentIdList.add(Long.parseLong(imGroupService.analysisImUserId(imUserId)));
+        }
+        imGroup.setStudentIdList(studentIdList);
+
+        imGroupService.addGroupMember(imGroup.getGroupId(), imGroup.getStudentIdList());
+        return succeed();
+    }
     @ApiOperation("解散群聊")
     @PostMapping(value = "/dismiss/{groupId}")
     public HttpResponseResult dismiss(@ApiParam(value = "群编号", required = true) @PathVariable("groupId") String groupId) throws Exception {