【im消息】下载地址替换,数据修复方法
This commit is contained in:
+3
@@ -99,4 +99,7 @@ public interface TencentCloudImConstant {
|
|||||||
String AP_SHANGHAI_TC_RAW = "https://cos.ap-shanghai.tencentcos.cn";
|
String AP_SHANGHAI_TC_RAW = "https://cos.ap-shanghai.tencentcos.cn";
|
||||||
String AP_SHANGHAI_TC_RP = "http://101.201.149.156:8609/tc";
|
String AP_SHANGHAI_TC_RP = "http://101.201.149.156:8609/tc";
|
||||||
|
|
||||||
|
String CN_RICH_ROW = "https://1600084494-cn.rich.my-imcloud.com";
|
||||||
|
String CN_RICH_RP = "http://101.201.149.156:8610/imdata";
|
||||||
|
|
||||||
}
|
}
|
||||||
+14
@@ -46,9 +46,23 @@ public class TxImMessageConTroller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/syncImMessage")
|
@GetMapping("/syncImMessage")
|
||||||
|
@Operation(summary = "同步IM消息")
|
||||||
public Result<Void> test(String groupId) {
|
public Result<Void> test(String groupId) {
|
||||||
imService.syncGroupHistory(groupId);
|
imService.syncGroupHistory(groupId);
|
||||||
return Result.ok();
|
return Result.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步IM消息(数据修复)
|
||||||
|
*
|
||||||
|
* @param groupIds(修复消息的群组id(多个用,隔开,不传则修复所有数据))
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/syncImMessageRepairData")
|
||||||
|
@Operation(summary = "同步IM消息(数据修复)")
|
||||||
|
public Result<Void> syncImMessageRepairData(String groupIds) {
|
||||||
|
imService.syncImMessageRepairData(groupIds);
|
||||||
|
return Result.ok();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,4 +46,6 @@ public interface ImService {
|
|||||||
Page<ImGroupSyncRecord> listGroupSyncRecord(GroupSyncFilter filter);
|
Page<ImGroupSyncRecord> listGroupSyncRecord(GroupSyncFilter filter);
|
||||||
|
|
||||||
|
|
||||||
|
void syncImMessageRepairData(String groupIds);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONArray;
|
|||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.renkang.consultation.api.ConSessionHelloApi;
|
import com.renkang.consultation.api.ConSessionHelloApi;
|
||||||
@@ -38,6 +39,7 @@ import java.net.URISyntaxException;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.renkang.im.common.TencentCloudImConstant.*;
|
import static com.renkang.im.common.TencentCloudImConstant.*;
|
||||||
|
|
||||||
@@ -347,6 +349,9 @@ public class ImServiceImpl implements ImService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String handleFile(String url) {
|
private String handleFile(String url) {
|
||||||
|
if (!url.startsWith("http")) {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
byte[] fileBytes;
|
byte[] fileBytes;
|
||||||
String fileName = UUID.randomUUID().toString();
|
String fileName = UUID.randomUUID().toString();
|
||||||
try {
|
try {
|
||||||
@@ -386,6 +391,9 @@ public class ImServiceImpl implements ImService {
|
|||||||
if (url.startsWith(AP_SHANGHAI_TC_RAW)) {
|
if (url.startsWith(AP_SHANGHAI_TC_RAW)) {
|
||||||
return url.replace(AP_SHANGHAI_TC_RAW, AP_SHANGHAI_TC_RP);
|
return url.replace(AP_SHANGHAI_TC_RAW, AP_SHANGHAI_TC_RP);
|
||||||
}
|
}
|
||||||
|
if (url.startsWith(CN_RICH_ROW)) {
|
||||||
|
return url.replace(CN_RICH_ROW, CN_RICH_RP);
|
||||||
|
}
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -466,4 +474,72 @@ public class ImServiceImpl implements ImService {
|
|||||||
LambdaQueryWrapper<ImGroupSyncRecord> wrapper = WrapperUtils.initLambdaWrapper(filter);
|
LambdaQueryWrapper<ImGroupSyncRecord> wrapper = WrapperUtils.initLambdaWrapper(filter);
|
||||||
return imGroupSyncRecordMapper.selectPage(filter.getPage(), wrapper);
|
return imGroupSyncRecordMapper.selectPage(filter.getPage(), wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* description: 修复IM消息数据
|
||||||
|
*
|
||||||
|
* @date: 2025/11/27 16:27
|
||||||
|
* @Param groupIds: [java.lang.String]
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void syncImMessageRepairData(String groupIds) {
|
||||||
|
List<String> groupIdArray = new ArrayList<>();
|
||||||
|
if (StrUtil.isNotBlank(groupIds)) {
|
||||||
|
groupIdArray = Arrays.stream(groupIds.split(",")).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
List<ImMsgRecordAll> imMsgRecordAlls = imMsgRecordAllMapper.selectList(new LambdaQueryWrapper<ImMsgRecordAll>()
|
||||||
|
.in(!groupIdArray.isEmpty(), ImMsgRecordAll::getGroupid, groupIdArray)
|
||||||
|
);
|
||||||
|
asyncTaskExecutor.submit(() -> {
|
||||||
|
int index = 0;
|
||||||
|
for (ImMsgRecordAll imMsgRecordAll : imMsgRecordAlls) {
|
||||||
|
index++;
|
||||||
|
try {
|
||||||
|
String contentType = imMsgRecordAll.getContenttype();
|
||||||
|
String content = imMsgRecordAll.getMsgcontent();
|
||||||
|
if (StrUtil.isEmpty(contentType) || StrUtil.isEmpty(content)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
JSONObject jsonObject = JSON.parseObject(content);
|
||||||
|
JSONArray msgBody = jsonObject.getJSONArray(MSG_BODY);
|
||||||
|
boolean isRepair = false;
|
||||||
|
for (int i = 0; i < msgBody.size(); i++) {
|
||||||
|
JSONObject jsonObject1 = msgBody.getJSONObject(i);
|
||||||
|
JSONObject msgContent = jsonObject1.getJSONObject(MSG_CONTENT);
|
||||||
|
switch (contentType) {
|
||||||
|
case TIM_IMAGE_ELEM:
|
||||||
|
handleImageElem(msgContent);
|
||||||
|
isRepair = true;
|
||||||
|
break;
|
||||||
|
case TIM_VIDEO_FILE_ELEM:
|
||||||
|
handleVideoFileElem(msgContent);
|
||||||
|
isRepair = true;
|
||||||
|
break;
|
||||||
|
case TIM_FILE_ELEM:
|
||||||
|
handleFileElem(msgContent);
|
||||||
|
isRepair = true;
|
||||||
|
break;
|
||||||
|
case TIM_SOUND_ELEM:
|
||||||
|
handleSoundElem(msgContent);
|
||||||
|
isRepair = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isRepair) {
|
||||||
|
imMsgRecordAllMapper.update(new LambdaUpdateWrapper<ImMsgRecordAll>()
|
||||||
|
.eq(ImMsgRecordAll::getId, imMsgRecordAll.getId())
|
||||||
|
.set(ImMsgRecordAll::getMsgcontent, jsonObject.toJSONString())
|
||||||
|
);
|
||||||
|
log.info("修复数据(数据id:{})成功:{}", imMsgRecordAll.getId(), jsonObject.toJSONString());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("修复数据(数据id:{})失败:{}", imMsgRecordAll.getId(), e.getMessage());
|
||||||
|
} finally {
|
||||||
|
//修复进度
|
||||||
|
log.info("======修复进度:{}/{}", index, imMsgRecordAlls.size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user