|
@@ -1,11 +1,15 @@
|
|
|
package com.yonge.cooleshow.biz.dal.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.yonge.cooleshow.auth.config.AppGlobalServiceConfig;
|
|
|
+import com.microsvc.toolkit.common.response.paging.QueryInfo;
|
|
|
import com.microsvc.toolkit.middleware.im.ImPluginContext;
|
|
|
import com.microsvc.toolkit.middleware.im.message.GroupMemberWrapper;
|
|
|
import com.microsvc.toolkit.middleware.im.message.MessageWrapper;
|
|
@@ -31,6 +35,8 @@ import com.yonge.cooleshow.biz.dal.service.ImUserFriendService;
|
|
|
import com.yonge.cooleshow.biz.dal.service.StudentStarService;
|
|
|
import com.yonge.cooleshow.biz.dal.service.SysUserService;
|
|
|
import com.yonge.cooleshow.biz.dal.service.TeacherService;
|
|
|
+import com.yonge.cooleshow.biz.dal.dto.search.StudentSearch;
|
|
|
+import com.yonge.cooleshow.biz.dal.dto.search.TeacherSearch;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.CourseGroup;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.ImGroup;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.ImGroupMember;
|
|
@@ -41,18 +47,14 @@ import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
|
|
|
import com.yonge.cooleshow.biz.dal.enums.ImGroupMemberRoleType;
|
|
|
import com.yonge.cooleshow.biz.dal.enums.ImGroupType;
|
|
|
import com.yonge.cooleshow.biz.dal.enums.RoleEnum;
|
|
|
-import com.yonge.cooleshow.biz.dal.service.CourseGroupService;
|
|
|
-import com.yonge.cooleshow.biz.dal.service.CustomerServiceBatchSendingService;
|
|
|
-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.StudentStarService;
|
|
|
-import com.yonge.cooleshow.biz.dal.service.SysConfigService;
|
|
|
-import com.yonge.cooleshow.biz.dal.service.SysUserService;
|
|
|
-import com.yonge.cooleshow.biz.dal.service.TeacherService;
|
|
|
+import com.yonge.cooleshow.biz.dal.service.*;
|
|
|
+import com.yonge.cooleshow.biz.dal.vo.StudentVo;
|
|
|
+import com.yonge.cooleshow.biz.dal.vo.TeacherVo;
|
|
|
import com.yonge.cooleshow.biz.dal.wrapper.im.ImGroupWrapper;
|
|
|
+import com.yonge.cooleshow.common.constant.SysConfigConstant;
|
|
|
import com.yonge.toolset.base.exception.BizException;
|
|
|
import com.yonge.toolset.base.util.ThreadPool;
|
|
|
+import com.yonge.toolset.mybatis.support.PageUtil;
|
|
|
import io.rong.RongCloud;
|
|
|
import io.rong.methods.message.history.History;
|
|
|
import io.rong.models.Result;
|
|
@@ -150,6 +152,9 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
@Autowired
|
|
|
private SysConfigService sysConfigService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private StudentService studentService;
|
|
|
+
|
|
|
@Override
|
|
|
public ImGroupDao getDao() {
|
|
|
return this.baseMapper;
|
|
@@ -251,6 +256,7 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
imGroup.setMemberNum(1);
|
|
|
imGroup.setCreateTime(now);
|
|
|
imGroup.setUpdateTime(now);
|
|
|
+ imGroup.setImg(sysConfigService.findConfigValue(SysConfigConstant.ICON_FANS_GROUP_DEFAULT));
|
|
|
String imGroupId = UUID.randomUUID() + imGroup.getType().getCode();
|
|
|
imGroup.setId(imGroupId);
|
|
|
ImGroup group = JSON.parseObject(JSON.toJSONString(imGroup), ImGroup.class);
|
|
@@ -265,7 +271,7 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
}
|
|
|
|
|
|
//创建融云群
|
|
|
- this.rtcCreate(imGroup.getCreateBy(),imGroupId,imGroup.getName());
|
|
|
+ this.rtcCreate(imGroup.getCreateBy(), imGroupId, imGroup.getName(),imGroup.getImg());
|
|
|
//加入融云群
|
|
|
imGroupMemberService.join(groupMembers,imGroupId);
|
|
|
}
|
|
@@ -310,6 +316,7 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
imGroup.setMemberNum(studentIds.size() + 1);
|
|
|
imGroup.setName(courseGroup.getName());
|
|
|
imGroup.setType(ImGroupType.COURSE);
|
|
|
+ imGroup.setImg(sysConfigService.findConfigValue(SysConfigConstant.ICON_COURSE_GROUP_DEFAULT));
|
|
|
imGroup.setCreateTime(now);
|
|
|
imGroup.setUpdateTime(now);
|
|
|
String imGroupId = UUID.randomUUID() + imGroup.getType().getCode();
|
|
@@ -328,7 +335,7 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
ImGroupMemberRoleType.STUDENT));
|
|
|
}
|
|
|
//创建融云群
|
|
|
- this.rtcCreate(courseGroup.getTeacherId(), imGroupId, imGroup.getName());
|
|
|
+ this.rtcCreate(courseGroup.getTeacherId(), imGroupId, imGroup.getName(),imGroup.getImg());
|
|
|
//加入融云群
|
|
|
imGroupMemberService.join(groupMembers, imGroupId);
|
|
|
return imGroupId;
|
|
@@ -336,12 +343,12 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
|
|
|
|
|
|
//创建融云群
|
|
|
- private void rtcCreate(Long userId, String imGroupId, String imGroupName) throws Exception {
|
|
|
- rtcCreate(userId, imGroupId, imGroupName, ClientEnum.TEACHER);
|
|
|
+ private void rtcCreate(Long userId, String imGroupId, String imGroupName,String img) throws Exception {
|
|
|
+ rtcCreate(userId, imGroupId, imGroupName, ClientEnum.TEACHER,img);
|
|
|
}
|
|
|
|
|
|
//创建融云群
|
|
|
- private void rtcCreate(Long userId, String imGroupId, String imGroupName, ClientEnum clientType) throws Exception {
|
|
|
+ private void rtcCreate(Long userId, String imGroupId, String imGroupName, ClientEnum clientType,String img) throws Exception {
|
|
|
//创建群
|
|
|
SysUser user = sysUserService.findUserById(userId);
|
|
|
|
|
@@ -355,7 +362,7 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
.groupId(imGroupId)
|
|
|
.userId(userId)
|
|
|
.clientType(clientType.getCode())
|
|
|
- .avatar(null)
|
|
|
+ .avatar(img)
|
|
|
.nickname(user.getUsername())
|
|
|
.isAdmin(true)
|
|
|
.imUserId(getImUserId(userId.toString(), clientType.getCode()))
|
|
@@ -491,13 +498,7 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
.eq(ImGroupMember::getRoleType, roleType)
|
|
|
.one();
|
|
|
|
|
|
- String imUserId = String.valueOf(userId);
|
|
|
- if (Objects.nonNull(groupMember)
|
|
|
- && ImGroupMemberRoleType.STUDENT == groupMember.getRoleType()) {
|
|
|
-
|
|
|
- imUserId = MessageFormat.format("{0}:{1}", imUserId, ClientEnum.STUDENT.name());
|
|
|
- }
|
|
|
-
|
|
|
+ String imUserId = imGroupService.getImUserId( String.valueOf(groupMember.getUserId()), groupMember.getRoleType().getCode());
|
|
|
if (imGroupMemberService.getDao().delByGroupIdAndUserId(groupId, userId, roleType) < 1) {
|
|
|
throw new BizException("操作失败:用户不在此群组");
|
|
|
}
|
|
@@ -554,6 +555,8 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
imGroup.setName(sysUser.getUsername() + "的粉丝群");
|
|
|
imGroup.setType(ImGroupType.FAN);
|
|
|
imGroup.setCreateTime(new Date());
|
|
|
+
|
|
|
+ imGroup.setImg(sysConfigService.findConfigValue(SysConfigConstant.ICON_FANS_GROUP_DEFAULT));
|
|
|
imGroup.setUpdateTime(new Date());
|
|
|
imGroup.setCreateBy(teacher.getUserId());
|
|
|
String imGroupId = UUID.randomUUID() + imGroup.getType().getCode();
|
|
@@ -566,7 +569,7 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
ImGroupMemberRoleType.STUDENT));
|
|
|
}
|
|
|
//创建融云群
|
|
|
- this.rtcCreate(sysUser.getId(), imGroupId, imGroup.getName());
|
|
|
+ this.rtcCreate(sysUser.getId(), imGroupId, imGroup.getName(),imGroup.getImg());
|
|
|
//加入融云群
|
|
|
imGroupMemberService.join(groupMembers, imGroupId);
|
|
|
|
|
@@ -604,10 +607,8 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
|
|
|
if (Objects.nonNull(groupMember)) {
|
|
|
|
|
|
- String imIdentity = MessageFormat.format("{0}:{1}", String.valueOf(userId),
|
|
|
+ String userKey = imGroupService.getImUserId(String.valueOf(userId),
|
|
|
ClientEnum.STUDENT.name());
|
|
|
- // 缓存用户重新入群标识
|
|
|
- String userKey = MessageFormat.format("{0}:{1}", groupId, imIdentity);
|
|
|
RBucket<Object> bucket = redissonClient.getBucket(userKey);
|
|
|
if (bucket.isExists()) {
|
|
|
return;
|
|
@@ -706,7 +707,7 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
@Override
|
|
|
public void importInfo(List<ImHistoryMessage> info) throws Exception {
|
|
|
|
|
|
- info.stream().forEach(i -> {
|
|
|
+ info.forEach(i -> {
|
|
|
//判断消息类型
|
|
|
Integer type = i.getTargetType();
|
|
|
if (type == 1) {
|
|
@@ -718,13 +719,13 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
//根据发送者分场景讨论
|
|
|
String id = i.getFromUserId();
|
|
|
String imUserId;
|
|
|
- if (id.contains(":student")) {
|
|
|
+ if (id.contains(":STUDENT")) {
|
|
|
String[] split = id.split(":");
|
|
|
String userId = split[0];
|
|
|
String clientType = split[1];
|
|
|
imUserId = getImUserId(userId, clientType);
|
|
|
} else {
|
|
|
- imUserId = getImUserId(id, "teacher");
|
|
|
+ imUserId = getImUserId(id, "TEACHER");
|
|
|
}
|
|
|
|
|
|
privateImportMessage.setFromAccount(imUserId);
|
|
@@ -768,10 +769,10 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
});*/
|
|
|
if (list.stream().map(TencentRequest.MessageBody::getMsgType).collect(Collectors.toList()).get(0).equals("RC:TxtMsg")) {
|
|
|
//文本对象
|
|
|
- list.stream().forEach(item -> item.setMsgType("TIMTextElem"));
|
|
|
+ list.forEach(item -> item.setMsgType("TIMTextElem"));
|
|
|
} else if (list.stream().map(TencentRequest.MessageBody::getMsgType).collect(Collectors.toList()).get(0).equals("RC:ImgMsg")) {
|
|
|
//图文对象
|
|
|
- list.stream().forEach(item -> item.setMsgType("TIMImageElem"));
|
|
|
+ list.forEach(item -> item.setMsgType("TIMImageElem"));
|
|
|
}
|
|
|
privateImportMessage.setTencentMessageBody(list);
|
|
|
try {
|
|
@@ -792,13 +793,13 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
String imUserId;
|
|
|
String id = i.getFromUserId();
|
|
|
//根据发送者分场景讨论
|
|
|
- if (id.contains(":student")) {
|
|
|
+ if (id.contains(":STUDENT")) {
|
|
|
String[] split = id.split(":");
|
|
|
String userId = split[0];
|
|
|
String clientType = split[1];
|
|
|
imUserId = getImUserId(userId, clientType);
|
|
|
} else {
|
|
|
- imUserId = getImUserId(id, "teacher");
|
|
|
+ imUserId = getImUserId(id, "TEACHER");
|
|
|
}
|
|
|
|
|
|
|
|
@@ -834,10 +835,10 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
|
|
|
//文本对象
|
|
|
if (bodyList.stream().map(TencentRequest.MessageBody::getMsgType).collect(Collectors.toList()).get(0).equals("RC:TxtMsg")) {
|
|
|
- bodyList.stream().forEach(item -> item.setMsgType("TIMTextElem"));
|
|
|
+ bodyList.forEach(item -> item.setMsgType("TIMTextElem"));
|
|
|
} else if (bodyList.stream().map(TencentRequest.MessageBody::getMsgType).collect(Collectors.toList()).get(0).equals("RC:ImgMsg")) {
|
|
|
//暂未支持图文对象
|
|
|
- bodyList.stream().forEach(item -> item.setMsgType("TIMCustomElem"));
|
|
|
+ bodyList.forEach(item -> item.setMsgType("TIMCustomElem"));
|
|
|
}
|
|
|
|
|
|
data1.setTencentMessageBody(bodyList);
|
|
@@ -884,6 +885,9 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
}
|
|
|
|
|
|
private void groupTransfer(List<ImGroup> records) {
|
|
|
+ String fansIcon = sysConfigService.findConfigValue(SysConfigConstant.ICON_FANS_GROUP_DEFAULT);
|
|
|
+ String courseIcon = sysConfigService.findConfigValue(SysConfigConstant.ICON_COURSE_GROUP_DEFAULT);
|
|
|
+ String defaultHeard = sysConfigService.findConfigValue(SysConfigConstant.DEFAULT_HEARD);
|
|
|
for (ImGroup imGroup : records) {
|
|
|
List<ImGroupMember> memberList = imGroupMemberService.lambdaQuery()
|
|
|
.eq(ImGroupMember::getGroupId, imGroup.getId())
|
|
@@ -902,7 +906,11 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
importGroup.setNotification(imGroup.getMemo());
|
|
|
importGroup.setFaceUrl(imGroup.getImg());
|
|
|
if (StringUtils.isEmpty(imGroup.getImg())) {
|
|
|
- importGroup.setFaceUrl("https://gyt.ks3-cn-beijing.ksyuncs.com/example/group_default_avatar.png");
|
|
|
+ if (imGroup.getType().equals(ImGroupType.COURSE)) {
|
|
|
+ importGroup.setFaceUrl(courseIcon);
|
|
|
+ } else {
|
|
|
+ importGroup.setFaceUrl(fansIcon);
|
|
|
+ }
|
|
|
}
|
|
|
importGroup.setApplyJoinOption(Boolean.TRUE.equals(imGroup.getAutoPassFlag()) ? "FreeAccess" :
|
|
|
"NeedPermission");
|
|
@@ -919,7 +927,7 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
for (ImGroupMember member : groupMembers) {
|
|
|
String avatar = member.getAvatar();
|
|
|
if (StringUtils.isEmpty(avatar)) {
|
|
|
- avatar = "https://daya.ks3-cn-beijing.ksyun.com/202203/T1WgJaE.png";
|
|
|
+ avatar = defaultHeard;
|
|
|
}
|
|
|
register(member.getUserId(), imGroup.getId(), avatar, false,
|
|
|
ImGroupMemberRoleType.STUDENT.equals(member.getRoleType()) ? ClientEnum.STUDENT :
|
|
@@ -972,5 +980,78 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
// 自动激活学生IM帐号
|
|
|
registerUser(groupMembers);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void importUser() {
|
|
|
+ int page = 1;
|
|
|
+ int rows = 200;
|
|
|
+ List<String[]> teachers = getTeachers(page, rows);
|
|
|
+ while (!teachers.isEmpty()) {
|
|
|
+ register(teachers);
|
|
|
+ page++;
|
|
|
+ teachers = getTeachers(page, rows);
|
|
|
+ }
|
|
|
+ page = 1;
|
|
|
+
|
|
|
+
|
|
|
+ List<String[]> student = getStudent(page, rows);
|
|
|
+ while (!student.isEmpty()) {
|
|
|
+ register(student);
|
|
|
+ page++;
|
|
|
+ student = getStudent(page, rows);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void register(List<String[]> users) {
|
|
|
+ for (String[] user : users) {
|
|
|
+ try {
|
|
|
+ register(user[0], ClientEnum.valueOf(user[1]), user[2], user[3]);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("注册失败:" + JSON.toJSONString(user) + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String[]> getStudent(int page,int rows) {
|
|
|
+ String defaultHeard = sysConfigService.findConfigValue(SysConfigConstant.DEFAULT_HEARD);
|
|
|
+ StudentSearch studentQuery = new StudentSearch();
|
|
|
+ studentQuery.setPage(page);
|
|
|
+ studentQuery.setRows(rows);
|
|
|
+ IPage<StudentVo> studentIPage = studentService.selectPage(PageUtil.getPage(studentQuery), studentQuery);
|
|
|
+ return studentIPage.getRecords().stream().map(next -> {
|
|
|
+ String[] strings = new String[4];
|
|
|
+ strings[0] = next.getUserId().toString();
|
|
|
+ strings[1] = ClientEnum.STUDENT.name();
|
|
|
+ strings[2] = next.getUsername();
|
|
|
+ String avatar = next.getAvatar();
|
|
|
+ strings[3] = avatar;
|
|
|
+ if (StringUtils.isEmpty(avatar)) {
|
|
|
+ strings[3] = defaultHeard;
|
|
|
+ }
|
|
|
+ return strings;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String[]> getTeachers(int page, int rows) {
|
|
|
+ String defaultHeard = sysConfigService.findConfigValue(SysConfigConstant.DEFAULT_HEARD);
|
|
|
+ TeacherSearch query = new TeacherSearch();
|
|
|
+ query.setPage(page);
|
|
|
+ query.setRows(rows);
|
|
|
+ IPage<TeacherVo> teacherIPage = teacherService.selectPage(PageUtil.getPage(query), query);
|
|
|
+ List<TeacherVo> records = teacherIPage.getRecords();
|
|
|
+ return records.stream().map(next -> {
|
|
|
+ String[] strings = new String[4];
|
|
|
+ strings[0] = next.getUserId().toString();
|
|
|
+ strings[1] = ClientEnum.TEACHER.name();
|
|
|
+ strings[2] = next.getRealName();
|
|
|
+ String avatar = next.getAvatar();
|
|
|
+ strings[3] = avatar;
|
|
|
+ if (StringUtils.isEmpty(avatar)) {
|
|
|
+ strings[3] = defaultHeard;
|
|
|
+ }
|
|
|
+ return strings;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
}
|
|
|
|