Files
bj_power/bj_power_wms/internal/handler/routes.go
T
SunYF f9eaebad28 feat(mes/wms/终端): 签字循环业务重构 + 叫料池实物账两列 + 工位流水按包真分页 + 下线单据提示条(2026-11-30 现场整改)
【MES · 签字循环重构(业务重构,非修 bug)】
- 旧模型作废(签字随报工落库、检验员分支永不生效的死代码);新口径:
  工人干完点「呼叫签字」→ 检验员巡检端签 OK/NG → OK 后工人再点一次「报工」;NG 整改后重新呼叫(新一轮)
- 内容指纹(SHA256):呼叫时算一次落库,报工时重算比对,变了即「签字后改数据作废本轮」要求重呼;
  只覆盖步骤录入(值/文本/勾选/拧紧结果),装机绑定不进指纹(独立台账)、改备注不触发
- 轮次统一:一次呼叫=一轮,操作工/检验员共用 round;NG/撤回/重呼=新一轮,旧轮作废历史保留
- 三档状态(作业中/签字中/待整改/可报工)从签字记录推导,不建表不存终端
- 报工闸门:本轮需签步骤齐全(操作工+检验员OK)+ 指纹未变才放行
- 撤回呼叫整轮作废;超时巡检每分钟扫描(阈值 30 分钟可在基础设置调),超时落预警中心+异常角标不进铃铛,60 分钟窗口去重
- 工位终端新增签字交互接口与呼叫/撤回/状态查询;巡检端保留 NG 回看

【MES · 叫料池实物账(十五节 Q1/Q16 + 17.6 裁决)】
- call_pool 新增 receivedQty(已收累计,拒收按退库单冲减)/ returnedQty(已退累计,按退库单号防重)两列实物账,与 sentQty 额度账并存
- 台面在手(可用)= 已收 − 已装 − 已退;在途 = 已发 − 已收

【工位终端 · 物料/叫料页重构(十五节 Q1~Q17 拍板落地)】
- 「本工位物料明细」改名「物料明细」,四数列改为:可用/需求/已发/已收/已装,量为 0 也显示不分左右托盘
- 去除「刷新池子」「刷新」按钮(有长连接);「我的叫料单」扩为类银行流水(叫料/退料/等等)
- 叫料/退料数量列直排,提交时弹窗确认数量并选接驳台;管理端叫料与退料 AGV 派车流程统一收归库管
- 工位流水按包真分页(2026-11-29 拍板):后端按包号分组 Count+Limit/Offset,每页 20 包,前端不再内存聚合

【下线 · 单据流转提示条】
- MES/WMS 前端整体删除 NextStepBar / nextStep / nextStepRules(35 条规则表整套下线),页面不再出现常驻「下一步」提示条

【文档】
- 问题临时.md 新增十四节(主控独立审计:终端账号删除/心跳/闸门函数 8 处对码全过)+ 十五节(工位物料叫料 8 条原话逐字留档与 Q1~Q17 拍板底稿)
- 新增《工位终端页面.md》;案例.md 同步更新验收口径
2026-11-30 15:25:29 +08:00

440 lines
32 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package handler
import (
"net/http"
"bj_power_wms/internal/svc"
"bj_power_wms/internal/ws"
"github.com/zeromicro/go-zero/rest"
)
func RegisterHandlers(server *rest.Server, ctx *svc.ServiceContext) {
server.AddRoutes(
[]rest.Route{
{Method: http.MethodGet, Path: "/api/health", Handler: healthHandler(ctx)},
{Method: http.MethodGet, Path: "/api/server-time", Handler: serverTimeHandler(ctx)},
{Method: http.MethodPost, Path: "/api/auth/login", Handler: loginHandler(ctx)},
},
)
// 附件静态文件(图纸 PDF / 图片预览):免鉴权,供 <a target=_blank> / 新窗口直接打开
server.AddRoutes(
[]rest.Route{
{Method: http.MethodGet, Path: "/uploads/:name", Handler: serveUploadFileHandler(ctx)},
},
)
// WebSocket 握手浏览器无法携带 Authorization 头,故 /api/todos/ws 跳过全局 JWT 中间件,
// 改由 todoWebSocketHandler 内部用 query 中的 token 复用 ParseToken 校验(问题8)。
jwtGuard := authInterceptor(ctx)
server.Use(func(next http.HandlerFunc) http.HandlerFunc {
guarded := jwtGuard(next)
return func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/api/todos/ws" {
next.ServeHTTP(w, r)
return
}
guarded(w, r)
}
})
// 当前登录用户(JWT 鉴权)
server.AddRoutes(
[]rest.Route{
{Method: http.MethodPost, Path: "/api/user/change-password", Handler: changePasswordHandler(ctx)},
{Method: http.MethodPost, Path: "/api/user/logout", Handler: logoutHandler(ctx)},
{Method: http.MethodGet, Path: "/api/user/info", Handler: userInfoHandler(ctx)},
{Method: http.MethodGet, Path: "/api/user/list", Handler: listUsersHandler(ctx)},
{Method: http.MethodPost, Path: "/api/user/create", Handler: createUserHandler(ctx)},
{Method: http.MethodPost, Path: "/api/user/update", Handler: updateUserHandler(ctx)},
{Method: http.MethodPost, Path: "/api/user/delete", Handler: deleteUserHandler(ctx)},
},
)
// 角色与权限(RBAC 数据化,取代 rbac.go 中的硬编码权限 map)
server.AddRoutes(
[]rest.Route{
{Method: http.MethodPost, Path: "/api/rbac/seed", Handler: seedRbacHandler(ctx)},
{Method: http.MethodGet, Path: "/api/roles", Handler: listRolesHandler(ctx)},
{Method: http.MethodGet, Path: "/api/roles/options", Handler: roleOptionsHandler(ctx)},
{Method: http.MethodPost, Path: "/api/roles", Handler: createRoleHandler(ctx)},
{Method: http.MethodPost, Path: "/api/roles/update", Handler: updateRoleHandler(ctx)},
{Method: http.MethodPost, Path: "/api/roles/delete", Handler: deleteRoleHandler(ctx)},
{Method: http.MethodGet, Path: "/api/permissions", Handler: listPermissionsHandler(ctx)},
{Method: http.MethodGet, Path: "/api/event/logs", Handler: eventLogListHandler(ctx)},
},
)
// 物料档案(写操作权限守卫;query/list/detail 供各页下拉拾取器使用,保持登录可访问)
server.AddRoutes(
[]rest.Route{
{Method: http.MethodPost, Path: "/api/material/create", Handler: requirePerm(ctx, "material:create", createMaterialHandler(ctx))},
{Method: http.MethodPost, Path: "/api/material/update", Handler: requirePerm(ctx, "material:edit", updateMaterialHandler(ctx))},
{Method: http.MethodGet, Path: "/api/material/query", Handler: queryMaterialsHandler(ctx)},
{Method: http.MethodGet, Path: "/api/material/list", Handler: listMaterialsHandler(ctx)},
{Method: http.MethodGet, Path: "/api/material/detail", Handler: getMaterialHandler(ctx)},
{Method: http.MethodGet, Path: "/api/material/export", Handler: requirePerm(ctx, "material:export", exportMaterialsHandler(ctx))},
{Method: http.MethodPost, Path: "/api/material/import", Handler: requirePerm(ctx, "material:import", excelMaterialImportHandler(ctx))},
{Method: http.MethodPost, Path: "/api/material/import/preview", Handler: requirePerm(ctx, "material:import", excelMaterialImportPreviewHandler(ctx))},
{Method: http.MethodGet, Path: "/api/material/import-template", Handler: requirePerm(ctx, "material:import", excelMaterialImportTemplateHandler(ctx))},
{Method: http.MethodPost, Path: "/api/material/toggle-status", Handler: requirePerm(ctx, "material:edit", toggleMaterialStatusHandler(ctx))},
{Method: http.MethodGet, Path: "/api/material/refs", Handler: requirePerm(ctx, "material:edit", materialRefsHandler(ctx))},
{Method: http.MethodPost, Path: "/api/material/delete", Handler: requirePerm(ctx, "material:edit", deleteMaterialHandler(ctx))},
{Method: http.MethodPost, Path: "/api/material/retry-sync", Handler: requirePerm(ctx, "material:edit", retryMaterialSyncHandler(ctx))},
},
)
// 同步失败台账(2026-11-08):只记「本地已提交、对端通知失败」的跨系统回调,人工重试,不自动重传
server.AddRoutes(
[]rest.Route{
{Method: http.MethodGet, Path: "/api/sync-failures", Handler: requirePerm(ctx, "sync:retry", syncFailureListHandler(ctx))},
{Method: http.MethodPost, Path: "/api/sync-failures/retry", Handler: requirePerm(ctx, "sync:retry", syncFailureRetryHandler(ctx))},
{Method: http.MethodPost, Path: "/api/sync-failures/ignore", Handler: requirePerm(ctx, "sync:retry", syncFailureIgnoreHandler(ctx))},
},
)
// 入库
server.AddRoutes(
[]rest.Route{
{Method: http.MethodPost, Path: "/api/inbound/create", Handler: createInboundHandler(ctx)},
{Method: http.MethodGet, Path: "/api/inbound/query", Handler: queryInboundHandler(ctx)},
{Method: http.MethodGet, Path: "/api/inbound/details", Handler: inboundDetailsHandler(ctx)},
{Method: http.MethodGet, Path: "/api/inbound/export", Handler: exportInboundHandler(ctx)},
{Method: http.MethodPost, Path: "/api/inbound/batch-excel", Handler: excelInboundHandler(ctx)},
{Method: http.MethodPost, Path: "/api/inbound/batch-excel/preview", Handler: excelInboundPreviewHandler(ctx)},
{Method: http.MethodGet, Path: "/api/inbound/import-template", Handler: excelInboundImportTemplateHandler(ctx)},
// 入库库位联动:选物料后回填最近一次入库库位
{Method: http.MethodGet, Path: "/api/inbound/last-location", Handler: lastInboundLocationHandler(ctx)},
// 入库作废:填原因 + 回滚库存(结构件按批次、电气件按 SN 精确回滚)
{Method: http.MethodPost, Path: "/api/inbound/void", Handler: requirePerm(ctx, "inbound:void", voidInboundHandler(ctx))},
},
)
// 出库(统一主表:备料出库 workorder / 通用出库 general,装箱信息落在同一张表)
server.AddRoutes(
[]rest.Route{
{Method: http.MethodPost, Path: "/api/outbound/general", Handler: requirePerm(ctx, "outbound:general", makeOutboundHandler(ctx, "general"))},
{Method: http.MethodPost, Path: "/api/outbound/project", Handler: requirePerm(ctx, "outbound:project", makeOutboundHandler(ctx, "project"))},
{Method: http.MethodGet, Path: "/api/outbound/query", Handler: queryOutboundHandler(ctx)},
{Method: http.MethodGet, Path: "/api/outbound/export", Handler: exportOutboundHandler(ctx)},
// 出库库位联动:优先批次在库库位,其次该物料最近一次入库库位(客户诉求 一.9「出库相同」)
{Method: http.MethodGet, Path: "/api/outbound/location-hint", Handler: outboundLocationHintHandler(ctx)},
// 出库作废(2026-11-03 断头路补全,对齐入库作废):仅通用/科技项目出库可作废,
// 填原因+按明细回滚库存;备料/补料/叫料出库不在此列,走退库逆向闭环。
{Method: http.MethodPost, Path: "/api/outbound/void", Handler: requirePerm(ctx, "outbound:void", voidOutboundHandler(ctx))},
// 目标工位下拉选项(需求20:来自 MES 工位列表,不允许手输)
{Method: http.MethodGet, Path: "/api/outbound/stations", Handler: listStationOptionsHandler(ctx)},
// B5 叫料队列(仓库端):待备料列表 / 完成备料(WMS 扣库存+通知 MES)/ 驳回
{Method: http.MethodGet, Path: "/api/call/pending", Handler: requirePerm(ctx, "call:view", callPendingHandler(ctx))},
{Method: http.MethodPost, Path: "/api/call/complete", Handler: requirePerm(ctx, "call:manage", callCompleteHandler(ctx))},
// 2026-11-26:批量完成备料(同包多条一次扣库,整包预检+逐单复用单条逻辑,不改底层出库)
{Method: http.MethodPost, Path: "/api/call/complete-batch", Handler: requirePerm(ctx, "call:manage", callBatchCompleteHandler(ctx))},
{Method: http.MethodPost, Path: "/api/call/reject", Handler: requirePerm(ctx, "call:manage", callRejectHandler(ctx))},
// 托盘工作台(2026-11-03):接驳台台账列表 + 手动派 AGV 回收空托盘(单点步进、到位待令)
{Method: http.MethodGet, Path: "/api/pallet/docks", Handler: PalletDocksHandler(ctx)},
{Method: http.MethodGet, Path: "/api/pallet/station-docks", Handler: StationDocksProxyHandler(ctx)},
{Method: http.MethodPost, Path: "/api/pallet/dispatch", Handler: requirePerm(ctx, "call:manage", PalletDispatchHandler(ctx))},
// E4 托盘余料明细(2026-11-04 拍板):代发起退料弹窗自动带出(只读转发 MES)
{Method: http.MethodGet, Path: "/api/pallet/residual", Handler: palletResidualHandler(ctx)},
// JBT21 空位查询(2026-11-04 定稿 Q5:无空位派 AGV 回收按钮禁用并提示;只读转发 MES)
{Method: http.MethodGet, Path: "/api/pallet/jbt21-free", Handler: Jbt21FreeHandler(ctx)},
// 人工清台(2026-11-05 兜底:托盘被人工卸走后台账卡死;仅清台账不碰账)
{Method: http.MethodPost, Path: "/api/pallet/clear", Handler: requirePerm(ctx, "call:manage", palletClearHandler(ctx))},
// 配送单(2026-11-26 按工位凑车:一单=一托盘=一工位;2026-11-27 锁改派车:可建多张待配送单、同一时刻只允许一张在途)
{Method: http.MethodGet, Path: "/api/delivery/list", Handler: requirePerm(ctx, "call:view", deliveryListHandler(ctx))},
{Method: http.MethodGet, Path: "/api/delivery/detail", Handler: requirePerm(ctx, "call:view", deliveryDetailHandler(ctx))},
{Method: http.MethodGet, Path: "/api/delivery/workstations", Handler: requirePerm(ctx, "call:view", deliveryWorkstationsHandler(ctx))},
{Method: http.MethodGet, Path: "/api/delivery/station", Handler: requirePerm(ctx, "call:view", deliveryStationHandler(ctx))},
{Method: http.MethodGet, Path: "/api/delivery/active", Handler: requirePerm(ctx, "call:view", deliveryActiveHandler(ctx))},
{Method: http.MethodPost, Path: "/api/delivery/create", Handler: requirePerm(ctx, "call:manage", deliveryCreateHandler(ctx))},
{Method: http.MethodPost, Path: "/api/delivery/update", Handler: requirePerm(ctx, "call:manage", deliveryUpdateHandler(ctx))},
{Method: http.MethodPost, Path: "/api/delivery/delete", Handler: requirePerm(ctx, "call:manage", deliveryDeleteHandler(ctx))},
{Method: http.MethodPost, Path: "/api/delivery/dispatch", Handler: requirePerm(ctx, "call:manage", deliveryDispatchHandler(ctx))},
// WMS 代叫料(2026-11-05 拍板:与工位终端同一套叫料包逻辑)
{Method: http.MethodPost, Path: "/api/call/create", Handler: requirePerm(ctx, "call:manage", callCreateProxyHandler(ctx))},
{Method: http.MethodGet, Path: "/api/call/pool-raw", Handler: requirePerm(ctx, "call:view", callPoolRawProxyHandler(ctx))},
// 库管代工位补料申请(2026-11-14 用户第16条):只转发 MES 生成待审批补料单,WMS 不审批/不调额度
{Method: http.MethodPost, Path: "/api/shortage/on-behalf", Handler: requirePerm(ctx, "call:manage", shortageOnBehalfHandler(ctx))},
},
)
// P1 备料清单(2026-11-04 用户拍板):只读展示"今天及以后×工单×工位×物料×数量",数据源 MES 日排产实时算
server.AddRoutes(
[]rest.Route{
{Method: http.MethodGet, Path: "/api/preparation/list", Handler: requirePerm(ctx, "preparation:view", queryPreparationListHandler(ctx))},
},
)
// 库存
server.AddRoutes(
[]rest.Route{
{Method: http.MethodGet, Path: "/api/stock/query", Handler: queryStockHandler(ctx)},
{Method: http.MethodGet, Path: "/api/stock/material-summary", Handler: materialSummaryHandler(ctx)},
{Method: http.MethodGet, Path: "/api/stock/details", Handler: stockDetailsHandler(ctx)},
{Method: http.MethodGet, Path: "/api/stock/export", Handler: exportStockHandler(ctx)},
{Method: http.MethodGet, Path: "/api/stock/zone-summary", Handler: zoneSummaryHandler(ctx)},
{Method: http.MethodPost, Path: "/api/stock/lock", Handler: lockStockHandler(ctx)},
{Method: http.MethodPost, Path: "/api/stock/unlock", Handler: unlockStockHandler(ctx)},
{Method: http.MethodPost, Path: "/api/stock/check", Handler: checkStockHandler(ctx)},
{Method: http.MethodGet, Path: "/api/stock/shortage", Handler: shortageHandler(ctx)},
{Method: http.MethodGet, Path: "/api/stock/material-demand", Handler: materialDemandHandler(ctx)},
},
)
// 检验
server.AddRoutes(
[]rest.Route{
{Method: http.MethodPost, Path: "/api/inspection/batch-flip", Handler: batchFlipInspectionHandler(ctx)},
{Method: http.MethodPost, Path: "/api/inspection/dispose", Handler: disposeInspectionHandler(ctx)},
// 在库处置:从在库库存行直接发起不合格处置(JWT 登录即可,与同组检验接口权限一致)
{Method: http.MethodPost, Path: "/api/inspection/inventory-dispose", Handler: inventoryDisposeHandler(ctx)},
// 复检(换修闭环):针对「在库 + 不合格」库存行重新判定,闭合换修 / 不合格处置后续
{Method: http.MethodPost, Path: "/api/inspection/reinspect", Handler: reinspectHandler(ctx)},
{Method: http.MethodGet, Path: "/api/inspection/query", Handler: queryInspectionHandler(ctx)},
{Method: http.MethodGet, Path: "/api/inspection/export", Handler: exportInspectionHandler(ctx)},
{Method: http.MethodGet, Path: "/api/inspection/stats", Handler: statsInspectionHandler(ctx)},
{Method: http.MethodGet, Path: "/api/inspection/pending", Handler: pendingInspectionHandler(ctx)},
{Method: http.MethodGet, Path: "/api/inspection/pending/details", Handler: pendingDetailsInspectionHandler(ctx)},
},
)
// 接驳台主数据已迁 MES(2026-09-21,AGV 配送真源 2026-10-14 迁 MES):
// 仓库不再维护 dock 表、不再下发/查询 AGV 任务;出库目标工位下拉(/api/outbound/stations) 只读 MES 内部接口。
// 「AGV配送」页已随 GUI 一并移除,MES 为 AGV 任务与海康 RCS 客户端唯一真源。
// 区域(多级父子结构:区域/货架/层/位置号 4 个 Tab)
server.AddRoutes(
[]rest.Route{
{Method: http.MethodGet, Path: "/api/zone/list", Handler: requirePerm(ctx, "zone:view", listZonesHandler(ctx))},
{Method: http.MethodPost, Path: "/api/zone/node/create", Handler: requirePerm(ctx, "zone:create", createZoneNodeHandler(ctx))},
{Method: http.MethodPost, Path: "/api/zone/node/update", Handler: requirePerm(ctx, "zone:edit", updateZoneNodeHandler(ctx))},
{Method: http.MethodPost, Path: "/api/zone/batch-generate", Handler: requirePerm(ctx, "zone:create", batchGenerateHandler(ctx))},
// 下拉(兼容旧调用 + 层级级联),原样保留无权限包裹
{Method: http.MethodGet, Path: "/api/zone/picker", Handler: listZonesForPicker(ctx)},
// 同区空位推荐(入库选物料后无历史库位时自动推荐),无权限包裹
{Method: http.MethodGet, Path: "/api/zone/vacant", Handler: vacantZoneHandler(ctx)},
},
)
// 盘点(问题12 权限:发起/扫码/取消需 stocktake:start;查询/导出需 stocktake:view;写回分支在 handler 内再校 stocktake:writeback)
server.AddRoutes(
[]rest.Route{
{Method: http.MethodPost, Path: "/api/stocktake/start", Handler: requirePerm(ctx, "stocktake:start", startStocktakeHandler(ctx))},
{Method: http.MethodPost, Path: "/api/stocktake/record", Handler: requirePerm(ctx, "stocktake:start", recordStocktakeHandler(ctx))},
{Method: http.MethodPost, Path: "/api/stocktake/finish", Handler: requirePerm(ctx, "stocktake:start", finishStocktakeHandler(ctx))},
{Method: http.MethodPost, Path: "/api/stocktake/cancel", Handler: requirePerm(ctx, "stocktake:start", cancelStocktakeHandler(ctx))},
{Method: http.MethodGet, Path: "/api/stocktake/query", Handler: requirePerm(ctx, "stocktake:view", queryStocktakeHandler(ctx))},
{Method: http.MethodGet, Path: "/api/stocktake/active", Handler: requirePerm(ctx, "stocktake:view", activeStocktakeHandler(ctx))},
{Method: http.MethodGet, Path: "/api/stocktake/export", Handler: requirePerm(ctx, "stocktake:view", exportStocktakeHandler(ctx))},
},
)
// 在制品
server.AddRoutes(
[]rest.Route{
// 2026-11-24:公开手工登记 /api/semi/inbound 已废除(工位终端/MES 内部仍走 /api/internal/semi/inbound)。
{Method: http.MethodPost, Path: "/api/semi/outbound", Handler: semiOutboundHandler(ctx)},
{Method: http.MethodGet, Path: "/api/semi/query", Handler: querySemiHandler(ctx)},
// A2 在制品入库继承产线工单:前端凭工单号只读带出合同号(归属)
{Method: http.MethodGet, Path: "/api/workorder/contract", Handler: workOrderContractHandler(ctx)},
// B1 入库工单号软校验:只判工单存在(不要求有合同号),红字不阻断
{Method: http.MethodGet, Path: "/api/workorder/exists", Handler: workOrderExistsHandler(ctx)},
},
)
// 手工成品入库(方案A:完工检合格才入成品库,与 MES 完工回流内部接口共享创建逻辑)
server.AddRoutes(
[]rest.Route{
{Method: http.MethodPost, Path: "/api/finished/inbound", Handler: requirePerm(ctx, "wms.finished:edit", manualFinishedInboundHandler(ctx))},
// 2026-11-13 拍板:扫 SN 反查 MES 工单(只读);MES 不可达直接 502,前端据此禁用入库。
{Method: http.MethodGet, Path: "/api/finished/lookup", Handler: requirePerm(ctx, "wms.finished:edit", finishedLookupHandler(ctx))},
// 今日成品入库记录(只读表:统一库存主表 category=3 当天,登录可查)
{Method: http.MethodGet, Path: "/api/finished/inbound/today", Handler: finishedInboundTodayHandler(ctx)},
},
)
// 退库单(工位退料回库房,WMS 库管确认收货后库存加回)
server.AddRoutes(
[]rest.Route{
{Method: http.MethodPost, Path: "/api/return-order/confirm", Handler: confirmReturnOrderHandler(ctx)},
// 2026-11-24 问题14:已收货退库单直接修正数量(以最后确认为准、留痕)
{Method: http.MethodPost, Path: "/api/return-order/adjust", Handler: adjustReturnOrderHandler(ctx)},
{Method: http.MethodGet, Path: "/api/return-order/query", Handler: queryReturnOrdersHandler(ctx)},
{Method: http.MethodGet, Path: "/api/return-order/suggest-location", Handler: suggestReturnLocationHandler(ctx)},
// 库管代工位退料(2026-11-03 拍板):库管替操作工建退库单(选工位/工单/物料/数量/接驳台)
// 库管代退料走坑3双条件前置校验(台账无在制工件 + 工人已下班),工位自退不走
{Method: http.MethodPost, Path: "/api/return-order/manual", Handler: createReturnOrderHandler(ctx, true)},
// Q10:库管派车退料单(工位只发起需求并把料放接驳台)
{Method: http.MethodPost, Path: "/api/return-order/dispatch", Handler: requirePerm(ctx, "return:confirm", dispatchReturnOrderByWarehouseHandler(ctx))},
// 取消 PENDING 退料单(2026-11-04 拍板:库房可取消工位申请;已收货不可取消;联动作废未完成 AGV 任务)
{Method: http.MethodPost, Path: "/api/return-order/cancel", Handler: cancelReturnOrderHandler(ctx)},
// 余量参考值(2026-11-04 定稿:剩余余量=应剩余量−已退余量−已损耗,转发 MES 聚合;仅展示不阻断)
{Method: http.MethodGet, Path: "/api/return-order/reference", Handler: returnReferenceHandler(ctx)},
// D1 工单备料台账已于 2026-11-04 按用户拍板移除(台账页/路由/权限一并退役,不再复活)
},
)
// 生产退不良(产线使用中发现的不良品退回库房隔离,质量异常处置入口)
server.AddRoutes(
[]rest.Route{
{Method: http.MethodPost, Path: "/api/production-return", Handler: requirePerm(ctx, "prodreturn:manage", createProductionReturnHandler(ctx))},
{Method: http.MethodGet, Path: "/api/production-return/query", Handler: requirePerm(ctx, "prodreturn:manage", queryProductionReturnHandler(ctx))},
{Method: http.MethodGet, Path: "/api/production-return/export", Handler: requirePerm(ctx, "prodreturn:manage", exportProductionReturnHandler(ctx))},
},
)
// 工单物料台账(WMS 侧)
server.AddRoutes(
[]rest.Route{
{Method: http.MethodGet, Path: "/api/orders", Handler: ordersHandler(ctx)},
},
)
// 附件(下沉到各业务页内嵌使用:入库/物料/检验/在制品/出库)
// 2026-10-28 生命周期重构:附件中心转纯查阅;删除/恢复/彻底清除唯一入口=数据归档页(attachment:manage);
// 业务面板仅保留上传人本人「移除」误传附件(/remove,handler 内校验本人)。
server.AddRoutes(
[]rest.Route{
{Method: http.MethodPost, Path: "/api/attachments/upload", Handler: uploadAttachmentHandler(ctx)},
{Method: http.MethodGet, Path: "/api/attachments", Handler: listAttachmentsHandler(ctx)},
{Method: http.MethodPost, Path: "/api/attachments/remove", Handler: removeAttachmentHandler(ctx)},
// 删除前提示清楚:预检只读(保护期/引用/备份覆盖情况),登录即可查
{Method: http.MethodPost, Path: "/api/attachments/delete-precheck", Handler: deletePrecheckHandler(ctx)},
// 以下为数据归档页清理工作台(attachment:manage)
{Method: http.MethodPost, Path: "/api/attachments/delete", Handler: requirePerm(ctx, "attachment:manage", deleteAttachmentHandler(ctx))},
{Method: http.MethodPost, Path: "/api/attachments/restore", Handler: requirePerm(ctx, "attachment:manage", restoreAttachmentHandler(ctx))},
{Method: http.MethodPost, Path: "/api/attachments/purge", Handler: requirePerm(ctx, "attachment:manage", purgeAttachmentHandler(ctx))},
{Method: http.MethodGet, Path: "/api/attachments/orphans", Handler: requirePerm(ctx, "attachment:manage", orphanScanHandler(ctx))},
{Method: http.MethodPost, Path: "/api/attachments/orphans/purge", Handler: requirePerm(ctx, "attachment:manage", orphanPurgeHandler(ctx))},
// 附件中心(系统管理 → 附件中心)
{Method: http.MethodGet, Path: "/api/attachments/all", Handler: requirePerm(ctx, "attachment:view", listAllAttachmentsHandler(ctx))},
{Method: http.MethodGet, Path: "/api/attachments/disk-status", Handler: requirePerm(ctx, "attachment:view", diskStatusHandler(ctx))},
// 空间清理:批量物理清理已删附件归 attachment:manage
{Method: http.MethodPost, Path: "/api/attachments/purge-deleted", Handler: requirePerm(ctx, "attachment:manage", purgeDeletedHandler(ctx))},
},
)
// 大屏展示数据(免登录)
server.AddRoutes(
[]rest.Route{
{Method: http.MethodGet, Path: "/api/display/overview", Handler: internalDisplayHandler(ctx)},
{Method: http.MethodGet, Path: "/api/display/analytics", Handler: internalDisplayAnalyticsHandler(ctx)},
{Method: http.MethodGet, Path: "/api/display/calls", Handler: internalDisplayCallsHandler(ctx)},
{Method: http.MethodGet, Path: "/api/display/config", Handler: displayConfigHandler(ctx)},
},
)
// 数据归档(系统管理 → 备份到 U 盘 / 腾空间):仅管理员。
// 备份=流式导出到外部存储并记 backup_record;清理=物理删除(严格覆盖校验,不可逆)。
server.AddRoutes(
[]rest.Route{
{Method: http.MethodGet, Path: "/api/backup/items", Handler: requireAdmin(backupItemsHandler(ctx))},
{Method: http.MethodPost, Path: "/api/backup/start", Handler: requireAdmin(backupStartHandler(ctx))},
{Method: http.MethodGet, Path: "/api/backup/progress", Handler: requireAdmin(backupProgressHandler(ctx))},
{Method: http.MethodPost, Path: "/api/cleanup/check", Handler: requireAdmin(cleanupCheckHandler(ctx))},
{Method: http.MethodPost, Path: "/api/cleanup/start", Handler: requireAdmin(cleanupStartHandler(ctx))},
{Method: http.MethodGet, Path: "/api/cleanup/progress", Handler: requireAdmin(cleanupProgressHandler(ctx))},
// 数据归档增强:目录选择器 / 提醒 / 预览 / 历史
{Method: http.MethodGet, Path: "/api/backup/drives", Handler: requireAdmin(backupDrivesHandler(ctx))},
{Method: http.MethodGet, Path: "/api/backup/listdir", Handler: requireAdmin(backupListDirHandler(ctx))},
{Method: http.MethodGet, Path: "/api/backup/reminder", Handler: requireAdmin(backupReminderHandler(ctx))},
{Method: http.MethodPost, Path: "/api/cleanup/preview", Handler: requireAdmin(cleanupPreviewHandler(ctx))},
{Method: http.MethodGet, Path: "/api/backup/records", Handler: requireAdmin(backupRecordsHandler(ctx))},
},
)
// 异常告警(顶栏铃铛 + 告警列表):JWT 鉴权后注册
server.AddRoutes(
[]rest.Route{
{Method: http.MethodGet, Path: "/api/alerts", Handler: listAlertsHandler(ctx)},
{Method: http.MethodPost, Path: "/api/alerts/:id/resolve", Handler: resolveAlertHandler(ctx)},
{Method: http.MethodPost, Path: "/api/alerts/resolve-all", Handler: resolveAllAlertsHandler(ctx)},
{Method: http.MethodGet, Path: "/api/alert-rules", Handler: listAlertRulesHandler(ctx)},
{Method: http.MethodPost, Path: "/api/alert-rules/update", Handler: updateAlertRuleHandler(ctx)},
},
)
// 系统基础设置(admin-only):保存即生效,无需重启。
server.AddRoutes(
[]rest.Route{
{Method: http.MethodGet, Path: "/api/settings", Handler: requireAdmin(SettingsHandler(ctx))},
{Method: http.MethodPut, Path: "/api/settings", Handler: requireAdmin(SaveSettingsHandler(ctx))},
},
)
// 本机只读信息(OS / 主机名 / Go 版本 / 端口 / 启动时间 / 当前生效 MES 地址)。
// MES 地址可在「基础设置」页修改(保存即生效,2026-11-02);mes-ping 供页面"测试连接"。
server.AddRoutes(
[]rest.Route{
{Method: http.MethodGet, Path: "/api/system/info", Handler: SystemInfoHandler(ctx)},
{Method: http.MethodGet, Path: "/api/system/mes-ping", Handler: requireAdmin(MesPingHandler(ctx))},
},
)
// 项目间内部 API(X-API-TOKEN 写死 token 保护)
// 与 JWT 侧业务接口同实现,仅供 MES(B)/工位终端(D) 等服务间调用
server.AddRoutes(
[]rest.Route{
{Method: http.MethodPost, Path: "/api/internal/stock/check", Handler: wrapInternal(ctx)(checkStockHandler(ctx))},
{Method: http.MethodPost, Path: "/api/internal/stock/lock", Handler: wrapInternal(ctx)(lockStockHandler(ctx))},
{Method: http.MethodPost, Path: "/api/internal/stock/unlock", Handler: wrapInternal(ctx)(unlockStockHandler(ctx))},
{Method: http.MethodGet, Path: "/api/internal/stock/query", Handler: wrapInternal(ctx)(queryStockHandler(ctx))},
// 可用批次/SN 查询(MES 物料存在性校验等内部调用)
{Method: http.MethodGet, Path: "/api/internal/stock/batches", Handler: wrapInternal(ctx)(listStockBatchesInternalHandler(ctx))},
// 装机绑定值校验(2026-11-26 定稿:SN 必须是发到本工位的出库明细 SN;批次件放开不校验)
{Method: http.MethodGet, Path: "/api/internal/inventory/bind-values-check", Handler: wrapInternal(ctx)(bindValuesCheckInternalHandler(ctx))},
// 已签收出库未退 SN 清单(2026-11-28 坑2:工位退料 SN 清单自动推导的数据源)
{Method: http.MethodGet, Path: "/api/internal/stock/signed-out-sns", Handler: wrapInternal(ctx)(signedOutSNsInternalHandler(ctx))},
{Method: http.MethodPost, Path: "/api/internal/semi/inbound", Handler: wrapInternal(ctx)(semiInboundHandler(ctx))},
{Method: http.MethodPost, Path: "/api/internal/semi/outbound", Handler: wrapInternal(ctx)(semiOutboundHandler(ctx))},
{Method: http.MethodPost, Path: "/api/internal/finished/inbound", Handler: wrapInternal(ctx)(finishedInboundHandler(ctx))},
// 型号导出(MES 型号维护已本地化 M3/M6,列表/增改删内部接口随调用方消亡移除,仅保留导出)
{Method: http.MethodGet, Path: "/api/internal/product-types/export", Handler: wrapInternal(ctx)(exportProductTypesInternalHandler(ctx))},
// 物料两库对等(需求一 M3/M5):MES→WMS 推送落点,按 code 幂等 upsert(删除=停用 isActive=false)
{Method: http.MethodPost, Path: "/api/internal/materials/upsert", Handler: wrapInternal(ctx)(upsertMaterialInternalHandler(ctx))},
{Method: http.MethodPost, Path: "/api/internal/material/exists", Handler: wrapInternal(ctx)(materialExistsHandler(ctx))},
// 看板物料追溯入口复用:物料档案 + 库存查询(按编码/批次)
{Method: http.MethodGet, Path: "/api/internal/material/query", Handler: wrapInternal(ctx)(materialQueryInternalHandler(ctx))},
{Method: http.MethodPost, Path: "/api/internal/material/manage-modes", Handler: wrapInternal(ctx)(materialManageModesHandler(ctx))},
// 物料分页查询(需求一 M7:MES 冷启动全量拉取用;MES 推送走上方 /upsert)
{Method: http.MethodGet, Path: "/api/internal/materials", Handler: wrapInternal(ctx)(queryMaterialsHandler(ctx))},
{Method: http.MethodGet, Path: "/api/internal/material/list-all", Handler: wrapInternal(ctx)(listMaterialsHandler(ctx))},
{Method: http.MethodPost, Path: "/api/internal/return-order", Handler: wrapInternal(ctx)(createReturnOrderHandler(ctx, false))},
// 取消退料单/工位列表/已退汇总(2026-11-28:pending-agv 随 10 秒轮询删除)
{Method: http.MethodPost, Path: "/api/internal/return-order/cancel", Handler: wrapInternal(ctx)(cancelReturnOrderInternalHandler(ctx))},
{Method: http.MethodGet, Path: "/api/internal/return-order/station-list", Handler: wrapInternal(ctx)(stationReturnListInternalHandler(ctx))},
{Method: http.MethodGet, Path: "/api/internal/return-order/pending-count", Handler: wrapInternal(ctx)(returnOrderPendingCountInternalHandler(ctx))},
{Method: http.MethodGet, Path: "/api/internal/return-order/returned-summary", Handler: wrapInternal(ctx)(returnedSummaryInternalHandler(ctx))},
// MES 质量检验(过程检/完工检)判不合格 → 联动 WMS 在库处置(按物料+SN/批次定位库存行)
{Method: http.MethodPost, Path: "/api/internal/inventory/dispose", Handler: wrapInternal(ctx)(internalInventoryDisposeHandler(ctx))},
// AGV 到位回写(MES AGV 回调调用):出库单 已出库 → 已送达(补齐状态机无写者的断头路)
{Method: http.MethodPost, Path: "/api/internal/outbound/delivered", Handler: wrapInternal(ctx)(markOutboundDeliveredHandler(ctx))},
// 配送单送达回写(2026-11-05 拍板:AGV 卸货放行后 MES 回写;配送单不存在时忽略,兼容旧链路)
{Method: http.MethodPost, Path: "/api/internal/delivery/delivered", Handler: wrapInternal(ctx)(deliveryDeliveredInternalHandler(ctx))},
{Method: http.MethodGet, Path: "/api/internal/delivery/status", Handler: wrapInternal(ctx)(deliveryStatusInternalHandler(ctx))},
// 叫料单送达量查询(2026-11-27 部分到货显示:MES 列表透传给工位终端)
{Method: http.MethodGet, Path: "/api/internal/call/arrived", Handler: wrapInternal(ctx)(callArrivedHandler(ctx))},
// 成品序列号在库核验(MES「成品试验」登记前只读校验,另一代理已建 handler)
{Method: http.MethodGet, Path: "/api/internal/inventory/sn-exists", Handler: wrapInternal(ctx)(inventorySnExistsInternalHandler(ctx))},
},
)
// 待办统计 + WebSocket 推送(问题8):菜单角标实时刷新 + 本机语音播报触发源
todoHub := ws.NewTodoHub(ctx)
todoHub.Start()
server.AddRoutes(
[]rest.Route{
{Method: http.MethodGet, Path: "/api/todos/stats", Handler: todoStatsHandler(todoHub)},
},
)
// 退料 AGV 到位回调(2026-11-28 对账铁律):MES 调,写 arrived_at + WS 弹库房收货提示。
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/internal/return-order/arrived", Handler: wrapInternal(ctx)(returnOrderArrivedHandler(ctx, todoHub)),
})
// WebSocket 长连接单独注册并放大超时,避免被全局超时掐断
server.AddRoute(rest.Route{
Method: http.MethodGet, Path: "/api/todos/ws", Handler: todoWebSocketHandler(ctx, todoHub),
}, rest.WithTimeout(3600_000_000_000))
}