feat: 多系统新增扫码中间件与 AGV 对接,优化拧紧与退库流程
新增扫码中间件支持网络型扫码枪键盘注入,AGV 对接从 WMS 迁至 MES 统一管理;新增拧紧不合格人工处置与 PLC 对账机制,优化退库单关联与工位终端功能,同时清理旧 AGV 任务表,完善数据库与配置项。
This commit is contained in:
@@ -59,10 +59,24 @@ func lineOccupyHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// lineCallMaterialHandler POST /api/line/call-material(工位终端叫料:AGV 送达本工位固定接驳台)
|
||||
// 接驳台不允许用户选择/传入:统一用 yaml Station.Dock 配置覆盖后转发 MES。
|
||||
// 请求体:{stationNo, orderNo, items:[{materialCode, materialName, unit, snMode, qty}]}
|
||||
func lineCallMaterialHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
// ============ B5 叫料(代理 MES 内部 API,2026-10-13 定稿) ============
|
||||
// 接驳台:每行可选(GxR1/GxR2),未选时用 yaml Station.Dock 配置兜底(本工位固定接驳台)。
|
||||
|
||||
// callPoolHandler GET /api/call/pool 叫料池(本工位物料行四数:需求/调整/已发/占用/可用)
|
||||
func callPoolHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
q := url.Values{}
|
||||
if v := strings.TrimSpace(r.URL.Query().Get("stationNo")); v != "" {
|
||||
q.Set("stationNo", v)
|
||||
}
|
||||
body, _, err := ctx.Mes.Get("/api/internal/call/pool", q)
|
||||
mesJSON(w, body, err)
|
||||
}
|
||||
}
|
||||
|
||||
// callCreateHandler POST /api/call/create 发起叫料(按物料行拆 N 张单,占用池子可用量)
|
||||
// 请求体:{stationNo, items:[{materialCode, qty, dock?}]};每行缺省接驳台用 yaml Station.Dock 兜底。
|
||||
func callCreateHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
payload, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
@@ -75,28 +89,37 @@ func lineCallMaterialHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
dock := strings.TrimSpace(ctx.Config.Station.Dock)
|
||||
if dock == "" {
|
||||
fail(w, http.StatusInternalServerError, "本工位接驳台未配置(配置文件 Station.Dock),请联系运维")
|
||||
return
|
||||
if items, ok := req["items"].([]any); ok {
|
||||
for _, it := range items {
|
||||
m, ok := it.(map[string]any)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if d, _ := m["dock"].(string); strings.TrimSpace(d) == "" {
|
||||
if dock == "" {
|
||||
fail(w, http.StatusInternalServerError, "本工位接驳台未配置(配置文件 Station.Dock)且未选择目标接驳台,请联系运维")
|
||||
return
|
||||
}
|
||||
m["dock"] = dock // 兜底:目标接驳台取本工位配置
|
||||
}
|
||||
}
|
||||
}
|
||||
req["dock"] = dock // 覆盖前端传入值:目标接驳台只由服务端配置文件决定
|
||||
if req["operator"] == nil || req["operator"] == "" {
|
||||
if u := currentUsername(r); u != "" {
|
||||
req["operator"] = u
|
||||
}
|
||||
}
|
||||
body, _ := json.Marshal(req)
|
||||
resp, _, err := ctx.Mes.Post("/api/internal/line/call-material", json.RawMessage(body))
|
||||
resp, _, err := ctx.Mes.Post("/api/internal/call/create", json.RawMessage(body))
|
||||
mesJSON(w, resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
// materialRequestsHandler GET /api/material-requests 代理 MES /api/internal/material-requests
|
||||
// 工位终端按当前登录工位过滤「待接料」行(stationNo 由前端带入)。
|
||||
func materialRequestsHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
// callListHandler GET /api/call/list 叫料单列表(本工位;status 可空=全部)
|
||||
func callListHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
q := url.Values{}
|
||||
for _, k := range []string{"stationNo", "status", "orderNo", "planDate", "materialCode", "targetDock"} {
|
||||
for _, k := range []string{"stationNo", "status", "materialCode", "targetDock", "source", "requestNo"} {
|
||||
if v := strings.TrimSpace(r.URL.Query().Get(k)); v != "" {
|
||||
q.Set(k, v)
|
||||
}
|
||||
@@ -106,9 +129,23 @@ func materialRequestsHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// materialReceiveHandler POST /api/material-request/receive 代理 MES /api/internal/station/receive-material
|
||||
// 主入口:工人扫码接料(扫描备料单号确认)。operator 由本服务补当前登录人。
|
||||
func materialReceiveHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
// callSignHandler POST /api/call/sign 签收(仅已发货;签收=确认收到,系统不再对差异)
|
||||
func callSignHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return callStateHandler(ctx, "/api/internal/call/sign", "签收")
|
||||
}
|
||||
|
||||
// callCancelHandler POST /api/call/cancel 取消(仅待备料,工位本人)
|
||||
func callCancelHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return callStateHandler(ctx, "/api/internal/call/cancel", "取消")
|
||||
}
|
||||
|
||||
// callReturnHandler POST /api/call/return 申请退库(仅已发货/签收前;整单退,仓库确认收回后关单)
|
||||
func callReturnHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return callStateHandler(ctx, "/api/internal/call/return", "退库申请")
|
||||
}
|
||||
|
||||
// callStateHandler 叫料单状态动作通用代理:补 operator(当前登录人)后转发 MES 内部端点。
|
||||
func callStateHandler(ctx *svc.ServiceContext, mesPath, action string) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
payload, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
@@ -121,7 +158,7 @@ func materialReceiveHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
if req["requestNo"] == nil || req["requestNo"] == "" {
|
||||
fail(w, http.StatusBadRequest, "缺少备料单号")
|
||||
fail(w, http.StatusBadRequest, "缺少叫料单号")
|
||||
return
|
||||
}
|
||||
if req["operator"] == nil || req["operator"] == "" {
|
||||
@@ -130,7 +167,19 @@ func materialReceiveHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
body, _ := json.Marshal(req)
|
||||
resp, _, err := ctx.Mes.Post("/api/internal/station/receive-material", json.RawMessage(body))
|
||||
resp, _, err := ctx.Mes.Post(mesPath, json.RawMessage(body))
|
||||
if err != nil {
|
||||
fail(w, http.StatusBadGateway, action+"失败:MES 不可达")
|
||||
return
|
||||
}
|
||||
mesJSON(w, resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
// docksHandler GET /api/docks 接驳台列表(代理 MES /api/internal/docks;终端按工位过滤 R1/R2)
|
||||
func docksHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
body, _, err := ctx.Mes.Get("/api/internal/docks", url.Values{})
|
||||
mesJSON(w, body, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"bj_power_workstation/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
// plcMismatchCheckHandler POST /api/plc/mismatch/check
|
||||
// 代理 MES /api/internal/plc/mismatch/check(事件驱动,禁止定时轮询)。
|
||||
// 终端在「开始作业(T2)/扫SN(T3)」时按需调用单工位检查;MES 不可达或业务拒绝均静默跳过,不阻断作业。
|
||||
func plcMismatchCheckHandler(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
|
||||
}
|
||||
respBody, _, err := ctx.Mes.Post("/api/internal/plc/mismatch/check", json.RawMessage(payload))
|
||||
if err != nil {
|
||||
// MES 不可达:静默跳过,提示不拦,不影响终端作业
|
||||
logx.Errorf("PLC↔MES 对账检查 MES 不可达,静默跳过: %v", err)
|
||||
ok(w, map[string]any{"hasMismatch": false})
|
||||
return
|
||||
}
|
||||
if msg := mesRespCode(respBody); msg != "" {
|
||||
// 业务拒绝(如工位号无效):静默跳过,不阻断作业
|
||||
logx.Errorf("PLC↔MES 对账检查 MES 业务拒绝,静默跳过: %s", msg)
|
||||
ok(w, map[string]any{"hasMismatch": false})
|
||||
return
|
||||
}
|
||||
// 透传 MES 响应体(data={hasMismatch,stationNo,plcBit,detail,options,graceWindow})
|
||||
passJSON(w, respBody)
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,9 @@ func RegisterHandlers(server *rest.Server, ctx *svc.ServiceContext) {
|
||||
{Method: http.MethodGet, Path: "/pdfopen/:name", Handler: pdfOpenHandler(ctx)},
|
||||
{Method: http.MethodGet, Path: "/api/tightening/list", Handler: tighteningListHandler(ctx)},
|
||||
{Method: http.MethodPost, Path: "/api/tightening/record", Handler: tighteningRecordHandler(ctx)},
|
||||
{Method: http.MethodPost, Path: "/api/report/process-done", Handler: processDoneHandler(ctx)},
|
||||
{Method: http.MethodGet, Path: "/api/tightening/live", Handler: tighteningLiveHandler(ctx)},
|
||||
{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)},
|
||||
{Method: http.MethodPost, Path: "/api/station/logout", Handler: logoutHandler(ctx)},
|
||||
{Method: http.MethodPost, Path: "/api/sync/flush", Handler: syncFlushHandler(ctx)},
|
||||
@@ -55,9 +57,14 @@ func RegisterHandlers(server *rest.Server, ctx *svc.ServiceContext) {
|
||||
// 产线点位 / 叫料(代理 MES 内部 API)
|
||||
{Method: http.MethodGet, Path: "/api/line/points", Handler: linePointsHandler(ctx)},
|
||||
{Method: http.MethodPost, Path: "/api/line/occupy", Handler: lineOccupyHandler(ctx)},
|
||||
{Method: http.MethodPost, Path: "/api/line/call-material", Handler: lineCallMaterialHandler(ctx)},
|
||||
{Method: http.MethodGet, Path: "/api/material-requests", Handler: materialRequestsHandler(ctx)},
|
||||
{Method: http.MethodPost, Path: "/api/material-request/receive", Handler: materialReceiveHandler(ctx)},
|
||||
// B5 叫料六端点(代理 MES 内部 API):池子/发起/列表/签收/取消/退库申请
|
||||
{Method: http.MethodGet, Path: "/api/call/pool", Handler: callPoolHandler(ctx)},
|
||||
{Method: http.MethodGet, Path: "/api/docks", Handler: docksHandler(ctx)},
|
||||
{Method: http.MethodPost, Path: "/api/call/create", Handler: callCreateHandler(ctx)},
|
||||
{Method: http.MethodGet, Path: "/api/call/list", Handler: callListHandler(ctx)},
|
||||
{Method: http.MethodPost, Path: "/api/call/sign", Handler: callSignHandler(ctx)},
|
||||
{Method: http.MethodPost, Path: "/api/call/cancel", Handler: callCancelHandler(ctx)},
|
||||
{Method: http.MethodPost, Path: "/api/call/return", Handler: callReturnHandler(ctx)},
|
||||
|
||||
// 巡检 / 应急呼叫 / 数量不符 / 退料(代理 MES 内部 API)
|
||||
{Method: http.MethodPost, Path: "/api/inspection/submit", Handler: inspectionSubmitHandler(ctx)},
|
||||
@@ -73,6 +80,9 @@ func RegisterHandlers(server *rest.Server, ctx *svc.ServiceContext) {
|
||||
{Method: http.MethodGet, Path: "/api/trace", Handler: traceHandler(ctx)},
|
||||
{Method: http.MethodPost, Path: "/api/workpiece/online", Handler: onlineHandler(ctx)},
|
||||
{Method: http.MethodPost, Path: "/api/workpiece/done", Handler: doneHandler(ctx)},
|
||||
|
||||
// PLC↔MES 对账(#8 T2/T3 终端事件驱动检查,不轮询):代理 MES 内部接口,MES 不可达静默跳过
|
||||
{Method: http.MethodPost, Path: "/api/plc/mismatch/check", Handler: plcMismatchCheckHandler(ctx)},
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,4 +111,42 @@ func tighteningRecordHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
fmt.Sprintf("拧紧录入 sn=%s 步骤=%s 扭矩=%.1f 结果=%s", req.Sn, req.StepName, req.Torque, req.Result))
|
||||
ok(w, map[string]any{"id": id, "result": req.Result})
|
||||
}
|
||||
}
|
||||
|
||||
// tighteningLiveHandler GET /api/tightening/live —— 返回 OP 控制器最近推送、尚未确认上报的拧紧结果(前端轮询预填)。
|
||||
func tighteningLiveHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if ctx.Tightening == nil || !ctx.Tightening.Enabled() {
|
||||
ok(w, map[string]any{"enabled": false, "list": []any{}})
|
||||
return
|
||||
}
|
||||
ok(w, map[string]any{"enabled": true, "list": ctx.Tightening.Latest()})
|
||||
}
|
||||
}
|
||||
|
||||
// tighteningConsumeHandler POST /api/tightening/consume —— 操作工点「完成」后标记某条 OP 缓冲结果为已确认(防重复上报)。
|
||||
// 入参 {id}。
|
||||
func tighteningConsumeHandler(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 struct {
|
||||
ID int64 `json:"id"`
|
||||
}
|
||||
if err := json.Unmarshal(payload, &req); err != nil {
|
||||
fail(w, http.StatusBadRequest, "请求体解析失败")
|
||||
return
|
||||
}
|
||||
if req.ID <= 0 {
|
||||
fail(w, http.StatusBadRequest, "缺少缓冲结果 ID")
|
||||
return
|
||||
}
|
||||
if ctx.Tightening != nil {
|
||||
ctx.Tightening.Consume(req.ID)
|
||||
}
|
||||
ok(w, map[string]any{"ok": true})
|
||||
}
|
||||
}
|
||||
@@ -157,7 +157,9 @@ func onlineHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
ctx.Store.AddEventLog(req.OrderNo, opName, "online_register", "上线建档 sn="+req.Sn)
|
||||
ok(w, map[string]any{"queued": false})
|
||||
// 透传 MES 响应(data 即 PLC↔MES 对账 mismatch 对象,无对账时为 null),
|
||||
// 供前端建档成功后按需弹「两项」提示;离线队列分支仍返回 {queued:true}。
|
||||
passJSON(w, respBody)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user