按模块说明
一、MES — 叫料单扩展(schema + 逻辑) material_request 新增字段:packageNo(叫料包号,一次提交=一包)、callDate(叫料日,默认当天)、planBreakdown(jsonb,工单×排产日明细 []CallPlanBreakdown);targetDock 语义降级为"期望接驳台(可空,配送时 WMS 确定实际台)"。 新增 internal/logic/call_plan.go:实时计算「叫料需求明细(工单×排产日×物料)」,派生两类提示(当日剩余未叫 / 跨日量明细),不落库、不拦提交;接驳台空台校验 EnsureStationDocksEmpty、托盘回库 DispatchPalletReturnManual、人工清台 ClearDockLedger、配送单派车 DispatchDeliveryAgv、工位物料明细 StationMaterialDetail。 新增 internal/handler/production/call_pkg.go:8 个 MES 内部端点(X-API-TOKEN 网关),供 WMS 调用——叫料需求明细、按包查单、接驳台状态、托盘回库、人工清台、配送单派车、叫料池原始行、工位物料明细、WMS 代叫料。 internal/handler/production/call.go、internal/logic/call.go、agv.go、qty_report.go、routes_production.go、wmsclient/client.go、db.go 同步接入上述逻辑。 二、WMS — 配送单(新功能,叫料与送料彻底拆开) 新增 schema/delivery_order.go + delivery_order_item.go 及 ent 生成代码:delivery_order(PENDING→DISPATCHED→DONE / CANCELLED,一单=一次托盘配送)、delivery_order_item(配送物料明细快照:工单/工艺/排产日)。 新增 internal/handler/delivery.go + 路由 + DeliveryOrders.vue 页面(仓储作业 → 配送单)。 mesclient/client.go 扩展:MES 叫料单结构补 packageNo/callDate/workOrderNo/planBreakdown,新增 PoolRow/DockPalletState/DeliveryAgvItem/getJSON 等。 CallQueue.vue:按叫料包展示,新增「代叫料」「建配送单」按钮与对话框;出库单回写所属配送单号(outbound_order 加字段);AGV 派送改由配送单驱动。 三、工位终端 — 叫料体验升级 MaterialPanel.vue:新增「本工位物料明细」卡(工艺物料全集×工位账四数,量为 0 也显示);叫料改为「叫料包」模式(默认当天、可勾选分批、可选其他排产日、期望接驳台可空),新增叫料日选择器、两条提示横幅(当日剩余未叫 / 跨日量明细)、托盘回库按钮。 InspectPanel.vue/Main.vue/OnlinePanel.vue/OfflinePanel.vue/WorkPanel.vue/SyncQueueDialog.vue/api/index.js/internal/handler/line.go/routes.go 同步接入接驳台状态、托盘回库、下班双台空台校验等。 web/static/index.html 构建刷新。 四、文档 案例.md:重写第 5/6/8/9 节与新「配送单」流程,补「模拟模式跳过接驳台校验」说明,库管员菜单加「配送单」;并修正"本单箱体"等措辞歧义。 客户问题.md:同步本轮拍板口径。 五、构建产物 / 同步 多个 MES 前端页面(.vue)随本次改动统一重新构建刷新;ent 生成代码(MES material_request、WMS delivery_order/outbound_order 相关)随 schema 更新重新生成。
This commit is contained in:
@@ -440,9 +440,12 @@ func (s *Service) AdjustPoolQty(ctx context.Context, stationNo int, materialCode
|
||||
return nil
|
||||
}
|
||||
|
||||
// CreateCallOrders 发起叫料:按物料行拆 N 张单;事务内行锁占用池子可用量(耗尽即止)。
|
||||
// source=CALL(工位终端叫料)/ REFILL(数量不符补发,refReportNo 必填);两入口消耗同一池子。
|
||||
func (s *Service) CreateCallOrders(ctx context.Context, stationNo int, items []CallItem, source, refReportNo, operator string) (int, error) {
|
||||
// CreateCallOrders 发起叫料:按物料行拆 N 张单(2026-11-05 拍板:一次提交=一个叫料包,
|
||||
// 同批所有单赋同一 package_no;callDate=所选排产日默认当天);事务内行锁占用池子可用量(耗尽即止)。
|
||||
// source=CALL(工位终端叫料/WMS 代叫料)/ REFILL(数量不符补发,refReportNo 必填);两入口消耗同一池子。
|
||||
// 接驳台降级为「期望接驳台」(可空,配送时 WMS 确定实际接驳台);提交时校验两接驳台都为空
|
||||
// (force=true 为 PLC 离线降级强提,仅 CALL 口径生效)。
|
||||
func (s *Service) CreateCallOrders(ctx context.Context, stationNo int, items []CallItem, source, refReportNo, operator string, callDate string, force bool) (int, error) {
|
||||
if stationNo <= 0 {
|
||||
return 0, errors.New("工位号无效")
|
||||
}
|
||||
@@ -488,15 +491,19 @@ func (s *Service) CreateCallOrders(ctx context.Context, stationNo int, items []C
|
||||
}
|
||||
}
|
||||
}
|
||||
// 2026-11-05 拍板:两个接驳台都为空才能叫料(提交时校验;PLC 离线降级=提示后可强行提交)
|
||||
if source == "CALL" && !force {
|
||||
if derr := s.EnsureStationDocksEmpty(ctx, stationNo); derr != nil {
|
||||
return 0, derr
|
||||
}
|
||||
}
|
||||
// 接驳台降级为期望接驳台(可空);填写时仍须属于本工位且启用
|
||||
// 预校验(fail-fast,减少进事务后回滚)
|
||||
for _, it := range items {
|
||||
if it.MaterialCode == "" || it.Qty <= 0 {
|
||||
return 0, errors.New("叫料明细的物料编码与数量必填")
|
||||
}
|
||||
if it.Dock == "" {
|
||||
return 0, errors.New("请选择目标接驳台")
|
||||
}
|
||||
if !dockSet[it.Dock] {
|
||||
if it.Dock != "" && !dockSet[it.Dock] {
|
||||
return 0, fmt.Errorf("接驳台 %s 不属于本工位或已停用,请在「产线管理」确认后重选", it.Dock)
|
||||
}
|
||||
}
|
||||
@@ -512,6 +519,11 @@ func (s *Service) CreateCallOrders(ctx context.Context, stationNo int, items []C
|
||||
}()
|
||||
created := 0
|
||||
ts := time.Now().UnixNano()
|
||||
// 叫料包(2026-11-05 拍板):同批提交的所有单赋同一包号;存量单为空=单包
|
||||
packageNo := fmt.Sprintf("PK%d-%d", stationNo, ts)
|
||||
if callDate == "" {
|
||||
callDate = time.Now().Format("2006-01-02")
|
||||
}
|
||||
borrowLogs := []borrowLogEntry{}
|
||||
for _, it := range items {
|
||||
ownRow, rerr := tx.CallPool.Query().
|
||||
@@ -599,12 +611,15 @@ func (s *Service) CreateCallOrders(ctx context.Context, stationNo int, items []C
|
||||
return created, fmt.Errorf("%s 自身可用 %d 不足(请求 %d),请开启借料或从同工序工位借料", it.MaterialCode, ownAvail, it.Qty)
|
||||
}
|
||||
reqNo := fmt.Sprintf("MR%d", ts+int64(created))
|
||||
// 工单×排产日明细拆分(2026-11-05 拍板:物料挂工单;池聚合层不动,明细层补留)
|
||||
breakdown := s.splitPlanBreakdown(ctx, stationNo, it.MaterialCode, it.Qty, callDate)
|
||||
if _, cerr := tx.MaterialRequest.Create().
|
||||
SetRequestNo(reqNo).SetMaterialCode(it.MaterialCode).SetMaterialName(ownRow.MaterialName).
|
||||
SetUnit(ownRow.Unit).SetSnMode(ownRow.SnMode).SetReqQty(float64(it.Qty)).
|
||||
SetStatus("PENDING").SetStationNo(stationNo).SetTargetDock(it.Dock).
|
||||
SetCrossDay(ownRow.CrossDay).SetSource(source).SetRefReportNo(refReportNo).
|
||||
SetBorrowFrom(alloc).SetNeedAgv(true).SetOperator(operator).Save(ctx); cerr != nil {
|
||||
SetBorrowFrom(alloc).SetNeedAgv(true).SetOperator(operator).
|
||||
SetPackageNo(packageNo).SetCallDate(callDate).SetPlanBreakdown(breakdown).Save(ctx); cerr != nil {
|
||||
return created, cerr
|
||||
}
|
||||
if d := borrowDetail(alloc, stationNo, it.MaterialCode); d != "" {
|
||||
@@ -617,8 +632,9 @@ func (s *Service) CreateCallOrders(ctx context.Context, stationNo int, items []C
|
||||
}
|
||||
committed = true
|
||||
s.ctx.EventLog.Write(ctx, "call.create", "", operator, "material_request", "",
|
||||
fmt.Sprintf("工位%d 发起叫料 %d 项", stationNo, created),
|
||||
map[string]any{"stationNo": stationNo, "count": created, "source": source, "refReportNo": refReportNo})
|
||||
fmt.Sprintf("工位%d 发起叫料 %d 项(包 %s,叫料日 %s)", stationNo, created, packageNo, callDate),
|
||||
map[string]any{"stationNo": stationNo, "count": created, "source": source,
|
||||
"refReportNo": refReportNo, "packageNo": packageNo, "callDate": callDate})
|
||||
for _, bl := range borrowLogs {
|
||||
s.ctx.EventLog.Write(ctx, "call.create", "", operator, "material_request", bl.reqNo,
|
||||
"操作人["+operator+"] "+borrowDetail(bl.alloc, stationNo, bl.materialCode), nil)
|
||||
@@ -627,6 +643,17 @@ func (s *Service) CreateCallOrders(ctx context.Context, stationNo int, items []C
|
||||
return created, nil
|
||||
}
|
||||
|
||||
// ListMaterialRequestsByPackage 按叫料包号查叫料单(WMS 建配送单数据源;
|
||||
// 含工单×排产明细 planBreakdown 与出库单号;按创建时间升序)。
|
||||
func (s *Service) ListMaterialRequestsByPackage(ctx context.Context, packageNo string) ([]*ent.MaterialRequest, error) {
|
||||
if packageNo == "" {
|
||||
return nil, errors.New("缺少包号")
|
||||
}
|
||||
return s.ctx.EntClient.MaterialRequest.Query().
|
||||
Where(materialrequest.PackageNo(packageNo)).
|
||||
Order(ent.Asc(materialrequest.FieldCreatedAt)).All(ctx)
|
||||
}
|
||||
|
||||
// loadCallForUpdate 事务内锁叫料单并复核状态(返回锁后的行)
|
||||
func loadCallForUpdate(ctx context.Context, tx *ent.Tx, requestNo string) (*ent.MaterialRequest, error) {
|
||||
mr, err := tx.MaterialRequest.Query().
|
||||
|
||||
Reference in New Issue
Block a user