/**
* 根据getPersonIdNumber分组
* 按照getAppearTime max 排序 取第一条
*/
private List<TracePointPersonLog> getMaxTimeList(List<TracePointPersonLog> tracePointPersonLogList) {
if (CollectionUtils.isEmpty(tracePointPersonLogList)) {
return Collections.emptyList();
}
return tracePointPersonLogList.stream()
.collect(Collectors.groupingBy(TracePointPersonLog::getPersonIdNumber,
Collectors.maxBy(Comparator.comparing(TracePointPersonLog::getAppearTime))))
.values()
.stream()
.flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty))
.sorted(Comparator.comparing(TracePointPersonLog::getAppearTime).reversed())
.collect(Collectors.toList());
}
Java1.8按某个字段分组每组取出最大时间的一条数据
于 2023-02-27 10:26:51 首次发布