feat: AGV三段链安全机制、补料/损耗/下班闭环、接驳台左右互换
AGV 调度: - 任务重构为 GO_LOAD/TRANSPORT/EMPTY_RETURN/FREE 三段链,到位即停(ARRIVED)需人工确认装卸 - 自由调度单点步进,每段强制弹"请确保路径畅通无杂物";托盘回收独立工作台 - 接驳台 PLC 传感器检测到托盘即自动卸货放行,传感器故障由人工按钮兜底(无轮询) - 车辆状态只读展示(海康3.1.7 queryAgvStatus),调度仍由 RCS 负责 物料闭环: - 补料管理(SHORTAGE):工位申请 + 主管审批调增叫料池额度,与借料/差异补发三轨并行 - 损耗台账(loss_ledger):退料实际 < 理论必填原因、后审核,工单不记损耗 - 退料强制指定左/右接驳台,WMS 库管可代工位退料 下班闭环: - 工位终端自检接驳台剩余物料后下班;库管收货 + 托盘拉走后事件驱动自动结班 - 退出登录未下班仅作安全提示(不强制拦截、不新增责任审批) 接驳台左右按操作员朝向建模(dock.side 字段),废除"奇左偶右"隐式约定; 看板标签 / seed / 迁移补丁 / 布局文档统一为中文左/右。 产线布局说明:C1 前线头 AGV 点、C15 后线尾 AGV 点、外部 O1/O2/O3 散点, 清理修订痕迹为最终态描述。
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"bj_power_workstation/internal/mes"
|
||||
"bj_power_workstation/internal/svc"
|
||||
@@ -242,3 +243,73 @@ func tempStoreHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
ok(w, map[string]any{"queued": false})
|
||||
}
|
||||
}
|
||||
|
||||
// scrapHandler POST /api/report/scrap
|
||||
// {sn, reason, operator} → 调 MES /api/internal/workpiece/scrap(工件报废/人工取走,2026-11-03 补全)。
|
||||
// 与「暂存退库」语义互斥:报废=永久退出产线(SCRAPPED),退库=合法暂停(SEMI_STORED)可重上线。
|
||||
// 故意不做离线排队:报废是一次性状态变更,MES 端按当前状态强校验(已报废再报会被拒),
|
||||
// 离线重发必然失败徒增噪声——MES 不可达时直接提示现场重试。
|
||||
func scrapHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
Sn string `json:"sn"`
|
||||
Reason string `json:"reason"`
|
||||
Operator string `json:"operator"`
|
||||
}
|
||||
if err := parseJSON(r, &req); err != nil {
|
||||
fail(w, http.StatusBadRequest, "参数错误")
|
||||
return
|
||||
}
|
||||
if req.Sn == "" {
|
||||
fail(w, http.StatusBadRequest, "缺少 sn")
|
||||
return
|
||||
}
|
||||
if req.Reason == "" {
|
||||
fail(w, http.StatusBadRequest, "报废/取走原因必填")
|
||||
return
|
||||
}
|
||||
// 操作人取工位登录态可信身份(防冒名),与暂存退库同口径
|
||||
op := req.Operator
|
||||
if ss, sErr := ctx.Store.GetStationSession(); sErr == nil && ss != nil && ss.Name != "" {
|
||||
op = ss.Name
|
||||
}
|
||||
body := map[string]any{"sn": req.Sn, "reason": req.Reason}
|
||||
payloadBytes, _ := json.Marshal(body)
|
||||
respBody, _, err := ctx.Mes.Post("/api/internal/workpiece/scrap?operator="+url.QueryEscape(op), json.RawMessage(payloadBytes))
|
||||
if err != nil {
|
||||
var bizErr *mes.BizError
|
||||
if errors.As(err, &bizErr) {
|
||||
msg := mesRespCode(bizErr.Body)
|
||||
if msg == "" {
|
||||
msg = bizErr.Error()
|
||||
}
|
||||
fail(w, http.StatusConflict, msg)
|
||||
return
|
||||
}
|
||||
ctx.Store.AddEventLog("", op, "scrap_failed",
|
||||
"报废登记失败(MES不可达) sn="+req.Sn)
|
||||
fail(w, http.StatusBadGateway, "MES 不可达,报废未登记,请稍后重试(不要重复提交)")
|
||||
return
|
||||
}
|
||||
if msg := mesRespCode(respBody); msg != "" {
|
||||
fail(w, http.StatusConflict, msg)
|
||||
return
|
||||
}
|
||||
ctx.Store.AddEventLog("", op, "workpiece_scrap",
|
||||
"工件报废/人工取走 sn="+req.Sn+" 原因="+req.Reason)
|
||||
ok(w, map[string]any{"ok": true})
|
||||
}
|
||||
}
|
||||
|
||||
// mesConfigHandler GET /api/mes-config 代理 MES 公开配置快照(拧紧手填开关 / 缓存策略 / AGV 超时等),
|
||||
// 供工位终端前端按配置显隐或约束交互(2026-11-03 拍板:拧紧禁止手填时输入框置灰,只能由枪自动采集)。
|
||||
func mesConfigHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
b, _, err := ctx.Mes.Get("/api/internal/public-config", nil)
|
||||
if err != nil {
|
||||
fail(w, http.StatusBadGateway, "MES 不可达,配置获取失败")
|
||||
return
|
||||
}
|
||||
ok(w, json.RawMessage(b))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,8 @@ func RegisterHandlers(server *rest.Server, ctx *svc.ServiceContext) {
|
||||
{Method: http.MethodPost, Path: "/api/tightening/consume", Handler: tighteningConsumeHandler(ctx)},
|
||||
{Method: http.MethodPost, Path: "/api/report/process-done", Handler: processDoneHandler(ctx)},
|
||||
{Method: http.MethodPost, Path: "/api/report/temp-store", Handler: tempStoreHandler(ctx)},
|
||||
// 工件报废/人工取走(2026-11-03 补全):与暂存退库语义互斥,原因必填,不做离线排队
|
||||
{Method: http.MethodPost, Path: "/api/report/scrap", Handler: scrapHandler(ctx)},
|
||||
{Method: http.MethodPost, Path: "/api/station/logout", Handler: logoutHandler(ctx)},
|
||||
{Method: http.MethodPost, Path: "/api/sync/flush", Handler: syncFlushHandler(ctx)},
|
||||
{Method: http.MethodGet, Path: "/api/sync/stats", Handler: syncStatsHandler(ctx)},
|
||||
@@ -74,6 +76,9 @@ func RegisterHandlers(server *rest.Server, ctx *svc.ServiceContext) {
|
||||
{Method: http.MethodPost, Path: "/api/emergency/call", Handler: emergencyCallHandler(ctx)},
|
||||
{Method: http.MethodPost, Path: "/api/qty-report", Handler: qtyReportHandler(ctx)},
|
||||
{Method: http.MethodPost, Path: "/api/return-material", Handler: returnMaterialHandler(ctx)},
|
||||
// 下班/结束作业闭环(2026-11-03):查询班次(退出提示)+ 下班提交(自检接驳台剩余物料)
|
||||
{Method: http.MethodGet, Path: "/api/shift", Handler: shiftGetHandler(ctx)},
|
||||
{Method: http.MethodPost, Path: "/api/off-duty", Handler: offDutyHandler(ctx)},
|
||||
{Method: http.MethodPost, Path: "/api/inspection/upload", Handler: inspectionUploadHandler(ctx)},
|
||||
|
||||
// 在制品 / 0-13 上下线建档完工 / 物料清单领料 / 追溯(代理 MES 内部 API)
|
||||
@@ -89,6 +94,9 @@ func RegisterHandlers(server *rest.Server, ctx *svc.ServiceContext) {
|
||||
|
||||
// PLC↔MES 对账(#8 T2/T3 终端事件驱动检查,不轮询):代理 MES 内部接口,MES 不可达静默跳过
|
||||
{Method: http.MethodPost, Path: "/api/plc/mismatch/check", Handler: plcMismatchCheckHandler(ctx)},
|
||||
},
|
||||
|
||||
// 2026-11-03 拍板:MES 公开配置快照(拧紧手填开关/缓存策略/AGV 超时),终端按配置显隐交互
|
||||
{Method: http.MethodGet, Path: "/api/mes-config", Handler: mesConfigHandler(ctx)},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"bj_power_workstation/internal/svc"
|
||||
)
|
||||
@@ -112,6 +113,42 @@ func returnMaterialHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// shiftGetHandler GET /api/shift —— 当前班次状态(退出登录前提示「未下班」用,2026-11-03 下班闭环)。
|
||||
func shiftGetHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
stationNo := stationNoFromRequest(ctx)
|
||||
resp, _, perr := ctx.Mes.Get("/api/internal/station/shift?stationNo="+strconv.Itoa(stationNo), nil)
|
||||
mesJSON(w, resp, perr)
|
||||
}
|
||||
}
|
||||
|
||||
// offDutyHandler POST /api/off-duty —— 下班/结束作业(工人自检接驳台剩余物料后提交)。
|
||||
// {hasLeftover, items[]}:确认无剩余直接下班;有剩余走退料流程(指定接驳台/实际量/损耗原因)后离场。
|
||||
func offDutyHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
payload, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
fail(w, http.StatusBadRequest, "请求体读取失败")
|
||||
return
|
||||
}
|
||||
var req map[string]any
|
||||
if err := json.Unmarshal(payload, &req); err != nil {
|
||||
fail(w, http.StatusBadRequest, "请求体解析失败")
|
||||
return
|
||||
}
|
||||
req["stationNo"] = stationNoFromRequest(ctx)
|
||||
injectOperator(req, r)
|
||||
body, _ := json.Marshal(req)
|
||||
resp, _, perr := ctx.Mes.Post("/api/internal/station/off-duty", json.RawMessage(body))
|
||||
mesJSON(w, resp, perr)
|
||||
}
|
||||
}
|
||||
|
||||
// stationNoFromRequest 固定工位号(与 /api/config 同源:workstation 配置)。
|
||||
func stationNoFromRequest(ctx *svc.ServiceContext) int {
|
||||
return ctx.Config.Station.StationNo
|
||||
}
|
||||
|
||||
// inspectionUploadHandler POST /api/inspection/upload(巡检拍照 base64 上传,代理 MES 内部接口)
|
||||
// 请求体:{filename, data(base64)}
|
||||
func inspectionUploadHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
|
||||
@@ -89,6 +89,8 @@ func tighteningRecordHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
if ss != nil {
|
||||
opID = ss.UserID
|
||||
}
|
||||
// 拧紧域工位标签载体(自洽闭环):写入 DOCK%02d、syncer 上报前同公式反推工位号——
|
||||
// 与接驳台 dock 表编码无关,接驳台左右互换(side 字段)不影响本数据流。
|
||||
dockCode := fmt.Sprintf("DOCK%02d", ctx.Config.Station.StationNo)
|
||||
id, err := ctx.Store.InsertTorqueResult(store.TorqueResult{
|
||||
WorkOrderNo: req.WorkOrderNo,
|
||||
|
||||
Reference in New Issue
Block a user