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:
@@ -0,0 +1,123 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"bj_power_wms/internal/mesclient"
|
||||
"bj_power_wms/internal/svc"
|
||||
)
|
||||
|
||||
// ============ AGV 三段链 / 托盘工作台(2026-11-03 三层安全机制) ============
|
||||
// 库管在 WMS 侧的 AGV 交互入口:装货确认(叫料队列行内)与托盘回收派车(托盘工作台)。
|
||||
// 所有确认动作都在 MES「到位待令(ARRIVED)」闸门后执行;空车段由 MES 业务自动触发免弹窗。
|
||||
|
||||
// ConfirmCallLoadHandler POST /call/confirm-load {requestNo}
|
||||
// 库管在叫料队列对「到位待令」的空车段点「确认装车并送货」→ MES 生成重载运输段发往工位接驳台。
|
||||
func ConfirmCallLoadHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
RequestNo string `json:"requestNo"`
|
||||
Operator string `json:"operator"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
fail(w, http.StatusBadRequest, "参数错误: "+err.Error())
|
||||
return
|
||||
}
|
||||
if req.RequestNo == "" {
|
||||
fail(w, http.StatusBadRequest, "requestNo 必填")
|
||||
return
|
||||
}
|
||||
op := r.Header.Get("X-Username")
|
||||
if op == "" {
|
||||
op = req.Operator
|
||||
}
|
||||
if err := ctx.Mes.AgvConfirm(r.Context(), req.RequestNo, "load_go", "", op); err != nil {
|
||||
fail(w, http.StatusBadGateway, err.Error())
|
||||
return
|
||||
}
|
||||
ok(w, map[string]any{"ok": true})
|
||||
}
|
||||
}
|
||||
|
||||
// PalletDocksHandler GET /pallet/docks —— 接驳台台账列表(托盘工作台:谁有托盘/空托盘待回收)。
|
||||
func PalletDocksHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
docks, err := ctx.Mes.ListDocks(r.Context())
|
||||
if err != nil {
|
||||
fail(w, http.StatusBadGateway, "MES 不可达: "+err.Error())
|
||||
return
|
||||
}
|
||||
ok(w, map[string]any{"list": dockViews(docks)})
|
||||
}
|
||||
}
|
||||
|
||||
// StationDocksProxyHandler GET /pallet/station-docks?stationNo= —— 某工位两个接驳台(代退料选左/右)。
|
||||
func StationDocksProxyHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
stationNo, _ := strconv.Atoi(r.URL.Query().Get("stationNo"))
|
||||
if stationNo <= 0 {
|
||||
fail(w, http.StatusBadRequest, "stationNo 必填")
|
||||
return
|
||||
}
|
||||
docks, err := ctx.Mes.ListDocks(r.Context())
|
||||
if err != nil {
|
||||
fail(w, http.StatusBadGateway, "MES 不可达: "+err.Error())
|
||||
return
|
||||
}
|
||||
out := []map[string]any{}
|
||||
for _, d := range dockViews(docks) {
|
||||
if d["stationNo"] == stationNo {
|
||||
out = append(out, map[string]any{"code": d["dockCode"], "label": d["label"]})
|
||||
}
|
||||
}
|
||||
ok(w, map[string]any{"docks": out})
|
||||
}
|
||||
}
|
||||
|
||||
// dockViews 统一接驳台视图(含操作员左右中文)。
|
||||
func dockViews(docks []mesclient.DockRow) []map[string]any {
|
||||
out := make([]map[string]any, 0, len(docks))
|
||||
for _, d := range docks {
|
||||
side := "右"
|
||||
if d.Side == "left" {
|
||||
side = "左"
|
||||
}
|
||||
out = append(out, map[string]any{
|
||||
"dockCode": d.DockCode, "name": d.Name, "dockType": d.DockType,
|
||||
"stationNo": d.StationNo, "side": d.Side, "sideCn": side,
|
||||
"label": "工位" + strconv.Itoa(d.StationNo) + " " + side + "(" + d.DockCode + ")",
|
||||
"hasPallet": d.HasPallet, "palletRef": d.PalletRef, "status": d.Status,
|
||||
})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// PalletDispatchHandler POST /pallet/dispatch {dockCode, operator}
|
||||
// 库管派 AGV 回收指定工位接驳台的托盘(空车段免弹窗,到位待令后确认装车)。
|
||||
func PalletDispatchHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
DockCode string `json:"dockCode"`
|
||||
Operator string `json:"operator"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
fail(w, http.StatusBadRequest, "参数错误: "+err.Error())
|
||||
return
|
||||
}
|
||||
if req.DockCode == "" {
|
||||
fail(w, http.StatusBadRequest, "dockCode 必填")
|
||||
return
|
||||
}
|
||||
op := r.Header.Get("X-Username")
|
||||
if op == "" {
|
||||
op = req.Operator
|
||||
}
|
||||
if err := ctx.Mes.PalletDispatch(r.Context(), req.DockCode, op); err != nil {
|
||||
fail(w, http.StatusBadGateway, err.Error())
|
||||
return
|
||||
}
|
||||
ok(w, map[string]any{"ok": true})
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ type returnOrderCreateRequest struct {
|
||||
Reason string `json:"reason"`
|
||||
Operator string `json:"operator"`
|
||||
StationNo int `json:"stationNo"`
|
||||
ReturnDock string `json:"returnDock"` // 2026-11-03 拍板:退料接驳台(AGV 拉货依据)
|
||||
RefNo string `json:"refNo"` // B5:叫料单退库时的叫料单号(仓库确认收回后回调 MES 关单回补)
|
||||
}
|
||||
|
||||
@@ -89,6 +90,7 @@ func createReturnOrderInternalHandler(ctx *svc.ServiceContext) http.HandlerFunc
|
||||
SetNillableSpec(strPtr(req.Spec)).
|
||||
SetQty(req.Qty).
|
||||
SetNillableUnit(strPtr(req.Unit)).
|
||||
SetReturnDock(req.ReturnDock).
|
||||
SetReason(req.Reason).
|
||||
SetOperator(req.Operator).
|
||||
SetStatus("PENDING").
|
||||
@@ -401,6 +403,7 @@ func queryReturnOrdersHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
q := r.URL.Query()
|
||||
status := q.Get("status")
|
||||
orderNo := strings.TrimSpace(q.Get("orderNo"))
|
||||
page := atoi(q.Get("page"), 1)
|
||||
pageSize := atoi(q.Get("pageSize"), 50)
|
||||
if page < 1 {
|
||||
@@ -413,6 +416,10 @@ func queryReturnOrdersHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
if status != "" {
|
||||
builder = builder.Where(returnorder.StatusEQ(status))
|
||||
}
|
||||
// 按工单号筛选(转产按工单精确退料:库管可分工作业面确认收货,账目清晰)
|
||||
if orderNo != "" {
|
||||
builder = builder.Where(returnorder.OrderNoEQ(orderNo))
|
||||
}
|
||||
total, err := builder.Count(ctx0())
|
||||
if err != nil {
|
||||
fail(w, http.StatusInternalServerError, err.Error())
|
||||
|
||||
@@ -102,6 +102,12 @@ func RegisterHandlers(server *rest.Server, ctx *svc.ServiceContext) {
|
||||
{Method: http.MethodGet, Path: "/api/call/pending", Handler: requirePerm(ctx, "call:view", callPendingHandler(ctx))},
|
||||
{Method: http.MethodPost, Path: "/api/call/complete", Handler: requirePerm(ctx, "call:manage", callCompleteHandler(ctx))},
|
||||
{Method: http.MethodPost, Path: "/api/call/reject", Handler: requirePerm(ctx, "call:manage", callRejectHandler(ctx))},
|
||||
// AGV 三段链装货确认(2026-11-03 三层机制):到位待令 → 库管「确认装车并送货」
|
||||
{Method: http.MethodPost, Path: "/api/call/confirm-load", Handler: requirePerm(ctx, "call:manage", ConfirmCallLoadHandler(ctx))},
|
||||
// 托盘工作台(2026-11-03):接驳台台账列表 + 手动派 AGV 回收空托盘(单点步进、到位待令)
|
||||
{Method: http.MethodGet, Path: "/api/pallet/docks", Handler: PalletDocksHandler(ctx)},
|
||||
{Method: http.MethodGet, Path: "/api/pallet/station-docks", Handler: StationDocksProxyHandler(ctx)},
|
||||
{Method: http.MethodPost, Path: "/api/pallet/dispatch", Handler: requirePerm(ctx, "call:manage", PalletDispatchHandler(ctx))},
|
||||
},
|
||||
)
|
||||
|
||||
@@ -197,6 +203,8 @@ func RegisterHandlers(server *rest.Server, ctx *svc.ServiceContext) {
|
||||
{Method: http.MethodPost, Path: "/api/return-order/confirm", Handler: confirmReturnOrderHandler(ctx)},
|
||||
{Method: http.MethodGet, Path: "/api/return-order/query", Handler: queryReturnOrdersHandler(ctx)},
|
||||
{Method: http.MethodGet, Path: "/api/return-order/suggest-location", Handler: suggestReturnLocationHandler(ctx)},
|
||||
// 库管代工位退料(2026-11-03 拍板):库管替操作工建退库单(选工位/工单/物料/数量/接驳台)
|
||||
{Method: http.MethodPost, Path: "/api/return-order/manual", Handler: createReturnOrderInternalHandler(ctx)},
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user