- 新增异步任务线程池配置,支持项目初始化异步执行 - 定义异步任务状态枚举,统一管理任务生命周期状态 - 实现通用SSE通道管理器,支持用户绑定及多业务消息推送 - 创建统一SSE消息结构,支持多业务类型及事件分类 - 提供基础SSE连接管理接口,支持连接建立、状态查询及关闭 - 提供项目初始化异步任务服务接口及实现,支持进度回调和任务取消 - 添加项目初始化异步预览任务接口,支持异步提交、状态查询、结果获取及取消 - 新增项目初始化任务SSE接口,实现任务异步提交与实时进度推送 - 设计前端SSE集成文档,详细说明SSE连接、消息格式和对接步骤 - 添加Spring工具类,方便非Spring管理类获取Bean实例 - 优化项目控制器,整合异步任务相关API接口支持异步项目初始化工作流
77 lines
1.6 KiB
Java
77 lines
1.6 KiB
Java
package cn.yinlihupo.common.sse;
|
||
|
||
import lombok.Builder;
|
||
import lombok.Data;
|
||
|
||
import java.time.LocalDateTime;
|
||
|
||
/**
|
||
* SSE 消息包装类
|
||
* 统一的消息格式,支持多业务类型
|
||
*/
|
||
@Data
|
||
@Builder
|
||
public class SseMessage {
|
||
|
||
/**
|
||
* 消息类型
|
||
* 例如:project-init、system-notification、task-notification 等
|
||
*/
|
||
private String type;
|
||
|
||
/**
|
||
* 事件名称
|
||
* 例如:submitted、progress、complete、error 等
|
||
*/
|
||
private String event;
|
||
|
||
/**
|
||
* 用户ID
|
||
*/
|
||
private String userId;
|
||
|
||
/**
|
||
* 业务数据
|
||
*/
|
||
private Object data;
|
||
|
||
/**
|
||
* 消息时间戳
|
||
*/
|
||
private LocalDateTime timestamp;
|
||
|
||
/**
|
||
* 创建消息
|
||
*/
|
||
public static SseMessage of(String type, String event, String userId, Object data) {
|
||
return SseMessage.builder()
|
||
.type(type)
|
||
.event(event)
|
||
.userId(userId)
|
||
.data(data)
|
||
.timestamp(LocalDateTime.now())
|
||
.build();
|
||
}
|
||
|
||
/**
|
||
* 创建项目初始化消息
|
||
*/
|
||
public static SseMessage projectInit(String event, String userId, Object data) {
|
||
return of("project-init", event, userId, data);
|
||
}
|
||
|
||
/**
|
||
* 创建系统通知消息
|
||
*/
|
||
public static SseMessage systemNotify(String event, String userId, Object data) {
|
||
return of("system-notification", event, userId, data);
|
||
}
|
||
|
||
/**
|
||
* 创建任务通知消息
|
||
*/
|
||
public static SseMessage taskNotify(String event, String userId, Object data) {
|
||
return of("task-notification", event, userId, data);
|
||
}
|
||
}
|