feat(appearance): /oapi/appearance 出参摘除 logoText(子应用 header 定稿只出 logo 图,门户文字走 /api/schLogoText 自有链;init 侧缺失字段自动清 yh-logo-text)——出参恰三字段 {theme,avatar,logoUrl},测试对齐
build / build-push (push) Successful in 2m14s

This commit is contained in:
chenxing
2026-10-09 17:08:00 +08:00
parent 977b5c90a4
commit 47f9e3f751
3 changed files with 15 additions and 20 deletions
@@ -16,7 +16,8 @@ import java.util.Map;
* 强制(/oapi/* 无签名 401);appKey 准入归网关台账/限流管,本应用不维护 per-app 白名单。
*
* <p>出参 = 当前用户【生效值】{@code {theme, avatar, logoUrl}}(个人 → 学校 → 平台级联合成,
* 层级知识留在 UserHome 内部不外露;null=未配置,消费端 init 侧清对应本地键回落默认观感)。
* 层级知识留在 UserHome 内部不外露;null=未配置,消费端 init 侧清对应本地键回落默认观感;
* logoText 已于 2026-10-09 定稿摘除——子应用不再消费 LOGO 文字,门户走 /api/schLogoText 自有链)。
* 返回裸 payload(平台 oapi 无信封包装),消费端整体透传给浏览器。</p>
*/
@RestController
@@ -89,9 +89,11 @@ public class AppearanceServiceImpl implements IAppearanceService {
}
/**
* 当前用户生效外观(oapi 代理轮 2026-10-08,{@code /oapi/appearance} 出参真源;2026-10-09 JSON 化+LOGO 文字):
* {@code {theme, avatar, logoText, logoUrl}}——theme 为【JSON 对象】(个人自选 → 学校默认 → 平台默认(schId=0)
* 级联,层级知识留在 UserHome 内部,对外不拆 my/sch);avatar 为生效样式;logoText 本校→平台级联;
* 当前用户生效外观(oapi 代理轮 2026-10-08,{@code /oapi/appearance} 出参真源;2026-10-09 JSON 化;
* 同日定稿摘除 logoText——子应用 header 定稿只出 logo 图,文字仅门户消费且走 /api/schLogoText 自有链,
* init 侧对缺失字段按 null 语义自动清 yh-logo-text 本地键):
* {@code {theme, avatar, logoUrl}}——theme 为【JSON 对象】(个人自选 → 学校默认 → 平台默认(schId=0)
* 级联,层级知识留在 UserHome 内部,对外不拆 my/sch);avatar 为生效样式;
* logoUrl 为本校 type=1 → 平台 type=0 择优。
*
* <p>schId 解析走本地 user_current_role(oapi 入参只有 userId,不引 identity 跨仓):roleId 当前角色学校,
@@ -103,7 +105,6 @@ public class AppearanceServiceImpl implements IAppearanceService {
Map<String, Object> out = new HashMap<>();
out.put("theme", null);
out.put("avatar", null);
out.put("logoText", null);
out.put("logoUrl", null);
if (userId == null) {
return out;
@@ -132,10 +133,9 @@ public class AppearanceServiceImpl implements IAppearanceService {
if (avatar == null) {
avatar = schSettingsService.readAvatarWithFallback(schId).getValue();
}
out.put("logoText", schSettingsService.readLogoTextWithFallback(schId).getValue());
out.put("logoUrl", resolveLogoUrl(schId));
} catch (Exception e) {
// 学校/平台段降级:theme/avatar/logoText/logoUrl 保持已得值或 null
// 学校/平台段降级:theme/avatar/logoUrl 保持已得值或 null
}
// theme 出 JSON 对象(2026-10-09 契约);值已过 decodeThemeState 校验,解析失败按 null 降级
out.put("theme", theme == null ? null : ThemeCodec.toJsonNode(theme));
@@ -257,14 +257,15 @@ class AppearanceServiceTest {
assertTrue(theme.get("sideDeep").asBoolean());
assertFalse(theme.get("gradOn").asBoolean());
assertEquals("silhouette", out.get("avatar"));
assertNull(out.get("logoText"));
assertFalse(out.containsKey("logoText"), "logoText 已定稿摘除(子应用不消费 LOGO 文字)");
assertNull(out.get("logoUrl"));
verify(schSettingsService, never()).readThemeWithFallback(any());
verify(schSettingsService, never()).readAvatarWithFallback(any());
verify(schSettingsService, never()).readLogoTextWithFallback(any());
}
@Test
@DisplayName("生效值:个人未设 → 学校/平台级联(theme 出 JSON 对象)+ logoText 本校→平台级联")
@DisplayName("生效值:个人未设 → 学校/平台级联(theme 出 JSON 对象),出参恰三字段")
void effective_fallsToCascade() {
stubCurrentRole(3);
when(userAppearanceRepository.findByUserId(10133)).thenReturn(Optional.empty());
@@ -272,8 +273,6 @@ class AppearanceServiceTest {
.thenReturn(new ISchSettingsService.LayerValue("{\"theme\":\"ink\",\"sideDeep\":false,\"gradOn\":true,\"sideFollow\":false}", 0));
when(schSettingsService.readAvatarWithFallback(3))
.thenReturn(new ISchSettingsService.LayerValue("text", 3));
when(schSettingsService.readLogoTextWithFallback(3))
.thenReturn(new ISchSettingsService.LayerValue("云海教育平台", 0));
when(logoRepository.findBySchIdAndType(any(), any())).thenReturn(Collections.emptyList());
Map<String, Object> out = service.getEffectiveAppearance(10133);
@@ -282,11 +281,9 @@ class AppearanceServiceTest {
assertFalse(theme.get("sideDeep").asBoolean());
assertTrue(theme.get("gradOn").asBoolean());
assertEquals("text", out.get("avatar"), "本校已配直接生效(hitSchId=本校)");
assertEquals("云海教育平台", out.get("logoText"), "logoText 本校空→平台层");
// 出参只四字段,不外露 my/sch 拆分
assertEquals(4, out.size());
assertTrue(out.containsKey("theme") && out.containsKey("avatar")
&& out.containsKey("logoText") && out.containsKey("logoUrl"));
// 出参只三字段(logoText 已摘),不外露 my/sch 拆分
assertEquals(3, out.size());
assertTrue(out.containsKey("theme") && out.containsKey("avatar") && out.containsKey("logoUrl"));
}
@Test
@@ -301,16 +298,13 @@ class AppearanceServiceTest {
.thenReturn(new ISchSettingsService.LayerValue(null, 0));
when(schSettingsService.readAvatarWithFallback(0))
.thenReturn(new ISchSettingsService.LayerValue(null, 0));
when(schSettingsService.readLogoTextWithFallback(0))
.thenReturn(new ISchSettingsService.LayerValue(null, 0));
when(logoRepository.findBySchIdAndType(any(), any())).thenReturn(Collections.emptyList());
Map<String, Object> out = service.getEffectiveAppearance(10133);
assertNull(out.get("theme"), "脏值落级联且两级皆无 → null");
assertNull(out.get("avatar"));
assertNull(out.get("logoText"));
assertNull(out.get("logoUrl"));
assertEquals(4, out.size());
assertEquals(3, out.size());
verify(schSettingsService).readThemeWithFallback(0);
verify(schSettingsService).readAvatarWithFallback(0);
}