feat: 退料闭环定稿(损耗台账/备料清单/退料AGV自动派车/剩余量参考)+ 工位托盘守卫
- MES 新增损耗台账 loss_ledger,差异确认损耗接口 ConfirmReceiveLoss(按工单归集) - 备料清单 preparation:MES 按 日计划×工单×工位×物料 实时计算,WMS 只读展示 PreparationList - 退料闭环:N5 工位托盘守卫(未完成禁止退料)、退料 AGV 自动派车(JBT21 空位判定 + 托盘回收链路)、退料参考剩余量接口(应剩余=实备-已耗-已退-已损) - 新增 AGV 车辆状态表 agv_vehicle_state 及查询 - 整合接驳台/叫料池/库存锁既有闭环,清理 sql 目录注释生成脚本与 catalog,更新文档
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -353,15 +354,136 @@ func (c *Client) ExportProductTypes(ctx context.Context, code, name, spec, isAct
|
||||
|
||||
// CreateReturnOrder 调 WMS /api/internal/return-order 预建退库单(工位退料/叫料单退库,待 WMS 确认收货)。
|
||||
// refNo 非空 = 叫料单退库(B5):携带叫料单号,WMS 确认收回后凭此回调 MES /call/return-confirm。
|
||||
// returnDock(2026-11-03 拍板):退料必须指定接驳台(AGV 从该接驳台拉货),WMS 退库单展示。
|
||||
func (c *Client) CreateReturnOrder(ctx context.Context, orderNo, sn, materialCode, materialName, spec, reason, operator string, stationNo, qty int, unit, refNo, returnDock string) error {
|
||||
// returnDock(2026-11-03 拍板):退料必须指定接驳台(退料托盘放置位置),WMS 退库单展示。
|
||||
// lossReason(2026-11-04 拍板):损耗原因(巡检退料一律必填;转产退料实际<理论时必填),WMS 退库单落 loss_reason 可查。
|
||||
// transportMode(2026-11-04 定稿):运输方式 agv/manual——agv=传感器检测到接驳台有托盘且库房有空位自动派车;manual=无 AGV。
|
||||
func (c *Client) CreateReturnOrder(ctx context.Context, orderNo, sn, materialCode, materialName, spec, reason, operator string, stationNo, qty int, unit, refNo, returnDock, lossReason, transportMode string) error {
|
||||
return c.post(ctx, "/api/internal/return-order", map[string]any{
|
||||
"orderNo": orderNo, "sn": sn, "materialCode": materialCode, "materialName": materialName,
|
||||
"spec": spec, "qty": qty, "unit": unit, "reason": reason, "operator": operator, "stationNo": stationNo,
|
||||
"refNo": refNo, "returnDock": returnDock,
|
||||
"refNo": refNo, "returnDock": returnDock, "lossReason": lossReason, "transportMode": transportMode,
|
||||
})
|
||||
}
|
||||
|
||||
// StationReturnList 工位终端「我的退料单」列表(WMS internal 转发)。
|
||||
func (c *Client) StationReturnList(ctx context.Context, stationNo int) ([]map[string]any, error) {
|
||||
u := fmt.Sprintf("%s/api/internal/return-order/station-list?stationNo=%d", c.BaseURL(), stationNo)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("X-API-TOKEN", c.token)
|
||||
resp, err := c.hc.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
var env struct {
|
||||
Code int `json:"code"`
|
||||
Data []map[string]any `json:"data"`
|
||||
Msg string `json:"message"`
|
||||
}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&env); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if env.Code != 0 {
|
||||
return nil, fmt.Errorf("WMS 返回错误: %s", env.Msg)
|
||||
}
|
||||
if env.Data == nil {
|
||||
return []map[string]any{}, nil
|
||||
}
|
||||
return env.Data, nil
|
||||
}
|
||||
|
||||
// ---------- 退料 AGV 自动派车 / 工位取消退料 / 余量参考值(2026-11-04 口径定稿) ----------
|
||||
|
||||
// PendingReturnRow 待派车退料单行(WMS /api/internal/return-order/pending-agv 返回)。
|
||||
type PendingReturnRow struct {
|
||||
ReturnNo string `json:"returnNo"`
|
||||
ReturnDock string `json:"returnDock"`
|
||||
StationNo int `json:"stationNo"`
|
||||
OrderNo string `json:"orderNo"`
|
||||
}
|
||||
|
||||
// PendingAgvReturns 拉取待自动派车退料单(PENDING + 运输方式=AGV + 未派车)。
|
||||
func (c *Client) PendingAgvReturns(ctx context.Context) ([]PendingReturnRow, error) {
|
||||
u := c.BaseURL() + "/api/internal/return-order/pending-agv"
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("X-API-TOKEN", c.token)
|
||||
resp, err := c.hc.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
var env struct {
|
||||
Code int `json:"code"`
|
||||
Data []PendingReturnRow `json:"data"`
|
||||
Msg string `json:"message"`
|
||||
}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&env); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if env.Code != 0 {
|
||||
return nil, fmt.Errorf("WMS 返回错误: %s", env.Msg)
|
||||
}
|
||||
if env.Data == nil {
|
||||
return []PendingReturnRow{}, nil
|
||||
}
|
||||
return env.Data, nil
|
||||
}
|
||||
|
||||
// MarkReturnDispatched 回写退料单「已派车」标记(自动派车成功后调用,防重复派车)。
|
||||
func (c *Client) MarkReturnDispatched(ctx context.Context, returnNo string) error {
|
||||
return c.post(ctx, "/api/internal/return-order/mark-dispatched", map[string]any{"returnNo": returnNo})
|
||||
}
|
||||
|
||||
// CancelReturnOrder 工位取消自己发起的 PENDING 退料单(工位终端 → MES 转发 WMS)。
|
||||
func (c *Client) CancelReturnOrder(ctx context.Context, returnNo string, stationNo int, operator, reason string) error {
|
||||
return c.post(ctx, "/api/internal/return-order/cancel", map[string]any{
|
||||
"returnNo": returnNo, "stationNo": stationNo, "operator": operator, "reason": reason,
|
||||
})
|
||||
}
|
||||
|
||||
// ReturnedSummaryRow 已退余量汇总行(WMS /api/internal/return-order/returned-summary 返回)。
|
||||
type ReturnedSummaryRow struct {
|
||||
OrderNo string `json:"orderNo"`
|
||||
MaterialCode string `json:"materialCode"`
|
||||
ReturnedQty float64 `json:"returnedQty"` // PENDING+RECEIVED 退料数量合计(已取消不计)
|
||||
}
|
||||
|
||||
// FetchReturnedSummary 拉取某工位已退余量汇总(余量参考值=应剩余量−已退−损耗)。
|
||||
func (c *Client) FetchReturnedSummary(ctx context.Context, stationNo int) ([]ReturnedSummaryRow, error) {
|
||||
u := fmt.Sprintf("%s/api/internal/return-order/returned-summary?stationNo=%d", c.BaseURL(), stationNo)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("X-API-TOKEN", c.token)
|
||||
resp, err := c.hc.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
var env struct {
|
||||
Code int `json:"code"`
|
||||
Data []ReturnedSummaryRow `json:"data"`
|
||||
Msg string `json:"message"`
|
||||
}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&env); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if env.Code != 0 {
|
||||
return nil, fmt.Errorf("WMS 返回错误: %s", env.Msg)
|
||||
}
|
||||
if env.Data == nil {
|
||||
return []ReturnedSummaryRow{}, nil
|
||||
}
|
||||
return env.Data, nil
|
||||
}
|
||||
|
||||
// DisplayOverview 拉取 WMS 免登录看板总览 /api/display/overview。
|
||||
// 用于看板「仓储动态」屏。WMS 不可达时返回 err,由调用方降级为空对象(看板其余屏不受影响)。
|
||||
func (c *Client) DisplayOverview(ctx context.Context) (map[string]any, error) {
|
||||
|
||||
Reference in New Issue
Block a user