重构排产/叫料配送/时钟/终端事件驱动,清理 SHIPPED 废弃状态
时钟与 JWT:验签按「谁签发谁的时间为准」,向签发方取 /api/server-time, 对端地址由既有 BaseURL 自动推导;不再要求现场人工 w32tm 对时。 排产 C 方案:工单状态不再回写排产,排产只表示启用开关;启用排产是唯一 开工开关,未启用不允许建档上件;完工/取消后工单进度从工单派生、叫料池 按工单状态重算;逐日手改后合计为准;日期筛选默认空=全部日期。 叫料配送 B 方案:新增 DELIVERED 待签收态,货真到工位才从 PREPARED 转 DELIVERED、工人签收再转 DONE;PREPARED 在途不可签收/退库;叫料队列一屏 显示 PENDING+PREPARED、支持批量完成备料;配送链改按工位凑车,一张配送单 =一个托盘=一个工位,只在配送单页新建,未派车可删可改;新建弹窗直列有货 工位;派车硬门禁要求接驳台传感器检测到托盘;删除改为事务内复核状态、 带 PENDING 条件删单头,防止并发派车时误删。 装配记账:新增已装量 installedQty 与追溯绑定 traceBind,落实「总账=分账 之和」;追溯件绑定/撤销回补、非序列号件报工按单台用量自动扣已装;报工前 按工位×物料核对累计已签收 ≥ 已消耗,不够拦下。 工件与工位终端:建档/重上线增加上料位可达性校验与 PLC 送件、半截补齐防 重复扣库;终端去轮询改事件驱动(报警/工件到位/点位/停单即时推送),铃铛 只挂消息类预警、与待办角标分家;刷新保留拧紧录入;跨服务连线失败不再 误报成数据库故障;新增 BJ_POWER_DEV=1 单进程调试模式(不起守护/托盘)。 告警:新增处置字段 resolved_at/resolved_by,红点=待处置数,确认关闭才消。 清理:删除 migrate 中 SHIPPED→DELIVERED 兼容补丁;场景1测试断言改为 现行 PREPARED / DELIVERED;同步更新案例.md、现场对时操作卡.md 与 ent 生成代码。
This commit is contained in:
@@ -16,30 +16,37 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
// Manager 工位报警事件流(谁受影响谁播报,2026-10-20 轮询改事件驱动;多会话版 2026-11-11):
|
||||
// Manager 工位事件流(谁受影响谁播报,2026-10-20 轮询改事件驱动;多会话版 2026-11-11;
|
||||
// 2026-11-25 扩展为工位事件流:报警+工件到位+点位变化+停单状态,终端页面零轮询):
|
||||
// 后台长连接 MES GET /api/internal/station/alerts/stream(SSE,X-API-TOKEN 鉴权),
|
||||
// 只认 station.alert 事件;按每个前端订阅方自带的工位号过滤「工位N」相关报警后分发
|
||||
// (一台终端实例可同时登录多个虚拟工位,各订阅方只收到自己工位的报警)。
|
||||
// 断线自动重连(3 秒退避);前端断线重连后的一次性补拉走 GET /api/alerts/station(前端自己调)。
|
||||
// 认 station.* 事件;按每个前端订阅方自带的工位号过滤后分发
|
||||
// (一台终端实例可同时登录多个虚拟工位,各订阅方只收到自己工位的事件)。
|
||||
// 断线自动重连(3 秒退避);前端断线重连后的一次性补拉由前端自己做。
|
||||
type Manager struct {
|
||||
mc *mes.Client
|
||||
|
||||
mu sync.Mutex
|
||||
clients map[chan string]int // channel → 订阅方工位号(<=0 表示不过滤,全收)
|
||||
clients map[chan workEvent]int // channel → 订阅方工位号(<=0 表示不过滤,全收)
|
||||
}
|
||||
|
||||
// New 新建报警流管理器(多会话版:不再绑定单一固定工位)。
|
||||
// workEvent 单条工位事件:Type=SSE 事件名(station.alert/station.workpiece/…),Data=JSON 载荷。
|
||||
type workEvent struct {
|
||||
Type string
|
||||
Data string
|
||||
}
|
||||
|
||||
// New 新建工位事件流管理器(多会话版:不再绑定单一固定工位)。
|
||||
func New(mc *mes.Client) *Manager {
|
||||
return &Manager{
|
||||
mc: mc,
|
||||
clients: make(map[chan string]int),
|
||||
clients: make(map[chan workEvent]int),
|
||||
}
|
||||
}
|
||||
|
||||
// Subscribe 本机前端订阅(每个 EventSource 连接一个 channel),stationNo 为订阅方工位号;
|
||||
// <=0 时不按工位过滤(兼容固定工位模式/未知来源),全部转发。
|
||||
func (m *Manager) Subscribe(stationNo int) chan string {
|
||||
ch := make(chan string, 32)
|
||||
func (m *Manager) Subscribe(stationNo int) chan workEvent {
|
||||
ch := make(chan workEvent, 32)
|
||||
m.mu.Lock()
|
||||
m.clients[ch] = stationNo
|
||||
m.mu.Unlock()
|
||||
@@ -47,7 +54,7 @@ func (m *Manager) Subscribe(stationNo int) chan string {
|
||||
}
|
||||
|
||||
// Unsubscribe 取消订阅并关闭 channel。
|
||||
func (m *Manager) Unsubscribe(ch chan string) {
|
||||
func (m *Manager) Unsubscribe(ch chan workEvent) {
|
||||
m.mu.Lock()
|
||||
if _, ok := m.clients[ch]; ok {
|
||||
delete(m.clients, ch)
|
||||
@@ -56,16 +63,33 @@ func (m *Manager) Unsubscribe(ch chan string) {
|
||||
m.mu.Unlock()
|
||||
}
|
||||
|
||||
func (m *Manager) broadcast(data string) {
|
||||
// PublishLocal 本地事件广播(不经 MES):拧紧枪连接状态等本机变化,直接推给前端订阅方。
|
||||
func (m *Manager) PublishLocal(typ, data string) {
|
||||
m.dispatch(typ, data)
|
||||
}
|
||||
|
||||
func (m *Manager) broadcast(ev workEvent) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
for ch, st := range m.clients {
|
||||
if st > 0 && !mentionStation(data, st) {
|
||||
continue // 只推给「工位N」相关订阅方(多会话:一台实例服务多工位互不串音)
|
||||
deliver := true
|
||||
switch ev.Type {
|
||||
case "station.alert":
|
||||
deliver = st <= 0 || mentionStation(ev.Data, st)
|
||||
case "station.workpiece", "station.state":
|
||||
if st > 0 {
|
||||
var p struct {
|
||||
StationNo int `json:"stationNo"`
|
||||
}
|
||||
deliver = json.Unmarshal([]byte(ev.Data), &p) == nil && p.StationNo == st
|
||||
}
|
||||
}
|
||||
if !deliver {
|
||||
continue
|
||||
}
|
||||
select {
|
||||
case ch <- data:
|
||||
default: // 订阅者堆积(前端卡死)直接丢帧,下一条报警自然追上
|
||||
case ch <- ev:
|
||||
default: // 订阅者堆积(前端卡死)直接丢帧,下一事件自然追上
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -132,8 +156,8 @@ func (m *Manager) runOnce(ctx context.Context) error {
|
||||
event = strings.TrimSpace(strings.TrimPrefix(line, "event:"))
|
||||
case strings.HasPrefix(line, "data:"):
|
||||
data := strings.TrimSpace(strings.TrimPrefix(line, "data:"))
|
||||
if event == "station.alert" && data != "" {
|
||||
m.dispatch(data)
|
||||
if mesStationEvents[event] && data != "" {
|
||||
m.dispatch(event, data)
|
||||
}
|
||||
event = ""
|
||||
default:
|
||||
@@ -142,7 +166,26 @@ func (m *Manager) runOnce(ctx context.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
// dispatch 解析 MES 报警事件(station.alert),交给 broadcast 按订阅方工位分发。
|
||||
// mesStationEvents MES 侧下发的工位事件类型白名单(与 MES station_alert_stream.go 同口径)。
|
||||
var mesStationEvents = map[string]bool{
|
||||
"station.alert": true,
|
||||
"station.workpiece": true,
|
||||
"station.points": true,
|
||||
"station.state": true,
|
||||
}
|
||||
|
||||
// dispatch 按事件类型广播(station.alert 先解析校验脏帧,其余类型 JSON 直传由订阅方过滤)。
|
||||
func (m *Manager) dispatch(typ, data string) {
|
||||
if typ == "station.alert" {
|
||||
var a alertPayload
|
||||
if err := json.Unmarshal([]byte(data), &a); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
m.broadcast(workEvent{Type: typ, Data: data})
|
||||
}
|
||||
|
||||
// alertPayload 报警事件载荷(station.alert,2026-10-20 原有结构不变)。
|
||||
type alertPayload struct {
|
||||
ID int `json:"id"`
|
||||
Type string `json:"type"`
|
||||
@@ -151,11 +194,3 @@ type alertPayload struct {
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
func (m *Manager) dispatch(data string) {
|
||||
var a alertPayload
|
||||
if err := json.Unmarshal([]byte(data), &a); err != nil {
|
||||
return
|
||||
}
|
||||
m.broadcast(data)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user