- 新实体 user_appearance(per-user 一行,theme_state/avatar_style 紧凑编码,NULL=跟随学校默认) - 新增 GET appearance 聚合出参 + saveMyTheme/saveMyAvatarStyle 双写端点(登录态 /api/** 链路) - 聚合读永不抛:个人段/学校段独立降级(identity 跨仓故障→学校段 null),脏值视同未配置 - Logo 择优复用 findLogoList 口径(本校 type=1 → 系统 type=0 → null),URL 拼法对齐 getLogoList - ThemeCodec 编解码下沉 + resolveThemeSchId/resolveSchId 下沉 SchSettingsService(行为等价重构,供共享) - 单测:ThemeCodecTest 5 例 + AppearanceServiceTest 9 例(聚合降级/upsert 置 NULL/择优/校验从严)
78 lines
2.5 KiB
Java
78 lines
2.5 KiB
Java
package com.yunhai.userhome.service.impl;
|
|
|
|
import com.yunhai.platform.utils.model.BoaUser;
|
|
import com.yunhai.userhome.entity.SchSettings;
|
|
import com.yunhai.userhome.entity.UserCurrentRole;
|
|
import com.yunhai.userhome.repository.SchSettingsRepository;
|
|
import com.yunhai.userhome.service.ISchSettingsService;
|
|
import com.yunhai.userhome.service.IUserCurrentRoleService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.util.Optional;
|
|
|
|
/**
|
|
* 学校设置服务:学校设置完全本地化(sch_settings 表),不再依赖跨仓 schConfig。
|
|
* <p>findBySchId 直接查本地表,查不到兜底默认主题;saveSchTheme/saveSchLogo 写本地表即可闭环。</p>
|
|
*/
|
|
@Service
|
|
public class SchSettingsServiceImpl implements ISchSettingsService {
|
|
|
|
@Autowired
|
|
private SchSettingsRepository schSettingsRepository;
|
|
|
|
@Autowired
|
|
private IUserCurrentRoleService userCurrentRoleService;
|
|
|
|
@Override
|
|
public void save(SchSettings schSettings) {
|
|
schSettingsRepository.save(schSettings);
|
|
}
|
|
|
|
@Override
|
|
public Optional<SchSettings> findBySchIdRaw(Integer schId) {
|
|
return schSettingsRepository.findFirstBySchId(schId);
|
|
}
|
|
|
|
@Override
|
|
public Optional<SchSettings> findBySchId(Integer schId) {
|
|
Optional<SchSettings> local = schSettingsRepository.findFirstBySchId(schId);
|
|
if (local.isPresent()) {
|
|
return local;
|
|
}
|
|
SchSettings def = new SchSettings();
|
|
def.setSchId(schId);
|
|
def.setThemeName("default-theme");
|
|
def.setAppBgUrl("");
|
|
def.setLogoUrl("");
|
|
return Optional.of(def);
|
|
}
|
|
|
|
@Override
|
|
public java.util.List<SchSettings> findBySchIds(java.util.List<Integer> schId) {
|
|
return schSettingsRepository.getSchSettingList(schId);
|
|
}
|
|
|
|
@Override
|
|
public Integer resolveSchId(BoaUser user) {
|
|
if (user.getSchool() != null) {
|
|
return user.getSchool().getId();
|
|
}
|
|
if (user.getBureau() != null) {
|
|
return user.getBureau().getId();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
@Override
|
|
public Integer resolveThemeSchId(BoaUser user, Integer explicitSchId) {
|
|
if (user.getType() != null && user.getType() == 1) {
|
|
return explicitSchId == null ? 0 : explicitSchId;
|
|
}
|
|
return userCurrentRoleService.findById(user.getId())
|
|
.map(UserCurrentRole::getSchId)
|
|
.filter(schId -> schId != null && schId > 0)
|
|
.orElseGet(() -> resolveSchId(user));
|
|
}
|
|
}
|