【发布时间】:2022-01-12 12:57:44
【问题描述】:
@Override
public List<ExpenseListingDTO> getExpenseListByServiceFileId(Long serviceFileId) {
if (Long.valueOf(serviceFileId) != null) {
List<ExpenseListDetail> expenseListDetail = expenseListDetailRepository.findByServiceFileId(serviceFileId);
List<ExpenseList> expenseList = expenseListRepository.findByExpenseListDetailListIn(expenseListDetail);
//
List<ExpenseListingDTO> expenseListDtoList = expenseListMapper.expenseListDTOToExpenseListingDTO(expenseListMapper.entityListToDtoList(expenseList));
expenseListDtoList.parallelStream().forEach(dto -> {
dto.setTotalAmount(
expenseListDetail.stream().filter(s -> s.getOperationType().equals(OperationType.NEW_EXPENSE.getValue()) || s.getOperationType().equals(OperationType.EXPENSE_RETURN.getValue()))
.filter(s -> !s.getStatus().equals(ExpenseListDetailStatus.PASSIVE.getValue())).map(ExpenseListDetail::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add));
});
return expenseListDtoList.stream()
.distinct()
.collect(Collectors.toList());
}
return Collections.emptyList();
}
此函数返回一个列表。但是我的输出中有一些相同的列表。我想删除重复项。但它没有用。这里有什么问题?
【问题讨论】:
-
返回集合而不是列表返回费用ListDtoList.stream() .distinct() .collect(Collectors.toSet())
-
它应该返回列表。我不能使用 .toSet :(
-
您可以将该集合转换为列表。
-
可以添加
ExpenseListingDTO的完整代码吗?你实现equals()方法了吗?