|  | @@ -1,6 +1,9 @@
 | 
	
		
			
				|  |  |  package com.yonge.cooleshow.biz.dal.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
	
		
			
				|  |  | +import com.google.common.collect.Lists;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.auth.config.AppGlobalServiceConfig;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.config.RongCloudConfig;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dao.CourseScheduleStudentPaymentDao;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.dao.ImGroupDao;
 | 
	
	
		
			
				|  | @@ -10,21 +13,35 @@ import com.yonge.cooleshow.biz.dal.dto.ImGroupSearchDto;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.entity.CourseGroup;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.entity.ImGroup;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.entity.ImGroupMember;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.entity.Teacher;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.enums.ImGroupMemberRoleType;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.biz.dal.enums.ImGroupType;
 | 
	
		
			
				|  |  | -import com.yonge.cooleshow.biz.dal.service.*;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.service.CourseGroupService;
 | 
	
		
			
				|  |  | +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;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.biz.dal.service.TeacherService;
 | 
	
		
			
				|  |  |  import com.yonge.toolset.base.exception.BizException;
 | 
	
		
			
				|  |  | +import com.yonge.toolset.base.util.ThreadPool;
 | 
	
		
			
				|  |  |  import io.rong.models.Result;
 | 
	
		
			
				|  |  |  import io.rong.models.group.GroupMember;
 | 
	
		
			
				|  |  |  import io.rong.models.group.GroupModel;
 | 
	
		
			
				|  |  |  import org.apache.commons.collections.CollectionUtils;
 | 
	
		
			
				|  |  |  import org.slf4j.Logger;
 | 
	
		
			
				|  |  |  import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  | +import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import javax.annotation.Resource;
 | 
	
		
			
				|  |  | -import java.util.*;
 | 
	
		
			
				|  |  | +import java.util.Collections;
 | 
	
		
			
				|  |  | +import java.util.Date;
 | 
	
		
			
				|  |  | +import java.util.List;
 | 
	
		
			
				|  |  | +import java.util.Objects;
 | 
	
		
			
				|  |  | +import java.util.Optional;
 | 
	
		
			
				|  |  | +import java.util.Set;
 | 
	
		
			
				|  |  | +import java.util.UUID;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
		
			
				|  |  |   * 即时通讯群组(ImGroup)表服务实现类
 | 
	
	
		
			
				|  | @@ -47,8 +64,14 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
 | 
	
		
			
				|  |  |      private ImGroupMemberAuditDao imGroupMemberAuditDao;
 | 
	
		
			
				|  |  |      @Resource
 | 
	
		
			
				|  |  |      private SysUserService sysUserService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private ImGroupService imGroupService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private TeacherService teacherService;
 | 
	
		
			
				|  |  |      @Resource
 | 
	
		
			
				|  |  |      private CourseScheduleStudentPaymentDao courseScheduleStudentPaymentDao;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private AppGlobalServiceConfig appGlobalServiceConfig;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public ImGroupDao getDao() {
 | 
	
	
		
			
				|  | @@ -194,5 +217,46 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
 | 
	
		
			
				|  |  |              throw new BizException("退出群聊失败,请联系管理员");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 用户群组信息
 | 
	
		
			
				|  |  | +     *
 | 
	
		
			
				|  |  | +     * @param groupId 群组ID
 | 
	
		
			
				|  |  | +     * @param userId  用户ID
 | 
	
		
			
				|  |  | +     * @return ImGroup
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public ImGroup findGroupInfoById(String groupId, Long userId) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        ImGroup group = imGroupService.getById(groupId);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 异步执行自动加入群组功能
 | 
	
		
			
				|  |  | +        ThreadPool.getExecutor().submit(() -> {
 | 
	
		
			
				|  |  | +            try {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                if (Objects.nonNull(group) && appGlobalServiceConfig.getGroupMemberJoin()) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    // 若用户群组存在,判定用户是否拥有老师身份,自动加入群组
 | 
	
		
			
				|  |  | +                    int count = teacherService.count(Wrappers.<Teacher>lambdaQuery()
 | 
	
		
			
				|  |  | +                            .eq(Teacher::getUserId, userId));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    // 用户是否已加入该群组
 | 
	
		
			
				|  |  | +                    int groupMembers = imGroupMemberService.count(Wrappers.<ImGroupMember>lambdaQuery()
 | 
	
		
			
				|  |  | +                            .eq(ImGroupMember::getGroupId, groupId).eq(ImGroupMember::getUserId, userId));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    if (count > 0 && groupMembers > 0) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                        // 自动加入该群组
 | 
	
		
			
				|  |  | +                        imGroupMemberService.join(Lists.newArrayList(new GroupMember(userId.toString(), groupId, null)), groupId);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            } catch (Exception e) {
 | 
	
		
			
				|  |  | +                log.error("findGroupInfoById groupId={}, userId={}", group, userId, e);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return group;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 |