feat(appearance): 主题档存储/传输全面 JSON 化(读侧兼容旧紧凑值)+ LOGO 文字 sch_settings.logo_text 级联读写(LOGO文字与主题JSON化)
build / build-push (push) Successful in 2m1s

This commit is contained in:
chenxing
2026-10-09 10:35:03 +08:00
parent 8b3f8afd77
commit f9282574e2
8 changed files with 228 additions and 96 deletions
@@ -65,7 +65,7 @@ public class AppearanceServiceImpl implements IAppearanceService {
try {
Optional<UserAppearance> ua = userAppearanceRepository.findByUserId(user.getId());
if (ua.isPresent()) {
out.put("myTheme", validCompactTheme(ua.get().getThemeState()));
out.put("myTheme", validThemeState(ua.get().getThemeState()));
out.put("avatarMy", validAvatarStyle(ua.get().getAvatarStyle()));
}
} catch (Exception e) {
@@ -77,7 +77,7 @@ public class AppearanceServiceImpl implements IAppearanceService {
if (schId != null) {
SchSettings sch = schSettingsService.findBySchIdRaw(schId).orElse(null);
if (sch != null) {
out.put("schTheme", validCompactTheme(sch.getThemeName()));
out.put("schTheme", validThemeState(sch.getThemeName()));
out.put("avatarSch", validAvatarStyle(sch.getAvatarStyle()));
}
out.put("logoUrl", resolveLogoUrl(schId));
@@ -89,9 +89,10 @@ public class AppearanceServiceImpl implements IAppearanceService {
}
/**
* 当前用户生效外观(oapi 代理轮 2026-10-08,{@code /oapi/appearance} 出参真源):
* {@code {theme, avatar, logoUrl}}——主题/头像为【合成后的生效值】(个人自选 → 学校默认 → 平台默认(schId=0)
* 级联,层级知识留在 UserHome 内部,对外不拆 my/sch);logoUrl 为本校 type=1 → 平台 type=0 择优。
* 当前用户生效外观(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 本校→平台级联;
* logoUrl 为本校 type=1 → 平台 type=0 择优。
*
* <p>schId 解析走本地 user_current_role(oapi 入参只有 userId,不引 identity 跨仓):roleId 当前角色学校,
* 无角色/跨校态回落 0(平台层)。与 /api/appearance 的 resolveThemeSchId(超管强制 0)仅在「超管临时切入
@@ -102,6 +103,7 @@ 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;
@@ -115,7 +117,7 @@ public class AppearanceServiceImpl implements IAppearanceService {
try {
Optional<UserAppearance> ua = userAppearanceRepository.findByUserId(userId);
if (ua.isPresent()) {
myTheme = validCompactTheme(ua.get().getThemeState());
myTheme = validThemeState(ua.get().getThemeState());
myAvatar = validAvatarStyle(ua.get().getAvatarStyle());
}
} catch (Exception e) {
@@ -125,25 +127,18 @@ public class AppearanceServiceImpl implements IAppearanceService {
String avatar = myAvatar;
try {
if (theme == null) {
// 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;
}
}
theme = schSettingsService.readThemeWithFallback(schId).getValue();
}
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/logoUrl 保持已得值或 null
// 学校/平台段降级:theme/avatar/logoText/logoUrl 保持已得值或 null
}
out.put("theme", theme);
// theme 出 JSON 对象(2026-10-09 契约);值已过 decodeThemeState 校验,解析失败按 null 降级
out.put("theme", theme == null ? null : ThemeCodec.toJsonNode(theme));
out.put("avatar", avatar);
return out;
}
@@ -155,11 +150,8 @@ public class AppearanceServiceImpl implements IAppearanceService {
// 跟随学校默认:置 NULL(列语义见实体注释)
ua.setThemeState(null);
} else {
String compact = themeState.trim();
if (ThemeCodec.decodeThemeState(compact) == null) {
throw new DException("主题档不合法: " + themeState);
}
ua.setThemeState(compact);
// 写侧从严:只收 JSON、产规范化 JSON 串(紧凑入参抛 DException,2026-10-09 JSON 化契约)
ua.setThemeState(ThemeCodec.encodeThemeState(themeState));
}
ua.setUDate(new Date());
userAppearanceRepository.save(ua);
@@ -190,11 +182,9 @@ public class AppearanceServiceImpl implements IAppearanceService {
});
}
/** 紧凑编码校验读(非法/脏值/旧格式 → null 视同未配置;合法返回原紧凑串) */
private String validCompactTheme(String raw) {
if (!StringUtils.hasText(raw)) return null;
String compact = raw.trim();
return ThemeCodec.decodeThemeState(compact) == null ? null : compact;
/** 主题档校验读(JSON 校验→规范化;旧紧凑四段兼容转 JSON;脏值 → null 视同未配置) */
private String validThemeState(String raw) {
return StringUtils.hasText(raw) ? ThemeCodec.decodeThemeState(raw) : null;
}
private String validAvatarStyle(String raw) {