feat: 多系统新增扫码中间件与 AGV 对接,优化拧紧与退库流程

新增扫码中间件支持网络型扫码枪键盘注入,AGV 对接从 WMS 迁至 MES 统一管理;新增拧紧不合格人工处置与 PLC 对账机制,优化退库单关联与工位终端功能,同时清理旧 AGV 任务表,完善数据库与配置项。
This commit is contained in:
SunYF
2026-10-14 17:24:59 +08:00
parent 8e6048c64b
commit f65a52d9e1
170 changed files with 15415 additions and 10572 deletions
-28
View File
@@ -1,28 +0,0 @@
package handler
import (
"net/http"
"bj_power_mes/common/httpx"
"bj_power_mes/internal/logic"
"bj_power_mes/internal/svc"
)
// MaterialDeliveryProgressHandler GET /api/v1/material-requests/progress?orderNo=&materialCode=&page=&pageSize=
//
// 配送进度(只读聚合):WMS 台账「需求/已发出/已退回/已消耗/净领用/缺口」
// + MES 备料单「已接料」→ 派生「在途 / 线边」。
// 不新增账本、不双写:两边各管各的真源字段,本接口只做合成展示。
func MaterialDeliveryProgressHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
data, err := logic.New(svcCtx).DeliveryProgress(r.Context(),
q.Get("orderNo"), q.Get("materialCode"),
atoiDefault(q.Get("page"), 1), atoiDefault(q.Get("pageSize"), 50))
if err != nil {
httpx.Fail(w, 3204, err.Error())
return
}
httpx.Ok(w, data)
}
}
-23
View File
@@ -59,26 +59,3 @@ func ListPointsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
httpx.Ok(w, data)
}
}
// CallMaterialHandler POST /line/call-material(工位终端叫料:选接驳台)
func CallMaterialHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
StationNo int `json:"stationNo"`
Dock string `json:"dock"`
OrderNo string `json:"orderNo"`
Items []logic.CallMaterialItem `json:"items"`
}
if err := httpx.ParseJSON(r, &req); err != nil {
httpx.BadRequest(w, "请求体解析失败")
return
}
production.LogImpersonation(svcCtx, r, "", "/api/internal/line/call-material")
n, err := logic.New(svcCtx).CallMaterial(r.Context(), req.StationNo, req.Dock, req.OrderNo, production.StationOp(r, ""), req.Items)
if err != nil {
httpx.Fail(w, 2406, err.Error())
return
}
httpx.OkMessage(w, "叫料已提交", map[string]any{"count": n})
}
}
+2
View File
@@ -25,6 +25,8 @@ var pathPermMap = map[string]string{
// 数量不符处理(produce.qty 菜单下:补发/退库/调整关闭)
"POST:/api/v1/qty-reports/handle": "produce.qty:handle",
"POST:/api/v1/plc/send-process": "produce.plc:send",
"POST:/api/v1/plc/mismatch/override": "produce.plc.mismatch:override",
"POST:/api/v1/torque/dispose": "produce.torque:dispose",
"POST:/api/v1/process-flows": "produce.processflow:add",
"POST:/api/v1/process-flows/status": "produce.processflow:edit",
"DELETE:/api/v1/process-flows/*": "produce.processflow:delete",
@@ -74,3 +74,33 @@ func PlcMismatchCheckInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFun
})
}
}
// PlcMismatchOverrideReq 管理员 override 请求(#8 supervisor override 端点)
type PlcMismatchOverrideReq struct {
StationNo int `json:"stationNo"`
Reason string `json:"reason"`
Operator string `json:"operator"`
}
// PlcMismatchOverrideHandler POST /api/v1/plc/mismatch/override
// 管理员 override:关闭某工位的 PLC↔MES 对账告警(静默 30 分钟),用于误报/人工处置后解除阻断。
// 权限:produce.plc.mismatch:override(仅 SUPER_ADMIN 等管理员级角色,见 perm.go pathPermMap)。
func PlcMismatchOverrideHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req PlcMismatchOverrideReq
if err := httpx.ParseJSON(r, &req); err != nil {
httpx.BadRequest(w, "请求体解析失败")
return
}
op := operator(r, req.Operator)
if req.StationNo <= 0 {
httpx.BadRequest(w, "工位号无效")
return
}
if err := logic.New(svcCtx).ResolveMismatchOverride(r.Context(), req.StationNo, req.Reason, op); err != nil {
httpx.Fail(w, 2403, err.Error())
return
}
httpx.Ok(w, map[string]any{"stationNo": req.StationNo, "overridden": true})
}
}
@@ -0,0 +1,159 @@
package production
import (
"net/http"
"strconv"
"bj_power_mes/common/httpx"
"bj_power_mes/internal/logic"
"bj_power_mes/internal/svc"
)
// ============ AGV 调度(2026-10-14 由 WMS 迁至 MES 为唯一真源) ============
// 业务接口(/api/v1) 供 MES 前端;内部接口(/api/internal) 供 WMS 代理转发;
// SPI 回调(/api/spi) 供海康 RCS 主动回调(需在 RCS 后台配置上层回调地址,生产环境以防火墙/IP 白名单隔离)。
// SubmitAgvHandler 手动下发 AGV(WMS「下发AGV」页 / MES 前端):按 target_dock 聚合派车。
func SubmitAgvHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req logic.AgvSubmitRequest
if err := httpx.ParseJSON(r, &req); err != nil {
httpx.BadRequest(w, "请求体解析失败")
return
}
operator := r.Header.Get("X-Username")
if operator == "" {
operator = "dispatcher"
}
created, failed, err := logic.New(svcCtx).SubmitAgv(r.Context(), req, operator)
if err != nil {
httpx.Fail(w, 3301, err.Error())
return
}
httpx.Ok(w, map[string]any{"created": created, "failed": failed})
}
}
// ListAgvTasksHandler 查询 AGV 任务列表(分页)。
func ListAgvTasksHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
page := atoiSafe(q.Get("page"), 1)
size := atoiSafe(q.Get("pageSize"), 20)
data, err := logic.New(svcCtx).ListAgvTasks(r.Context(), q.Get("status"), q.Get("targetDock"), page, size)
if err != nil {
httpx.Fail(w, 3302, err.Error())
return
}
httpx.Ok(w, data)
}
}
// RefreshAgvTasksHandler 轮询海康 RCS 刷新未终态任务状态。
func RefreshAgvTasksHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
changed, err := logic.New(svcCtx).RefreshAgvTasks(r.Context())
if err != nil {
httpx.Fail(w, 3303, err.Error())
return
}
httpx.Ok(w, map[string]any{"changed": changed})
}
}
// CancelAgvTaskHandler 取消 AGV 任务(软取消)。
func CancelAgvTaskHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
TaskNo string `json:"taskNo"`
Reason string `json:"reason"`
}
if err := httpx.ParseJSON(r, &req); err != nil || req.TaskNo == "" {
httpx.BadRequest(w, "缺少任务号")
return
}
operator := r.Header.Get("X-Username")
if operator == "" {
operator = "dispatcher"
}
if err := logic.New(svcCtx).CancelAgvTask(r.Context(), req.TaskNo, req.Reason, operator); err != nil {
httpx.Fail(w, 3304, err.Error())
return
}
httpx.OkMessage(w, "已取消", nil)
}
}
// AgvModeHandler 返回 AGV 对接模式(mock / 真实 RCS)。
func AgvModeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
httpx.Ok(w, logic.New(svcCtx).AgvMode())
}
}
// DispatchAgvInternalHandler POST /api/internal/agv/dispatch
// WMS 仓库完成备料后调用(X-API-TOKEN):MES 据叫料单触发海康 RCS 派车。
func DispatchAgvInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
RequestNo string `json:"requestNo"`
Operator string `json:"operator"`
OutboundNo string `json:"outboundNo"`
}
if err := httpx.ParseJSON(r, &req); err != nil || req.RequestNo == "" {
httpx.BadRequest(w, "缺少叫料单号")
return
}
op := req.Operator
if op == "" {
op = "warehouse"
}
mr, err := logic.New(svcCtx).LoadCallForDispatch(r.Context(), req.RequestNo)
if err != nil {
httpx.Fail(w, 3305, err.Error())
return
}
if !mr.NeedAgv || mr.TargetDock == "" {
httpx.OkMessage(w, "该叫料单无需 AGV 派车", nil)
return
}
if derr := logic.New(svcCtx).DispatchAgvForCall(r.Context(), mr, op); derr != nil {
httpx.Fail(w, 3306, "AGV 派车失败: "+derr.Error())
return
}
httpx.OkMessage(w, "AGV 已派车", nil)
}
}
// AgvCallbackHandler POST /api/spi/agv/callback 海康 RCS SPI 任务状态回调(文档 2.2.1)。
// 注意:RCS 回调不带我方鉴权头,生产环境必须以防火墙/IP 白名单隔离该端点(待与 RCS 方确认鉴权方式)。
func AgvCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var body struct {
RobotTaskCode string `json:"robotTaskCode"`
TaskStatus string `json:"taskStatus"`
Method string `json:"method"`
}
if err := httpx.ParseJSON(r, &body); err != nil {
httpx.BadRequest(w, "回调报文解析失败")
return
}
if err := logic.New(svcCtx).ApplyAgvCallback(r.Context(), body.RobotTaskCode, body.TaskStatus, body.Method); err != nil {
httpx.Fail(w, 3307, err.Error())
return
}
httpx.OkMessage(w, "ok", nil)
}
}
// atoiSafe 安全解析分页参数(非法/缺省回退 def)。
func atoiSafe(s string, def int) int {
if s == "" {
return def
}
n, err := strconv.Atoi(s)
if err != nil || n < 1 {
return def
}
return n
}
@@ -0,0 +1,210 @@
package production
import (
"net/http"
"strconv"
"bj_power_mes/common/httpx"
"bj_power_mes/internal/logic"
"bj_power_mes/internal/svc"
)
// ============ B5 叫料(2026-10-13 定稿) ============
// 工位端点(pool/create/cancel/sign/return):StationSessionAuth 登录态鉴权,操作人与工位号取可信注入头;
// 仓库端点(complete/reject/return-confirm):X-API-TOKEN 内部网关,操作人取请求体(WMS 后端透传)。
// CallPoolInternalHandler GET /api/internal/call/pool?stationNo= 叫料池行(四数+可用量)。
func CallPoolInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
stationNo := StationNo(r, 0)
if n, err := strconv.Atoi(r.URL.Query().Get("stationNo")); err == nil && n > 0 {
stationNo = n
}
if stationNo <= 0 {
httpx.BadRequest(w, "缺少工位号")
return
}
rows, err := logic.New(svcCtx).StationPool(r.Context(), stationNo)
if err != nil {
httpx.Fail(w, 3201, err.Error())
return
}
httpx.Ok(w, rows)
}
}
// CreateCallHandler POST /api/internal/call/create 发起叫料(按物料行拆 N 张单,占用池子可用量)。
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"`
}
if err := httpx.ParseJSON(r, &req); err != nil {
httpx.BadRequest(w, "请求体解析失败")
return
}
stationNo := StationNo(r, req.StationNo)
n, err := logic.New(svcCtx).CreateCallOrders(r.Context(), stationNo, req.Items,
req.Source, req.RefReportNo, StationOp(r, ""))
if err != nil {
httpx.Fail(w, 3202, err.Error())
return
}
httpx.OkMessage(w, "叫料已提交", map[string]any{"count": n})
}
}
// CancelCallHandler POST /api/internal/call/cancel 取消叫料(仅待备料,工位本人)。
func CancelCallHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
RequestNo string `json:"requestNo"`
StationNo int `json:"stationNo"`
}
if err := httpx.ParseJSON(r, &req); err != nil || req.RequestNo == "" {
httpx.BadRequest(w, "缺少叫料单号")
return
}
if err := logic.New(svcCtx).CancelCall(r.Context(), req.RequestNo, StationNo(r, req.StationNo), StationOp(r, "")); err != nil {
httpx.Fail(w, 3203, err.Error())
return
}
httpx.OkMessage(w, "已取消", nil)
}
}
// SignCallHandler POST /api/internal/call/sign 签收(仅已发货;签收=确认收到,系统不再对差异)。
func SignCallHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
RequestNo string `json:"requestNo"`
StationNo int `json:"stationNo"`
}
if err := httpx.ParseJSON(r, &req); err != nil || req.RequestNo == "" {
httpx.BadRequest(w, "缺少叫料单号")
return
}
if err := logic.New(svcCtx).SignCall(r.Context(), req.RequestNo, StationNo(r, req.StationNo), StationOp(r, "")); err != nil {
httpx.Fail(w, 3204, err.Error())
return
}
httpx.OkMessage(w, "已签收", nil)
}
}
// ReturnCallHandler POST /api/internal/call/return 申请退库(仅已发货/签收前;整单退)。
func ReturnCallHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
RequestNo string `json:"requestNo"`
StationNo int `json:"stationNo"`
}
if err := httpx.ParseJSON(r, &req); err != nil || req.RequestNo == "" {
httpx.BadRequest(w, "缺少叫料单号")
return
}
if err := logic.New(svcCtx).RequestReturn(r.Context(), req.RequestNo, StationNo(r, req.StationNo), StationOp(r, "")); err != nil {
httpx.Fail(w, 3205, err.Error())
return
}
httpx.OkMessage(w, "退库已申请,等待仓库收回", nil)
}
}
// CompleteCallHandler POST /api/internal/call/complete 仓库完成备料通知(WMS 本地扣库存后调用):
// PENDING → SHIPPED,记实发量与 WMS 出库单号;占用释放、池子已发累加。
func CompleteCallHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
RequestNo string `json:"requestNo"`
SentQty float64 `json:"sentQty"` // 实发量(≤0=全发)
OutboundNo string `json:"outboundNo"`
Operator string `json:"operator"`
}
if err := httpx.ParseJSON(r, &req); err != nil || req.RequestNo == "" {
httpx.BadRequest(w, "缺少叫料单号")
return
}
op := req.Operator
if op == "" {
op = "warehouse"
}
if err := logic.New(svcCtx).CompleteCall(r.Context(), req.RequestNo, req.SentQty, req.OutboundNo, op); err != nil {
httpx.Fail(w, 3206, err.Error())
return
}
httpx.OkMessage(w, "已完成备料", nil)
}
}
// RejectCallHandler POST /api/internal/call/reject 仓库驳回(仅待备料;理由必填,异常标记:非当日等)。
func RejectCallHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
RequestNo string `json:"requestNo"`
Reason string `json:"reason"`
Operator string `json:"operator"`
}
if err := httpx.ParseJSON(r, &req); err != nil || req.RequestNo == "" {
httpx.BadRequest(w, "缺少叫料单号")
return
}
op := req.Operator
if op == "" {
op = "warehouse"
}
if err := logic.New(svcCtx).RejectCall(r.Context(), req.RequestNo, req.Reason, op); err != nil {
httpx.Fail(w, 3207, err.Error())
return
}
httpx.OkMessage(w, "已驳回", nil)
}
}
// ConfirmReturnHandler POST /api/internal/call/return-confirm 仓库确认收回(退库闭环终点):
// RETURNING → RETURNED,池子已发额度回补。
func ConfirmReturnHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
RequestNo string `json:"requestNo"`
Operator string `json:"operator"`
}
if err := httpx.ParseJSON(r, &req); err != nil || req.RequestNo == "" {
httpx.BadRequest(w, "缺少叫料单号")
return
}
op := req.Operator
if op == "" {
op = "warehouse"
}
if err := logic.New(svcCtx).ConfirmReturn(r.Context(), req.RequestNo, op); err != nil {
httpx.Fail(w, 3208, err.Error())
return
}
httpx.OkMessage(w, "已确认收回,叫料单关闭", nil)
}
}
// AdjustPoolHandler POST /api/internal/call/pool-adjust 叫料池人工改量(同工艺多工位场景;留痕)。
func AdjustPoolHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
StationNo int `json:"stationNo"`
MaterialCode string `json:"materialCode"`
NewQty int `json:"newQty"`
Operator string `json:"operator"`
}
if err := httpx.ParseJSON(r, &req); err != nil {
httpx.BadRequest(w, "请求体解析失败")
return
}
if err := logic.New(svcCtx).AdjustPoolQty(r.Context(), req.StationNo, req.MaterialCode, req.NewQty, req.Operator); err != nil {
httpx.Fail(w, 3209, err.Error())
return
}
httpx.OkMessage(w, "已调整", nil)
}
}
@@ -57,59 +57,13 @@ func ListMaterialsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
}
// ---------- 备料单 ----------
// ---------- 叫料单(B5:只读列表;发起/签收/退库/取消在工位终端,完成/驳回/收回在仓库端) ----------
// GenerateMaterialHandler 按日排产生成备料单(生成前校验物料清单物料在 WMS 档案存在)
func GenerateMaterialHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
PlanDate string `json:"planDate"`
}
if err := httpx.ParseJSON(r, &req); err != nil {
httpx.BadRequest(w, "请求体解析失败")
return
}
count, missing, err := logic.New(svcCtx).GenerateMaterialRequest(r.Context(), req.PlanDate, operator(r, ""))
if err != nil {
httpx.Fail(w, 3103, err.Error())
return
}
if len(missing) > 0 {
// 有物料在 WMS 档案不存在:不生成,把缺失列表返回给前端弹窗
httpx.Ok(w, map[string]any{"count": 0, "missing": missing, "blocked": true})
return
}
httpx.OkMessage(w, "生成完成", map[string]any{"count": count, "blocked": false})
}
}
// AutoOutboundHandler POST /material-requests/auto-outbound 备料自动出库(一键补出)。
// 日常由「生成备料单」自动触发(客户第1条:平时无需操作);库存补齐后库管可在此一键补出。
func AutoOutboundHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
PlanDate string `json:"planDate"`
OrderNo string `json:"orderNo"`
}
if err := httpx.ParseJSON(r, &req); err != nil {
httpx.BadRequest(w, "请求体解析失败")
return
}
if req.PlanDate == "" && req.OrderNo == "" {
httpx.BadRequest(w, "planDate 与 orderNo 至少填一个")
return
}
done, short := logic.New(svcCtx).AutoOutboundRequests(r.Context(), req.PlanDate, req.OrderNo, operator(r, ""))
httpx.OkMessage(w, "自动出库完成", map[string]any{"done": done, "short": short})
}
}
func ListMaterialRequestsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
// ListCallsHandler GET /material-requests 叫料单列表(MES 后台只读视图)。
func ListCallsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
data, err := logic.New(svcCtx).ListMaterialRequests(r.Context(), logic.MaterialRequestQuery{
OrderNo: q.Get("orderNo"),
PlanDate: q.Get("planDate"),
data, err := logic.New(svcCtx).ListCalls(r.Context(), logic.CallQuery{
Status: q.Get("status"),
MaterialCode: q.Get("materialCode"),
MaterialName: q.Get("materialName"),
@@ -126,16 +80,16 @@ func ListMaterialRequestsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
}
// ListMaterialRequestsInternalHandler 内部接口:供 WMS 拉取备料单(含 target_dock),X-API-TOKEN 保护。
// WMS AGV 配送页据此展示待发料行,仓管确认 target_dock 后调用 WMS AGV 下发。
func ListMaterialRequestsInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
// ListCallsInternalHandler 内部接口:供 WMS 叫料队列/终端拉取叫料单,X-API-TOKEN 保护。
func ListCallsInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
data, err := logic.New(svcCtx).ListMaterialRequests(r.Context(), logic.MaterialRequestQuery{
OrderNo: q.Get("orderNo"),
PlanDate: q.Get("planDate"),
Status: q.Get("status"),
StationNo: q.Get("stationNo"),
data, err := logic.New(svcCtx).ListCalls(r.Context(), logic.CallQuery{
Status: q.Get("status"),
MaterialCode: q.Get("materialCode"),
StationNo: q.Get("stationNo"),
Source: q.Get("source"),
RequestNo: q.Get("requestNo"),
})
if err != nil {
httpx.Fail(w, 3105, err.Error())
@@ -144,81 +98,3 @@ func ListMaterialRequestsInternalHandler(svcCtx *svc.ServiceContext) http.Handle
httpx.Ok(w, data)
}
}
// MarkMaterialRequestStatusInternalHandler 内部接口:WMS 下发 AGV 后回写备料单状态(DELIVERING/DONE)。
// 供 WMS AGV 任务推进状态时联动 MES 备料单,保持一致。
func MarkMaterialRequestStatusInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
RequestNo string `json:"requestNo"`
Status string `json:"status"`
}
if err := httpx.ParseJSON(r, &req); err != nil || req.RequestNo == "" {
httpx.BadRequest(w, "请求体缺失")
return
}
// 备料单状态词表:PENDING(待备料)/LOCKED(已备料已出库)/DELIVERING(配送中)/DONE(已接料完结)
// WMS 取消 AGV 后回退用 PENDING(待备料),与 MES 词表对齐(修复 WAIT_SEND 越界静默失败)
if req.Status != "DELIVERING" && req.Status != "DONE" && req.Status != "PENDING" {
httpx.Fail(w, 3106, "非法状态")
return
}
if err := logic.New(svcCtx).SetMaterialRequestStatus(r.Context(), req.RequestNo, req.Status); err != nil {
httpx.Fail(w, 3106, err.Error())
return
}
httpx.Ok(w, nil)
}
}
// ---------- 接驳台 / 接料确认 ----------
// 接驳台查询/维护接口见 dock.go(真源已迁 MES 本地 dock 表)。
// ReceiveMaterialRequestHandler POST /material-requests/receive 接料确认(MES 备料页人工点「已接料」)。
// qty 可空(≤0 表示确认本批全部剩余);累加 receivedQty(已接料),上限为已发出量。
func ReceiveMaterialRequestHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
RequestNo string `json:"requestNo"`
Qty int `json:"qty"`
}
// ParseJSON 失败与 requestNo 为空分开报,避免误导入参正确却看不到真实原因(AITEST 闭环实测)
if err := httpx.ParseJSON(r, &req); err != nil {
httpx.BadRequest(w, "请求体解析失败")
return
}
if req.RequestNo == "" {
httpx.BadRequest(w, "缺少备料单号")
return
}
if err := logic.New(svcCtx).ReceiveMaterialRequest(r.Context(), req.RequestNo, req.Qty, operator(r, "")); err != nil {
httpx.Fail(w, 3114, err.Error())
return
}
httpx.OkMessage(w, "已接料", nil)
}
}
// StationReceiveMaterialInternalHandler POST /api/internal/station/receive-material 接料确认内部接口。
// 供工位终端代理调用(工人扫码接料主入口),X-API-TOKEN 保护。逻辑同 ReceiveMaterialRequestHandler。
func StationReceiveMaterialInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
RequestNo string `json:"requestNo"`
Qty int `json:"qty"`
}
if err := httpx.ParseJSON(r, &req); err != nil {
httpx.BadRequest(w, "请求体解析失败")
return
}
if req.RequestNo == "" {
httpx.BadRequest(w, "缺少备料单号")
return
}
if err := logic.New(svcCtx).ReceiveMaterialRequest(r.Context(), req.RequestNo, req.Qty, StationOp(r, "")); err != nil {
httpx.Fail(w, 3114, err.Error())
return
}
httpx.Ok(w, nil)
}
}
@@ -93,6 +93,24 @@ func TorqueRecordsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
}
// TorqueDispositionHandler 拧紧不合格人工处置(B6 最小闭环,质检/班组长确认放行):
// 清标记 + 写 event_log(谁/何时/原因) + 置对应 torque_ng 预警 resolved。
// 后端权限码 produce.torque:dispose(perm.go pathPermMap 兜底校验,仅 INSPECTOR/SUPER_ADMIN 持有)。
func TorqueDispositionHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req logic.TorqueDisposeReq
if err := httpx.ParseJSON(r, &req); err != nil {
httpx.BadRequest(w, "请求体解析失败")
return
}
if err := logic.New(svcCtx).DisposeTorqueNg(r.Context(), req, operator(r, "")); err != nil {
httpx.Fail(w, 3205, err.Error())
return
}
httpx.OkMessage(w, "已确认放行", nil)
}
}
// ProcessStepsHandler 查询工位的工序步骤(参数采集模板),供巡检终端等按工位动态渲染。
// 按 stationNo 加载该工位启用工艺流程的工序步骤。
func ProcessStepsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
@@ -113,10 +113,7 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
Method: http.MethodGet, Path: "/api/internal/order-usage", Handler: internal(production.OrderUsageInternalHandler(serverCtx)),
})
server.AddRoute(rest.Route{
Method: http.MethodGet, Path: "/api/internal/material-requests", Handler: internal(production.ListMaterialRequestsInternalHandler(serverCtx)),
})
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/internal/material-request/status", Handler: internal(production.MarkMaterialRequestStatusInternalHandler(serverCtx)),
Method: http.MethodGet, Path: "/api/internal/material-requests", Handler: internal(production.ListCallsInternalHandler(serverCtx)),
})
server.AddRoute(rest.Route{
Method: http.MethodGet, Path: "/api/internal/dock/pallet", Handler: internal(production.DockPalletInternalHandler(serverCtx)),
@@ -145,14 +142,64 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
server.AddRoute(rest.Route{
Method: http.MethodGet, Path: "/api/internal/line/points", Handler: internal(ListPointsHandler(serverCtx)),
})
// ---------- 叫料(B5,供工位终端/WMS 仓库端调用,X-API-TOKEN 保护)----------
// 工位端点:StationSessionAuth 登录态鉴权(操作人/工位号可信注入)
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/internal/line/call-material", Handler: internal(production.StationSessionAuth(serverCtx)(CallMaterialHandler(serverCtx))),
Method: http.MethodGet, Path: "/api/internal/call/pool", Handler: internal(production.StationSessionAuth(serverCtx)(production.CallPoolInternalHandler(serverCtx))),
})
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/internal/call/create", Handler: internal(production.StationSessionAuth(serverCtx)(production.CreateCallHandler(serverCtx))),
})
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/internal/call/cancel", Handler: internal(production.StationSessionAuth(serverCtx)(production.CancelCallHandler(serverCtx))),
})
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/internal/call/sign", Handler: internal(production.StationSessionAuth(serverCtx)(production.SignCallHandler(serverCtx))),
})
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/internal/call/return", Handler: internal(production.StationSessionAuth(serverCtx)(production.ReturnCallHandler(serverCtx))),
})
// 仓库端点:完成备料/驳回/确认收回(WMS 后端以 X-API-TOKEN 调用)
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/internal/call/complete", Handler: internal(production.CompleteCallHandler(serverCtx)),
})
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/internal/call/reject", Handler: internal(production.RejectCallHandler(serverCtx)),
})
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/internal/call/return-confirm", Handler: internal(production.ConfirmReturnHandler(serverCtx)),
})
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/internal/call/pool-adjust", Handler: internal(production.AdjustPoolHandler(serverCtx)),
})
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/internal/line/occupy", Handler: internal(production.StationSessionAuth(serverCtx)(OccupyPointHandler(serverCtx))),
})
// PLC↔MES 对账检查(#8):终端 T2/T3 经由本内部路由代理访问(X-API-TOKEN 保护)。
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/internal/station/receive-material", Handler: internal(production.StationSessionAuth(serverCtx)(production.StationReceiveMaterialInternalHandler(serverCtx))),
Method: http.MethodPost, Path: "/api/internal/plc/mismatch/check", Handler: internal(PlcMismatchCheckInternalHandler(serverCtx)),
})
// ---------- AGV 调度(2026-10-14 迁 MES 为唯一真源,海康 RCS) ----------
// WMS 仓库端「AGV配送」页透明代理到本组(X-API-TOKEN 保护);MES 是 AGV 任务与 RCS 客户端唯一真源。
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/internal/agv/submit", Handler: internal(production.SubmitAgvHandler(serverCtx)),
})
server.AddRoute(rest.Route{
Method: http.MethodGet, Path: "/api/internal/agv/tasks", Handler: internal(production.ListAgvTasksHandler(serverCtx)),
})
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/internal/agv/refresh", Handler: internal(production.RefreshAgvTasksHandler(serverCtx)),
})
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/internal/agv/cancel", Handler: internal(production.CancelAgvTaskHandler(serverCtx)),
})
server.AddRoute(rest.Route{
Method: http.MethodGet, Path: "/api/internal/agv/mode", Handler: internal(production.AgvModeHandler(serverCtx)),
})
// 叫料完成备料后由 MES 自动派车(CompleteCall 内部已触发);此端点为手动补派/重试专用
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/internal/agv/dispatch", Handler: internal(production.DispatchAgvInternalHandler(serverCtx)),
})
// ---------- JWT 业务 API ----------
@@ -185,16 +232,12 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
{Method: http.MethodPost, Path: "/daily-plans/:id/status", Handler: production.DailyPlanStatusHandler(serverCtx)},
{Method: http.MethodGet, Path: "/daily-plans/suggest-docks", Handler: production.SuggestedDockCodesHandler(serverCtx)},
{Method: http.MethodPost, Path: "/material-requests/generate", Handler: production.GenerateMaterialHandler(serverCtx)},
{Method: http.MethodGet, Path: "/material-requests", Handler: production.ListMaterialRequestsHandler(serverCtx)},
// 叫料单列表(B5:MES 后台只读视图;发起/签收/退库/取消在工位终端,完成/驳回/收回在仓库端)
{Method: http.MethodGet, Path: "/material-requests", Handler: production.ListCallsHandler(serverCtx)},
// 物料档案(代理 WMS /api/internal/materials,WMS 是物料主数据源;WMS 不可达返回空列表)
{Method: http.MethodGet, Path: "/materials", Handler: production.ListMaterialsHandler(serverCtx)},
// 工单单台用料(物料清单已删除:工单详情页只读汇总 = 工单工艺组合×工艺物料清单)
{Method: http.MethodGet, Path: "/order-usage", Handler: production.OrderUsageHandler(serverCtx)},
{Method: http.MethodPost, Path: "/material-requests/receive", Handler: production.ReceiveMaterialRequestHandler(serverCtx)},
{Method: http.MethodPost, Path: "/material-requests/auto-outbound", Handler: production.AutoOutboundHandler(serverCtx)},
// 配送进度(只读聚合:WMS 台账四段量 + MES 已接料 → 在途/线边)
{Method: http.MethodGet, Path: "/material-requests/progress", Handler: MaterialDeliveryProgressHandler(serverCtx)},
// 数量不符处理(MES 为唯一真源与处理侧;上报入口在 /api/internal/station/qty-report)
{Method: http.MethodGet, Path: "/qty-reports", Handler: ListQtyReportsHandler(serverCtx)},
{Method: http.MethodGet, Path: "/qty-reports/stats", Handler: QtyReportStatsHandler(serverCtx)},
@@ -206,10 +249,24 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
{Method: http.MethodGet, Path: "/plc/send-logs", Handler: production.PlcSendLogsHandler(serverCtx)},
// PLC↔MES 对账检查(#8):终端 T2/T3 单工位(弹终端)、系统 T6/T7 全量 11 位(落预警中心)。事件驱动,禁止定时轮询。
// MES 前端(T7 手动核对)与管理后台走本 JWT 路由;工位终端经 /api/internal/plc/mismatch/check 代理。
{Method: http.MethodPost, Path: "/plc/mismatch/check", Handler: PlcMismatchCheckInternalHandler(serverCtx)},
// PLC↔MES 对账管理员 override(#8 supervisor override):关闭某工位对账告警(静默 30 分钟)。
// 权限码 produce.plc.mismatch:override(仅管理员级角色);与操作工忽略严格区分。
{Method: http.MethodPost, Path: "/plc/mismatch/override", Handler: PlcMismatchOverrideHandler(serverCtx)},
// ---------- AGV 调度(MES 前端,2026-10-14 迁 MES 为唯一真源) ----------
// 与 WMS 代理端点同源:WMS 仓管「AGV配送」页经 /api/internal/agv/* 转发;MES 前端直接走本组。
{Method: http.MethodPost, Path: "/agv/submit", Handler: production.SubmitAgvHandler(serverCtx)},
{Method: http.MethodGet, Path: "/agv/tasks", Handler: production.ListAgvTasksHandler(serverCtx)},
{Method: http.MethodPost, Path: "/agv/refresh", Handler: production.RefreshAgvTasksHandler(serverCtx)},
{Method: http.MethodPost, Path: "/agv/cancel", Handler: production.CancelAgvTaskHandler(serverCtx)},
{Method: http.MethodGet, Path: "/agv/mode", Handler: production.AgvModeHandler(serverCtx)},
{Method: http.MethodPost, Path: "/torque/report", Handler: production.TorqueReportHandler(serverCtx)},
{Method: http.MethodGet, Path: "/torque/records", Handler: production.TorqueRecordsHandler(serverCtx)},
// 拧紧不合格人工处置(质检/班组长确认放行):清标记 + 写 event_log + 置预警 resolved。权限码 produce.torque:dispose。
{Method: http.MethodPost, Path: "/torque/dispose", Handler: production.TorqueDispositionHandler(serverCtx)},
// ---------- 签字机制(需求B):操作工报工签字随 /workpiece/report 落库;检验员签字为独立动作 ----------
{Method: http.MethodPost, Path: "/signs/inspector", Handler: production.InspectorSignHandler(serverCtx)},
@@ -276,7 +333,6 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
{Method: http.MethodPost, Path: "/product-processes/status", Handler: SetProductProcessStatusHandler(serverCtx)},
{Method: http.MethodDelete, Path: "/product-processes/:id", Handler: DeleteProductProcessHandler(serverCtx)},
{Method: http.MethodGet, Path: "/line/points", Handler: ListPointsHandler(serverCtx)},
{Method: http.MethodPost, Path: "/line/call-material", Handler: CallMaterialHandler(serverCtx)},
// ---------- PAD 巡检终端(块8) ----------
{Method: http.MethodPost, Path: "/inspections", Handler: CreateInspectionHandler(serverCtx)},
@@ -330,6 +386,12 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
rest.WithMaxBytes(maxUploadBytes(serverCtx.Config.Upload.MaxMB, serverCtx.Config.Upload.MaxSize)),
)
// ---------- 海康 RCS SPI 主动回调(文档 2.2.1 任务状态回馈) ----------
// 注意:RCS 回调不携带我方鉴权头;生产环境必须以防火墙 / IP 白名单隔离该端点(待与 RCS 方确认鉴权方式)。
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/spi/agv/callback", Handler: production.AgvCallbackHandler(serverCtx),
})
// ---------- 公开文件访问(免 JWT) ----------
// <img>/el-image 发起的图片请求无法携带 Authorization 头,走 JWT 组会 401
// 导致"上传成功但页面图片加载失败"(2026-09-08 修复)。文件名为系统生成的