Files
bj_power/bj_power_wms/internal/handler/routes.go
T
SunYF b0c048d9aa feat: 新增收集式校验错误弹窗及工位报警语音播报
新增 ErrorListDialog 组件用于统一展示结构化校验错误信息,实现报错一次收全;新增工位报警语音播报功能,通过浏览器 SpeechSynthesis 播放本工位相关报警;调整物料类别及序列号字段文案,移除「其他」类别;新增工单实际开始字段及采集方式配置;优化 AGV 及 PlcSend 页签刷新逻辑;新增看板物料追溯及工位报警接口;删除 PLC 强制写 M 位及相关测试代码;同步数据库字段注释及补丁。
2026-10-20 16:36:26 +08:00

264 lines
17 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"
"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.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)},
},
)
server.Use(authInterceptor(ctx))
// 当前登录用户(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/toggle-status", Handler: requirePerm(ctx, "material:edit", toggleMaterialStatusHandler(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.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: generalOutboundHandler(ctx)},
{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)},
// 目标工位下拉选项(需求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))},
{Method: http.MethodPost, Path: "/api/call/reject", Handler: requirePerm(ctx, "call:manage", callRejectHandler(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{
{Method: http.MethodPost, Path: "/api/semi/inbound", Handler: semiInboundHandler(ctx)},
{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)},
},
)
// 手工成品入库(方案A:完工检合格才入成品库,与 MES 完工回流内部接口共享创建逻辑)
server.AddRoutes(
[]rest.Route{
{Method: http.MethodPost, Path: "/api/finished/inbound", Handler: requirePerm(ctx, "wms.finished:edit", manualFinishedInboundHandler(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)},
{Method: http.MethodGet, Path: "/api/return-order/query", Handler: queryReturnOrdersHandler(ctx)},
{Method: http.MethodGet, Path: "/api/return-order/suggest-location", Handler: suggestReturnLocationHandler(ctx)},
},
)
// 生产退不良(产线使用中发现的不良品退回库房隔离,质量异常处置入口)
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)},
},
)
// 附件(下沉到各业务页内嵌使用:入库/物料/检验/半成品/出库)
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/delete", Handler: deleteAttachmentHandler(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))},
{Method: http.MethodPost, Path: "/api/attachments/archive", Handler: requirePerm(ctx, "attachment:manage", archiveAttachmentsHandler(ctx))},
// 空间清理(需求2):物理清理已删附件归 attachment:manage;日志清理仅管理员
{Method: http.MethodPost, Path: "/api/attachments/purge-deleted", Handler: requirePerm(ctx, "attachment:manage", purgeDeletedHandler(ctx))},
{Method: http.MethodPost, Path: "/api/attachments/clean-logs", Handler: requireAdmin(cleanLogsHandler(ctx))},
},
)
// 大屏展示数据(免登录)
server.AddRoutes(
[]rest.Route{
{Method: http.MethodGet, Path: "/api/display/overview", Handler: internalDisplayHandler(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))},
{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.MethodPost, Path: "/api/internal/material/types", Handler: wrapInternal(ctx)(materialTypesHandler(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)(createReturnOrderInternalHandler(ctx))},
// MES 质量检验(过程检/完工检)判不合格 → 联动 WMS 在库处置(按物料+SN/批次定位库存行)
{Method: http.MethodPost, Path: "/api/internal/inventory/dispose", Handler: wrapInternal(ctx)(internalInventoryDisposeHandler(ctx))},
},
)
}