SET FOREIGN_KEY_CHECKS=0;

CREATE TABLE IF NOT EXISTS `sys_dept` (
        `dept_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '部门id',
        `parent_id` bigint(20) NULL DEFAULT 0 COMMENT '父部门id 默认0',
        `ancestors` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '祖级列表',
        `dept_name` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '部门名称',
        `order_num` int(11) NULL DEFAULT 0 COMMENT '显示顺序',
        `leader` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '负责人',
        `phone` varchar(11) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '联系电话',
        `email` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '邮箱',
        `status` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '0' COMMENT '部门状态（0停用 1正常）',
        `del_flag` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '0' COMMENT '删除标志（0代表存在 1代表删除）',
        `create_by` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '创建者',
        `create_time` bigint(20) NULL DEFAULT 0 COMMENT '创建时间',
        `update_by` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '更新者',
        `update_time` bigint(20) NULL DEFAULT 0 COMMENT '更新时间',
        PRIMARY KEY (`dept_id`) USING BTREE
    ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '部门表' ROW_FORMAT = Dynamic;

-- -- add default dept

INSERT
    IGNORE INTO `sys_dept` (
        `dept_id`,
        `parent_id`,
        `ancestors`,
        `dept_name`,
        `order_num`,
        `leader`,
        `phone`,
        `email`,
        `status`,
        `del_flag`,
        `create_by`,
        `create_time`,
        `update_by`,
        `update_time`
    )
VALUES (
        100,
        0,
        '0',
        '系统维护部',
        0,
        'admin',
        '',
        '',
        '1',
        '0',
        'admin',
        1697091866188,
        '',
        NULL
    );

INSERT
    IGNORE INTO `sys_dept` (
        `dept_id`,
        `parent_id`,
        `ancestors`,
        `dept_name`,
        `order_num`,
        `leader`,
        `phone`,
        `email`,
        `status`,
        `del_flag`,
        `create_by`,
        `create_time`,
        `update_by`,
        `update_time`
    )
VALUES (
        101,
        100,
        '0,100',
        '运维一部',
        1,
        'admin',
        '',
        '',
        '1',
        '0',
        'admin',
        1697091866192,
        '',
        NULL
    );

-- for cn/en locale
UPDATE `sys_dept`
SET
    `parent_id` = 0,
    `ancestors` = '0',
    `dept_name` = 'dept.root',
    `order_num` = 0,
    `leader` = 'supervisor',
    `phone` = NULL,
    `email` = NULL,
    `status` = '1',
    `del_flag` = '0',
    `create_by` = 'supervisor',
    `create_time` = 1699348237468,
    `update_by` = NULL,
    `update_time` = 0
WHERE `dept_id` = 100;

UPDATE `sys_dept`
SET
    `parent_id` = 100,
    `ancestors` = '0,100',
    `dept_name` = 'dept.root.item1',
    `order_num` = 1,
    `leader` = 'supervisor',
    `phone` = NULL,
    `email` = NULL,
    `status` = '1',
    `del_flag` = '0',
    `create_by` = 'supervisor',
    `create_time` = 1699348237468,
    `update_by` = NULL,
    `update_time` = 0
WHERE `dept_id` = 101;

SET FOREIGN_KEY_CHECKS=1;    