/* 修改人:Ld 修改时间:2026-08-04 14:33:59; 同步车间派工移动端菜单到正式库 */
SET XACT_ABORT ON;
BEGIN TRAN;

DECLARE @ModuleId INT;

SELECT @ModuleId = id
FROM dbo.基础表_模块信息
WHERE [path] = N'SeikoWorkshop/WorkshopAssignmentMobile';

IF @ModuleId IS NULL
BEGIN
    INSERT INTO dbo.基础表_模块信息
    (
        [path],
        component,
        redirect,
        name,
        title,
        icon,
        是否通知,
        消息通知来源,
        通知条件,
        dashboardIcon,
        是否禁用
    )
    VALUES
    (
        N'SeikoWorkshop/WorkshopAssignmentMobile',
        N'/SeikoWorkshop/WorkshopAssignmentMobile',
        NULL,
        N'WorkshopAssignmentMobile',
        N'车间派工移动端',
        N'ShopScheduling',
        NULL,
        NULL,
        NULL,
        NULL,
        0
    );

    SET @ModuleId = SCOPE_IDENTITY();
END
ELSE
BEGIN
    UPDATE dbo.基础表_模块信息
    SET component = N'/SeikoWorkshop/WorkshopAssignmentMobile',
        redirect = NULL,
        name = N'WorkshopAssignmentMobile',
        title = N'车间派工移动端',
        icon = N'ShopScheduling',
        是否禁用 = 0
    WHERE id = @ModuleId;
END;

/* 修改人:Ld 修改时间:2026-08-04 14:33:59; 按测试库配置给角色2追加精工车间移动端派工菜单权限 */
IF NOT EXISTS
(
    SELECT 1
    FROM dbo.基础表_角色模块信息
    WHERE id = @ModuleId
      AND pid = 26
      AND 角色编号 = 2
)
BEGIN
    INSERT INTO dbo.基础表_角色模块信息
    (
        id,
        pid,
        模块顺序,
        角色编号,
        是否启用,
        角色模块顺序
    )
    SELECT
        @ModuleId,
        26,
        @ModuleId,
        2,
        1,
        ISNULL(MAX(角色模块顺序), 0) + 1
    FROM dbo.基础表_角色模块信息
    WHERE 角色编号 = 2
      AND pid = 26;
END
ELSE
BEGIN
    UPDATE dbo.基础表_角色模块信息
    SET 是否启用 = 1
    WHERE id = @ModuleId
      AND pid = 26
      AND 角色编号 = 2;
END;

SELECT @ModuleId AS 模块ID;
SELECT id, [path], component, name, title, icon, 是否禁用
FROM dbo.基础表_模块信息
WHERE id = @ModuleId;

SELECT id, pid, 模块顺序, 角色编号, 是否启用, 角色模块顺序
FROM dbo.基础表_角色模块信息
WHERE id = @ModuleId
ORDER BY 角色编号;

COMMIT TRAN;
