创建群,拉假人入群
This commit is contained in:
@@ -38,4 +38,9 @@ public interface IFakeUserService {
|
||||
* 获取假人列表
|
||||
*/
|
||||
List<User> getFakeUsers();
|
||||
|
||||
/**
|
||||
* 从现有假人中随机挑选指定数量
|
||||
*/
|
||||
List<User> pickFakeUsers(int count);
|
||||
}
|
||||
|
||||
@@ -174,4 +174,18 @@ public class FakeUserServiceImpl implements IFakeUserService {
|
||||
.eq(User::getIsFake, 1)
|
||||
.eq(User::getStatus, 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* 从现有假人中随机挑选指定数量
|
||||
*/
|
||||
@Override
|
||||
public List<User> pickFakeUsers(int count) {
|
||||
List<User> fakes = getFakeUsers();
|
||||
if (fakes.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
Collections.shuffle(fakes, RANDOM);
|
||||
int size = Math.min(count, fakes.size());
|
||||
return new ArrayList<>(fakes.subList(0, size));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.tailbet.mapper.UserMapper;
|
||||
import com.tailbet.openim.OpenIMApiClient;
|
||||
import com.tailbet.service.IGroupService;
|
||||
import com.tailbet.service.IAuditService;
|
||||
import com.tailbet.service.IFakeUserService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -38,6 +39,7 @@ public class GroupServiceImpl implements IGroupService {
|
||||
private final UserMapper userMapper;
|
||||
private final SysConfigMapper sysConfigMapper;
|
||||
private final IAuditService auditService;
|
||||
private final IFakeUserService fakeUserService;
|
||||
private final OpenIMApiClient openIMApiClient;
|
||||
|
||||
/**
|
||||
@@ -132,16 +134,31 @@ public class GroupServiceImpl implements IGroupService {
|
||||
groupMemberMapper.insert(buildMember(groupId, botUserId, ROLE_NORMAL, now));
|
||||
}
|
||||
|
||||
// OpenIM 侧建群:群主为 owner,机器人作为初始成员
|
||||
List<String> memberUserIDs = ownerIsBot
|
||||
? List.of()
|
||||
: List.of(String.valueOf(botUserId));
|
||||
// 机器人入群
|
||||
if (!ownerIsBot) {
|
||||
groupMemberMapper.insert(buildMember(groupId, botUserId, ROLE_NORMAL, now));
|
||||
}
|
||||
|
||||
// 从现有假人中挑选10个进群
|
||||
List<User> fakeUsers = fakeUserService.pickFakeUsers(10);
|
||||
for (User fake : fakeUsers) {
|
||||
groupMemberMapper.insert(buildMember(groupId, fake.getId(), ROLE_NORMAL, now));
|
||||
}
|
||||
|
||||
// OpenIM 侧建群:群主、机器人和假人作为初始成员
|
||||
List<String> memberUserIDs = new java.util.ArrayList<>();
|
||||
if (!ownerIsBot) {
|
||||
memberUserIDs.add(String.valueOf(botUserId));
|
||||
}
|
||||
fakeUsers.stream()
|
||||
.map(fake -> String.valueOf(fake.getId()))
|
||||
.forEach(memberUserIDs::add);
|
||||
openIMApiClient.createGroup(String.valueOf(groupId), name, String.valueOf(ownerUserId), memberUserIDs);
|
||||
|
||||
// 审计日志
|
||||
auditService.log(groupId, null, operatorId, "CREATE_GROUP",
|
||||
String.format("{\"name\":\"%s\",\"ownerUserId\":%d,\"botUserId\":%d}",
|
||||
name.replace("\\", "\\\\").replace("\"", "\\\""), ownerUserId, botUserId));
|
||||
String.format("{\"name\":\"%s\",\"ownerUserId\":%d,\"botUserId\":%d,\"fakeCount\":%d}",
|
||||
name.replace("\\", "\\\\").replace("\"", "\\\""), ownerUserId, botUserId, fakeUsers.size()));
|
||||
|
||||
log.info("创建群成功: groupId={}, name={}, ownerUserId={}, botUserId={}, operatorId={}",
|
||||
groupId, name, ownerUserId, botUserId, operatorId);
|
||||
|
||||
Reference in New Issue
Block a user