-- ============================================================================ -- 物料收发明细表:菜单 + 字段 + 按钮 + 权限(权限库) -- 对应后端:/warehouseInOutStatis/listByPage、/warehouseInOutStatis/export -- Output DTO:me.iiv.iivframework.controller.warehouse.output.WarehouseInOutStatisOutput -- -- 环境对应的权限 schema: -- dev → xiaoqu_comples_d -- test → test -- prod → xiaoqu_comples_p -- 切环境只需改第一行 USE,其余语句通用。 -- -- ⚠️ 上线前在 prod 复核(sanity check,见文件末尾): -- ① parent_id=213(库存统计目录)在 prod 是否一致; -- ② path 'warehouseInOutManage/materialInOutDetail' 不重复; -- ③ 兄弟菜单(dev 为 214 库存统计详情 / 258 库存物品详情)授权并集是否符合预期。 -- -- dev 实测(2026-08-03):parent_id=213 下兄弟菜单 214(order_by=0)、258(order_by=1), -- 授权并集 authority_id = (1, 102),order_by 取最大值+1 = 2。 -- ============================================================================ USE xiaoqu_comples_d; -- dev;test 改 USE test; prod 改 USE xiaoqu_comples_p; START TRANSACTION; -- order_by 动态取同 parent_id=213 下兄弟菜单最大值+1(dev=2) SET @next_order_by := (SELECT COALESCE(MAX(order_by), 0) + 1 FROM webpage WHERE parent_id = 213); -- ───────────────────────────────────────────────────────────── -- ① webpage:菜单本体(挂到「库存统计」id=213 之下) -- ───────────────────────────────────────────────────────────── INSERT INTO webpage (title, param, icon, description, order_by, parent_id, `type`, `status`, `path`, is_table_show) VALUES ('物料收发明细表', '', '', '', @next_order_by, 213, 0, 1, 'warehouseInOutManage/materialInOutDetail', 1); -- ⚠️ 必须在 webpage insert 后立即取 LAST_INSERT_ID() SET @new_web_id := LAST_INSERT_ID(); SELECT @new_web_id AS new_webpage_id, @next_order_by AS used_order_by; -- ───────────────────────────────────────────────────────────── -- ② webpage_authority:菜单授权(动态并集:同 parent_id=213 下兄弟菜单的 authority_id 集合,不硬编码) -- ───────────────────────────────────────────────────────────── INSERT INTO webpage_authority (web_id, authority_id, title, `path`, parent_id, check_status, `type`, is_table_show, order_by) SELECT @new_web_id, sa.authority_id, '物料收发明细表', 'warehouseInOutManage/materialInOutDetail', 213, 1, 0, 1, @next_order_by FROM ( SELECT DISTINCT authority_id FROM webpage_authority WHERE web_id IN (SELECT id FROM webpage WHERE parent_id = 213 AND id <> @new_web_id) AND soft_delete = 0 ) sa; -- ───────────────────────────────────────────────────────────── -- ③ page_field:页面字段定义(13 列,与 doc/物料明细表.xlsx 一一对应, -- class_name 与后端 Output DTO 全限定类名严格一致) -- 本页搜索区为前端手写(非元数据驱动),故 nav_select 全部为 0; -- field_type 参照 web_id=258 样例(string/date/select/inputSelect) -- ───────────────────────────────────────────────────────────── INSERT INTO page_field (web_id, cn_name, en_name, class_name, field_type, order_by, is_select, nav_select, is_table_show, param) VALUES (@new_web_id, '物料编码', 'materialNo', 'me.iiv.iivframework.controller.warehouse.output.WarehouseInOutStatisOutput', 'string', 1, 1, 0, 1, ''), (@new_web_id, '物料名称', 'materielFullName', 'me.iiv.iivframework.controller.warehouse.output.WarehouseInOutStatisOutput', 'string', 2, 1, 0, 1, ''), (@new_web_id, '物料规格型号', 'specifications', 'me.iiv.iivframework.controller.warehouse.output.WarehouseInOutStatisOutput', 'string', 3, 1, 0, 1, ''), (@new_web_id, '出入库申请日期', 'applyDate', 'me.iiv.iivframework.controller.warehouse.output.WarehouseInOutStatisOutput', 'date', 4, 1, 0, 1, ''), (@new_web_id, '出入库确认日期', 'confirmTime', 'me.iiv.iivframework.controller.warehouse.output.WarehouseInOutStatisOutput', 'date', 5, 1, 0, 1, ''), (@new_web_id, '出入库日期', 'bizDate', 'me.iiv.iivframework.controller.warehouse.output.WarehouseInOutStatisOutput', 'string', 6, 1, 0, 1, ''), (@new_web_id, '出入库分类', 'warehouseTypeName', 'me.iiv.iivframework.controller.warehouse.output.WarehouseInOutStatisOutput', 'string', 7, 1, 0, 1, ''), (@new_web_id, '出入库单号', 'orderNo', 'me.iiv.iivframework.controller.warehouse.output.WarehouseInOutStatisOutput', 'string', 8, 1, 0, 1, ''), (@new_web_id, '仓库名称', 'warehouseName', 'me.iiv.iivframework.controller.warehouse.output.WarehouseInOutStatisOutput', 'string', 9, 1, 0, 1, ''), (@new_web_id, '仓库所属公司', 'assetOwnerName', 'me.iiv.iivframework.controller.warehouse.output.WarehouseInOutStatisOutput', 'string', 10, 1, 0, 1, ''), (@new_web_id, '入库数量', 'inCount', 'me.iiv.iivframework.controller.warehouse.output.WarehouseInOutStatisOutput', 'string', 11, 1, 0, 1, ''), (@new_web_id, '出库数量', 'outCount', 'me.iiv.iivframework.controller.warehouse.output.WarehouseInOutStatisOutput', 'string', 12, 1, 0, 1, ''), (@new_web_id, '结余数量', 'balance', 'me.iiv.iivframework.controller.warehouse.output.WarehouseInOutStatisOutput', 'string', 13, 1, 0, 1, ''); -- ───────────────────────────────────────────────────────────── -- ④ field_webpage_authority:字段级权限(动态并集:跟随 ② 授予的 authority 范围 CROSS JOIN page_field) -- ───────────────────────────────────────────────────────────── INSERT INTO field_webpage_authority (web_id, authority_id, cn_name, en_name, is_select, nav_select, field_type, field_id, order_by, check_status, param, is_table_show) SELECT pf.web_id, wa.authority_id, pf.cn_name, pf.en_name, pf.is_select, pf.nav_select, pf.field_type, pf.id, pf.order_by, 1, pf.param, pf.is_table_show FROM page_field pf CROSS JOIN ( SELECT DISTINCT authority_id FROM webpage_authority WHERE web_id = @new_web_id AND soft_delete = 0 ) wa WHERE pf.web_id = @new_web_id; -- ───────────────────────────────────────────────────────────── -- ⑤ button:导出按钮(参照 web_id=258 的 export 按钮样例) -- ───────────────────────────────────────────────────────────── INSERT INTO button (web_id, cn_name, en_name, icon, class_name, function_path, `type`, `status`, order_by, theme, memo, app_en_name) VALUES (@new_web_id, '导出', 'export', '', '', '', 1, 0, 0, 'primary', '', ''); SET @new_button_id := LAST_INSERT_ID(); -- ───────────────────────────────────────────────────────────── -- ⑥ button_webpage_authority:按钮授权(同样动态并集) -- ───────────────────────────────────────────────────────────── INSERT INTO button_webpage_authority (web_id, authority_id, cn_name, en_name, button_id, order_by, check_status, param, icon, `type`, class_name, theme, memo) SELECT @new_web_id, wa.authority_id, '导出', 'export', @new_button_id, 0, 1, '', '', 1, '', 'primary', '' FROM ( SELECT DISTINCT authority_id FROM webpage_authority WHERE web_id = @new_web_id AND soft_delete = 0 ) wa; -- ───────────────────────────────────────────────────────────── -- ⑦ 校验 -- ───────────────────────────────────────────────────────────── SELECT id, parent_id, title, path, order_by FROM webpage WHERE id = @new_web_id; SELECT COUNT(*) AS authority_grants FROM webpage_authority WHERE web_id = @new_web_id; SELECT COUNT(*) AS field_count FROM page_field WHERE web_id = @new_web_id; SELECT COUNT(*) AS field_grants_total FROM field_webpage_authority WHERE web_id = @new_web_id; -- 期待 field_count = 13;field_grants_total = 13 × authority_grants(dev: 13 × 2 = 26) SELECT id, web_id, cn_name, en_name FROM button WHERE id = @new_button_id; SELECT COUNT(*) AS button_grants FROM button_webpage_authority WHERE web_id = @new_web_id; -- 期待 button_grants = authority_grants(dev: 2) COMMIT; -- 失败请改 ROLLBACK -- ============================================================================ -- 上线前 prod sanity check(只读,不随事务执行): -- -- USE xiaoqu_comples_p; -- -- ① 「库存统计」目录 id 是否仍是 213 -- SELECT id, title FROM webpage WHERE id = 213; -- -- ② 213 下兄弟菜单 + 授权并集大小 -- SELECT w.id, w.title, w.order_by, COUNT(DISTINCT wa.authority_id) AS auth_cnt -- FROM webpage w -- LEFT JOIN webpage_authority wa ON wa.web_id = w.id AND wa.soft_delete = 0 -- WHERE w.parent_id = 213 -- GROUP BY w.id, w.title, w.order_by; -- -- ③ 防重复执行:确认 path 尚未存在 -- SELECT id, title, path FROM webpage WHERE path = 'warehouseInOutManage/materialInOutDetail'; -- -- ④ 防按钮重复:确认同目录兄弟菜单 export 按钮样例 -- SELECT id, web_id, cn_name, en_name FROM button WHERE web_id IN (SELECT id FROM webpage WHERE parent_id = 213); -- ============================================================================