diff --git a/src/main/java/com/yunhai/userhome/service/impl/AppearanceServiceImpl.java b/src/main/java/com/yunhai/userhome/service/impl/AppearanceServiceImpl.java index b29b632..1c7c968 100644 --- a/src/main/java/com/yunhai/userhome/service/impl/AppearanceServiceImpl.java +++ b/src/main/java/com/yunhai/userhome/service/impl/AppearanceServiceImpl.java @@ -125,7 +125,16 @@ public class AppearanceServiceImpl implements IAppearanceService { String avatar = myAvatar; try { if (theme == null) { - theme = schSettingsService.readThemeWithFallback(schId).getValue(); + // readThemeWithFallback 命中值是 ThemeState JSON(schTheme 端点口径);oapi 契约统一出 + // 紧凑编码(init 侧 compactThemeToJson 只认紧凑形态),脏值宽松降 null 不抛 + String hit = schSettingsService.readThemeWithFallback(schId).getValue(); + if (hit != null) { + try { + theme = ThemeCodec.encodeThemeState(hit); + } catch (DException e) { + theme = null; + } + } } if (avatar == null) { avatar = schSettingsService.readAvatarWithFallback(schId).getValue(); diff --git a/src/test/java/com/yunhai/userhome/service/AppearanceServiceTest.java b/src/test/java/com/yunhai/userhome/service/AppearanceServiceTest.java index f1f597d..8585563 100644 --- a/src/test/java/com/yunhai/userhome/service/AppearanceServiceTest.java +++ b/src/test/java/com/yunhai/userhome/service/AppearanceServiceTest.java @@ -254,18 +254,19 @@ class AppearanceServiceTest { } @Test - @DisplayName("生效值:个人未设 → 学校/平台级联(缺陷 C 修复验证:合成链走 readThemeWithFallback)") + @DisplayName("生效值:个人未设 → 学校/平台级联(缺陷 C 修复验证:合成链走 readThemeWithFallback),层间编码统一紧凑形态") void effective_fallsToCascade() { stubCurrentRole(3); when(userAppearanceRepository.findByUserId(10133)).thenReturn(Optional.empty()); + // 级联命中值是 ThemeState JSON(schTheme 端点口径)——合成层须转回紧凑编码 when(schSettingsService.readThemeWithFallback(3)) - .thenReturn(new ISchSettingsService.LayerValue("ink|0|1|1", 0)); + .thenReturn(new ISchSettingsService.LayerValue("{\"theme\":\"ink\",\"sideDeep\":false,\"gradOn\":true,\"sideFollow\":false}", 0)); when(schSettingsService.readAvatarWithFallback(3)) .thenReturn(new ISchSettingsService.LayerValue("text", 3)); when(logoRepository.findBySchIdAndType(any(), any())).thenReturn(Collections.emptyList()); Map out = service.getEffectiveAppearance(10133); - assertEquals("ink|0|1|1", out.get("theme"), "本校空回落平台档(hitSchId=0)"); + assertEquals("ink|0|1|0", out.get("theme"), "级联 JSON 转紧凑编码,init 侧才可收敛"); assertEquals("text", out.get("avatar"), "本校已配直接生效(hitSchId=本校)"); // 出参只三字段,不外露 my/sch 拆分 assertTrue(out.containsKey("theme") && out.containsKey("avatar") && out.containsKey("logoUrl"));