|  | @@ -2,12 +2,25 @@ package com.yonge.cooleshow.biz.dal.service.impl;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 |  |  import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 | 
											
												
													
														|  |  import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 |  |  import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
											
												
													
														|  | 
 |  | +import com.google.common.collect.Maps;
 | 
											
												
													
														|  | 
 |  | +import com.yonge.cooleshow.biz.dal.entity.ImGroup;
 | 
											
												
													
														|  |  import com.yonge.cooleshow.biz.dal.entity.StudentTotal;
 |  |  import com.yonge.cooleshow.biz.dal.entity.StudentTotal;
 | 
											
												
													
														|  | 
 |  | +import com.yonge.cooleshow.biz.dal.entity.SysUser;
 | 
											
												
													
														|  |  import com.yonge.cooleshow.biz.dal.entity.TeacherTotal;
 |  |  import com.yonge.cooleshow.biz.dal.entity.TeacherTotal;
 | 
											
												
													
														|  | 
 |  | +import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
 | 
											
												
													
														|  | 
 |  | +import com.yonge.cooleshow.biz.dal.enums.ImGroupMemberRoleType;
 | 
											
												
													
														|  | 
 |  | +import com.yonge.cooleshow.biz.dal.enums.MessageTypeEnum;
 | 
											
												
													
														|  | 
 |  | +import com.yonge.cooleshow.biz.dal.mapper.SysUserMapper;
 | 
											
												
													
														|  | 
 |  | +import com.yonge.cooleshow.biz.dal.service.ImGroupMemberService;
 | 
											
												
													
														|  | 
 |  | +import com.yonge.cooleshow.biz.dal.service.ImGroupService;
 | 
											
												
													
														|  |  import com.yonge.cooleshow.biz.dal.service.StudentTotalService;
 |  |  import com.yonge.cooleshow.biz.dal.service.StudentTotalService;
 | 
											
												
													
														|  |  import com.yonge.cooleshow.biz.dal.service.TeacherTotalService;
 |  |  import com.yonge.cooleshow.biz.dal.service.TeacherTotalService;
 | 
											
												
													
														|  |  import com.yonge.cooleshow.common.entity.HttpResponseResult;
 |  |  import com.yonge.cooleshow.common.entity.HttpResponseResult;
 | 
											
												
													
														|  |  import com.yonge.cooleshow.common.enums.YesOrNoEnum;
 |  |  import com.yonge.cooleshow.common.enums.YesOrNoEnum;
 | 
											
												
													
														|  | 
 |  | +import com.yonge.toolset.base.util.ThreadPool;
 | 
											
												
													
														|  | 
 |  | +import com.yonge.toolset.thirdparty.message.MessageSenderPluginContext;
 | 
											
												
													
														|  | 
 |  | +import io.rong.models.group.GroupMember;
 | 
											
												
													
														|  | 
 |  | +import lombok.extern.slf4j.Slf4j;
 | 
											
												
													
														|  |  import org.redisson.api.RedissonClient;
 |  |  import org.redisson.api.RedissonClient;
 | 
											
												
													
														|  |  import org.springframework.beans.factory.annotation.Autowired;
 |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
											
												
													
														|  |  import org.springframework.stereotype.Service;
 |  |  import org.springframework.stereotype.Service;
 | 
											
										
											
												
													
														|  | @@ -15,7 +28,11 @@ import com.yonge.cooleshow.biz.dal.entity.StudentStar;
 | 
											
												
													
														|  |  import com.yonge.cooleshow.biz.dal.dao.StudentStarDao;
 |  |  import com.yonge.cooleshow.biz.dal.dao.StudentStarDao;
 | 
											
												
													
														|  |  import com.yonge.cooleshow.biz.dal.service.StudentStarService;
 |  |  import com.yonge.cooleshow.biz.dal.service.StudentStarService;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +import java.util.List;
 | 
											
												
													
														|  | 
 |  | +import java.util.Map;
 | 
											
												
													
														|  | 
 |  | +import java.util.Objects;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +@Slf4j
 | 
											
												
													
														|  |  @Service
 |  |  @Service
 | 
											
												
													
														|  |  public class StudentStarServiceImpl extends ServiceImpl<StudentStarDao, StudentStar> implements StudentStarService {
 |  |  public class StudentStarServiceImpl extends ServiceImpl<StudentStarDao, StudentStar> implements StudentStarService {
 | 
											
												
													
														|  |      @Autowired
 |  |      @Autowired
 | 
											
										
											
												
													
														|  | @@ -24,6 +41,14 @@ public class StudentStarServiceImpl extends ServiceImpl<StudentStarDao, StudentS
 | 
											
												
													
														|  |      private StudentTotalService studentTotalService;
 |  |      private StudentTotalService studentTotalService;
 | 
											
												
													
														|  |      @Autowired
 |  |      @Autowired
 | 
											
												
													
														|  |      private TeacherTotalService teacherTotalService;
 |  |      private TeacherTotalService teacherTotalService;
 | 
											
												
													
														|  | 
 |  | +    @Autowired
 | 
											
												
													
														|  | 
 |  | +    private ImGroupMemberService imGroupMemberService;
 | 
											
												
													
														|  | 
 |  | +    @Autowired
 | 
											
												
													
														|  | 
 |  | +    private ImGroupService imGroupService;
 | 
											
												
													
														|  | 
 |  | +    @Autowired
 | 
											
												
													
														|  | 
 |  | +    private SysUserMapper sysUserMapper;
 | 
											
												
													
														|  | 
 |  | +    @Autowired
 | 
											
												
													
														|  | 
 |  | +    private SysMessageServiceImpl sysMessageService;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      @Override
 |  |      @Override
 | 
											
												
													
														|  |      public StudentStar getByStudentIdAndTeacherId(Long studentId, Long teacherId) {
 |  |      public StudentStar getByStudentIdAndTeacherId(Long studentId, Long teacherId) {
 | 
											
										
											
												
													
														|  | @@ -42,6 +67,10 @@ public class StudentStarServiceImpl extends ServiceImpl<StudentStarDao, StudentS
 | 
											
												
													
														|  |              save(studentStar);
 |  |              save(studentStar);
 | 
											
												
													
														|  |              studentTotal.setStarTeacherNum(studentTotal.getStarTeacherNum() + 1);
 |  |              studentTotal.setStarTeacherNum(studentTotal.getStarTeacherNum() + 1);
 | 
											
												
													
														|  |              teacherTotal.setFansNum(teacherTotal.getFansNum() + 1);
 |  |              teacherTotal.setFansNum(teacherTotal.getFansNum() + 1);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            // 关注老师,自动加入老师粉丝群
 | 
											
												
													
														|  | 
 |  | +            studentAutoJoinTeacherFansGroup(studentId, teacherId);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |          } else if (YesOrNoEnum.NO.equals(starStatus) && null != studentStar) {
 |  |          } else if (YesOrNoEnum.NO.equals(starStatus) && null != studentStar) {
 | 
											
												
													
														|  |              remove(Wrappers.<StudentStar>lambdaQuery()
 |  |              remove(Wrappers.<StudentStar>lambdaQuery()
 | 
											
												
													
														|  |                      .eq(StudentStar::getStudentId, studentId)
 |  |                      .eq(StudentStar::getStudentId, studentId)
 | 
											
										
											
												
													
														|  | @@ -54,4 +83,52 @@ public class StudentStarServiceImpl extends ServiceImpl<StudentStarDao, StudentS
 | 
											
												
													
														|  |          teacherTotalService.updateTotalCache(teacherTotal);
 |  |          teacherTotalService.updateTotalCache(teacherTotal);
 | 
											
												
													
														|  |          return HttpResponseResult.succeed(true);
 |  |          return HttpResponseResult.succeed(true);
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +    /**
 | 
											
												
													
														|  | 
 |  | +     * 学生关注老师,自动加入粉丝群
 | 
											
												
													
														|  | 
 |  | +     * @param studentId 学生ID
 | 
											
												
													
														|  | 
 |  | +     * @param teacherId 老师ID
 | 
											
												
													
														|  | 
 |  | +     */
 | 
											
												
													
														|  | 
 |  | +    private void studentAutoJoinTeacherFansGroup(Long studentId, Long teacherId) {
 | 
											
												
													
														|  | 
 |  | +        ThreadPool.getExecutor().submit(() -> {
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            try {
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                // 查询老师粉丝群
 | 
											
												
													
														|  | 
 |  | +                ImGroup imGroup = imGroupService.lambdaQuery()
 | 
											
												
													
														|  | 
 |  | +                        .eq(ImGroup::getCreateBy, teacherId)
 | 
											
												
													
														|  | 
 |  | +                        .eq(ImGroup::getAutoPassFlag, true)
 | 
											
												
													
														|  | 
 |  | +                        .one();
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                if (Objects.nonNull(imGroup)) {
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                    //处理本地群成员
 | 
											
												
													
														|  | 
 |  | +                    List<GroupMember> groupMembers = imGroupMemberService.initGroupMember(imGroup.getId(),
 | 
											
												
													
														|  | 
 |  | +                            studentId, false, ImGroupMemberRoleType.STUDENT);
 | 
											
												
													
														|  | 
 |  | +                    //同步群成员数量
 | 
											
												
													
														|  | 
 |  | +                    imGroupService.getDao().updateMemberNum(imGroup.getId());
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                    //加入融云群
 | 
											
												
													
														|  | 
 |  | +                    imGroupMemberService.join(groupMembers, imGroup.getId());
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                    // 发送通知消息
 | 
											
												
													
														|  | 
 |  | +                    SysUser student = sysUserMapper.selectById(studentId);
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                    if (Objects.nonNull(student)) {
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                        Map<Long, String> receivers = Maps.newHashMap();
 | 
											
												
													
														|  | 
 |  | +                        receivers.put(student.getId(), student.getPhone());
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                        sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.STUDENT_AUTOJOIN_FANSGROUP,
 | 
											
												
													
														|  | 
 |  | +                                receivers, null, 0, null, ClientEnum.STUDENT.getCode(), imGroup.getName());
 | 
											
												
													
														|  | 
 |  | +                    }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            } catch (Exception e) {
 | 
											
												
													
														|  | 
 |  | +                log.error("StudentStar studentId={}, teacherId={}", studentId, teacherId);
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        });
 | 
											
												
													
														|  | 
 |  | +    }
 | 
											
												
													
														|  |  }
 |  |  }
 |