代码如下:
public class Service{
public IPage<ChannelAgentOrgVO> getChannelAgentTeamStream(Page<ChannelAgentOrgVO> page, Channel channel) {
Page<Channel> channelPage = this.getPage(new Page<>(page.getCurrent(), page.getSize()), channel);
Stream<Channel> channelStream = channelPage.getRecords().stream();
Stream<ChannelAgentOrgVO> voStream = channelStream.map(c -> {
ChannelAgentOrgVO vo = new ChannelAgentOrgVO();
vo.setChannel(c);
return vo;
});
List<Long> channelOrgIds = channelPage.getRecords().stream().map(Channel::getChannelOrgId).collect(Collectors.toList());
List<Long> agentOrgIds = channelPage.getRecords().stream().map(Channel::getAgentOrgId).collect(Collectors.toList());
List<Long> agentTeamIds = channelPage.getRecords().stream().map(Channel::getAgentTeamId).collect(Collectors.toList());
List<ChannelOrg> channelOrgList = channelOrgService.lambdaQuery().in(ChannelOrg::getId, channelOrgIds)
.select(ChannelOrg::getId,
ChannelOrg::getCode,
ChannelOrg::getName,
ChannelOrg::getFullName,
ChannelOrg::getType)
.list();
List<Org> agentOrgList = agentOrgService.lambdaQuery().in(Org::getId, agentOrgIds)
.select(Org::getId,
Org::getCode,
Org::getName,
Org::getFullName,
Org::getType)
.list();
List<AgentTeam> agentTeamList = agentTeamService.lambdaQuery().in(AgentTeam::getId, agentTeamIds)
.select(AgentTeam::getId,
AgentTeam::getName,
AgentTeam::getFullName,
AgentTeam::getAddressDetail,
AgentTeam::getAddressName,
AgentTeam::getAddressContact)
.list();
voStream = voStream.peek(vo -> channelOrgList.forEach(channelOrg -> {
if (Objects.equals(channelOrg.getId(), vo.getChannel().getChannelOrgId())) {
vo.setChannelOrg(channelOrg);
}
}));
voStream = voStream.peek(vo -> agentOrgList.forEach(agentOrg -> {
if (Objects.equals(agentOrg.getId(), vo.getChannel().getAgentOrgId())) {
vo.setAgentOrg(agentOrg);
}
}));
voStream = voStream.map(vo -> {
agentTeamList.forEach(agentTeam -> {
if (Objects.equals(agentTeam.getId(), vo.getChannel().getAgentTeamId())) {
vo.setAgentTeam(agentTeam);
}
});
return vo;
});
return new PageResult<>(channelPage, voStream.collect(Collectors.toList())).getVoPage();
}
}
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.