CREATE DATABASE IF NOT EXISTS `sop` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
USE `sop`;

DROP TABLE IF EXISTS `api_info`;
CREATE TABLE `api_info` (
                            `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
                            `application` varchar(64) NOT NULL DEFAULT '' COMMENT '应用名称',
                            `api_name` varchar(128) NOT NULL DEFAULT '' COMMENT '接口名称',
                            `api_version` varchar(16) NOT NULL DEFAULT '1.0' COMMENT '版本号',
                            `description` varchar(64) DEFAULT '' COMMENT '接口描述',
                            `remark` text COMMENT '备注',
                            `interface_class_name` varchar(128) NOT NULL DEFAULT '' COMMENT '接口class',
                            `method_name` varchar(128) NOT NULL DEFAULT '' COMMENT '方法名称',
                            `param_info` text COMMENT '参数信息',
                            `is_permission` tinyint(4) NOT NULL DEFAULT '0' COMMENT '接口是否需要授权访问',
                            `is_need_Token` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否需要appAuthToken',
                            `reg_source` tinyint(4) NOT NULL DEFAULT '1' COMMENT '注册来源，1-系统注册,2-手动注册',
                            `status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '1启用，0禁用',
                            `add_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
                            `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                            PRIMARY KEY (`id`),
                            UNIQUE KEY `uk_apiname_version` (`api_name`,`api_version`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf32 COMMENT='接口信息表';

DROP TABLE IF EXISTS `isv_info`;
CREATE TABLE `isv_info` (
                            `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
                            `app_id` varchar(100) NOT NULL COMMENT 'appKey',
                            `status` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '1启用，2禁用',
                            `remark` varchar(512) DEFAULT NULL COMMENT '备注',
                            `add_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
                            `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                            PRIMARY KEY (`id`),
                            UNIQUE KEY `uk_appid` (`app_id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf32 COMMENT='isv信息表';

DROP TABLE IF EXISTS `isv_keys`;
CREATE TABLE `isv_keys` (
                            `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
                            `isv_id` bigint(20) NOT NULL DEFAULT '0' COMMENT 'isv_info.id',
                            `key_format` tinyint(4) NOT NULL DEFAULT '1' COMMENT '秘钥格式，1：PKCS8(JAVA适用)，2：PKCS1(非JAVA适用)',
                            `public_key_isv` text NOT NULL COMMENT '开发者生成的公钥',
                            `private_key_isv` text NOT NULL COMMENT '开发者生成的私钥（交给开发者）',
                            `public_key_platform` text NOT NULL COMMENT '平台生成的公钥（交给开发者）',
                            `private_key_platform` text NOT NULL COMMENT '平台生成的私钥',
                            `add_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
                            `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                            PRIMARY KEY (`id`),
                            UNIQUE KEY `uk_appid` (`isv_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8 COMMENT='ISV秘钥管理';

DROP TABLE IF EXISTS `perm_group`;
CREATE TABLE `perm_group` (
                              `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
                              `group_name` varchar(64) NOT NULL COMMENT '分组描述',
                              `is_deleted` tinyint(4) DEFAULT '0' COMMENT '是否删除',
                              `add_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
                              `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                              PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf32 COMMENT='分组表';

DROP TABLE IF EXISTS `perm_group_permission`;
CREATE TABLE `perm_group_permission` (
                                         `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
                                         `group_id` bigint(20) NOT NULL DEFAULT '0' COMMENT 'perm_group.id',
                                         `api_id` varchar(64) NOT NULL COMMENT 'api_info.id',
                                         `add_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
                                         `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                         PRIMARY KEY (`id`),
                                         UNIQUE KEY `uk_code_apiid` (`group_id`,`api_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf32 COMMENT='组权限表';

DROP TABLE IF EXISTS `perm_isv_group`;
CREATE TABLE `perm_isv_group` (
                                  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
                                  `isv_id` bigint(20) NOT NULL COMMENT 'isv_info表id',
                                  `group_id` bigint(20) NOT NULL DEFAULT '0' COMMENT 'perm_group.id',
                                  `add_time` datetime DEFAULT CURRENT_TIMESTAMP,
                                  `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
                                  PRIMARY KEY (`id`),
                                  UNIQUE KEY `uk_user_role` (`isv_id`,`group_id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf32 COMMENT='isv分组';

DROP TABLE IF EXISTS `sys_admin_user`;
CREATE TABLE `sys_admin_user` (
                                  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
                                  `username` varchar(128) NOT NULL DEFAULT '' COMMENT '用户名',
                                  `password` varchar(128) NOT NULL DEFAULT '' COMMENT '密码',
                                  `nickname` varchar(64) NOT NULL DEFAULT '' COMMENT '用户名',
                                  `email` varchar(128) NOT NULL DEFAULT '' COMMENT '邮箱',
                                  `avatar` varchar(128) NOT NULL DEFAULT '' COMMENT '头像',
                                  `status` tinyint(4) unsigned NOT NULL DEFAULT '1' COMMENT '状态，1：启用，2：禁用',
                                  `reg_type` varchar(32) NOT NULL DEFAULT '1' COMMENT '注册类型，1-系统，2-手动',
                                  `add_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
                                  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
                                  PRIMARY KEY (`id`),
                                  UNIQUE KEY `uk_username` (`username`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf32 COMMENT='系统用户表';

DROP TABLE IF EXISTS `sys_config`;
CREATE TABLE `sys_config` (
                              `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
                              `config_key` varchar(64) NOT NULL DEFAULT '',
                              `config_value` varchar(256) NOT NULL DEFAULT '',
                              `remark` varchar(128) NOT NULL DEFAULT '',
                              `is_deleted` tinyint(4) NOT NULL DEFAULT '0',
                              `add_time` datetime DEFAULT CURRENT_TIMESTAMP,
                              `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
                              PRIMARY KEY (`id`) USING BTREE,
                              UNIQUE KEY `uk_configkey` (`config_key`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf32 COMMENT='系统配置表';

