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); } }