REQ-3345: 解决查询不到账号的问题

This commit is contained in:
yanglin 2025-02-18 16:37:27 +08:00
parent 86a2e2fdbe
commit e1cb4c61ce
2 changed files with 7 additions and 9 deletions

View File

@ -64,13 +64,13 @@ public class GroupManager {
BizAssertions.assertTrue(request.getPeople().size() > 1, "群成员数量(含群主)不能少于2");
groupSupport.log(0L, "create-group:preparing", request);
// DON'T delete this line
accountService.getOrCreateImAccounts(request.getPeople());
accountService.maybeCreateImAccounts(request.getPeople());
return transactionTemplate.execute(unused -> {
Group savedGroup = groupDao.findByBizCode(request.getBizCode(), request.getGroupType(), true)
.orElse(null);
BizAssertions.assertTrue(savedGroup == null || savedGroup.isDismissed(),
String.format("群已经存在: %s", request.getName()));
ImAccounts imAccounts = accountService.getOrCreateImAccounts(request.getPeople());
ImAccounts imAccounts = accountService.getAccountsByPersons(request.getPeople());
String owner = imAccounts.findAccount(request.getOwner()).orElse(null);
BizAssertions.assertNotNull(owner, "群主没有IM账号, 无法创建群. {}", request.getOwner());
Group group = groupSupport.buildNewGroup(request, imAccounts);
@ -119,7 +119,7 @@ public class GroupManager {
public GroupAddMembersResponse addMembers(GroupAddMembersRequest request) {
// DON'T delete this line
accountService.getOrCreateImAccounts(request.getMembers());
accountService.maybeCreateImAccounts(request.getMembers());
return transactionTemplate.execute(unused -> {
Group group = getGroupForUpdateOrThrow(request.getTid());
groupSupport.log(group.getTid(), "add-members", request);
@ -135,7 +135,7 @@ public class GroupManager {
return new GroupAddMembersResponse();
BizAssertions.assertTrue(group.addMoreMembers(prePersons.size() + addPersons.size()),
"群聊人数上限{}人, 请删除部分已选人员", group.getMemberLimit());
ImAccounts imAccounts = accountService.getOrCreateImAccounts(addPersons);
ImAccounts imAccounts = accountService.getAccountsByPersons(addPersons);
if (imAccounts.isAccountEmpty()) {
notification.send("添加群成员[{},{}], 有效群成员IM账号列表为空. 请求成员信息: {}",
group.getTid(), group.getName(), JSON.toJSONString(request.getMembers()));

View File

@ -393,12 +393,10 @@ public class AccountService {
/**
* 无法保证所有账号创建成功可能的原因是因为人员的信息不全或者是人员信息不正确
*/
public ImAccounts getOrCreateImAccounts(Set<PersonAccountAttribute> persons) {
public void maybeCreateImAccounts(Set<PersonAccountAttribute> persons) {
ImAccounts imAccounts = getAccountsByPersons(persons);
if (imAccounts.getAccountSize() == persons.size())
return imAccounts;
registerAccountIfAbsent(persons);
return getAccountsByPersons(persons);
if (imAccounts.getAccountSize() != persons.size())
registerAccountIfAbsent(persons);
}
public void registerAccountIfAbsent(Collection<PersonAccountAttribute> persons) {