@@ -0,0 +1,20 @@
|
||||
package com.yunhai.userhome.service;
|
||||
|
||||
import com.yunhai.userhome.entity.MenuBar;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IMenuBarService {
|
||||
|
||||
List<MenuBar> getMenuBarList(Integer schId);
|
||||
|
||||
List<MenuBar> findMenuBarById(Integer userId);
|
||||
|
||||
void saveMenuBar(MenuBar menuBar);
|
||||
|
||||
void toggleMenuBarShow(Integer id, Integer schId);
|
||||
|
||||
void saveMenuBarOrderNum(Integer id, Integer orderNum);
|
||||
|
||||
void deleteMenuBar(Integer id);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.yunhai.userhome.service;
|
||||
|
||||
import com.yunhai.userhome.entity.SchSettings;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface ISchSettingsService {
|
||||
|
||||
void save(SchSettings schSettings);
|
||||
|
||||
Optional<SchSettings> findBySchId(Integer schId);
|
||||
|
||||
List<SchSettings> findBySchIds(List<Integer> schIds);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.yunhai.userhome.service;
|
||||
|
||||
import com.yunhai.userhome.entity.StatsBar;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IStatsBarService {
|
||||
|
||||
List<StatsBar> getStatsBarList(Integer schId);
|
||||
|
||||
List<StatsBar> findStatsBarById(Integer userId);
|
||||
|
||||
void saveStatsBar(StatsBar statsBar);
|
||||
|
||||
void toggleStatsBarShow(Integer id, Integer schId);
|
||||
|
||||
void saveStatsBarOrderNum(Integer id, Integer orderNum);
|
||||
|
||||
void deleteStatsBar(Integer id);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.yunhai.userhome.service;
|
||||
|
||||
import com.yunhai.userhome.entity.TeacherCopilot;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ITeacherCopilotService {
|
||||
|
||||
List<TeacherCopilot> getList(Integer schId);
|
||||
|
||||
List<TeacherCopilot> findById(Integer userId);
|
||||
|
||||
void save(TeacherCopilot teacherCopilot);
|
||||
|
||||
void toggleShow(Integer id, Integer schId);
|
||||
|
||||
void saveOrderNum(Integer id, Integer orderNum);
|
||||
|
||||
void delete(Integer id);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.yunhai.userhome.service;
|
||||
|
||||
import com.yunhai.userhome.entity.UserMessage;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IUserMessageService {
|
||||
|
||||
List<UserMessage> getUserMessageAppIds(Integer userId, Integer schId);
|
||||
|
||||
Page<UserMessage> findUserMessageByAppId(UserMessage userMessage, Pageable pageable);
|
||||
|
||||
Page<UserMessage> findUserMessageByUserId(Integer userId, Pageable pageable);
|
||||
|
||||
List<UserMessage> findUserMessageByUserId(Integer userId);
|
||||
|
||||
Boolean findUserMessageUnRead(Integer userId);
|
||||
|
||||
void updateRead(Integer userId, Integer appId);
|
||||
|
||||
void updateUserRead(Integer id, Integer userId);
|
||||
|
||||
void updateReadAll(Integer userId);
|
||||
|
||||
Page<UserMessage> findUserMessageById(Integer userId, Integer page, Integer count);
|
||||
|
||||
void readMsgById(Integer msgId);
|
||||
|
||||
void readMsgAll(Integer userId);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.yunhai.userhome.service;
|
||||
|
||||
import com.yunhai.userhome.entity.LightApp;
|
||||
import com.yunhai.userhome.entity.UserSettings;
|
||||
import com.yunhai.userhome.entity.UserSettingsDesktopApp;
|
||||
import com.yunhai.userhome.entity.Wallpaper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface IUserSettingsService {
|
||||
|
||||
List<Wallpaper> findWallList(Integer userId);
|
||||
|
||||
void deleteWallById(Integer id);
|
||||
|
||||
void saveWallpaper(Wallpaper wallpaper);
|
||||
|
||||
void checkWallpaper(Integer userId, String wallpaperUrl);
|
||||
|
||||
Optional<UserSettings> findUserSettings(Integer userId);
|
||||
|
||||
void saveUserSettings(UserSettings userSettings);
|
||||
|
||||
void saveUserWidget(UserSettings userSettings);
|
||||
|
||||
void saveUserAppIds(Integer id, Integer userId, String appIds);
|
||||
|
||||
void toggleWidgetShow(Integer id, Integer userId);
|
||||
|
||||
List<LightApp> findLightAppList(Integer schId, Integer userId);
|
||||
|
||||
void saveLightApp(LightApp lightApp);
|
||||
|
||||
void deleteLightAppById(Integer id);
|
||||
|
||||
void deleteDesktopAppById(Integer id);
|
||||
|
||||
void saveDesktopApp(UserSettingsDesktopApp model);
|
||||
|
||||
List<UserSettingsDesktopApp> saveDesktopAppList(List<UserSettingsDesktopApp> list);
|
||||
|
||||
UserSettings initUserSettings(Integer userId);
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.yunhai.userhome.service.impl;
|
||||
|
||||
import com.yunhai.platform.apistd.BizException;
|
||||
import com.yunhai.platform.utils.exception.ErrorCode;
|
||||
import com.yunhai.userhome.entity.MenuBar;
|
||||
import com.yunhai.userhome.entity.UserCurrentRole;
|
||||
import com.yunhai.userhome.repository.MenuBarRepository;
|
||||
import com.yunhai.userhome.service.IMenuBarService;
|
||||
import com.yunhai.userhome.service.IUserCurrentRoleService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 菜单栏服务(对齐旧 UserHome service.impl.MenuBarService)。
|
||||
*/
|
||||
@Service
|
||||
public class MenuBarServiceImpl implements IMenuBarService {
|
||||
|
||||
@Autowired
|
||||
private IUserCurrentRoleService userCurrentRoleService;
|
||||
|
||||
@Autowired
|
||||
private MenuBarRepository menuBarRepository;
|
||||
|
||||
@Override
|
||||
public List<MenuBar> getMenuBarList(Integer schId) {
|
||||
List<MenuBar> list;
|
||||
if (schId == 0)
|
||||
list = menuBarRepository.findBySchId(0);
|
||||
else
|
||||
list = menuBarRepository.findBySchIdIn(Arrays.asList(0, schId));
|
||||
list.forEach(x -> {
|
||||
Boolean isHide = x.getHideSchIds().contains(schId);
|
||||
x.setIsShow(!isHide);
|
||||
x.setIsEdit(x.getSchId().equals(schId));
|
||||
});
|
||||
list = list.stream().sorted(Comparator.comparing(MenuBar::getOrderNum, Comparator.nullsLast(Integer::compareTo))).collect(Collectors.toList());
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuBar> findMenuBarById(Integer userId) {
|
||||
UserCurrentRole userCurrentRole = userCurrentRoleService.findById(userId)
|
||||
.orElseThrow(() -> new BizException(ErrorCode.INTERNAL_SERVER_ERROR));
|
||||
List<MenuBar> list = getMenuBarList(userCurrentRole.getSchId());
|
||||
List<MenuBar> result = list.stream().filter(MenuBar::getIsShow).collect(Collectors.toList());
|
||||
result = result.stream().sorted(Comparator.comparing(MenuBar::getOrderNum, Comparator.nullsLast(Integer::compareTo))).collect(Collectors.toList());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveMenuBar(MenuBar menuBar) {
|
||||
if (menuBar.getId() != null) {
|
||||
Optional<MenuBar> optional = menuBarRepository.findById(menuBar.getId());
|
||||
if (optional.isPresent()) {
|
||||
menuBar.setHideSchIds(optional.get().getHideSchIds());
|
||||
}
|
||||
}
|
||||
menuBarRepository.save(menuBar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveMenuBarOrderNum(Integer id, Integer orderNum) {
|
||||
Optional<MenuBar> optionalMenuBar = menuBarRepository.findById(id);
|
||||
if (!optionalMenuBar.isPresent())
|
||||
throw new BizException(ErrorCode.INTERNAL_SERVER_ERROR);
|
||||
MenuBar menuBar = optionalMenuBar.get();
|
||||
menuBar.setOrderNum(orderNum);
|
||||
menuBarRepository.save(menuBar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toggleMenuBarShow(Integer id, Integer schId) {
|
||||
Optional<MenuBar> optionalMenuBar = menuBarRepository.findById(id);
|
||||
if (!optionalMenuBar.isPresent())
|
||||
throw new BizException(ErrorCode.INTERNAL_SERVER_ERROR);
|
||||
MenuBar menuBar = optionalMenuBar.get();
|
||||
Integer index = menuBar.getHideSchIds().indexOf(schId);
|
||||
List<Integer> schIds = menuBar.getHideSchIds();
|
||||
if (index.equals(-1))
|
||||
schIds.add(schId);
|
||||
else
|
||||
schIds.remove(Integer.valueOf(schId));
|
||||
menuBar.setHideSchIds(schIds);
|
||||
menuBarRepository.save(menuBar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteMenuBar(Integer id) {
|
||||
Optional<MenuBar> optionalMenuBar = menuBarRepository.findById(id);
|
||||
if (!optionalMenuBar.isPresent())
|
||||
throw new BizException(ErrorCode.INTERNAL_SERVER_ERROR);
|
||||
menuBarRepository.delete(optionalMenuBar.get());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
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>
|
||||
*/
|
||||
@Service
|
||||
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);
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
SchSettings def = new SchSettings();
|
||||
def.setSchId(schId);
|
||||
def.setThemeName("default-theme");
|
||||
def.setAppBgUrl("");
|
||||
def.setLogoUrl("");
|
||||
return def;
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.util.List<SchSettings> findBySchIds(java.util.List<Integer> schId) {
|
||||
return schSettingsRepository.getSchSettingList(schId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.yunhai.userhome.service.impl;
|
||||
|
||||
import com.yunhai.platform.apistd.BizException;
|
||||
import com.yunhai.platform.utils.exception.ErrorCode;
|
||||
import com.yunhai.userhome.entity.StatsBar;
|
||||
import com.yunhai.userhome.entity.UserCurrentRole;
|
||||
import com.yunhai.userhome.repository.StatsBarRepository;
|
||||
import com.yunhai.userhome.service.IStatsBarService;
|
||||
import com.yunhai.userhome.service.IUserCurrentRoleService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 统计栏目服务(对齐旧 UserHome service.impl.StatsBarService)。
|
||||
*/
|
||||
@Service
|
||||
public class StatsBarServiceImpl implements IStatsBarService {
|
||||
|
||||
@Autowired
|
||||
private IUserCurrentRoleService userCurrentRoleService;
|
||||
|
||||
@Autowired
|
||||
private StatsBarRepository statsBarRepository;
|
||||
|
||||
@Override
|
||||
public List<StatsBar> getStatsBarList(Integer schId) {
|
||||
List<StatsBar> list;
|
||||
if (schId == 0)
|
||||
list = statsBarRepository.findBySchId(0);
|
||||
else
|
||||
list = statsBarRepository.findBySchIdIn(Arrays.asList(0, schId));
|
||||
list.forEach(x -> {
|
||||
x.setIsShow(x.getShowSchIds().contains(schId));
|
||||
x.setIsEdit(x.getSchId().equals(schId));
|
||||
});
|
||||
list = list.stream().sorted(Comparator.comparing(StatsBar::getOrderNum, Comparator.nullsLast(Integer::compareTo))).collect(Collectors.toList());
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<StatsBar> findStatsBarById(Integer userId) {
|
||||
UserCurrentRole userCurrentRole = userCurrentRoleService.findById(userId)
|
||||
.orElseThrow(() -> new BizException(ErrorCode.INTERNAL_SERVER_ERROR));
|
||||
List<StatsBar> list = getStatsBarList(userCurrentRole.getSchId());
|
||||
List<StatsBar> result = list.stream().filter(StatsBar::getIsShow).collect(Collectors.toList());
|
||||
result = result.stream().sorted(Comparator.comparing(StatsBar::getOrderNum, Comparator.nullsLast(Integer::compareTo))).collect(Collectors.toList());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveStatsBar(StatsBar statsBar) {
|
||||
if (statsBar.getId() != null) {
|
||||
Optional<StatsBar> optional = statsBarRepository.findById(statsBar.getId());
|
||||
if (optional.isPresent()) {
|
||||
statsBar.setShowSchIds(optional.get().getShowSchIds());
|
||||
}
|
||||
}
|
||||
statsBarRepository.save(statsBar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveStatsBarOrderNum(Integer id, Integer orderNum) {
|
||||
Optional<StatsBar> optionalStatsBar = statsBarRepository.findById(id);
|
||||
if (!optionalStatsBar.isPresent())
|
||||
throw new BizException(ErrorCode.INTERNAL_SERVER_ERROR);
|
||||
StatsBar statsBar = optionalStatsBar.get();
|
||||
statsBar.setOrderNum(orderNum);
|
||||
statsBarRepository.save(statsBar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toggleStatsBarShow(Integer id, Integer schId) {
|
||||
Optional<StatsBar> optionalStatsBar = statsBarRepository.findById(id);
|
||||
if (!optionalStatsBar.isPresent())
|
||||
throw new BizException(ErrorCode.INTERNAL_SERVER_ERROR);
|
||||
StatsBar statsBar = optionalStatsBar.get();
|
||||
Integer index = statsBar.getShowSchIds().indexOf(schId);
|
||||
List<Integer> schIds = statsBar.getShowSchIds();
|
||||
if (index.equals(-1))
|
||||
schIds.add(schId);
|
||||
else
|
||||
schIds.remove(Integer.valueOf(schId));
|
||||
statsBar.setShowSchIds(schIds);
|
||||
statsBarRepository.save(statsBar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteStatsBar(Integer id) {
|
||||
Optional<StatsBar> optionalStatsBar = statsBarRepository.findById(id);
|
||||
if (!optionalStatsBar.isPresent())
|
||||
throw new BizException(ErrorCode.INTERNAL_SERVER_ERROR);
|
||||
statsBarRepository.delete(optionalStatsBar.get());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.yunhai.userhome.service.impl;
|
||||
|
||||
import com.yunhai.platform.apistd.BizException;
|
||||
import com.yunhai.platform.utils.exception.ErrorCode;
|
||||
import com.yunhai.userhome.entity.TeacherCopilot;
|
||||
import com.yunhai.userhome.entity.UserCurrentRole;
|
||||
import com.yunhai.userhome.repository.TeacherCopilotRepository;
|
||||
import com.yunhai.userhome.service.ITeacherCopilotService;
|
||||
import com.yunhai.userhome.service.IUserCurrentRoleService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 教师助手服务(对齐旧 UserHome service.impl.TeacherCopilotService)。
|
||||
*/
|
||||
@Service
|
||||
public class TeacherCopilotServiceImpl implements ITeacherCopilotService {
|
||||
|
||||
@Autowired
|
||||
private IUserCurrentRoleService userCurrentRoleService;
|
||||
|
||||
@Autowired
|
||||
private TeacherCopilotRepository teacherCopilotRepository;
|
||||
|
||||
@Override
|
||||
public List<TeacherCopilot> getList(Integer schId) {
|
||||
List<TeacherCopilot> list;
|
||||
if (schId == 0)
|
||||
list = teacherCopilotRepository.findBySchId(0);
|
||||
else
|
||||
list = teacherCopilotRepository.findBySchIdIn(Arrays.asList(0, schId));
|
||||
list.forEach(x -> {
|
||||
x.setIsShow(x.getShowSchIds().contains(schId));
|
||||
x.setIsEdit(x.getSchId().equals(schId));
|
||||
});
|
||||
list = list.stream().sorted(Comparator.comparing(TeacherCopilot::getOrderNum, Comparator.nullsLast(Integer::compareTo))).collect(Collectors.toList());
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TeacherCopilot> findById(Integer userId) {
|
||||
UserCurrentRole userCurrentRole = userCurrentRoleService.findById(userId)
|
||||
.orElseThrow(() -> new BizException(ErrorCode.INTERNAL_SERVER_ERROR));
|
||||
List<TeacherCopilot> list = getList(userCurrentRole.getSchId());
|
||||
List<TeacherCopilot> result = list.stream().filter(TeacherCopilot::getIsShow).collect(Collectors.toList());
|
||||
result = result.stream().sorted(Comparator.comparing(TeacherCopilot::getOrderNum, Comparator.nullsLast(Integer::compareTo))).collect(Collectors.toList());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(TeacherCopilot teacherCopilot) {
|
||||
if (teacherCopilot.getId() != null) {
|
||||
Optional<TeacherCopilot> optional = teacherCopilotRepository.findById(teacherCopilot.getId());
|
||||
if (optional.isPresent()) {
|
||||
teacherCopilot.setShowSchIds(optional.get().getShowSchIds());
|
||||
}
|
||||
}
|
||||
teacherCopilotRepository.save(teacherCopilot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveOrderNum(Integer id, Integer orderNum) {
|
||||
Optional<TeacherCopilot> optional = teacherCopilotRepository.findById(id);
|
||||
if (!optional.isPresent())
|
||||
throw new BizException(ErrorCode.INTERNAL_SERVER_ERROR);
|
||||
TeacherCopilot teacherCopilot = optional.get();
|
||||
teacherCopilot.setOrderNum(orderNum);
|
||||
teacherCopilotRepository.save(teacherCopilot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toggleShow(Integer id, Integer schId) {
|
||||
Optional<TeacherCopilot> optional = teacherCopilotRepository.findById(id);
|
||||
if (!optional.isPresent())
|
||||
throw new BizException(ErrorCode.INTERNAL_SERVER_ERROR);
|
||||
TeacherCopilot teacherCopilot = optional.get();
|
||||
Integer index = teacherCopilot.getShowSchIds().indexOf(schId);
|
||||
List<Integer> schIds = teacherCopilot.getShowSchIds();
|
||||
if (index.equals(-1))
|
||||
schIds.add(schId);
|
||||
else
|
||||
schIds.remove(Integer.valueOf(schId));
|
||||
teacherCopilot.setShowSchIds(schIds);
|
||||
teacherCopilotRepository.save(teacherCopilot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Integer id) {
|
||||
Optional<TeacherCopilot> optional = teacherCopilotRepository.findById(id);
|
||||
if (!optional.isPresent())
|
||||
throw new BizException(ErrorCode.INTERNAL_SERVER_ERROR);
|
||||
teacherCopilotRepository.delete(optional.get());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package com.yunhai.userhome.service.impl;
|
||||
|
||||
import com.yunhai.userhome.entity.UserMessage;
|
||||
import com.yunhai.userhome.repository.UserMessageRepository;
|
||||
import com.yunhai.userhome.service.IUserMessageService;
|
||||
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.CriteriaBuilder;
|
||||
import javax.persistence.criteria.CriteriaQuery;
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import javax.persistence.criteria.Root;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 用户消息服务:行为对齐旧 UserHome UserMessageService(本地 user_message 表)。
|
||||
* WS 推送态由前端轮询兜底,本服务不消费 Redis 缓存(旧工程依赖 Redis,新工程未引入)。
|
||||
*/
|
||||
@Service
|
||||
public class UserMessageServiceImpl implements IUserMessageService {
|
||||
|
||||
@Autowired
|
||||
private UserMessageRepository userMessageRepository;
|
||||
|
||||
@Override
|
||||
public List<UserMessage> getUserMessageAppIds(Integer userId, Integer schId) {
|
||||
return userMessageRepository.getUserMessageAppList(userId, schId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<UserMessage> findUserMessageByAppId(UserMessage userMessage, Pageable pageable) {
|
||||
return userMessageRepository.findAll(select(userMessage), pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<UserMessage> findUserMessageByUserId(Integer userId, Pageable pageable) {
|
||||
return userMessageRepository.findAll(select(userId, null), pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserMessage> findUserMessageByUserId(Integer userId) {
|
||||
// 旧版优先读 Redis 缓存,缓存缺失再查库;新工程无 Redis,直接查库(行为等价:返回该用户全部消息)
|
||||
return userMessageRepository.findAll(select(userId, null), PageRequest.of(0, Integer.MAX_VALUE, Sort.by(Sort.Direction.DESC, "cDate"))).getContent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean findUserMessageUnRead(Integer userId) {
|
||||
return userMessageRepository.count(select(userId, false)) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateRead(Integer userId, Integer appId) {
|
||||
userMessageRepository.updateRead(userId, appId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUserRead(Integer id, Integer userId) {
|
||||
// 单条已读:前端按 id 移除本地列表后再调;服务端标记该条已读
|
||||
userMessageRepository.updateReadById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateReadAll(Integer userId) {
|
||||
userMessageRepository.updateReadAll(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<UserMessage> findUserMessageById(Integer userId, Integer page, Integer count) {
|
||||
Sort sort = Sort.by(Sort.Direction.DESC, "id");
|
||||
Pageable pageable = PageRequest.of(page - 1, count, sort);
|
||||
return userMessageRepository.findAll(select(userId, null), pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMsgById(Integer msgId) {
|
||||
userMessageRepository.updateReadById(msgId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMsgAll(Integer userId) {
|
||||
userMessageRepository.updateReadAll(userId);
|
||||
}
|
||||
|
||||
private Specification<UserMessage> select(UserMessage userMessage) {
|
||||
return (Root<UserMessage> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
if (userMessage != null) {
|
||||
if (userMessage.getUserId() != null) {
|
||||
predicates.add(cb.equal(root.get("userId"), userMessage.getUserId()));
|
||||
}
|
||||
if (userMessage.getAppId() != null) {
|
||||
predicates.add(cb.equal(root.get("appId"), userMessage.getAppId()));
|
||||
}
|
||||
}
|
||||
return query.where(predicates.toArray(new Predicate[0])).getRestriction();
|
||||
};
|
||||
}
|
||||
|
||||
private Specification<UserMessage> select(Integer userId, Boolean isRead) {
|
||||
return (Root<UserMessage> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
if (userId != null) {
|
||||
predicates.add(cb.equal(root.get("userId"), userId));
|
||||
}
|
||||
if (isRead != null) {
|
||||
predicates.add(cb.equal(root.get("isRead"), isRead));
|
||||
}
|
||||
return query.where(predicates.toArray(new Predicate[0])).getRestriction();
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
package com.yunhai.userhome.service.impl;
|
||||
|
||||
import com.yunhai.platform.apistd.BizException;
|
||||
import com.yunhai.platform.utils.exception.ErrorCode;
|
||||
import com.yunhai.userhome.entity.*;
|
||||
import com.yunhai.userhome.repository.LightAppRepository;
|
||||
import com.yunhai.userhome.repository.UserSettingsDesktopAppRepository;
|
||||
import com.yunhai.userhome.repository.UserSettingsRepository;
|
||||
import com.yunhai.userhome.repository.WallpaperRepository;
|
||||
import com.yunhai.userhome.service.IUserCurrentRoleService;
|
||||
import com.yunhai.userhome.service.IUserSettingsService;
|
||||
import com.yunhai.userhome.utils.OtherUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 用户设置服务(对齐旧 UserHome service.impl.UserSettingsService)。
|
||||
*/
|
||||
@Service
|
||||
public class UserSettingsServiceImpl implements IUserSettingsService {
|
||||
|
||||
@Autowired
|
||||
private WallpaperRepository wallpaperRepository;
|
||||
|
||||
@Autowired
|
||||
private UserSettingsRepository userSettingsRepository;
|
||||
|
||||
@Autowired
|
||||
private IUserCurrentRoleService userCurrentRoleService;
|
||||
|
||||
@Autowired
|
||||
private LightAppRepository lightAppRepository;
|
||||
|
||||
@Autowired
|
||||
private UserSettingsDesktopAppRepository userSettingsDesktopAppRepository;
|
||||
|
||||
@Override
|
||||
public List<Wallpaper> findWallList(Integer userId) {
|
||||
UserCurrentRole currentRole = userCurrentRoleService.findById(userId)
|
||||
.orElseThrow(() -> new BizException(ErrorCode.INTERNAL_SERVER_ERROR));
|
||||
List<Wallpaper> resultList = new ArrayList<>();
|
||||
List<Wallpaper> baseList = wallpaperRepository.findBySchIdAndType(0, 0);
|
||||
List<Wallpaper> schList = wallpaperRepository.findBySchIdAndType(currentRole.getSchId(), 1);
|
||||
List<Wallpaper> userList = wallpaperRepository.findByUserIdAndType(userId, 2);
|
||||
if (currentRole.getSchId() == 0) baseList.forEach(x -> x.setIsEdit(true));
|
||||
if (OtherUtil.isAdminById(currentRole.getRoleId())) schList.forEach(x -> x.setIsEdit(true));
|
||||
userList.forEach(x -> x.setIsEdit(true));
|
||||
resultList.addAll(baseList);
|
||||
resultList.addAll(schList);
|
||||
resultList.addAll(userList);
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteWallById(Integer id) {
|
||||
if (!wallpaperRepository.existsById(id))
|
||||
throw new BizException(ErrorCode.INTERNAL_SERVER_ERROR);
|
||||
wallpaperRepository.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveWallpaper(Wallpaper wallpaper) {
|
||||
wallpaperRepository.save(wallpaper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkWallpaper(Integer userId, String wallpaperUrl) {
|
||||
UserSettings model = getUserSettings(null, userId);
|
||||
model.setWallpaperUrl(wallpaperUrl);
|
||||
userSettingsRepository.save(model);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<UserSettings> findUserSettings(Integer userId) {
|
||||
UserCurrentRole currentRole = userCurrentRoleService.findById(userId)
|
||||
.orElseThrow(() -> new BizException(ErrorCode.INTERNAL_SERVER_ERROR));
|
||||
return userSettingsRepository.findByUserIdAndSchIdAndRoleId(currentRole.getUserId(), currentRole.getSchId(), currentRole.getRoleId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveUserSettings(UserSettings userSettings) {
|
||||
userSettingsRepository.save(userSettings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveUserWidget(UserSettings userSettings) {
|
||||
UserSettings model = getUserSettings(userSettings.getId(), userSettings.getUserId());
|
||||
model.setXAxis(userSettings.getXAxis());
|
||||
model.setYAxis(userSettings.getYAxis());
|
||||
model.setWidth(userSettings.getWidth());
|
||||
model.setHeight(userSettings.getHeight());
|
||||
model.setIsWidgetShow(true);
|
||||
userSettingsRepository.save(model);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveUserAppIds(Integer id, Integer userId, String appIds) {
|
||||
UserSettings model = getUserSettings(id, userId);
|
||||
model.setWidgetAppIds(appIds);
|
||||
userSettingsRepository.save(model);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toggleWidgetShow(Integer id, Integer userId) {
|
||||
UserSettings model = getUserSettings(id, userId);
|
||||
if (model.getIsWidgetShow() == null) model.setIsWidgetShow(true);
|
||||
model.setIsWidgetShow(!model.getIsWidgetShow());
|
||||
userSettingsRepository.save(model);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
@Override
|
||||
public List<LightApp> findLightAppList(Integer schId, Integer userId) {
|
||||
Specification specification = (Specification) (root, criteriaQuery, criteriaBuilder) -> {
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
Predicate basePre = criteriaBuilder.and(
|
||||
criteriaBuilder.equal(root.get("schId"), 0),
|
||||
criteriaBuilder.equal(root.get("isPublic"), true));
|
||||
Predicate schPre = criteriaBuilder.and(
|
||||
criteriaBuilder.equal(root.get("schId"), schId),
|
||||
criteriaBuilder.equal(root.get("isPublic"), true));
|
||||
Predicate userPre = criteriaBuilder.and(
|
||||
criteriaBuilder.equal(root.get("schId"), schId),
|
||||
criteriaBuilder.equal(root.get("userId"), userId));
|
||||
if (schId == 0)
|
||||
predicates.add(basePre);
|
||||
else if (userId == null)
|
||||
predicates.add(criteriaBuilder.or(basePre, schPre));
|
||||
else
|
||||
predicates.add(criteriaBuilder.or(basePre, schPre, userPre));
|
||||
return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
|
||||
};
|
||||
Sort sort = Sort.by(Sort.Direction.DESC, "id");
|
||||
List<LightApp> result = lightAppRepository.findAll(specification, sort);
|
||||
|
||||
if (schId == 0) result.forEach(x -> x.setIsEdit(true));
|
||||
else if (userId == null)
|
||||
result.stream().filter(x -> x.getSchId() != null && x.getSchId().equals(schId) && x.getUserId() == null)
|
||||
.forEach(x -> x.setIsEdit(true));
|
||||
else
|
||||
result.stream().filter(x -> x.getSchId() != null && x.getUserId() != null && x.getSchId().equals(schId) && x.getUserId().equals(userId))
|
||||
.forEach(x -> x.setIsEdit(true));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveLightApp(LightApp lightApp) {
|
||||
if (lightApp.getSchId() == 0) lightApp.setUserId(null);
|
||||
if (lightApp.getUserId() == null) lightApp.setIsPublic(true);
|
||||
lightAppRepository.save(lightApp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteLightAppById(Integer id) {
|
||||
lightAppRepository.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDesktopAppById(Integer id) {
|
||||
userSettingsDesktopAppRepository.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveDesktopApp(UserSettingsDesktopApp model) {
|
||||
userSettingsDesktopAppRepository.save(model);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserSettingsDesktopApp> saveDesktopAppList(List<UserSettingsDesktopApp> list) {
|
||||
return userSettingsDesktopAppRepository.saveAll(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserSettings initUserSettings(Integer userId) {
|
||||
UserCurrentRole currentRole = userCurrentRoleService.findById(userId)
|
||||
.orElseThrow(() -> new BizException(ErrorCode.INTERNAL_SERVER_ERROR));
|
||||
UserSettings model = new UserSettings();
|
||||
model.setSchId(currentRole.getSchId());
|
||||
model.setRoleId(currentRole.getRoleId());
|
||||
model.setUserId(currentRole.getUserId());
|
||||
return userSettingsRepository.save(model);
|
||||
}
|
||||
|
||||
private UserSettings getUserSettings(Integer id, Integer userId) {
|
||||
Optional<UserSettings> optional;
|
||||
if (id != null)
|
||||
optional = userSettingsRepository.findById(id);
|
||||
else
|
||||
optional = findUserSettings(userId);
|
||||
if (optional.isPresent()) return optional.get();
|
||||
else {
|
||||
return initUserSettings(userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user