✨ 站内消息.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.orion.ops.module.infra.api;
|
||||
|
||||
import com.orion.ops.module.infra.define.SystemMessageDefine;
|
||||
import com.orion.ops.module.infra.entity.dto.message.SystemMessageCreateDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.message.SystemMessageDTO;
|
||||
import com.orion.ops.module.infra.enums.MessageClassifyEnum;
|
||||
|
||||
/**
|
||||
@@ -12,6 +14,15 @@ import com.orion.ops.module.infra.enums.MessageClassifyEnum;
|
||||
*/
|
||||
public interface SystemMessageApi {
|
||||
|
||||
/**
|
||||
* 创建系统消息
|
||||
*
|
||||
* @param define define
|
||||
* @param dto dto
|
||||
* @return id
|
||||
*/
|
||||
Long create(SystemMessageDefine define, SystemMessageDTO dto);
|
||||
|
||||
/**
|
||||
* 创建系统消息
|
||||
*
|
||||
@@ -19,6 +30,6 @@ public interface SystemMessageApi {
|
||||
* @param dto dto
|
||||
* @return id
|
||||
*/
|
||||
Long createSystemMessage(MessageClassifyEnum classify, SystemMessageCreateDTO dto);
|
||||
Long create(MessageClassifyEnum classify, SystemMessageCreateDTO dto);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.orion.ops.module.infra.define;
|
||||
|
||||
import com.orion.lang.utils.Strings;
|
||||
import com.orion.ops.module.infra.enums.MessageClassifyEnum;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 系统消息定义
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/5/14 17:06
|
||||
*/
|
||||
public interface SystemMessageDefine {
|
||||
|
||||
/**
|
||||
* @return 消息分类
|
||||
*/
|
||||
MessageClassifyEnum getClassify();
|
||||
|
||||
/**
|
||||
* @return 消息类型
|
||||
*/
|
||||
String getType();
|
||||
|
||||
/**
|
||||
* @return 标题
|
||||
*/
|
||||
String getTitle();
|
||||
|
||||
/**
|
||||
* @return 内容
|
||||
*/
|
||||
String getContent();
|
||||
|
||||
/**
|
||||
* 格式化内容
|
||||
*
|
||||
* @param params params
|
||||
* @return content
|
||||
*/
|
||||
default String formatContent(Map<String, Object> params) {
|
||||
return Strings.format(this.getContent(), params);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,6 +27,11 @@ public class SystemMessageCreateDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 10)
|
||||
@Schema(description = "消息分类")
|
||||
private String classify;
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 32)
|
||||
@Schema(description = "消息类型")
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.orion.ops.module.infra.entity.dto.message;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 系统消息 请求业务对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.8
|
||||
* @since 2024-5-11 16:29
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "SystemMessageDTO", description = "系统消息 请求业务对象")
|
||||
public class SystemMessageDTO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 64)
|
||||
@Schema(description = "消息关联")
|
||||
private String relKey;
|
||||
|
||||
@NotNull
|
||||
@Schema(description = "接收人id")
|
||||
private Long receiverId;
|
||||
|
||||
@Schema(description = "接收人用户名")
|
||||
private String receiverUsername;
|
||||
|
||||
@Schema(description = "参数")
|
||||
private Map<String, Object> params;
|
||||
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.orion.ops.module.infra.api.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
import com.orion.ops.module.infra.api.SystemMessageApi;
|
||||
import com.orion.ops.module.infra.convert.SystemMessageProviderConvert;
|
||||
import com.orion.ops.module.infra.define.SystemMessageDefine;
|
||||
import com.orion.ops.module.infra.entity.dto.message.SystemMessageCreateDTO;
|
||||
import com.orion.ops.module.infra.entity.dto.message.SystemMessageDTO;
|
||||
import com.orion.ops.module.infra.entity.request.message.SystemMessageCreateRequest;
|
||||
import com.orion.ops.module.infra.enums.MessageClassifyEnum;
|
||||
import com.orion.ops.module.infra.service.SystemMessageService;
|
||||
@@ -28,12 +29,28 @@ public class SystemMessageApiImpl implements SystemMessageApi {
|
||||
private SystemMessageService systemMessageService;
|
||||
|
||||
@Override
|
||||
public Long createSystemMessage(MessageClassifyEnum classify, SystemMessageCreateDTO dto) {
|
||||
log.info("SystemMessageApi.createSystemMessage dto: {}", JSON.toJSONString(dto));
|
||||
public Long create(SystemMessageDefine define, SystemMessageDTO dto) {
|
||||
Valid.valid(dto);
|
||||
// 转换
|
||||
SystemMessageCreateRequest request = SystemMessageCreateRequest.builder()
|
||||
.classify(define.getClassify().name())
|
||||
.type(define.getType())
|
||||
.title(define.getTitle())
|
||||
.content(define.formatContent(dto.getParams()))
|
||||
.relKey(dto.getRelKey())
|
||||
.receiverId(dto.getReceiverId())
|
||||
.receiverUsername(dto.getReceiverUsername())
|
||||
.build();
|
||||
// 创建
|
||||
return systemMessageService.createSystemMessage(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long create(MessageClassifyEnum classify, SystemMessageCreateDTO dto) {
|
||||
dto.setClassify(classify.name());
|
||||
Valid.valid(dto);
|
||||
// 转换
|
||||
SystemMessageCreateRequest request = SystemMessageProviderConvert.MAPPER.toRequest(dto);
|
||||
request.setClassify(classify.name());
|
||||
// 创建
|
||||
return systemMessageService.createSystemMessage(request);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.orion.ops.module.infra.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.orion.lang.function.Functions;
|
||||
import com.orion.lang.utils.Booleans;
|
||||
@@ -44,6 +45,7 @@ public class SystemMessageServiceImpl implements SystemMessageService {
|
||||
|
||||
@Override
|
||||
public Long createSystemMessage(SystemMessageCreateRequest request) {
|
||||
log.info("SystemMessageService.createSystemMessage request: {}", JSON.toJSONString(request));
|
||||
// 设置接收人用户名
|
||||
if (request.getReceiverUsername() == null) {
|
||||
Optional.ofNullable(request.getReceiverId())
|
||||
|
||||
Reference in New Issue
Block a user