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 / 图片预览):免鉴权,供 / 新窗口直接打开 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)}, }, ) // 物料档案 server.AddRoutes( []rest.Route{ {Method: http.MethodPost, Path: "/api/material/create", Handler: createMaterialHandler(ctx)}, {Method: http.MethodPost, Path: "/api/material/update", Handler: 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: exportMaterialsHandler(ctx)}, {Method: http.MethodPost, Path: "/api/material/import", Handler: excelMaterialImportHandler(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/create", Handler: createOutboundHandler(ctx)}, {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)}, }, ) // AGV 配送(海康 RCS 对接:下发/任务列表/状态轮询/接驳台状态) server.AddRoutes( []rest.Route{ {Method: http.MethodPost, Path: "/api/agv/submit", Handler: requirePerm(ctx, "agv:manage", submitAgvHandler(ctx))}, {Method: http.MethodGet, Path: "/api/agv/tasks", Handler: requirePerm(ctx, "agv:manage", listAgvTasksHandler(ctx))}, {Method: http.MethodPost, Path: "/api/agv/refresh", Handler: requirePerm(ctx, "agv:manage", refreshAgvHandler(ctx))}, {Method: http.MethodGet, Path: "/api/agv/docks", Handler: requirePerm(ctx, "agv:manage", listDocksHandler(ctx))}, {Method: http.MethodGet, Path: "/api/agv/materials", Handler: requirePerm(ctx, "agv:manage", listAgvMaterialsHandler(ctx))}, {Method: http.MethodPost, Path: "/api/agv/cancel", Handler: requirePerm(ctx, "agv:manage", cancelAgvHandler(ctx))}, {Method: http.MethodGet, Path: "/api/agv/mode", Handler: requirePerm(ctx, "agv:manage", agvModeHandler(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/deduct", Handler: deductStockHandler(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/producible", Handler: queryProducibleHandler(ctx)}, }, ) // 检验 server.AddRoutes( []rest.Route{ {Method: http.MethodPost, Path: "/api/inspection/create", Handler: createInspectionHandler(ctx)}, {Method: http.MethodPost, Path: "/api/inspection/batch-flip", Handler: batchFlipInspectionHandler(ctx)}, {Method: http.MethodPost, Path: "/api/inspection/dispose", Handler: disposeInspectionHandler(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)}, }, ) // 接驳台主数据(独立主数据:产线/库房/其他,产线类型与工位 1:1 绑定) server.AddRoutes( []rest.Route{ {Method: http.MethodGet, Path: "/api/docks", Handler: requirePerm(ctx, "dock:manage", listDocksMaintHandler(ctx))}, {Method: http.MethodPost, Path: "/api/docks", Handler: requirePerm(ctx, "dock:add", createDockHandler(ctx))}, {Method: http.MethodPost, Path: "/api/docks/update", Handler: requirePerm(ctx, "dock:edit", updateDockHandler(ctx))}, {Method: http.MethodPost, Path: "/api/docks/delete", Handler: requirePerm(ctx, "dock:delete", deleteDockHandler(ctx))}, }, ) // 区域(多级父子结构:区域/货架/层/位置号 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)}, }, ) // 盘点 server.AddRoutes( []rest.Route{ {Method: http.MethodPost, Path: "/api/stocktake/start", Handler: startStocktakeHandler(ctx)}, {Method: http.MethodPost, Path: "/api/stocktake/record", Handler: recordStocktakeHandler(ctx)}, {Method: http.MethodPost, Path: "/api/stocktake/finish", Handler: finishStocktakeHandler(ctx)}, {Method: http.MethodGet, Path: "/api/stocktake/query", Handler: queryStocktakeHandler(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)}, }, ) // 退库单(工位退料回库房,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/ledger", Handler: queryReturnLedgerHandler(ctx)}, }, ) // 工单物料台账(WMS 侧) server.AddRoutes( []rest.Route{ {Method: http.MethodGet, Path: "/api/ledger/query", Handler: queryLedgerHandler(ctx)}, {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))}, }, ) // 大屏展示数据(免登录) 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/ledger/sync", Handler: wrapInternal(ctx)(ledgerSyncHandler(ctx))}, {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.MethodPost, Path: "/api/internal/stock/deduct", Handler: wrapInternal(ctx)(deductStockHandler(ctx))}, {Method: http.MethodGet, Path: "/api/internal/stock/query", Handler: wrapInternal(ctx)(queryStockHandler(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))}, {Method: http.MethodGet, Path: "/api/internal/product-types", Handler: wrapInternal(ctx)(listProductTypesInternalHandler(ctx))}, {Method: http.MethodGet, Path: "/api/internal/product-types/export", Handler: wrapInternal(ctx)(exportProductTypesInternalHandler(ctx))}, {Method: http.MethodPost, Path: "/api/internal/product-types", Handler: wrapInternal(ctx)(createProductTypeInternalHandler(ctx))}, {Method: http.MethodPut, Path: "/api/internal/product-types", Handler: wrapInternal(ctx)(updateProductTypeInternalHandler(ctx))}, {Method: http.MethodPost, Path: "/api/internal/product-types/delete", Handler: wrapInternal(ctx)(deleteProductTypeInternalHandler(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.MethodPost, Path: "/api/internal/dock/pallet-sync", Handler: syncDockPalletHandler(ctx)}, {Method: http.MethodPost, Path: "/api/internal/return-order", Handler: wrapInternal(ctx)(createReturnOrderInternalHandler(ctx))}, {Method: http.MethodGet, Path: "/api/internal/docks", Handler: wrapInternal(ctx)(listDocksInternalHandler(ctx))}, {Method: http.MethodPost, Path: "/api/internal/material/backflush", Handler: wrapInternal(ctx)(backflushInternalHandler(ctx))}, }, ) }