mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 04:39:00 +08:00
feat(pigx-upms-api): 新增站内消息/公告发送功能
- 新增MessageNoticeDTO用于站内消息/公告数据传输 - 在RemoteMessageService中添加sendNotice接口 - 在SysMessageService及其实现类中新增sendNotice方法 - 在SysMessageController中新增sendNotice接口并添加权限控制 - 完善消息保存逻辑,支持站内消息/公告的发送
This commit is contained in:
1 parent
7015e4704c
commit
e60a28a17e
5 files changed
+135
-4
No files matched your search
+53
@@ -0,0 +1,53 @@
|
||||
package com.pig4cloud.pigx.admin.api.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.FieldNameConstants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 站内消息/公告发送
|
||||
*
|
||||
* @author lengleng
|
||||
* @date 2024/07/18
|
||||
*/
|
||||
@Data
|
||||
@FieldNameConstants
|
||||
public class MessageNoticeDTO {
|
||||
|
||||
/**
|
||||
* 分类 0-公告 1-站内信
|
||||
*/
|
||||
@NotBlank
|
||||
private String category;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
@NotBlank
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
@NotBlank
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 通知全体 0-否 1-是
|
||||
*/
|
||||
private String allFlag = "0";
|
||||
|
||||
/**
|
||||
* 接收用户ID列表(allFlag=0时必填)
|
||||
*/
|
||||
private List<Long> userIds = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 排序(越大越在前)
|
||||
*/
|
||||
private Integer sort = 0;
|
||||
|
||||
}
|
||||
+10
@@ -21,6 +21,7 @@ package com.pig4cloud.pigx.admin.api.feign;
|
||||
|
||||
import com.pig4cloud.pigx.admin.api.dto.MessageEmailDTO;
|
||||
import com.pig4cloud.pigx.admin.api.dto.MessageHookDTO;
|
||||
import com.pig4cloud.pigx.admin.api.dto.MessageNoticeDTO;
|
||||
import com.pig4cloud.pigx.admin.api.dto.MessageSmsDTO;
|
||||
import com.pig4cloud.pigx.common.core.constant.ServiceNameConstants;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
@@ -64,4 +65,13 @@ public interface RemoteMessageService {
|
||||
@PostMapping("/sysMessage/send/hook")
|
||||
R sendHook(@RequestBody MessageHookDTO hookDTO);
|
||||
|
||||
/**
|
||||
* 发送站内消息/公告
|
||||
*
|
||||
* @param noticeDTO 站内消息 DTO
|
||||
* @return {@link R }
|
||||
*/
|
||||
@PostMapping("/sysMessage/send/notice")
|
||||
R sendNotice(@RequestBody MessageNoticeDTO noticeDTO);
|
||||
|
||||
}
|
||||
+24
@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.pig4cloud.pigx.admin.api.dto.MessageEmailDTO;
|
||||
import com.pig4cloud.pigx.admin.api.dto.MessageHookDTO;
|
||||
import com.pig4cloud.pigx.admin.api.dto.MessageNoticeDTO;
|
||||
import com.pig4cloud.pigx.admin.api.dto.MessageSmsDTO;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysMessageEntity;
|
||||
import com.pig4cloud.pigx.admin.api.vo.SysMessageVO;
|
||||
@@ -200,7 +201,10 @@ public class SysMessageController {
|
||||
* @param messageSmsDTO 消息 短信 DTO
|
||||
* @return {@link R }
|
||||
*/
|
||||
@Operation(summary = "发送短信", description = "发送短信")
|
||||
@SysLog("发送短信")
|
||||
@PostMapping("/send/sms")
|
||||
@HasPermission("sys_message_add")
|
||||
public R sendSms(@Valid @RequestBody MessageSmsDTO messageSmsDTO) {
|
||||
return sysMessageService.sendSms(messageSmsDTO);
|
||||
}
|
||||
@@ -211,7 +215,10 @@ public class SysMessageController {
|
||||
* @param messageEmailDTO 留言内容 电子邮件 DTO
|
||||
* @return {@link R }
|
||||
*/
|
||||
@Operation(summary = "发送邮件", description = "发送邮件")
|
||||
@SysLog("发送邮件")
|
||||
@PostMapping("/send/email")
|
||||
@HasPermission("sys_message_add")
|
||||
public R sendEmail(@Valid @RequestBody MessageEmailDTO messageEmailDTO) {
|
||||
return sysMessageService.sendEmail(messageEmailDTO);
|
||||
}
|
||||
@@ -222,7 +229,10 @@ public class SysMessageController {
|
||||
* @param messageHookDTO 消息挂钩 DTO
|
||||
* @return {@link R }
|
||||
*/
|
||||
@Operation(summary = "发送 webhook", description = "发送 webhook")
|
||||
@SysLog("发送 webhook")
|
||||
@PostMapping("/send/hook")
|
||||
@HasPermission("sys_message_add")
|
||||
public R sendWebhook(@Valid @RequestBody MessageHookDTO messageHookDTO) {
|
||||
return sysMessageService.sendHook(messageHookDTO);
|
||||
}
|
||||
@@ -232,4 +242,18 @@ public class SysMessageController {
|
||||
return sysMessageService.listHookBizCode(messageHookDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送站内消息/公告
|
||||
*
|
||||
* @param noticeDTO 站内消息 DTO
|
||||
* @return {@link R }
|
||||
*/
|
||||
@Operation(summary = "发送站内消息/公告", description = "发送站内消息/公告")
|
||||
@SysLog("发送站内消息/公告")
|
||||
@PostMapping("/send/notice")
|
||||
@HasPermission("sys_message_add")
|
||||
public R sendNotice(@Valid @RequestBody MessageNoticeDTO noticeDTO) {
|
||||
return sysMessageService.sendNotice(noticeDTO);
|
||||
}
|
||||
|
||||
}
|
||||
+9
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.pig4cloud.pigx.admin.api.dto.MessageEmailDTO;
|
||||
import com.pig4cloud.pigx.admin.api.dto.MessageHookDTO;
|
||||
import com.pig4cloud.pigx.admin.api.dto.MessageNoticeDTO;
|
||||
import com.pig4cloud.pigx.admin.api.dto.MessageSmsDTO;
|
||||
import com.pig4cloud.pigx.admin.api.entity.SysMessageEntity;
|
||||
import com.pig4cloud.pigx.admin.api.vo.SysMessageVO;
|
||||
@@ -102,4 +103,12 @@ public interface SysMessageService extends IService<SysMessageEntity> {
|
||||
*/
|
||||
R listHookBizCode(MessageHookDTO messageHookDTO);
|
||||
|
||||
/**
|
||||
* 发送站内消息/公告
|
||||
*
|
||||
* @param noticeDTO 站内消息 DTO
|
||||
* @return {@link R }
|
||||
*/
|
||||
R sendNotice(MessageNoticeDTO noticeDTO);
|
||||
|
||||
}
|
||||
+39
-4
@@ -24,10 +24,7 @@ import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.pig4cloud.pigx.admin.api.constant.SmsBizCodeEnum;
|
||||
import com.pig4cloud.pigx.admin.api.constant.SystemConfigTypeEnum;
|
||||
import com.pig4cloud.pigx.admin.api.constant.UpmsErrorCodes;
|
||||
import com.pig4cloud.pigx.admin.api.dto.MessageEmailDTO;
|
||||
import com.pig4cloud.pigx.admin.api.dto.MessageHookDTO;
|
||||
import com.pig4cloud.pigx.admin.api.dto.MessageSmsDTO;
|
||||
import com.pig4cloud.pigx.admin.api.dto.SysLogDTO;
|
||||
import com.pig4cloud.pigx.admin.api.dto.*;
|
||||
import com.pig4cloud.pigx.admin.api.entity.*;
|
||||
import com.pig4cloud.pigx.admin.api.feign.RemoteLogService;
|
||||
import com.pig4cloud.pigx.admin.api.vo.OrgTreeVO;
|
||||
@@ -149,10 +146,12 @@ public class SysMessageServiceImpl extends ServiceImpl<SysMessageMapper, SysMess
|
||||
|
||||
if (Objects.isNull(sysMessage.getId())) {
|
||||
baseMapper.insert(messageEntity);
|
||||
sysMessage.setId(messageEntity.getId());
|
||||
} else {
|
||||
baseMapper.updateById(sysMessage);
|
||||
}
|
||||
|
||||
|
||||
// 删除原有用户
|
||||
relationMapper.delete(Wrappers.<SysMessageRelationEntity>lambdaQuery()
|
||||
.eq(SysMessageRelationEntity::getMsgId, messageEntity.getId()));
|
||||
@@ -549,4 +548,40 @@ public class SysMessageServiceImpl extends ServiceImpl<SysMessageMapper, SysMess
|
||||
return R.ok(configEntityList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送站内消息/公告
|
||||
*
|
||||
* @param noticeDTO 站内消息 DTO
|
||||
* @return {@link R }
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public R sendNotice(MessageNoticeDTO noticeDTO) {
|
||||
// 构建消息VO
|
||||
SysMessageVO messageVO = new SysMessageVO();
|
||||
messageVO.setCategory(noticeDTO.getCategory());
|
||||
messageVO.setTitle(noticeDTO.getTitle());
|
||||
messageVO.setContent(noticeDTO.getContent());
|
||||
messageVO.setAllFlag(noticeDTO.getAllFlag());
|
||||
messageVO.setSort(noticeDTO.getSort());
|
||||
|
||||
// 设置接收用户列表
|
||||
if (CollUtil.isNotEmpty(noticeDTO.getUserIds())) {
|
||||
List<OrgTreeVO> userList = noticeDTO.getUserIds().stream().map(userId -> {
|
||||
OrgTreeVO orgTreeVO = new OrgTreeVO();
|
||||
orgTreeVO.setId(userId);
|
||||
return orgTreeVO;
|
||||
}).toList();
|
||||
messageVO.setUserList(userList);
|
||||
}
|
||||
|
||||
// 保存消息
|
||||
saveOrUpdateMessage(messageVO);
|
||||
|
||||
// 立即发送消息
|
||||
sendMessage(messageVO.getId());
|
||||
|
||||
return R.ok(messageVO.getId());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user