feat(im): 新增importAccountsWithNames方法,addGroupMember时批量导入账号名称
- 新增 importAccountsWithNames 方法,使用腾讯IM新版 AccountList 格式导入账号及昵称 - addGroupMember 改为调用新方法,一次批量导入账号+名称 - multiAccountImport 旧方法保持不变,不影响其他调用方 - AddGroupMemberDTO.memberName 移除@JsonIgnore,确保Feign跨服务传输 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -164,6 +164,22 @@ public class TencentCloudImUtil {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入多个账号(带昵称)
|
||||||
|
*
|
||||||
|
* @param accounts 账号信息列表,每个元素包含 UserID 和可选的 Nick
|
||||||
|
*/
|
||||||
|
public String importAccountsWithNames(List<JSONObject> accounts) {
|
||||||
|
Integer random = RandomUtils.nextInt(0, 999999999);
|
||||||
|
String httpsUrl = getHttpsUrl(TencentCloudImApiConstant.AccountManage.MULTI_ACCOUNT_IMPORT, random);
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("AccountList", accounts);
|
||||||
|
log.info("腾讯云im导入多个账号,请求参数:{}", jsonObject);
|
||||||
|
String result = HttpUtil.doPost(httpsUrl, jsonObject);
|
||||||
|
log.info("腾讯云im导入多个账户,返回结果:{}", result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除账号
|
* 删除账号
|
||||||
*
|
*
|
||||||
@@ -526,22 +542,18 @@ public class TencentCloudImUtil {
|
|||||||
*/
|
*/
|
||||||
public AddGroupMemberVO addGroupMember(AddGroupMemberDTO dto) {
|
public AddGroupMemberVO addGroupMember(AddGroupMemberDTO dto) {
|
||||||
try {
|
try {
|
||||||
// 先导入账号,确保成员在IM系统中已注册
|
// 先导入账号及其名称,确保成员在IM系统中已注册
|
||||||
if (dto.getMemberList() != null && !dto.getMemberList().isEmpty()) {
|
if (dto.getMemberList() != null && !dto.getMemberList().isEmpty()) {
|
||||||
List<String> memberAccounts = dto.getMemberList().stream()
|
// 构建腾讯IM新版 AccountList 格式(含昵称)
|
||||||
.map(AddGroupMemberDTO.MemberListDTO::getMemberAccount)
|
List<JSONObject> accountList = dto.getMemberList().stream().map(member -> {
|
||||||
.collect(Collectors.toList());
|
JSONObject account = new JSONObject();
|
||||||
multiAccountImport(memberAccounts);
|
account.put("UserID", member.getMemberAccount());
|
||||||
// 导入成员名称(失败不影响主流程)
|
|
||||||
for (AddGroupMemberDTO.MemberListDTO member : dto.getMemberList()) {
|
|
||||||
if (StringUtils.isNotEmpty(member.getMemberName())) {
|
if (StringUtils.isNotEmpty(member.getMemberName())) {
|
||||||
try {
|
account.put("Nick", member.getMemberName());
|
||||||
accountImport(member.getMemberAccount(), member.getMemberName(), null);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.warn("导入群成员名称失败, account={}, name={}", member.getMemberAccount(), member.getMemberName(), e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
return account;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
importAccountsWithNames(accountList);
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer random = RandomUtils.nextInt(0, 999999999);
|
Integer random = RandomUtils.nextInt(0, 999999999);
|
||||||
|
|||||||
Reference in New Issue
Block a user