feat(mes): 添加定时同步可生产数量到WMS及BOM项相关标准字段
- 在main.go中添加定时任务每10分钟同步可生产数量到WMS系统 - 为BomItem实体添加relatedStandard字段及相关CRUD方法 - 为InspectionRecord实体添加reportNo、materialCode、materialName等字段 - 更新ent schema确保新字段的验证和默认值设置 - 添加必要的数据库迁移和字段映射逻辑
This commit is contained in:
@@ -284,6 +284,72 @@ func (c *Client) DisplayOverview(ctx context.Context) (map[string]any, error) {
|
||||
return body.Data, nil
|
||||
}
|
||||
|
||||
// StockAvailable 批量查询物料可用量(调 WMS /api/internal/stock/check,qty 传 0 只取可用量)。
|
||||
// 返回 materialCode → availQty。用于 MES 侧计算可生产数量(BOM 单台用量在 MES、库存可用量在 WMS)。
|
||||
func (c *Client) StockAvailable(ctx context.Context, codes []string) (map[string]int, error) {
|
||||
items := make([]map[string]any, 0, len(codes))
|
||||
for _, code := range codes {
|
||||
items = append(items, map[string]any{"materialCode": code, "qty": 0})
|
||||
}
|
||||
b, err := json.Marshal(map[string]any{"items": items})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.baseURL+"/api/internal/stock/check", bytes.NewReader(b))
|
||||
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 body struct {
|
||||
Code int `json:"code"`
|
||||
Data struct {
|
||||
Items []struct {
|
||||
MaterialCode string `json:"materialCode"`
|
||||
AvailQty int `json:"availQty"`
|
||||
} `json:"items"`
|
||||
} `json:"data"`
|
||||
}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&body); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.StatusCode >= 300 || body.Code != 0 {
|
||||
return nil, &RespError{Status: resp.StatusCode}
|
||||
}
|
||||
out := make(map[string]int, len(body.Data.Items))
|
||||
for _, it := range body.Data.Items {
|
||||
out[it.MaterialCode] = it.AvailQty
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// ProducibleItem 可生产数量快照行(MES 计算后推送 WMS 只读展示)
|
||||
type ProducibleItem struct {
|
||||
ProductCode string `json:"productCode"`
|
||||
ProductName string `json:"productName"`
|
||||
ProducibleQty int `json:"producibleQty"`
|
||||
ShortText string `json:"shortText"`
|
||||
ComputedAt int64 `json:"computedAt"`
|
||||
}
|
||||
|
||||
// ProducibleDemand 未来5天物料需求行(推送 WMS,供备料四态「预警」判定)
|
||||
type ProducibleDemand struct {
|
||||
MaterialCode string `json:"materialCode"`
|
||||
Future5Qty int `json:"future5Qty"`
|
||||
}
|
||||
|
||||
// SyncProducible 推送可生产数量快照 + 未来5天需求到 WMS /api/internal/producible/sync(全量覆盖)。
|
||||
func (c *Client) SyncProducible(ctx context.Context, items []ProducibleItem, demands []ProducibleDemand) error {
|
||||
return c.post(ctx, "/api/internal/producible/sync", map[string]any{
|
||||
"items": items, "demands": demands,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Client) post(ctx context.Context, path string, body any) error {
|
||||
b, err := json.Marshal(body)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user