Переглянути джерело

Merge branch 'feature/1019-tenant' into test

yuanliang 1 рік тому
батько
коміт
9408417d5f

+ 12 - 0
cooleshow-app/src/main/java/com/yonge/cooleshow/admin/controller/StudentController.java

@@ -109,6 +109,17 @@ public class StudentController extends BaseController {
         IPage<StudentVo> pages = studentService.selectPage(PageUtil.getPage(query), query);
         List<StudentVo> rows = pages.getRecords();
 
+        List<Long> tenantGroupIds = rows.stream().map(Student::getTenantGroupId)
+                .filter(next -> next != null && next != -1L).distinct().collect(Collectors.toList());
+        Map<Long, String> tenantGroupIdNameMap = new HashMap<>();
+        if (!tenantGroupIds.isEmpty()) {
+            Map<Long, String> tenantGroupMap = tenantGroupService.lambdaQuery()
+                    .in(TenantGroup::getId, tenantGroupIds)
+                    .list().stream().collect(Collectors.toMap(TenantGroup::getId, TenantGroup::getName));
+            tenantGroupIdNameMap.putAll(tenantGroupMap);
+        }
+
+
         for (StudentVo vo : rows) {
             if (vo.getDelFlag() == YesOrNoEnum.YES) {
                 vo.setUserStatus(UserStatusEnum.CLOSED);
@@ -119,6 +130,7 @@ public class StudentController extends BaseController {
                     vo.setUserStatus(UserStatusEnum.NORMAL);
                 }
             }
+            vo.setTenantGroupName(tenantGroupIdNameMap.getOrDefault(vo.getTenantGroupId(), ""));
         }
         return succeed(PageUtil.pageInfo(pages));
     }

+ 1 - 1
cooleshow-app/src/main/java/com/yonge/cooleshow/tenant/controller/StudentController.java

@@ -120,7 +120,7 @@ public class StudentController extends BaseController {
             List<String> studentPhones =
                     rows.stream().map(StudentVo::getPhone).filter(StringUtils::isNotEmpty).collect(Collectors.toList());
             groupByPhone = tenantActivationCodeService.lambdaQuery()
-                    .eq(TenantActivationCode::getId, query.getTenantAlbumPurchaseId())
+                    .eq(TenantActivationCode::getTenantAlbumPurchaseId, query.getTenantAlbumPurchaseId())
                     .in(TenantActivationCode::getActivationPhone, studentPhones)
                     .list().stream().collect(Collectors.groupingBy(TenantActivationCode::getActivationPhone));
         }

+ 35 - 0
cooleshow-app/src/main/java/com/yonge/cooleshow/tenant/controller/open/OpenTenantGroupController.java

@@ -0,0 +1,35 @@
+package com.yonge.cooleshow.tenant.controller.open;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.microsvc.toolkit.common.response.paging.PageInfo;
+import com.microsvc.toolkit.common.response.paging.QueryInfo;
+import com.microsvc.toolkit.common.response.template.R;
+import com.yonge.cooleshow.biz.dal.service.TenantGroupService;
+import com.yonge.cooleshow.biz.dal.wrapper.TenantGroupWrapper;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Slf4j
+@Validated
+@RestController
+@RequestMapping("${app-config.url.tenant:}/open/tenantGroup")
+@Api(tags = "机构小组表")
+public class OpenTenantGroupController {
+
+    @Autowired
+    private TenantGroupService tenantGroupService;
+
+    @ApiOperation(value = "查询分页", notes = "机构小组表- 传入 TenantGroupWrapper.TenantGroupQuery")
+    @PostMapping("/page")
+    public R<PageInfo<TenantGroupWrapper.TenantGroup>> page(@RequestBody TenantGroupWrapper.TenantGroupQuery query) {
+        IPage<TenantGroupWrapper.TenantGroup> pages = tenantGroupService.selectPage(QueryInfo.getPage(query), query);
+        return R.from(QueryInfo.pageInfo(pages));
+    }
+}

+ 12 - 0
cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/controller/StudentController.java

@@ -109,6 +109,17 @@ public class StudentController extends BaseController {
         IPage<StudentVo> pages = studentService.selectPage(PageUtil.getPage(query), query);
         List<StudentVo> rows = pages.getRecords();
 
+        List<Long> tenantGroupIds = rows.stream().map(Student::getTenantGroupId)
+                .filter(next -> next != null && next != -1L).distinct().collect(Collectors.toList());
+        Map<Long, String> tenantGroupIdNameMap = new HashMap<>();
+        if(!tenantGroupIds.isEmpty()){
+            Map<Long, String> tenantGroupMap = tenantGroupService.lambdaQuery()
+                    .in(TenantGroup::getId, tenantGroupIds)
+                    .list().stream().collect(Collectors.toMap(TenantGroup::getId, TenantGroup::getName));
+            tenantGroupIdNameMap.putAll(tenantGroupMap);
+        }
+
+
         for (StudentVo vo : rows) {
             if (vo.getDelFlag() == YesOrNoEnum.YES) {
                 vo.setUserStatus(UserStatusEnum.CLOSED);
@@ -119,6 +130,7 @@ public class StudentController extends BaseController {
                     vo.setUserStatus(UserStatusEnum.NORMAL);
                 }
             }
+            vo.setTenantGroupName(tenantGroupIdNameMap.getOrDefault(vo.getTenantGroupId(), ""));
         }
         return succeed(PageUtil.pageInfo(pages));
     }

+ 18 - 9
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TenantGroupServiceImpl.java

@@ -103,7 +103,7 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
             List<String> imGroupId = records.stream().map(TenantGroupWrapper.TenantGroup::getImGroupId)
                     .filter(Objects::nonNull).collect(Collectors.toList());
             List<String> existImgGroupIds = new ArrayList<>();
-            if (imGroupId.isEmpty()) {
+            if (!imGroupId.isEmpty()) {
                 List<String> imgGroupIds = imGroupService.lambdaQuery()
                         .in(ImGroup::getId, imGroupId)
                         .list().stream().map(ImGroup::getId).collect(Collectors.toList());
@@ -161,12 +161,16 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
                     log.error("加入机构小组群失败", e);
                     throw new BizException("加入机构小组群失败");
                 }
-                studentDao.update(null, Wrappers.<Student>lambdaUpdate()
-                        .in(Student::getUserId, userIds)
-                        .eq(Student::getTenantId, tenantGroup.getTenantId())
-                        .set(Student::getTenantGroupId, entity.getId()));
             }
         }
+        // 加群成员
+        List<Long> userIds = tenantGroup.getUserIds();
+        if (CollectionUtils.isNotEmpty(userIds)) {
+            studentDao.update(null, Wrappers.<Student>lambdaUpdate()
+                    .in(Student::getUserId, userIds)
+                    .eq(Student::getTenantId, tenantGroup.getTenantId())
+                    .set(Student::getTenantGroupId, entity.getId()));
+        }
         return true;
     }
 
@@ -198,8 +202,7 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
             ImGroup imGroup = imGroupService.getById(oldImGroupId);
             // 群被删除过,并且需要重新建群
             if (imGroup == null) {
-                SysUser sysUser = sysUserService.getByUserId(entity.getAdminId());
-                String imGroupId = createImGroup(entity.getAdminId(), sysUser.getUsername());
+                String imGroupId = createImGroup(entity.getAdminId(), tenantGroup.getName());
                 entity.setImGroupId(imGroupId);
 
                 // 添加群成员
@@ -399,6 +402,9 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
                                 String.valueOf(teacherId));
                         imGroupCoreService.groupQuit(teacherId, ClientEnum.TEACHER.getCode(),
                                 imGroupId, true);
+                        imGroupService.lambdaUpdate()
+                                .set(ImGroup::getCreateBy, toTeacher)
+                                .eq(ImGroup::getId, imGroupId);
                     } catch (Exception e) {
                         log.error("移交负责人失败", e);
                         throw new BizException("移交负责人失败");
@@ -432,13 +438,13 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
         return true;
     }
 
-    public String createImGroup(Long groupAdmin, String userName) {
+    public String createImGroup(Long groupAdmin, String groupName) {
         try {
             ImGroupWrapper.ImGroup imGroup = new ImGroupWrapper.ImGroup();
             imGroup.setId(IdWorker.getId());
             imGroup.setCreateBy(groupAdmin);
             imGroup.setType(ImGroupType.ORG.getCode());
-            imGroup.setName(userName);
+            imGroup.setName(groupName);
             return imGroupService.create(imGroup);
         } catch (Exception e) {
             log.error("创建机构小组群失败", e);
@@ -491,6 +497,9 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
                     String.valueOf(oldGroup.getAdminId()));
             imGroupCoreService.groupQuit(oldGroup.getAdminId(), ClientEnum.TEACHER.getCode(),
                     oldGroup.getImGroupId(), true);
+            imGroupService.lambdaUpdate()
+                    .set(ImGroup::getCreateBy, tenantGroup.getAdminId())
+                    .eq(ImGroup::getId, imGroupId);
         } catch (Exception e) {
             log.error("更换群主失败", e);
             throw new BizException("更换群主失败");

+ 14 - 0
cooleshow-user/user-student/src/main/java/com/yonge/cooleshow/student/controller/ImGroupController.java

@@ -7,10 +7,12 @@ import com.yonge.cooleshow.auth.api.entity.SysUser;
 import com.yonge.cooleshow.biz.dal.dto.ImGroupResultDto;
 import com.yonge.cooleshow.biz.dal.dto.ImGroupSearchDto;
 import com.yonge.cooleshow.biz.dal.entity.ImGroup;
+import com.yonge.cooleshow.biz.dal.entity.ImGroupMember;
 import com.yonge.cooleshow.biz.dal.entity.ImUserFriend;
 import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
 import com.yonge.cooleshow.biz.dal.enums.ImGroupMemberRoleType;
 import com.yonge.cooleshow.biz.dal.enums.MK;
+import com.yonge.cooleshow.biz.dal.service.ImGroupMemberService;
 import com.yonge.cooleshow.biz.dal.service.ImGroupService;
 import com.yonge.cooleshow.biz.dal.service.ImUserFriendService;
 import com.yonge.cooleshow.biz.dal.service.SysUserService;
@@ -55,6 +57,9 @@ public class ImGroupController extends BaseController {
     @Autowired
     private ImUserFriendService imUserFriendService;
 
+    @Autowired
+    private ImGroupMemberService imGroupMemberService;
+
     @ApiOperation("获取群详情")
     @PostMapping(value = "/getDetail/{groupId}")
     public HttpResponseResult<ImGroup> getDetail(@ApiParam(value = "群编号", required = true) @PathVariable("groupId") String groupId) throws Exception {
@@ -70,6 +75,15 @@ public class ImGroupController extends BaseController {
         if (group == null) {
             return failed(HttpStatus.NO_CONTENT, "群组不存在");
         }
+        ImGroupMember admin = imGroupMemberService.lambdaQuery()
+                .eq(ImGroupMember::getGroupId, group.getId())
+                .eq(ImGroupMember::getUserId, sysUserService.getUser().getId())
+                .eq(ImGroupMember::getIsAdmin, true)
+                .last("limit 1").one();
+        if (admin == null) {
+            // 该用户不在该群,无权限查看,处理用户退出群后,查看历史消息校验
+            return failed(HttpStatus.NO_CONTENT, "群组不存在");
+        }
         return succeed(group);
     }
 

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

@@ -6,10 +6,12 @@ import com.yonge.cooleshow.auth.api.entity.SysUser;
 import com.yonge.cooleshow.biz.dal.dto.ImGroupResultDto;
 import com.yonge.cooleshow.biz.dal.dto.ImGroupSearchDto;
 import com.yonge.cooleshow.biz.dal.entity.ImGroup;
+import com.yonge.cooleshow.biz.dal.entity.ImGroupMember;
 import com.yonge.cooleshow.biz.dal.entity.ImUserFriend;
 import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
 import com.yonge.cooleshow.biz.dal.enums.ImGroupMemberRoleType;
 import com.yonge.cooleshow.biz.dal.enums.MK;
+import com.yonge.cooleshow.biz.dal.service.ImGroupMemberService;
 import com.yonge.cooleshow.biz.dal.service.ImGroupService;
 import com.yonge.cooleshow.biz.dal.service.ImUserFriendService;
 import com.yonge.cooleshow.biz.dal.service.SysUserService;
@@ -55,6 +57,9 @@ public class ImGroupController extends BaseController {
     @Autowired
     private ImUserFriendService imUserFriendService;
 
+    @Autowired
+    private ImGroupMemberService imGroupMemberService;
+
     @ApiOperation("创建群聊")
     @PostMapping(value = "/create")
     public HttpResponseResult create(@Valid @RequestBody ImGroupWrapper.ImGroup imGroup, BindingResult bindingResult) throws Exception {
@@ -127,9 +132,17 @@ public class ImGroupController extends BaseController {
     @ApiOperation("获取群详情")
     @PostMapping(value = "/getDetail/{groupId}")
     public HttpResponseResult<ImGroup> getDetail(@ApiParam(value = "群编号", required = true) @PathVariable("groupId") String groupId) throws Exception {
-        SysUser user = sysUserService.getUser();
         ImGroup group = imGroupService.getById(groupId);
-        if (group == null || group.getCreateBy().equals(user.getId())) {
+        if (group == null) {
+            return failed(HttpStatus.NO_CONTENT, "群组不存在");
+        }
+        ImGroupMember admin = imGroupMemberService.lambdaQuery()
+                .eq(ImGroupMember::getGroupId, group.getId())
+                .eq(ImGroupMember::getUserId, sysUserService.getUser().getId())
+                .eq(ImGroupMember::getIsAdmin, true)
+                .last("limit 1").one();
+        if (admin == null) {
+            // 该用户不在该群,无权限查看,处理用户退出群后,查看历史消息校验
             return failed(HttpStatus.NO_CONTENT, "群组不存在");
         }
         return succeed(group);

+ 1 - 1
cooleshow-user/user-tenant/src/main/java/com/yonge/cooleshow/tenant/controller/StudentController.java

@@ -118,7 +118,7 @@ public class StudentController extends BaseController {
             List<String> studentPhones =
                     rows.stream().map(StudentVo::getPhone).filter(StringUtils::isNotEmpty).collect(Collectors.toList());
              groupByPhone = tenantActivationCodeService.lambdaQuery()
-                    .eq(TenantActivationCode::getId, query.getTenantAlbumPurchaseId())
+                    .eq(TenantActivationCode::getTenantAlbumPurchaseId, query.getTenantAlbumPurchaseId())
                     .in(TenantActivationCode::getActivationPhone, studentPhones)
                     .list().stream().collect(Collectors.groupingBy(TenantActivationCode::getActivationPhone));
         }