feat(通知): 四级严重度与严重度/时间双排序,客户端与后台管理同步
通知表新增 severity(紧急/高危/中危/低危,V161),由 scene + level 推导且 不回改 level:老客户端配色不受影响,secret_balance 的余量偏低与欠费也能分档。 列表与聚合接口默认按严重度倒序(同档按时间倒序),sort=time 切纯时间排序; 聚合组取组内最高严重度。两端铃铛加彩色等级标签与排序切换,展开明细沿用 同一排序,严重度排序下隐藏会跨天误导的日期头。
This commit is contained in:
+5
-3
@@ -37,7 +37,7 @@ class AdminNotificationControllerTest {
|
||||
controller.summary(request);
|
||||
controller.page(request, 1L, 20L, false, "余额", NotificationService.CATEGORY_CONFIG_ERROR,
|
||||
LocalDate.of(2026, 9, 10), LocalDate.of(2026, 9, 13),
|
||||
"task_partial", LocalDate.of(2026, 9, 12), 1160L, false);
|
||||
"task_partial", LocalDate.of(2026, 9, 12), 1160L, false, NotificationService.SORT_TIME);
|
||||
|
||||
verify(notificationService).summary(24L, NotificationService.AUDIENCE_ADMIN);
|
||||
ArgumentCaptor<NotificationPageQuery> queryCaptor = ArgumentCaptor.forClass(NotificationPageQuery.class);
|
||||
@@ -55,6 +55,7 @@ class AdminNotificationControllerTest {
|
||||
assertThat(query.getDay()).isEqualTo(LocalDate.of(2026, 9, 12));
|
||||
assertThat(query.getSubjectUserId()).isEqualTo(1160L);
|
||||
assertThat(query.getSubjectUnlabelled()).isFalse();
|
||||
assertThat(query.getSort()).isEqualTo(NotificationService.SORT_TIME);
|
||||
}
|
||||
|
||||
/** 聚合视图与单条列表读的是同一份"谁的副本",这里守 groups 这条新出口别绕过管理员维度。 */
|
||||
@@ -62,10 +63,11 @@ class AdminNotificationControllerTest {
|
||||
void groupsUseOperatorIdAndAdminAudience() {
|
||||
when(adminAuthSupport.requireConsoleOperator(request)).thenReturn(admin(24L));
|
||||
|
||||
controller.groups(request, 1L, 20L, false, null, null, null, null);
|
||||
controller.groups(request, 1L, 20L, false, null, null, null, null, NotificationService.SORT_SEVERITY);
|
||||
|
||||
verify(notificationService).groups(eq(24L), eq(NotificationService.AUDIENCE_ADMIN),
|
||||
argThat(query -> query.getPage().equals(1L) && query.getPageSize().equals(20L)));
|
||||
argThat(query -> query.getPage().equals(1L) && query.getPageSize().equals(20L)
|
||||
&& NotificationService.SORT_SEVERITY.equals(query.getSort())));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-1
@@ -35,7 +35,7 @@ class NotificationControllerTest {
|
||||
controller.summary(request);
|
||||
controller.page(request, 2L, 20L, true, "欠费", NotificationService.CATEGORY_TASK_ERROR,
|
||||
LocalDate.of(2026, 9, 1), LocalDate.of(2026, 9, 13),
|
||||
"task_failed", LocalDate.of(2026, 9, 5));
|
||||
"task_failed", LocalDate.of(2026, 9, 5), NotificationService.SORT_TIME);
|
||||
|
||||
verify(notificationService).summary(1095L, NotificationService.AUDIENCE_USER);
|
||||
ArgumentCaptor<NotificationPageQuery> queryCaptor = ArgumentCaptor.forClass(NotificationPageQuery.class);
|
||||
@@ -50,6 +50,7 @@ class NotificationControllerTest {
|
||||
assertThat(query.getEndDate()).isEqualTo(LocalDate.of(2026, 9, 13));
|
||||
assertThat(query.getScene()).isEqualTo("task_failed");
|
||||
assertThat(query.getDay()).isEqualTo(LocalDate.of(2026, 9, 5));
|
||||
assertThat(query.getSort()).isEqualTo(NotificationService.SORT_TIME);
|
||||
// 桌面端的主体用户就是本人,接口不暴露 subjectUserId,展开只靠 场景+自然日
|
||||
assertThat(query.getSubjectUserId()).isNull();
|
||||
}
|
||||
|
||||
+27
@@ -156,6 +156,33 @@ class NotificationGroupTest {
|
||||
List.of(headline(6, "t", "c")));
|
||||
|
||||
assertThat(groups().getGroups().get(0).getLevel()).isEqualTo("error");
|
||||
// 严重度同样取组内最高:service_down 不论 level 都是紧急
|
||||
assertThat(groups().getGroups().get(0).getSeverity())
|
||||
.isEqualTo(NotificationService.SEVERITY_URGENT);
|
||||
}
|
||||
|
||||
/** 默认按严重度:高危组即使更旧也排在中危组前面;切 time 才回到自然日倒序。 */
|
||||
@Test
|
||||
void defaultGroupOrderPutsHigherSeverityFirstAndTimeSortRestoresDayOrder() {
|
||||
stub(List.of(
|
||||
row(9, "task_partial", 1160L, LocalDate.of(2026, 10, 13), "warning", null),
|
||||
row(8, "task_failed", 1160L, LocalDate.of(2026, 10, 12), "warning", null)),
|
||||
List.of(headline(9, "t", "c"), headline(8, "t", "c")));
|
||||
|
||||
NotificationGroupPageVo bySeverity = groups();
|
||||
assertThat(bySeverity.getGroups()).extracting(NotificationGroupVo::getScene)
|
||||
.containsExactly("task_failed", "task_partial");
|
||||
assertThat(bySeverity.getGroups()).extracting(NotificationGroupVo::getSeverity)
|
||||
.containsExactly(NotificationService.SEVERITY_HIGH, NotificationService.SEVERITY_MEDIUM);
|
||||
|
||||
NotificationPageQuery timeQuery = new NotificationPageQuery();
|
||||
timeQuery.setSort(NotificationService.SORT_TIME);
|
||||
NotificationGroupPageVo byTime = service.groups(24L, NotificationService.AUDIENCE_ADMIN, timeQuery);
|
||||
|
||||
assertThat(byTime.getGroups()).extracting(NotificationGroupVo::getScene)
|
||||
.containsExactly("task_partial", "task_failed");
|
||||
assertThat(byTime.getGroups()).extracting(NotificationGroupVo::getDay)
|
||||
.containsExactly(LocalDate.of(2026, 10, 13), LocalDate.of(2026, 10, 12));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+91
@@ -70,6 +70,7 @@ class NotificationServiceTest {
|
||||
assertThat(row.getAudience()).isEqualTo("user");
|
||||
assertThat(row.getScene()).isEqualTo("secret_balance");
|
||||
assertThat(row.getLevel()).isEqualTo("error");
|
||||
assertThat(row.getSeverity()).isEqualTo(NotificationService.SEVERITY_URGENT);
|
||||
assertThat(row.getTitle()).isEqualTo("代理欠费");
|
||||
assertThat(row.getContent()).isEqualTo("余额不足");
|
||||
assertThat(row.getDedupeKey()).isEqualTo("secret_balance:7:proxy:20260913");
|
||||
@@ -335,6 +336,96 @@ class NotificationServiceTest {
|
||||
.isEqualTo(NotificationService.CATEGORY_CONFIG_ERROR);
|
||||
}
|
||||
|
||||
/** 列表项还必须带严重度:后端是唯一推导源,前端不再各自按 scene/level 猜。 */
|
||||
@Test
|
||||
void pageItemsCarrySeverity() {
|
||||
UserNotificationEntity row = new UserNotificationEntity();
|
||||
row.setId(9L);
|
||||
row.setScene(NotificationService.SCENE_TASK_FAILED);
|
||||
row.setLevel(NotificationService.LEVEL_WARNING);
|
||||
when(mapper.selectCount(any())).thenReturn(1L, 0L);
|
||||
when(mapper.selectList(any())).thenReturn(List.of(row));
|
||||
|
||||
NotificationPageVo page = service.page(7L, NotificationService.AUDIENCE_USER,
|
||||
NotificationPageQuery.of(1L, 20L, false, null, null, null, null));
|
||||
|
||||
assertThat(page.getItems().get(0).getSeverity())
|
||||
.isEqualTo(NotificationService.SEVERITY_HIGH);
|
||||
}
|
||||
|
||||
/** 四级严重度的唯一推导口径:scene 优先,level 区分同场景轻重。 */
|
||||
@Test
|
||||
void severityMapsScenesAndLevelsToFourBands() {
|
||||
assertThat(NotificationService.severityOf(NotificationService.SCENE_SERVICE_DOWN,
|
||||
NotificationService.LEVEL_WARNING)).isEqualTo(NotificationService.SEVERITY_URGENT);
|
||||
assertThat(NotificationService.severityOf(NotificationService.SCENE_SECRET_BALANCE,
|
||||
NotificationService.LEVEL_ERROR)).isEqualTo(NotificationService.SEVERITY_URGENT);
|
||||
assertThat(NotificationService.severityOf(NotificationService.SCENE_SECRET_BALANCE,
|
||||
NotificationService.LEVEL_WARNING)).isEqualTo(NotificationService.SEVERITY_MEDIUM);
|
||||
assertThat(NotificationService.severityOf(NotificationService.SCENE_TASK_FAILED,
|
||||
NotificationService.LEVEL_WARNING)).isEqualTo(NotificationService.SEVERITY_HIGH);
|
||||
assertThat(NotificationService.severityOf(NotificationService.SCENE_SECRET_INVALID,
|
||||
NotificationService.LEVEL_WARNING)).isEqualTo(NotificationService.SEVERITY_HIGH);
|
||||
assertThat(NotificationService.severityOf(NotificationService.SCENE_MAIXIANG_ANOMALY,
|
||||
NotificationService.LEVEL_WARNING)).isEqualTo(NotificationService.SEVERITY_HIGH);
|
||||
assertThat(NotificationService.severityOf(NotificationService.SCENE_TASK_PARTIAL,
|
||||
NotificationService.LEVEL_WARNING)).isEqualTo(NotificationService.SEVERITY_MEDIUM);
|
||||
assertThat(NotificationService.severityOf(NotificationService.SCENE_SYSTEM,
|
||||
NotificationService.LEVEL_INFO)).isEqualTo(NotificationService.SEVERITY_LOW);
|
||||
// 未登记 scene 不让通知失去分档:按 level 兜底
|
||||
assertThat(NotificationService.severityOf("legacy_scene", NotificationService.LEVEL_ERROR))
|
||||
.isEqualTo(NotificationService.SEVERITY_URGENT);
|
||||
assertThat(NotificationService.severityOf("legacy_scene", NotificationService.LEVEL_INFO))
|
||||
.isEqualTo(NotificationService.SEVERITY_LOW);
|
||||
assertThat(NotificationService.severityOf(null, null))
|
||||
.isEqualTo(NotificationService.SEVERITY_MEDIUM);
|
||||
assertThat(NotificationService.severityRank(NotificationService.SEVERITY_URGENT))
|
||||
.isGreaterThan(NotificationService.severityRank(NotificationService.SEVERITY_HIGH));
|
||||
assertThat(NotificationService.severityRank(NotificationService.SEVERITY_HIGH))
|
||||
.isGreaterThan(NotificationService.severityRank(NotificationService.SEVERITY_MEDIUM));
|
||||
assertThat(NotificationService.severityRank(NotificationService.SEVERITY_MEDIUM))
|
||||
.isGreaterThan(NotificationService.severityRank(NotificationService.SEVERITY_LOW));
|
||||
}
|
||||
|
||||
/** 默认排序必须在 SQL 侧按严重度分档;分页不能先按 id 取一页再在内存里排。 */
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void pageDefaultSortUsesSeverityCase() {
|
||||
when(mapper.selectCount(any())).thenReturn(1L, 0L);
|
||||
when(mapper.selectList(any())).thenReturn(List.of());
|
||||
|
||||
service.page(7L, NotificationService.AUDIENCE_USER,
|
||||
NotificationPageQuery.of(1L, 20L, false, null, null, null, null));
|
||||
|
||||
ArgumentCaptor<LambdaQueryWrapper<UserNotificationEntity>> captor =
|
||||
ArgumentCaptor.forClass(LambdaQueryWrapper.class);
|
||||
verify(mapper).selectList(captor.capture());
|
||||
assertThat(captor.getValue().getSqlSegment())
|
||||
.contains("CASE severity")
|
||||
.contains("'urgent'")
|
||||
.contains("'low'");
|
||||
}
|
||||
|
||||
/** 切到时间排序时不能再套严重度 CASE,否则「按时间」只是同一档内的局部排序。 */
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void pageTimeSortDoesNotUseSeverityCase() {
|
||||
when(mapper.selectCount(any())).thenReturn(1L, 0L);
|
||||
when(mapper.selectList(any())).thenReturn(List.of());
|
||||
NotificationPageQuery query = NotificationPageQuery.of(1L, 20L, false, null, null, null, null);
|
||||
query.setSort(NotificationService.SORT_TIME);
|
||||
|
||||
service.page(7L, NotificationService.AUDIENCE_USER, query);
|
||||
|
||||
ArgumentCaptor<LambdaQueryWrapper<UserNotificationEntity>> captor =
|
||||
ArgumentCaptor.forClass(LambdaQueryWrapper.class);
|
||||
verify(mapper).selectList(captor.capture());
|
||||
assertThat(captor.getValue().getSqlSegment())
|
||||
.doesNotContain("CASE severity")
|
||||
.contains("ORDER BY")
|
||||
.contains("id DESC");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void summaryAndUnreadCountScopeByReceiverAndAudience() {
|
||||
|
||||
Reference in New Issue
Block a user