feat: 核心业务实体扩充(混产模板/产品BOM/试制记录)、WMS 库存检验增强与前端通用能力
- MES 新增实体:混产模板、产品BOM、产品工艺物料、试制记录(schema + ent 生成码 + logic/handler/前端页) - WMS 实体增强:检验记录、库存、半成品重构;新增序列号库存与短缺代报 - AGV 与产能:AGV 手动点位与链路、物料守卫、短缺预测、原因字典 - 前端通用能力:新增下一步引导组件 NextStepBar,统一帮助文档/布局/请求拦截与操作列 - 工位终端:界面与各 handler 调整(api/store/绑定/PLC/拧紧/上报等) - 配置与文档:更新 mes-api.yaml、WMS README 及案例/产线API/问题记录/项目说明/流程说明
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
@@ -77,6 +78,76 @@ func (c *Client) Ping(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 2026-11-13 拍板:成品入库扫 SN 反查 MES。WMS 必须区分「MES 不可达」与「SN 查不到」,
|
||||
// 前者 502 硬拒、后者 404 硬拒,二者都禁止成品入库;物料入库链不调用本方法,绝不误伤。
|
||||
var (
|
||||
ErrMESUnreachable = errors.New("MES 不可达")
|
||||
ErrMESTimeout = errors.New("MES 响应超时")
|
||||
ErrFinishedSNNotFound = errors.New("SN 无对应工单")
|
||||
)
|
||||
|
||||
// isTimeout 识别连接/读超时与 context deadline(http.Client Timeout=6s 会以 net.Error 形式返回)。
|
||||
// 2026-11-13 拍板:MES 宕机时必须单独捕获超时,不能和「不可达」混成同一句提示。
|
||||
func isTimeout(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
if errors.Is(err, context.DeadlineExceeded) {
|
||||
return true
|
||||
}
|
||||
var ne net.Error
|
||||
if errors.As(err, &ne) && ne.Timeout() {
|
||||
return true
|
||||
}
|
||||
s := strings.ToLower(err.Error())
|
||||
return strings.Contains(s, "timeout") || strings.Contains(s, "deadline exceeded")
|
||||
}
|
||||
|
||||
// FinishedLookup MES 透传的成品档案快照(WMS 只读展示,禁止前端改写)。
|
||||
type FinishedLookup struct {
|
||||
Sn string `json:"sn"`
|
||||
OrderNo string `json:"orderNo"`
|
||||
ProductCode string `json:"productCode"`
|
||||
ProductName string `json:"productName"`
|
||||
ProductStatus string `json:"productStatus"`
|
||||
OwnershipType string `json:"ownershipType"`
|
||||
OwnershipNo string `json:"ownershipNo"`
|
||||
}
|
||||
|
||||
// LookupFinishedBySN 调 MES /api/internal/finished/lookup?sn= 反查工单与成品档案。
|
||||
// 反查本身即「MES 在线」判据,省去额外一次 Ping(4s);业务错与网络错分开返回。
|
||||
func (c *Client) LookupFinishedBySN(ctx context.Context, sn string) (*FinishedLookup, error) {
|
||||
u := c.BaseURL() + "/api/internal/finished/lookup?sn=" + url.QueryEscape(sn)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%w: %v", ErrMESUnreachable, err)
|
||||
}
|
||||
req.Header.Set("X-API-TOKEN", c.token)
|
||||
resp, err := c.hc.Do(req)
|
||||
if err != nil {
|
||||
if isTimeout(err) {
|
||||
return nil, fmt.Errorf("%w: %v", ErrMESTimeout, err)
|
||||
}
|
||||
return nil, fmt.Errorf("%w: %v", ErrMESUnreachable, err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode >= 400 {
|
||||
return nil, fmt.Errorf("%w: HTTP %d(请检查 MES 地址与内部 token)", ErrMESUnreachable, resp.StatusCode)
|
||||
}
|
||||
var env struct {
|
||||
Code int `json:"code"`
|
||||
Data FinishedLookup `json:"data"`
|
||||
Msg string `json:"message"`
|
||||
}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&env); err != nil {
|
||||
return nil, fmt.Errorf("%w: 响应解析失败 %v", ErrMESUnreachable, err)
|
||||
}
|
||||
if env.Code != 0 {
|
||||
return nil, fmt.Errorf("%w: %s", ErrFinishedSNNotFound, env.Msg)
|
||||
}
|
||||
return &env.Data, nil
|
||||
}
|
||||
|
||||
// MaterialRequest MES 叫料单行(B5:不绑工单/不绑排产;七态状态机)
|
||||
type MaterialRequest struct {
|
||||
ID int `json:"id"`
|
||||
@@ -278,6 +349,16 @@ func (c *Client) CreateCall(ctx context.Context, stationNo int, callDate string,
|
||||
})
|
||||
}
|
||||
|
||||
// CreateShortageOnBehalf 库管代工位提交补料申请(转发 MES /api/internal/shortage/on-behalf)。
|
||||
// 复用 MES 现有补料申请 logic 只生成待主管审批的补料单;WMS 不审批、不调增叫料池额度。
|
||||
// 产品工号不作为独立字段下发(补料申请表无此列),由调用方附在补料原因里带过去。
|
||||
func (c *Client) CreateShortageOnBehalf(ctx context.Context, stationNo int, materialCode string, qty int, reason, operator string) error {
|
||||
return c.postJSON(ctx, "/api/internal/shortage/on-behalf", map[string]any{
|
||||
"stationNo": stationNo, "materialCode": materialCode,
|
||||
"qty": qty, "reason": reason, "operator": operator,
|
||||
})
|
||||
}
|
||||
|
||||
// DockClear 人工清台(托盘被人工卸走后台账卡死兜底)
|
||||
func (c *Client) DockClear(ctx context.Context, dockCode, operator, reason string) error {
|
||||
return c.postJSON(ctx, "/api/internal/dock/clear", map[string]any{
|
||||
@@ -703,7 +784,7 @@ func (c *Client) FetchReturnReference(ctx context.Context, stationNo int) ([]Ret
|
||||
return env.Data.Rows, nil
|
||||
}
|
||||
|
||||
// WorkOrderContract MES 工单归属解析结果(A2 半成品入库继承产线工单)
|
||||
// WorkOrderContract MES 工单归属解析结果(A2 在制品入库继承产线工单)
|
||||
type WorkOrderContract struct {
|
||||
WorkOrderNo string `json:"workOrderNo"`
|
||||
ContractNo string `json:"contractNo"`
|
||||
@@ -735,8 +816,16 @@ func (c *Client) GetWorkOrder(ctx context.Context, orderNo string) (*WorkOrderCo
|
||||
if err := json.NewDecoder(resp.Body).Decode(&env); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.StatusCode >= 400 {
|
||||
return nil, fmt.Errorf("MES 工单查询失败(HTTP %d): %s", resp.StatusCode, env.Msg)
|
||||
}
|
||||
// 2026-11-13 修复:原来把 MES 的「任何」业务错都吞成 (nil,nil),上层一律误报 404「工单不存在」,
|
||||
// 掩盖了 MES 不可达 / token 失效 / 网关异常。现只对「工单确实不存在」降级,其余原样上抛。
|
||||
if env.Code != 0 {
|
||||
return nil, nil
|
||||
if strings.Contains(env.Msg, "不存在") || strings.Contains(env.Msg, "未找到") || env.Code == 2003 {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, fmt.Errorf("MES 工单查询失败(%d): %s", env.Code, env.Msg)
|
||||
}
|
||||
return &env.Data, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user