Browse Source

Merge remote-tracking branch 'origin/feature/1020-tencent-im' into feature/1020-tencent-im

Eric 1 year ago
parent
commit
a769ef132f

+ 85 - 83
.idea/httpRequests/http-requests-log.http

@@ -1,3 +1,88 @@
+POST http://127.0.0.1:8805/api-web/imHistoryMessage/imToTencent
+Authorization: bearer 01af4346-c7e5-4e43-9950-9617ff0743bf
+Content-Length: 0
+Connection: Keep-Alive
+User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.6)
+Accept-Encoding: br,deflate,gzip,x-gzip
+
+###
+
+POST http://127.0.0.1:8805/api-web/imHistoryMessage/imToTencent
+Authorization: bearer 01af4346-c7e5-4e43-9950-9617ff0743bf
+Content-Length: 0
+Connection: Keep-Alive
+User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.6)
+Accept-Encoding: br,deflate,gzip,x-gzip
+
+<> 2023-10-20T201808.200.json
+
+###
+
+POST http://127.0.0.1:8805/api-web/imHistoryMessage/imToTencent
+Authorization: bearer 01af4346-c7e5-4e43-9950-9617ff0743bf
+Content-Length: 0
+Connection: Keep-Alive
+User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.6)
+Accept-Encoding: br,deflate,gzip,x-gzip
+
+<> 2023-10-20T200147.200.json
+
+###
+
+POST http://127.0.0.1:8805/api-web/imHistoryMessage/ImportIM
+Authorization: bearer 01af4346-c7e5-4e43-9950-9617ff0743bf
+Content-Length: 0
+Connection: Keep-Alive
+User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.6)
+Accept-Encoding: br,deflate,gzip,x-gzip
+
+<> 2023-10-20T195243.200.json
+
+###
+
+POST http://127.0.0.1:8805/api-web/imHistoryMessage/imToTencent
+Authorization: bearer 01af4346-c7e5-4e43-9950-9617ff0743bf
+Content-Length: 0
+Connection: Keep-Alive
+User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.6)
+Accept-Encoding: br,deflate,gzip,x-gzip
+
+<> 2023-10-20T195232.200.json
+
+###
+
+GET http://127.0.0.1:8805/api-web/imGroup/groupTransfer
+Authorization: bearer 01af4346-c7e5-4e43-9950-9617ff0743bf
+Connection: Keep-Alive
+User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.6)
+Accept-Encoding: br,deflate,gzip,x-gzip
+
+<> 2023-10-20T195151.200.json
+
+###
+
+POST http://127.0.0.1:8805/api-web/imHistoryMessage/imToTencent
+Authorization: bearer 01af4346-c7e5-4e43-9950-9617ff0743bf
+Content-Length: 0
+Connection: Keep-Alive
+User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.6)
+Accept-Encoding: br,deflate,gzip,x-gzip
+
+<> 2023-10-20T195028.200.json
+
+###
+
+POST http://127.0.0.1:8805/api-web/imHistoryMessage/imToTencent
+Authorization: bearer 31a32cfa-3c2e-4b27-bea4-bff679f1eee2
+Content-Length: 0
+Connection: Keep-Alive
+User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.6)
+Accept-Encoding: br,deflate,gzip,x-gzip
+
+<> 2023-10-20T194928.200.json
+
+###
+
 GET http://127.0.0.1:8005/open/queryAllOrg
 Connection: Keep-Alive
 User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.6)
@@ -531,86 +616,3 @@ Accept-Encoding: br,deflate,gzip,x-gzip
 
 ###
 
-GET http://127.0.0.1:9001/studentVipGroup/joinLiveRoomByShare?courseScheduleId=2179
-Authorization: bearer 093517b0-c9a4-407b-b558-0d71bf157b16
-Connection: Keep-Alive
-User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.6)
-Accept-Encoding: br,deflate,gzip,x-gzip
-
-<> 2023-06-12T095238.200.json
-
-###
-
-GET http://127.0.0.1:9001/studentVipGroup/joinLiveRoomByShare?courseScheduleId=2179
-Authorization: bearer 093517b0-c9a4-407b-b558-0d71bf157b16
-Connection: Keep-Alive
-User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.6)
-Accept-Encoding: br,deflate,gzip,x-gzip
-
-<> 2023-06-12T095217.200.json
-
-###
-
-GET http://127.0.0.1:9001/studentVipGroup/joinLiveRoomByShare?courseScheduleId=2179
-Authorization: bearer 093517b0-c9a4-407b-b558-0d71bf157b16
-Connection: Keep-Alive
-User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.6)
-Accept-Encoding: br,deflate,gzip,x-gzip
-
-<> 2023-06-12T095045.200.json
-
-###
-
-GET http://127.0.0.1:9001/studentVipGroup/joinLiveRoomByShare?courseScheduleId=2179
-Authorization: bearer 093517b0-c9a4-407b-b558-0d71bf157b16
-Connection: Keep-Alive
-User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.6)
-Accept-Encoding: br,deflate,gzip,x-gzip
-
-<> 2023-06-12T094907.200.json
-
-###
-
-GET http://127.0.0.1:9001/studentVipGroup/joinLiveRoomByShare?courseScheduleId=2179
-Authorization: bearer 81d0c352-fcc8-4812-87f5-0f7a68d10451
-Connection: Keep-Alive
-User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.6)
-Accept-Encoding: br,deflate,gzip,x-gzip
-
-<> 2023-06-12T094734.200.json
-
-###
-
-POST http://localhost:8005/imSendGroupMessage/send
-Content-Type: application/json
-tenantId: 1
-Authorization: bearer 9b756b90-f27a-4ca9-99b1-da854c72eb3f
-Content-Length: 99
-Connection: Keep-Alive
-User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.6)
-Accept-Encoding: br,deflate,gzip,x-gzip
-
-{"postType":"0","messageContent":"3の3","messageType":"TXT","targetIds":"232","isIncludeSender":0}
-
-<> 2023-06-09T174838.200.json
-
-###
-
-GET http://127.0.0.1:8005/task/closeLiveCourseRoom
-Connection: Keep-Alive
-User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.6)
-Accept-Encoding: br,deflate,gzip,x-gzip
-
-<> 2023-06-08T214126.200.json
-
-###
-
-GET http://127.0.0.1:8005/task/closeLiveCourseRoom
-Connection: Keep-Alive
-User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.6)
-Accept-Encoding: br,deflate,gzip,x-gzip
-
-<> 2023-06-08T210807.200.json
-
-###
-

+ 23 - 0
mec-application/src/main/java/com/ym/mec/web/controller/ImHistoryMessageController.java

@@ -65,4 +65,27 @@ public class ImHistoryMessageController extends BaseController {
 		}
 	}
 
+    @ApiOperation("融云im To 腾讯")
+    @PostMapping(value = "/imToTencent")
+    public void imToTencent() throws Exception {
+        com.yonge.mongodb.PageInfo<HistoryMessage> info;
+//        historyMessageService.updateAllStatus(0);
+        //计算总数据量
+        long count = historyMessageService.querySyncCount();
+        //计算调用次数
+        long num = (int) Math.ceil(count / 100);
+        for (long i = 0; i <=num ; i++) {
+            int size =100;
+            //获取融云消息
+            //List<ImGroup> list = imGroupService.lambdaQuery().last("limit "+(page-1)*size+","+size).list();
+            info = historyMessageService.getImToTencent(i,size);
+            List<HistoryMessage> footer = info.getRows();
+            if (CollectionUtils.isEmpty(footer)) {
+                break;
+            }
+            //IM转换
+            imGroupService.imToTencent(footer);
+        }
+    }
+
 }

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/ImGroupService.java

@@ -1,6 +1,8 @@
 package com.ym.mec.biz.service;
 
+import com.alibaba.fastjson.JSONObject;
 import com.microsvc.toolkit.middleware.im.message.GroupMemberWrapper;
+import com.microsvc.toolkit.middleware.im.message.TencentRequest;
 import com.microsvc.toolkit.middleware.rtc.RTCRoomPluginService;
 import com.ym.mec.biz.dal.dto.im.BasicUserInfo;
 import com.ym.mec.biz.dal.dto.ImGroupDto;
@@ -12,6 +14,7 @@ import com.ym.mec.biz.dal.enums.school.ESchoolStaffType;
 import com.ym.mec.biz.dal.wrapper.ImGroupWrapper;
 import com.ym.mec.common.service.BaseService;
 import com.yonge.log.dal.model.HistoryMessage;
+import org.jetbrains.annotations.NotNull;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
@@ -203,4 +206,12 @@ public interface ImGroupService extends BaseService<String, ImGroup> {
 	 * @throws Exception
 	 */
 	void importInfo(List<HistoryMessage> info) throws Exception;
+
+    void imToTencent(List<HistoryMessage> list);
+
+    @NotNull
+    List<TencentRequest.MessageBody> getGroupMessage(HistoryMessage i, JSONObject jsonObject);
+
+    @NotNull
+    List<TencentRequest.MessageBody> getPrivateMessge(HistoryMessage i, JSONObject jsonObject);
 }

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

@@ -60,10 +60,13 @@ import com.ym.mec.common.page.QueryInfo;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.common.tenant.TenantContextHolder;
 import com.yonge.log.dal.model.HistoryMessage;
+import com.yonge.log.dal.model.HistoryMessageTencent;
 import com.yonge.log.service.HistoryMessageService;
+import com.yonge.log.service.HistoryMessageTenantService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.jetbrains.annotations.NotNull;
 import org.joda.time.DateTime;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -77,6 +80,9 @@ import java.io.IOException;
 import java.net.URL;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
 import java.util.Base64;
 import java.util.Calendar;
@@ -147,6 +153,10 @@ public class ImGroupServiceImpl extends BaseServiceImpl<String, ImGroup> impleme
 
     @Autowired
     private ImPluginContext imPluginContext;
+
+    @Autowired
+    private HistoryMessageTenantService historyMessageTencentService;
+
     @Override
     public BaseDAO<String, ImGroup> getDAO() {
         return imGroupDao;
@@ -1192,67 +1202,11 @@ public class ImGroupServiceImpl extends BaseServiceImpl<String, ImGroup> impleme
 
                     //设置body
                     //TencentRequest.MessageBody body = new TencentRequest.MessageBody();
-                    List<TencentRequest.MessageBody> list = new ArrayList<>();
 
                     JSONObject jsonObject = JSONObject.parseObject(i.getContent());
 
-                    if (i.getClassname().equals("RC:TxtMsg")) {
-                        //文本
-                        TencentRequest.MessageBody body1 = getTimTextElem(jsonObject.getString("content"));
-                        list.add(body1);
-                    } else if (i.getClassname().equals("RC:ImgMsg")) {
-                        //图片
-                        TencentRequest.MessageBody body1 = getTimImageElem(jsonObject.getString("imageUri"));
-                        list.add(body1);
-                    } else if (i.getClassname().equals("RC:GIFMsg")) {
-                        //GIf
-                        String remoteUrl = jsonObject.getString("remoteUrl");
-                        int gifDataSize = jsonObject.getInteger("gifDataSize");
-                        int width = jsonObject.getInteger("width");
-                        int height = jsonObject.getInteger("height");
-                        TencentRequest.MessageBody body1 = getTimGifElem(remoteUrl, gifDataSize, width, height);
-                        list.add(body1);
-                    } else if (i.getClassname().equals("RC:HQVCMsg")) {
-                        //语音
-                        String remoteUrl = jsonObject.getString("remoteUrl");
-                        int duration = jsonObject.getInteger("duration");
-                        TencentRequest.MessageBody body1 = getTimSoundElem(remoteUrl, duration);
-                        list.add(body1);
-                    } else if (i.getClassname().equals("RC:FileMsg")) {
-                        //文件
-                        String fileUrl = jsonObject.getString("fileUrl");
-                        String size = jsonObject.getString("size");
-                        String name = jsonObject.getString("name");
-
-                        TencentRequest.MessageBody body1 = getTimFileElem(fileUrl, size, name);
-                        list.add(body1);
-                    } else if (i.getClassname().equals("RC:SightMsg")) {
-                        //视频
-                        String sightUrl = jsonObject.getString("sightUrl");
-                        String size = jsonObject.getString("size");
-                        int duration = jsonObject.getInteger("duration");
-                        String content = jsonObject.getString("content");
-                        TencentRequest.MessageBody body1 = null;
-                        try {
-                            body1 = getTimVideoFileElem(sightUrl, size, duration, content);
-                        } catch (IOException e) {
-                            e.printStackTrace();
-                        }
-                        list.add(body1);
-                    } else if (i.getClassname().equals("RC:LBSMsg")) {
-                        //位置
-                        double latitude = jsonObject.getDouble("latitude");
-                        double longitude = jsonObject.getDouble("longitude");
-                        String poi = jsonObject.getString("poi");
-                        TencentRequest.MessageBody body1 = getTimLocationElem(latitude, longitude, poi);
-                        list.add(body1);
-                    } else if (i.getClassname().equals("RC:ImgTextMsg")) {
-                        //图文
-                        TencentRequest.MessageBody body1 = getTimTextElem(jsonObject.getString("content"));
-                        TencentRequest.MessageBody body2 = getTimImageElem(jsonObject.getString("imageUri"));
-                        list.add(body1);
-                        list.add(body2);
-                    } else {
+                    List<TencentRequest.MessageBody> list = getPrivateMessge(i, jsonObject);
+                    if (list.isEmpty()) {
                         updateStatus(i,1);
                         continue;
                     }
@@ -1295,7 +1249,6 @@ public class ImGroupServiceImpl extends BaseServiceImpl<String, ImGroup> impleme
                     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());
@@ -1335,68 +1288,9 @@ public class ImGroupServiceImpl extends BaseServiceImpl<String, ImGroup> impleme
                     JSONObject jsonObject = JSONObject.parseObject(i.getContent());
 
 
-                    if (i.getClassname().equals("RC:TxtMsg")) {
-                        //文本
-                        TencentRequest.MessageBody body1 = getTimTextElem(jsonObject.getString("content"));
-                        bodyList.add(body1);
-                    } else if (i.getClassname().equals("RC:ImgMsg")) {
-                        //图片
-                        TencentRequest.MessageBody body1 = getTimImageElem(jsonObject.getString("imageUri"));
-                        bodyList.add(body1);
-                    } else if (i.getClassname().equals("RC:GIFMsg")) {
-                        //GIf
-                        String remoteUrl = jsonObject.getString("remoteUrl");
-                        int gifDataSize = jsonObject.getInteger("gifDataSize");
-                        int width = jsonObject.getInteger("width");
-                        int height = jsonObject.getInteger("height");
-                        TencentRequest.MessageBody body1 = getTimGifElem(remoteUrl, gifDataSize, width, height);
-                        bodyList.add(body1);
-                    } else if (i.getClassname().equals("RC:HQVCMsg")) {
-                        //语音
-                        String remoteUrl = jsonObject.getString("remoteUrl");
-                        int duration = jsonObject.getInteger("duration");
-                        TencentRequest.MessageBody body1 = getTimSoundElem(remoteUrl, duration);
-                        bodyList.add(body1);
-                    } else if (i.getClassname().equals("RC:FileMsg")) {
-                        //文件
-                        String fileUrl = jsonObject.getString("fileUrl");
-                        String size = jsonObject.getString("size");
-                        String name = jsonObject.getString("name");
-
-                        TencentRequest.MessageBody body1 = getTimFileElem(fileUrl, size, name);
-                        bodyList.add(body1);
-                    } else if (i.getClassname().equals("RC:SightMsg")) {
-                        //视频
-                        String sightUrl = jsonObject.getString("sightUrl");
-                        String size = jsonObject.getString("size");
-                        int duration = jsonObject.getInteger("duration");
-                        String content = jsonObject.getString("content");
-                        TencentRequest.MessageBody body1 = null;
-                        try {
-                            body1 = getTimVideoFileElem(sightUrl, size, duration, content);
-                        } catch (IOException e) {
-                            log.error("视频转换失败", e);
-                        }
-                        bodyList.add(body1);
-                    } else if (i.getClassname().equals("RC:LBSMsg")) {
-                        //位置
-                        double latitude = jsonObject.getDouble("latitude");
-                        double longitude = jsonObject.getDouble("longitude");
-                        String poi = jsonObject.getString("poi");
-                        TencentRequest.MessageBody body1 = getTimLocationElem(latitude, longitude, poi);
-                        bodyList.add(body1);
-                    } else if (i.getClassname().equals("RC:ImgTextMsg")) {
-                        //图文
-                        TencentRequest.MessageBody body1 = getTimTextElem(jsonObject.getString("content"));
-                        TencentRequest.MessageBody body2 = getTimImageElem(jsonObject.getString("imageUri"));
-                        bodyList.add(body1);
-                        bodyList.add(body2);
-                    } else if (i.getClassname().equals("RC:CombineMsg")) {
-                        //合并转发
-                        String remoteUrl = jsonObject.getString("remoteUrl");
-                        int conversationType = jsonObject.getInteger("conversationType");
-                        getTimRelayElem();
-                    } else {
+                    List<TencentRequest.MessageBody> bodyList = getGroupMessage(i, jsonObject);
+
+                    if (CollectionUtils.isEmpty(bodyList)){
                         updateStatus(i,1);
                         continue;
                     }
@@ -1435,6 +1329,190 @@ public class ImGroupServiceImpl extends BaseServiceImpl<String, ImGroup> impleme
         }
     }
 
+
+    @Override
+    @Transactional
+    public void imToTencent(List<HistoryMessage> list) {
+
+        for (HistoryMessage historyMessage : list) {
+            HistoryMessageTencent tencent = new HistoryMessageTencent();
+            tencent.setId(historyMessage.getMsgUID());
+            // 时间
+            String dateTime = historyMessage.getDateTime();
+            LocalDateTime ldt = LocalDateTime.parse(dateTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"));
+            // yyyyMMddHH
+            String date = ldt.format(DateTimeFormatter.ofPattern("yyyyMMddHH"));
+            tencent.setMsgTime(Long.parseLong(date));
+
+            List<TencentRequest.MessageBody> bodyList = new ArrayList<>();
+            JSONObject jsonObject = JSONObject.parseObject(historyMessage.getContent());
+            // 类型
+            if (historyMessage.getTargetType() == 1) {
+                tencent.setChatType("C2C");
+                tencent.setToAccount(historyMessage.getTargetId());
+                bodyList = getPrivateMessge(historyMessage,jsonObject);
+            } else if (historyMessage.getTargetType() == 3) {
+                tencent.setChatType("GROUP");
+                tencent.setGroupId(historyMessage.getGroupId());
+                bodyList = getGroupMessage(historyMessage,jsonObject);
+            } else {
+                continue;
+            }
+            if (CollectionUtils.isEmpty(bodyList)) {
+                continue;
+            }
+            // 发送人
+            tencent.setFromAccount(historyMessage.getFromUserId());
+            //类型
+            tencent.setAppService("MEC");
+            tencent.setMsgFromPlatform(historyMessage.getSource());
+            tencent.setMsgTimestamp(ldt.toInstant(ZoneId.systemDefault().getRules().getOffset(ldt)).toEpochMilli()/1000);
+
+            // 消息转换
+            tencent.setCloudCustomData(jsonObject.getString("extra"));
+            tencent.setMsgBody(JSON.toJSONString(bodyList));
+
+            historyMessageTencentService.insert(tencent);
+
+            historyMessage.setSyncFlag(1);
+            historyMessageService.updateSyncFlag(historyMessage.getMsgUID(),1);
+        }
+
+    }
+
+    @NotNull
+    @Override
+    public List<TencentRequest.MessageBody> getGroupMessage(HistoryMessage i, JSONObject jsonObject) {
+        List<TencentRequest.MessageBody> bodyList = new ArrayList<>();
+        if (i.getClassname().equals("RC:TxtMsg")) {
+            //文本
+            TencentRequest.MessageBody body1 = getTimTextElem(jsonObject.getString("content"));
+            bodyList.add(body1);
+        } else if (i.getClassname().equals("RC:ImgMsg")) {
+            //图片
+            TencentRequest.MessageBody body1 = getTimImageElem(jsonObject.getString("imageUri"));
+            bodyList.add(body1);
+        } else if (i.getClassname().equals("RC:GIFMsg")) {
+            //GIf
+            String remoteUrl = jsonObject.getString("remoteUrl");
+            int gifDataSize = jsonObject.getInteger("gifDataSize");
+            int width = jsonObject.getInteger("width");
+            int height = jsonObject.getInteger("height");
+            TencentRequest.MessageBody body1 = getTimGifElem(remoteUrl, gifDataSize, width, height);
+            bodyList.add(body1);
+        } else if (i.getClassname().equals("RC:HQVCMsg")) {
+            //语音
+            String remoteUrl = jsonObject.getString("remoteUrl");
+            int duration = jsonObject.getInteger("duration");
+            TencentRequest.MessageBody body1 = getTimSoundElem(remoteUrl, duration);
+            bodyList.add(body1);
+        } else if (i.getClassname().equals("RC:FileMsg")) {
+            //文件
+            String fileUrl = jsonObject.getString("fileUrl");
+            String size = jsonObject.getString("size");
+            String name = jsonObject.getString("name");
+
+            TencentRequest.MessageBody body1 = getTimFileElem(fileUrl, size, name);
+            bodyList.add(body1);
+        } else if (i.getClassname().equals("RC:SightMsg")) {
+            //视频
+            String sightUrl = jsonObject.getString("sightUrl");
+            String size = jsonObject.getString("size");
+            int duration = jsonObject.getInteger("duration");
+            String content = jsonObject.getString("content");
+            TencentRequest.MessageBody body1 = null;
+            try {
+                body1 = getTimVideoFileElem(sightUrl, size, duration, content);
+            } catch (IOException e) {
+                log.error("视频转换失败", e);
+            }
+            bodyList.add(body1);
+        } else if (i.getClassname().equals("RC:LBSMsg")) {
+            //位置
+            double latitude = jsonObject.getDouble("latitude");
+            double longitude = jsonObject.getDouble("longitude");
+            String poi = jsonObject.getString("poi");
+            TencentRequest.MessageBody body1 = getTimLocationElem(latitude, longitude, poi);
+            bodyList.add(body1);
+        } else if (i.getClassname().equals("RC:ImgTextMsg")) {
+            //图文
+            TencentRequest.MessageBody body1 = getTimTextElem(jsonObject.getString("content"));
+            TencentRequest.MessageBody body2 = getTimImageElem(jsonObject.getString("imageUri"));
+            bodyList.add(body1);
+            bodyList.add(body2);
+        } else if (i.getClassname().equals("RC:CombineMsg")) {
+            //合并转发
+            String remoteUrl = jsonObject.getString("remoteUrl");
+            int conversationType = jsonObject.getInteger("conversationType");
+            getTimRelayElem();
+        }
+        return bodyList;
+    }
+
+    @NotNull
+    @Override
+    public List<TencentRequest.MessageBody> getPrivateMessge(HistoryMessage i, JSONObject jsonObject) {
+        List<TencentRequest.MessageBody> list = new ArrayList<>();
+        if (i.getClassname().equals("RC:TxtMsg")) {
+            //文本
+            TencentRequest.MessageBody body1 = getTimTextElem(jsonObject.getString("content"));
+            list.add(body1);
+        } else if (i.getClassname().equals("RC:ImgMsg")) {
+            //图片
+            TencentRequest.MessageBody body1 = getTimImageElem(jsonObject.getString("imageUri"));
+            list.add(body1);
+        } else if (i.getClassname().equals("RC:GIFMsg")) {
+            //GIf
+            String remoteUrl = jsonObject.getString("remoteUrl");
+            int gifDataSize = jsonObject.getInteger("gifDataSize");
+            int width = jsonObject.getInteger("width");
+            int height = jsonObject.getInteger("height");
+            TencentRequest.MessageBody body1 = getTimGifElem(remoteUrl, gifDataSize, width, height);
+            list.add(body1);
+        } else if (i.getClassname().equals("RC:HQVCMsg")) {
+            //语音
+            String remoteUrl = jsonObject.getString("remoteUrl");
+            int duration = jsonObject.getInteger("duration");
+            TencentRequest.MessageBody body1 = getTimSoundElem(remoteUrl, duration);
+            list.add(body1);
+        } else if (i.getClassname().equals("RC:FileMsg")) {
+            //文件
+            String fileUrl = jsonObject.getString("fileUrl");
+            String size = jsonObject.getString("size");
+            String name = jsonObject.getString("name");
+
+            TencentRequest.MessageBody body1 = getTimFileElem(fileUrl, size, name);
+            list.add(body1);
+        } else if (i.getClassname().equals("RC:SightMsg")) {
+            //视频
+            String sightUrl = jsonObject.getString("sightUrl");
+            String size = jsonObject.getString("size");
+            int duration = jsonObject.getInteger("duration");
+            String content = jsonObject.getString("content");
+            TencentRequest.MessageBody body1 = null;
+            try {
+                body1 = getTimVideoFileElem(sightUrl, size, duration, content);
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+            list.add(body1);
+        } else if (i.getClassname().equals("RC:LBSMsg")) {
+            //位置
+            double latitude = jsonObject.getDouble("latitude");
+            double longitude = jsonObject.getDouble("longitude");
+            String poi = jsonObject.getString("poi");
+            TencentRequest.MessageBody body1 = getTimLocationElem(latitude, longitude, poi);
+            list.add(body1);
+        } else if (i.getClassname().equals("RC:ImgTextMsg")) {
+            //图文
+            TencentRequest.MessageBody body1 = getTimTextElem(jsonObject.getString("content"));
+            TencentRequest.MessageBody body2 = getTimImageElem(jsonObject.getString("imageUri"));
+            list.add(body1);
+            list.add(body2);
+        }
+        return list;
+    }
+
     private TencentRequest.MessageBody getTimGifElem(String remoteUr,int size,int width,int height) {
         if (StringUtils.isEmpty(remoteUr) && size == 0 && width == 0 && height == 0) {
             return null;
@@ -1676,6 +1754,9 @@ public class ImGroupServiceImpl extends BaseServiceImpl<String, ImGroup> impleme
 
     //url路径改造
     private static String urlTypeChange(String url){
+        if (true){
+            return url;
+        }
         if (url.isEmpty()){
             log.warn("url为空");
         }

+ 16 - 0
mec-common/audit-log/src/main/java/com/yonge/log/dal/dao/HistoryMessageTenantDao.java

@@ -0,0 +1,16 @@
+package com.yonge.log.dal.dao;
+
+import com.yonge.log.dal.model.HistoryMessage;
+import com.yonge.log.dal.model.HistoryMessageTencent;
+import com.yonge.mongodb.dao.BaseDaoWithMongo;
+import org.springframework.stereotype.Component;
+
+@Component
+public class HistoryMessageTenantDao extends BaseDaoWithMongo<String, HistoryMessageTencent> {
+
+	@Override
+	public Class<HistoryMessageTencent> getClassEntity() {
+		return HistoryMessageTencent.class;
+	}
+
+}

+ 2 - 0
mec-common/audit-log/src/main/java/com/yonge/log/dal/model/HistoryMessage.java

@@ -41,6 +41,8 @@ public class HistoryMessage implements Serializable {
 
     private Integer status;
 
+    private Integer syncFlag;
+
     private String appId;
 
     private String busChannel;

+ 66 - 0
mec-common/audit-log/src/main/java/com/yonge/log/dal/model/HistoryMessageTencent.java

@@ -0,0 +1,66 @@
+package com.yonge.log.dal.model;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.mapping.Document;
+import org.springframework.data.mongodb.core.mapping.Field;
+
+import java.io.Serializable;
+
+/**
+ * @author 袁亮
+ * @apiNote 腾讯IM消息模型
+ */
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+@Document(collection = "im_history_message_tencent")
+public class HistoryMessageTencent implements Serializable {
+
+    @Id
+    private String id;
+
+    @Field("msg_time")
+    private Long msgTime;
+
+    @Field("chat_type")
+    private String chatType;
+
+    @Field("client_ip")
+    private String clientIp;
+
+    @Field("cloud_custom_data")
+    private String cloudCustomData;
+
+    @Field("from_account")
+    private String fromAccount;
+
+    @Field("app_service")
+    private String appService;
+
+    @Field("msg_from_platform")
+    private String msgFromPlatform;
+
+    @Field("msg_random")
+    private Long msgRandom;
+
+    @Field("msg_seq")
+    private Long msgSeq;
+
+    @Field("msg_timestamp")
+    private Long msgTimestamp;
+
+    @Field("to_account")
+    private String toAccount;
+
+    @Field("group_id")
+    private String groupId;
+
+    @Field("msg_body")
+    private String msgBody;
+
+}

+ 7 - 0
mec-common/audit-log/src/main/java/com/yonge/log/service/HistoryMessageService.java

@@ -7,6 +7,7 @@ import com.yonge.mongodb.service.BaseServiceWithMongo;
 import java.io.File;
 import java.time.LocalDateTime;
 import java.util.Date;
+import java.util.List;
 
 public interface HistoryMessageService extends BaseServiceWithMongo<String, HistoryMessage> {
 
@@ -24,4 +25,10 @@ public interface HistoryMessageService extends BaseServiceWithMongo<String, Hist
     void updateStatus(String id, Integer status);
 
     void updateAllStatus(int status);
+
+    long querySyncCount();
+
+    PageInfo<HistoryMessage> getImToTencent(long page, int size);
+
+    void updateSyncFlag(String id, int syncFlag);
 }

+ 13 - 0
mec-common/audit-log/src/main/java/com/yonge/log/service/HistoryMessageTenantService.java

@@ -0,0 +1,13 @@
+package com.yonge.log.service;
+
+import com.yonge.log.dal.model.HistoryMessage;
+import com.yonge.log.dal.model.HistoryMessageTencent;
+import com.yonge.mongodb.PageInfo;
+import com.yonge.mongodb.service.BaseServiceWithMongo;
+
+import java.io.File;
+import java.util.Date;
+
+public interface HistoryMessageTenantService extends BaseServiceWithMongo<String, HistoryMessageTencent> {
+
+}

+ 87 - 41
mec-common/audit-log/src/main/java/com/yonge/log/service/impl/HistoryMessageServiceImpl.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.mongodb.operation.AggregateOperation;
 import com.yonge.log.dal.dao.HistoryMessageDao;
 import com.yonge.log.dal.model.HistoryMessage;
+import com.yonge.log.dal.model.HistoryMessageTencent;
 import com.yonge.log.service.HistoryMessageService;
 import com.yonge.mongodb.PageInfo;
 import com.yonge.mongodb.dao.BaseDaoWithMongo;
@@ -15,6 +16,7 @@ import org.springframework.data.mongodb.core.query.Criteria;
 import org.springframework.data.mongodb.core.query.Query;
 import org.springframework.data.mongodb.core.query.Update;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.io.BufferedReader;
 import java.io.File;
@@ -40,8 +42,8 @@ import java.util.zip.ZipInputStream;
 @Service
 public class HistoryMessageServiceImpl extends BaseServiceImplWithMongo<String, HistoryMessage> implements HistoryMessageService {
 
-	@Autowired
-	private HistoryMessageDao historyMessageDao;
+    @Autowired
+    private HistoryMessageDao historyMessageDao;
 
     @Autowired
     private MongoTemplate mongoTemplate;
@@ -51,15 +53,15 @@ public class HistoryMessageServiceImpl extends BaseServiceImplWithMongo<String,
 		return historyMessageDao;
 	}
 
-	@Override
-	public void saveImHistoryMessage(File file) throws Exception {
+    @Override
+    public void saveImHistoryMessage(File file) throws Exception {
 //		long length = file.length();
 //		if(length > 1048576){
-			doNioReadFile(file);
+        doNioReadFile(file);
 //		}else {
 //			doBufferReadFile(file);
 //		}
-	}
+    }
 
     @Override
     public long selectCount(int status, Date date) {
@@ -127,49 +129,93 @@ public class HistoryMessageServiceImpl extends BaseServiceImplWithMongo<String,
         mongoTemplate.updateMulti(query, update, HistoryMessage.class);
     }
 
+    @Override
+    public long querySyncCount() {
+        Query query = new Query();
+
+        Criteria criteria = new Criteria().orOperator(Criteria.where("syncFlag").is(0),Criteria.where("syncFlag").is(null));
+        query.addCriteria(criteria);
+        return mongoTemplate.count(query,HistoryMessage.class);
+    }
+
+    @Override
+    public PageInfo<HistoryMessage> getImToTencent(long page, int size) {
+        PageInfo<HistoryMessage> pageInfo = new PageInfo<HistoryMessage>(Long.valueOf(page).intValue(), size);
+
+        long total = this.querySyncCount();
+        List<HistoryMessage> dataList = null;
+        if (total > 0) {
+            pageInfo.setTotal(total);
+
+            Query query = new Query();
+            Criteria criteria = new Criteria().orOperator(Criteria.where("syncFlag").is(0),Criteria.where("syncFlag").is(null));
+            query.addCriteria(criteria);
+            query.skip(pageInfo.getOffset()).limit(pageInfo.getLimit());
+            dataList = mongoTemplate.find(query, HistoryMessage.class);
+        }
+        if (total == 0) {
+            dataList = new ArrayList<>();
+        }
+        pageInfo.setRows(dataList);
+        return pageInfo;
+    }
+
+    @Override
+    public void updateSyncFlag(String id, int syncFlag) {
+
+        Criteria criteria = Criteria.where("_id").is(id);
+        Query query = new Query(criteria);
+
+        Update update = new Update();
+        update.set("syncFlag", syncFlag); // 设置新的 status 值
+
+        mongoTemplate.updateMulti(query, update, HistoryMessage.class);
+    }
+
+
 //	public static void main(String[] args) throws Exception {
 //		doNioReadFile1(new File("/Users/chenxiaoyu/Documents/77fe9ce6-7d91-4568-afe3-9e8ac351e87f.zip"));
 //	}
 
-	public void doNioReadFile(File file) {
-		ZipInputStream zin = null;
-		try {
-			zin = new ZipInputStream(new FileInputStream(file), StandardCharsets.UTF_8);
-			ZipFile zf = new ZipFile(file);
-			ZipEntry ze;
-			Set<HistoryMessage> historyMessages = new HashSet<>();
-			while ((ze = zin.getNextEntry()) != null) {
-				BufferedReader br = new BufferedReader(new InputStreamReader(zf.getInputStream(ze)));
-				String line;
-				while ((line = br.readLine()) != null) {
-					try {
-						historyMessages.add(JSONObject.parseObject(line.substring(line.indexOf("{")), HistoryMessage.class));
+    public void doNioReadFile(File file) {
+        ZipInputStream zin = null;
+        try {
+            zin = new ZipInputStream(new FileInputStream(file), StandardCharsets.UTF_8);
+            ZipFile zf = new ZipFile(file);
+            ZipEntry ze;
+            Set<HistoryMessage> historyMessages = new HashSet<>();
+            while ((ze = zin.getNextEntry()) != null) {
+                BufferedReader br = new BufferedReader(new InputStreamReader(zf.getInputStream(ze)));
+                String line;
+                while ((line = br.readLine()) != null) {
+                    try {
+                        historyMessages.add(JSONObject.parseObject(line.substring(line.indexOf("{")), HistoryMessage.class));
 //						if(historyMessages.size() >= 2000){
 //							historyMessageDao.batchInsert(new ArrayList<>(historyMessages),HistoryMessage.class);
 //							historyMessages.clear();
 //						}
-					}catch (Exception e){
-						e.printStackTrace();
-					}
-				}
-				br.close();
-				break;
-			}
-			if(historyMessages.size() > 0){
-				historyMessageDao.batchInsert(historyMessages.stream().sorted(Comparator.comparing(HistoryMessage::getDateTime)).collect(Collectors.toList()),HistoryMessage.class);
-			}
-		} catch (IOException e) {
-			e.printStackTrace();
-		} finally {
-			if (zin != null) {
-				try {
-					zin.closeEntry();
-				} catch (IOException e) {
-					e.printStackTrace();
-				}
-			}
-		}
-	}
+                    }catch (Exception e){
+                        e.printStackTrace();
+                    }
+                }
+                br.close();
+                break;
+            }
+            if(historyMessages.size() > 0){
+                historyMessageDao.batchInsert(historyMessages.stream().sorted(Comparator.comparing(HistoryMessage::getDateTime)).collect(Collectors.toList()),HistoryMessage.class);
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            if (zin != null) {
+                try {
+                    zin.closeEntry();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
 
 //	public void doBufferReadFile(File file) throws Exception
 //	{

+ 27 - 0
mec-common/audit-log/src/main/java/com/yonge/log/service/impl/HistoryMessageTenantServiceImpl.java

@@ -0,0 +1,27 @@
+package com.yonge.log.service.impl;
+
+import com.yonge.log.dal.dao.HistoryMessageTenantDao;
+import com.yonge.log.dal.dao.OperationLogDao;
+import com.yonge.log.dal.model.HistoryMessage;
+import com.yonge.log.dal.model.HistoryMessageTencent;
+import com.yonge.log.dal.model.OperationLog;
+import com.yonge.log.service.HistoryMessageTenantService;
+import com.yonge.log.service.OperationLogService;
+import com.yonge.mongodb.dao.BaseDaoWithMongo;
+import com.yonge.mongodb.service.BaseServiceWithMongo;
+import com.yonge.mongodb.service.impl.BaseServiceImplWithMongo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class HistoryMessageTenantServiceImpl extends BaseServiceImplWithMongo<String, HistoryMessageTencent> implements HistoryMessageTenantService {
+
+        @Autowired
+        private HistoryMessageTenantDao historyMessageTenantDao;
+
+        @Override
+        public BaseDaoWithMongo<String, HistoryMessageTencent> getDAO() {
+            return historyMessageTenantDao;
+        }
+
+}