Browse Source

消息导入

liujc 1 year ago
parent
commit
384becbd43

+ 1 - 27
mec-application/src/main/java/com/ym/mec/web/controller/ImHistoryMessageController.java

@@ -64,7 +64,6 @@ public class ImHistoryMessageController extends BaseController {
         executor.execute(() -> {
 
             // 100个线程的无界线程池
-            ExecutorService executorService = Executors.newFixedThreadPool(100);
             com.yonge.mongodb.PageInfo<HistoryMessage> info;
 //        historyMessageService.updateAllStatus(0);
             //计算总数据量
@@ -85,37 +84,12 @@ public class ImHistoryMessageController extends BaseController {
                 try {
                     // 过滤 groupId为空的
                     footer = footer.stream().filter(o -> StringUtils.isNotBlank(o.getGroupId())).collect(Collectors.toList());
-                    // 根据 groupId 分组
-                    Map<String, List<HistoryMessage>> map = footer.stream().collect(Collectors.groupingBy(HistoryMessage::getGroupId, LinkedHashMap::new, Collectors.toList()));
-
-                    List<Future<?>> list = new ArrayList<>();
-                    for (Map.Entry<String, List<HistoryMessage>> entry : map.entrySet()) {
-                        String k = entry.getKey();
-                        List<HistoryMessage> v = entry.getValue();
-
-                        list.add(executorService.submit(() -> {
-                            try {
-                                imGroupService.importInfo(v);
-                            } catch (Exception e) {
-
-                                log.error("群聊导入失败",e);
-                            }
-
-                        }));
-                    }
-                    for (Future<?> future : list) {
-                        try {
-                            future.get();
-                        } catch (Exception e){
-                            log.error("群聊导入失败",e);
-                        }
-                    }
+                    imGroupService.importInfo(footer);
                 } catch (Exception e) {
                     log.error("IM导入失败",e);
                 }
                 log.info("已导入:" + (i + 1) * size);
             }
-            executorService.shutdown();
         });
     }
 

+ 4 - 4
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ImGroupServiceImpl.java

@@ -1448,7 +1448,7 @@ public class ImGroupServiceImpl extends BaseServiceImpl<String, ImGroup> impleme
                     privateImportMessage.setTencentMessageBody(list);
                     privateImportMessage.setCloudCustomData(jsonObject.getString("extra"));
 
-                    log.info("导入私聊消息:{}", JSON.toJSONString(privateImportMessage));
+//                    log.info("导入私聊消息:{}", JSON.toJSONString(privateImportMessage));
                     try {
                         imPluginContext.getPluginService().importPrivateMessage(privateImportMessage);
                         //为已导入数据更改标识
@@ -1457,7 +1457,7 @@ public class ImGroupServiceImpl extends BaseServiceImpl<String, ImGroup> impleme
                         log.info("导入私聊消息成功");
                     } catch (Exception e) {
                         updateStatus(i,2);
-                        log.error("导入私聊IM消息失败 msg:{},entity:{}", list, i, e);
+                        log.error("导入私聊IM消息失败 msg:{},entity:{}", JSON.toJSONString(privateImportMessage), i, e);
                     }
                 } else if (type == 3) {
                     //群组会话
@@ -1526,7 +1526,7 @@ public class ImGroupServiceImpl extends BaseServiceImpl<String, ImGroup> impleme
                     list.add(data1);
                     //导入消息列表
                     groupImportMessage.setMsgList(list);
-                    log.info("导入群聊消息:{}", JSON.toJSONString(groupImportMessage));
+//                    log.info("导入群聊消息:{}", JSON.toJSONString(groupImportMessage));
                     try {
                         imPluginContext.getPluginService().importGroupMessage(groupImportMessage);
                         //为已导入数据更改标识
@@ -1534,7 +1534,7 @@ public class ImGroupServiceImpl extends BaseServiceImpl<String, ImGroup> impleme
                         log.info("导入消息成功");
                     } catch (Exception e) {
                         updateStatus(i,2);
-                        log.error("导入群组IM消息失败 msg:{},entity:{}", list, i, e);
+                        log.error("导入群组IM消息失败 msg:{},entity:{}", JSON.toJSONString(groupImportMessage), i, e);
                     }
                 }
             }catch (Exception e) {