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

-- 初始化租户数据
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, type, parent_id, sort, hidden, enabled, create_by, create_time, version, deleted)
VALUES
-- 首页
(99, '工作台', '/dashboard', '/src/pages/dashboard/index', 'DashboardOutlined', 2, NULL, 0, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),

-- 系统管理
(1, '系统管理', '/system', 'Layout', 'SettingOutlined', 1, NULL, 1, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 用户管理
(2, '用户管理', '/system/user', '/src/pages/system/user/index', 'UserOutlined', 2, 1, 10, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 角色管理
(3, '角色管理', '/system/role', '/src/pages/system/role/index', 'TeamOutlined', 2, 1, 20, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 菜单管理
(4, '菜单管理', '/system/menu', '/src/pages/system/menu/index', 'MenuOutlined', 2, 1, 30, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 部门管理
(5, '部门管理', '/system/department', '/src/pages/system/department/index', 'ApartmentOutlined', 2, 1, 40, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),

-- 工作流管理
(100, '工作流管理', '/workflow', 'Layout', 'DeploymentUnitOutlined', 1, NULL, 2, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 工作流设计
(101, '工作流设计', '/workflow/definition', '/src/pages/workflow/definition/index', 'EditOutlined', 2, 100, 10, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 工作流实例
(102, '工作流实例', '/workflow/instance', '/src/pages/workflow/instance/index', 'BranchesOutlined', 2, 100, 20, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 节点管理
(103, '节点管理', '/workflow/node-design', '/src/pages/workflow/nodedesign/design/index', 'ControlOutlined', 2, 100, 40, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),

(200, '运维管理', '/deploy', '', 'DeploymentUnitOutlined', 2, 0, 50, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),

(201, '项目组管理', '/deploy/project-group', '/src/pages/Deploy/ProjectGroup/List/index', 'ProjectOutlined', 2, 200, 1, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),

(202, '应用管理', '/deploy/applications', '/src/pages/Deploy/Application/List/index', 'AppstoreOutlined', 2, 200, 2, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),

(203, '环境管理', '/deploy/environments', '/src/pages/Deploy/Environment/List/index', 'CloudOutlined', 2, 200, 3, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),

(204, '部署配置管理', '/deploy/deployment', '/src/pages/Deploy/Deployment/List/index', 'CloudOutlined', 2, 200, 4, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),

(205, 'Jenkins管理', '/deploy/jenkins-manager', '/src/pages/Deploy/JenkinsManager/List', 'CloudOutlined', 2, 200, 5, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),

(206, 'Git管理', '/deploy/git-manager', '/src/pages/Deploy/GitManager/List', 'CloudOutlined', 2, 200, 6, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE),
-- 三方系统
(207, '三方系统管理', '/deploy/external', '/src/pages/Deploy/external/index', 'ApiOutlined', 2, 200, 7, FALSE, TRUE, 'system', '2024-01-01 00:00:00', 0, FALSE);

-- 初始化角色数据
INSERT INTO sys_role (id, create_time, code, name, type, description, sort)
VALUES
(1, NOW(), 'SUPER_ADMIN', '超级管理员', 1, '系统超级管理员，拥有所有权限', 1),
(2, NOW(), 'SYSTEM_ADMIN', '系统管理员', 1, '系统管理员，拥有大部分系统管理权限', 2),
(3, NOW(), 'COMMON_USER', '普通用户', 2, '普通用，仅拥有基本操作权限', 3);

-- 初始化角色标签
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, 1), (2, 2), (2, 3), (2, 4), (2, 5),  -- 系统管理员拥有系统管理相关权限
(3, 205);  -- 普通用户拥有三方系统权限

-- 初始化权限模板
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, 205);  -- 基础权限模板关联三方系统菜单

-- 初始化权限数据
INSERT INTO sys_permission (id, create_time, menu_id, code, name, type, sort)
VALUES 
-- 用户管理权限
(1, NOW(), 2, 'system:user:list', '用户列表', 'FUNCTION', 1),
(2, NOW(), 2, 'system:user:create', '用户创建', 'FUNCTION', 2),
(3, NOW(), 2, 'system:user:update', '用户修改', 'FUNCTION', 3),
(4, NOW(), 2, 'system:user:delete', '用户删除', 'FUNCTION', 4),

-- 角色管理权限
(5, NOW(), 3, 'system:role:list', '角色列表', 'FUNCTION', 1),
(6, NOW(), 3, 'system:role:create', '角色创建', 'FUNCTION', 2),
(7, NOW(), 3, 'system:role:update', '角色修改', 'FUNCTION', 3),
(8, NOW(), 3, 'system:role:delete', '角色删除', 'FUNCTION', 4),

-- 三方系统权限
(9, NOW(), 205, 'system:external:list', '三方系统列表', 'FUNCTION', 1),
(10, NOW(), 205, 'system:external:create', '三方系统创建', 'FUNCTION', 2),
(11, NOW(), 205, 'system:external:update', '三方系统修改', 'FUNCTION', 3),
(12, NOW(), 205, 'system:external:delete', '三方系统删除', 'FUNCTION', 4),
(13, NOW(), 205, 'system:external:test', '连接测试', 'FUNCTION', 5),
(14, NOW(), 205, 'system:external:sync', '数据同步', 'FUNCTION', 6);

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

-- 初始化外部系统
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', '2023-12-01 00:00:00', 0, 'admin', '2023-12-01 00:00:00', 0,
    'GitLab测试环境', 'GIT', 'http://gitlab.test.com', '测试环境GitLab服务器', 2, 1,
    'TOKEN', NULL, NULL, 'test-token',
    'SUCCESS', '2023-12-01 00:00:00', '2023-12-01 00:00:00', '{}'
), (
    3, 'admin', '2024-12-03 10:35:58.932966', 0, 'admin', '2024-12-03 10:35:58.932966', 0,
    '链宇GIT', 'GIT', 'http://119.3.203.210:8088/', NULL, 1, 1,
    'TOKEN', NULL, NULL, 'cNSud7D1GmYQKEMco7s5',
    NULL, NULL, NULL, '{}'
);

-- --------------------------------------------------------------------------------------
-- 初始化工作流相关数据
-- --------------------------------------------------------------------------------------
-- 工作流定义测试数据
INSERT INTO workflow_definition (
    -- 基础信息
    name, `key`, process_definition_id, flow_version, description, category, triggers,
    -- 流程配置
    graph, local_variables_schema, tags,
    -- 流程属性
    status, is_executable, target_namespace,
    -- 审计字段
    created_at, updated_at, created_by, updated_by, is_deleted
) VALUES
-- 简单脚本流程：开始 -> 脚本任务 -> 结束
(
    '简单脚本流程', 'simple_script_flow', null, 1, '一个包含脚本任务的简单流程', 'SCRIPT_EXECUTION', 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
  } ]
}',
    '{"formItems":[]}',
    '["simple","script","test"]',
    'DRAFT', TRUE, 'http://www.flowable.org/test',
    NOW(), NOW(), 1, 1, FALSE
),

-- 复杂业务流程：开始 -> 脚本任务A -> 脚本任务B -> 结束
(
    '复杂业务流程', 'complex_business_flow', null, 1, '包含多个脚本任务节点的业务流程', 'SCRIPT_EXECUTION', 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
  } ]
}',
    '{"formItems":[{"type":"input","label":"业务参数","name":"businessParam","required":true}]}',
    '["complex","business","multi-task"]',
    'DRAFT', TRUE, 'http://www.flowable.org/test',
    NOW(), NOW(), 1, 1, FALSE
);


-- --------------------------------------------------------------------------------------
-- 初始化工作流节点定义数据
-- --------------------------------------------------------------------------------------
-- 初始化工作流节点定义数据
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);
