-- --------------------------------------------------------------------------------------
-- 初始化系统基础数据
-- --------------------------------------------------------------------------------------

-- 初始化租户数据
INSERT INTO sys_tenant (id, create_time, code, name, address, contact_name, contact_phone, email, enabled)
VALUES (1, NOW(), 'admin', '系统管理租户', '北京市朝阳区', '管理员', '13800138000', 'admin@system.com', 1);

-- 初始化部门数据
INSERT INTO sys_department (id, create_time, code, name, description, sort, enabled)
VALUES (1, NOW(), 'ROOT', '根部门', '系统根部门', 0, 1);

INSERT INTO sys_department (id, create_time, code, name, description, parent_id, sort, enabled)
VALUES 
(2, NOW(), 'IT', '信息技术部', '负责公司IT系统的规划、建设和运维', 1, 1, 1),
(3, NOW(), 'DEV', '研发部', '负责产品研发和技术创新', 1, 2, 1),
(4, NOW(), 'OPS', '运维部', '负责系统运维和技术支持', 1, 3, 1);

-- 初始化用户数据（密码统一为：123456）
INSERT INTO sys_user (id, create_time, username, password, nickname, email, phone, department_id, enabled)
VALUES 
(1, NOW(), 'admin', '$2a$10$viWVqfZwQxViLQDk7hhVg.ENYT.3zUFf.aBetlarImKPSS0V2gbSa', '超级管理员', 'admin@system.com', '13800138000', 1, 1),
(2, NOW(), 'it_manager', '$2a$10$viWVqfZwQxViLQDk7hhVg.ENYT.3zUFf.aBetlarImKPSS0V2gbSa', 'IT经理', 'it@system.com', '13800138001', 2, 1),
(3, NOW(), 'dev_manager', '$2a$10$viWVqfZwQxViLQDk7hhVg.ENYT.3zUFf.aBetlarImKPSS0V2gbSa', '研发经理', 'dev@system.com', '13800138002', 3, 1),
(4, NOW(), 'ops_manager', '$2a$10$viWVqfZwQxViLQDk7hhVg.ENYT.3zUFf.aBetlarImKPSS0V2gbSa', '运维经理', 'ops@system.com', '13800138003', 4, 1);

-- 初始化系统参数
INSERT INTO sys_param (id, create_time, code, name, value, type, description, enabled)
VALUES 
(1, NOW(), 'SYSTEM_NAME', '系统名称', 'Deploy Ease Platform', 'STRING', '系统显示名称', 1),
(2, NOW(), 'SYSTEM_LOGO', '系统Logo', '/static/logo.png', 'STRING', '系统Logo路径', 1),
(3, NOW(), 'LOGIN_BACKGROUND', '登录背景', '/static/login-bg.jpg', 'STRING', '登录页面背景图片', 1);

-- --------------------------------------------------------------------------------------
-- 初始化权限管理数据
-- --------------------------------------------------------------------------------------

-- --------------------------------------------------------------------------------------
-- 初始化权限管理数据
-- --------------------------------------------------------------------------------------

-- --------------------------------------------------------------------------------------
-- 初始化权限管理数据
-- --------------------------------------------------------------------------------------

-- 先清理已有数据
DELETE FROM sys_menu;

INSERT INTO sys_menu (id, name, path, component, icon, permission, type, parent_id, sort, hidden, enabled, create_by, create_time, version, deleted)
VALUES
-- 首页
(99, '工作台', '/dashboard', 'Dashboard', 'DashboardOutlined', NULL, 2, NULL, 0, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),

-- 工作流管理
(100, '工作流管理', '/workflow', NULL, 'DeploymentUnitOutlined', NULL, 1, NULL, 1, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 工作流设计
(101, '工作流设计', '/workflow/definitions', 'Workflow/Definition/List', 'EditOutlined', 'workflow:definition', 2, 100, 10, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 工作流设计器（隐藏路由，用于编辑工作流）
(1011, '工作流设计器', '/workflow/design/:id', 'Workflow/Design', 'EditOutlined', NULL, 2, 100, 11, TRUE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 工作流实例
(102, '工作流实例', '/workflow/instances', 'Workflow/Instance/List', 'BranchesOutlined', 'workflow:instance', 2, 100, 20, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 表单管理
(104, '表单管理', '/workflow/form', 'Form/Definition/List', 'FormOutlined', 'workflow:form', 2, 100, 30, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 表单设计器（隐藏路由，用于设计表单）
(1041, '表单设计器', '/workflow/form/:id/design', 'Form/Definition/Designer', 'FormOutlined', NULL, 2, 100, 31, TRUE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 表单数据详情（隐藏路由，用于查看表单数据）
(1042, '表单数据详情', '/workflow/form/data/:id', 'Form/Data/List/Detail', 'FileTextOutlined', NULL, 2, 100, 32, TRUE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 运维管理
(200, '运维管理', '/deploy', NULL, 'DeploymentUnitOutlined', NULL, 1, NULL, 2, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 团队管理
(201, '团队管理', '/deploy/teams', 'Deploy/Team/List', 'TeamOutlined', 'deploy:team', 2, 200, 1, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 应用管理
(202, '应用管理', '/deploy/applications', 'Deploy/Application/List', 'AppstoreOutlined', 'deploy:application', 2, 200, 2, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 定时任务管理
(203, '定时任务管理', '/deploy/schedule-jobs', 'Deploy/ScheduleJob/List', 'ClockCircleOutlined', 'deploy:schedule-job', 2, 200, 3, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 环境管理
(204, '环境管理', '/deploy/environments', 'Deploy/Environment/List', 'CloudOutlined', 'deploy:environment', 2, 200, 4, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),

-- 资源管理
(300, '资源管理', '/resource', NULL, 'DatabaseOutlined', NULL, 1, NULL, 3, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 服务器管理
(301, '服务器管理', '/resource/servers', 'Resource/Server/List', 'CloudServerOutlined', 'resource:server', 2, 300, 1, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- Jenkins管理
(302, 'Jenkins管理', '/resource/jenkins', 'Resource/Jenkins/List', 'BuildOutlined', 'resource:jenkins', 2, 300, 2, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- Git管理
(303, 'Git管理', '/resource/git', 'Resource/Git/List', 'GithubOutlined', 'resource:git', 2, 300, 3, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 三方系统管理
(304, '三方系统管理', '/resource/external', 'Resource/External/List', 'ApiOutlined', 'resource:external', 2, 300, 4, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),

-- 系统管理
(1, '系统管理', '/system', NULL, 'SettingOutlined', NULL, 1, NULL, 99, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 用户管理
(2, '用户管理', '/system/users', 'System/User/List', 'UserOutlined', 'system:user', 2, 1, 10, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 角色管理
(3, '角色管理', '/system/roles', 'System/Role/List', 'TeamOutlined', 'system:role', 2, 1, 20, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 菜单管理
(4, '菜单管理', '/system/menus', 'System/Menu/List', 'MenuOutlined', 'system:menu', 2, 1, 30, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 部门管理
(5, '部门管理', '/system/departments', 'System/Department/List', 'ApartmentOutlined', 'system:department', 2, 1, 40, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 权限管理（隐藏菜单）
(6, '权限管理', '/system/permissions', 'System/Permission/List', 'SafetyOutlined', 'system:permission', 2, 1, 50, TRUE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE);

-- ==================== 初始化角色数据 ====================
DELETE FROM sys_role WHERE id < 100;

INSERT INTO sys_role (id, create_time, code, name, type, description, sort, is_admin)
VALUES
(1, NOW(), 'ROLE_ADMIN', '管理员', 1, '系统管理员，拥有所有权限', 1, 1),
(2, NOW(), 'ROLE_OPS', '运维', 2, '运维人员，负责服务器、部署等运维工作', 2, 0),
(3, NOW(), 'ROLE_DEV', '开发', 2, '开发人员，负责应用开发和部署', 3, 0),
(4, NOW(), 'ROLE_HR', 'HR', 2, '人力资源，负责人员管理', 4, 0),
(5, NOW(), 'ROLE_BA', 'BA/产品', 2, '业务分析/产品经理，负责需求和产品管理', 5, 0);

-- 初始化角色标签
INSERT INTO sys_role_tag (id, create_time, name, color)
VALUES 
(1, NOW(), '系统内置', '#ff4d4f'),
(2, NOW(), '重要角色', '#ffa940'),
(3, NOW(), '普通角色', '#73d13d');

-- 初始化角色标签关联
INSERT INTO sys_role_tag_relation (role_id, tag_id)
VALUES 
(1, 1),
(2, 1),
(2, 2),
(3, 3);

-- 初始化用户角色关联
INSERT INTO sys_user_role (user_id, role_id)
VALUES 
( 1, 1),
( 2, 2),
(3, 2),
(4, 3);

-- 初始化角色菜单关联
INSERT INTO sys_role_menu (role_id, menu_id)
SELECT 1, id FROM sys_menu;  -- 管理员拥有所有菜单权限

INSERT INTO sys_role_menu (role_id, menu_id)
VALUES 
(2, 200), (2, 201), (2, 202), (2, 203), (2, 204), (2, 300), (2, 301), (2, 302), (2, 303), (2, 304),  -- 运维拥有运维管理和资源管理权限
(3, 100), (3, 101), (3, 102), (3, 104), (3, 200), (3, 202);  -- 开发拥有工作流和应用管理权限

-- ==================== 初始化权限数据 ====================
DELETE FROM sys_permission WHERE id < 10000;

-- 系统管理权限
-- INSERT INTO sys_permission (id, create_time, menu_id, code, name, type, sort) VALUES
-- -- 用户管理 (menu_id=2)
-- (1, NOW(), 2, 'system:user:list', '用户查询', 'FUNCTION', 1),
-- (2, NOW(), 2, 'system:user:view', '用户详情', 'FUNCTION', 2),
-- (3, NOW(), 2, 'system:user:create', '用户创建', 'FUNCTION', 3),
-- (4, NOW(), 2, 'system:user:update', '用户修改', 'FUNCTION', 4),
-- (5, NOW(), 2, 'system:user:delete', '用户删除', 'FUNCTION', 5),
--
-- -- 角色管理 (menu_id=3)
-- (11, NOW(), 3, 'system:role:list', '角色查询', 'FUNCTION', 1),
-- (12, NOW(), 3, 'system:role:view', '角色详情', 'FUNCTION', 2),
-- (13, NOW(), 3, 'system:role:create', '角色创建', 'FUNCTION', 3),
-- (14, NOW(), 3, 'system:role:update', '角色修改', 'FUNCTION', 4),
-- (15, NOW(), 3, 'system:role:delete', '角色删除', 'FUNCTION', 5),
-- (16, NOW(), 3, 'system:role:permission-tree', '获取权限树', 'FUNCTION', 6),
-- (17, NOW(), 3, 'system:role:assign-tags', '分配标签', 'FUNCTION', 7),
-- (18, NOW(), 3, 'system:role:assign-roles', '分配角色', 'FUNCTION', 8),
-- (19, NOW(), 3, 'system:role:get-permissions', '获取角色权限', 'FUNCTION', 9),
-- (20, NOW(), 3, 'system:role:assign-permissions', '分配权限', 'FUNCTION', 10),
--
-- -- 菜单管理 (menu_id=4)
-- (21, NOW(), 4, 'system:menu:list', '菜单查询', 'FUNCTION', 1),
-- (22, NOW(), 4, 'system:menu:view', '菜单详情', 'FUNCTION', 2),
-- (23, NOW(), 4, 'system:menu:create', '菜单创建', 'FUNCTION', 3),
-- (24, NOW(), 4, 'system:menu:update', '菜单修改', 'FUNCTION', 4),
-- (25, NOW(), 4, 'system:menu:delete', '菜单删除', 'FUNCTION', 5),
--
-- -- 权限管理 (menu_id=6)
-- (26, NOW(), 6, 'system:permission:list', '权限查询', 'FUNCTION', 1),
-- (27, NOW(), 6, 'system:permission:view', '权限详情', 'FUNCTION', 2),
-- (28, NOW(), 6, 'system:permission:create', '权限创建', 'FUNCTION', 3),
-- (29, NOW(), 6, 'system:permission:update', '权限修改', 'FUNCTION', 4),
-- (30, NOW(), 6, 'system:permission:delete', '权限删除', 'FUNCTION', 5),
--
-- -- 部门管理 (menu_id=5)
-- (31, NOW(), 5, 'system:department:list', '部门查询', 'FUNCTION', 1),
-- (32, NOW(), 5, 'system:department:view', '部门详情', 'FUNCTION', 2),
-- (33, NOW(), 5, 'system:department:create', '部门创建', 'FUNCTION', 3),
-- (34, NOW(), 5, 'system:department:update', '部门修改', 'FUNCTION', 4),
-- (35, NOW(), 5, 'system:department:delete', '部门删除', 'FUNCTION', 5),
--
-- -- 运维管理权限
-- -- 团队管理 (menu_id=201)
-- (101, NOW(), 201, 'deploy:team:list', '团队查询', 'FUNCTION', 1),
-- (102, NOW(), 201, 'deploy:team:view', '团队详情', 'FUNCTION', 2),
-- (103, NOW(), 201, 'deploy:team:create', '团队创建', 'FUNCTION', 3),
-- (104, NOW(), 201, 'deploy:team:update', '团队修改', 'FUNCTION', 4),
-- (105, NOW(), 201, 'deploy:team:delete', '团队删除', 'FUNCTION', 5),
--
-- -- 应用管理 (menu_id=202)
-- (111, NOW(), 202, 'deploy:application:list', '应用查询', 'FUNCTION', 1),
-- (112, NOW(), 202, 'deploy:application:view', '应用详情', 'FUNCTION', 2),
-- (113, NOW(), 202, 'deploy:application:create', '应用创建', 'FUNCTION', 3),
-- (114, NOW(), 202, 'deploy:application:update', '应用修改', 'FUNCTION', 4),
-- (115, NOW(), 202, 'deploy:application:delete', '应用删除', 'FUNCTION', 5),
--
-- -- 定时任务管理 (menu_id=203)
-- (121, NOW(), 203, 'deploy:schedule-job:list', '任务查询', 'FUNCTION', 1),
-- (122, NOW(), 203, 'deploy:schedule-job:view', '任务详情', 'FUNCTION', 2),
-- (123, NOW(), 203, 'deploy:schedule-job:create', '任务创建', 'FUNCTION', 3),
-- (124, NOW(), 203, 'deploy:schedule-job:update', '任务修改', 'FUNCTION', 4),
-- (125, NOW(), 203, 'deploy:schedule-job:delete', '任务删除', 'FUNCTION', 5),
-- (126, NOW(), 203, 'deploy:schedule-job:pause', '暂停任务', 'FUNCTION', 6),
-- (127, NOW(), 203, 'deploy:schedule-job:resume', '恢复任务', 'FUNCTION', 7),
-- (128, NOW(), 203, 'deploy:schedule-job:disable', '禁用任务', 'FUNCTION', 8),
-- (129, NOW(), 203, 'deploy:schedule-job:enable', '启用任务', 'FUNCTION', 9),
-- (130, NOW(), 203, 'deploy:schedule-job:trigger', '手动触发', 'FUNCTION', 10),
--
-- -- 环境管理 (menu_id=204)
-- (141, NOW(), 204, 'deploy:environment:list', '环境查询', 'FUNCTION', 1),
-- (142, NOW(), 204, 'deploy:environment:view', '环境详情', 'FUNCTION', 2),
-- (143, NOW(), 204, 'deploy:environment:create', '环境创建', 'FUNCTION', 3),
-- (144, NOW(), 204, 'deploy:environment:update', '环境修改', 'FUNCTION', 4),
-- (145, NOW(), 204, 'deploy:environment:delete', '环境删除', 'FUNCTION', 5),
--
-- -- 团队配置管理 (无对应菜单，menu_id=NULL)
-- (151, NOW(), NULL, 'deploy:team-config:list', '团队配置查询', 'FUNCTION', 11),
-- (152, NOW(), NULL, 'deploy:team-config:view', '团队配置详情', 'FUNCTION', 12),
-- (153, NOW(), NULL, 'deploy:team-config:update', '团队配置修改', 'FUNCTION', 13),
--
-- -- 团队成员管理 (无对应菜单，menu_id=NULL)
-- (161, NOW(), NULL, 'deploy:team-member:list', '团队成员查询', 'FUNCTION', 21),
-- (162, NOW(), NULL, 'deploy:team-member:view', '团队成员详情', 'FUNCTION', 22),
-- (163, NOW(), NULL, 'deploy:team-member:create', '团队成员创建', 'FUNCTION', 23),
-- (164, NOW(), NULL, 'deploy:team-member:update', '团队成员修改', 'FUNCTION', 24),
-- (165, NOW(), NULL, 'deploy:team-member:delete', '团队成员删除', 'FUNCTION', 25),
--
-- -- 团队应用管理 (无对应菜单，menu_id=NULL)
-- (171, NOW(), NULL, 'deploy:team-application:list', '团队应用查询', 'FUNCTION', 31),
-- (172, NOW(), NULL, 'deploy:team-application:view', '团队应用详情', 'FUNCTION', 32),
-- (173, NOW(), NULL, 'deploy:team-application:create', '团队应用创建', 'FUNCTION', 33),
-- (174, NOW(), NULL, 'deploy:team-application:update', '团队应用修改', 'FUNCTION', 34),
-- (175, NOW(), NULL, 'deploy:team-application:delete', '团队应用删除', 'FUNCTION', 35),
--
-- -- 应用分类管理 (无对应菜单，menu_id=NULL)
-- (181, NOW(), NULL, 'deploy:application-category:list', '应用分类查询', 'FUNCTION', 11),
-- (182, NOW(), NULL, 'deploy:application-category:view', '应用分类详情', 'FUNCTION', 12),
-- (183, NOW(), NULL, 'deploy:application-category:create', '应用分类创建', 'FUNCTION', 13),
-- (184, NOW(), NULL, 'deploy:application-category:update', '应用分类修改', 'FUNCTION', 14),
-- (185, NOW(), NULL, 'deploy:application-category:delete', '应用分类删除', 'FUNCTION', 15),
--
-- -- 服务器分类管理 (无对应菜单，menu_id=NULL)
-- (191, NOW(), NULL, 'deploy:server-category:list', '服务器分类查询', 'FUNCTION', 11),
-- (192, NOW(), NULL, 'deploy:server-category:view', '服务器分类详情', 'FUNCTION', 12),
-- (193, NOW(), NULL, 'deploy:server-category:create', '服务器分类创建', 'FUNCTION', 13),
-- (194, NOW(), NULL, 'deploy:server-category:update', '服务器分类修改', 'FUNCTION', 14),
-- (195, NOW(), NULL, 'deploy:server-category:delete', '服务器分类删除', 'FUNCTION', 15),
--
-- -- 定时任务日志 (无对应菜单，menu_id=NULL)
-- (201, NOW(), NULL, 'deploy:schedule-job-log:list', '任务日志查询', 'FUNCTION', 21),
-- (202, NOW(), NULL, 'deploy:schedule-job-log:view', '任务日志详情', 'FUNCTION', 22),
-- (203, NOW(), NULL, 'deploy:schedule-job-log:delete', '任务日志删除', 'FUNCTION', 23),
--
-- -- 定时任务分类 (无对应菜单，menu_id=NULL)
-- (211, NOW(), NULL, 'deploy:schedule-job-category:list', '任务分类查询', 'FUNCTION', 31),
-- (212, NOW(), NULL, 'deploy:schedule-job-category:view', '任务分类详情', 'FUNCTION', 32),
-- (213, NOW(), NULL, 'deploy:schedule-job-category:create', '任务分类创建', 'FUNCTION', 33),
-- (214, NOW(), NULL, 'deploy:schedule-job-category:update', '任务分类修改', 'FUNCTION', 34),
-- (215, NOW(), NULL, 'deploy:schedule-job-category:delete', '任务分类删除', 'FUNCTION', 35),
--
-- -- 资源管理权限（继续补充）
-- -- 服务器管理 (menu_id=301)
-- (221, NOW(), 301, 'resource:server:list', '服务器查询', 'FUNCTION', 1),
-- (222, NOW(), 301, 'resource:server:view', '服务器详情', 'FUNCTION', 2),
-- (223, NOW(), 301, 'resource:server:create', '服务器创建', 'FUNCTION', 3),
-- (224, NOW(), 301, 'resource:server:update', '服务器修改', 'FUNCTION', 4),
-- (225, NOW(), 301, 'resource:server:delete', '服务器删除', 'FUNCTION', 5),
--
-- -- Jenkins管理 (menu_id=302)
-- (231, NOW(), 302, 'resource:jenkins:list', 'Jenkins查询', 'FUNCTION', 1),
-- (232, NOW(), 302, 'resource:jenkins:view', 'Jenkins详情', 'FUNCTION', 2),
-- (233, NOW(), 302, 'resource:jenkins:create', 'Jenkins创建', 'FUNCTION', 3),
-- (234, NOW(), 302, 'resource:jenkins:update', 'Jenkins修改', 'FUNCTION', 4),
-- (235, NOW(), 302, 'resource:jenkins:delete', 'Jenkins删除', 'FUNCTION', 5),
--
-- -- Jenkins Job管理 (无对应菜单，menu_id=NULL)
-- (241, NOW(), NULL, 'resource:jenkins-job:list', 'Jenkins任务查询', 'FUNCTION', 11),
-- (242, NOW(), NULL, 'resource:jenkins-job:view', 'Jenkins任务详情', 'FUNCTION', 12),
-- (243, NOW(), NULL, 'resource:jenkins-job:create', 'Jenkins任务创建', 'FUNCTION', 13),
-- (244, NOW(), NULL, 'resource:jenkins-job:update', 'Jenkins任务修改', 'FUNCTION', 14),
-- (245, NOW(), NULL, 'resource:jenkins-job:delete', 'Jenkins任务删除', 'FUNCTION', 15),
-- (246, NOW(), NULL, 'resource:jenkins-job:sync', '同步Jenkins任务', 'FUNCTION', 16),
--
-- -- Jenkins View管理 (无对应菜单，menu_id=NULL)
-- (251, NOW(), NULL, 'resource:jenkins-view:list', 'Jenkins视图查询', 'FUNCTION', 21),
-- (252, NOW(), NULL, 'resource:jenkins-view:view', 'Jenkins视图详情', 'FUNCTION', 22),
-- (253, NOW(), NULL, 'resource:jenkins-view:sync', '同步Jenkins视图', 'FUNCTION', 23),
--
-- -- Jenkins Build管理 (无对应菜单，menu_id=NULL)
-- (261, NOW(), NULL, 'resource:jenkins-build:list', '构建记录查询', 'FUNCTION', 31),
-- (262, NOW(), NULL, 'resource:jenkins-build:view', '构建记录详情', 'FUNCTION', 32),
-- (263, NOW(), NULL, 'resource:jenkins-build:sync', '同步构建记录', 'FUNCTION', 33),
--
-- -- Jenkins Sync History (无对应菜单，menu_id=NULL)
-- (271, NOW(), NULL, 'resource:jenkins-sync:list', '同步历史查询', 'FUNCTION', 41),
-- (272, NOW(), NULL, 'resource:jenkins-sync:view', '同步历史详情', 'FUNCTION', 42),
--
-- -- Git管理 (menu_id=303)
-- (281, NOW(), 303, 'resource:git:list', 'Git查询', 'FUNCTION', 1),
-- (282, NOW(), 303, 'resource:git:view', 'Git详情', 'FUNCTION', 2),
-- (283, NOW(), 303, 'resource:git:create', 'Git创建', 'FUNCTION', 3),
-- (284, NOW(), 303, 'resource:git:update', 'Git修改', 'FUNCTION', 4),
-- (285, NOW(), 303, 'resource:git:delete', 'Git删除', 'FUNCTION', 5),
--
-- -- 仓库组管理 (无对应菜单，menu_id=NULL)
-- (291, NOW(), NULL, 'resource:repository-group:list', '仓库组查询', 'FUNCTION', 11),
-- (292, NOW(), NULL, 'resource:repository-group:view', '仓库组详情', 'FUNCTION', 12),
-- (293, NOW(), NULL, 'resource:repository-group:create', '仓库组创建', 'FUNCTION', 13),
-- (294, NOW(), NULL, 'resource:repository-group:update', '仓库组修改', 'FUNCTION', 14),
-- (295, NOW(), NULL, 'resource:repository-group:delete', '仓库组删除', 'FUNCTION', 15),
--
-- -- 仓库项目管理 (无对应菜单，menu_id=NULL)
-- (301, NOW(), NULL, 'resource:repository-project:list', '仓库项目查询', 'FUNCTION', 21),
-- (302, NOW(), NULL, 'resource:repository-project:view', '仓库项目详情', 'FUNCTION', 22),
-- (303, NOW(), NULL, 'resource:repository-project:create', '仓库项目创建', 'FUNCTION', 23),
-- (304, NOW(), NULL, 'resource:repository-project:update', '仓库项目修改', 'FUNCTION', 24),
-- (305, NOW(), NULL, 'resource:repository-project:delete', '仓库项目删除', 'FUNCTION', 25),
-- (306, NOW(), NULL, 'resource:repository-project:sync', '同步仓库项目', 'FUNCTION', 26),
--
-- -- 仓库分支管理 (无对应菜单，menu_id=NULL)
-- (311, NOW(), NULL, 'resource:repository-branch:list', '仓库分支查询', 'FUNCTION', 31),
-- (312, NOW(), NULL, 'resource:repository-branch:view', '仓库分支详情', 'FUNCTION', 32),
-- (313, NOW(), NULL, 'resource:repository-branch:sync', '同步仓库分支', 'FUNCTION', 33),
--
-- -- 三方系统管理 (menu_id=304)
-- (321, NOW(), 304, 'resource:external:list', '三方系统查询', 'FUNCTION', 1),
-- (322, NOW(), 304, 'resource:external:view', '三方系统详情', 'FUNCTION', 2),
-- (323, NOW(), 304, 'resource:external:create', '三方系统创建', 'FUNCTION', 3),
-- (324, NOW(), 304, 'resource:external:update', '三方系统修改', 'FUNCTION', 4),
-- (325, NOW(), 304, 'resource:external:delete', '三方系统删除', 'FUNCTION', 5),
--
-- -- 工作流管理权限（继续补充）
-- -- 工作流设计 (menu_id=101)
-- (331, NOW(), 101, 'workflow:definition:list', '工作流查询', 'FUNCTION', 1),
-- (332, NOW(), 101, 'workflow:definition:view', '工作流详情', 'FUNCTION', 2),
-- (333, NOW(), 101, 'workflow:definition:create', '工作流创建', 'FUNCTION', 3),
-- (334, NOW(), 101, 'workflow:definition:update', '工作流修改', 'FUNCTION', 4),
-- (335, NOW(), 101, 'workflow:definition:delete', '工作流删除', 'FUNCTION', 5),
--
-- -- 工作流实例 (menu_id=102)
-- (341, NOW(), 102, 'workflow:instance:list', '实例查询', 'FUNCTION', 1),
-- (342, NOW(), 102, 'workflow:instance:view', '实例详情', 'FUNCTION', 2),
-- (343, NOW(), 102, 'workflow:instance:create', '实例创建', 'FUNCTION', 3),
-- (344, NOW(), 102, 'workflow:instance:update', '实例修改', 'FUNCTION', 4),
-- (345, NOW(), 102, 'workflow:instance:delete', '实例删除', 'FUNCTION', 5),
--
-- -- 节点定义管理 (无对应菜单，menu_id=NULL)
-- (351, NOW(), NULL, 'workflow:node-definition:list', '节点定义查询', 'FUNCTION', 11),
-- (352, NOW(), NULL, 'workflow:node-definition:view', '节点定义详情', 'FUNCTION', 12),
-- (353, NOW(), NULL, 'workflow:node-definition:create', '节点定义创建', 'FUNCTION', 13),
-- (354, NOW(), NULL, 'workflow:node-definition:update', '节点定义修改', 'FUNCTION', 14),
-- (355, NOW(), NULL, 'workflow:node-definition:delete', '节点定义删除', 'FUNCTION', 15),
--
-- -- 节点实例管理 (无对应菜单，menu_id=NULL)
-- (361, NOW(), NULL, 'workflow:node-instance:list', '节点实例查询', 'FUNCTION', 11),
-- (362, NOW(), NULL, 'workflow:node-instance:view', '节点实例详情', 'FUNCTION', 12),
-- (363, NOW(), NULL, 'workflow:node-instance:update', '节点实例修改', 'FUNCTION', 13),
-- (364, NOW(), NULL, 'workflow:node-instance:delete', '节点实例删除', 'FUNCTION', 15),
--
-- -- 工作流分类 (无对应菜单，menu_id=NULL)
-- (371, NOW(), NULL, 'workflow:category:list', '工作流分类查询', 'FUNCTION', 21),
-- (372, NOW(), NULL, 'workflow:category:view', '工作流分类详情', 'FUNCTION', 22),
-- (373, NOW(), NULL, 'workflow:category:create', '工作流分类创建', 'FUNCTION', 23),
-- (374, NOW(), NULL, 'workflow:category:update', '工作流分类修改', 'FUNCTION', 24),
-- (375, NOW(), NULL, 'workflow:category:delete', '工作流分类删除', 'FUNCTION', 25),
--
-- -- 表单管理 (menu_id=104)
-- (381, NOW(), 104, 'workflow:form:list', '表单查询', 'FUNCTION', 1),
-- (382, NOW(), 104, 'workflow:form:view', '表单详情', 'FUNCTION', 2),
-- (383, NOW(), 104, 'workflow:form:create', '表单创建', 'FUNCTION', 3),
-- (384, NOW(), 104, 'workflow:form:update', '表单修改', 'FUNCTION', 4),
-- (385, NOW(), 104, 'workflow:form:delete', '表单删除', 'FUNCTION', 5),
--
-- -- 表单数据管理 (无对应菜单，menu_id=NULL)
-- (391, NOW(), NULL, 'workflow:form-data:list', '表单数据查询', 'FUNCTION', 11),
-- (392, NOW(), NULL, 'workflow:form-data:view', '表单数据详情', 'FUNCTION', 12),
-- (393, NOW(), NULL, 'workflow:form-data:create', '表单数据创建', 'FUNCTION', 13),
-- (394, NOW(), NULL, 'workflow:form-data:update', '表单数据修改', 'FUNCTION', 14),
-- (395, NOW(), NULL, 'workflow:form-data:delete', '表单数据删除', 'FUNCTION', 15),
--
-- -- 表单分类管理 (无对应菜单，menu_id=NULL)
-- (401, NOW(), NULL, 'workflow:form-category:list', '表单分类查询', 'FUNCTION', 21),
-- (402, NOW(), NULL, 'workflow:form-category:view', '表单分类详情', 'FUNCTION', 22),
-- (403, NOW(), NULL, 'workflow:form-category:create', '表单分类创建', 'FUNCTION', 23),
-- (404, NOW(), NULL, 'workflow:form-category:update', '表单分类修改', 'FUNCTION', 24),
-- (405, NOW(), NULL, 'workflow:form-category:delete', '表单分类删除', 'FUNCTION', 25),
--
-- -- 审批任务管理 (无对应菜单，menu_id=NULL)
-- (411, NOW(), NULL, 'workflow:approval:list', '审批任务查询', 'FUNCTION', 21),
-- (412, NOW(), NULL, 'workflow:approval:view', '审批任务详情', 'FUNCTION', 22),
-- (413, NOW(), NULL, 'workflow:approval:approve', '审批任务通过', 'FUNCTION', 23),
-- (414, NOW(), NULL, 'workflow:approval:reject', '审批任务驳回', 'FUNCTION', 24),
-- (415, NOW(), NULL, 'workflow:approval:transfer', '审批任务转交', 'FUNCTION', 25),
--
-- -- 系统管理权限（继续补充）
-- -- 角色标签管理 (无对应菜单，menu_id=NULL)
-- (421, NOW(), NULL, 'system:role-tag:list', '角色标签查询', 'FUNCTION', 11),
-- (422, NOW(), NULL, 'system:role-tag:view', '角色标签详情', 'FUNCTION', 12),
-- (423, NOW(), NULL, 'system:role-tag:create', '角色标签创建', 'FUNCTION', 13),
-- (424, NOW(), NULL, 'system:role-tag:update', '角色标签修改', 'FUNCTION', 14),
-- (425, NOW(), NULL, 'system:role-tag:delete', '角色标签删除', 'FUNCTION', 15),
--
-- -- 通知管理权限
-- -- 通知渠道管理 (无对应菜单，menu_id=NULL)
-- (431, NOW(), NULL, 'notification:channel:list', '通知渠道查询', 'FUNCTION', 11),
-- (432, NOW(), NULL, 'notification:channel:view', '通知渠道详情', 'FUNCTION', 12),
-- (433, NOW(), NULL, 'notification:channel:create', '通知渠道创建', 'FUNCTION', 13),
-- (434, NOW(), NULL, 'notification:channel:update', '通知渠道修改', 'FUNCTION', 14),
-- (435, NOW(), NULL, 'notification:channel:delete', '通知渠道删除', 'FUNCTION', 15);

-- ==================== 分配权限给角色 ====================
DELETE FROM sys_role_permission;

-- 管理员拥有所有权限
INSERT INTO sys_role_permission (role_id, permission_id)
SELECT 1, id FROM sys_permission WHERE id < 10000;

-- 运维角色权限（运维管理权限）
INSERT INTO sys_role_permission (role_id, permission_id)
SELECT 2, id FROM sys_permission WHERE code LIKE 'deploy:%';

-- 开发角色权限（应用管理权限）
INSERT INTO sys_role_permission (role_id, permission_id)
SELECT 3, id FROM sys_permission WHERE code LIKE 'deploy:application:%';

-- ==================== 分配角色给用户 ====================
DELETE FROM sys_user_role;

-- admin 用户拥有管理员角色
INSERT INTO sys_user_role (user_id, role_id) VALUES (1, 1);

-- ops_manager 拥有运维角色
INSERT INTO sys_user_role (user_id, role_id) VALUES (4, 2);

-- dev_manager 拥有开发角色
INSERT INTO sys_user_role (user_id, role_id) VALUES (3, 3);

-- 初始化权限模板
INSERT INTO sys_permission_template (id, create_time, code, name, type, description, enabled)
VALUES 
(1, NOW(), 'FULL_PERMISSION', '完整权限模板', 1, '包含所有系统权限的模板', 1),
(2, NOW(), 'BASIC_PERMISSION', '基础权限模板', 1, '包含基本操作权限的模板', 1);

-- 初始化模板菜单关联
INSERT INTO sys_template_menu (template_id, menu_id)
SELECT 1, id FROM sys_menu;  -- 完整权限模板关联所有菜单

INSERT INTO sys_template_menu (template_id, menu_id)
VALUES (2, 304);  -- 基础权限模板关联三方系统菜单

-- --------------------------------------------------------------------------------------
-- 初始化外部系统数据
-- --------------------------------------------------------------------------------------

-- 初始化外部系统
INSERT INTO sys_external_system (
    id, create_by, create_time, deleted, update_by, update_time, version,
    name, type, url, remark, sort, enabled, auth_type, username, password, token,
    sync_status, last_sync_time, last_connect_time, config
) VALUES (
    1, 'admin', '2023-12-01 00:00:00', 0, 'admin', '2023-12-01 00:00:00', 0,
    '链宇JENKINS', 'JENKINS', 'https://ly-jenkins.iscmtech.com', '链宇JENKINS', 1, 1,
    'BASIC', 'admin', 'Lianyu!@#~123456', NULL,
    'SUCCESS', '2023-12-01 00:00:00', '2023-12-01 00:00:00', '{}'
), (
    2, 'admin', '2024-12-03 10:35:58.932966', 0, 'admin', '2024-12-03 10:35:58.932966', 0,
    '链宇GIT', 'GIT', 'https://ly-gitlab.iscmtech.com/', NULL, 1, 1,
    'TOKEN', NULL, NULL, 'cNSud7D1GmYQKEMco7s5',
    NULL, NULL, NULL, '{}'
);

-- --------------------------------------------------------------------------------------
-- 初始化工作流相关数据
-- --------------------------------------------------------------------------------------

-- 工作流分类初始数据
INSERT INTO workflow_category (name, code, description, icon, sort, supported_triggers, enabled, create_by, create_time, update_by, update_time, version, deleted)
VALUES
('脚本执行', 'SCRIPT_EXECUTION', '用于执行各类脚本的流程', 'CodeOutlined', 1, '["MANUAL","SCHEDULED"]', 1, 'system', NOW(), 'system', NOW(), 0, 0),
('应用部署', 'DEPLOYMENT', '用于应用部署的流程', 'DeploymentUnitOutlined', 2, '["MANUAL","SCHEDULED","APPROVAL"]', 1, 'system', NOW(), 'system', NOW(), 0, 0),
('数据同步', 'DATA_SYNC', '用于第三方系统数据同步的流程', 'SyncOutlined', 3, '["MANUAL","SCHEDULED"]', 1, 'system', NOW(), 'system', NOW(), 0, 0),
('配置同步', 'CONFIG_SYNC', '用于配置中心数据同步的流程', 'SettingOutlined', 4, '["MANUAL","APPROVAL"]', 1, 'system', NOW(), 'system', NOW(), 0, 0),
('审批流程', 'APPROVAL', '纯审批流程', 'AuditOutlined', 5, '["MANUAL"]', 1, 'system', NOW(), 'system', NOW(), 0, 0),
('其他', 'OTHER', '其他类型流程', 'AppstoreOutlined', 99, '["MANUAL"]', 1, 'system', NOW(), 'system', NOW(), 0, 0);

-- 工作流定义测试数据
INSERT INTO workflow_definition (
    -- 基础信息
    name, `key`, process_definition_id, flow_version, description, category_id, form_definition_id,
    -- 流程配置
    graph,
    -- 流程属性
    status,
    -- 审计字段
    create_time, update_time, create_by, update_by, deleted, version
) VALUES
-- 简单脚本流程：开始 -> 脚本任务 -> 结束
(
    '简单脚本流程', 'simple_script_flow', null, 1, '一个包含脚本任务的简单流程', 1, null,
    '{
  "nodes" : [ {
    "id" : "startEvent1",
    "code" : "START_EVENT",
    "type" : "START_EVENT",
    "name" : "开始",
    "graph" : {
      "shape" : "circle",
      "size" : {
        "width" : 40,
        "height" : 40
      },
      "style" : {
        "fill" : "#e8f7ff",
        "stroke" : "#1890ff",
        "icon" : "play-circle",
        "iconColor" : "#1890ff",
        "strokeWidth" : 2
      },
      "ports" : {
        "groups" : {
          "out" : {
            "position" : "right",
            "attrs" : {
              "circle" : {
                "r" : 4,
                "fill" : "#ffffff",
                "stroke" : "#1890ff"
              }
            }
          }
        },
        "types" : [ "out" ]
      },
      "position" : {
        "x" : 100,
        "y" : 100
      }
    },
    "config" : {
      "name" : "开始节点",
      "description" : "启动流程"
    }
  }, {
    "id" : "scriptTask1",
    "code" : "SCRIPT_TASK",
    "type" : "SCRIPT_TASK",
    "name" : "执行脚本",
    "graph" : {
      "shape" : "rect",
      "size" : {
        "width" : 40,
        "height" : 40
      },
      "style" : {
        "fill" : "#fff1f0",
        "stroke" : "#ff4d4f",
        "icon" : "code",
        "iconColor" : "#ff4d4f",
        "strokeWidth" : 2
      },
      "ports" : {
        "groups" : {
          "in" : {
            "position" : "left",
            "attrs" : {
              "circle" : {
                "r" : 4,
                "fill" : "#ffffff",
                "stroke" : "#1890ff"
              }
            }
          },
          "out" : {
            "position" : "right",
            "attrs" : {
              "circle" : {
                "r" : 4,
                "fill" : "#ffffff",
                "stroke" : "#1890ff"
              }
            }
          }
        },
        "types" : [ "in", "out" ]
      },
      "position" : {
        "x" : 300,
        "y" : 100
      }
    },
    "config" : {
      "name" : "脚本任务",
      "description" : "执行一个简单的Shell脚本",
      "language" : "shell",
      "script" : "echo ''Hello World''"
    }
  }, {
    "id" : "endEvent1",
    "code" : "END_EVENT",
    "type" : "END_EVENT",
    "name" : "结束",
    "graph" : {
      "shape" : "circle",
      "size" : {
        "width" : 40,
        "height" : 40
      },
      "style" : {
        "fill" : "#fff1f0",
        "stroke" : "#ff4d4f",
        "icon" : "stop",
        "iconColor" : "#ff4d4f",
        "strokeWidth" : 2
      },
      "ports" : {
        "groups" : {
          "in" : {
            "position" : "left",
            "attrs" : {
              "circle" : {
                "r" : 4,
                "fill" : "#ffffff",
                "stroke" : "#1890ff"
              }
            }
          }
        },
        "types" : [ "in" ]
      },
      "position" : {
        "x" : 500,
        "y" : 100
      }
    },
    "config" : {
      "name" : "结束节点",
      "description" : "流程结束"
    }
  } ],
  "edges" : [ {
    "id" : "flow1",
    "from" : "startEvent1",
    "to" : "scriptTask1",
    "name" : "开始到脚本",
    "config" : {
      "type" : "sequence"
    },
    "properties" : null
  }, {
    "id" : "flow2",
    "from" : "scriptTask1",
    "to" : "endEvent1",
    "name" : "脚本到结束",
    "config" : {
      "type" : "sequence"
    },
    "properties" : null
  } ]
}',
    'DRAFT',
    NOW(), NOW(), NULL, NULL, 0, 0
),

-- 复杂业务流程：开始 -> 脚本任务A -> 脚本任务B -> 结束
(
    '复杂业务流程', 'complex_business_flow', null, 1, '包含多个脚本任务节点的业务流程', 1, null,
    '{
  "nodes" : [ {
    "id" : "startEvent1",
    "code" : "START_EVENT",
    "type" : "START_EVENT",
    "name" : "开始",
    "graph" : {
      "shape" : "circle",
      "size" : {
        "width" : 40,
        "height" : 40
      },
      "style" : {
        "fill" : "#e8f7ff",
        "stroke" : "#1890ff",
        "icon" : "play-circle",
        "iconColor" : "#1890ff",
        "strokeWidth" : 2
      },
      "ports" : {
        "groups" : {
          "out" : {
            "position" : "right",
            "attrs" : {
              "circle" : {
                "r" : 4,
                "fill" : "#ffffff",
                "stroke" : "#1890ff"
              }
            }
          }
        },
        "types" : [ "out" ]
      },
      "position" : {
        "x" : 100,
        "y" : 100
      }
    },
    "config" : {
      "name" : "开始节点",
      "description" : "启动流程"
    }
  }, {
    "id" : "scriptTask1",
    "code" : "SCRIPT_TASK",
    "type" : "SCRIPT_TASK",
    "name" : "数据处理",
    "graph" : {
      "shape" : "rect",
      "size" : {
        "width" : 40,
        "height" : 40
      },
      "style" : {
        "fill" : "#fff1f0",
        "stroke" : "#ff4d4f",
        "icon" : "code",
        "iconColor" : "#ff4d4f",
        "strokeWidth" : 2
      },
      "ports" : {
        "groups" : {
          "in" : {
            "position" : "left",
            "attrs" : {
              "circle" : {
                "r" : 4,
                "fill" : "#ffffff",
                "stroke" : "#1890ff"
              }
            }
          },
          "out" : {
            "position" : "right",
            "attrs" : {
              "circle" : {
                "r" : 4,
                "fill" : "#ffffff",
                "stroke" : "#1890ff"
              }
            }
          }
        },
        "types" : [ "in", "out" ]
      },
      "position" : {
        "x" : 300,
        "y" : 100
      }
    },
    "config" : {
      "name" : "脚本任务A",
      "description" : "数据处理",
      "language" : "shell",
      "script" : "process_data.sh"
    }
  }, {
    "id" : "scriptTask2",
    "code" : "SCRIPT_TASK",
    "type" : "SCRIPT_TASK",
    "name" : "生成报告",
    "graph" : {
      "shape" : "rect",
      "size" : {
        "width" : 40,
        "height" : 40
      },
      "style" : {
        "fill" : "#fff1f0",
        "stroke" : "#ff4d4f",
        "icon" : "code",
        "iconColor" : "#ff4d4f",
        "strokeWidth" : 2
      },
      "ports" : {
        "groups" : {
          "in" : {
            "position" : "left",
            "attrs" : {
              "circle" : {
                "r" : 4,
                "fill" : "#ffffff",
                "stroke" : "#1890ff"
              }
            }
          },
          "out" : {
            "position" : "right",
            "attrs" : {
              "circle" : {
                "r" : 4,
                "fill" : "#ffffff",
                "stroke" : "#1890ff"
              }
            }
          }
        },
        "types" : [ "in", "out" ]
      },
      "position" : {
        "x" : 500,
        "y" : 100
      }
    },
    "config" : {
      "name" : "脚本任务B",
      "description" : "生成报告",
      "language" : "shell",
      "script" : "generate_report.sh"
    }
  }, {
    "id" : "endEvent1",
    "code" : "END_EVENT",
    "type" : "END_EVENT",
    "name" : "结束",
    "graph" : {
      "shape" : "circle",
      "size" : {
        "width" : 40,
        "height" : 40
      },
      "style" : {
        "fill" : "#fff1f0",
        "stroke" : "#ff4d4f",
        "icon" : "stop",
        "iconColor" : "#ff4d4f",
        "strokeWidth" : 2
      },
      "ports" : {
        "groups" : {
          "in" : {
            "position" : "left",
            "attrs" : {
              "circle" : {
                "r" : 4,
                "fill" : "#ffffff",
                "stroke" : "#1890ff"
              }
            }
          }
        },
        "types" : [ "in" ]
      },
      "position" : {
        "x" : 700,
        "y" : 100
      }
    },
    "config" : {
      "name" : "结束节点",
      "description" : "流程结束"
    }
  } ],
  "edges" : [ {
    "id" : "flow1",
    "from" : "startEvent1",
    "to" : "scriptTask1",
    "name" : "开始到处理",
    "config" : {
      "type" : "sequence"
    },
    "properties" : null
  }, {
    "id" : "flow2",
    "from" : "scriptTask1",
    "to" : "scriptTask2",
    "name" : "处理到报告",
    "config" : {
      "type" : "sequence"
    },
    "properties" : null
  }, {
    "id" : "flow3",
    "from" : "scriptTask2",
    "to" : "endEvent1",
    "name" : "报告到结束",
    "config" : {
      "type" : "sequence"
    },
    "properties" : null
  } ]
}',
    'DRAFT',
    NOW(), NOW(), NULL, NULL, 0, 0
);


-- --------------------------------------------------------------------------------------
-- 初始化工作流节点定义数据
-- --------------------------------------------------------------------------------------
-- 初始化工作流节点定义数据
INSERT INTO workflow_node_definition (
    node_type, node_code, node_name, description, category,
    ui_variables, panel_variables_schema, local_variables_schema, 
    form_variables_schema, enabled,
    create_time, create_by, update_time, update_by, version, deleted
) VALUES 
-- 开始节点
(
    'START_EVENT', 'START_EVENT', '开始节点', '工作流的起点', 'EVENT',
    '{
        "shape": "circle",
        "size": {"width": 40, "height": 40},
        "style": {
            "fill": "#e8f7ff",
            "stroke": "#1890ff", 
            "strokeWidth": 2,
            "icon": "play-circle",
            "iconColor": "#1890ff"
        },
        "ports": {
            "groups": {
                "out": {
                    "position": "right",
                    "attrs": {
                        "circle": {"r": 4, "fill": "#ffffff", "stroke": "#1890ff"}
                    }
                }
            }
        }
    }',
    '{
        "type": "object",
        "properties": {
            "code": {"type": "string", "title": "节点Code"},
            "name": {"type": "string", "title": "节点名称"},
            "description": {"type": "string", "title": "节点描述"}
        },
        "required": ["code", "name"]
    }',
    '{}',
    '{"formItems": []}',
    1,
    NOW(), 'system', NOW(), 'system', 1, 0
),
-- 结束节点  
(
    'END_EVENT', 'END_EVENT', '结束节点', '工作流的终点', 'EVENT',
    '{
        "shape": "circle",
        "size": {"width": 40, "height": 40},
        "style": {
            "fill": "#fff1f0",
            "stroke": "#ff4d4f",
            "strokeWidth": 2, 
            "icon": "stop",
            "iconColor": "#ff4d4f"
        },
        "ports": {
            "groups": {
                "in": {
                    "position": "left",
                    "attrs": {
                        "circle": {"r": 4, "fill": "#ffffff", "stroke": "#1890ff"}
                    }
                }
            }
        }
    }',
    '{
        "type": "object",
        "properties": {
            "code": {"type": "string", "title": "节点Code"},
            "name": {"type": "string", "title": "节点名称"}, 
            "description": {"type": "string", "title": "节点描述"}
        },
        "required": ["code", "name"]
    }',
    '{}',
    '{"formItems": []}',
    1,
    NOW(), 'system', NOW(), 'system', 1, 0
),
-- 脚本任务节点
(
    'SCRIPT_TASK', 'SCRIPT_TASK', '脚本任务', '脚本执行任务', 'TASK',
    '{
        "shape": "rect",
        "size": {"width": 120, "height": 60},
        "style": {
            "fill": "#ffffff",
            "stroke": "#1890ff",
            "strokeWidth": 2,
            "icon": "code", 
            "iconColor": "#1890ff"
        },
        "ports": {
            "groups": {
                "in": {
                    "position": "left",
                    "attrs": {
                        "circle": {"r": 4, "fill": "#ffffff", "stroke": "#1890ff"}
                    }
                },
                "out": {
                    "position": "right", 
                    "attrs": {
                        "circle": {"r": 4, "fill": "#ffffff", "stroke": "#1890ff"}
                    }
                }
            }
        }
    }',
    '{
        "type": "object",
        "properties": {
            "code": {"type": "string", "title": "节点Code"},
            "name": {"type": "string", "title": "节点名称"},
            "description": {"type": "string", "title": "节点描述"},
            "script": {
                "type": "string",
                "title": "脚本内容",
                "format": "textarea",
                "description": "需要执行的脚本内容"
            },
            "language": {
                "type": "string", 
                "title": "脚本语言",
                "default": "shell",
                "enum": ["shell", "python", "javascript"],
                "enumNames": ["Shell脚本", "Python脚本", "JavaScript脚本"]
            },
            "interpreter": {
                "type": "string",
                "title": "解释器路径",
                "description": "脚本解释器的路径，例如：/bin/bash"
            },
            "workingDirectory": {
                "type": "string",
                "title": "工作目录", 
                "default": "/tmp"
            },
            "delegate": {
                "type": "string",
                "title": "执行委派者",
                "default": "${shellTaskDelegate}"
            }
        },
        "required": ["code", "name", "script", "language", "delegate"]
    }',
    '{
        "environment": {"type": "object", "additionalProperties": {"type": "string"}}
    }',
    '{"formItems": []}',
    1,
    NOW(), 'system', NOW(), 'system', 1, 0
);

-- --------------------------------------------------------------------------------------
-- 初始化项目管理数据
-- --------------------------------------------------------------------------------------

-- 初始化项目组数据
-- 注意：以下数据已注释，需要时请取消注释并修改为实际数据
-- INSERT INTO deploy_project_group (id, create_by, create_time, tenant_code, type, project_group_code, project_group_name, project_group_desc, enabled, sort)
-- VALUES
-- (1, 'admin', NOW(), 'admin', 'PRODUCT', 'DEMO', '示例项目组', '用于演示的项目组', 1, 1),
-- (2, 'admin', NOW(), 'admin', 'PRODUCT', 'PLATFORM', '平台项目组', '平台相关的项目组', 1, 2);

-- 初始化应用数据
-- 注意：以下数据已注释，需要时请取消注释并修改为实际数据
-- INSERT INTO deploy_application (
--     id, create_by, create_time,
--     project_group_id, app_code, app_name, app_desc, enabled,
--     repo_url, repo_branch, repo_type, build_type, dev_language, dev_framework, sort
-- )
-- VALUES
-- (
--     1, 'admin', NOW(),
--     1, 'DEMO-APP', '示例应用', '用于演示的应用', 1,
--     'https://github.com/demo/demo-app.git', 'main', 'GIT', 'MAVEN', 'JAVA', 'SPRING_BOOT', 1
-- ),
-- (
--     2, 'admin', NOW(),
--     1, 'DEMO-WEB', '示例前端', '用于演示的前端应用', 1,
--     'https://github.com/demo/demo-web.git', 'main', 'GIT', 'NPM', 'NODEJS', 'VUE', 2
-- ),
-- (
--     3, 'admin', NOW(),
--     2, 'PLATFORM-API', '平台API', '平台后端服务', 1,
--     'https://github.com/platform/platform-api.git', 'main', 'GIT', 'MAVEN', 'JAVA', 'SPRING_BOOT', 1
-- ),
-- (
--     4, 'admin', NOW(),
--     2, 'PLATFORM-WEB', '平台前端', '平台前端应用', 1,
--     'https://github.com/platform/platform-web.git', 'main', 'GIT', 'NPM', 'NODEJS', 'VUE', 2
-- );

-- --------------------------------------------------------------------------------------
-- 初始化通知渠道数据
-- --------------------------------------------------------------------------------------

-- 企业微信通知渠道示例
INSERT INTO sys_notification_channel 
(name, channel_type, config, status, description, create_by, create_time, update_by, update_time, version, deleted) 
VALUES 
('研发部企业微信群', 'WEWORK', 
 '{"webhookUrl":"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=example-key-please-replace"}',
 'DISABLED', 
 '研发部通知群，用于部署通知（示例数据，请修改为实际的Webhook地址）', 
 'admin', NOW(), 'admin', NOW(), 0, 0);

-- 飞书、邮件等其他渠道类型暂未启用，等后续开启相应枚举后再添加示例数据
-- ('运维飞书告警群', 'FEISHU', 
--  '{"webhookUrl":"https://open.feishu.cn/open-apis/bot/v2/hook/example-hook-id","secret":"example-secret"}',
--  'DISABLED',
--  '运维团队告警通知（示例数据，请修改为实际配置）',
--  'admin', NOW(), 'admin', NOW(), 0, 0),
-- 
-- ('管理员邮件通知', 'EMAIL', 
--  '{"smtpHost":"smtp.qq.com","smtpPort":465,"username":"notify@example.com","password":"[REDACTED]
--  'DISABLED',
--  '管理员邮件通知渠道（示例数据，请修改为实际配置）',
--  'admin', NOW(), 'admin', NOW(), 0, 0);

-- --------------------------------------------------------------------------------------
-- 初始化表单分类数据
-- --------------------------------------------------------------------------------------

INSERT INTO form_category (name, code, description, icon, sort, enabled, create_by, create_time, update_by, update_time, version, deleted)
VALUES
('审批表单', 'APPROVAL', '用于审批流程的表单', 'CheckCircleOutlined', 1, 1, 'system', NOW(), 'system', NOW(), 0, 0),
('数据采集', 'DATA_COLLECTION', '用于数据采集的表单', 'DatabaseOutlined', 2, 1, 'system', NOW(), 'system', NOW(), 0, 0),
('问卷调查', 'SURVEY', '用于问卷调查的表单', 'FormOutlined', 3, 1, 'system', NOW(), 'system', NOW(), 0, 0),
('其他', 'OTHER', '其他类型的表单', 'FileOutlined', 99, 1, 'system', NOW(), 'system', NOW(), 0, 0);

-- --------------------------------------------------------------------------------------
-- 初始化团队管理数据
-- --------------------------------------------------------------------------------------

-- 初始化团队数据
INSERT INTO deploy_team (id, team_code, team_name, description, owner_id, owner_name, enabled, sort, create_by, create_time, update_by, update_time, version, deleted)
VALUES
(1, 'PLATFORM_TEAM', '平台研发团队', '负责基础平台和框架的开发维护', 1, '超级管理员', 1, 1, 'admin', NOW(), 'admin', NOW(), 1, 0),
(2, 'DEVOPS_TEAM', 'DevOps团队', '负责CI/CD和运维自动化', 4, '运维经理', 1, 2, 'admin', NOW(), 'admin', NOW(), 1, 0);

-- 初始化团队成员数据
INSERT INTO deploy_team_member (team_id, user_id, user_name, role_in_team, join_time, create_by, create_time, update_by, update_time, version, deleted)
VALUES
-- 平台研发团队成员
(1, 1, 'admin', '负责人', NOW(), 'admin', NOW(), 'admin', NOW(), 1, 0),
(1, 3, 'dev_manager', '开发', NOW(), 'admin', NOW(), 'admin', NOW(), 1, 0),
-- DevOps团队成员
(2, 4, 'ops_manager', '负责人', NOW(), 'admin', NOW(), 'admin', NOW(), 1, 0),
(2, 2, 'it_manager', '运维', NOW(), 'admin', NOW(), 'admin', NOW(), 1, 0);

-- 初始化团队配置数据
INSERT INTO deploy_team_config (team_id, allowed_environment_ids, environment_approval_required, approver_user_ids, create_by, create_time, update_by, update_time, version, deleted)
VALUES
-- 平台研发团队配置（可访问开发和测试环境，都不需要审批）
(1, '[1, 2]', '[false, false]', '[null, null]', 'admin', NOW(), 'admin', NOW(), 1, 0),
-- DevOps团队配置（可访问所有环境，生产环境需要审批，审批人是用户1和4）
(2, '[1, 2, 3]', '[false, false, true]', '[null, null, [1, 4]]', 'admin', NOW(), 'admin', NOW(), 1, 0);

-- ====================================================================
-- 定时任务初始化数据
-- ====================================================================

-- 初始化定时任务分类数据
INSERT INTO schedule_job_category (id, code, name, description, icon, color, enabled, sort, create_by, create_time, update_by, update_time, version, deleted)
VALUES
(1, 'DATA_CLEAN', '数据清理', '定期清理系统历史数据和临时文件', 'DeleteOutlined', '#ff4d4f', 1, 1, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 1, 0),
(2, 'DATA_SYNC', '数据同步', '同步外部系统数据到本地', 'SyncOutlined', '#1890ff', 1, 2, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 1, 0),
(3, 'REPORT', '报表生成', '定期生成和发送各类统计报表', 'BarChartOutlined', '#52c41a', 1, 3, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 1, 0),
(4, 'MONITOR', '系统监控', '监控系统健康状态和性能指标', 'EyeOutlined', '#faad14', 1, 4, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 1, 0),
(5, 'BACKUP', '备份任务', '定期备份数据库和重要文件', 'DatabaseOutlined', '#722ed1', 1, 5, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 1, 0);

-- 初始化定时任务数据
INSERT INTO schedule_job (id, job_name, job_description, category_id, bean_name, method_name, method_params, 
                          cron_expression, status, concurrent, timeout_seconds, retry_count, 
                          create_by, create_time, update_by, update_time, version, deleted)
VALUES
-- 数据清理任务
(1, '工作流历史数据清理', '清理90天前已完成或已取消的工作流实例数据', 1, 'workflowCleanJob', 'execute', 
 '{"retentionDays": 90}', '0 0 2 * * ?', 'ENABLED', 0, 3600, 2, 
 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 1, 0),

-- Git数据同步任务（需要先配置外部系统，修改externalSystemId参数）
(2, 'Git仓库组同步', '定期同步Git仓库组信息，每天凌晨2点执行', 2, 'repositoryGroupServiceImpl', 'syncGroups', 
 '{"externalSystemId": 1}', '0 0 2 * * ?', 'DISABLED', 0, 3600, 2, 
 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 1, 0),

(3, 'Git项目同步', '定期同步Git项目信息，每天凌晨3点执行', 2, 'repositoryProjectServiceImpl', 'syncProjects', 
 '{"externalSystemId": 1}', '0 0 3 * * ?', 'DISABLED', 0, 3600, 2, 
 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 1, 0),

(4, 'Git分支同步', '定期同步Git仓库分支信息，每5分钟执行一次', 2, 'repositoryBranchServiceImpl', 'syncBranches', 
 '{"externalSystemId": 1}', '0 */5 * * * ?', 'DISABLED', 0, 3600, 2, 
 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 1, 0),

-- Jenkins数据同步任务（需要先配置外部系统，修改externalSystemId参数）
(5, 'Jenkins视图同步', '定期同步Jenkins视图信息，每天凌晨4点执行', 2, 'jenkinsViewServiceImpl', 'syncViews', 
 '{"externalSystemId": 1}', '0 0 4 * * ?', 'DISABLED', 0, 3600, 2, 
 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 1, 0),

(6, 'Jenkins任务同步', '定期同步Jenkins任务信息，每天凌晨5点执行', 2, 'jenkinsJobServiceImpl', 'syncJobs', 
 '{"externalSystemId": 1}', '0 0 5 * * ?', 'DISABLED', 0, 3600, 2, 
 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 1, 0),

(7, 'Jenkins构建同步', '定期同步Jenkins构建信息，每5分钟执行一次', 2, 'jenkinsBuildServiceImpl', 'syncBuilds', 
 '{"externalSystemId": 1}', '0 */5 * * * ?', 'DISABLED', 0, 3600, 2, 
 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 1, 0);

-- =====================================================
-- 服务器管理初始数据
-- =====================================================

-- 服务器分类
INSERT INTO deploy_server_category (id, name, code, icon, description, sort, enabled, create_by, create_time, update_by, update_time, version, deleted) VALUES
(1, 'Web服务器', 'WEB_SERVER', 'server', 'Web应用服务器、前端服务器', 1, 1, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 1, 0),
(2, '数据库服务器', 'DATABASE_SERVER', 'database', '数据库服务器、缓存服务器', 2, 1, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 1, 0),
(3, '中间件服务器', 'MIDDLEWARE_SERVER', 'cluster', '消息队列、搜索引擎等中间件', 3, 1, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 1, 0),
(4, '应用服务器', 'APP_SERVER', 'cloud-server', '业务应用服务器', 4, 1, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 1, 0),
(5, '其他', 'OTHER', 'hdd', '其他类型服务器', 99, 1, 'system', '2024-01-01 00:00:00', 'system', '2024-01-01 00:00:00', 1, 0);
