public List<UserTicket> list(UserTicketRefCondition condition) {
List<UserTicket> list = UserTicketMapperStruct.INSTANCE.po2Entity4List(userTicketRefRepositoryService.list(condition));
if (CollectionUtil.isNotEmpty(list)){
// 取出要批量查询的用户id
List<Long> userIds = list.stream().map(UserTicket::getUserId).toList();
// 根据ids取出对应的数据
List<UserInfo> userInfos = userInfoService.getUserListByIds(userIds);
// 构造用户id到用户信息的映射
Map<Long, UserInfo> userInfoMap = userInfos.stream().collect(Collectors.toMap(UserInfo::getId, Function.identity()));
// 遍历赋值
list.forEach(userTicket -> {
UserInfo userInfo = userInfoMap.get(userTicket.getUserId());
if (ObjectUtils.isNotEmpty(userInfo)){
userTicket.setUserName(userInfo.getPhone());
}
});
}
return list;
}
java stream流学习记录
最新推荐文章于 2024-11-03 11:01:20 发布