VirtualFleetSettlementDetail virtualFleetSettlementDetail = new VirtualFleetSettlementDetail();
virtualFleetSettlementDetail.setUserId(1L);
virtualFleetSettlementDetail.setActivityId(1);
virtualFleetSettlementDetail.setTeamId(1);
virtualFleetSettlementDetail.setMemberGrowthValue(100);
virtualFleetSettlementDetail.setSettlementId(1);
VirtualFleetSettlementDetail virtualFleetSettlementDetail2 = new VirtualFleetSettlementDetail();
virtualFleetSettlementDetail2.setUserId(1L);
virtualFleetSettlementDetail2.setTeamId(1);
virtualFleetSettlementDetail2.setActivityId(1);
virtualFleetSettlementDetail2.setMemberGrowthValue(400);
virtualFleetSettlementDetail2.setSettlementId(1);
VirtualFleetSettlementDetail virtualFleetSettlementDetail4 = new VirtualFleetSettlementDetail();
virtualFleetSettlementDetail4.setUserId(1L);
virtualFleetSettlementDetail4.setTeamId(2);
virtualFleetSettlementDetail4.setActivityId(1);
virtualFleetSettlementDetail4.setMemberGrowthValue(300);
virtualFleetSettlementDetail4.setSettlementId(1);
VirtualFleetSettlementDetail virtualFleetSettlementDetail3 = new VirtualFleetSettlementDetail();
virtualFleetSettlementDetail3.setUserId(2L);
virtualFleetSettlementDetail3.setTeamId(1);
virtualFleetSettlementDetail3.setActivityId(1);
virtualFleetSettlementDetail3.setMemberGrowthValue(100);
virtualFleetSettlementDetail3.setSettlementId(1);
List<VirtualFleetSettlementDetail> pageList = new ArrayList<>();
pageList.add(virtualFleetSettlementDetail);
pageList.add(virtualFleetSettlementDetail2);
pageList.add(virtualFleetSettlementDetail3);
pageList.add(virtualFleetSettlementDetail4);
List<VirtualFleetSettlementDetail> newpageList = new ArrayList<>();
pageList.parallelStream()
.collect(Collectors.groupingBy(o -> (o.getActivityId() + "" + o.getTeamId() + "" + o.getUserId() + "" + o.getSettlementId()), Collectors.toList()))
.forEach(
(id, transfer) -> {
transfer.stream().reduce((a, b) -> new VirtualFleetSettlementDetail().setActivityId(a.getActivityId())
.setTeamId(a.getTeamId()).setUserId(a.getUserId()).setSettlementId(a.getSettlementId())
.setMemberGrowthValue(a.getMemberGrowthValue() + b.getMemberGrowthValue())).
ifPresent(newpageList::add);
});
System.out.println("newpageList==" + newpageList);
结果:
newpageList==[VirtualFleetSettlementDetail(activityId=1, settlementId=1, activityCode=null, teamId=2, userId=1, phone=null, captain=null, teamLevel=null, rightsType=null, memberGrowthValue=300, couponType=null, couponCode=null, couponTitle=null, couponSubTitle=null, couponConditionMoney=null, couponMoney=null, couponCount=null, couponIconUrl=null, status=null), VirtualFleetSettlementDetail(activityId=1, settlementId=1, activityCode=null, teamId=1, userId=1, phone=null, captain=null, teamLevel=null, rightsType=null, memberGrowthValue=500, couponType=null, couponCode=null, couponTitle=null, couponSubTitle=null, couponConditionMoney=null, couponMoney=null, couponCount=null, couponIconUrl=null, status=null), VirtualFleetSettlementDetail(activityId=1, settlementId=1, activityCode=null, teamId=1, userId=2, phone=null, captain=null, teamLevel=null, rightsType=null, memberGrowthValue=100, couponType=null, couponCode=null, couponTitle=null, couponSubTitle=null, couponConditionMoney=null, couponMoney=null, couponCount=null, couponIconUrl=null, status=null)]
[VirtualFleetSettlementDetail(activityId = 1, settlementId = 1, activityCode = null, teamId = 2, userId = 1, phone = null, captain = null, teamLevel = null, rightsType = null, memberGrowthValue = 300, couponType = null, couponCode = null, couponTitle = null, couponSubTitle = null, couponConditionMoney = null, couponMoney = null, couponCount = null, couponIconUrl = null, status = null),
VirtualFleetSettlementDetail(activityId = 1, settlementId = 1, activityCode = null, teamId = 1, userId = 1, phone = null, captain = null, teamLevel = null, rightsType = null, memberGrowthValue = 500, couponType = null, couponCode = null, couponTitle = null, couponSubTitle = null, couponConditionMoney = null, couponMoney = null, couponCount = null, couponIconUrl = null, status = null),
VirtualFleetSettlementDetail(activityId = 1, settlementId = 1, activityCode = null, teamId = 1, userId = 2, phone = null, captain = null, teamLevel = null, rightsType = null, memberGrowthValue = 100, couponType = null, couponCode = null, couponTitle = null, couponSubTitle = null, couponConditionMoney = null, couponMoney = null, couponCount = null, couponIconUrl = null, status = null)]