feat(mes): 添加定时同步可生产数量到WMS及BOM项相关标准字段
- 在main.go中添加定时任务每10分钟同步可生产数量到WMS系统 - 为BomItem实体添加relatedStandard字段及相关CRUD方法 - 为InspectionRecord实体添加reportNo、materialCode、materialName等字段 - 更新ent schema确保新字段的验证和默认值设置 - 添加必要的数据库迁移和字段映射逻辑
This commit is contained in:
@@ -3,6 +3,7 @@ package syncer
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"bj_power_workstation/internal/mes"
|
||||
@@ -53,7 +54,7 @@ func (s *Syncer) RunOnce(ctx context.Context) int {
|
||||
}
|
||||
|
||||
// flushTorque 上报未同步拧紧结果:
|
||||
// POST /api/internal/tightening/report;成功标记 synced=1,失败保持 0 等待下轮重试。
|
||||
// POST /api/internal/torque/report;成功标记 synced=1,失败保持 0 等待下轮重试。
|
||||
func (s *Syncer) flushTorque(ctx context.Context) int {
|
||||
rows, err := s.st.ListTorqueResults("", true, reportBatchLimit)
|
||||
if err != nil {
|
||||
@@ -70,17 +71,24 @@ func (s *Syncer) flushTorque(ctx context.Context) int {
|
||||
default:
|
||||
}
|
||||
|
||||
// MES 内部接口以 stationNo(数字工位号)落库,并据此做应拧/实拧分组统计;
|
||||
// 本地存的是 DOCK 编码(DOCK01 ↔ 工位1),上报前换算为工位号。
|
||||
stationNo := strings.TrimLeft(strings.TrimPrefix(t.DockCode, "DOCK"), "0")
|
||||
if stationNo == "" {
|
||||
stationNo = "0"
|
||||
}
|
||||
body := map[string]any{
|
||||
"workOrderNo": t.WorkOrderNo,
|
||||
"sn": t.Sn,
|
||||
"dockCode": t.DockCode,
|
||||
"stationNo": stationNo,
|
||||
"screwNo": t.ScrewNo,
|
||||
"torque": t.Torque,
|
||||
"angle": t.Angle,
|
||||
"result": t.Result,
|
||||
"operator": t.Operator,
|
||||
}
|
||||
if _, _, err := s.mes.Post("/api/internal/tightening/report", body); err != nil {
|
||||
if _, _, err := s.mes.Post("/api/internal/torque/report", body); err != nil {
|
||||
logx.Errorf("上报拧紧结果失败(id=%d sn=%s): %v", t.ID, t.Sn, err)
|
||||
continue
|
||||
}
|
||||
@@ -96,8 +104,10 @@ func (s *Syncer) flushTorque(ctx context.Context) int {
|
||||
}
|
||||
|
||||
// flushQueue 上报未同步的离线缓存队列,payload 原样透传:
|
||||
// - kind=process_done → POST /api/internal/station/report
|
||||
// - kind=temp_store → POST /api/internal/station/checkin
|
||||
// - kind=process_done → POST /api/internal/station/report
|
||||
// - kind=temp_store → POST /api/internal/station/checkin
|
||||
// - kind=online_register → POST /api/internal/workpiece/online(上线建档)
|
||||
// - kind=offline_finish → POST /api/internal/workpiece/done(下线完工入库)
|
||||
//
|
||||
// 成功标记 synced=1;失败 synced 保持 0 并累计 retry_count。
|
||||
func (s *Syncer) flushQueue(ctx context.Context) int {
|
||||
@@ -121,6 +131,10 @@ func (s *Syncer) flushQueue(ctx context.Context) int {
|
||||
path = "/api/internal/station/report"
|
||||
case "temp_store":
|
||||
path = "/api/internal/station/checkin"
|
||||
case "online_register":
|
||||
path = "/api/internal/workpiece/online"
|
||||
case "offline_finish":
|
||||
path = "/api/internal/workpiece/done"
|
||||
default:
|
||||
logx.Errorf("未知队列类型(kind=%s id=%d),跳过", it.Kind, it.ID)
|
||||
_ = s.st.BumpQueueRetry(it.ID)
|
||||
|
||||
Reference in New Issue
Block a user