This commit is contained in:
xd 2024-04-30 08:26:27 +08:00
parent 22fb459e53
commit 71910079e6
1 changed files with 12 additions and 1 deletions

View File

@ -138,7 +138,18 @@ public class SysNoticeController extends BaseController
Map<String, List<SysNoticeUser>> groupedByNoticeType = list.stream() Map<String, List<SysNoticeUser>> groupedByNoticeType = list.stream()
.collect(Collectors.groupingBy(SysNoticeUser::getSendTimeFormat)); .collect(Collectors.groupingBy(SysNoticeUser::getSendTimeFormat));
for(String key:groupedByNoticeType.keySet()){
// 使用TreeMap并提供一个Comparator用于排序key
Map<String, List<SysNoticeUser>> sortedMap = new TreeMap<>(new Comparator<String>() {
@Override
public int compare(String k1, String k2) {
// 降序排序
return k2.compareTo(k1);
}
});
sortedMap.putAll(groupedByNoticeType);
for(String key:sortedMap.keySet()){
List<SysNoticeUser> lt = groupedByNoticeType.get(key); List<SysNoticeUser> lt = groupedByNoticeType.get(key);
lt.sort((t1, t2) -> t2.getSendTime().compareTo(t1.getSendTime())); lt.sort((t1, t2) -> t2.getSendTime().compareTo(t1.getSendTime()));
map = new HashMap<>(); map = new HashMap<>();