diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/CodeGenerators.java b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/CodeGenerators.java index 2811e166..e8ff942a 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/CodeGenerators.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/CodeGenerators.java @@ -26,7 +26,7 @@ public class CodeGenerators { // 作者 String author = Const.ORION_AUTHOR; // 模块 - String module = "asset"; + String module = "infra"; // 生成的表 Table[] tables = { // Template.create("dict_key", "字典配置项", "dict") @@ -49,24 +49,22 @@ public class CodeGenerators { // .disableUnitTest() // .vue("exec", "exec-template-host") // .build(), - Template.create("upload_task", "上传任务", "upload") + Template.create("system_message", "系统消息", "message") .disableUnitTest() - .vue("exec", "upload-task") - .enableRowSelection() - .dict("uploadTaskStatus", "status") - .comment("上传任务状态") - .fields("WAITING", "UPLOADING", "FINISHED", "FAILED", "CANCELED") - .labels("等待中", "上传中", "已完成", "已失败", "已取消") + .enableProviderApi() + .vue("system", "message") + .dict("messageClassify", "classify", "messageClassify") + .comment("消息分类") + .fields("NOTICE", "TODO") + .labels("通知", "待办") .valueUseFields() - .build(), - Template.create("upload_task_file", "上传任务文件", "upload") - .disableUnitTest() - .vue("exec", "upload-task-file") - .enableRowSelection() - .dict("uploadTaskFileStatus", "status") - .comment("上传任务文件状态") - .fields("WAITING", "UPLOADING", "FINISHED", "FAILED", "CANCELED") - .labels("等待中", "上传中", "已完成", "已失败", "已取消") + .dict("messageType", "type", "messageType") + .comment("消息类型") + .fields("EXEC_FAILED", "UPLOAD_FAILED") + .labels("执行失败", "上传失败") + .extra("tagLabel", "执行失败", "上传失败") + .extra("tagVisible", true, true) + .extra("tagColor", "red", "red") .valueUseFields() .build(), }; diff --git a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/DictTemplate.java b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/DictTemplate.java index 4760400a..214a46aa 100644 --- a/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/DictTemplate.java +++ b/orion-ops-framework/orion-ops-spring-boot-starter-mybatis/src/main/java/com/orion/ops/framework/mybatis/core/generator/template/DictTemplate.java @@ -14,6 +14,17 @@ import java.util.LinkedHashMap; */ public class DictTemplate extends Template { + // // $comment + // export const $field = { + // // labels[0] + // fields[0]: 'values[0]', + // // labels[1] + // fields[0]: 'values[1]', + // }; + // + // // $comment 字典项 + // export const $keyField = '$keyName'; + private final DictMeta dictMeta; public DictTemplate(Table table, String keyName, String variable) { diff --git a/orion-ops-module-infra/orion-ops-module-infra-provider/src/main/java/com/orion/ops/module/infra/api/SystemMessageApi.java b/orion-ops-module-infra/orion-ops-module-infra-provider/src/main/java/com/orion/ops/module/infra/api/SystemMessageApi.java new file mode 100644 index 00000000..17a5c01c --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-provider/src/main/java/com/orion/ops/module/infra/api/SystemMessageApi.java @@ -0,0 +1,24 @@ +package com.orion.ops.module.infra.api; + +import com.orion.ops.module.infra.entity.dto.message.SystemMessageCreateDTO; +import com.orion.ops.module.infra.enums.MessageClassifyEnum; + +/** + * 系统消息 对外服务类 + * + * @author Jiahang Li + * @version 1.0.8 + * @since 2024-5-11 16:29 + */ +public interface SystemMessageApi { + + /** + * 创建系统消息 + * + * @param classify classify + * @param dto dto + * @return id + */ + Long createSystemMessage(MessageClassifyEnum classify, SystemMessageCreateDTO dto); + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-provider/src/main/java/com/orion/ops/module/infra/entity/dto/message/SystemMessageCreateDTO.java b/orion-ops-module-infra/orion-ops-module-infra-provider/src/main/java/com/orion/ops/module/infra/entity/dto/message/SystemMessageCreateDTO.java new file mode 100644 index 00000000..9ab2c708 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-provider/src/main/java/com/orion/ops/module/infra/entity/dto/message/SystemMessageCreateDTO.java @@ -0,0 +1,56 @@ +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; + +/** + * 系统消息 创建请求业务对象 + * + * @author Jiahang Li + * @version 1.0.8 + * @since 2024-5-11 16:29 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Schema(name = "SystemMessageCreateDTO", description = "系统消息 创建请求业务对象") +public class SystemMessageCreateDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + @NotBlank + @Size(max = 32) + @Schema(description = "消息类型") + private String type; + + @NotBlank + @Size(max = 64) + @Schema(description = "消息关联") + private String relKey; + + @NotBlank + @Size(max = 128) + @Schema(description = "标题") + private String title; + + @NotBlank + @Schema(description = "消息内容") + private String content; + + @NotNull + @Schema(description = "接收人id") + private Long receiverId; + + @Schema(description = "接收人用户名") + private String receiverUsername; + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-provider/src/main/java/com/orion/ops/module/infra/enums/MessageClassifyEnum.java b/orion-ops-module-infra/orion-ops-module-infra-provider/src/main/java/com/orion/ops/module/infra/enums/MessageClassifyEnum.java new file mode 100644 index 00000000..5bb3fe2a --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-provider/src/main/java/com/orion/ops/module/infra/enums/MessageClassifyEnum.java @@ -0,0 +1,24 @@ +package com.orion.ops.module.infra.enums; + +/** + * 消息分类 + * + * @author Jiahang Li + * @version 1.0.8 + * @since 2024/5/11 16:38 + */ +public enum MessageClassifyEnum { + + /** + * 通知 + */ + NOTICE, + + /** + * 待办 + */ + TODO, + + ; + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/api/impl/SystemMessageApiImpl.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/api/impl/SystemMessageApiImpl.java new file mode 100644 index 00000000..8c427d85 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/api/impl/SystemMessageApiImpl.java @@ -0,0 +1,41 @@ +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.entity.dto.message.SystemMessageCreateDTO; +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; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +/** + * 系统消息 对外服务实现类 + * + * @author Jiahang Li + * @version 1.0.8 + * @since 2024-5-11 16:29 + */ +@Slf4j +@Service +public class SystemMessageApiImpl implements SystemMessageApi { + + @Resource + private SystemMessageService systemMessageService; + + @Override + public Long createSystemMessage(MessageClassifyEnum classify, SystemMessageCreateDTO dto) { + log.info("SystemMessageApi.createSystemMessage dto: {}", JSON.toJSONString(dto)); + Valid.valid(dto); + // 转换 + SystemMessageCreateRequest request = SystemMessageProviderConvert.MAPPER.toRequest(dto); + request.setClassify(classify.name()); + // 创建 + return systemMessageService.createSystemMessage(request); + } + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/SystemMessageController.http b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/SystemMessageController.http new file mode 100644 index 00000000..0d0df1fa --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/SystemMessageController.http @@ -0,0 +1,39 @@ +### 查询系统消息列表 +POST {{baseUrl}}/infra/system-message/list +Content-Type: application/json +Authorization: {{token}} + +{ + "limit": 10, + "maxId": null, + "classify": "NOTICE", + "queryCount": true, + "queryUnread": true +} + + +### 查询是否有未读消息 +GET {{baseUrl}}/infra/system-message/has-unread +Authorization: {{token}} + + +### 查询是否有未读消息 +PUT {{baseUrl}}/infra/system-message/read?id=1 +Authorization: {{token}} + + +### 更新全部系统消息为已读 +PUT {{baseUrl}}/infra/system-message/read-all?classify=NOTICE +Authorization: {{token}} + + +### 删除系统消息 +DELETE {{baseUrl}}/infra/system-message/delete?id=1 +Authorization: {{token}} + + +### 清理已读的系统消息 +DELETE {{baseUrl}}/infra/system-message/clear?classify=NOTICE +Authorization: {{token}} + +### diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/SystemMessageController.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/SystemMessageController.java new file mode 100644 index 00000000..fca4e08f --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/controller/SystemMessageController.java @@ -0,0 +1,90 @@ +package com.orion.ops.module.infra.controller; + +import com.orion.ops.framework.log.core.annotation.IgnoreLog; +import com.orion.ops.framework.log.core.enums.IgnoreLogMode; +import com.orion.ops.framework.web.core.annotation.RestWrapper; +import com.orion.ops.module.infra.entity.request.message.SystemMessageQueryRequest; +import com.orion.ops.module.infra.entity.vo.SystemMessageVO; +import com.orion.ops.module.infra.service.SystemMessageService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; + +/** + * 系统消息 api + * + * @author Jiahang Li + * @version 1.0.8 + * @since 2024-5-11 16:29 + */ +@Tag(name = "infra - 系统消息服务") +@Slf4j +@Validated +@RestWrapper +@RestController +@RequestMapping("/infra/system-message") +@SuppressWarnings({"ELValidationInJSP", "SpringElInspection"}) +public class SystemMessageController { + + @Resource + private SystemMessageService systemMessageService; + + @IgnoreLog(IgnoreLogMode.ALL) + @PostMapping("/list") + @Operation(summary = "查询系统消息列表") + public List getSystemMessageList(@RequestBody SystemMessageQueryRequest request) { + return systemMessageService.getSystemMessageList(request); + } + + @IgnoreLog(IgnoreLogMode.ALL) + @GetMapping("/count") + @Operation(summary = "查询系统消息数量") + @Parameter(name = "queryUnread", description = "queryUnread", required = true) + public Map getSystemMessageCount(@RequestParam("queryUnread") Boolean queryUnread) { + return systemMessageService.getSystemMessageCount(queryUnread); + } + + @IgnoreLog(IgnoreLogMode.ALL) + @GetMapping("/has-unread") + @Operation(summary = "查询是否有未读消息") + public Boolean checkHasUnreadMessage() { + return systemMessageService.checkHasUnreadMessage(); + } + + @PutMapping("/read") + @Operation(summary = "更新系统消息为已读") + @Parameter(name = "id", description = "id", required = true) + public Integer readSystemMessage(@RequestParam("id") Long id) { + return systemMessageService.readSystemMessage(id); + } + + @PutMapping("/read-all") + @Operation(summary = "更新全部系统消息为已读") + @Parameter(name = "classify", description = "classify", required = true) + public Integer readAllSystemMessage(@RequestParam("classify") String classify) { + return systemMessageService.readAllSystemMessage(classify); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除系统消息") + @Parameter(name = "id", description = "id", required = true) + public Integer deleteSystemMessage(@RequestParam("id") Long id) { + return systemMessageService.deleteSystemMessageById(id); + } + + @DeleteMapping("/clear") + @Operation(summary = "清理已读的系统消息") + @Parameter(name = "classify", description = "classify", required = true) + public Integer clearSystemMessage(@RequestParam("classify") String classify) { + return systemMessageService.clearSystemMessage(classify); + } + +} + diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/SystemMessageConvert.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/SystemMessageConvert.java new file mode 100644 index 00000000..64b79551 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/SystemMessageConvert.java @@ -0,0 +1,32 @@ +package com.orion.ops.module.infra.convert; + +import com.orion.ops.module.infra.entity.domain.SystemMessageDO; +import com.orion.ops.module.infra.entity.request.message.SystemMessageCreateRequest; +import com.orion.ops.module.infra.entity.request.message.SystemMessageQueryRequest; +import com.orion.ops.module.infra.entity.vo.SystemMessageVO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +/** + * 系统消息 内部对象转换器 + * + * @author Jiahang Li + * @version 1.0.8 + * @since 2024-5-11 16:29 + */ +@Mapper +public interface SystemMessageConvert { + + SystemMessageConvert MAPPER = Mappers.getMapper(SystemMessageConvert.class); + + SystemMessageDO to(SystemMessageCreateRequest request); + + SystemMessageDO to(SystemMessageQueryRequest request); + + SystemMessageVO to(SystemMessageDO domain); + + List to(List list); + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/SystemMessageProviderConvert.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/SystemMessageProviderConvert.java new file mode 100644 index 00000000..7dfc71f2 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/convert/SystemMessageProviderConvert.java @@ -0,0 +1,22 @@ +package com.orion.ops.module.infra.convert; + +import com.orion.ops.module.infra.entity.dto.message.SystemMessageCreateDTO; +import com.orion.ops.module.infra.entity.request.message.SystemMessageCreateRequest; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * 系统消息 对外服务对象转换器 + * + * @author Jiahang Li + * @version 1.0.8 + * @since 2024-5-11 16:29 + */ +@Mapper +public interface SystemMessageProviderConvert { + + SystemMessageProviderConvert MAPPER = Mappers.getMapper(SystemMessageProviderConvert.class); + + SystemMessageCreateRequest toRequest(SystemMessageCreateDTO request); + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/dao/SystemMessageDAO.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/dao/SystemMessageDAO.java new file mode 100644 index 00000000..2c9b1dca --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/dao/SystemMessageDAO.java @@ -0,0 +1,31 @@ +package com.orion.ops.module.infra.dao; + +import com.orion.ops.framework.mybatis.core.mapper.IMapper; +import com.orion.ops.module.infra.entity.domain.SystemMessageDO; +import com.orion.ops.module.infra.entity.dto.SystemMessageCountDTO; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 系统消息 Mapper 接口 + * + * @author Jiahang Li + * @version 1.0.8 + * @since 2024-5-11 16:29 + */ +@Mapper +public interface SystemMessageDAO extends IMapper { + + /** + * 查询消息数量 + * + * @param receiverId receiverId + * @param status status + * @return count + */ + List selectSystemMessageCount(@Param("receiverId") Long receiverId, + @Param("status") Integer status); + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/domain/SystemMessageDO.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/domain/SystemMessageDO.java new file mode 100644 index 00000000..b016fffc --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/domain/SystemMessageDO.java @@ -0,0 +1,73 @@ +package com.orion.ops.module.infra.entity.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.orion.ops.framework.mybatis.core.domain.BaseDO; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; + +/** + * 系统消息 实体对象 + * + * @author Jiahang Li + * @version 1.0.8 + * @since 2024-5-11 16:29 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +@TableName(value = "system_message", autoResultMap = true) +@Schema(name = "SystemMessageDO", description = "系统消息 实体对象") +public class SystemMessageDO extends BaseDO { + + private static final long serialVersionUID = 1L; + + @Schema(description = "id") + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + @Schema(description = "消息分类") + @TableField("classify") + private String classify; + + @Schema(description = "消息类型") + @TableField("type") + private String type; + + @Schema(description = "消息状态") + @TableField("status") + private Integer status; + + @Schema(description = "消息关联") + @TableField("rel_key") + private String relKey; + + @Schema(description = "标题") + @TableField("title") + private String title; + + @Schema(description = "消息内容") + @TableField("content") + private String content; + + @Schema(description = "接收人id") + @TableField("receiver_id") + private Long receiverId; + + @Schema(description = "接收人用户名") + @TableField("receiver_username") + private String receiverUsername; + + @Schema(description = "创建人") + @TableField(exist = false) + private String creator; + + @Schema(description = "修改人") + @TableField(exist = false) + private String updater; + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/dto/SystemMessageCountDTO.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/dto/SystemMessageCountDTO.java new file mode 100644 index 00000000..05980814 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/dto/SystemMessageCountDTO.java @@ -0,0 +1,33 @@ +package com.orion.ops.module.infra.entity.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * 系统消息数量对象 + * + * @author Jiahang Li + * @version 1.0.8 + * @since 2024/5/11 18:15 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Schema(name = "SystemMessageCountDTO", description = "系统消息数量对象") +public class SystemMessageCountDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "消息分类") + private String classify; + + @Schema(description = "数量") + private Integer count; + +} \ No newline at end of file diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/message/SystemMessageCreateRequest.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/message/SystemMessageCreateRequest.java new file mode 100644 index 00000000..1dfcf24c --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/message/SystemMessageCreateRequest.java @@ -0,0 +1,62 @@ +package com.orion.ops.module.infra.entity.request.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; + +/** + * 系统消息 创建请求对象 + * + * @author Jiahang Li + * @version 1.0.8 + * @since 2024-5-11 16:29 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Schema(name = "SystemMessageCreateRequest", description = "系统消息 创建请求对象") +public class SystemMessageCreateRequest implements Serializable { + + private static final long serialVersionUID = 1L; + + @NotBlank + @Size(max = 10) + @Schema(description = "消息分类") + private String classify; + + @NotBlank + @Size(max = 32) + @Schema(description = "消息类型") + private String type; + + @NotBlank + @Size(max = 64) + @Schema(description = "消息关联") + private String relKey; + + @NotBlank + @Size(max = 128) + @Schema(description = "标题") + private String title; + + @NotBlank + @Schema(description = "消息内容") + private String content; + + @NotNull + @Schema(description = "接收人id") + private Long receiverId; + + @Size(max = 32) + @Schema(description = "接收人用户名") + private String receiverUsername; + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/message/SystemMessageQueryRequest.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/message/SystemMessageQueryRequest.java new file mode 100644 index 00000000..ad6e2cc1 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/message/SystemMessageQueryRequest.java @@ -0,0 +1,35 @@ +package com.orion.ops.module.infra.entity.request.message; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 系统消息 查询请求对象 + * + * @author Jiahang Li + * @version 1.0.8 + * @since 2024-5-11 16:29 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Schema(name = "SystemMessageQueryRequest", description = "系统消息 查询请求对象") +public class SystemMessageQueryRequest { + + @Schema(description = "大小") + private Integer limit; + + @Schema(description = "maxId") + private Long maxId; + + @Schema(description = "消息分类") + private String classify; + + @Schema(description = "是否查询未读消息") + private Boolean queryUnread; + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/vo/SystemMessageVO.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/vo/SystemMessageVO.java new file mode 100644 index 00000000..fdbc1b00 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/vo/SystemMessageVO.java @@ -0,0 +1,52 @@ +package com.orion.ops.module.infra.entity.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.Date; + +/** + * 系统消息 视图响应对象 + * + * @author Jiahang Li + * @version 1.0.8 + * @since 2024-5-11 16:29 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Schema(name = "SystemMessageVO", description = "系统消息 视图响应对象") +public class SystemMessageVO implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "id") + private Long id; + + @Schema(description = "消息分类") + private String classify; + + @Schema(description = "消息类型") + private String type; + + @Schema(description = "消息状态") + private Integer status; + + @Schema(description = "消息关联") + private String relKey; + + @Schema(description = "标题") + private String title; + + @Schema(description = "消息内容") + private String content; + + @Schema(description = "创建时间") + private Date createTime; + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/enums/MessageStatusEnum.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/enums/MessageStatusEnum.java new file mode 100644 index 00000000..bdb6f10f --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/enums/MessageStatusEnum.java @@ -0,0 +1,31 @@ +package com.orion.ops.module.infra.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 消息状态 + * + * @author Jiahang Li + * @version 1.0.8 + * @since 2024/5/11 16:35 + */ +@Getter +@AllArgsConstructor +public enum MessageStatusEnum { + + /** + * 未读 + */ + UNREAD(0), + + /** + * 已读 + */ + READ(1), + + ; + + private final Integer status; + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/SystemMessageService.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/SystemMessageService.java new file mode 100644 index 00000000..6a0389d7 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/SystemMessageService.java @@ -0,0 +1,82 @@ +package com.orion.ops.module.infra.service; + +import com.orion.ops.module.infra.entity.request.message.SystemMessageCreateRequest; +import com.orion.ops.module.infra.entity.request.message.SystemMessageQueryRequest; +import com.orion.ops.module.infra.entity.vo.SystemMessageVO; + +import java.util.List; +import java.util.Map; + +/** + * 系统消息 服务类 + * + * @author Jiahang Li + * @version 1.0.8 + * @since 2024-5-11 16:29 + */ +public interface SystemMessageService { + + /** + * 创建系统消息 + * + * @param request request + * @return id + */ + Long createSystemMessage(SystemMessageCreateRequest request); + + /** + * 查询系统消息列表 + * + * @param request request + * @return rows + */ + List getSystemMessageList(SystemMessageQueryRequest request); + + /** + * 查询系统消息数量 + * + * @param queryUnread queryUnread + * @return rows + */ + Map getSystemMessageCount(Boolean queryUnread); + + /** + * 查询是否有未读消息 + * + * @return has + */ + Boolean checkHasUnreadMessage(); + + /** + * 更新系统消息为已读 + * + * @param id id + * @return effect + */ + Integer readSystemMessage(Long id); + + /** + * 更新全部系统消息为已读 + * + * @param classify classify + * @return effect + */ + Integer readAllSystemMessage(String classify); + + /** + * 删除系统消息 + * + * @param id id + * @return effect + */ + Integer deleteSystemMessageById(Long id); + + /** + * 清理已读的系统消息 + * + * @param classify classify + * @return effect + */ + Integer clearSystemMessage(String classify); + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/SystemMessageServiceImpl.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/SystemMessageServiceImpl.java new file mode 100644 index 00000000..d1fa51c4 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/SystemMessageServiceImpl.java @@ -0,0 +1,165 @@ +package com.orion.ops.module.infra.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.orion.lang.function.Functions; +import com.orion.lang.utils.Booleans; +import com.orion.ops.framework.common.constant.Const; +import com.orion.ops.framework.security.core.utils.SecurityUtils; +import com.orion.ops.module.infra.convert.SystemMessageConvert; +import com.orion.ops.module.infra.dao.SystemMessageDAO; +import com.orion.ops.module.infra.dao.SystemUserDAO; +import com.orion.ops.module.infra.entity.domain.SystemMessageDO; +import com.orion.ops.module.infra.entity.domain.SystemUserDO; +import com.orion.ops.module.infra.entity.dto.SystemMessageCountDTO; +import com.orion.ops.module.infra.entity.request.message.SystemMessageCreateRequest; +import com.orion.ops.module.infra.entity.request.message.SystemMessageQueryRequest; +import com.orion.ops.module.infra.entity.vo.SystemMessageVO; +import com.orion.ops.module.infra.enums.MessageStatusEnum; +import com.orion.ops.module.infra.service.SystemMessageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * 系统消息 服务实现类 + * + * @author Jiahang Li + * @version 1.0.8 + * @since 2024-5-11 16:29 + */ +@Slf4j +@Service +public class SystemMessageServiceImpl implements SystemMessageService { + + @Resource + private SystemMessageDAO systemMessageDAO; + + @Resource + private SystemUserDAO systemUserDAO; + + @Override + public Long createSystemMessage(SystemMessageCreateRequest request) { + // 设置接收人用户名 + if (request.getReceiverUsername() == null) { + Optional.ofNullable(request.getReceiverId()) + .map(systemUserDAO::selectById) + .map(SystemUserDO::getUsername) + .ifPresent(request::setReceiverUsername); + } + // 转换 + SystemMessageDO record = SystemMessageConvert.MAPPER.to(request); + record.setStatus(MessageStatusEnum.UNREAD.getStatus()); + // 插入 + int effect = systemMessageDAO.insert(record); + Long id = record.getId(); + log.info("SystemMessageService-createSystemMessage id: {}, effect: {}", id, effect); + return id; + } + + @Override + public List getSystemMessageList(SystemMessageQueryRequest request) { + Long userId = SecurityUtils.getLoginUserId(); + Integer status = Booleans.isTrue(request.getQueryUnread()) ? MessageStatusEnum.UNREAD.getStatus() : null; + // 查询列表 + return systemMessageDAO.of() + .createValidateWrapper() + .eq(SystemMessageDO::getReceiverId, userId) + .eq(SystemMessageDO::getClassify, request.getClassify()) + .lt(SystemMessageDO::getId, request.getMaxId()) + .eq(SystemMessageDO::getStatus, status) + .last(Const.LIMIT + Const.SPACE + request.getLimit()) + .orderByDesc(SystemMessageDO::getId) + .then() + .list(SystemMessageConvert.MAPPER::to); + } + + @Override + public Map getSystemMessageCount(Boolean queryUnread) { + Long userId = SecurityUtils.getLoginUserId(); + Integer status = queryUnread ? MessageStatusEnum.UNREAD.getStatus() : null; + // 查询数量 + List countList = systemMessageDAO.selectSystemMessageCount(userId, status); + // 返回 + return countList.stream() + .collect(Collectors.toMap(SystemMessageCountDTO::getClassify, + SystemMessageCountDTO::getCount, + Functions.right())); + } + + @Override + public Boolean checkHasUnreadMessage() { + // 查询 + return systemMessageDAO.of() + .createWrapper() + .select(SystemMessageDO::getId) + .eq(SystemMessageDO::getReceiverId, SecurityUtils.getLoginUserId()) + .eq(SystemMessageDO::getStatus, MessageStatusEnum.UNREAD.getStatus()) + .then() + .only() + .optional() + .isPresent(); + } + + @Override + public Integer readSystemMessage(Long id) { + Long userId = SecurityUtils.getLoginUserId(); + log.info("SystemMessageService-readSystemMessage id: {}, userId: {}", id, userId); + // 修改状态 + SystemMessageDO update = new SystemMessageDO(); + update.setStatus(MessageStatusEnum.READ.getStatus()); + LambdaQueryWrapper wrapper = systemMessageDAO.wrapper() + .eq(SystemMessageDO::getId, id) + .eq(SystemMessageDO::getReceiverId, userId); + int effect = systemMessageDAO.update(update, wrapper); + log.info("SystemMessageService-readSystemMessage id: {}, effect: {}", id, effect); + return effect; + } + + @Override + public Integer readAllSystemMessage(String classify) { + Long userId = SecurityUtils.getLoginUserId(); + log.info("SystemMessageService-readAllSystemMessage classify: {}, userId: {}", classify, userId); + // 修改状态 + SystemMessageDO update = new SystemMessageDO(); + update.setStatus(MessageStatusEnum.READ.getStatus()); + LambdaQueryWrapper wrapper = systemMessageDAO.wrapper() + .eq(SystemMessageDO::getReceiverId, userId) + .eq(SystemMessageDO::getClassify, classify) + .eq(SystemMessageDO::getStatus, MessageStatusEnum.UNREAD.getStatus()); + int effect = systemMessageDAO.update(update, wrapper); + log.info("SystemMessageService-readAllSystemMessage classify: {}, effect: {}", classify, effect); + return effect; + } + + @Override + public Integer deleteSystemMessageById(Long id) { + log.info("SystemMessageService-deleteSystemMessageById id: {}", id); + // 删除 + LambdaQueryWrapper wrapper = systemMessageDAO.wrapper() + .eq(SystemMessageDO::getId, id) + .eq(SystemMessageDO::getReceiverId, SecurityUtils.getLoginUserId()); + int effect = systemMessageDAO.delete(wrapper); + log.info("SystemMessageService-deleteSystemMessageById id: {}, effect: {}", id, effect); + return effect; + } + + @Override + public Integer clearSystemMessage(String classify) { + Long userId = SecurityUtils.getLoginUserId(); + log.info("SystemMessageService-clearSystemMessage classify: {}, userId: {}", classify, userId); + // 删除 + LambdaQueryWrapper wrapper = systemMessageDAO.wrapper() + .eq(SystemMessageDO::getReceiverId, userId) + .eq(SystemMessageDO::getClassify, classify) + .eq(SystemMessageDO::getStatus, MessageStatusEnum.READ.getStatus()); + int effect = systemMessageDAO.delete(wrapper); + log.info("SystemMessageService-clearSystemMessage classify: {}, effect: {}", classify, effect); + return effect; + } + +} diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/resources/mapper/SystemMessageMapper.xml b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/resources/mapper/SystemMessageMapper.xml new file mode 100644 index 00000000..2c3e9098 --- /dev/null +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/resources/mapper/SystemMessageMapper.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + id, classify, type, status, rel_key, title, content, receiver_id, receiver_username, create_time, update_time, deleted + + + + + + diff --git a/orion-ops-ui/.env.development b/orion-ops-ui/.env.development index 01433b12..8baf6503 100644 --- a/orion-ops-ui/.env.development +++ b/orion-ops-ui/.env.development @@ -1,4 +1,4 @@ VITE_API_BASE_URL= 'http://127.0.0.1:9200/orion/api' VITE_WS_BASE_URL= 'ws://127.0.0.1:9200/orion/keep-alive' -VITE_APP_VERSION= '1.0.7' +VITE_APP_VERSION= '1.0.8' VITE_SFTP_PREVIEW_MB= 2 diff --git a/orion-ops-ui/.env.production b/orion-ops-ui/.env.production index d324128c..58105ca7 100644 --- a/orion-ops-ui/.env.production +++ b/orion-ops-ui/.env.production @@ -1,4 +1,4 @@ VITE_API_BASE_URL= '/orion/api' VITE_WS_BASE_URL= '/orion/keep-alive' -VITE_APP_VERSION= '1.0.7' +VITE_APP_VERSION= '1.0.8' VITE_SFTP_PREVIEW_MB= 2 diff --git a/orion-ops-ui/package.json b/orion-ops-ui/package.json index b908221b..7f16e257 100644 --- a/orion-ops-ui/package.json +++ b/orion-ops-ui/package.json @@ -1,7 +1,7 @@ { "name": "orion-ops-pro-ui", "description": "Orion Ops Pro for Vue", - "version": "1.0.7", + "version": "1.0.8", "private": true, "author": "Jiahang Li", "license": "Apache 2.0",