feat: 菜单按业务域重排为7组 + 预警中心更名异常告警 + AGV独立权限码与齐套测算分账明细
This commit is contained in:
@@ -11,9 +11,10 @@ import (
|
||||
// inventorySnExistsInternalHandler 按成品序列号精确核验 WMS 库存(X-API-TOKEN 内部接口,只读)。
|
||||
// GET /api/internal/inventory/sn-exists?sn=
|
||||
// MES「成品试验」登记前调用:成品 SN 必须对应一条仍有效在库的库存行。
|
||||
// 判定口径:sn_code 精确相等 + 数量>0(inventories 无软删字段,不臆造删除标记,
|
||||
// 与库存聚合查询 /api/internal/material/query 的 QuantityGT(0) 口径一致)。
|
||||
// 命中返回 found=true 并带出 materialCode/qty;未命中返回 found=false,不写任何表。
|
||||
// 判定口径(2026-11-15 收紧):必须是「成品、逐件SN、在库、数量>0」的库存行,
|
||||
// 与成品入库 finished_inbound.go:84-89 落库口径一致;避免同 SN 的来料/在制品行
|
||||
// 被误判为成品已入库,导致 MES 试验登记被误放行并去核销一条非成品库存行。
|
||||
// inventories 无软删字段,不臆造删除标记。命中返回 found=true 并带出 materialCode/qty。
|
||||
func inventorySnExistsInternalHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
sn := strings.TrimSpace(r.URL.Query().Get("sn"))
|
||||
@@ -22,7 +23,13 @@ func inventorySnExistsInternalHandler(ctx *svc.ServiceContext) http.HandlerFunc
|
||||
return
|
||||
}
|
||||
rows, err := ctx.EntClient.Inventory.Query().
|
||||
Where(inventory.SnCodeEQ(sn), inventory.QuantityGT(0)).
|
||||
Where(
|
||||
inventory.SnCodeEQ(sn),
|
||||
inventory.SnModeEQ(snModeSN),
|
||||
inventory.CategoryEQ(invCatFinished),
|
||||
inventory.StatusEQ("在库"),
|
||||
inventory.QuantityGT(0),
|
||||
).
|
||||
Limit(1).All(ctx0())
|
||||
if err != nil {
|
||||
fail(w, http.StatusInternalServerError, "查询成品库存失败,请稍后重试")
|
||||
|
||||
@@ -29,21 +29,23 @@ type seedPerm struct {
|
||||
var seedPermissions = []seedPerm{
|
||||
// ===== 菜单权限 =====
|
||||
{"dashboard:view", "工作台", "MENU", "/", "HomeFilled", 10, ""},
|
||||
{"inbound:view", "入库管理", "MENU", "/inbound", "Download", 20, ""},
|
||||
{"outbound:view", "出库管理", "MENU", "/outbound", "Upload", 30, ""},
|
||||
{"inbound:view", "来料入库", "MENU", "/inbound", "Download", 20, ""},
|
||||
{"outbound:record", "出库记录", "MENU", "/outbound", "List", 30, ""},
|
||||
{"outbound:general", "通用出库", "MENU", "/general-outbound", "Upload", 31, ""},
|
||||
{"outbound:project", "科技项目出库", "MENU", "/project-outbound", "Upload", 32, ""},
|
||||
{"call:view", "叫料队列", "MENU", "/call-queue", "Bell", 35, ""},
|
||||
// P1(2026-11-04 用户拍板):备料清单——只读展示"今天及以后×工单×工位×物料×数量",数据源 MES 日排产实时算
|
||||
{"preparation:view", "备料清单", "MENU", "/preparation", "Tickets", 36, ""},
|
||||
// 菜单 code 不得共用:配送单/托盘工作台从 call:view、return:view 拆出独立权限(问题18)
|
||||
{"delivery:view", "配送单", "MENU", "/delivery", "Bell", 37, ""},
|
||||
{"pallet:view", "托盘工作台", "MENU", "/pallet-workbench", "Box", 38, ""},
|
||||
{"pallet:view", "托盘与AGV", "MENU", "/pallet-workbench", "Box", 38, ""},
|
||||
{"inventory:view", "库存查询", "MENU", "/inventory", "Search", 40, ""},
|
||||
{"inspection:view", "来料检验", "MENU", "/inspection-incoming", "CircleCheck", 50, ""},
|
||||
{"stocktake:view", "库存盘点", "MENU", "/stocktake", "List", 60, ""},
|
||||
{"semi:view", "在制品/成品", "MENU", "/semi", "Box", 70, ""},
|
||||
{"semi:view", "在制品", "MENU", "/semi", "Box", 70, ""},
|
||||
{"wms.finished:edit", "成品入库", "MENU", "/finished-inbound", "Box", 72, ""},
|
||||
{"return:view", "退库确认", "MENU", "/return-order", "RefreshLeft", 85, ""},
|
||||
{"prodreturn:manage", "生产退不良", "MENU", "/production-return", "WarningFilled", 87, ""},
|
||||
{"return:view", "退库单收货", "MENU", "/return-order", "RefreshLeft", 85, ""},
|
||||
{"prodreturn:manage", "不良品退库", "MENU", "/production-return", "WarningFilled", 87, ""},
|
||||
{"zone:view", "仓库结构", "MENU", "/zone", "Location", 90, ""},
|
||||
{"material:view", "物料档案", "MENU", "/material", "Goods", 100, ""},
|
||||
{"user:manage", "账号管理", "MENU", "/users", "EditPen", 110, ""},
|
||||
@@ -54,18 +56,18 @@ var seedPermissions = []seedPerm{
|
||||
{"sys.settings:view", "基础设置", "MENU", "/settings", "Setting", 150, ""},
|
||||
// 同步失败台账(2026-11-08):跨系统通知失败人工重试,菜单码同时作为后端 requirePerm 校验码
|
||||
{"sync:retry", "同步失败台账", "MENU", "/sync-failure", "Refresh", 152, ""},
|
||||
// 预警中心/预警规则原先无独立 code,补登独立 MENU 权限(问题18)
|
||||
{"alert.center:view", "预警中心", "MENU", "/alert-center", "Bell", 154, ""},
|
||||
{"alert.rule:view", "预警规则", "MENU", "/alert-rule", "Bell", 156, ""},
|
||||
// 异常告警/告警配置原先无独立 code,补登独立 MENU 权限(问题18)
|
||||
{"alert.center:view", "异常告警", "MENU", "/alert-center", "Bell", 154, ""},
|
||||
{"alert.rule:view", "告警配置", "MENU", "/alert-rule", "Bell", 156, ""},
|
||||
{"sys.settings:edit", "保存基础设置", "BUTTON", "", "", 290, "sys.settings:view"},
|
||||
// ===== 按钮权限 =====
|
||||
{"inbound:create", "批量入库", "BUTTON", "", "", 200, "inbound:view"},
|
||||
{"inbound:import", "Excel导入", "BUTTON", "", "", 201, "inbound:view"},
|
||||
{"inbound:export", "导出", "BUTTON", "", "", 202, "inbound:view"},
|
||||
{"inbound:void", "作废入库单", "BUTTON", "", "", 203, "inbound:view"},
|
||||
{"outbound:create", "发起出库", "BUTTON", "", "", 210, "outbound:view"},
|
||||
{"outbound:export", "导出", "BUTTON", "", "", 211, "outbound:view"},
|
||||
{"outbound:void", "作废出库单", "BUTTON", "", "", 212, "outbound:view"},
|
||||
{"outbound:create", "发起出库", "BUTTON", "", "", 210, "outbound:general"},
|
||||
{"outbound:export", "导出", "BUTTON", "", "", 211, "outbound:record"},
|
||||
{"outbound:void", "作废出库单", "BUTTON", "", "", 212, "outbound:record"},
|
||||
{"call:manage", "叫料-完成备料/驳回", "BUTTON", "", "", 240, "call:view"},
|
||||
{"inspection:create", "录入检验", "BUTTON", "", "", 220, "inspection:view"},
|
||||
{"inspection:export", "导出", "BUTTON", "", "", 221, "inspection:view"},
|
||||
@@ -134,10 +136,11 @@ func SeedRBAC(ctx *svc.ServiceContext, operator string) (createdP, createdR, bou
|
||||
exist, _ := ctx.EntClient.Permission.Query().
|
||||
Where(permission.CodeEQ(p.Code)).Exist(ctx0())
|
||||
if exist {
|
||||
// 已存在:幂等补齐 parent_code(新增字段不影响已建角色权限)
|
||||
// 与 MES 对齐:名称/路径/归类随种子幂等纠正,已建角色授权不受影响
|
||||
_, _ = ctx.EntClient.Permission.Update().
|
||||
Where(permission.CodeEQ(p.Code)).
|
||||
SetParentCode(p.Parent).
|
||||
SetName(p.Name).SetPath(p.Path).SetType(p.Type).
|
||||
SetIcon(p.Icon).SetSort(p.Sort).SetParentCode(p.Parent).
|
||||
Save(ctx0())
|
||||
continue
|
||||
}
|
||||
@@ -154,22 +157,38 @@ func SeedRBAC(ctx *svc.ServiceContext, operator string) (createdP, createdR, bou
|
||||
// 退役权限码清理(幂等):随功能退役的权限码及存量角色里的旧码一并摘除。
|
||||
// - agv:manage / agv:dispatch:AGV 配送页随 GUI 一并移除,AGV 真源迁 MES(E.1 2026-10-17)
|
||||
// - ledger:view:工单备料台账随用户 2026-11-04 明确拍板移除(D1 移除),不再复活
|
||||
for _, dead := range []string{"agv:manage", "agv:dispatch", "ledger:view"} {
|
||||
// outbound:view 已拆成出库记录 / 通用出库 / 科技项目出库三个独立菜单码,旧码一并退役
|
||||
for _, dead := range []string{"agv:manage", "agv:dispatch", "ledger:view", "outbound:view"} {
|
||||
_, _ = ctx.EntClient.Permission.Delete().Where(permission.CodeEQ(dead)).Exec(ctx0())
|
||||
}
|
||||
if allRoles, _ := ctx.EntClient.Role.Query().All(ctx0()); len(allRoles) > 0 {
|
||||
for _, rl := range allRoles {
|
||||
kept := make([]string, 0, len(rl.PermissionCodes))
|
||||
kept := make([]string, 0, len(rl.PermissionCodes)+3)
|
||||
changed := false
|
||||
for _, c := range rl.PermissionCodes {
|
||||
if c == "agv:manage" || c == "agv:dispatch" || c == "ledger:view" {
|
||||
changed = true
|
||||
continue
|
||||
}
|
||||
if c == "outbound:view" {
|
||||
// 旧码等价换成三个新菜单码:出库记录 / 通用出库 / 科技项目出库。
|
||||
// 所有角色(含自建角色)一律补齐,绝不因拆码丢菜单或 403。
|
||||
kept = append(kept, "outbound:record", "outbound:general", "outbound:project")
|
||||
changed = true
|
||||
continue
|
||||
}
|
||||
kept = append(kept, c)
|
||||
}
|
||||
if changed {
|
||||
_, _ = ctx.EntClient.Role.UpdateOneID(rl.ID).SetPermissionCodes(kept).Save(ctx0())
|
||||
seen := map[string]bool{}
|
||||
dedup := make([]string, 0, len(kept))
|
||||
for _, c := range kept {
|
||||
if !seen[c] {
|
||||
seen[c] = true
|
||||
dedup = append(dedup, c)
|
||||
}
|
||||
}
|
||||
_, _ = ctx.EntClient.Role.UpdateOneID(rl.ID).SetPermissionCodes(dedup).Save(ctx0())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,8 +111,8 @@ func RegisterHandlers(server *rest.Server, ctx *svc.ServiceContext) {
|
||||
// 出库(统一主表:备料出库 workorder / 通用出库 general,装箱信息落在同一张表)
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{Method: http.MethodPost, Path: "/api/outbound/general", Handler: makeOutboundHandler(ctx, "general")},
|
||||
{Method: http.MethodPost, Path: "/api/outbound/project", Handler: makeOutboundHandler(ctx, "project")},
|
||||
{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「出库相同」)
|
||||
@@ -335,7 +335,7 @@ func RegisterHandlers(server *rest.Server, ctx *svc.ServiceContext) {
|
||||
},
|
||||
)
|
||||
|
||||
// 预警中心(顶栏铃铛 + 预警列表):JWT 鉴权后注册
|
||||
// 异常告警(顶栏铃铛 + 告警列表):JWT 鉴权后注册
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{Method: http.MethodGet, Path: "/api/alerts", Handler: listAlertsHandler(ctx)},
|
||||
|
||||
@@ -20,6 +20,8 @@ func shortageOnBehalfHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
StationNo int `json:"stationNo"`
|
||||
ProductWorkNo string `json:"productWorkNo"`
|
||||
MaterialCode string `json:"materialCode"`
|
||||
MaterialName string `json:"materialName"`
|
||||
Unit string `json:"unit"`
|
||||
Qty int `json:"qty"`
|
||||
Reason string `json:"reason"`
|
||||
Operator string `json:"operator"`
|
||||
@@ -38,7 +40,8 @@ func shortageOnBehalfHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
op = r.Header.Get("X-Username")
|
||||
}
|
||||
if err := ctx.Mes.CreateShortageOnBehalf(r.Context(), req.StationNo,
|
||||
req.MaterialCode, req.Qty, reason, op); err != nil {
|
||||
strings.TrimSpace(req.MaterialCode), strings.TrimSpace(req.MaterialName), strings.TrimSpace(req.Unit),
|
||||
req.Qty, reason, op); err != nil {
|
||||
fail(w, http.StatusBadGateway, "MES 补料申请提交失败: "+fmtErr(err))
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user