-- =====================================================
-- 增量迁移: 补货员管理 + 设备补货单 权限数据
-- 执行方式: 在 haha-admin 数据库中直接执行此 SQL
-- =====================================================

-- 补货员管理模块权限
INSERT IGNORE INTO t_data_permission (permission_code, permission_name, module_code, module_name, operation_type, description, sort_order) VALUES
('replenisher:create', '添加补货员', 'replenisher', '补货员管理', 'create', '创建新补货员', 131),
('replenisher:read', '查询补货员', 'replenisher', '补货员管理', 'read', '查看补货员列表和详情', 132),
('replenisher:update', '修改补货员', 'replenisher', '补货员管理', 'update', '编辑补货员信息和绑定设备', 133),
('replenisher:delete', '删除补货员', 'replenisher', '补货员管理', 'delete', '删除补货员', 134);

-- 设备补货单模块权限
INSERT IGNORE INTO t_data_permission (permission_code, permission_name, module_code, module_name, operation_type, description, sort_order) VALUES
('replenishment:order:create', '创建补货单', 'replenishment-order', '设备补货单', 'create', '创建新补货单', 141),
('replenishment:order:read', '查询补货单', 'replenishment-order', '设备补货单', 'read', '查看补货单列表和详情', 142),
('replenishment:order:update', '修改补货单', 'replenishment-order', '设备补货单', 'update', '编辑补货单信息', 143),
('replenishment:order:delete', '删除补货单', 'replenishment-order', '设备补货单', 'delete', '删除补货单', 144),
('replenishment:order:submit', '提交补货单', 'replenishment-order', '设备补货单', 'execute', '提交补货单', 145),
('replenishment:order:sync', '同步ERP', 'replenishment-order', '设备补货单', 'execute', '同步补货单到ERP系统', 146),
('replenishment:order:complete', '完成补货单', 'replenishment-order', '设备补货单', 'execute', '完成补货单', 147);

-- 为新权限分配超级管理员角色(role_id=1)
INSERT IGNORE INTO t_role_permission (role_id, permission_id)
SELECT 1, id FROM t_data_permission
WHERE module_code IN ('replenisher', 'replenishment-order')
  AND id NOT IN (SELECT permission_id FROM t_role_permission WHERE role_id = 1);
