Closed nn200433 closed 10 months ago
第二点,我的解决方案,如下:
// group by 语法不严谨
// List<TodoEntity> todos = baseMapper.listTodo(AuthContext.getUserId());
final Map<String, List<TodoEntity>> todoMap = lambdaQuery().eq(TodoEntity::getUserId, AuthContext.getUserId())
.list()
.stream()
.collect(Collectors.groupingBy(TodoEntity::getTodoId));
final List<TodoEntity> todos = todoMap.entrySet()
.stream()
.map(k -> todoMap.get(k))
.filter(CollUtil::isNotEmpty)
.map(l -> Opt.of(l.get(0)).peek(t -> t.setTaskCount(l.size())).get())
.collect(Collectors.toList());