mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2026-04-30 17:11:28 +08:00
同步vue版本代码修改
update 使用常量替代硬编码的删除标志,优化查询条件 update 增加消息推送模块注释 update 优化 将全局继承MPJ改为按需求继承 fix 修复 distinct 在 sqlserver 中的限制 补缺排序字段 确保语法正确 update 增加部门Excel转换处理和下拉选项数据源
This commit is contained in:
@@ -31,12 +31,12 @@ public class RemoteMessageServiceImpl implements RemoteMessageService {
|
||||
/**
|
||||
* 发送消息
|
||||
*
|
||||
* @param sessionKey session主键 一般为用户id
|
||||
* @param message 消息文本
|
||||
* @param userIds 用户ID列表
|
||||
* @param message 消息文本
|
||||
*/
|
||||
@Override
|
||||
public void publishMessage(List<Long> sessionKey, String message) {
|
||||
publishMessagePayload(sessionKey, RemotePushPayLoad.of(PushTypeEnum.MESSAGE, PushSourceEnum.BACKEND, message, null));
|
||||
public void publishMessage(List<Long> userIds, String message) {
|
||||
publishMessagePayload(userIds, RemotePushPayLoad.of(PushTypeEnum.MESSAGE, PushSourceEnum.BACKEND, message, null));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,9 +12,29 @@ import java.util.List;
|
||||
*/
|
||||
public interface ISysMessageService {
|
||||
|
||||
/**
|
||||
* 查询当前用户消息盒子数据
|
||||
* 按系统消息、通知公告、工作流消息分类返回
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 消息盒子数据
|
||||
*/
|
||||
SysMessageBoxVo queryMessageBox(Long userId);
|
||||
|
||||
/**
|
||||
* 存储全局广播消息到数据库
|
||||
*
|
||||
* @param payload 消息推送体
|
||||
* @return 回填消息ID后的消息体
|
||||
*/
|
||||
PushPayloadDTO storeAll(PushPayloadDTO payload);
|
||||
|
||||
/**
|
||||
* 存储指定用户消息到数据库
|
||||
*
|
||||
* @param userIds 用户ID集合
|
||||
* @param payload 消息推送体
|
||||
* @return 回填消息ID后的消息体
|
||||
*/
|
||||
PushPayloadDTO storeUsers(List<Long> userIds, PushPayloadDTO payload);
|
||||
}
|
||||
|
||||
@@ -34,15 +34,45 @@ import java.util.concurrent.TimeUnit;
|
||||
@Service
|
||||
public class SysMessageServiceImpl implements ISysMessageService {
|
||||
|
||||
/**
|
||||
* 全局广播用户标识(所有用户可见)
|
||||
*/
|
||||
private static final String GLOBAL_USER_IDS = "0";
|
||||
|
||||
/**
|
||||
* 消息分类:系统消息
|
||||
*/
|
||||
private static final String CATEGORY_SYSTEM = "system";
|
||||
|
||||
/**
|
||||
* 消息分类:通知公告
|
||||
*/
|
||||
private static final String CATEGORY_NOTICE = "notice";
|
||||
|
||||
/**
|
||||
* 消息分类:工作流
|
||||
*/
|
||||
private static final String CATEGORY_WORKFLOW = "workflow";
|
||||
|
||||
/**
|
||||
* 消息盒子每页展示最大条数
|
||||
*/
|
||||
private static final int BOX_LIMIT = 100;
|
||||
|
||||
/**
|
||||
* 消息盒子展示消息天数(仅展示30天内)
|
||||
*/
|
||||
private static final long BOX_DAYS = 30L;
|
||||
|
||||
private final SysMessageMapper baseMapper;
|
||||
|
||||
/**
|
||||
* 查询当前用户消息盒子数据
|
||||
* 按系统消息、通知公告、工作流消息分类返回
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 分类消息盒子数据
|
||||
*/
|
||||
@Override
|
||||
public SysMessageBoxVo queryMessageBox(Long userId) {
|
||||
SysMessageBoxVo box = new SysMessageBoxVo();
|
||||
@@ -52,16 +82,37 @@ public class SysMessageServiceImpl implements ISysMessageService {
|
||||
return box;
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储全局广播消息到数据库
|
||||
*
|
||||
* @param payload 消息推送体
|
||||
* @return 回填消息ID后的消息体
|
||||
*/
|
||||
@Override
|
||||
public PushPayloadDTO storeAll(PushPayloadDTO payload) {
|
||||
return storeMessage(null, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储指定用户消息到数据库
|
||||
*
|
||||
* @param userIds 用户ID集合
|
||||
* @param payload 消息推送体
|
||||
* @return 回填消息ID后的消息体
|
||||
*/
|
||||
@Override
|
||||
public PushPayloadDTO storeUsers(List<Long> userIds, PushPayloadDTO payload) {
|
||||
return storeMessage(userIds, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一消息存储逻辑
|
||||
* 判断是否需要存入消息盒子,需要则插入数据库
|
||||
*
|
||||
* @param userIds 用户ID集合(为null则全局广播)
|
||||
* @param payload 消息推送体
|
||||
* @return 回填消息ID后的消息体
|
||||
*/
|
||||
private PushPayloadDTO storeMessage(List<Long> userIds, PushPayloadDTO payload) {
|
||||
if (!supportsMessageBox(payload)) {
|
||||
return payload;
|
||||
@@ -72,6 +123,14 @@ public class SysMessageServiceImpl implements ISysMessageService {
|
||||
return payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类和用户ID查询消息列表
|
||||
* 仅查询30天内、最多100条、按时间倒序
|
||||
*
|
||||
* @param category 消息分类
|
||||
* @param userId 用户ID
|
||||
* @return 消息VO列表
|
||||
*/
|
||||
private List<SysMessageVo> selectMessageList(String category, Long userId) {
|
||||
LambdaQueryWrapper<SysMessage> lqw = Wrappers.lambdaQuery();
|
||||
lqw.eq(SysMessage::getCategory, category);
|
||||
@@ -84,6 +143,13 @@ public class SysMessageServiceImpl implements ISysMessageService {
|
||||
return list.stream().map(this::buildVo).toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建消息实体(用于数据库存储)
|
||||
*
|
||||
* @param userIds 接收用户ID集合
|
||||
* @param payload 消息推送体
|
||||
* @return 系统消息实体
|
||||
*/
|
||||
private SysMessage buildMessage(List<Long> userIds, PushPayloadDTO payload) {
|
||||
SysMessage message = new SysMessage();
|
||||
message.setMessageId(payload.getMessageId() == null ? IdGeneratorUtil.nextLongId() : payload.getMessageId());
|
||||
@@ -99,6 +165,12 @@ public class SysMessageServiceImpl implements ISysMessageService {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 消息实体转换为展示VO
|
||||
*
|
||||
* @param entity 消息实体
|
||||
* @return 消息展示VO
|
||||
*/
|
||||
private SysMessageVo buildVo(SysMessage entity) {
|
||||
SysMessageVo vo = new SysMessageVo();
|
||||
vo.setMessageId(entity.getMessageId());
|
||||
@@ -114,6 +186,13 @@ public class SysMessageServiceImpl implements ISysMessageService {
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断消息是否需要存入消息盒子
|
||||
* 仅系统消息、通知消息需要存入
|
||||
*
|
||||
* @param payload 消息推送体
|
||||
* @return 是否支持存入消息盒子
|
||||
*/
|
||||
private boolean supportsMessageBox(PushPayloadDTO payload) {
|
||||
if (payload == null) {
|
||||
return false;
|
||||
@@ -125,6 +204,12 @@ public class SysMessageServiceImpl implements ISysMessageService {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据消息类型/来源自动解析消息分类
|
||||
*
|
||||
* @param payload 消息推送体
|
||||
* @return 消息分类(system/notice/workflow)
|
||||
*/
|
||||
private String resolveCategory(PushPayloadDTO payload) {
|
||||
if (StringUtils.equalsAny(payload.getType(), PushTypeEnum.NOTICE.getType())
|
||||
|| StringUtils.equalsAny(payload.getSource(), PushSourceEnum.NOTICE.getSource())) {
|
||||
@@ -136,6 +221,12 @@ public class SysMessageServiceImpl implements ISysMessageService {
|
||||
return CATEGORY_SYSTEM;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据消息分类自动生成消息标题
|
||||
*
|
||||
* @param payload 消息推送体
|
||||
* @return 消息标题
|
||||
*/
|
||||
private String resolveTitle(PushPayloadDTO payload) {
|
||||
return switch (resolveCategory(payload)) {
|
||||
case CATEGORY_NOTICE -> "通知公告消息";
|
||||
@@ -144,6 +235,12 @@ public class SysMessageServiceImpl implements ISysMessageService {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析消息内容(从data中提取noticeContent)
|
||||
*
|
||||
* @param payload 消息推送体
|
||||
* @return 消息内容
|
||||
*/
|
||||
private String resolveContent(PushPayloadDTO payload) {
|
||||
Object data = payload.getData();
|
||||
if (data instanceof Map<?, ?> map) {
|
||||
@@ -152,6 +249,12 @@ public class SysMessageServiceImpl implements ISysMessageService {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析JSON数据字符串为对象
|
||||
*
|
||||
* @param dataJson JSON字符串
|
||||
* @return 解析后对象
|
||||
*/
|
||||
private Object parseData(String dataJson) {
|
||||
if (StringUtils.isBlank(dataJson)) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user