按模块说明

一、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:
SunYF
2026-11-05 19:18:18 +08:00
parent 46fcb59079
commit 1d1dc1bdd8
102 changed files with 12953 additions and 379 deletions
@@ -33,14 +33,17 @@ func CallPoolInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
}
// CreateCallHandler POST /api/internal/call/create 发起叫料(按物料行拆 N 张单,占用池子可用量)。
// CreateCallHandler POST /api/internal/call/create 发起叫料(一次提交=一个叫料包,按物料行拆 N 张单,
// 占用池子可用量)。callDate=所选排产日(空=当天);force=true 为 PLC 离线降级强行提交。
func CreateCallHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
StationNo int `json:"stationNo"`
Source string `json:"source"` // CALL(默认)/REFILL
RefReportNo string `json:"refReportNo"`
Items []logic.CallItem `json:"items"`
StationNo int `json:"stationNo"`
Source string `json:"source"` // CALL(默认)/REFILL
RefReportNo string `json:"refReportNo"`
CallDate string `json:"callDate"`
Force bool `json:"force"`
Items []logic.CallItem `json:"items"`
}
if err := httpx.ParseJSON(r, &req); err != nil {
httpx.BadRequest(w, "请求体解析失败")
@@ -48,7 +51,7 @@ func CreateCallHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
stationNo := StationNo(r, req.StationNo)
n, err := logic.New(svcCtx).CreateCallOrders(r.Context(), stationNo, req.Items,
req.Source, req.RefReportNo, StationOp(r, ""))
req.Source, req.RefReportNo, StationOp(r, ""), req.CallDate, req.Force)
if err != nil {
httpx.Fail(w, 3202, err.Error())
return
@@ -0,0 +1,204 @@
package production
// 2026-11-05 叫料包+配送单拍板:MES 内部端点(X-API-TOKEN 网关)
// ① 叫料需求明细(工单×排产日,两类提示数据源)
// ② 按工位批量读左右接驳台实时传感器(空台校验/下班校验共用)
// ③ 按包查叫料单(WMS 建配送单数据源,含工单×排产明细)
// ④ 托盘回库(传感器为准、台账软校验)
// ⑤ 人工清台(JBT21 等台账卡死兜底)
// ⑥ 配送单派车(AGV 派车改配送单驱动)
// ⑦ 叫料池原始行(WMS 代叫料对话框数据源)
// ⑧ 工位物料明细(工艺物料全集 左连接 工位账,量为0也显示)
import (
"net/http"
"strconv"
"bj_power_mes/common/httpx"
"bj_power_mes/internal/logic"
"bj_power_mes/internal/svc"
)
// CallPlanDetailInternalHandler GET /api/internal/call/plan-detail?stationNo=
// 叫料需求明细 + 「当日剩余没叫/跨日量明细」两类提示(实时计算不落库不拦提交)。
func CallPlanDetailInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
n, _ := strconv.Atoi(r.URL.Query().Get("stationNo"))
if n <= 0 {
httpx.BadRequest(w, "缺少工位号")
return
}
detail, err := logic.New(svcCtx).CallPlanDetail(r.Context(), n)
if err != nil {
httpx.Fail(w, 3230, err.Error())
return
}
httpx.Ok(w, detail)
}
}
// CallPackageInternalHandler GET /api/internal/call/package?packageNo=
// 按包查叫料单(WMS 建配送单数据源;含工单×排产明细 planBreakdown、出库单号)。
func CallPackageInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
pkg := r.URL.Query().Get("packageNo")
if pkg == "" {
httpx.BadRequest(w, "缺少包号")
return
}
rows, err := logic.New(svcCtx).ListMaterialRequestsByPackage(r.Context(), pkg)
if err != nil {
httpx.Fail(w, 3231, err.Error())
return
}
httpx.Ok(w, rows)
}
}
// StationDockPalletsInternalHandler GET /api/internal/dock/station-pallets?stationNo=
// 按工位批量读左右接驳台实时传感器(叫料空台校验/下班校验共用;PLC 不可达回退台账并标 plcOk=false)。
func StationDockPalletsInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
n, _ := strconv.Atoi(r.URL.Query().Get("stationNo"))
if n <= 0 {
httpx.BadRequest(w, "缺少工位号")
return
}
rows, err := logic.New(svcCtx).StationDockPallets(r.Context(), n)
if err != nil {
httpx.Fail(w, 3232, err.Error())
return
}
httpx.Ok(w, rows)
}
}
// PalletReturnInternalHandler POST /api/internal/dock/pallet-return
// 托盘回库(工位终端触发):传感器为准、台账软校验,不一致由操作人确认(confirmHasPallet)留痕;
// 物理拉回仓库 JBT21,非退料——物料账/库存不变。
func PalletReturnInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
DockCode string `json:"dockCode"`
Operator string `json:"operator"`
ConfirmHasPallet bool `json:"confirmHasPallet"`
}
if err := httpx.ParseJSON(r, &req); err != nil || req.DockCode == "" {
httpx.BadRequest(w, "缺少接驳台编码")
return
}
if err := logic.New(svcCtx).DispatchPalletReturnManual(r.Context(), req.DockCode, req.Operator, req.ConfirmHasPallet); err != nil {
httpx.Fail(w, 3233, err.Error())
return
}
httpx.OkMessage(w, "托盘回库已派车(物理拉回仓库,非退料;物料账与库存不变)", nil)
}
}
// DockClearInternalHandler POST /api/internal/dock/clear
// 人工清台:托盘被人工卸走后台账卡死兜底;仅清台账,不碰任何库存/池账/工件账。
func DockClearInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
DockCode string `json:"dockCode"`
Operator string `json:"operator"`
Reason string `json:"reason"`
}
if err := httpx.ParseJSON(r, &req); err != nil || req.DockCode == "" {
httpx.BadRequest(w, "缺少接驳台编码")
return
}
if err := logic.New(svcCtx).ClearDockLedger(r.Context(), req.DockCode, req.Operator, req.Reason); err != nil {
httpx.Fail(w, 3234, err.Error())
return
}
httpx.OkMessage(w, "已清台(台账置无托盘)", nil)
}
}
// DispatchDeliveryInternalHandler POST /api/internal/delivery/dispatch
// 配送单派车(AGV 派车改配送单驱动):WMS 校验配送单后转发,生成空车段(GO_LOAD)前往装货点 JBT21。
func DispatchDeliveryInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
DeliveryNo string `json:"deliveryNo"`
TargetDock string `json:"targetDock"`
Operator string `json:"operator"`
Items []logic.DeliveryAgvItem `json:"items"`
}
if err := httpx.ParseJSON(r, &req); err != nil || req.DeliveryNo == "" {
httpx.BadRequest(w, "缺少配送单号")
return
}
if err := logic.New(svcCtx).DispatchDeliveryAgv(r.Context(), req.DeliveryNo, req.TargetDock, req.Items, req.Operator); err != nil {
httpx.Fail(w, 3235, err.Error())
return
}
httpx.OkMessage(w, "配送单已派车(空车前往装货点,到位待令后确认装车)", nil)
}
}
// CallPoolRawInternalHandler GET /api/internal/call/pool-raw?stationNo=
// 叫料池原始行(WMS 代叫料对话框数据源;与终端同源同口径)。
func CallPoolRawInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
n, _ := strconv.Atoi(r.URL.Query().Get("stationNo"))
if n <= 0 {
httpx.BadRequest(w, "缺少工位号")
return
}
rows, err := logic.New(svcCtx).StationPool(r.Context(), n)
if err != nil {
httpx.Fail(w, 3201, err.Error())
return
}
httpx.Ok(w, rows)
}
}
// CreateCallInternalHandler POST /api/internal/call/create-internal
// WMS 代叫料(2026-11-05 拍板:与工位终端同一套逻辑;操作人取请求体,plain internal)。
func CreateCallInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
StationNo int `json:"stationNo"`
Source string `json:"source"`
CallDate string `json:"callDate"`
Force bool `json:"force"`
Operator string `json:"operator"`
Items []logic.CallItem `json:"items"`
}
if err := httpx.ParseJSON(r, &req); err != nil {
httpx.BadRequest(w, "请求体解析失败")
return
}
if req.Source == "" {
req.Source = "CALL"
}
n, err := logic.New(svcCtx).CreateCallOrders(r.Context(), req.StationNo, req.Items,
req.Source, "", req.Operator, req.CallDate, req.Force)
if err != nil {
httpx.Fail(w, 3202, err.Error())
return
}
httpx.OkMessage(w, "代叫料已提交", map[string]any{"count": n})
}
}
// StationMaterialDetailInternalHandler GET /api/internal/call/material-detail?stationNo=
// 工位物料明细(工艺物料全集 左连接 工位账四数,量为0也显示、不分左右托盘)。
func StationMaterialDetailInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
n, _ := strconv.Atoi(r.URL.Query().Get("stationNo"))
if n <= 0 {
httpx.BadRequest(w, "缺少工位号")
return
}
rows, err := logic.New(svcCtx).StationMaterialDetail(r.Context(), n)
if err != nil {
httpx.Fail(w, 3236, err.Error())
return
}
httpx.Ok(w, rows)
}
}
@@ -230,6 +230,18 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
server.AddRoute(rest.Route{
Method: http.MethodGet, Path: "/api/internal/call/pool", Handler: internal(production.StationSessionAuth(serverCtx)(production.CallPoolInternalHandler(serverCtx))),
})
// 2026-11-05 叫料包/配送单拍板:需求明细(两类提示)、按包查单、工位物料明细
server.AddRoute(rest.Route{Method: http.MethodGet, Path: "/api/internal/call/plan-detail", Handler: internal(production.CallPlanDetailInternalHandler(serverCtx))})
server.AddRoute(rest.Route{Method: http.MethodGet, Path: "/api/internal/call/package", Handler: internal(production.CallPackageInternalHandler(serverCtx))})
server.AddRoute(rest.Route{Method: http.MethodGet, Path: "/api/internal/call/pool-raw", Handler: internal(production.CallPoolRawInternalHandler(serverCtx))})
server.AddRoute(rest.Route{Method: http.MethodGet, Path: "/api/internal/call/material-detail", Handler: internal(production.StationMaterialDetailInternalHandler(serverCtx))})
// 接驳台实时传感器批量读 / 托盘回库(工位终端)/ 人工清台 / 配送单派车
server.AddRoute(rest.Route{Method: http.MethodGet, Path: "/api/internal/dock/station-pallets", Handler: internal(production.StationDockPalletsInternalHandler(serverCtx))})
server.AddRoute(rest.Route{Method: http.MethodPost, Path: "/api/internal/dock/pallet-return", Handler: internal(production.PalletReturnInternalHandler(serverCtx))})
server.AddRoute(rest.Route{Method: http.MethodPost, Path: "/api/internal/dock/clear", Handler: internal(production.DockClearInternalHandler(serverCtx))})
server.AddRoute(rest.Route{Method: http.MethodPost, Path: "/api/internal/delivery/dispatch", Handler: internal(production.DispatchDeliveryInternalHandler(serverCtx))})
// WMS 代叫料(与工位终端同一套 CreateCallOrders;操作人取请求体)
server.AddRoute(rest.Route{Method: http.MethodPost, Path: "/api/internal/call/create-internal", Handler: internal(production.CreateCallInternalHandler(serverCtx))})
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/internal/call/create", Handler: internal(production.StationSessionAuth(serverCtx)(production.CreateCallHandler(serverCtx))),
})