|
@@ -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为空");
|
|
|
}
|