重构排产/叫料配送/时钟/终端事件驱动,清理 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:
@@ -127,7 +127,7 @@ func permissionGuard(svcCtx *svc.ServiceContext) func(http.HandlerFunc) http.Han
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
code, ok := pathPerm(r.Method, r.URL.Path)
|
||||
if ok && !userHasPerm(r, svcCtx, code) {
|
||||
httpx.FailHTTP(w, http.StatusForbidden, "无操作权限:"+code)
|
||||
httpx.FailHTTP(w, http.StatusForbidden, "无操作权限:"+code+";请找管理员在角色管理开通")
|
||||
return
|
||||
}
|
||||
next(w, r)
|
||||
|
||||
@@ -122,27 +122,6 @@ func AgvModeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// DispatchCallInternalHandler POST /api/internal/agv/dispatch-call body {requestNo, operator}
|
||||
// 库管人工派车(2026-11-03 定论:废除备料完成自动派车)——WMS 叫料队列点「送货」→ 下发空车去程段。
|
||||
func DispatchCallInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
RequestNo string `json:"requestNo"`
|
||||
Operator string `json:"operator"`
|
||||
}
|
||||
_ = json.NewDecoder(r.Body).Decode(&req)
|
||||
if req.RequestNo == "" {
|
||||
httpx.Fail(w, 3309, "requestNo 必填")
|
||||
return
|
||||
}
|
||||
if err := logic.New(svcCtx).DispatchCallAgv(r.Context(), req.RequestNo, req.Operator); err != nil {
|
||||
httpx.Fail(w, 3309, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{"ok": true})
|
||||
}
|
||||
}
|
||||
|
||||
// ListAgvPointsHandler GET /agv/points?enabledOnly=1 列出 AGV 点位(启停用管理 / 派车下拉)。
|
||||
func ListAgvPointsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -114,6 +114,20 @@ func ListAlertsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// BellCountHandler GET /alerts/bell-count 顶栏铃铛未读数(2026-11-25 拍板:铃铛与待办分家)。
|
||||
// 只统计「消息通知类」白名单类型(logic.MessageAlertTypes)的 UNREAD 数;
|
||||
// 业务待办/需处置异常不进铃铛,走左侧「异常告警」菜单角标(produce.alert,全类型未处置数)。
|
||||
func BellCountHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
n, err := logic.New(svcCtx).UnreadMessageAlertCount(r.Context())
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3306, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{"count": n})
|
||||
}
|
||||
}
|
||||
|
||||
// StationAlertsInternalHandler GET /api/internal/station/alerts?stationNo=&minutes=
|
||||
// 工位终端「本工位相关报警」查询(谁受影响谁播报,2026-10-20):工位终端后端代理调用,
|
||||
// X-API-TOKEN 保护。返回最近 minutes 分钟内 UNREAD 且命中「工位N」的报警列表。
|
||||
|
||||
@@ -79,7 +79,27 @@ func CancelCallHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// SignCallHandler POST /api/internal/call/sign 签收(仅已发货;签收=确认收到,系统不再对差异)。
|
||||
// MarkDeliveredHandler POST /api/internal/call/mark-delivered
|
||||
// 货到工位回写(WMS 配送单送达时反查明细调本接口):把 PREPARED → DELIVERED(待签收)。
|
||||
func MarkDeliveredHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
RequestNos []string `json:"requestNos"`
|
||||
Operator string `json:"operator"`
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &req); err != nil || len(req.RequestNos) == 0 {
|
||||
httpx.BadRequest(w, "缺少叫料单号列表")
|
||||
return
|
||||
}
|
||||
if err := logic.New(svcCtx).MarkCallsDelivered(r.Context(), req.RequestNos, req.Operator); err != nil {
|
||||
httpx.Fail(w, 3206, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.OkMessage(w, "已标记待签收", nil)
|
||||
}
|
||||
}
|
||||
|
||||
// SignCallHandler POST /api/internal/call/sign 签收(仅待签收;签收=确认收到,系统不再对差异)。
|
||||
func SignCallHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
@@ -98,7 +118,7 @@ func SignCallHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// ReturnCallHandler POST /api/internal/call/return 申请退库(仅已发货/签收前;整单退)。
|
||||
// ReturnCallHandler POST /api/internal/call/return 申请退库(仅已备料/签收前;整单退)。
|
||||
func ReturnCallHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
@@ -118,7 +138,7 @@ func ReturnCallHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
|
||||
// CompleteCallHandler POST /api/internal/call/complete 仓库完成备料通知(WMS 本地扣库存后调用):
|
||||
// PENDING → SHIPPED,记实发量与 WMS 出库单号;占用释放、池子已发累加。
|
||||
// PENDING → PREPARED,记实发量与 WMS 出库单号;占用释放、池子已发累加。
|
||||
func CompleteCallHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
|
||||
@@ -37,24 +37,6 @@ func CallPlanDetailInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
|
||||
}
|
||||
}
|
||||
|
||||
// CallPackageInternalHandler GET /api/internal/call/package?packageNo=
|
||||
// 按包查叫料单(WMS 建配送单数据源;含工单×排产明细 planBreakdown、出库单号)。
|
||||
func CallPackageInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
pkg := r.URL.Query().Get("packageNo")
|
||||
if pkg == "" {
|
||||
httpx.BadRequest(w, "缺少包号")
|
||||
return
|
||||
}
|
||||
rows, err := logic.New(svcCtx).ListMaterialRequestsByPackage(r.Context(), pkg)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3231, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, rows)
|
||||
}
|
||||
}
|
||||
|
||||
// StationDockPalletsInternalHandler GET /api/internal/dock/station-pallets?stationNo=
|
||||
// 按工位批量读左右接驳台实时传感器(叫料空台校验/下班校验共用;PLC 不可达回退台账并标 plcOk=false)。
|
||||
func StationDockPalletsInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
|
||||
@@ -89,8 +89,18 @@ func ListCallsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
func ListCallsInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
q := r.URL.Query()
|
||||
// 2026-11-26:statuses=PENDING,PREPARED 一次查两个状态;空则退回单值 status,兼容既有调用方。
|
||||
var statuses []string
|
||||
if raw := strings.TrimSpace(q.Get("statuses")); raw != "" {
|
||||
for _, s := range strings.Split(raw, ",") {
|
||||
if s = strings.TrimSpace(s); s != "" {
|
||||
statuses = append(statuses, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
data, err := logic.New(svcCtx).ListCalls(r.Context(), logic.CallQuery{
|
||||
Status: q.Get("status"),
|
||||
Statuses: statuses,
|
||||
MaterialCode: q.Get("materialCode"),
|
||||
StationNo: q.Get("stationNo"),
|
||||
Source: q.Get("source"),
|
||||
|
||||
@@ -9,10 +9,18 @@ import (
|
||||
)
|
||||
|
||||
// StationAlertsStreamHandler GET /api/internal/station/alerts/stream(X-API-TOKEN 保护)
|
||||
// 工位终端「本工位相关报警」SSE 推送端点(谁受影响谁播报,2026-10-20 轮询改事件驱动):
|
||||
// 复用全局 SSE Hub(与看板快照同一广播中心),仅下发 station.alert 事件类型,其余事件(dashboard.*)不透传;
|
||||
// 工位终端「本工位相关事件」SSE 推送端点(谁受影响谁播报,2026-10-20 轮询改事件驱动;
|
||||
// 2026-11-25 扩展为工位事件流:报警 + 工件到位 + 点位变化 + 停单状态,终端页面零轮询):
|
||||
// 复用全局 SSE Hub(与看板快照同一广播中心),仅下发 station.* 事件类型,其余事件(dashboard.*)不透传;
|
||||
// 每 15 秒写一行 SSE 注释心跳(": ping")防中间设备掐空闲长连接;客户端断开由 r.Context().Done() 感知。
|
||||
// 报警 JSON 全量下发、按「工位N」过滤由终端后端做(Hub 广播语义,唯一消费者=终端后端,无需 MES 逐连接过滤)。
|
||||
var stationEventTypes = map[string]bool{
|
||||
"station.alert": true, // 报警(2026-10-20 原有)
|
||||
"station.workpiece": true, // 工件到位落实(2026-11-25)
|
||||
"station.points": true, // 点位台账占位/释放(2026-11-25)
|
||||
"station.state": true, // 停单/恢复接单(2026-11-25)
|
||||
}
|
||||
|
||||
func StationAlertsStreamHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
fl, ok := w.(http.Flusher)
|
||||
@@ -32,7 +40,7 @@ func StationAlertsStreamHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
for {
|
||||
select {
|
||||
case m := <-ch:
|
||||
if m.Type != "station.alert" {
|
||||
if !stationEventTypes[m.Type] {
|
||||
continue
|
||||
}
|
||||
if _, err := fmt.Fprintf(w, "event: %s\ndata: %s\n\n", m.Type, m.Data); err != nil {
|
||||
|
||||
@@ -587,7 +587,7 @@ func ForceCompletePreviewHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
|
||||
// ForceCompleteHandler POST /work-orders/force-complete {id, reason}
|
||||
// 强制完工(方案 A,2026-10-20 拍板):在制工件>0 拒绝;未完成排产自动 CANCELLED;
|
||||
// PENDING 叫料自动取消;SHIPPED 列出人工处理;原因必填;落 event_log 四项快照。
|
||||
// PENDING 叫料自动取消;PREPARED 列出人工处理;原因必填;落 event_log 四项快照。
|
||||
func ForceCompleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
|
||||
@@ -189,10 +189,8 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodPost, Path: "/api/internal/agv/pallet-dispatch", Handler: internal(production.PalletDispatchInternalHandler(serverCtx)),
|
||||
})
|
||||
// 库管人工派车(2026-11-03 定论:废除备料完成自动派车,WMS 点「送货」才发车)
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodPost, Path: "/api/internal/agv/dispatch-call", Handler: internal(production.DispatchCallInternalHandler(serverCtx)),
|
||||
})
|
||||
// 2026-11-26 配送链定稿:旧按单派车端点(/api/internal/agv/dispatch-call)已随叫料队列
|
||||
// 「送货」通道一起删除,配送统一走 /api/internal/delivery/dispatch(配送单驱动)。
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodGet, Path: "/api/internal/dock/list", Handler: internal(production.DockListInternalHandler(serverCtx)),
|
||||
})
|
||||
@@ -270,7 +268,8 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
})
|
||||
// 2026-11-05 叫料包/配送单拍板:需求明细(两类提示)、按包查单、工位物料明细
|
||||
server.AddRoute(rest.Route{Method: http.MethodGet, Path: "/api/internal/call/plan-detail", Handler: internal(production.CallPlanDetailInternalHandler(serverCtx))})
|
||||
server.AddRoute(rest.Route{Method: http.MethodGet, Path: "/api/internal/call/package", Handler: internal(production.CallPackageInternalHandler(serverCtx))})
|
||||
// 2026-11-26 按工位凑车定稿:旧按包查叫料单端点(/api/internal/call/package)随配送单
|
||||
// 按包建单一并删除,新建配送单走 PREPARED 全量拉取按工位过滤(/api/internal/material-requests)。
|
||||
server.AddRoute(rest.Route{Method: http.MethodGet, Path: "/api/internal/call/pool-raw", Handler: internal(production.CallPoolRawInternalHandler(serverCtx))})
|
||||
server.AddRoute(rest.Route{Method: http.MethodGet, Path: "/api/internal/call/material-detail", Handler: internal(production.StationMaterialDetailInternalHandler(serverCtx))})
|
||||
// 接驳台实时传感器批量读 / 托盘回库(工位终端)/ 人工清台 / 配送单派车
|
||||
@@ -286,6 +285,9 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodPost, Path: "/api/internal/call/cancel", Handler: internal(production.StationSessionAuth(serverCtx)(production.CancelCallHandler(serverCtx))),
|
||||
})
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodPost, Path: "/api/internal/call/mark-delivered", Handler: internal(production.MarkDeliveredHandler(serverCtx)),
|
||||
})
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodPost, Path: "/api/internal/call/sign", Handler: internal(production.StationSessionAuth(serverCtx)(production.SignCallHandler(serverCtx))),
|
||||
})
|
||||
@@ -527,6 +529,7 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
{Method: http.MethodGet, Path: "/alert-rules", Handler: production.ListAlertRulesAliasHandler(serverCtx)},
|
||||
{Method: http.MethodPut, Path: "/alert-rules/:id", Handler: production.UpdateAlertRulePathHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/alerts", Handler: production.ListAlertsHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/alerts/bell-count", Handler: production.BellCountHandler(serverCtx)},
|
||||
// 处置预警(遗留5):置已读并记录处置人/处置时间;批量端点放参数路由前,避免被 :id 吞掉
|
||||
{Method: http.MethodPost, Path: "/alerts/resolve-all", Handler: production.ResolveAllAlertsHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/alerts/:id/resolve", Handler: production.ResolveAlertHandler(serverCtx)},
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
// CallStatusInternalHandler GET /api/internal/call/status?requestNo=
|
||||
// 供 WMS 同步失败台账重试前判对端终态(已 SHIPPED/DONE 则不再重放通知)。
|
||||
// 供 WMS 同步失败台账重试前判对端终态(已 PREPARED/DONE 则不再重放通知)。
|
||||
func CallStatusInternalHandler(serverCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
requestNo := strings.TrimSpace(r.URL.Query().Get("requestNo"))
|
||||
@@ -67,7 +67,7 @@ func SyncFailureRetryHandler(serverCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
if err := serverCtx.Wms.PostRaw(r.Context(), row.Endpoint, syncfailure.Payload(row)); err != nil {
|
||||
_ = syncfailure.MarkRetryFailed(serverCtx.SQLDB, id, err.Error())
|
||||
httpx.Fail(w, 2104, "重试失败(已计入 retry_count): "+err.Error())
|
||||
httpx.Fail(w, 2104, "重试失败(已计入 retry_count);请先到对端核实是否收到,避免重复处理,确认未收到再重试:"+err.Error())
|
||||
return
|
||||
}
|
||||
_ = syncfailure.MarkSuccess(serverCtx.SQLDB, id)
|
||||
|
||||
Reference in New Issue
Block a user