feat: 两库对等物料管理及产品工号贯通全流程
- 新增 MES 本地物料表及双向同步接口,WMS 物料变更自动同步 - 全流程新增产品工号字段,贯通入库/库存/出库/检验环节 - 工单管理支持多工单混产,移除单工单互斥限制 - 新增批次号/SN 字段支持质量检验联动 WMS 库存处置 - 修复权限规则,仅内置管理员账号不允许修改删除 - 工位终端新增 SN 扫码自动切换所属工单功能
This commit is contained in:
@@ -102,6 +102,54 @@ func (c *Client) postSemi(ctx context.Context, path string, body any) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DisposeInventoryReq MES → WMS 在库不合格处置请求(调 /api/internal/inventory/dispose)
|
||||
// 定位口径与 WMS 一致:sn 非空按 SN 料(material_code+序列号)精确定位;
|
||||
// 否则按批次料(material_code+batch_no)定位(同批次多行全部置状态)。
|
||||
// DisposalType 仅支持 RETURN/REWORK/SCRAP;RETURN 必填 ReturnTrackingNo。
|
||||
type DisposeInventoryReq struct {
|
||||
MaterialCode string `json:"materialCode"`
|
||||
Sn string `json:"sn"`
|
||||
BatchNo string `json:"batchNo"`
|
||||
DisposalType string `json:"disposalType"`
|
||||
ReturnTrackingNo string `json:"returnTrackingNo"`
|
||||
Remark string `json:"remark"`
|
||||
Operator string `json:"operator"`
|
||||
}
|
||||
|
||||
// DisposeInventory 调 WMS /api/internal/inventory/dispose 执行在库处置(退货/返修/报废)。
|
||||
// 网络/超时、非2xx、业务码非0 均返回 error 且优先携带 WMS 原文 message,
|
||||
// 供质量检验保存链路透出「库存联动失败」原因(不阻断检验记录落库)。
|
||||
func (c *Client) DisposeInventory(ctx context.Context, req DisposeInventoryReq) error {
|
||||
b, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
httpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, c.BaseURL()+"/api/internal/inventory/dispose", bytes.NewReader(b))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
httpReq.Header.Set("Content-Type", "application/json")
|
||||
httpReq.Header.Set("X-API-TOKEN", c.token)
|
||||
resp, err := c.hc.Do(httpReq)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
raw, _ := io.ReadAll(resp.Body)
|
||||
var br struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
_ = json.Unmarshal(raw, &br)
|
||||
if resp.StatusCode >= 300 || br.Code != 0 {
|
||||
if br.Message != "" {
|
||||
return errors.New(br.Message)
|
||||
}
|
||||
return &RespError{Status: resp.StatusCode}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// FinishedInbound 成品完工回流入库:调 WMS /api/internal/finished/inbound。
|
||||
// 成品 SN 由 MES 系统生成(工件SN),统一库存主表 category=3;失败返回 err 由调用方降级。
|
||||
func (c *Client) FinishedInbound(ctx context.Context, productCode, productName, sn, orderNo, operator string) error {
|
||||
@@ -157,8 +205,10 @@ type ProductTypeRow struct {
|
||||
Category string `json:"category"`
|
||||
ManageMode int `json:"manageMode"` // 1结构件(批次)/2电气件(SN)
|
||||
IsActive bool `json:"isActive"`
|
||||
CreatedAt int64 `json:"createdAt"`
|
||||
UpdatedAt int64 `json:"updatedAt"`
|
||||
// SyncPending 推送 WMS 失败标记(两库对等 M3):true=本地已落、WMS 待重推
|
||||
SyncPending bool `json:"syncPending"`
|
||||
CreatedAt int64 `json:"createdAt"`
|
||||
UpdatedAt int64 `json:"updatedAt"`
|
||||
}
|
||||
|
||||
// get 调 WMS GET 接口并解出 {code,data}
|
||||
@@ -193,91 +243,9 @@ func (c *Client) get(ctx context.Context, path string, out any) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// putJSON 调 WMS PUT 接口
|
||||
func (c *Client) putJSON(ctx context.Context, path string, body any) error {
|
||||
b, err := json.Marshal(body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPut, c.BaseURL()+path, bytes.NewReader(b))
|
||||
if err != nil {
|
||||
return 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 err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode >= 300 {
|
||||
return &RespError{Status: resp.StatusCode}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProductTypes 全量产品型号(item_type=3,id asc,新建在底部)。isActive 可空。
|
||||
func (c *Client) ProductTypes(ctx context.Context, isActive string) ([]ProductTypeRow, error) {
|
||||
q := "/api/internal/product-types?"
|
||||
if isActive != "" {
|
||||
q += "isActive=" + isActive
|
||||
}
|
||||
var list []ProductTypeRow
|
||||
if err := c.get(ctx, q, &list); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// ProductTypePage 分页+搜索(产品型号管理页真分页)。
|
||||
// 2026-09-08 禁止关键字混搜:编码/名称/类别各自独立模糊。
|
||||
func (c *Client) ProductTypePage(ctx context.Context, code, name, category, isActive string, page, pageSize int) (int64, []ProductTypeRow, error) {
|
||||
q := fmt.Sprintf("/api/internal/product-types?page=%d&pageSize=%d", page, pageSize)
|
||||
if code != "" {
|
||||
q += "&code=" + url.QueryEscape(code)
|
||||
}
|
||||
if name != "" {
|
||||
q += "&name=" + url.QueryEscape(name)
|
||||
}
|
||||
if category != "" {
|
||||
q += "&category=" + url.QueryEscape(category)
|
||||
}
|
||||
if isActive != "" {
|
||||
q += "&isActive=" + isActive
|
||||
}
|
||||
var data struct {
|
||||
Total int64 `json:"total"`
|
||||
List []ProductTypeRow `json:"list"`
|
||||
}
|
||||
if err := c.get(ctx, q, &data); err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
return data.Total, data.List, nil
|
||||
}
|
||||
|
||||
// CreateProductType 新建产品型号(code 可空由 WMS 自动生成 PROD-日期-流水)
|
||||
// spec/unit 必填(与 WMS 物料档案必填口径一致)
|
||||
func (c *Client) CreateProductType(ctx context.Context, code, name, spec, unit, category string, isActive bool, manageMode int) error {
|
||||
return c.post(ctx, "/api/internal/product-types", map[string]any{
|
||||
"code": code, "name": name, "spec": spec, "unit": unit, "category": category, "isActive": isActive, "manageMode": manageMode,
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateProductType 修改产品型号(编码不可改)
|
||||
func (c *Client) UpdateProductType(ctx context.Context, id int, name, spec, unit, category string, isActive bool, manageMode int) error {
|
||||
return c.putJSON(ctx, "/api/internal/product-types", map[string]any{
|
||||
"id": id, "name": name, "spec": spec, "unit": unit, "category": category, "isActive": isActive, "manageMode": manageMode,
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteProductType 删除产品型号(引用保护由调用方与 WMS 双侧校验)
|
||||
func (c *Client) DeleteProductType(ctx context.Context, id int) error {
|
||||
return c.post(ctx, "/api/internal/product-types/delete", map[string]any{"id": id})
|
||||
}
|
||||
|
||||
// ExportProductTypes 拉取产品型号导出 xlsx 字节流(WMS 端执行统一导出时间规则)。
|
||||
// 编码/名称/类别各自独立模糊筛选(禁止关键字混搜)。
|
||||
func (c *Client) ExportProductTypes(ctx context.Context, code, name, category, isActive, startDate, endDate string) ([]byte, error) {
|
||||
// 编码/名称各自独立模糊筛选(禁止关键字混搜)。
|
||||
func (c *Client) ExportProductTypes(ctx context.Context, code, name, isActive, startDate, endDate string) ([]byte, error) {
|
||||
q := "/api/internal/product-types/export?"
|
||||
if code != "" {
|
||||
q += "code=" + url.QueryEscape(code) + "&"
|
||||
@@ -285,9 +253,6 @@ func (c *Client) ExportProductTypes(ctx context.Context, code, name, category, i
|
||||
if name != "" {
|
||||
q += "name=" + url.QueryEscape(name) + "&"
|
||||
}
|
||||
if category != "" {
|
||||
q += "category=" + url.QueryEscape(category) + "&"
|
||||
}
|
||||
if isActive != "" {
|
||||
q += "isActive=" + isActive + "&"
|
||||
}
|
||||
@@ -737,34 +702,25 @@ func (c *Client) MaterialPage(ctx context.Context, code, name, spec string, item
|
||||
return out.Total, out.List, nil
|
||||
}
|
||||
|
||||
// CreateMaterial 调 WMS 创建物料(POST /api/internal/materials)
|
||||
func (c *Client) CreateMaterial(ctx context.Context, code, name, spec, unit, description string, itemType, manageMode, safetyStock int, templateCode string) error {
|
||||
return c.post(ctx, "/api/internal/materials", map[string]any{
|
||||
"code": code, "name": name, "spec": spec, "unit": unit, "description": description,
|
||||
"itemType": itemType, "manageMode": manageMode, "templateCode": templateCode, "safetyStock": safetyStock,
|
||||
})
|
||||
// MaterialUpsert MES→WMS 物料推送载荷(POST WMS /api/internal/materials/upsert,按 code 幂等)。
|
||||
type MaterialUpsert struct {
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Spec string `json:"spec"`
|
||||
Unit string `json:"unit"`
|
||||
Description string `json:"description"`
|
||||
ItemType int `json:"itemType"`
|
||||
ManageMode int `json:"manageMode"`
|
||||
TemplateCode string `json:"templateCode"`
|
||||
SafetyStock int `json:"safetyStock"`
|
||||
IsActive *bool `json:"isActive"`
|
||||
}
|
||||
|
||||
// UpdateMaterial 调 WMS 更新物料(PUT /api/internal/materials)
|
||||
func (c *Client) UpdateMaterial(ctx context.Context, id int, name, spec, unit, description string, itemType, manageMode, safetyStock int, templateCode string) error {
|
||||
b, _ := json.Marshal(map[string]any{
|
||||
"id": id, "name": name, "spec": spec, "unit": unit, "description": description,
|
||||
"itemType": itemType, "manageMode": manageMode, "templateCode": templateCode, "safetyStock": safetyStock,
|
||||
// UpsertMaterialToWMS 推送物料到 WMS(需求一 M3/M5:MES 本地写入后同步推送;按 code 幂等 upsert)。
|
||||
func (c *Client) UpsertMaterialToWMS(ctx context.Context, m MaterialUpsert) error {
|
||||
return c.post(ctx, "/api/internal/materials/upsert", map[string]any{
|
||||
"code": m.Code, "name": m.Name, "spec": m.Spec, "unit": m.Unit, "description": m.Description,
|
||||
"itemType": m.ItemType, "manageMode": m.ManageMode, "templateCode": m.TemplateCode,
|
||||
"safetyStock": m.SafetyStock, "isActive": m.IsActive,
|
||||
})
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPut, c.BaseURL()+"/api/internal/materials", bytes.NewReader(b))
|
||||
if err != nil {
|
||||
return 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 err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode >= 400 {
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
return fmt.Errorf("WMS PUT /api/internal/materials %d: %s", resp.StatusCode, string(body))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user