CREATE TABLE "SC_AUDIT_LOG"(
    "ID" INT IDENTITY(1, 1) NOT NULL,
    "CREATE_TIME" TIMESTAMP(0),
    "OPERATOR_NAME" VARCHAR(255),
    "OPERATOR_ID" INT,
    "OPERATE_CONTENT" VARCHAR(255),
    "IP_ADDRESS" VARCHAR(255),
    "IP_INFO" VARCHAR(255),
    "REQUEST_PATH" VARCHAR(255),
    "REQUEST_MOTHED" VARCHAR(255),
    "REQUEST_PARAM" TEXT,
    "OPERATE_TYPE" VARCHAR(255),
    "OPERATE_RESULT" VARCHAR(255),
    "TIME_CONSUMING" INT,
    "READ_STATUS" INT DEFAULT 0,
    "READ_USER_ID" INT,
    "READ_USER_NAME" VARCHAR(255),
    "READ_REAL_NAME" VARCHAR(255),
    PRIMARY KEY("ID")
);

CREATE TABLE "SC_AUDIT_LOG_SIGN"(
    "ID" INT IDENTITY(1, 1) NOT NULL,
    "SIGN_ID" INT,
    "LOG_ID" INT,
    "CREATE_TIME" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY("ID")
);

CREATE TABLE "SC_LOG_SIGN"(
    "ID" INT IDENTITY(1, 1) NOT NULL,
    "OPERATOR_ID" INT,
    "OPERATOR_NAME" VARCHAR(255),
    "SIGN_VALUE" VARCHAR(1024),
    "PUBLICKEY" VARCHAR(1024),
    "DEVICE_ID" VARCHAR(255),
    "CREATE_TIME" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY("ID")
);

CREATE TABLE "SC_DICT"(
    "ID" INT IDENTITY(80, 1) NOT NULL,
    "TYPE" VARCHAR(255),
    "TITLE" VARCHAR(255),
    "SCOPE" INT DEFAULT 1,
    "SORT_ORDER" INT,
    "DESCRIPTION" VARCHAR(255),
    "CREATE_TIME" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY("ID"),
    CONSTRAINT "UNIQUE__TITLE" UNIQUE("TITLE"),
    CONSTRAINT "UNIQUE__TYPE" UNIQUE("TYPE")
);

CREATE TABLE "SC_DICT_DATA"(
    "ID" INT IDENTITY(221, 1) NOT NULL,
    "DICT_ID" INT,
    "TITLE" VARCHAR(255),
    "VALUE" VARCHAR(255),
    "SORT_ORDER" INT,
    "STATUS" INT,
    "DESCRIPTION" VARCHAR(255),
    "CREATE_TIME" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY("ID"),
    CONSTRAINT "DICT_ID_TITLE_UNIQUE" UNIQUE("DICT_ID", "TITLE")
);

CREATE TABLE "SC_PARAM_CONF"(
    "ID" INT IDENTITY(23, 1) NOT NULL,
    "ITEM" INT,
    "KEY" VARCHAR(255),
    "VALUE" VARCHAR(255),
    "TYPE" VARCHAR(255),
    "STATUS" INT,
    "CREATE_TIME" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP(),
    "MEMO" VARCHAR(255),
    PRIMARY KEY("ID")
);


CREATE TABLE "SC_DEPARTMENT"(
    "ID" INT IDENTITY(1, 1) NOT NULL,
    "PARENT_ID" INT,
    "TITLE" VARCHAR(1024),
    "IS_PARENT" INT,
    "SORT_ORDER" INT,
    "STATUS" INT,
    "CREATE_TIME" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY("ID")
);

CREATE TABLE "SC_DEPARTMENT_HEADER"(
    "ID" INT IDENTITY(1, 1) NOT NULL,
    "DEPARTMENT_ID" INT,
    "TYPE" INT,
    "USER_ID" INT,
    "CREATE_TIME" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY("ID")
);

CREATE TABLE "SC_POSITION"(
    "ID" INT IDENTITY(172, 1) NOT NULL,
    "NAME" VARCHAR(255),
    "STATUS" INT,
    "CREATE_TIME" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY("ID")
);

CREATE TABLE "SC_USER" (
    "ID" INT IDENTITY(1, 1) NOT NULL,
    "USERNAME" VARCHAR(255),
    "PASSWORD" VARCHAR(255),
    "REALNAME" VARCHAR(255),
    "ORGANIZATION_ID" INT,
    "TEL" VARCHAR(25),
    "EMAIL" VARCHAR(255),
    "STATUS" INT DEFAULT 0,
    "U_PUBLICKEY" VARCHAR(1024),
    "POSITION_ID" INT,
    "SEX" INT,
    "AVATAR" VARCHAR(1024),
    "CREATE_TIME" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP(),
    "UPDATE_TIME" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP(),
    "PASS_UPDATE_TIME" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY("ID")
);
CREATE TABLE "SC_USER_ROLE"(
    "ID" INT IDENTITY(232, 1) NOT NULL,
    "ROLE_ID" INT,
    "USER_ID" INT,
    "CREATE_TIME" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY("ID")
);

CREATE TABLE "SC_ROLE"(
    "ID" INT IDENTITY(33, 1) NOT NULL,
    "NAME" VARCHAR(255),
    "DEFAULT_ROLE" INT,
    "DATA_TYPE" INT,
    "DESCRIPTION" VARCHAR(255),
    "CREATE_TIME" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY("ID")
);

CREATE TABLE "SC_ROLE_DEPARTMENT"(
    "ID" INT IDENTITY(1, 1) NOT NULL,
    "DEPARTMENT_ID" INT,
    "ROLE_ID" INT,
    "CREATE_TIME" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY("ID")
);

CREATE TABLE "SC_ROLE_PERMISSION"(
    "ID" INT IDENTITY(1486, 1) NOT NULL,
    "PERMISSION_ID" INT,
    "ROLE_ID" INT,
    "CREATE_TIME" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY("ID")
);


CREATE TABLE "SC_PERMISSION"(
    "ID" INT IDENTITY(1, 1) NOT NULL,
    "DESCRIPTION" VARCHAR(255),
    "NAME" VARCHAR(255),
    "PARENT_ID" INT,
    "P_TYPE" INT,
    "SORT_ORDER" INT,
    "COMPONENT" VARCHAR(255),
    "PATH" VARCHAR(255),
    "TITLE" VARCHAR(255),
    "ICON" VARCHAR(255),
    "P_LEVEL" INT,
    "BUTTON_TYPE" VARCHAR(255),
    "P_STATUS" INT,
    "URL" VARCHAR(255),
    "NEED_VERIFY" INT DEFAULT 0,
    "CREATE_TIME" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY("ID")
);


-- 初始化数据
INSERT INTO SC_PARAM_CONF (ITEM, KEY, VALUE, TYPE, STATUS, MEMO) VALUES (0, 'ipWhitelistSwitch', 'false', 'OBJECT', 0, null);
INSERT INTO SC_PARAM_CONF (ITEM, KEY, VALUE, TYPE, STATUS, MEMO) VALUES (1, 'communicateTimeOut', '30', 'OBJECT', 0, null);
INSERT INTO SC_PARAM_CONF (ITEM, KEY, VALUE, TYPE, STATUS, MEMO) VALUES (1, 'heartDetectTime', '5', 'OBJECT', 0, null);
INSERT INTO SC_PARAM_CONF (ITEM, KEY, VALUE, TYPE, STATUS, MEMO) VALUES (1, 'ftpUploadPath', '/app/upload', 'OBJECT', 0, null);
INSERT INTO SC_PARAM_CONF (ITEM, KEY, VALUE, TYPE, STATUS, MEMO) VALUES (1, 'heartPackage', 'test', 'OBJECT', 0, null);
INSERT INTO SC_PARAM_CONF (ITEM, KEY, VALUE, TYPE, STATUS, MEMO) VALUES (2, 'BInterfaceTimeOut', '0', 'OBJECT', 0, null);
INSERT INTO SC_PARAM_CONF (ITEM, KEY, VALUE, TYPE, STATUS, MEMO) VALUES (3, 'encryptionMachineApproval', 'false', 'OBJECT', 0, null);
INSERT INTO SC_PARAM_CONF (ITEM, KEY, VALUE, TYPE, STATUS, MEMO) VALUES (3, 'secretKeyApproval', 'false', 'OBJECT', 0, null);
INSERT INTO SC_PARAM_CONF (ITEM, KEY, VALUE, TYPE, STATUS, MEMO) VALUES (4, 'loginMethod', '1', 'OBJECT', 0, null);
INSERT INTO SC_PARAM_CONF (ITEM, KEY, VALUE, TYPE, STATUS, MEMO) VALUES (4, 'isUseGraphicCode', 'true', 'OBJECT', 0, null);
INSERT INTO SC_PARAM_CONF (ITEM, KEY, VALUE, TYPE, STATUS, MEMO) VALUES (5, 'printSpare1', '', 'OBJECT', 0, null);
INSERT INTO SC_PARAM_CONF (ITEM, KEY, VALUE, TYPE, STATUS, MEMO) VALUES (5, 'printSpare2', '', 'OBJECT', 0, null);
INSERT INTO SC_PARAM_CONF (ITEM, KEY, VALUE, TYPE, STATUS, MEMO) VALUES (6, 'windowPeriodNumber', '4', 'OBJECT', 0, null);
INSERT INTO SC_PARAM_CONF (ITEM, KEY, VALUE, TYPE, STATUS, MEMO) VALUES (7, 'sysDebugSwitch', 'dev', 'OBJECT', 0, null);
INSERT INTO SC_PARAM_CONF (ITEM, KEY, VALUE, TYPE, STATUS, MEMO) VALUES (8, 'logLevel', 'debug', 'OBJECT', 0, null);
INSERT INTO SC_PARAM_CONF (ITEM, KEY, VALUE, TYPE, STATUS, MEMO) VALUES (5, 'printProtoId', '17', 'OBJECT', 0, null);
INSERT INTO SC_PARAM_CONF (ITEM, KEY, VALUE, TYPE, STATUS, MEMO) VALUES (5, 'printIP', '1.1.1.1', 'OBJECT', 0, null);
INSERT INTO SC_PARAM_CONF (ITEM, KEY, VALUE, TYPE, STATUS, MEMO) VALUES (5, 'printPort', '1111', 'OBJECT', 0, null);
INSERT INTO SC_PARAM_CONF (ITEM, KEY, VALUE, TYPE, STATUS, MEMO) VALUES (null, 'errorValue', '3', 'OBJECT', 0, null);
INSERT INTO SC_PARAM_CONF (ITEM, KEY, VALUE, TYPE, STATUS, MEMO) VALUES (10, 'clientUserLimitTimes', '3', 'OBJECT', 0, null);
INSERT INTO SC_PARAM_CONF (ITEM, KEY, VALUE, TYPE, STATUS, MEMO) VALUES (null, 'status', '1', 'OBJECT', 0, null);
INSERT INTO SC_PARAM_CONF (ITEM, KEY, VALUE, TYPE, STATUS, MEMO) VALUES (null, 'scheduleEnabled', '1', 'OBJECT', 0, null);
INSERT INTO SC_PARAM_CONF (ITEM, KEY, VALUE, TYPE, STATUS, MEMO) VALUES (null, 'initStatus', '1', 'OBJECT', 0, null);
INSERT INTO SC_PARAM_CONF (ITEM, KEY, VALUE, TYPE, STATUS, MEMO) VALUES (null, 'tmk_init', 'false', null, null, null);



SET IDENTITY_INSERT SC_DICT ON；
INSERT INTO SC_DICT (ID, TYPE, TITLE, SCOPE, SORT_ORDER, DESCRIPTION) VALUES (6, 'sex', '性别', 1, 1, null);
INSERT INTO SC_DICT (ID, TYPE, TITLE, SCOPE, SORT_ORDER, DESCRIPTION) VALUES (9, 'stutas_usable', '状态-是否可用', 1, 3, null);
INSERT INTO SC_DICT (ID, TYPE, TITLE, SCOPE, SORT_ORDER, DESCRIPTION) VALUES (23, 'heart_time', '心跳检测时间', 1, 1, null);
INSERT INTO SC_DICT (ID, TYPE, TITLE, SCOPE, SORT_ORDER, DESCRIPTION) VALUES (38, 'b_overtime', 'B端界面超时时间', 1, 1, null);
INSERT INTO SC_DICT (ID, TYPE, TITLE, SCOPE, SORT_ORDER, DESCRIPTION) VALUES (42, 'HSM_type', '加密机类型', 1, 0, null);
INSERT INTO SC_DICT (ID, TYPE, TITLE, SCOPE, SORT_ORDER, DESCRIPTION) VALUES (76, 'Publickey_format', '公钥格式', 1, 0, null);
INSERT INTO SC_DICT (ID, TYPE, TITLE, SCOPE, SORT_ORDER, DESCRIPTION) VALUES (81, 'version', '系统版本号', 1, 0, '');

SET IDENTITY_INSERT SC_DICT_DATA ON;
INSERT INTO SC_DICT_DATA (ID, DICT_ID, TITLE, VALUE, SORT_ORDER, STATUS, DESCRIPTION) VALUES (25, 76, 'DER', 'DER', 1, 0, null);
INSERT INTO SC_DICT_DATA (ID, DICT_ID, TITLE, VALUE, SORT_ORDER, STATUS, DESCRIPTION) VALUES (26, 76, 'BASE64', 'BASE64', 2, 0, null);
INSERT INTO SC_DICT_DATA (ID, DICT_ID, TITLE, VALUE, SORT_ORDER, STATUS, DESCRIPTION) VALUES (27, 38, '30秒', '30000', 1, 0, null);
INSERT INTO SC_DICT_DATA (ID, DICT_ID, TITLE, VALUE, SORT_ORDER, STATUS, DESCRIPTION) VALUES (28, 38, '10分钟', '600000', 5, 0, null);
INSERT INTO SC_DICT_DATA (ID, DICT_ID, TITLE, VALUE, SORT_ORDER, STATUS, DESCRIPTION) VALUES (86, 42, '密码机', 'encryptor', 0, 0, null);
INSERT INTO SC_DICT_DATA (ID, DICT_ID, TITLE, VALUE, SORT_ORDER, STATUS, DESCRIPTION) VALUES (93, 38, '5分钟', '300000', 4, 0, null);
INSERT INTO SC_DICT_DATA (ID, DICT_ID, TITLE, VALUE, SORT_ORDER, STATUS, DESCRIPTION) VALUES (100, 6, '男', '1', 0, 0, null);
INSERT INTO SC_DICT_DATA (ID, DICT_ID, TITLE, VALUE, SORT_ORDER, STATUS, DESCRIPTION) VALUES (101, 8, '浙江', '杭州', 0, 0, '奥利给');
INSERT INTO SC_DICT_DATA (ID, DICT_ID, TITLE, VALUE, SORT_ORDER, STATUS, DESCRIPTION) VALUES (105, 6, '女', '2', 0, 0, null);
INSERT INTO SC_DICT_DATA (ID, DICT_ID, TITLE, VALUE, SORT_ORDER, STATUS, DESCRIPTION) VALUES (106, 9, '可用', '0', 0, 0, null);
INSERT INTO SC_DICT_DATA (ID, DICT_ID, TITLE, VALUE, SORT_ORDER, STATUS, DESCRIPTION) VALUES (107, 9, '不可用', '-1', 1, 0, null);
INSERT INTO SC_DICT_DATA (ID, DICT_ID, TITLE, VALUE, SORT_ORDER, STATUS, DESCRIPTION) VALUES (108, 23, '10秒', '1', 0, 0, null);
INSERT INTO SC_DICT_DATA (ID, DICT_ID, TITLE, VALUE, SORT_ORDER, STATUS, DESCRIPTION) VALUES (109, 23, '20秒', '2', 0, 0, null);
INSERT INTO SC_DICT_DATA (ID, DICT_ID, TITLE, VALUE, SORT_ORDER, STATUS, DESCRIPTION) VALUES (110, 23, '30秒', '3', 0, 0, null);
INSERT INTO SC_DICT_DATA (ID, DICT_ID, TITLE, VALUE, SORT_ORDER, STATUS, DESCRIPTION) VALUES (111, 23, '40秒', '4', 0, 0, null);
INSERT INTO SC_DICT_DATA (ID, DICT_ID, TITLE, VALUE, SORT_ORDER, STATUS, DESCRIPTION) VALUES (112, 23, '50秒', '5', 3, 0, null);
INSERT INTO SC_DICT_DATA (ID, DICT_ID, TITLE, VALUE, SORT_ORDER, STATUS, DESCRIPTION) VALUES (113, 23, '60秒', '6', 5, 0, null);
INSERT INTO SC_DICT_DATA (ID, DICT_ID, TITLE, VALUE, SORT_ORDER, STATUS, DESCRIPTION) VALUES (114, 38, '关闭', '0', 0, 0, null);
INSERT INTO SC_DICT_DATA (ID, DICT_ID, TITLE, VALUE, SORT_ORDER, STATUS, DESCRIPTION) VALUES (116, 38, '1分钟', '60000', 2, 0, null);
INSERT INTO SC_DICT_DATA (ID, DICT_ID, TITLE, VALUE, SORT_ORDER, STATUS, DESCRIPTION) VALUES (117, 38, '2分钟', '120000', 3, 0, null);
INSERT INTO SC_DICT_DATA (ID, DICT_ID, TITLE, VALUE, SORT_ORDER, STATUS, DESCRIPTION) VALUES (218, 76, 'RAW', 'RAW', 0, 0, '');
INSERT INTO SC_DICT_DATA (ID, DICT_ID, TITLE, VALUE, SORT_ORDER, STATUS, DESCRIPTION) VALUES (219, 76, 'SM2PKXY', 'SM2PKXY', 3, 0, '');
INSERT INTO SC_DICT_DATA (ID, DICT_ID, TITLE, VALUE, SORT_ORDER, STATUS, DESCRIPTION) VALUES (220, 76, 'SM2PK04XY', 'SM2PK04XY', 4, 0, '');
INSERT INTO SC_DICT_DATA (ID, DICT_ID, TITLE, VALUE, SORT_ORDER, STATUS, DESCRIPTION) VALUES (222, 81, 'version', 'V1.00', 0, 0, '');


SET IDENTITY_INSERT SC_PERMISSION ON；
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (5, null, null, 24, 1, 0, null, '/sysconf/paramConf/save', '是否开启白名单', null, 4, null, 0, null, 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (20, '', 'sys', null, 0, 3, 'Main', '/sys', '系统配置', 'md-desktop', 1, '', 0, '', 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (24, null, 'parameter', 20, 0, 0, 'sys-configuration/setting-manage/setting', '/parameterSet', '业务参数配置', 'md-construct', 2, null, 0, null, 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (25, null, 'dict-manage', 20, 0, 4, 'sys-configuration/dict-manage/dictManage', '/dictManage', '字典管理', 'ios-bookmarks', 2, null, -1, null, 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (28, null, 'position-manage', 20, 0, 8, 'sys-configuration/position-manage/position', '/positionManage', '职位管理', 'ios-people', 2, null, 0, null, 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (29, null, 'department-manage', 20, 0, 6, 'sys-configuration/department-manage/departmentManage', '/departmentManage', '部门管理', 'ios-albums', 2, null, 0, null, 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (30, null, 'role-manage', 186, 0, 3, 'sys-configuration/role-manage/roleManage', '/roleManage', '角色权限管理', 'ios-ribbon', 2, null, 0, null, 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (32, null, 'menu-manage', 20, 0, 2, 'sys-configuration/menu-manage/menuManage', '/menuManage', '菜单权限管理', 'md-list', 2, null, 0, null, 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (78, null, null, 28, 1, 0, null, '/position/save', '添加职位', null, 4, null, 0, null, 1);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (182, '', 'audit', null, 0, 15, 'Main', '/audit', '管理日志', 'ios-albums', 1, '', 0, '', 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (185, '', 'logManagement', 182, 0, 0, 'monitor/events/audit', '/logManagement', '操作日志', 'ios-albums', 2, '', 0, '', 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (186, null, 'user', null, 0, 1, 'Main', '/user', '用户角色', 'md-person', 1, null, 0, null, 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (187, null, 'userManage', 186, 0, 0, 'sys-configuration/user-manage/userManage', '/userManage', '用户管理', 'ios-person', 2, null, 0, null, 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (188, '', 'signLog', null, 0, 17, 'Main', '/signLog', '审计日志', 'md-albums', 1, '', 0, '', 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (189, null, 'sign', 188, 0, 0, 'monitor/events/sign', '/sign', '审计', 'md-albums', 2, null, 0, null, 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (194, null, 'loginLog', 182, 0, 2, 'monitor/events/loginLog', '/loginLog', '登录日志', 'md-log-in', 2, null, 0, null, 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (195, null, 'runLog', 182, 0, 3, 'monitor/events/runLog', '/runLog', '运行日志', 'ios-flower', 2, null, 0, null, 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (202, null, 'deviceManager', null, 0, 9, 'Main', '/deviceManager', '设备管理', 'md-tablet-landscape', 1, null, 0, null, 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (203, null, 'cipherMachineManage', 202, 0, 0, 'deviceManager/cipherMachineManage/index', '/cipherMachineManage', '密码机管理', 'ios-easel', 2, null, 0, null, 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (204, null, 'groupManagement', 202, 0, 1, 'deviceManager/groupManagement/index', '/groupManagement', '分组管理', 'md-grid', 2, null, 0, null, 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (205, null, 'serve', null, 0, 7, 'Main', '/serve', '服务管理1', 'ios-browsers', 1, null, 0, null, 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (206, null, 'serviceManagement', 205, 0, 0, 'serviceManagement/index', '/serviceManagement', '服务管理', 'ios-browsers', 2, null, 0, null, 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (207, null, 'application', null, 0, 5, 'Main', '/application', '应用管理1', 'ios-apps', 1, null, 0, null, 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (208, null, 'appliedManagement', 207, 0, 0, 'appliedManagement/index', '/appliedManagement', '应用管理', 'ios-apps', 2, null, 0, null, 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (209, null, 'certManagement', null, 0, 13, 'Main', '/certManagement', '证书管理', 'md-clipboard', 1, null, 0, null, 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (210, null, 'caManagement', 209, 0, 0, 'certManagement/caManagement/index', '/caManagement', 'CA管理', 'ios-bookmarks', 2, null, 0, null, 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (211, null, 'applicationCert', 209, 0, 1, 'certManagement/applicationCert/index', '/applicationCert', '应用证书', 'md-bookmarks', 2, null, 0, null, 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (212, null, 'keyManagement', null, 0, 11, 'Main', '/keyManagement', '密钥管理', 'ios-key', 1, null, 0, null, 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (213, null, 'keyTemplateManage', 212, 0, 0, 'keyManagement/keyTemplateManage/index', '/keyTemplateManage', '密钥模板管理', 'md-key', 2, null, 0, null, 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (214, '', 'symmetricKey', 212, 0, 1, 'keyManagement/symmetricKey/index', '/symmetricKey', '对称密钥管理', 'ios-keypad', 2, '', 0, '', 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (215, null, 'asymmetricKey', 212, 0, 2, 'keyManagement/asymmetricKey/index', '/asymmetricKey', '非对称密钥管理', 'md-keypad', 2, null, 0, null, 0);
INSERT INTO SC_PERMISSION (ID, DESCRIPTION, NAME, PARENT_ID, P_TYPE, SORT_ORDER, COMPONENT, PATH, TITLE, ICON, P_LEVEL, BUTTON_TYPE, P_STATUS, URL, NEED_VERIFY) VALUES (216, null, 'mainKeyManagement', 20, 0, 0, 'sys-configuration/keyManagement/index', '/mainKeyManagement', '主密钥管理', 'ios-key', 2, null, 0, null, 0);


INSERT INTO SC_USER (USERNAME, PASSWORD, REALNAME, ORGANIZATION_ID, TEL, EMAIL, STATUS, UPDATE_TIME, POSITION_ID, SEX, AVATAR, PASS_UPDATE_TIME, U_PUBLICKEY) VALUES ('admin', '$2a$10$9.9KrL/wEMPhxwFf/G3M7OFPnE/ICwWuyE1GRIT1XVXiH7Gksb8XC', '超级管理员', null, null, null, 0, CURRENT_TIMESTAMP(), null, null, null, CURRENT_TIMESTAMP(), '');

SET IDENTITY_INSERT SC_ROLE ON；
INSERT INTO SC_ROLE (ID, NAME, DEFAULT_ROLE, DESCRIPTION, DATA_TYPE) VALUES (1, '超级管理员', null, null, null);
INSERT INTO SC_ROLE (ID, NAME, DEFAULT_ROLE, DESCRIPTION, DATA_TYPE) VALUES (25, '密钥管理员', null, null, null);
INSERT INTO SC_ROLE (ID, NAME, DEFAULT_ROLE, DESCRIPTION, DATA_TYPE) VALUES (32, '配置管理员', null, '', null);
INSERT INTO SC_ROLE (ID, NAME, DEFAULT_ROLE, DESCRIPTION, DATA_TYPE) VALUES (33, '审计管理员', null, '', null);


INSERT INTO SC_USER_ROLE (ROLE_ID, USER_ID) VALUES (1, 1);

INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (182, 33);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (185, 33);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (188, 33);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (189, 33);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (194, 33);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (195, 33);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (20, 25);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (216, 25);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (212, 25);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (213, 25);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (214, 25);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (215, 25);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (209, 25);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (210, 25);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (211, 25);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (20, 32);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (24, 32);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (207, 32);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (208, 32);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (205, 32);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (206, 32);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (202, 32);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (203, 32);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (204, 32);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (186, 1);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (187, 1);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (30, 1);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (20, 1);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (216, 1);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (24, 1);
INSERT INTO SC_ROLE_PERMISSION (PERMISSION_ID, ROLE_ID) VALUES (5, 1);



-- 密码设备
CREATE TABLE sp_device (
    id                    BIGINT NOT NULL   COMMENT 'id',
    name                  VARCHAR(255) DEFAULT '' COMMENT '名称',
    manufacturer          VARCHAR(255) DEFAULT '' COMMENT '制造厂商',
    manufacturer_model    VARCHAR(255) DEFAULT '' COMMENT '制造厂商型号',
    service_ip            VARCHAR(30) DEFAULT '' COMMENT '服务ip',
    service_port          INT COMMENT '服务端口',
    manage_ip             VARCHAR(30) DEFAULT '' COMMENT '管理ip',
    manage_port           INT COMMENT '管理端口',
    enc_key_idx           INT COMMENT '加密密钥索引',
    access_credentials    VARCHAR(255) DEFAULT '' COMMENT '访问凭证',
    status                VARCHAR(25) DEFAULT '' COMMENT '设备状态',
    group_id              BIGINT NOT NULL DEFAULT 0  COMMENT '设备组id',
    group_name            VARCHAR(255) NOT NULL DEFAULT ''  COMMENT '设备组名称',
    weight                INT DEFAULT 1 COMMENT '负载时权重',
    tmk_status            VARCHAR(25) DEFAULT '' COMMENT 'tmk状态',
    device_serial         VARCHAR(25) NOT NULL DEFAULT ''  COMMENT '设备序列号',
    pub_key               VARCHAR(400)  NOT NULL DEFAULT ''  COMMENT '设备公钥',
    enc_tmk               VARCHAR(255)  NOT NULL DEFAULT ''  COMMENT 'tmk密文',
    connected             TINYINT      NOT NULL DEFAULT 0,
    last_connected_time   TIMESTAMP ,
    last_check_time       TIMESTAMP ,
    remark            VARCHAR(500) NOT NULL DEFAULT ''  COMMENT '备注',
    update_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    create_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY (id)
);

-- 设备组
CREATE TABLE sp_device_group (
    id                BIGINT NOT NULL  COMMENT 'id',
    name              VARCHAR(255) NOT NULL DEFAULT '' COMMENT '服务名称',
    remark            VARCHAR(500) NOT NULL DEFAULT ''  COMMENT '备注',
    update_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    create_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY (id)
);

-- TMK
CREATE TABLE sp_tmk_info (
    id                BIGINT NOT NULL  COMMENT 'id',
    device_serial     VARCHAR(255) NOT NULL DEFAULT ''  COMMENT '设备序列号',
    enc_tmk           VARCHAR(255)  NOT NULL DEFAULT ''  COMMENT 'tmk密文',
    pub_key           VARCHAR(400)  NOT NULL DEFAULT ''  COMMENT '设备公钥',
    remark             VARCHAR(500) NOT NULL DEFAULT ''  COMMENT '备注',
    update_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    create_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY (id)
);

-- 密码服务
CREATE TABLE sp_crypto_service (
    id                BIGINT NOT NULL  COMMENT 'id',
    name              VARCHAR(255) NOT NULL DEFAULT '' COMMENT '服务名称',
--    device_group_id   BIGINT NOT NULL DEFAULT 0  COMMENT '设备组id',
--    device_group_name VARCHAR(255) NOT NULL DEFAULT ''  COMMENT '设备组名称',
    status            VARCHAR(50) NOT NULL DEFAULT '' COMMENT '状态',
    creator_id        BIGINT  COMMENT '创建者id',
    remark            VARCHAR(500) NOT NULL DEFAULT ''  COMMENT '备注',
    update_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    create_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY (id)
);

-- 密码服务设备组
CREATE TABLE sp_crypto_service_device_group (
    id                BIGINT NOT NULL  COMMENT 'id',
    service_id        BIGINT NOT NULL  COMMENT '密码服务id',
    device_group_id   BIGINT NOT NULL DEFAULT 0  COMMENT '设备组id',
    device_group_name VARCHAR(255) NOT NULL DEFAULT ''  COMMENT '设备组名称',
    remark            VARCHAR(500) NOT NULL DEFAULT ''  COMMENT '备注',
    update_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    create_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY (id)
);

-- 密码服务api
CREATE TABLE sp_crypto_service_api (
    id                BIGINT NOT NULL  COMMENT 'id',
    crypto_service_id BIGINT NOT NULL  COMMENT '密码服务id',
    api_group         VARCHAR(255) NOT NULL DEFAULT ''  COMMENT 'API分组',
    api_code          VARCHAR(255) NOT NULL DEFAULT ''  COMMENT 'API标识',
    api_name          VARCHAR(255) NOT NULL DEFAULT ''  COMMENT 'API名称',
    remark            VARCHAR(500) NOT NULL DEFAULT ''  COMMENT '备注',
    update_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    create_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY (id)
);

-- 业务应用
CREATE TABLE sp_application (
    id                BIGINT NOT NULL  COMMENT 'id',
    name              VARCHAR(255) NOT NULL DEFAULT '' COMMENT '应用名称',
    app_key           VARCHAR(100) NOT NULL DEFAULT '' COMMENT 'app_key',
    app_secret        VARCHAR(100) NOT NULL DEFAULT '' COMMENT 'app_secret',
    status            VARCHAR(50) NOT NULL DEFAULT '' COMMENT '状态',
    creator_id        BIGINT  COMMENT '创建者id',
    remark            VARCHAR(500) NOT NULL DEFAULT ''  COMMENT '备注',
    update_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    create_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY (id)
);

-- 业务应用绑定的服务
CREATE TABLE sp_app_service (
    id                BIGINT NOT NULL  COMMENT 'id',
    application_id    BIGINT NOT NULL  COMMENT '应用id',
    service_id        BIGINT NOT NULL  COMMENT '服务id',
    remark            VARCHAR(500) NOT NULL DEFAULT ''  COMMENT '备注',
    update_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    create_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY (id)
);

-- 密钥模版
CREATE TABLE sp_key_template (
    id                BIGINT NOT NULL  COMMENT 'id',
    code              VARCHAR(100) NOT NULL DEFAULT ''  COMMENT '编号',
    name              VARCHAR(255) NOT NULL DEFAULT ''  COMMENT '名称',
    key_type          VARCHAR(30)  NOT NULL DEFAULT ''  COMMENT '密钥类型',
    key_alg           VARCHAR(30)  NOT NULL DEFAULT ''  COMMENT '密钥算法',
    key_length        INT NOT NULL DEFAULT 0  COMMENT '密钥长度',
    key_usage         INT NOT NULL DEFAULT 0  COMMENT '密钥用途',
    check_alg         VARCHAR(30)  NOT NULL DEFAULT ''  COMMENT '校验算法',
    check_value       VARCHAR(255)  NOT NULL DEFAULT ''  COMMENT '校验值',
    valid_time        INT NOT NULL DEFAULT 0  COMMENT '有效期',
    valid_unit        VARCHAR(30)  NOT NULL DEFAULT ''  COMMENT '有效期时间单位',
    start_after_create_time   INT NOT NULL DEFAULT 0  COMMENT '创建后多长时间生效',
    start_after_create_unit   VARCHAR(30)  NOT NULL DEFAULT ''  COMMENT '创建后多长时间生效时间单位',
    remark             VARCHAR(500) NOT NULL DEFAULT ''  COMMENT '备注',
    update_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    create_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY (id)
);

-- 密钥信息
CREATE TABLE sp_key_info (
    id                BIGINT NOT NULL  COMMENT 'id',
    application_id    BIGINT NOT NULL  COMMENT '应用id',
    key_template_id   BIGINT NOT NULL  COMMENT '模版id',
    code              VARCHAR(100) NOT NULL DEFAULT ''  COMMENT '编号',
    key_type          VARCHAR(30)  NOT NULL DEFAULT ''  COMMENT '密钥分类',
    key_alg           VARCHAR(30)  NOT NULL DEFAULT ''  COMMENT '密钥算法',
    key_length        INT NOT NULL DEFAULT 0  COMMENT '密钥长度',
    key_usage         INT NOT NULL DEFAULT 0  COMMENT '密钥用途',
    status            VARCHAR(30)  NOT NULL DEFAULT ''  COMMENT '密钥状态',
    check_alg         VARCHAR(30)  NOT NULL DEFAULT ''  COMMENT '校验算法',
    check_value       VARCHAR(255)  NOT NULL DEFAULT ''  COMMENT '校验值',
    effective_time    TIMESTAMP  COMMENT '启用时间',
    expired_time      TIMESTAMP  COMMENT '停用时间',
    remark            VARCHAR(500) NOT NULL DEFAULT ''  COMMENT '备注',
    deleted           TINYINT      NOT NULL DEFAULT 0,
    update_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    create_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    delete_time       TIMESTAMP,
    PRIMARY KEY (id)
);

-- 密钥记录
CREATE TABLE sp_key_record (
    id                BIGINT NOT NULL  COMMENT 'id',
    key_id            BIGINT NOT NULL  COMMENT '密钥id',
    key_index         VARCHAR(100) NOT NULL DEFAULT ''  COMMENT '密钥索引',
    key_data          VARCHAR(255)  NOT NULL DEFAULT ''  COMMENT '密钥密文',
    pub_idx           VARCHAR(10)   NOT NULL DEFAULT ''  COMMENT '公钥',
    pub_key           VARCHAR(400)  NOT NULL DEFAULT ''  COMMENT '公钥',
    check_alg         VARCHAR(30)  NOT NULL DEFAULT ''  COMMENT '校验算法',
    check_value       VARCHAR(255)  NOT NULL DEFAULT ''  COMMENT '校验值',
    effective_time    TIMESTAMP  COMMENT '生效时间',
    expired_time         TIMESTAMP  COMMENT '过期时间',
    remark             VARCHAR(500) NOT NULL DEFAULT ''  COMMENT '备注',
    update_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    create_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY (id)
);
CREATE INDEX idx_kid ON sp_key_record(key_id);
CREATE INDEX idx_pk ON sp_key_record(pub_idx);

-- 证书请求记录
CREATE TABLE sp_key_csr (
    id                BIGINT NOT NULL  COMMENT 'id',
    application_id    BIGINT NOT NULL  COMMENT '应用id',
    key_id            BIGINT NOT NULL  COMMENT '密钥id',
    key_record_id     BIGINT NOT NULL  COMMENT '密钥记录id',
    subject           VARCHAR(1020) NOT NULL DEFAULT '' COMMENT 'DN',
    key_data          VARCHAR(255)  NOT NULL DEFAULT ''  COMMENT '密钥密文',
    pub_key           VARCHAR(400)  NOT NULL DEFAULT ''  COMMENT '公钥',
    csr_txt           VARCHAR(2000) COMMENT '证书',
    remark             VARCHAR(500) NOT NULL DEFAULT ''  COMMENT '备注',
    update_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    create_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY (id)
);
-- 应用证书
CREATE TABLE sp_app_cert (
    id                BIGINT NOT NULL  COMMENT 'id',
    application_id    BIGINT NOT NULL  COMMENT '应用id',
    key_id            BIGINT NOT NULL  COMMENT '密钥id',
    key_record_id     BIGINT NOT NULL  COMMENT '密钥记录id',
    key_alg         VARCHAR(30)  NOT NULL DEFAULT ''  COMMENT '密钥算法',
    cert_type       VARCHAR(30)  NOT NULL DEFAULT '' COMMENT '证书类型,加密|签名',
    status          VARCHAR(30) DEFAULT '' COMMENT '状态',
    single           TINYINT      NOT NULL DEFAULT 0 COMMENT '是否单证',
    version         VARCHAR(10)   NOT NULL DEFAULT '' COMMENT '证书版本',
    subject         VARCHAR(255)  NOT NULL DEFAULT '' COMMENT 'DN',
    serial_number   VARCHAR(255)   NOT NULL DEFAULT '' COMMENT '证书号',
    issuer_dn       VARCHAR(255)  NOT NULL DEFAULT '' COMMENT '颁发者',
    not_before      TIMESTAMP      NOT NULL COMMENT '开始时间',
    not_after       TIMESTAMP      NOT NULL COMMENT '结束时间',
    key_usage       VARCHAR(200)  NOT NULL DEFAULT '' COMMENT '密钥用途',
    pub_key         VARCHAR(255)  NOT NULL DEFAULT '' COMMENT '公钥',
    enc_pri_key     VARCHAR(255)  NOT NULL DEFAULT '' COMMENT '加密后的私钥',
    cert_text        VARCHAR(4099) NOT NULL DEFAULT '' COMMENT '证书',
    remark             VARCHAR(500) NOT NULL DEFAULT ''  COMMENT '备注',
    update_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    create_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY (id)
);
-- CA证书
CREATE TABLE sp_ca_cert (
    id                BIGINT NOT NULL  COMMENT 'id',
    ca_name         VARCHAR(255)  NOT NULL DEFAULT ''  COMMENT 'ca name',
    ca_url          VARCHAR(255)  NOT NULL DEFAULT '' COMMENT 'url',
    key_alg         VARCHAR(30)  NOT NULL DEFAULT ''  COMMENT '密钥算法',
    status          VARCHAR(30) DEFAULT '' COMMENT '状态',
    subject         VARCHAR(255)  NOT NULL DEFAULT '' COMMENT 'DN',
    serial_number   VARCHAR(255)   NOT NULL DEFAULT '' COMMENT '证书号',
    issuer_dn       VARCHAR(255)  NOT NULL DEFAULT '' COMMENT '颁发者',
    not_before      TIMESTAMP      NOT NULL COMMENT '开始时间',
    not_after       TIMESTAMP      NOT NULL COMMENT '结束时间',
    pub_key         VARCHAR(255)  NOT NULL DEFAULT '' COMMENT '公钥',
    cert_text        VARCHAR(4099) NOT NULL DEFAULT '' COMMENT '证书',
    remark             VARCHAR(500) NOT NULL DEFAULT ''  COMMENT '备注',
    update_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    create_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY (id)
);

-- ip白名单
CREATE TABLE sp_ip_whitelist (
    id                BIGINT NOT NULL  COMMENT 'id',
    app_id          BIGINT NOT NULL  COMMENT '应用id',
    ip              VARCHAR(30)  NOT NULL DEFAULT ''  COMMENT 'ip',
    scope           VARCHAR(30)  NOT NULL DEFAULT '' COMMENT 'app | global',
    status          VARCHAR(30)  NOT NULL DEFAULT '' COMMENT '',
    creator         VARCHAR(30)  NOT NULL DEFAULT '' COMMENT '',
    remark             VARCHAR(500) NOT NULL DEFAULT ''  COMMENT '备注',
    update_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    create_time       TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
    PRIMARY KEY (id)
);