本提交完成了WMS系统的多维度优化升级: 1. 新增RBAC权限系统,支持角色/菜单/按钮三级权限管控 2. 重构库存盘点、物料管理、区域维护等模块的查询筛选与展示逻辑 3. 优化入库/出库/质检等业务流程,完善数据冗余与业务闭环 4. 移除旧装箱表,将装箱逻辑合并到出库主表 5. 新增前端权限判断工具、导出工具与端到端测试用例 6. 补充完善各类注释与数据库字段说明
160 lines
7.1 KiB
Go
160 lines
7.1 KiB
Go
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)},
|
||
},
|
||
)
|
||
|
||
server.Use(authInterceptor(ctx))
|
||
|
||
// 当前登录用户(JWT 鉴权)
|
||
server.AddRoutes(
|
||
[]rest.Route{
|
||
{Method: http.MethodPost, Path: "/api/user/change-password", Handler: changePasswordHandler(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.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)},
|
||
},
|
||
)
|
||
|
||
// 物料档案
|
||
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)},
|
||
},
|
||
)
|
||
|
||
// 入库
|
||
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)},
|
||
},
|
||
)
|
||
|
||
// 出库(统一主表:备料出库 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)},
|
||
},
|
||
)
|
||
|
||
// 库存
|
||
server.AddRoutes(
|
||
[]rest.Route{
|
||
{Method: http.MethodGet, Path: "/api/stock/query", Handler: queryStockHandler(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)},
|
||
},
|
||
)
|
||
|
||
// 检验
|
||
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.MethodGet, Path: "/api/inspection/query", Handler: queryInspectionHandler(ctx)},
|
||
{Method: http.MethodGet, Path: "/api/inspection/export", Handler: exportInspectionHandler(ctx)},
|
||
},
|
||
)
|
||
|
||
// 区域
|
||
server.AddRoutes(
|
||
[]rest.Route{
|
||
{Method: http.MethodPost, Path: "/api/zone/create", Handler: createZoneHandler(ctx)},
|
||
{Method: http.MethodPost, Path: "/api/zone/update", Handler: updateZoneHandler(ctx)},
|
||
{Method: http.MethodGet, Path: "/api/zone/list", Handler: listZonesHandler(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.MethodGet, Path: "/api/ledger/query", Handler: queryLedgerHandler(ctx)},
|
||
{Method: http.MethodGet, Path: "/api/orders", Handler: ordersHandler(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))},
|
||
},
|
||
)
|
||
}
|