feat: 退料闭环定稿(损耗台账/备料清单/退料AGV自动派车/剩余量参考)+ 工位托盘守卫
- MES 新增损耗台账 loss_ledger,差异确认损耗接口 ConfirmReceiveLoss(按工单归集) - 备料清单 preparation:MES 按 日计划×工单×工位×物料 实时计算,WMS 只读展示 PreparationList - 退料闭环:N5 工位托盘守卫(未完成禁止退料)、退料 AGV 自动派车(JBT21 空位判定 + 托盘回收链路)、退料参考剩余量接口(应剩余=实备-已耗-已退-已损) - 新增 AGV 车辆状态表 agv_vehicle_state 及查询 - 整合接驳台/叫料池/库存锁既有闭环,清理 sql 目录注释生成脚本与 catalog,更新文档
This commit is contained in:
@@ -78,26 +78,26 @@ func (c *Client) Ping(ctx context.Context) error {
|
||||
|
||||
// MaterialRequest MES 叫料单行(B5:不绑工单/不绑排产;七态状态机)
|
||||
type MaterialRequest struct {
|
||||
ID int `json:"id"`
|
||||
RequestNo string `json:"requestNo"`
|
||||
MaterialCode string `json:"materialCode"`
|
||||
MaterialName string `json:"materialName"`
|
||||
Unit string `json:"unit"`
|
||||
SnMode int `json:"snMode"`
|
||||
ReqQty float64 `json:"reqQty"`
|
||||
SentQty float64 `json:"sentQty"`
|
||||
ReturnedQty float64 `json:"returnedQty"`
|
||||
Status string `json:"status"`
|
||||
TargetDock string `json:"targetDock"`
|
||||
StationNo int `json:"stationNo"`
|
||||
Source string `json:"source"`
|
||||
RefReportNo string `json:"refReportNo"`
|
||||
NeedAgv bool `json:"needAgv"`
|
||||
CrossDay bool `json:"crossDay"`
|
||||
OutboundNo string `json:"outboundNo"`
|
||||
RejectReason string `json:"rejectReason"`
|
||||
Operator string `json:"operator"`
|
||||
CreatedAt string `json:"createdAt"` // RFC3339(MES ent 序列化),大屏叫料池显示 HH:MM 用
|
||||
ID int `json:"id"`
|
||||
RequestNo string `json:"requestNo"`
|
||||
MaterialCode string `json:"materialCode"`
|
||||
MaterialName string `json:"materialName"`
|
||||
Unit string `json:"unit"`
|
||||
SnMode int `json:"snMode"`
|
||||
ReqQty float64 `json:"reqQty"`
|
||||
SentQty float64 `json:"sentQty"`
|
||||
ReturnedQty float64 `json:"returnedQty"`
|
||||
Status string `json:"status"`
|
||||
TargetDock string `json:"targetDock"`
|
||||
StationNo int `json:"stationNo"`
|
||||
Source string `json:"source"`
|
||||
RefReportNo string `json:"refReportNo"`
|
||||
NeedAgv bool `json:"needAgv"`
|
||||
CrossDay bool `json:"crossDay"`
|
||||
OutboundNo string `json:"outboundNo"`
|
||||
RejectReason string `json:"rejectReason"`
|
||||
Operator string `json:"operator"`
|
||||
CreatedAt string `json:"createdAt"` // RFC3339(MES ent 序列化),大屏叫料池显示 HH:MM 用
|
||||
BorrowFrom map[string]int `json:"borrowFrom"` // 跨工位借料来源(MES 记账):stationNo→借用量;含本工位自取
|
||||
}
|
||||
|
||||
@@ -185,6 +185,110 @@ func (c *Client) FetchMaterialDemand(ctx context.Context, days int) ([]MaterialD
|
||||
return env.Data, nil
|
||||
}
|
||||
|
||||
// ---------- P1 备料清单(2026-11-04 用户拍板) ----------
|
||||
|
||||
// PreparationRow 备料清单行(MES 实时算返回):一行 = 某排产日 × 某工单 × 某工位 × 某物料。
|
||||
type PreparationRow struct {
|
||||
PlanDate string `json:"planDate"`
|
||||
OrderNo string `json:"orderNo"`
|
||||
ProductName string `json:"productName"`
|
||||
StationNo int `json:"stationNo"`
|
||||
StationQty int `json:"stationQty"` // 该工位分产量(台)
|
||||
MaterialCode string `json:"materialCode"` // 物料编码(图号)
|
||||
MaterialName string `json:"materialName"`
|
||||
Spec string `json:"spec"`
|
||||
Unit string `json:"unit"`
|
||||
Qty int `json:"qty"` // 需求量 = ceil(分产量×单台用量)
|
||||
UnitQty float64 `json:"unitQty"` // 单台用量
|
||||
Status string `json:"status"` // 排产状态
|
||||
}
|
||||
|
||||
// PreparationList 备料清单返回。
|
||||
type PreparationList struct {
|
||||
Rows []PreparationRow `json:"rows"`
|
||||
Total int `json:"total"`
|
||||
Range string `json:"range"`
|
||||
PlanCnt int `json:"planCnt"`
|
||||
}
|
||||
|
||||
// FetchPreparationList 实时向 MES 拉取备料清单(只读;MES 现算现返,工艺改动刷新即联动)。
|
||||
func (c *Client) FetchPreparationList(ctx context.Context) (*PreparationList, error) {
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.baseURL+"/api/internal/preparation-list", 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 *PreparationList `json:"data"`
|
||||
Msg string `json:"message"`
|
||||
}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&env); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if env.Code != 0 {
|
||||
msg := env.Msg
|
||||
if msg == "" {
|
||||
msg = "MES 返回失败"
|
||||
}
|
||||
return nil, errors.New(msg)
|
||||
}
|
||||
if env.Data == nil {
|
||||
return &PreparationList{Rows: []PreparationRow{}}, nil
|
||||
}
|
||||
return env.Data, nil
|
||||
}
|
||||
|
||||
// ---------- E4 托盘余料明细(2026-11-04 拍板) ----------
|
||||
|
||||
// PalletResidualRow 接驳台托盘余料行(MES 从最近送达的 AGV 运输段 materials_json 解析)。
|
||||
type PalletResidualRow struct {
|
||||
RequestNo string `json:"requestNo"`
|
||||
MaterialCode string `json:"materialCode"`
|
||||
MaterialName string `json:"materialName"`
|
||||
Unit string `json:"unit"`
|
||||
Qty float64 `json:"qty"`
|
||||
}
|
||||
|
||||
// FetchPalletResidual 拉取指定接驳台托盘余料明细(供 WMS 托盘工作台代退料弹窗自动带出)。
|
||||
func (c *Client) FetchPalletResidual(ctx context.Context, dock string) ([]PalletResidualRow, error) {
|
||||
u := c.baseURL + "/api/internal/pallet/residual?dock=" + url.QueryEscape(dock)
|
||||
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 []PalletResidualRow `json:"data"`
|
||||
Msg string `json:"message"`
|
||||
}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&env); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if env.Code != 0 {
|
||||
msg := env.Msg
|
||||
if msg == "" {
|
||||
msg = "MES 返回失败"
|
||||
}
|
||||
return nil, errors.New(msg)
|
||||
}
|
||||
if env.Data == nil {
|
||||
return []PalletResidualRow{}, nil
|
||||
}
|
||||
return env.Data, nil
|
||||
}
|
||||
|
||||
// DockRow MES 接驳台主数据行(dock 真源已迁 MES,WMS 仅只读取用)。
|
||||
type DockRow struct {
|
||||
ID int64 `json:"id"`
|
||||
@@ -196,6 +300,9 @@ type DockRow struct {
|
||||
Status string `json:"status"`
|
||||
HasPallet bool `json:"hasPallet"`
|
||||
PalletRef string `json:"palletRef"`
|
||||
// Cleared 台面清空(R19 2026-11-03 拍板):= !HasPallet,转产退料确认收货闸门依据,
|
||||
// 与 MES GuardTransferReroute(校验 Dock.HasPallet==false)同口径。
|
||||
Cleared bool `json:"cleared"`
|
||||
}
|
||||
|
||||
// ListDocks 拉取 MES 接驳台主数据(dock 真源在 MES)。
|
||||
@@ -231,6 +338,10 @@ func (c *Client) ListDocks(ctx context.Context) ([]DockRow, error) {
|
||||
if env.Data.List == nil {
|
||||
return []DockRow{}, nil
|
||||
}
|
||||
// Cleared 派生:无托盘即台面已清空(MES 侧不单独下发 cleared 字段)
|
||||
for i := range env.Data.List {
|
||||
env.Data.List[i].Cleared = !env.Data.List[i].HasPallet
|
||||
}
|
||||
return env.Data.List, nil
|
||||
}
|
||||
|
||||
@@ -243,12 +354,171 @@ func (c *Client) AgvConfirm(ctx context.Context, bizNo, action, nextDock, operat
|
||||
return c.postInternal(ctx, "/api/internal/agv/confirm", body, "AGV 确认动作失败")
|
||||
}
|
||||
|
||||
// AgvDispatch 库管人工派车(2026-11-03 定论:废除备料完成自动派车):
|
||||
// 叫料队列点「送货」→ MES internal /api/internal/agv/dispatch-call 下发空车去程段。
|
||||
func (c *Client) AgvDispatch(ctx context.Context, requestNo, operator string) error {
|
||||
body, _ := json.Marshal(map[string]any{"requestNo": requestNo, "operator": operator})
|
||||
return c.postInternal(ctx, "/api/internal/agv/dispatch-call", body, "AGV 派车失败")
|
||||
}
|
||||
|
||||
// PalletDispatch 托盘回收派车(WMS 托盘工作台):空车前往工位接驳台拉托盘(业务自动触发免弹窗)。
|
||||
func (c *Client) PalletDispatch(ctx context.Context, dockCode, operator string) error {
|
||||
body, _ := json.Marshal(map[string]any{"dockCode": dockCode, "operator": operator})
|
||||
return c.postInternal(ctx, "/api/internal/agv/pallet-dispatch", body, "托盘回收派车失败")
|
||||
}
|
||||
|
||||
// ---------- 退料 AGV 自动派车 / 取消联动 / 损耗落账 / 余量参考值(2026-11-04 口径定稿) ----------
|
||||
|
||||
// Jbt21Free 查询库房接驳台 JBT21 是否有空位(无空位不派车——托盘回收按钮禁用/自动派车等待)。
|
||||
func (c *Client) Jbt21Free(ctx context.Context) (bool, string, error) {
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.baseURL+"/api/internal/agv/jbt21-free", nil)
|
||||
if err != nil {
|
||||
return false, "", err
|
||||
}
|
||||
req.Header.Set("X-API-TOKEN", c.token)
|
||||
resp, err := c.hc.Do(req)
|
||||
if err != nil {
|
||||
return false, "", err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
var env struct {
|
||||
Code int `json:"code"`
|
||||
Data struct {
|
||||
Free bool `json:"free"`
|
||||
Reason string `json:"reason"`
|
||||
} `json:"data"`
|
||||
Msg string `json:"message"`
|
||||
}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&env); err != nil {
|
||||
return false, "", err
|
||||
}
|
||||
if env.Code != 0 {
|
||||
return false, "", errors.New(env.Msg)
|
||||
}
|
||||
return env.Data.Free, env.Data.Reason, nil
|
||||
}
|
||||
|
||||
// CancelAgvByDock 按接驳台取消未终态 PALLET 回收任务(退料单取消联动:作废未完成 AGV 任务)。
|
||||
// 返回 hasInTransit=true 表示该接驳台存在已装车运输中的段(调用方应拒绝取消退料单)。
|
||||
func (c *Client) CancelAgvByDock(ctx context.Context, dockCode, reason string) (map[string]any, error) {
|
||||
body, _ := json.Marshal(map[string]any{"dockCode": dockCode, "reason": reason})
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.baseURL+"/api/internal/agv/cancel-by-dock", bytes.NewReader(body))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
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, errors.New(env.Msg)
|
||||
}
|
||||
return env.Data, nil
|
||||
}
|
||||
|
||||
// LossConfirm WMS 确认收货实收<应退时就地损耗落账(损耗确认移 WMS,MES 只读展示)。
|
||||
func (c *Client) LossConfirm(ctx context.Context, returnNo, orderNo string, stationNo int,
|
||||
materialCode, materialName string, theoryQty, actualQty, lossQty float64, reason, operator string) error {
|
||||
body, _ := json.Marshal(map[string]any{
|
||||
"returnNo": returnNo, "orderNo": orderNo, "stationNo": stationNo,
|
||||
"materialCode": materialCode, "materialName": materialName,
|
||||
"theoryQty": theoryQty, "actualQty": actualQty, "lossQty": lossQty,
|
||||
"reason": reason, "operator": operator,
|
||||
})
|
||||
return c.postInternal(ctx, "/api/internal/loss/confirm", body, "损耗落账失败")
|
||||
}
|
||||
|
||||
// ReturnRefRow 余量参考值行(MES 聚合返回,N4 定稿:应剩余量=实际备料量−已消耗−已退−已损耗)。
|
||||
type ReturnRefRow struct {
|
||||
OrderNo string `json:"orderNo"`
|
||||
MaterialCode string `json:"materialCode"`
|
||||
MaterialName string `json:"materialName"`
|
||||
Unit string `json:"unit"`
|
||||
TheoryQty float64 `json:"theoryQty"`
|
||||
PreparedQty float64 `json:"preparedQty"` // 实际备料量
|
||||
ConsumedQty float64 `json:"consumedQty"` // 已消耗
|
||||
LossQty float64 `json:"lossQty"`
|
||||
ReturnedQty float64 `json:"returnedQty"`
|
||||
RefLeft float64 `json:"refLeft"`
|
||||
}
|
||||
|
||||
// StationReturnGuardResult WMS 代退料前置校验结果(拍板2 三态):
|
||||
// Allowed=true 放行;NeedForce=true = PLC 离线(前端弹风险提示,ForceConfirm 重提);
|
||||
// Allowed=false & NeedForce=false = 硬拒(Reason 为拒绝文案)。
|
||||
type StationReturnGuardResult struct {
|
||||
Allowed bool `json:"allowed"`
|
||||
NeedForce bool `json:"needForce"`
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
|
||||
// StationReturnGuard WMS 代退料前置校验(N5 2026-11-04 拍板 + 拍板2):工位传感器无托盘
|
||||
// (工件已完工离开工位)才允许退料;PLC 离线返回 NeedForce=true 供人工强行确认。
|
||||
func (c *Client) StationReturnGuard(ctx context.Context, stationNo int) (*StationReturnGuardResult, error) {
|
||||
u := fmt.Sprintf("%s/api/internal/station/return-guard?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 StationReturnGuardResult `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, errors.New(env.Msg)
|
||||
}
|
||||
return &env.Data, nil
|
||||
}
|
||||
|
||||
// FetchReturnReference 拉取某工位余量参考值列表(WMS 代退料展示参考值)。
|
||||
func (c *Client) FetchReturnReference(ctx context.Context, stationNo int) ([]ReturnRefRow, error) {
|
||||
u := fmt.Sprintf("%s/api/internal/return-reference?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 struct {
|
||||
Rows []ReturnRefRow `json:"rows"`
|
||||
} `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, errors.New(env.Msg)
|
||||
}
|
||||
return env.Data.Rows, nil
|
||||
}
|
||||
|
||||
// WorkOrderContract MES 工单归属解析结果(A2 半成品入库继承产线工单)
|
||||
type WorkOrderContract struct {
|
||||
WorkOrderNo string `json:"workOrderNo"`
|
||||
@@ -347,8 +617,10 @@ func (c *Client) CallReject(ctx context.Context, requestNo, reason, operator str
|
||||
}
|
||||
|
||||
// CallReturnConfirm 通知 MES 仓库已确认收回退库(B5 退库闭环终点):MES 关单并回补叫料池额度。
|
||||
func (c *Client) CallReturnConfirm(ctx context.Context, requestNo, operator string) error {
|
||||
b, _ := json.Marshal(map[string]any{"requestNo": requestNo, "operator": operator})
|
||||
// 2026-11-03 拍板(R18):带回实收量/收货差异/备注,MES 落「待核」差异,不自动进损耗台账。
|
||||
func (c *Client) CallReturnConfirm(ctx context.Context, requestNo, operator string, receiveQty, receiveDiff int, receiveNote string) error {
|
||||
b, _ := json.Marshal(map[string]any{"requestNo": requestNo, "operator": operator,
|
||||
"receiveQty": receiveQty, "receiveDiff": receiveDiff, "receiveNote": receiveNote})
|
||||
return c.postInternal(ctx, "/api/internal/call/return-confirm", b, "MES 叫料单退库确认回写失败")
|
||||
}
|
||||
|
||||
@@ -388,4 +660,3 @@ type RespError struct {
|
||||
func (e *RespError) Error() string {
|
||||
return "mes call failed with status " + fmt.Sprintf("%d", e.Status)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user