Explorar el Código

1.机构小组调整

yuanliang hace 1 año
padre
commit
c1b4d52a09
Se han modificado 14 ficheros con 489 adiciones y 79 borrados
  1. 39 0
      cooleshow-app/src/main/java/com/yonge/cooleshow/admin/controller/open/OpenTenantGroupController.java
  2. 46 0
      cooleshow-app/src/main/java/com/yonge/cooleshow/teacher/controller/TenantGroupController.java
  3. 63 0
      cooleshow-app/src/main/java/com/yonge/cooleshow/teacher/controller/open/OpenSubjectController.java
  4. 7 1
      cooleshow-app/src/main/java/com/yonge/cooleshow/tenant/controller/TenantGroupController.java
  5. 3 0
      cooleshow-app/src/main/java/com/yonge/cooleshow/tenant/vo/TenantGroupVo.java
  6. 35 0
      cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/controller/open/OpenTenantGroupController.java
  7. 2 1
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/TenantGroupService.java
  8. 143 76
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TenantGroupServiceImpl.java
  9. 3 0
      cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/TenantGroupWrapper.java
  10. 46 0
      cooleshow-user/user-teacher/src/main/java/com/yonge/cooleshow/teacher/controller/TenantGroupController.java
  11. 63 0
      cooleshow-user/user-teacher/src/main/java/com/yonge/cooleshow/teacher/controller/open/OpenSubjectController.java
  12. 1 1
      cooleshow-user/user-tenant/src/main/java/com/yonge/cooleshow/tenant/controller/TenantGroupController.java
  13. 35 0
      cooleshow-user/user-tenant/src/main/java/com/yonge/cooleshow/tenant/controller/open/OpenTenantGroupController.java
  14. 3 0
      cooleshow-user/user-tenant/src/main/java/com/yonge/cooleshow/tenant/vo/TenantGroupVo.java

+ 39 - 0
cooleshow-app/src/main/java/com/yonge/cooleshow/admin/controller/open/OpenTenantGroupController.java

@@ -0,0 +1,39 @@
+package com.yonge.cooleshow.admin.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.auth.api.client.SysUserFeignService;
+import com.yonge.cooleshow.auth.api.entity.SysUser;
+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;
+
+import javax.annotation.Resource;
+
+@Slf4j
+@Validated
+@RestController
+@RequestMapping("{app-config.url.admin:}/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));
+    }
+}

+ 46 - 0
cooleshow-app/src/main/java/com/yonge/cooleshow/teacher/controller/TenantGroupController.java

@@ -0,0 +1,46 @@
+package com.yonge.cooleshow.teacher.controller;
+
+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.auth.api.client.SysUserFeignService;
+import com.yonge.cooleshow.auth.api.entity.SysUser;
+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;
+
+import javax.annotation.Resource;
+
+@Slf4j
+@Validated
+@RestController
+@RequestMapping("${app-config.url.teacher:}/tenantGroup")
+@Api(tags = "机构小组表")
+public class TenantGroupController {
+
+    @Autowired
+    private TenantGroupService tenantGroupService;
+
+    @Resource
+    private SysUserFeignService sysUserFeignService;
+
+    @ApiOperation(value = "查询分页", notes = "机构小组表- 传入 TenantGroupWrapper.TenantGroupQuery")
+    @PostMapping("/page")
+    public R<PageInfo<TenantGroupWrapper.TenantGroup>> page(@RequestBody TenantGroupWrapper.TenantGroupQuery query) {
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        query.setTenantId(sysUser.getTenantId());
+        IPage<TenantGroupWrapper.TenantGroup> pages = tenantGroupService.selectPage(QueryInfo.getPage(query), query);
+
+        return R.from(QueryInfo.pageInfo(pages));
+    }
+
+}

+ 63 - 0
cooleshow-app/src/main/java/com/yonge/cooleshow/teacher/controller/open/OpenSubjectController.java

@@ -0,0 +1,63 @@
+package com.yonge.cooleshow.teacher.controller.open;
+
+import com.yonge.cooleshow.biz.dal.entity.Subject;
+import com.yonge.cooleshow.biz.dal.queryInfo.SubjectQueryInfo;
+import com.yonge.cooleshow.biz.dal.service.SubjectService;
+import com.yonge.cooleshow.common.controller.BaseController;
+import com.yonge.cooleshow.common.entity.HttpResponseResult;
+import com.yonge.toolset.base.page.PageInfo;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+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;
+
+import java.util.Map;
+import java.util.stream.Collectors;
+
+@RequestMapping("${app-config.url.teacher:}/open/subject")
+@Api(tags = "声部服务")
+@RestController
+public class OpenSubjectController extends BaseController {
+
+    @Autowired
+    private SubjectService subjectService;
+
+    @ApiOperation(value = "根据声部编号查询声部")
+    @GetMapping("/get/{id}")
+    public Object get(@ApiParam(value = "声部编号", required = true) @PathVariable("id") Long id) {
+        return succeed(subjectService.get(id));
+    }
+
+    @ApiOperation(value = "分页查询声部树状列表")
+    @PostMapping("/queryPageTree")
+    public HttpResponseResult<PageInfo<Subject>> queryPageTree(@RequestBody SubjectQueryInfo queryInfo) {
+        return succeed(subjectService.queryPageTree(queryInfo));
+    }
+
+    @ApiOperation(value = "分页查询声部列表")
+    @GetMapping("/queryPage")
+    public HttpResponseResult<PageInfo<Subject>> queryPage(SubjectQueryInfo queryInfo) {
+        PageInfo<Subject> pageInfo = subjectService.queryPage(queryInfo);
+
+        if (pageInfo.getRows().size() == 0) {
+            return succeed(pageInfo);
+        }
+
+        Map<Long, Subject> map =
+                subjectService.findBySubjectByIdList(pageInfo.getRows().stream().map(Subject::getParentSubjectId).collect(Collectors.toList())).stream()
+                .collect(Collectors.toMap(Subject::getId, t -> t));
+
+        pageInfo.getRows().forEach(row -> {
+            if (row.getParentSubjectId() != null && row.getParentSubjectId() > 0) {
+                row.setParentSubjectName(map.get(row.getParentSubjectId()).getName());
+            }
+        });
+        return succeed(pageInfo);
+    }
+}

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

@@ -85,7 +85,7 @@ public class TenantGroupController {
         TenantGroupWrapper.TenantGroup group = TenantGroupWrapper.TenantGroup.from(tenantGroup.jsonString());
         group.setCreateBy(sysUser.getId());
         group.setTenantId(sysUser.getTenantId());
-        tenantGroupService.update(group);
+        tenantGroupService.update(group, tenantGroup.getImGroupCreate());
 
         return R.defaultR();
     }
@@ -96,4 +96,10 @@ public class TenantGroupController {
 
         return R.from(tenantGroupService.delete(id));
     }
+
+    @ApiOperation(value = "处理机构小组交接", notes = "处理机构小组交接")
+    @PostMapping("/adjustTenantGroup")
+    public R<Boolean> adjustTenantGroup(@RequestBody TenantGroupWrapper.AdjustTenantGroup adjustTenantGroup) {
+        return R.from(tenantGroupService.adjustTenantGroup(adjustTenantGroup));
+    }
 }

+ 3 - 0
cooleshow-app/src/main/java/com/yonge/cooleshow/tenant/vo/TenantGroupVo.java

@@ -57,6 +57,9 @@ public class TenantGroupVo {
         @ApiModelProperty("群成员列表")
         private List<Long> userIds = new ArrayList<>();
 
+        @ApiModelProperty("是否创建群聊")
+        private Boolean imGroupCreate = false;
+
         public String jsonString() {
             return JSON.toJSONString(this);
         }

+ 35 - 0
cooleshow-user/user-admin/src/main/java/com/yonge/cooleshow/admin/controller/open/OpenTenantGroupController.java

@@ -0,0 +1,35 @@
+package com.yonge.cooleshow.admin.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("/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));
+    }
+}

+ 2 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/TenantGroupService.java

@@ -40,9 +40,10 @@ public interface TenantGroupService extends IService<TenantGroup>  {
     /**
      * 更新
      * @param tenantGroup TenantGroupWrapper.TenantGroup
+     * @param imGroupCreate 是否创建IM群
      * @return Boolean
      */
-    Boolean update(TenantGroupWrapper.TenantGroup tenantGroup);
+    Boolean update(TenantGroupWrapper.TenantGroup tenantGroup, Boolean imGroupCreate);
 
     Boolean delete(Long id);
 

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

@@ -34,19 +34,12 @@ import com.yonge.cooleshow.biz.dal.wrapper.im.ImGroupWrapper;
 import com.yonge.toolset.base.exception.BizException;
 import com.yonge.toolset.mybatis.support.PageUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -106,8 +99,20 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
             Map<Long, Integer> groupBy =
                     userCounts.stream().collect(Collectors.toMap(StudentWrapper.UserCount::getTenantGroupId
                             , StudentWrapper.UserCount::getCount));
+
+            List<String> imGroupId = records.stream().map(TenantGroupWrapper.TenantGroup::getImGroupId)
+                    .filter(Objects::nonNull).collect(Collectors.toList());
+            List<String> existImgGroupIds = new ArrayList<>();
+            if (imGroupId.isEmpty()) {
+                List<String> imgGroupIds = imGroupService.lambdaQuery()
+                        .in(ImGroup::getId, imGroupId)
+                        .list().stream().map(ImGroup::getId).collect(Collectors.toList());
+                existImgGroupIds.addAll(imgGroupIds);
+            }
+
             for (TenantGroupWrapper.TenantGroup record : records) {
                 record.setGroupUserCount(groupBy.getOrDefault(record.getId(), 0));
+                record.setImGroupExist(existImgGroupIds.contains(record.getImGroupId()));
             }
         }
         return iPage;
@@ -131,9 +136,8 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
             throw new BizException("小组名称已存在");
         }
         this.save(entity);
-        List<Long> userIds = tenantGroup.getUserIds();
-        // 有群成员才建立机构小组群
-        if (!userIds.isEmpty()) {
+        Long adminId = tenantGroup.getAdminId();
+        if (adminId != null) {
             // 建群
             try {
                 ImGroupWrapper.ImGroup imGroup = new ImGroupWrapper.ImGroup();
@@ -149,16 +153,19 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
                 throw new BizException("创建机构小组群失败");
             }
             // 加群成员
-            try {
-                imGroupService.addGroupMember(entity.getImGroupId(), new HashSet<>(userIds));
-            } catch (Exception e) {
-                log.error("加入机构小组群失败", e);
-                throw new BizException("加入机构小组群失败");
+            List<Long> userIds = tenantGroup.getUserIds();
+            if (CollectionUtils.isNotEmpty(userIds)) {
+                try {
+                    imGroupService.addGroupMember(entity.getImGroupId(), new HashSet<>(userIds));
+                } catch (Exception e) {
+                    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()));
             }
-            studentDao.update(null, Wrappers.<Student>lambdaUpdate()
-                    .in(Student::getUserId, userIds)
-                    .eq(Student::getTenantId, tenantGroup.getTenantId())
-                    .set(Student::getTenantGroupId, entity.getId()));
         }
         return true;
     }
@@ -171,7 +178,7 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
      */
     @Transactional(rollbackFor = Exception.class)
     @Override
-    public Boolean update(TenantGroupWrapper.TenantGroup tenantGroup) {
+    public Boolean update(TenantGroupWrapper.TenantGroup tenantGroup, Boolean imGroupCreate) {
         TenantGroup oldGroup = this.getById(tenantGroup.getId());
 
         Integer count = this.lambdaQuery()
@@ -184,48 +191,20 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
         }
 
         TenantGroup entity = JSON.parseObject(tenantGroup.jsonString(), TenantGroup.class);
-        // 修改小组负责人,调整群主,更换群主需要新的群主为该群成员
-        if (oldGroup.getImGroupId() != null && !oldGroup.getAdminId().equals(entity.getAdminId())) {
-
-            // 如果新负责人不在群,先加入群
-            Integer toAdminInThisGroup = imGroupMemberService.lambdaQuery()
-                    .eq(ImGroupMember::getGroupId, oldGroup.getImGroupId())
-                    .eq(ImGroupMember::getUserId, entity.getAdminId())
-                    .count();
-            if (toAdminInThisGroup == 0) {
-                // 新负责人加入群
-                try {
-                    SysUser newTeacher = sysUserService.getByUserId(entity.getAdminId());
-                    ImGroupMember imGroupMember = new ImGroupMember();
-                    imGroupMember.setGroupId(oldGroup.getImGroupId());
-                    imGroupMember.setUserId(entity.getAdminId());
-                    imGroupMember.setRoleType(ImGroupMemberRoleType.TEACHER);
-                    imGroupMember.setAvatar(newTeacher.getAvatar());
-                    imGroupMember.setNickname(newTeacher.getUsername());
-                    imGroupMember.setIsAdmin(false);
-                    imGroupMember.setRoleType(ImGroupMemberRoleType.TEACHER);
-
-                    imGroupMemberService.join(Collections.singletonList(imGroupMember), oldGroup.getImGroupId());
-                } catch (Exception e) {
-                    log.error("负责人加入群失败", e);
-                    throw new BizException("负责人加入群失败");
-                }
-            }
-
-            ImGroup oldImGroup = imGroupService.getById(oldGroup.getImGroupId());
-            if (oldImGroup != null) {
-                try {
-                    imGroupCoreService.changeGroupOwner(oldGroup.getImGroupId(),
-                            String.valueOf(tenantGroup.getAdminId()),
-                            String.valueOf(oldGroup.getAdminId()));
-                    imGroupCoreService.groupQuit(oldGroup.getAdminId(), ClientEnum.TEACHER.getCode(),
-                            oldGroup.getImGroupId(), true);
-                } catch (Exception e) {
-                    log.error("更换群主失败", e);
-                    throw new BizException("更换群主失败");
-                }
+        entity.setImGroupId(oldGroup.getImGroupId());
+        // 是否建群
+        if (Boolean.TRUE.equals(imGroupCreate)) {
+            String oldImGroupId = Optional.ofNullable(oldGroup.getImGroupId()).orElse("-1");
+            ImGroup imGroup = imGroupService.getById(oldImGroupId);
+            // 群被删除过,并且需要重新建群
+            if (imGroup == null) {
+                SysUser sysUser = sysUserService.getByUserId(entity.getAdminId());
+                String imGroupId = createImGroup(entity.getAdminId(), sysUser.getUsername());
+                entity.setImGroupId(imGroupId);
             }
         }
+        // 修改小组负责人,调整群主,更换群主需要新的群主为该群成员
+        changeGroupOwner(tenantGroup, oldGroup, entity);
         QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
         queryWrapper.lambda()
                 .eq(Student::getTenantId, tenantGroup.getTenantId())
@@ -238,15 +217,19 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
         List<Long> removeGroupUsers = oldGroupUsers.stream()
                 .filter(next -> !newGroupUsers.contains(next)).collect(Collectors.toList());
         // 移除的群成员,退群
+        ImGroup imGroup = imGroupService.getById(Optional.ofNullable(entity.getImGroupId()).orElse("-1"));
         if (!removeGroupUsers.isEmpty()) {
-            try {
-                for (Long removeUserId : removeGroupUsers) {
-                    imGroupCoreService.groupQuit(removeUserId, ClientEnum.STUDENT.getCode(), oldGroup.getImGroupId(),
-                            true);
+            if (imGroup != null) {
+                try {
+                    for (Long removeUserId : removeGroupUsers) {
+                        imGroupCoreService.groupQuit(removeUserId, ClientEnum.STUDENT.getCode(),
+                                oldGroup.getImGroupId(),
+                                true);
+                    }
+                } catch (Exception e) {
+                    log.error("群成员移出群失败", e);
+                    throw new BizException("群成员移出群失败");
                 }
-            } catch (Exception e) {
-                log.error("群成员移出群失败", e);
-                throw new BizException("群成员移出群失败");
             }
             studentDao.update(null, Wrappers.<Student>lambdaUpdate()
                     .in(Student::getUserId, removeGroupUsers)
@@ -258,11 +241,13 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
                 .collect(Collectors.toList());
         if (!newAddGroupUsers.isEmpty()) {
             // 加群成员
-            try {
-                imGroupService.addGroupMember(oldGroup.getImGroupId(), new HashSet<>(newAddGroupUsers));
-            } catch (Exception e) {
-                log.error("加入机构小组群失败", e);
-                throw new BizException("加入机构小组群失败");
+            if (imGroup != null) {
+                try {
+                    imGroupService.addGroupMember(oldGroup.getImGroupId(), new HashSet<>(newAddGroupUsers));
+                } catch (Exception e) {
+                    log.error("加入机构小组群失败", e);
+                    throw new BizException("加入机构小组群失败");
+                }
             }
             studentDao.update(null, Wrappers.<Student>lambdaUpdate()
                     .in(Student::getUserId, newAddGroupUsers)
@@ -279,6 +264,11 @@ 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);
@@ -405,7 +395,7 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
                 }
                 this.lambdaUpdate()
                         .set(TenantGroup::getAdminId, toTeacher)
-                        .set(imGroup == null, TenantGroup::getImGroupId, "-1")
+                        .set(imGroup == null, TenantGroup::getImGroupId, null)
                         .eq(TenantGroup::getId, detail.getTenantGroupId())
                         .update();
             } else if (Boolean.TRUE.equals(detail.getDismiss())) {
@@ -418,9 +408,86 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
                         throw new BizException("解散群失败");
                     }
                 }
-                this.removeById(detail.getTenantGroupId());
+                this.lambdaUpdate()
+                        .set(TenantGroup::getAdminId, toTeacher)
+                        .set(TenantGroup::getImGroupId, null)
+                        .eq(TenantGroup::getId, detail.getTenantGroupId())
+                        .update();
             }
         }
         return true;
     }
+
+    public String createImGroup(Long groupAdmin, String userName) {
+        try {
+            ImGroupWrapper.ImGroup imGroup = new ImGroupWrapper.ImGroup();
+            imGroup.setId(IdWorker.getId());
+            imGroup.setCreateBy(groupAdmin);
+            imGroup.setType(ImGroupType.ORG.getCode());
+            imGroup.setName(userName);
+            return imGroupService.create(imGroup);
+        } catch (Exception e) {
+            log.error("创建机构小组群失败", e);
+            throw new BizException("创建机构小组群失败");
+        }
+    }
+
+    private void changeGroupOwner(TenantGroupWrapper.TenantGroup tenantGroup, TenantGroup oldGroup,
+                                  TenantGroup newGroup) {
+        if (newGroup.getAdminId() == null || newGroup.getAdminId().equals(oldGroup.getAdminId())) {
+            return;
+        }
+        String imGroupId = Optional.ofNullable(newGroup.getImGroupId()).orElse("-1");
+        ImGroup imGroup = imGroupService.getById(imGroupId);
+        if (imGroup == null) {
+            // 群不存在
+            return;
+        }
+        // 如果新负责人不在群,先加入群
+        ImGroupMember groupMember = imGroupMemberService.lambdaQuery()
+                .eq(ImGroupMember::getGroupId, oldGroup.getImGroupId())
+                .eq(ImGroupMember::getRoleType, ImGroupMemberRoleType.TEACHER)
+                .eq(ImGroupMember::getUserId, newGroup.getAdminId())
+                .eq(ImGroupMember::getIsAdmin, true)
+                .last("limit 1").one();
+        if (groupMember != null) {
+            return;
+        }
+        // 新负责人加入群
+        try {
+            SysUser newTeacher = sysUserService.getByUserId(newGroup.getAdminId());
+            ImGroupMember imGroupMember = new ImGroupMember();
+            imGroupMember.setGroupId(oldGroup.getImGroupId());
+            imGroupMember.setUserId(newGroup.getAdminId());
+            imGroupMember.setRoleType(ImGroupMemberRoleType.TEACHER);
+            imGroupMember.setAvatar(newTeacher.getAvatar());
+            imGroupMember.setNickname(newTeacher.getUsername());
+            imGroupMember.setIsAdmin(false);
+            imGroupMember.setRoleType(ImGroupMemberRoleType.TEACHER);
+
+            imGroupMemberService.join(Collections.singletonList(imGroupMember), oldGroup.getImGroupId());
+        } catch (Exception e) {
+            log.error("负责人加入群失败", e);
+            throw new BizException("负责人加入群失败");
+        }
+
+        try {
+            imGroupCoreService.changeGroupOwner(oldGroup.getImGroupId(),
+                    String.valueOf(tenantGroup.getAdminId()),
+                    String.valueOf(oldGroup.getAdminId()));
+            imGroupCoreService.groupQuit(oldGroup.getAdminId(), ClientEnum.TEACHER.getCode(),
+                    oldGroup.getImGroupId(), true);
+        } catch (Exception e) {
+            log.error("更换群主失败", e);
+            throw new BizException("更换群主失败");
+        }
+    }
+
+    public List<Student> queryStudent(Long tenantId, Long tenantGroupId) {
+        QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda()
+                .eq(Student::getTenantId, tenantId)
+                .eq(Student::getTenantGroupId, tenantGroupId);
+        return studentDao.selectList(queryWrapper);
+    }
 }

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

@@ -81,6 +81,9 @@ public class TenantGroupWrapper {
         @ApiModelProperty("IM群聊ID")
         private String imGroupId;
 
+        @ApiModelProperty("IM群聊是否存在")
+        private Boolean imGroupExist;
+
         @ApiModelProperty("创建人")
         private Long createBy;
 

+ 46 - 0
cooleshow-user/user-teacher/src/main/java/com/yonge/cooleshow/teacher/controller/TenantGroupController.java

@@ -0,0 +1,46 @@
+package com.yonge.cooleshow.teacher.controller;
+
+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.auth.api.client.SysUserFeignService;
+import com.yonge.cooleshow.auth.api.entity.SysUser;
+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;
+
+import javax.annotation.Resource;
+
+@Slf4j
+@Validated
+@RestController
+@RequestMapping("/tenantGroup")
+@Api(tags = "机构小组表")
+public class TenantGroupController {
+
+    @Autowired
+    private TenantGroupService tenantGroupService;
+
+    @Resource
+    private SysUserFeignService sysUserFeignService;
+
+    @ApiOperation(value = "查询分页", notes = "机构小组表- 传入 TenantGroupWrapper.TenantGroupQuery")
+    @PostMapping("/page")
+    public R<PageInfo<TenantGroupWrapper.TenantGroup>> page(@RequestBody TenantGroupWrapper.TenantGroupQuery query) {
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        query.setTenantId(sysUser.getTenantId());
+        IPage<TenantGroupWrapper.TenantGroup> pages = tenantGroupService.selectPage(QueryInfo.getPage(query), query);
+
+        return R.from(QueryInfo.pageInfo(pages));
+    }
+
+}

+ 63 - 0
cooleshow-user/user-teacher/src/main/java/com/yonge/cooleshow/teacher/controller/open/OpenSubjectController.java

@@ -0,0 +1,63 @@
+package com.yonge.cooleshow.teacher.controller.open;
+
+import com.yonge.cooleshow.biz.dal.entity.Subject;
+import com.yonge.cooleshow.biz.dal.queryInfo.SubjectQueryInfo;
+import com.yonge.cooleshow.biz.dal.service.SubjectService;
+import com.yonge.cooleshow.common.controller.BaseController;
+import com.yonge.cooleshow.common.entity.HttpResponseResult;
+import com.yonge.toolset.base.page.PageInfo;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+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;
+
+import java.util.Map;
+import java.util.stream.Collectors;
+
+@RequestMapping("/open/subject")
+@Api(tags = "声部服务")
+@RestController
+public class OpenSubjectController extends BaseController {
+
+    @Autowired
+    private SubjectService subjectService;
+
+    @ApiOperation(value = "根据声部编号查询声部")
+    @GetMapping("/get/{id}")
+    public Object get(@ApiParam(value = "声部编号", required = true) @PathVariable("id") Long id) {
+        return succeed(subjectService.get(id));
+    }
+
+    @ApiOperation(value = "分页查询声部树状列表")
+    @PostMapping("/queryPageTree")
+    public HttpResponseResult<PageInfo<Subject>> queryPageTree(@RequestBody SubjectQueryInfo queryInfo) {
+        return succeed(subjectService.queryPageTree(queryInfo));
+    }
+
+    @ApiOperation(value = "分页查询声部列表")
+    @GetMapping("/queryPage")
+    public HttpResponseResult<PageInfo<Subject>> queryPage(SubjectQueryInfo queryInfo) {
+        PageInfo<Subject> pageInfo = subjectService.queryPage(queryInfo);
+
+        if (pageInfo.getRows().size() == 0) {
+            return succeed(pageInfo);
+        }
+
+        Map<Long, Subject> map =
+                subjectService.findBySubjectByIdList(pageInfo.getRows().stream().map(Subject::getParentSubjectId).collect(Collectors.toList())).stream()
+                .collect(Collectors.toMap(Subject::getId, t -> t));
+
+        pageInfo.getRows().forEach(row -> {
+            if (row.getParentSubjectId() != null && row.getParentSubjectId() > 0) {
+                row.setParentSubjectName(map.get(row.getParentSubjectId()).getName());
+            }
+        });
+        return succeed(pageInfo);
+    }
+}

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

@@ -86,7 +86,7 @@ public class TenantGroupController {
         TenantGroupWrapper.TenantGroup group = TenantGroupWrapper.TenantGroup.from(tenantGroup.jsonString());
         group.setCreateBy(sysUser.getId());
         group.setTenantId(sysUser.getTenantId());
-        tenantGroupService.update(group);
+        tenantGroupService.update(group, tenantGroup.getImGroupCreate());
 
         return R.defaultR();
     }

+ 35 - 0
cooleshow-user/user-tenant/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("/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));
+    }
+}

+ 3 - 0
cooleshow-user/user-tenant/src/main/java/com/yonge/cooleshow/tenant/vo/TenantGroupVo.java

@@ -60,6 +60,9 @@ public class TenantGroupVo {
         @ApiModelProperty("群成员列表")
         private List<Long> userIds = new ArrayList<>();
 
+        @ApiModelProperty("是否创建群聊")
+        private Boolean imGroupCreate = false;
+
         public String jsonString() {
             return JSON.toJSONString(this);
         }