|
@@ -41,6 +41,7 @@ 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;
|
|
@@ -71,9 +72,10 @@ import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStreamReader;
|
|
|
-import java.net.URL;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.text.MessageFormat;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -119,6 +121,9 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
@Autowired
|
|
|
private StudentStarService studentStarService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CustomerServiceBatchSendingService customerServiceBatchSendingService;
|
|
|
+
|
|
|
|
|
|
@Autowired
|
|
|
private ImPluginContext imPluginContext;
|
|
@@ -690,30 +695,68 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
*/
|
|
|
@Override
|
|
|
public void importInfo(List<ImHistoryMessage> info) throws Exception {
|
|
|
- URL url = new URL("https://console.tim.qq.com/v4/im_open_login_svc/account_import");
|
|
|
+
|
|
|
info.stream().forEach(i -> {
|
|
|
//判断消息类型
|
|
|
Integer type = i.getTargetType();
|
|
|
if (type == 1) {
|
|
|
//单聊会话
|
|
|
-
|
|
|
MessageWrapper.PrivateImportMessage privateImportMessage = new MessageWrapper.PrivateImportMessage();
|
|
|
//2:表示历史消息导入,消息不计入未读计数,且消息不会推送到终端
|
|
|
privateImportMessage.setSyncFromOldSystem(2);
|
|
|
//设置发送人
|
|
|
- privateImportMessage.setFromAccount(i.getFromUserId());
|
|
|
+ //根据发送者分场景讨论
|
|
|
+ String id = i.getFromUserId();
|
|
|
+ String imUserId;
|
|
|
+ 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");
|
|
|
+ }
|
|
|
+
|
|
|
+ privateImportMessage.setFromAccount(imUserId);
|
|
|
//设置接收人
|
|
|
privateImportMessage.setToAccount(i.getTargetId());
|
|
|
//设置随机数
|
|
|
privateImportMessage.setMsgRandom(new Random().nextInt());
|
|
|
- //设置body
|
|
|
|
|
|
+ //设置发送时间
|
|
|
+ String time = i.getDateTime();
|
|
|
+ SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ try {
|
|
|
+ Date date = df.parse(time);
|
|
|
+ long dateTime = date.getTime();
|
|
|
+ dateTime = dateTime / (1000);
|
|
|
+ privateImportMessage.setMsgTimeStamp(dateTime);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ //设置body
|
|
|
+ TencentRequest.MessageBody body = new TencentRequest.MessageBody();
|
|
|
List<TencentRequest.MessageBody> list = new ArrayList<>();
|
|
|
- list.stream().forEach(item -> {
|
|
|
+
|
|
|
+ if (i.getClassname().equals("RC:TxtMsg")){
|
|
|
+ TencentRequest.MessageBody body1 = CustomerServiceBatchSendingServiceImpl.getTimTextElem(i.getContent());
|
|
|
+ list.add(body1);
|
|
|
+ } else if (i.getClassname().equals("RC:ImgMsg")){
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(i.getContent());
|
|
|
+ TencentRequest.MessageBody body1 = CustomerServiceBatchSendingServiceImpl.getTimImageElem(jsonObject.getJSONObject("user").getString("portraitUri"));
|
|
|
+ list.add(body1);
|
|
|
+ }
|
|
|
+
|
|
|
+ /* body.setMsgType(i.getClassname());
|
|
|
+ body.setMsgContent(i.getContent());*/
|
|
|
+
|
|
|
+ /*list.add(body);*/
|
|
|
+ /* list.stream().forEach(item->{
|
|
|
item.setMsgContent(i.getContent());
|
|
|
item.setMsgType(i.getClassname());
|
|
|
- });
|
|
|
- if (list.stream().map(TencentRequest.MessageBody::getMsgType).collect(Collectors.toList()).get(0).equals("RC:TxtMsg")) {
|
|
|
+ });*/
|
|
|
+ if (list.stream().map(TencentRequest.MessageBody::getMsgType).collect(Collectors.toList()).get(0).equals("RC:TxtMsg")){
|
|
|
//文本对象
|
|
|
list.stream().forEach(item -> item.setMsgType("TIMTextElem"));
|
|
|
} else if (list.stream().map(TencentRequest.MessageBody::getMsgType).collect(Collectors.toList()).get(0).equals("RC:ImgMsg")) {
|
|
@@ -726,27 +769,61 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
} else if (type == 3) {
|
|
|
//群组会话
|
|
|
MessageWrapper.GroupImportMessage groupImportMessage = new MessageWrapper.GroupImportMessage();
|
|
|
List<MessageWrapper.GroupImportMessageData> list = new ArrayList<>();
|
|
|
MessageWrapper.GroupImportMessageData data1 = new MessageWrapper.GroupImportMessageData();
|
|
|
List<TencentRequest.MessageBody> bodyList = new ArrayList<>();
|
|
|
+ TencentRequest.MessageBody body = new TencentRequest.MessageBody();
|
|
|
//设置群组Id
|
|
|
groupImportMessage.setGroupId(i.getGroupId());
|
|
|
//设置发送人
|
|
|
- data1.setFromAccount(i.getFromUserId());
|
|
|
+ String imUserId;
|
|
|
+ String id = i.getFromUserId();
|
|
|
+ //根据发送者分场景讨论
|
|
|
+ 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");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ data1.setFromAccount(imUserId);
|
|
|
//设置随机数
|
|
|
data1.setRandom(new Random().nextInt());
|
|
|
//设置发送时间
|
|
|
- data1.setSendTime(Long.parseLong(i.getDateTime()));
|
|
|
- bodyList.stream().forEach(item -> {
|
|
|
- item.setMsgContent(i.getContent());
|
|
|
- item.setMsgType(i.getClassname());
|
|
|
- });
|
|
|
- if (bodyList.stream().map(TencentRequest.MessageBody::getMsgType).collect(Collectors.toList()).get(0).equals("RC:TxtMsg")) {
|
|
|
+
|
|
|
+ String time = i.getDateTime();
|
|
|
+ SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ try {
|
|
|
+ Date date = df.parse(time);
|
|
|
+ long dateTime = date.getTime();
|
|
|
+ dateTime = dateTime / (1000);
|
|
|
+ data1.setSendTime(dateTime);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ /*bodyList.stream().forEach(item->{
|
|
|
+ item.setMsgContent(i.getContent());
|
|
|
+ item.setMsgType(i.getClassname());
|
|
|
+ });*/
|
|
|
+ if (i.getClassname().equals("RC:TxtMsg")){
|
|
|
+ TencentRequest.MessageBody body1 = CustomerServiceBatchSendingServiceImpl.getTimTextElem(i.getContent());
|
|
|
+ bodyList.add(body1);
|
|
|
+ } else if (i.getClassname().equals("RC:ImgMsg")){
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(i.getContent());
|
|
|
+ TencentRequest.MessageBody body1 = CustomerServiceBatchSendingServiceImpl.getTimImageElem(jsonObject.getJSONObject("user").getString("portraitUri"));
|
|
|
+ bodyList.add(body1);
|
|
|
+ }
|
|
|
+ /*body.setMsgContent(i.getContent());
|
|
|
+ body.setMsgType(i.getClassname());*/
|
|
|
+
|
|
|
+ //文本对象
|
|
|
+ if (bodyList.stream().map(TencentRequest.MessageBody::getMsgType).collect(Collectors.toList()).get(0).equals("RC:TxtMsg")){
|
|
|
bodyList.stream().forEach(item -> item.setMsgType("TIMTextElem"));
|
|
|
} else if (bodyList.stream().map(TencentRequest.MessageBody::getMsgType).collect(Collectors.toList()).get(0).equals("RC:ImgMsg")) {
|
|
|
//暂未支持图文对象
|
|
@@ -763,12 +840,8 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
@@ -785,17 +858,19 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
*/
|
|
|
@Override
|
|
|
public void groupTransfer() {
|
|
|
- int page = 1;
|
|
|
- int size = 100;
|
|
|
- List<ImGroup> imGroups = this.lambdaQuery().orderByDesc(ImGroup::getCreateTime)
|
|
|
- .last("limit " + ((page - 1) * size) + "," + size).list();
|
|
|
- while (!imGroups.isEmpty()) {
|
|
|
- groupTransfer(imGroups);
|
|
|
-
|
|
|
- page++;
|
|
|
- imGroups = this.lambdaQuery().orderByDesc(ImGroup::getCreateTime)
|
|
|
- .last("limit " + ((page - 1) * size) + "," + size).list();
|
|
|
- }
|
|
|
+// int page = 1;
|
|
|
+// int size = 100;
|
|
|
+// List<ImGroup> imGroups = this.lambdaQuery().orderByDesc(ImGroup::getCreateTime)
|
|
|
+// .last("limit " + ((page - 1) * size) + "," + size).list();
|
|
|
+// while (!imGroups.isEmpty()) {
|
|
|
+// groupTransfer(imGroups);
|
|
|
+//
|
|
|
+// page++;
|
|
|
+// imGroups = this.lambdaQuery().orderByDesc(ImGroup::getCreateTime)
|
|
|
+// .last("limit " + ((page - 1) * size) + "," + size).list();
|
|
|
+// }
|
|
|
+ ImGroup byId = this.getById("9f677fcd-9d80-4db0-8beb-0ff04e6a98f6FAN");
|
|
|
+ groupTransfer(Collections.singletonList(byId));
|
|
|
}
|
|
|
|
|
|
private void groupTransfer(List<ImGroup> records) {
|
|
@@ -853,8 +928,11 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
|
|
|
data.setUnreadMsgNum(0);
|
|
|
return data;
|
|
|
}).collect(Collectors.toList());
|
|
|
- importGroupMember.setMemberList(members);
|
|
|
- imPluginContext.getPluginService().importGroupMember(importGroupMember);
|
|
|
+ List<List<MessageWrapper.ImportGroupMemberData>> partition = Lists.partition(members, 6);
|
|
|
+ for (List<MessageWrapper.ImportGroupMemberData> importGroupMemberData : partition) {
|
|
|
+ importGroupMember.setMemberList(importGroupMemberData);
|
|
|
+ imPluginContext.getPluginService().importGroupMember(importGroupMember);
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
log.error(String.format("群迁移加入群聊失败:%s", e.getMessage()));
|
|
|
}
|