Browse Source

Merge remote-tracking branch 'origin/feature/1019-tenant' into feature/1019-tenant

zouxuan 1 year ago
parent
commit
c1f9e29aed
19 changed files with 268 additions and 37 deletions
  1. 35 3
      cooleshow-app/src/main/java/com/yonge/cooleshow/admin/controller/StudentController.java
  2. 3 2
      cooleshow-app/src/main/java/com/yonge/cooleshow/admin/controller/TeacherController.java
  3. 14 1
      cooleshow-app/src/main/java/com/yonge/cooleshow/student/controller/ImGroupController.java
  4. 17 3
      cooleshow-app/src/main/java/com/yonge/cooleshow/teacher/controller/ImGroupController.java
  5. 20 5
      cooleshow-app/src/main/java/com/yonge/cooleshow/tenant/controller/StudentController.java
  6. 35 0
      cooleshow-app/src/main/java/com/yonge/cooleshow/tenant/controller/open/OpenTenantGroupController.java
  7. 33 2
      cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/controller/StudentController.java
  8. 3 2
      cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/controller/TeacherController.java
  9. 16 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/StudentServiceImpl.java
  10. 18 1
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TeacherServiceImpl.java
  11. 19 15
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TenantGroupServiceImpl.java
  12. 1 1
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TenantUnbindRecordServiceImpl.java
  13. 3 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/vo/StudentHomeVo.java
  14. 3 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/vo/TeacherVo.java
  15. 3 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/StudentWrapper.java
  16. 1 0
      cooleshow-user/user-biz/src/main/resources/config/mybatis/TenantAlbumMapper.xml
  17. 13 0
      cooleshow-user/user-student/src/main/java/com/yonge/cooleshow/student/controller/ImGroupController.java
  18. 14 0
      cooleshow-user/user-teacher/src/main/java/com/yonge/cooleshow/teacher/controller/ImGroupController.java
  19. 17 2
      cooleshow-user/user-tenant/src/main/java/com/yonge/cooleshow/tenant/controller/StudentController.java

+ 35 - 3
cooleshow-app/src/main/java/com/yonge/cooleshow/admin/controller/StudentController.java

@@ -7,9 +7,11 @@ import com.yonge.cooleshow.biz.dal.dto.VipSubmitReq;
 import com.yonge.cooleshow.biz.dal.dto.search.StudentSearch;
 import com.yonge.cooleshow.biz.dal.dto.search.VipRecordSearch;
 import com.yonge.cooleshow.biz.dal.entity.Student;
+import com.yonge.cooleshow.biz.dal.entity.TenantGroup;
 import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
 import com.yonge.cooleshow.biz.dal.service.MemberPriceSettingsService;
 import com.yonge.cooleshow.biz.dal.service.StudentService;
+import com.yonge.cooleshow.biz.dal.service.TenantGroupService;
 import com.yonge.cooleshow.biz.dal.service.VipCardRecordService;
 import com.yonge.cooleshow.biz.dal.vo.StudentVo;
 import com.yonge.cooleshow.biz.dal.vo.VipRecordVo;
@@ -41,12 +43,16 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 @RestController
 @RequestMapping("${app-config.url.admin:}/student")
@@ -55,7 +61,7 @@ public class StudentController extends BaseController {
     @Autowired
     private StudentService studentService;
 
-    @Autowired
+    @Resource
     private SysUserFeignService sysUserFeignService;
 
     @Autowired
@@ -64,6 +70,9 @@ public class StudentController extends BaseController {
     @Autowired
     private VipCardRecordService vipCardRecordService;
 
+    @Autowired
+    private TenantGroupService tenantGroupService;
+
     @GetMapping("/detail/{id}")
     @ApiOperation(value = "详情", notes = "传入id")
     @ApiImplicitParams({
@@ -100,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);
@@ -110,6 +130,7 @@ public class StudentController extends BaseController {
                     vo.setUserStatus(UserStatusEnum.NORMAL);
                 }
             }
+            vo.setTenantGroupName(tenantGroupIdNameMap.getOrDefault(vo.getTenantGroupId(), ""));
         }
         return succeed(PageUtil.pageInfo(pages));
     }
@@ -142,6 +163,16 @@ public class StudentController extends BaseController {
             throw new BizException("没有可导出数据");
         }
 
+        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);
@@ -152,13 +183,14 @@ public class StudentController extends BaseController {
                     vo.setUserStatus(UserStatusEnum.NORMAL);
                 }
             }
+            vo.setTenantGroupName(tenantGroupIdNameMap.getOrDefault(vo.getTenantGroupId(), ""));
         }
         OutputStream outputStream = response.getOutputStream();
         try {
             HSSFWorkbook workbook = POIUtil.exportExcel(new String[]{"学生编号", "学生姓名", "真实姓名", "性别", "出生日期",
-                    "年龄", "专业", "手机号码", "是否是会员", "注册时间", "用户状态", "学生来源"}, new String[]{
+                    "年龄", "专业", "手机号码", "是否是会员", "注册时间", "用户状态", "学生来源","小组"}, new String[]{
                     "userId", "username", "realName", "gender.msg", "birthdate", "age", "subjectName", "phone",
-                    "isVip.msg", "createTime", "userStatus.msg", "tenantName"}, rows);
+                    "isVip.msg", "createTime", "userStatus.msg", "tenantName", "tenantGroupName"}, rows);
             response.setContentType("application/octet-stream");
             response.setHeader("Content-Disposition", "attac:wq" +
                     "hment;filename=学生列表-" + DateUtil.getDate(new Date()) + ".xls");

+ 3 - 2
cooleshow-app/src/main/java/com/yonge/cooleshow/admin/controller/TeacherController.java

@@ -218,9 +218,10 @@ public class TeacherController extends BaseController {
         OutputStream outputStream = response.getOutputStream();
         try {
             HSSFWorkbook workbook = POIUtil.exportExcel(new String[]{"老师编号", "昵称", "姓名", "手机号", "老师类型",
-                    "注册时间", "认证时间", "状态", "是否是会员", "徽章", "机构"}, new String[]{
+                    "注册时间", "认证时间", "状态", "是否是会员", "徽章", "机构", "小组"}, new String[]{
                     "userId", "username", "realName", "phone", "entryFlag.code == 1 ? '达人' : '游客'", "createTime",
-                    "entryAuthDate","userStatus.msg", "isVip.code == 1 ? '是' : '否'", "tag", "tenantName"}, rows);
+                    "entryAuthDate","userStatus.msg", "isVip.code == 1 ? '是' : '否'", "tag", "tenantName",
+                    "tenantGroupName"}, rows);
             response.setContentType("application/octet-stream");
             response.setHeader("Content-Disposition", "attac:wq" +
                     "hment;filename=老师列表-" + DateUtil.getDate(new Date()) + ".xls");

+ 14 - 1
cooleshow-app/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;
@@ -61,6 +63,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 {
@@ -76,6 +81,14 @@ 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())
+                .last("limit 1").one();
+        if (admin == null) {
+            // 该用户不在该群,无权限查看,处理用户退出群后,查看历史消息校验
+            return failed(HttpStatus.NO_CONTENT, "群组不存在");
+        }
         return succeed(group);
     }
 
@@ -108,7 +121,7 @@ public class ImGroupController extends BaseController {
     @PostMapping(value = "/quit/{groupId}")
     public HttpResponseResult quit(@ApiParam(value = "群编号", required = true) @PathVariable("groupId") String groupId,
                                    @RequestParam(value = "quit",required = false,defaultValue = "false") boolean quit
-                                   ) throws Exception {
+    ) throws Exception {
         imGroupService.quit(groupId,sysUserService.getUserId(), ClientEnum.STUDENT, quit);
         return succeed();
     }

+ 17 - 3
cooleshow-app/src/main/java/com/yonge/cooleshow/teacher/controller/ImGroupController.java

@@ -5,10 +5,12 @@ import com.alibaba.fastjson.JSON;
 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;
@@ -32,6 +34,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.annotation.Resource;
 import javax.validation.Valid;
 import java.util.List;
 import java.util.Objects;
@@ -49,14 +52,17 @@ public class ImGroupController extends BaseController {
     /**
      * 服务对象
      */
-    @Autowired
+    @Resource
     private ImGroupService imGroupService;
-    @Autowired
+    @Resource
     private SysUserService sysUserService;
 
     @Autowired
     private ImUserFriendService imUserFriendService;
 
+    @Autowired
+    private ImGroupMemberService imGroupMemberService;
+
     @ApiOperation("创建群聊")
     @PostMapping(value = "/create")
     public HttpResponseResult create(@Valid @RequestBody ImGroupWrapper.ImGroup imGroup, BindingResult bindingResult) throws Exception {
@@ -85,7 +91,7 @@ public class ImGroupController extends BaseController {
     @PostMapping(value = "/quit/{groupId}")
     public HttpResponseResult quit(@ApiParam(value = "群编号", required = true) @PathVariable("groupId") String groupId,
                                    @RequestParam(value = "quit",required = false, defaultValue = "false") boolean quit
-                                   ) throws Exception {
+    ) throws Exception {
         imGroupService.quit(groupId, sysUserService.getUserId(), ClientEnum.TEACHER, quit);
         return succeed();
     }
@@ -97,6 +103,14 @@ 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())
+                .last("limit 1").one();
+        if (admin == null) {
+            // 该用户不在该群,无权限查看,处理用户退出群后,查看历史消息校验
+            return failed(HttpStatus.NO_CONTENT, "群组不存在");
+        }
         return succeed(group);
     }
 

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

@@ -83,6 +83,10 @@ public class StudentController extends BaseController {
     @ApiOperation(value = "详情", notes = "传入id")
     public HttpResponseResult<StudentVo> detail(@PathVariable("id") Long id) {
         StudentVo detail = studentService.detail(id);
+        if (detail != null && detail.getTenantGroupId() != null) {
+            TenantGroup group = tenantGroupService.getById(detail.getTenantGroupId());
+            detail.setTenantGroupName(group == null ? "" : group.getName());
+        }
         return succeed(detail);
     }
 
@@ -103,8 +107,8 @@ public class StudentController extends BaseController {
         }
 
         //如果真实姓名字段为空 把真实姓名赋值给昵称
-        rows.stream().forEach(r->{
-            if (StringUtils.isEmpty(r.getRealName())){
+        rows.stream().forEach(r -> {
+            if (StringUtils.isEmpty(r.getRealName())) {
                 if (StringUtils.isNotEmpty(r.getUsername()))
                     r.setRealName(r.getUsername());
             }
@@ -116,14 +120,14 @@ 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));
         }
         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()){
+        if (!tenantGroupIds.isEmpty()) {
             Map<Long, String> tenantGroupMap = tenantGroupService.lambdaQuery()
                     .eq(TenantGroup::getTenantId, tenantInfo.getId())
                     .in(TenantGroup::getId, tenantGroupIds)
@@ -169,12 +173,23 @@ public class StudentController extends BaseController {
             throw new BizException("没有可导出数据");
         }
 
+        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()
+                    .eq(TenantGroup::getTenantId, tenantInfo.getId())
+                    .in(TenantGroup::getId, tenantGroupIds)
+                    .list().stream().collect(Collectors.toMap(TenantGroup::getId, TenantGroup::getName));
+            tenantGroupIdNameMap.putAll(tenantGroupMap);
+        }
+
         List<StudentWrapper.ExportStudentTemplate> templateList = rows.stream().map(next -> {
             StudentWrapper.ExportStudentTemplate template = new StudentWrapper.ExportStudentTemplate();
             template.setUserName(next.getUsername());
             template.setPhone(next.getPhone());
             template.setSubjectName(next.getSubjectName());
-            template.setTenantGroupName(next.getTenantGroupName());
+            template.setTenantGroupName(tenantGroupIdNameMap.getOrDefault(next.getTenantGroupId(), ""));
             return template;
         }).collect(Collectors.toList());
 

+ 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));
+    }
+}

+ 33 - 2
cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/controller/StudentController.java

@@ -7,9 +7,11 @@ import com.yonge.cooleshow.biz.dal.dto.VipSubmitReq;
 import com.yonge.cooleshow.biz.dal.dto.search.StudentSearch;
 import com.yonge.cooleshow.biz.dal.dto.search.VipRecordSearch;
 import com.yonge.cooleshow.biz.dal.entity.Student;
+import com.yonge.cooleshow.biz.dal.entity.TenantGroup;
 import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
 import com.yonge.cooleshow.biz.dal.service.MemberPriceSettingsService;
 import com.yonge.cooleshow.biz.dal.service.StudentService;
+import com.yonge.cooleshow.biz.dal.service.TenantGroupService;
 import com.yonge.cooleshow.biz.dal.service.VipCardRecordService;
 import com.yonge.cooleshow.biz.dal.vo.StudentVo;
 import com.yonge.cooleshow.biz.dal.vo.VipRecordVo;
@@ -47,7 +49,10 @@ import javax.validation.Valid;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 @RestController
 @RequestMapping("/student")
@@ -65,6 +70,9 @@ public class StudentController extends BaseController {
     @Autowired
     private VipCardRecordService vipCardRecordService;
 
+    @Autowired
+    private TenantGroupService tenantGroupService;
+
     @GetMapping("/detail/{id}")
     @ApiOperation(value = "详情", notes = "传入id")
     @ApiImplicitParams({
@@ -101,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);
@@ -111,6 +130,7 @@ public class StudentController extends BaseController {
                     vo.setUserStatus(UserStatusEnum.NORMAL);
                 }
             }
+            vo.setTenantGroupName(tenantGroupIdNameMap.getOrDefault(vo.getTenantGroupId(), ""));
         }
         return succeed(PageUtil.pageInfo(pages));
     }
@@ -143,6 +163,16 @@ public class StudentController extends BaseController {
             throw new BizException("没有可导出数据");
         }
 
+        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);
@@ -153,13 +183,14 @@ public class StudentController extends BaseController {
                     vo.setUserStatus(UserStatusEnum.NORMAL);
                 }
             }
+            vo.setTenantGroupName(tenantGroupIdNameMap.getOrDefault(vo.getTenantGroupId(), ""));
         }
         OutputStream outputStream = response.getOutputStream();
         try {
             HSSFWorkbook workbook = POIUtil.exportExcel(new String[]{"学生编号", "学生姓名", "真实姓名", "性别", "出生日期",
-                    "年龄", "专业", "手机号码", "是否是会员", "注册时间", "用户状态", "学生来源"}, new String[]{
+                    "年龄", "专业", "手机号码", "是否是会员", "注册时间", "用户状态", "学生来源","小组"}, new String[]{
                     "userId", "username", "realName", "gender.msg", "birthdate", "age", "subjectName", "phone",
-                    "isVip.msg", "createTime", "userStatus.msg", "tenantName"}, rows);
+                    "isVip.msg", "createTime", "userStatus.msg", "tenantName", "tenantGroupName"}, rows);
             response.setContentType("application/octet-stream");
             response.setHeader("Content-Disposition", "attac:wq" +
                     "hment;filename=学生列表-" + DateUtil.getDate(new Date()) + ".xls");

+ 3 - 2
cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/controller/TeacherController.java

@@ -223,9 +223,10 @@ public class TeacherController extends BaseController {
         OutputStream outputStream = response.getOutputStream();
         try {
             HSSFWorkbook workbook = POIUtil.exportExcel(new String[]{"老师编号", "昵称", "姓名", "手机号", "老师类型",
-                    "注册时间", "认证时间", "状态", "是否是会员", "徽章", "机构"}, new String[]{
+                    "注册时间", "认证时间", "状态", "是否是会员", "徽章", "机构", "小组"}, new String[]{
                     "userId", "username", "realName", "phone", "entryFlag.code == 1 ? '达人' : '游客'", "createTime",
-                    "entryAuthDate","userStatus.msg", "isVip.code == 1 ? '是' : '否'", "tag", "tenantName"}, rows);
+                    "entryAuthDate","userStatus.msg", "isVip.code == 1 ? '是' : '否'", "tag", "tenantName",
+                    "tenantGroupName"}, rows);
             response.setContentType("application/octet-stream");
             response.setHeader("Content-Disposition", "attac:wq" +
                     "hment;filename=老师列表-" + DateUtil.getDate(new Date()) + ".xls");

+ 16 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/StudentServiceImpl.java

@@ -227,6 +227,12 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
             }
 
         }
+        if (detail.getTenantGroupId() != null) {
+            TenantGroup tenantGroup = tenantGroupMapper.selectById(detail.getTenantGroupId());
+            if (tenantGroup != null) {
+                studentHomeVo.setTenantGroupName(tenantGroup.getName());
+            }
+        }
 
         return studentHomeVo;
     }
@@ -461,6 +467,11 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
         }
         dataList.sort(Comparator.comparingInt(ExcelDataReaderProperty::getRowIndex));
 
+        QueryWrapper<TenantGroup> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda().eq(TenantGroup::getTenantId, tenantId);
+        List<TenantGroup> groups = tenantGroupMapper.selectList(queryWrapper);
+        Map<String, Long> groupNameIdMap = groups.stream().collect(Collectors.toMap(TenantGroup::getName, TenantGroup::getId));
+
         Map<String, Long> subjectIdNamemap = subjectDao.findAll(new HashMap<>())
                 .stream().collect(Collectors.toMap(next -> next.getName(), next -> next.getId()));
         Set<String> subjectNames = subjectIdNamemap.keySet();
@@ -485,6 +496,10 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
                 errMsg.add(String.format("第%s行声部不支持", msgRowNo));
             }
 
+            if (StringUtils.isNotEmpty(student.getTenantGroupName()) && !groupNameIdMap.containsKey(student.getTenantGroupName())) {
+                errMsg.add(String.format("第%s行小组不存在", msgRowNo));
+            }
+
             if (errMsg.size() > 100) {
                 break;
             }
@@ -528,6 +543,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
             student.setGender("男".equals(studentImport.getGender()) ? 1 : 0);
             student.setSubjectId(subjectIdNamemap.get(studentImport.getSubjectName()).toString());
             student.setPhone(studentImport.getPhone());
+            student.setTenantGroupId(groupNameIdMap.getOrDefault(studentImport.getTenantGroupName(), -1L));
 
             LocalDate birthday = LocalDate.parse(studentImport.getBirthday(), DateTimeFormatter.ISO_LOCAL_DATE);
             student.setBirthdate(birthday);

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

@@ -258,7 +258,24 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
                 .eq(MusicSheet::getSourceType, "TEACHER").list();
 
         Map<Long, List<MusicSheet>> groupByUserId = musicSheets.stream().collect(Collectors.groupingBy(MusicSheet::getUserId));
+
+        // 添加小组信息
+        Map<Long, List<TenantGroup>> groupByAdminId = new HashMap<>();
+        List<Long> teacherIds = teacherVos.stream().map(Teacher::getUserId).distinct().collect(Collectors.toList());
+        if(!teacherIds.isEmpty()){
+            QueryWrapper<TenantGroup> queryWrapper = new QueryWrapper<>();
+            queryWrapper.lambda().in(TenantGroup::getAdminId,teacherIds);
+            List<TenantGroup> tenantGroups = tenantGroupMapper.selectList(queryWrapper);
+            Map<Long, List<TenantGroup>> groupBy = tenantGroups.stream().collect(Collectors.groupingBy(TenantGroup::getAdminId));
+            groupByAdminId.putAll(groupBy);
+        }
+
+
         for (TeacherVo teacherVo : teacherVos) {
+            List<String> groups = groupByAdminId.getOrDefault(teacherVo.getUserId(), new ArrayList<>())
+                    .stream().map(TenantGroup::getName).collect(Collectors.toList());
+            teacherVo.setTenantGroupName(String.join(",", groups));
+
             List<MusicSheet> musicSheetList = groupByUserId.getOrDefault(teacherVo.getUserId(), new ArrayList<>());
             teacherVo.setMusicSheetCount(musicSheetList.size());
             List<String> names = musicSheetList.stream().map(MusicSheet::getMusicSheetName).collect(Collectors.toList());
@@ -1053,7 +1070,7 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
                     .eq(TenantGroup::getAdminId, teacher.getUserId());
             Integer count = tenantGroupMapper.selectCount(queryWrapper);
             if (count > 0) {
-                throw new BizException(5100, "该老师存在机构小组负责人身份,请先移交小组或者解散小组");
+                throw new BizException("该老师存在机构小组负责人身份,请先移交小组或者解散小组");
             }
 
             // 机构老师处理流程

+ 19 - 15
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);
 
                 // 添加群成员
@@ -207,7 +210,7 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
                 if (CollectionUtils.isNotEmpty(userIds)) {
                     // 加群成员
                     try {
-                        imGroupService.addGroupMember(oldGroup.getImGroupId(), new HashSet<>(userIds));
+                        imGroupService.addGroupMember(imGroupId, new HashSet<>(userIds));
                     } catch (Exception e) {
                         log.error("加入机构小组群失败", e);
                         throw new BizException("加入机构小组群失败");
@@ -280,11 +283,6 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
         if (group == null) {
             throw new BizException("机构小组不存在");
         }
-        List<Student> students = this.queryStudent(group.getTenantId(), group.getId());
-        if (!students.isEmpty()) {
-            throw new BizException("小组内存在学生");
-        }
-
         String imGroupId = group.getImGroupId();
         if (imGroupId != null) {
             ImGroup imGroup = imGroupService.getById(imGroupId);
@@ -404,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("移交负责人失败");
@@ -437,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);
@@ -496,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("更换群主失败");

+ 1 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TenantUnbindRecordServiceImpl.java

@@ -224,7 +224,7 @@ public class TenantUnbindRecordServiceImpl extends ServiceImpl<TenantUnbindRecor
                 .eq(TenantGroup::getAdminId, teacher.getUserId());
         Integer count = tenantGroupMapper.selectCount(queryWrapper);
         if (count > 0) {
-            throw new BizException(5100, "该老师存在机构小组负责人身份,请先移交小组或者解散小组");
+            throw new BizException("该老师存在机构小组负责人身份,请先移交小组或者解散小组");
         }
 
         this.lambdaUpdate()

+ 3 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/vo/StudentHomeVo.java

@@ -89,6 +89,9 @@ public class StudentHomeVo extends Student {
     @ApiModelProperty(value = "机构名称")
     private String tenantName;
 
+    @ApiModelProperty(value = "机构小组名称")
+    private String tenantGroupName;
+
     public YesOrNoEnum getTenantAlbumFlag() {
         return tenantAlbumFlag;
     }

+ 3 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/vo/TeacherVo.java

@@ -99,6 +99,9 @@ public class TeacherVo extends Teacher {
     @ApiModelProperty("曲谱名称")
     private String musicSheetName;
 
+    @ApiModelProperty("机构小组名称")
+    private String tenantGroupName;
+
 
     public YesOrNoEnum getDelFlag() {
         return delFlag;

+ 3 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/StudentWrapper.java

@@ -147,6 +147,9 @@ public class StudentWrapper {
         @ExcelProperty(value = "性别")
         private String gender;
 
+        @ExcelProperty(value = "小组")
+        private String tenantGroupName;
+
         private static final String PHONE_REG = "^1\\d{10}$";
 
         public List<String> checkValid() {

+ 1 - 0
cooleshow-user/user-biz/src/main/resources/config/mybatis/TenantAlbumMapper.xml

@@ -33,6 +33,7 @@
             <if test="param.keyword !=null and param.keyword.trim() !=''">
                 and (t.name_ like concat('%',#{param.keyword},'%')
                 or i.name_ like concat('%',#{param.keyword},'%')
+                or t.describe_ like concat('%',#{param.keyword},'%')
                 )
             </if>
             <if test="param.tenantId != null ">

+ 13 - 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,14 @@ 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())
+                .last("limit 1").one();
+        if (admin == null) {
+            // 该用户不在该群,无权限查看,处理用户退出群后,查看历史消息校验
+            return failed(HttpStatus.NO_CONTENT, "群组不存在");
+        }
         return succeed(group);
     }
 

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

@@ -2,13 +2,16 @@ package com.yonge.cooleshow.teacher.controller;
 
 
 import com.alibaba.fastjson.JSON;
+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;
@@ -52,6 +55,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 {
@@ -92,6 +98,14 @@ 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())
+                .last("limit 1").one();
+        if (admin == null) {
+            // 该用户不在该群,无权限查看,处理用户退出群后,查看历史消息校验
+            return failed(HttpStatus.NO_CONTENT, "群组不存在");
+        }
         return succeed(group);
     }
 

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

@@ -81,6 +81,10 @@ public class StudentController extends BaseController {
     @ApiOperation(value = "详情", notes = "传入id")
     public HttpResponseResult<StudentVo> detail(@PathVariable("id") Long id) {
         StudentVo detail = studentService.detail(id);
+        if (detail != null && detail.getTenantGroupId() != null) {
+            TenantGroup group = tenantGroupService.getById(detail.getTenantGroupId());
+            detail.setTenantGroupName(group == null ? "" : group.getName());
+        }
         return succeed(detail);
     }
 
@@ -114,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));
         }
@@ -167,12 +171,23 @@ public class StudentController extends BaseController {
             throw new BizException("没有可导出数据");
         }
 
+        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()
+                    .eq(TenantGroup::getTenantId, tenantInfo.getId())
+                    .in(TenantGroup::getId, tenantGroupIds)
+                    .list().stream().collect(Collectors.toMap(TenantGroup::getId, TenantGroup::getName));
+            tenantGroupIdNameMap.putAll(tenantGroupMap);
+        }
+
         List<StudentWrapper.ExportStudentTemplate> templateList = rows.stream().map(next -> {
             StudentWrapper.ExportStudentTemplate template = new StudentWrapper.ExportStudentTemplate();
             template.setUserName(next.getUsername());
             template.setPhone(next.getPhone());
             template.setSubjectName(next.getSubjectName());
-            template.setTenantGroupName(next.getTenantGroupName());
+            template.setTenantGroupName(tenantGroupIdNameMap.getOrDefault(next.getTenantGroupId(), ""));
             return template;
         }).collect(Collectors.toList());