refactor: 清理MES端本地product_type冗余代码,对齐WMS主数据架构
1. 移除MES端本地product_type实体、schema及相关CRUD代码,改为通过WMS内部API代理获取物料主数据 2. 更新物料管理粒度逻辑,新增"其他"类型(3)支持,同步更新入库校验规则 3. 修复前端物料选择、库存筛选等页面的类型判断逻辑,统一使用manage_mode区分管理类型 4. 清理静态资源文件冗余的样式代码,调整前端页面展示逻辑 5. 更新帮助文档,修正物料类型的说明描述
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package wmsclient
|
||||
package wmsclient
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -6,8 +6,10 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -630,3 +632,80 @@ type RespError struct {
|
||||
func (e *RespError) Error() string {
|
||||
return "wms call failed with status " + string(rune('0'+e.Status))
|
||||
}
|
||||
|
||||
// MaterialRow WMS 物料档案行(代理 WMS materials 表)
|
||||
type MaterialRow struct {
|
||||
ID int `json:"id"`
|
||||
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"`
|
||||
CreatedAt int64 `json:"createdAt"`
|
||||
UpdatedAt int64 `json:"updatedAt"`
|
||||
}
|
||||
|
||||
// MaterialPage 分页查询 WMS 物料(GET /api/internal/materials)
|
||||
func (c *Client) MaterialPage(ctx context.Context, code, name, spec string, itemType, manageMode, page, pageSize int) (int64, []MaterialRow, error) {
|
||||
q := "/api/internal/materials?page=" + strconv.Itoa(page) + "&pageSize=" + strconv.Itoa(pageSize)
|
||||
if code != "" {
|
||||
q += "&materialCode=" + url.QueryEscape(code)
|
||||
}
|
||||
if name != "" {
|
||||
q += "&name=" + url.QueryEscape(name)
|
||||
}
|
||||
if spec != "" {
|
||||
q += "&spec=" + url.QueryEscape(spec)
|
||||
}
|
||||
if itemType > 0 {
|
||||
q += "&itemType=" + strconv.Itoa(itemType)
|
||||
}
|
||||
if manageMode > 0 {
|
||||
q += "&manageMode=" + strconv.Itoa(manageMode)
|
||||
}
|
||||
var out struct {
|
||||
Total int64 `json:"total"`
|
||||
List []MaterialRow `json:"list"`
|
||||
}
|
||||
if err := c.get(ctx, q, &out); err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
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,
|
||||
})
|
||||
}
|
||||
|
||||
// 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,
|
||||
})
|
||||
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