Files
bj_power/bj_power_mes/internal/eventbus/bus.go
T
SunYF 450a094f0e feat: 装配线看板修正、统一密钥Hardman_2026、操作日志追溯、日志按天存储
Dashboard 移除 CNC/清洗机等不存在设备,改为纯装配线看板(扫码枪+拧紧枪+人工);JWT/内部token统一为 Hardman_2026 写入各 etc/*.yaml,MES 建表 DSN 改读 yaml;event_log 增加 workOrderNo/operator,BOM/备料/PLC下发/拧紧/扫码报工/半成品/AGV 全链路埋点,日志页支持工单号/操作人筛选;MES/WMS 日志按天存储(dailyWriter),WMS SetWriter 用 logx.NewWriter 适配
2026-08-28 09:22:19 +08:00

111 lines
3.3 KiB
Go

package eventbus
import (
"context"
"time"
)
// EventType 事件类型
type EventType string
const (
// 生产事件
EventLoad EventType = "LOAD"
EventUnload EventType = "UNLOAD"
EventExchange EventType = "EXCHANGE"
EventScan EventType = "SCAN"
EventMark EventType = "MARK"
EventReplenish EventType = "REPLENISH"
EventMachineStart EventType = "MACHINE_START"
EventMachineDone EventType = "MACHINE_DONE"
EventInspectionResult EventType = "INSPECTION_RESULT"
EventJobCompleted EventType = "JOB_COMPLETED"
EventJobScrapped EventType = "JOB_SCRAPPED"
EventJobDischarged EventType = "JOB_DISCHARGED"
// 工单生命周期事件
EventOrderStarted EventType = "ORDER_STARTED"
EventOrderPaused EventType = "ORDER_PAUSED"
EventOrderResumed EventType = "ORDER_RESUMED"
EventOrderCancelled EventType = "ORDER_CANCELLED"
EventOrderCompleted EventType = "ORDER_COMPLETED"
// 托盘生命周期事件
EventPalletCompleted EventType = "PALLET_COMPLETED"
// MOM 对接事件
EventMomReportSuccess EventType = "MOM_REPORT_SUCCESS"
EventMomReportFailure EventType = "MOM_REPORT_FAILURE"
EventMomAgvRequest EventType = "MOM_AGV_ENTRY_REQUESTED"
EventTempSlotChanged EventType = "TEMP_SLOT_CHANGED"
// 报警事件
EventAlarmRaised EventType = "ALARM_RAISED"
EventAlarmAcked EventType = "ALARM_ACKED"
// 人工交互事件
EventManualActionCreated EventType = "MANUAL_ACTION_CREATED"
EventManualActionResolved EventType = "MANUAL_ACTION_RESOLVED"
// 设备事件
EventEquipmentAvailabilityChanged EventType = "EQUIPMENT_AVAILABILITY_CHANGED"
// 连接状态事件
EventConnectionStatusUpdated EventType = "CONNECTION_STATUS_UPDATED"
// 装配线操作日志事件(工单/工件/操作步骤/人员可追溯)
EventBomSaved EventType = "BOM_SAVED"
EventMaterialRequested EventType = "MATERIAL_REQUESTED"
EventPlcProcessSent EventType = "PLC_PROCESS_SENT"
EventTorqueReported EventType = "TORQUE_REPORTED"
EventScanReported EventType = "SCAN_REPORTED"
EventSemiFlow EventType = "SEMI_FLOW"
EventAgvTaskCreated EventType = "AGV_TASK_CREATED"
EventAll EventType = "*"
)
// EntityType 实体类型
type EntityType string
const (
EntityJob EntityType = "job"
EntityTempSlot EntityType = "temp_slot"
)
// Event 事件
type Event struct {
ID string `json:"id"`
Type EventType `json:"type"`
Source string `json:"source"`
EntityType string `json:"entityType,omitempty"`
EntityID string `json:"entityId,omitempty"`
EntityVersion int64 `json:"entityVersion,omitempty"`
Timestamp time.Time `json:"timestamp"`
Payload map[string]any `json:"payload"`
}
// EventHandler 事件处理器
type EventHandler func(ctx context.Context, event Event) error
// Subscription 事件订阅
type Subscription interface {
Unsubscribe()
}
// Bus 事件总线接口
type Bus interface {
Publish(ctx context.Context, event Event) error
Subscribe(eventType EventType, handler EventHandler) Subscription
SubscribeAll(handler EventHandler) Subscription
Start(ctx context.Context) error
Stop() error
Close() error
}
type handlerEntry struct {
id uint64
handler EventHandler
}