@@ -0,0 +1,22 @@
|
||||
package com.yunhai.userhome.service;
|
||||
|
||||
import com.yunhai.userhome.entity.AppCategory;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface IAppCategoryService {
|
||||
|
||||
void save(AppCategory appCategory);
|
||||
|
||||
void deleteById(Integer id);
|
||||
|
||||
Optional<AppCategory> findById(Integer id);
|
||||
|
||||
List<AppCategory> findByRoleType(Integer roleType);
|
||||
|
||||
Page<AppCategory> findPageList(Integer page, Integer count, Integer roleType, String name);
|
||||
|
||||
void updateResDate(Integer id);
|
||||
}
|
||||
@@ -14,6 +14,12 @@ public interface IUserSettingsService {
|
||||
|
||||
List<Wallpaper> findWallList(Integer userId);
|
||||
|
||||
/** 管理视角壁纸列表(系统设置页):系统 + 目标学校,不含个人壁纸;isEdit 按调用者权限标记 */
|
||||
List<Wallpaper> findSchWallpaperManageList(BoaUser user, Integer targetSchId);
|
||||
|
||||
/** 管理视角 Logo 列表(系统设置页):系统 + 目标学校 */
|
||||
List<Logo> findSchLogoManageList(BoaUser user, Integer targetSchId);
|
||||
|
||||
void deleteWallById(Integer id, BoaUser user);
|
||||
|
||||
void saveWallpaper(Wallpaper wallpaper);
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.yunhai.userhome.service.impl;
|
||||
|
||||
import com.yunhai.platform.apistd.BizException;
|
||||
import com.yunhai.platform.utils.exception.ErrorCode;
|
||||
import com.yunhai.userhome.entity.AppCategory;
|
||||
import com.yunhai.userhome.repository.AppCategoryRepository;
|
||||
import com.yunhai.userhome.service.IAppCategoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 应用类别服务(自 systemsetting AppCategoryService 1:1 迁移,GetAppCategorySel/getTimestampByIds 无消费方不迁)。
|
||||
*/
|
||||
@Service
|
||||
public class AppCategoryServiceImpl implements IAppCategoryService {
|
||||
|
||||
@Autowired
|
||||
private AppCategoryRepository appCategoryRepository;
|
||||
|
||||
@Override
|
||||
public void save(AppCategory appCategory) {
|
||||
appCategoryRepository.save(appCategory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteById(Integer id) {
|
||||
if (!appCategoryRepository.existsById(id)) {
|
||||
throw new BizException(ErrorCode.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
appCategoryRepository.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<AppCategory> findById(Integer id) {
|
||||
return appCategoryRepository.findById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AppCategory> findByRoleType(Integer roleType) {
|
||||
return appCategoryRepository.findAllByRoleType(roleType);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
@Override
|
||||
public Page<AppCategory> findPageList(Integer page, Integer count, Integer roleType, String name) {
|
||||
Sort sort = Sort.by(Sort.Direction.DESC, "id");
|
||||
Pageable pageable = PageRequest.of(page - 1, count, sort);
|
||||
Specification specification = (Specification) (root, criteriaQuery, criteriaBuilder) -> {
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
if (roleType != null) {
|
||||
predicates.add(criteriaBuilder.equal(root.get("roleType"), roleType));
|
||||
}
|
||||
if (name != null && !name.trim().isEmpty()) {
|
||||
predicates.add(criteriaBuilder.like(root.get("name"), "%" + name + "%"));
|
||||
}
|
||||
return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
|
||||
};
|
||||
return appCategoryRepository.findAll(specification, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateResDate(Integer id) {
|
||||
Optional<AppCategory> optionalAppCategory = findById(id);
|
||||
if (!optionalAppCategory.isPresent()) {
|
||||
throw new BizException(ErrorCode.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
AppCategory model = optionalAppCategory.get();
|
||||
model.setResDate(new Date());
|
||||
appCategoryRepository.save(model);
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,16 @@
|
||||
package com.yunhai.userhome.service.impl;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.yunhai.userhome.entity.SchSettings;
|
||||
import com.yunhai.userhome.repository.SchSettingsRepository;
|
||||
import com.yunhai.userhome.service.ISchSettingsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 学校设置服务:行为对齐旧 UserHome SchSettingsService。
|
||||
* <p>关键:{@code findBySchId} 不查本地表,而是跨仓调用 {@code SCH_CONF_URL/oapi/getSchSetting},
|
||||
* 旧版如此(schConfig 服务为 homeImgUrl/isEnableDesktop/isLinkDesktop 等字段的权威来源),
|
||||
* 因此本地 sch_settings 表变更类能力(saveSchTheme/saveSchLogo)本期仅保留 P1 占位写入本地表。</p>
|
||||
* 学校设置服务:学校设置完全本地化(sch_settings 表),不再依赖跨仓 schConfig。
|
||||
* <p>findBySchId 直接查本地表,查不到兜底默认主题;saveSchTheme/saveSchLogo 写本地表即可闭环。</p>
|
||||
*/
|
||||
@Service
|
||||
public class SchSettingsServiceImpl implements ISchSettingsService {
|
||||
@@ -24,12 +18,6 @@ public class SchSettingsServiceImpl implements ISchSettingsService {
|
||||
@Autowired
|
||||
private SchSettingsRepository schSettingsRepository;
|
||||
|
||||
@Value("${SCH_CONF_URL:}")
|
||||
private String schConfUrl;
|
||||
|
||||
private final RestTemplate restTemplate = new RestTemplate();
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@Override
|
||||
public void save(SchSettings schSettings) {
|
||||
schSettingsRepository.save(schSettings);
|
||||
@@ -37,41 +25,16 @@ public class SchSettingsServiceImpl implements ISchSettingsService {
|
||||
|
||||
@Override
|
||||
public Optional<SchSettings> findBySchId(Integer schId) {
|
||||
SchSettings model = new SchSettings();
|
||||
try {
|
||||
if (schConfUrl == null || schConfUrl.isEmpty()) {
|
||||
return Optional.of(localFallbackBySchId(schId));
|
||||
}
|
||||
String apiPath = schConfUrl + "/oapi/getSchSetting?schId=" + schId;
|
||||
String resultStr = restTemplate.getForObject(apiPath, String.class);
|
||||
if (resultStr == null || resultStr.isEmpty()) {
|
||||
return Optional.of(localFallbackBySchId(schId));
|
||||
}
|
||||
JsonNode root = objectMapper.readTree(resultStr);
|
||||
JsonNode dataNode = root.get("data");
|
||||
if (root.has("code") && "0".equals(root.get("code").asText()) && dataNode != null && !dataNode.isNull()) {
|
||||
model = objectMapper.convertValue(dataNode, SchSettings.class);
|
||||
} else {
|
||||
return Optional.of(localFallbackBySchId(schId));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return Optional.of(localFallbackBySchId(schId));
|
||||
}
|
||||
return Optional.of(model);
|
||||
}
|
||||
|
||||
/** 跨仓不通时先查本地表,再兜底默认主题(对齐旧版异常分支)。 */
|
||||
private SchSettings localFallbackBySchId(Integer schId) {
|
||||
Optional<SchSettings> local = schSettingsRepository.findFirstBySchId(schId);
|
||||
if (local.isPresent()) {
|
||||
return local.get();
|
||||
return local;
|
||||
}
|
||||
SchSettings def = new SchSettings();
|
||||
def.setSchId(schId);
|
||||
def.setThemeName("default-theme");
|
||||
def.setAppBgUrl("");
|
||||
def.setLogoUrl("");
|
||||
return def;
|
||||
return Optional.of(def);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -73,6 +73,52 @@ public class UserSettingsServiceImpl implements IUserSettingsService {
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Wallpaper> findSchWallpaperManageList(BoaUser user, Integer targetSchId) {
|
||||
UserCurrentRole currentRole = userCurrentRoleService.findById(user.getId())
|
||||
.orElseThrow(() -> new BizException(ErrorCode.INTERNAL_SERVER_ERROR));
|
||||
boolean superAdmin = user.getType() == 1;
|
||||
if (!superAdmin && !OtherUtil.isAdminById(currentRole.getRoleId())) {
|
||||
throw new BizException(ErrorCode.FORBIDDEN);
|
||||
}
|
||||
Integer schId = superAdmin ? (targetSchId == null ? 0 : targetSchId) : currentRole.getSchId();
|
||||
List<Wallpaper> resultList = new ArrayList<>();
|
||||
List<Wallpaper> baseList = wallpaperRepository.findBySchIdAndType(0, 0);
|
||||
List<Wallpaper> schList = wallpaperRepository.findBySchIdAndType(schId, 1);
|
||||
if (superAdmin) {
|
||||
baseList.forEach(x -> x.setIsEdit(true));
|
||||
schList.forEach(x -> x.setIsEdit(true));
|
||||
} else {
|
||||
schList.forEach(x -> x.setIsEdit(true));
|
||||
}
|
||||
resultList.addAll(baseList);
|
||||
resultList.addAll(schList);
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Logo> findSchLogoManageList(BoaUser user, Integer targetSchId) {
|
||||
UserCurrentRole currentRole = userCurrentRoleService.findById(user.getId())
|
||||
.orElseThrow(() -> new BizException(ErrorCode.INTERNAL_SERVER_ERROR));
|
||||
boolean superAdmin = user.getType() == 1;
|
||||
if (!superAdmin && !OtherUtil.isAdminById(currentRole.getRoleId())) {
|
||||
throw new BizException(ErrorCode.FORBIDDEN);
|
||||
}
|
||||
Integer schId = superAdmin ? (targetSchId == null ? 0 : targetSchId) : currentRole.getSchId();
|
||||
List<Logo> resultList = new ArrayList<>();
|
||||
List<Logo> baseList = logoRepository.findBySchIdAndType(0, 0);
|
||||
List<Logo> schList = logoRepository.findBySchIdAndType(schId, 1);
|
||||
if (superAdmin) {
|
||||
baseList.forEach(x -> x.setIsEdit(true));
|
||||
schList.forEach(x -> x.setIsEdit(true));
|
||||
} else {
|
||||
schList.forEach(x -> x.setIsEdit(true));
|
||||
}
|
||||
resultList.addAll(baseList);
|
||||
resultList.addAll(schList);
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteWallById(Integer id, BoaUser user) {
|
||||
|
||||
Reference in New Issue
Block a user