diff --git a/databases/v1.0-beta.1.sql b/databases/v1.0-beta.1.sql deleted file mode 100644 index e0c16e1..0000000 --- a/databases/v1.0-beta.1.sql +++ /dev/null @@ -1,307 +0,0 @@ - -CREATE TABLE `admin_permissions` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `type` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '类型[行为:action,数据:data]', - `group_name` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '分组', - `sort` int(11) NOT NULL COMMENT '升序', - `name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '权限名', - `slug` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'slug', - `created_at` timestamp NULL DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - -CREATE TABLE `admin_role_permission` ( - `role_id` int(11) unsigned NOT NULL DEFAULT '0', - `perm_id` int(10) unsigned NOT NULL DEFAULT '0', - KEY `role_id` (`role_id`), - KEY `perm_id` (`perm_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -CREATE TABLE `admin_roles` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '角色名', - `slug` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'slug', - `created_at` timestamp NULL DEFAULT NULL, - `updated_at` timestamp NULL DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `slug` (`slug`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - -INSERT INTO `admin_roles` (`name`, `slug`, `created_at`, `updated_at`) -VALUES - ('超级管理角色', 'super-role', '2023-02-24 06:19:15', '2023-02-24 06:19:15'); - -CREATE TABLE `admin_user_role` ( - `admin_id` int(11) unsigned NOT NULL DEFAULT '0', - `role_id` int(10) unsigned NOT NULL DEFAULT '0', - KEY `admin_id` (`admin_id`), - KEY `role_id` (`role_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -INSERT INTO `admin_user_role` (`admin_id`, `role_id`) -VALUES - (1, 1); - -CREATE TABLE `admin_users` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '姓名', - `email` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '邮箱', - `password` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '密码', - `salt` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'Salt', - `login_ip` varchar(15) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '登录IP', - `login_at` timestamp NULL DEFAULT NULL COMMENT '登录时间', - `is_ban_login` tinyint(4) NOT NULL DEFAULT '0' COMMENT '1禁止登录,0否', - `login_times` int(11) NOT NULL DEFAULT '0' COMMENT '登录次数', - `created_at` timestamp NULL DEFAULT NULL, - `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (`id`), - UNIQUE KEY `administrators_email_unique` (`email`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - -INSERT INTO `admin_users` (`name`, `email`, `password`, `salt`, `login_ip`, `login_at`, `is_ban_login`, `login_times`, `created_at`, `updated_at`) -VALUES - ('超级管理员', 'admin@playedu.xyz', 'd771587aa711961304fa8c1a5273f491', 'VROkTh', '', '2023-04-06 16:51:17', 0, 0, '2023-02-19 18:10:12', '2023-04-06 16:51:17'); - -CREATE TABLE `app_config` ( - `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, - `group_name` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '分组', - `name` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '名称', - `sort` int(11) NOT NULL DEFAULT '0' COMMENT '升序', - `field_type` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '字段类型', - `key_name` varchar(188) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '键', - `key_value` longtext COLLATE utf8mb4_unicode_ci COMMENT '值', - `option_value` text COLLATE utf8mb4_unicode_ci COMMENT '可选值', - `is_private` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否私密信息', - `help` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '帮助信息', - `created_at` timestamp NULL DEFAULT NULL, - `is_hidden` tinyint(4) NOT NULL DEFAULT '0' COMMENT '1显示,0否', - PRIMARY KEY (`id`), - UNIQUE KEY `app_config_key_unique` (`key_name`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - -CREATE TABLE `course_chapters` ( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `course_id` int(11) NOT NULL DEFAULT '0' COMMENT '课程ID', - `name` varchar(64) NOT NULL DEFAULT '' COMMENT '章节名', - `sort` int(11) NOT NULL DEFAULT '0' COMMENT '升序', - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -CREATE TABLE `course_department` ( - `course_id` int(11) NOT NULL DEFAULT '0', - `dep_id` int(11) NOT NULL DEFAULT '0', - KEY `course_id` (`course_id`), - KEY `dep_id` (`dep_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -CREATE TABLE `course_hour` ( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `course_id` int(11) NOT NULL DEFAULT '0' COMMENT '课程ID', - `chapter_id` int(11) NOT NULL DEFAULT '0' COMMENT '章节ID', - `sort` int(11) NOT NULL DEFAULT '0' COMMENT '升序', - `title` varchar(255) NOT NULL DEFAULT '' COMMENT '课时名', - `type` varchar(20) NOT NULL DEFAULT '' COMMENT '课时类型', - `rid` int(11) NOT NULL DEFAULT '0' COMMENT '资源id', - `duration` int(11) NOT NULL COMMENT '时长[s]', - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (`id`), - KEY `course_id` (`course_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -CREATE TABLE `courses` ( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `title` varchar(255) NOT NULL DEFAULT '' COMMENT '课程标题', - `thumb` varchar(255) NOT NULL DEFAULT '' COMMENT '课程封面', - `charge` int(11) NOT NULL DEFAULT '0' COMMENT '课程价格(分)', - `short_desc` varchar(255) NOT NULL DEFAULT '' COMMENT '简介', - `class_hour` int(11) NOT NULL DEFAULT '0' COMMENT '课时数', - `is_show` tinyint(4) NOT NULL DEFAULT '0' COMMENT '显示[1:是,0:否]', - `is_required` tinyint(4) NOT NULL DEFAULT '0' COMMENT '1:必修,0:选修', - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, - `deleted_at` timestamp NULL DEFAULT NULL COMMENT '删除时间', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -CREATE TABLE `departments` ( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(64) NOT NULL DEFAULT '' COMMENT '部门名', - `parent_id` int(11) NOT NULL COMMENT '父id', - `parent_chain` varchar(255) NOT NULL DEFAULT '' COMMENT '父链', - `sort` int(11) NOT NULL DEFAULT '0' COMMENT '升序', - `created_at` timestamp NULL DEFAULT NULL, - `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -CREATE TABLE `resource_categories` ( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `parent_id` int(11) NOT NULL DEFAULT '0', - `parent_chain` varchar(2550) NOT NULL DEFAULT '', - `name` varchar(64) NOT NULL DEFAULT '' COMMENT '分类名', - `sort` int(11) NOT NULL COMMENT '升序', - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - - -CREATE TABLE `resource_category` ( - `cid` int(11) NOT NULL DEFAULT '0', - `rid` int(11) NOT NULL, - KEY `cid` (`cid`), - KEY `rid` (`rid`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - - -CREATE TABLE `resource_course_category` ( - `course_id` int(11) NOT NULL DEFAULT '0', - `category_id` int(11) NOT NULL DEFAULT '0', - KEY `course_id` (`course_id`), - KEY `category_id` (`category_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -CREATE TABLE `resource_videos` ( - `rid` int(11) unsigned NOT NULL, - `poster` varchar(255) NOT NULL DEFAULT '' COMMENT '封面', - `duration` int(10) unsigned NOT NULL COMMENT '视频时长[s]', - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - UNIQUE KEY `rid` (`rid`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -CREATE TABLE `resources` ( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `admin_id` int(11) NOT NULL DEFAULT '0', - `type` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '类型', - `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '资源名', - `extension` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '文件类型', - `size` bigint(20) DEFAULT '0' COMMENT '大小[字节]', - `disk` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '存储磁盘', - `file_id` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '文件id', - `path` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '相对地址', - `url` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'URL地址', - `created_at` timestamp NULL DEFAULT NULL, - `parent_id` int(11) NOT NULL DEFAULT '0' COMMENT '所属素材', - `is_hidden` tinyint(4) NOT NULL DEFAULT '0' COMMENT '隐藏[0:否,1:是]', - PRIMARY KEY (`id`), - KEY `type` (`type`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - -CREATE TABLE `user_course_hour_records` ( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `user_id` int(11) NOT NULL DEFAULT '0', - `course_id` int(11) NOT NULL DEFAULT '0', - `hour_id` int(11) NOT NULL DEFAULT '0', - `total_duration` int(11) NOT NULL DEFAULT '0' COMMENT '总时长', - `finished_duration` int(11) NOT NULL DEFAULT '0' COMMENT '已完成时长', - `real_duration` int(11) NOT NULL DEFAULT '0' COMMENT '实际观看时长', - `is_finished` tinyint(4) DEFAULT NULL COMMENT '是否看完[1:是,0:否]', - `finished_at` timestamp NULL DEFAULT NULL COMMENT '看完时间', - `created_at` timestamp NULL DEFAULT NULL, - `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (`id`), - KEY `u_h_c_id` (`user_id`,`hour_id`,`course_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -CREATE TABLE `user_course_records` ( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `user_id` int(11) NOT NULL DEFAULT '0', - `course_id` int(11) NOT NULL DEFAULT '0', - `hour_count` int(11) NOT NULL DEFAULT '0' COMMENT '课时数量', - `finished_count` int(11) NOT NULL DEFAULT '0' COMMENT '已完成课时数', - `progress` int(11) NOT NULL DEFAULT '0' COMMENT '进度', - `is_finished` tinyint(4) NOT NULL DEFAULT '0' COMMENT '看完[1:是,0:否]', - `finished_at` timestamp NULL DEFAULT NULL COMMENT '看完时间', - `created_at` timestamp NULL DEFAULT NULL, - `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -CREATE TABLE `user_department` ( - `user_id` int(11) unsigned NOT NULL DEFAULT '0', - `dep_id` int(11) unsigned NOT NULL DEFAULT '0', - KEY `user_id` (`user_id`), - KEY `dep_id` (`dep_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - - -CREATE TABLE `user_learn_duration_records` ( - `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, - `user_id` int(11) NOT NULL DEFAULT '0', - `created_date` date NOT NULL, - `duration` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '已学习时长[微秒]', - `start_at` timestamp NULL DEFAULT NULL COMMENT '开始时间', - `end_at` timestamp NULL DEFAULT NULL COMMENT '结束时间', - `course_id` int(11) NOT NULL DEFAULT '0', - `hour_id` int(11) NOT NULL DEFAULT '0', - PRIMARY KEY (`id`), - KEY `u_d` (`user_id`,`created_date`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - - -CREATE TABLE `user_learn_duration_stats` ( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `user_id` int(11) NOT NULL DEFAULT '0', - `duration` bigint(20) NOT NULL DEFAULT '0', - `created_date` date NOT NULL, - PRIMARY KEY (`id`), - KEY `u_d` (`user_id`,`created_date`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -CREATE TABLE `user_login_records` ( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `user_id` int(11) NOT NULL, - `jti` varchar(64) NOT NULL DEFAULT '' COMMENT 'JTI', - `ip` varchar(15) NOT NULL DEFAULT '' COMMENT '登录ip', - `ip_area` varchar(64) NOT NULL DEFAULT '' COMMENT 'Ip解析区域', - `browser` varchar(64) NOT NULL DEFAULT '' COMMENT '浏览器', - `browser_version` varchar(64) NOT NULL DEFAULT '' COMMENT '浏览器版本', - `os` varchar(128) NOT NULL DEFAULT '' COMMENT '操作系统', - `expired` bigint(20) NOT NULL DEFAULT '0' COMMENT '过期时间', - `is_logout` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否注销', - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - PRIMARY KEY (`id`), - UNIQUE KEY `jti` (`jti`), - KEY `user_id` (`user_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - - -CREATE TABLE `user_upload_image_logs` ( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `user_id` int(11) NOT NULL DEFAULT '0', - `typed` varchar(32) NOT NULL DEFAULT '' COMMENT '图片类型', - `scene` varchar(24) NOT NULL DEFAULT '' COMMENT '上传场景', - `driver` varchar(32) NOT NULL DEFAULT '' COMMENT '驱动', - `path` varchar(255) NOT NULL DEFAULT '' COMMENT '相对路径', - `url` varchar(255) NOT NULL DEFAULT '' COMMENT '访问地址', - `size` bigint(20) NOT NULL COMMENT '大小,单位:字节', - `name` varchar(255) NOT NULL DEFAULT '' COMMENT '文件名', - `created_at` timestamp NULL DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - - -CREATE TABLE `users` ( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `email` varchar(32) NOT NULL DEFAULT '' COMMENT '邮件', - `name` varchar(24) NOT NULL DEFAULT '' COMMENT '真实姓名', - `avatar` varchar(255) NOT NULL DEFAULT '' COMMENT '头像', - `password` varchar(128) NOT NULL DEFAULT '' COMMENT '密码', - `salt` varchar(12) NOT NULL DEFAULT '' COMMENT 'salt', - `id_card` varchar(64) NOT NULL DEFAULT '' COMMENT '身份证号', - `credit1` int(11) NOT NULL DEFAULT '0' COMMENT '学分', - `create_ip` varchar(15) NOT NULL DEFAULT '' COMMENT '注册Ip', - `create_city` varchar(32) NOT NULL DEFAULT '' COMMENT '注册城市', - `is_active` tinyint(4) NOT NULL DEFAULT '0' COMMENT '激活[1:是,0:否]', - `is_lock` tinyint(4) NOT NULL DEFAULT '0' COMMENT '锁定[1:是,0:否]', - `is_verify` tinyint(4) NOT NULL DEFAULT '0' COMMENT '实名认证[1:是,0:否]', - `verify_at` timestamp NULL DEFAULT NULL COMMENT '实名认证时间', - `is_set_password` tinyint(4) NOT NULL DEFAULT '0' COMMENT '设置密码[1:是,0:否]', - `login_at` timestamp NULL DEFAULT NULL COMMENT '登录时间', - `created_at` timestamp NULL DEFAULT NULL, - `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (`id`), - UNIQUE KEY `email` (`email`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/databases/v1.2.sql b/databases/v1.2.sql deleted file mode 100644 index 20fe79a..0000000 --- a/databases/v1.2.sql +++ /dev/null @@ -1,48 +0,0 @@ -DROP TABLE IF EXISTS admin_logs; - -CREATE TABLE IF NOT EXISTS `admin_logs` -( - `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, - `admin_id` int(11) NOT NULL DEFAULT '0' COMMENT '管理员ID', - `admin_name` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '管理员姓名', - `module` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '模块', - `title` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '请求方法标题', - `opt` int(2) NOT NULL DEFAULT '0' COMMENT '操作指令(0其它 1新增 2修改 3删除 4登录 5退出登录)', - `method` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '请求方法', - `request_method` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '请求方式POST,GET,PUT,DELETE', - `url` varchar(266) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '请求URL', - `param` mediumtext COLLATE utf8mb4_unicode_ci COMMENT '请求参数', - `result` mediumtext COLLATE utf8mb4_unicode_ci COMMENT '返回参数', - `ip` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'ip', - `ip_area` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '地址', - `error_msg` mediumtext COLLATE utf8mb4_unicode_ci COMMENT '错误消息', - `created_at` timestamp NULL DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `a_m_o` (`admin_id`,`module`,`opt`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - -CREATE TABLE `course_attachment` -( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `course_id` int(11) NOT NULL DEFAULT '0' COMMENT '课程ID', - `sort` int(11) NOT NULL DEFAULT '0' COMMENT '升序', - `title` varchar(255) NOT NULL DEFAULT '' COMMENT '附件名', - `type` varchar(20) NOT NULL DEFAULT '' COMMENT '附件类型', - `rid` int(11) NOT NULL DEFAULT '0' COMMENT '资源id', - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (`id`), - KEY `course_id` (`course_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -CREATE TABLE `course_attachment_download_log` -( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `user_id` int(11) NOT NULL DEFAULT '0' COMMENT '学员ID', - `course_id` int(11) NOT NULL DEFAULT '0' COMMENT '课程ID', - `title` varchar(255) NOT NULL DEFAULT '' COMMENT '课程标题', - `courser_attachment_id` int(11) NOT NULL DEFAULT '0' COMMENT '课程附件id', - `rid` int(11) NOT NULL DEFAULT '0' COMMENT '资源id', - `ip` varchar(45) NOT NULL DEFAULT '' COMMENT '下载ip', - `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; \ No newline at end of file diff --git a/playedu-common/src/main/java/xyz/playedu/common/service/AdminRoleService.java b/playedu-common/src/main/java/xyz/playedu/common/service/AdminRoleService.java index b9b415b..15b2fd3 100644 --- a/playedu-common/src/main/java/xyz/playedu/common/service/AdminRoleService.java +++ b/playedu-common/src/main/java/xyz/playedu/common/service/AdminRoleService.java @@ -31,6 +31,8 @@ public interface AdminRoleService extends IService { AdminRole getBySlug(String slug); + Integer initSuperAdminRole(); + void createWithPermissionIds(String name, Integer[] permissionIds); void relatePermissions(AdminRole role, Integer[] permissionIds); diff --git a/playedu-common/src/main/java/xyz/playedu/common/service/impl/AdminRoleServiceImpl.java b/playedu-common/src/main/java/xyz/playedu/common/service/impl/AdminRoleServiceImpl.java index 600147b..bb058a9 100644 --- a/playedu-common/src/main/java/xyz/playedu/common/service/impl/AdminRoleServiceImpl.java +++ b/playedu-common/src/main/java/xyz/playedu/common/service/impl/AdminRoleServiceImpl.java @@ -22,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import xyz.playedu.common.constant.BackendConstant; import xyz.playedu.common.domain.AdminRole; import xyz.playedu.common.domain.AdminRolePermission; import xyz.playedu.common.exception.NotFoundException; @@ -53,6 +54,20 @@ public class AdminRoleServiceImpl extends ServiceImpl> permissions = new HashMap<>() { @@ -279,7 +278,7 @@ public class AdminPermissionCheck implements ApplicationRunner { @Autowired private AdminPermissionService permissionService; @Override - public void run(ApplicationArguments args) throws Exception { + public void run(String... args) throws Exception { HashMap slugs = permissionService.allSlugs(); List list = new ArrayList<>(); Date now = new Date(); @@ -311,7 +310,7 @@ public class AdminPermissionCheck implements ApplicationRunner { }); }); - if (list.size() > 0) { + if (!list.isEmpty()) { permissionService.saveBatch(list); } } diff --git a/playedu-system/src/main/java/xyz/playedu/system/checks/AppConfigCheck.java b/playedu-system/src/main/java/xyz/playedu/system/checks/AppConfigCheck.java index 05d23be..d2bde52 100644 --- a/playedu-system/src/main/java/xyz/playedu/system/checks/AppConfigCheck.java +++ b/playedu-system/src/main/java/xyz/playedu/system/checks/AppConfigCheck.java @@ -16,8 +16,7 @@ package xyz.playedu.system.checks; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.ApplicationArguments; -import org.springframework.boot.ApplicationRunner; +import org.springframework.boot.CommandLineRunner; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; @@ -29,8 +28,8 @@ import xyz.playedu.common.service.AppConfigService; import java.util.*; @Component -@Order(1000) -public class AppConfigCheck implements ApplicationRunner { +@Order(100) +public class AppConfigCheck implements CommandLineRunner { private static final HashMap configs = new HashMap<>() { @@ -230,7 +229,7 @@ public class AppConfigCheck implements ApplicationRunner { @Autowired private AppConfigService configService; @Override - public void run(ApplicationArguments args) throws Exception { + public void run(String... args) throws Exception { Map keys = configService.allKeys(); List list = new ArrayList<>(); Date now = new Date(); @@ -250,7 +249,7 @@ public class AppConfigCheck implements ApplicationRunner { } }); - if (list.size() > 0) { + if (!list.isEmpty()) { configService.saveBatch(list); } } diff --git a/playedu-system/src/main/java/xyz/playedu/system/checks/MigrationCheck.java b/playedu-system/src/main/java/xyz/playedu/system/checks/MigrationCheck.java new file mode 100644 index 0000000..762e66c --- /dev/null +++ b/playedu-system/src/main/java/xyz/playedu/system/checks/MigrationCheck.java @@ -0,0 +1,709 @@ +/* + * Copyright (C) 2023 杭州白书科技有限公司 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package xyz.playedu.system.checks; + +import lombok.extern.slf4j.Slf4j; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.core.annotation.Order; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Component; + +import xyz.playedu.system.service.MigrationService; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Order(10) +@Component +@Slf4j +public class MigrationCheck implements CommandLineRunner { + + public static final List> TABLE_SQL = + new ArrayList<>() { + { + add( + new HashMap<>() { + { + put("table", "migrations"); + put("name", "20230406_16_51_17_1111_migrations"); + put( + "sql", + """ + CREATE TABLE `migrations` ( + `id` int unsigned NOT NULL AUTO_INCREMENT, + `migration` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, + PRIMARY KEY (`id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "admin_permissions"); + put("name", "20230406_16_51_17_1111_admin_permissions"); + put( + "sql", + """ + CREATE TABLE `admin_permissions` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `type` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '类型[行为:action,数据:data]', + `group_name` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '分组', + `sort` int(11) NOT NULL COMMENT '升序', + `name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '权限名', + `slug` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'slug', + `created_at` timestamp NULL DEFAULT NULL, + PRIMARY KEY (`id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "admin_role_permission"); + put("name", "20230406_16_51_17_1111_admin_role_permission"); + put( + "sql", + """ + CREATE TABLE `admin_role_permission` ( + `role_id` int(11) unsigned NOT NULL DEFAULT '0', + `perm_id` int(10) unsigned NOT NULL DEFAULT '0', + KEY `role_id` (`role_id`), + KEY `perm_id` (`perm_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "admin_roles"); + put("name", "20230406_16_51_17_1111_admin_roles"); + put( + "sql", + """ + CREATE TABLE `admin_roles` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '角色名', + `slug` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'slug', + `created_at` timestamp NULL DEFAULT NULL, + `updated_at` timestamp NULL DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `slug` (`slug`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "admin_user_role"); + put("name", "20230406_16_51_17_1111_admin_user_role"); + put( + "sql", + """ + CREATE TABLE `admin_user_role` ( + `admin_id` int(11) unsigned NOT NULL DEFAULT '0', + `role_id` int(10) unsigned NOT NULL DEFAULT '0', + KEY `admin_id` (`admin_id`), + KEY `role_id` (`role_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "admin_users"); + put("name", "20230406_16_51_17_1111_admin_users"); + put( + "sql", + """ + CREATE TABLE `admin_users` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '姓名', + `email` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '邮箱', + `password` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '密码', + `salt` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'Salt', + `login_ip` varchar(15) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '登录IP', + `login_at` timestamp NULL DEFAULT NULL COMMENT '登录时间', + `is_ban_login` tinyint(4) NOT NULL DEFAULT '0' COMMENT '1禁止登录,0否', + `login_times` int(11) NOT NULL DEFAULT '0' COMMENT '登录次数', + `created_at` timestamp NULL DEFAULT NULL, + `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `administrators_email_unique` (`email`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "app_config"); + put("name", "20230406_16_51_17_1111_app_config"); + put( + "sql", + """ + CREATE TABLE `app_config` ( + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, + `group_name` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '分组', + `name` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '名称', + `sort` int(11) NOT NULL DEFAULT '0' COMMENT '升序', + `field_type` varchar(24) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '字段类型', + `key_name` varchar(188) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '键', + `key_value` longtext COLLATE utf8mb4_unicode_ci COMMENT '值', + `option_value` text COLLATE utf8mb4_unicode_ci COMMENT '可选值', + `is_private` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否私密信息', + `help` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '帮助信息', + `created_at` timestamp NULL DEFAULT NULL, + `is_hidden` tinyint(4) NOT NULL DEFAULT '0' COMMENT '1显示,0否', + PRIMARY KEY (`id`), + UNIQUE KEY `app_config_key_unique` (`key_name`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "course_chapters"); + put("name", "20230406_16_51_17_1111_course_chapters"); + put( + "sql", + """ + CREATE TABLE `course_chapters` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `course_id` int(11) NOT NULL DEFAULT '0' COMMENT '课程ID', + `name` varchar(64) NOT NULL DEFAULT '' COMMENT '章节名', + `sort` int(11) NOT NULL DEFAULT '0' COMMENT '升序', + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` timestamp NULL DEFAULT NULL, + PRIMARY KEY (`id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "course_department"); + put("name", "20230406_16_51_17_1111_course_department"); + put( + "sql", + """ + CREATE TABLE `course_department` ( + `course_id` int(11) NOT NULL DEFAULT '0', + `dep_id` int(11) NOT NULL DEFAULT '0', + KEY `course_id` (`course_id`), + KEY `dep_id` (`dep_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "course_hour"); + put("name", "20230406_16_51_17_1111_course_hour"); + put( + "sql", + """ + CREATE TABLE `course_hour` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `course_id` int(11) NOT NULL DEFAULT '0' COMMENT '课程ID', + `chapter_id` int(11) NOT NULL DEFAULT '0' COMMENT '章节ID', + `sort` int(11) NOT NULL DEFAULT '0' COMMENT '升序', + `title` varchar(255) NOT NULL DEFAULT '' COMMENT '课时名', + `type` varchar(20) NOT NULL DEFAULT '' COMMENT '课时类型', + `rid` int(11) NOT NULL DEFAULT '0' COMMENT '资源id', + `duration` int(11) NOT NULL COMMENT '时长[s]', + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + KEY `course_id` (`course_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "courses"); + put("name", "20230406_16_51_17_1111_courses"); + put( + "sql", + """ + CREATE TABLE `courses` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `title` varchar(255) NOT NULL DEFAULT '' COMMENT '课程标题', + `thumb` varchar(255) NOT NULL DEFAULT '' COMMENT '课程封面', + `charge` int(11) NOT NULL DEFAULT '0' COMMENT '课程价格(分)', + `short_desc` varchar(255) NOT NULL DEFAULT '' COMMENT '简介', + `class_hour` int(11) NOT NULL DEFAULT '0' COMMENT '课时数', + `is_show` tinyint(4) NOT NULL DEFAULT '0' COMMENT '显示[1:是,0:否]', + `is_required` tinyint(4) NOT NULL DEFAULT '0' COMMENT '1:必修,0:选修', + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` timestamp NULL DEFAULT NULL, + `deleted_at` timestamp NULL DEFAULT NULL COMMENT '删除时间', + PRIMARY KEY (`id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "departments"); + put("name", "20230406_16_51_17_1111_departments"); + put( + "sql", + """ + CREATE TABLE `departments` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(64) NOT NULL DEFAULT '' COMMENT '部门名', + `parent_id` int(11) NOT NULL COMMENT '父id', + `parent_chain` varchar(255) NOT NULL DEFAULT '' COMMENT '父链', + `sort` int(11) NOT NULL DEFAULT '0' COMMENT '升序', + `created_at` timestamp NULL DEFAULT NULL, + `updated_at` timestamp NULL DEFAULT NULL, + PRIMARY KEY (`id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "resource_categories"); + put("name", "20230406_16_51_17_1111_resource_categories"); + put( + "sql", + """ + CREATE TABLE `resource_categories` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `parent_id` int(11) NOT NULL DEFAULT '0', + `parent_chain` varchar(2550) NOT NULL DEFAULT '', + `name` varchar(64) NOT NULL DEFAULT '' COMMENT '分类名', + `sort` int(11) NOT NULL COMMENT '升序', + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `updated_at` timestamp NULL DEFAULT NULL, + PRIMARY KEY (`id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "resource_category"); + put("name", "20230406_16_51_17_1111_resource_category"); + put( + "sql", + """ + CREATE TABLE `resource_category` ( + `cid` int(11) NOT NULL DEFAULT '0', + `rid` int(11) NOT NULL, + KEY `cid` (`cid`), + KEY `rid` (`rid`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "resource_course_category"); + put("name", "20230406_16_51_17_1111_resource_course_category"); + put( + "sql", + """ + CREATE TABLE `resource_course_category` ( + `course_id` int(11) NOT NULL DEFAULT '0', + `category_id` int(11) NOT NULL DEFAULT '0', + KEY `course_id` (`course_id`), + KEY `category_id` (`category_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "resource_videos"); + put("name", "20230406_16_51_17_1111_resource_videos"); + put( + "sql", + """ + CREATE TABLE `resource_videos` ( + `rid` int(11) unsigned NOT NULL, + `poster` varchar(255) NOT NULL DEFAULT '' COMMENT '封面', + `duration` int(10) unsigned NOT NULL COMMENT '视频时长[s]', + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + UNIQUE KEY `rid` (`rid`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "resources"); + put("name", "20230406_16_51_17_1111_resources"); + put( + "sql", + """ + CREATE TABLE `resources` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `admin_id` int(11) NOT NULL DEFAULT '0', + `type` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '类型', + `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '资源名', + `extension` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '文件类型', + `size` bigint(20) DEFAULT '0' COMMENT '大小[字节]', + `disk` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '存储磁盘', + `file_id` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '文件id', + `path` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '相对地址', + `url` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'URL地址', + `created_at` timestamp NULL DEFAULT NULL, + `parent_id` int(11) NOT NULL DEFAULT '0' COMMENT '所属素材', + `is_hidden` tinyint(4) NOT NULL DEFAULT '0' COMMENT '隐藏[0:否,1:是]', + PRIMARY KEY (`id`), + KEY `type` (`type`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "user_course_hour_records"); + put("name", "20230406_16_51_17_1111_user_course_hour_records"); + put( + "sql", + """ + CREATE TABLE `user_course_hour_records` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `user_id` int(11) NOT NULL DEFAULT '0', + `course_id` int(11) NOT NULL DEFAULT '0', + `hour_id` int(11) NOT NULL DEFAULT '0', + `total_duration` int(11) NOT NULL DEFAULT '0' COMMENT '总时长', + `finished_duration` int(11) NOT NULL DEFAULT '0' COMMENT '已完成时长', + `real_duration` int(11) NOT NULL DEFAULT '0' COMMENT '实际观看时长', + `is_finished` tinyint(4) DEFAULT NULL COMMENT '是否看完[1:是,0:否]', + `finished_at` timestamp NULL DEFAULT NULL COMMENT '看完时间', + `created_at` timestamp NULL DEFAULT NULL, + `updated_at` timestamp NULL DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `u_h_c_id` (`user_id`,`hour_id`,`course_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "user_course_records"); + put("name", "20230406_16_51_17_1111_user_course_records"); + put( + "sql", + """ + CREATE TABLE `user_course_records` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `user_id` int(11) NOT NULL DEFAULT '0', + `course_id` int(11) NOT NULL DEFAULT '0', + `hour_count` int(11) NOT NULL DEFAULT '0' COMMENT '课时数量', + `finished_count` int(11) NOT NULL DEFAULT '0' COMMENT '已完成课时数', + `progress` int(11) NOT NULL DEFAULT '0' COMMENT '进度', + `is_finished` tinyint(4) NOT NULL DEFAULT '0' COMMENT '看完[1:是,0:否]', + `finished_at` timestamp NULL DEFAULT NULL COMMENT '看完时间', + `created_at` timestamp NULL DEFAULT NULL, + `updated_at` timestamp NULL DEFAULT NULL, + PRIMARY KEY (`id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "user_department"); + put("name", "20230406_16_51_17_1111_user_department"); + put( + "sql", + """ + CREATE TABLE `user_department` ( + `user_id` int(11) unsigned NOT NULL DEFAULT '0', + `dep_id` int(11) unsigned NOT NULL DEFAULT '0', + KEY `user_id` (`user_id`), + KEY `dep_id` (`dep_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "user_learn_duration_records"); + put( + "name", + "20230406_16_51_17_1111_user_learn_duration_records"); + put( + "sql", + """ + CREATE TABLE `user_learn_duration_records` ( + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, + `user_id` int(11) NOT NULL DEFAULT '0', + `created_date` date NOT NULL, + `duration` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '已学习时长[微秒]', + `start_at` timestamp NULL DEFAULT NULL COMMENT '开始时间', + `end_at` timestamp NULL DEFAULT NULL COMMENT '结束时间', + `course_id` int(11) NOT NULL DEFAULT '0', + `hour_id` int(11) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`), + KEY `u_d` (`user_id`,`created_date`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "user_learn_duration_stats"); + put("name", "20230406_16_51_17_1111_user_learn_duration_stats"); + put( + "sql", + """ + CREATE TABLE `user_learn_duration_stats` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `user_id` int(11) NOT NULL DEFAULT '0', + `duration` bigint(20) NOT NULL DEFAULT '0', + `created_date` date NOT NULL, + PRIMARY KEY (`id`), + KEY `u_d` (`user_id`,`created_date`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "user_login_records"); + put("name", "20230406_16_51_17_1111_user_login_records"); + put( + "sql", + """ + CREATE TABLE `user_login_records` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `user_id` int(11) NOT NULL, + `jti` varchar(64) NOT NULL DEFAULT '' COMMENT 'JTI', + `ip` varchar(15) NOT NULL DEFAULT '' COMMENT '登录ip', + `ip_area` varchar(64) NOT NULL DEFAULT '' COMMENT 'Ip解析区域', + `browser` varchar(64) NOT NULL DEFAULT '' COMMENT '浏览器', + `browser_version` varchar(64) NOT NULL DEFAULT '' COMMENT '浏览器版本', + `os` varchar(128) NOT NULL DEFAULT '' COMMENT '操作系统', + `expired` bigint(20) NOT NULL DEFAULT '0' COMMENT '过期时间', + `is_logout` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否注销', + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + PRIMARY KEY (`id`), + UNIQUE KEY `jti` (`jti`), + KEY `user_id` (`user_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "user_upload_image_logs"); + put("name", "20230406_16_51_17_1111_user_upload_image_logs"); + put( + "sql", + """ + CREATE TABLE `user_upload_image_logs` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `user_id` int(11) NOT NULL DEFAULT '0', + `typed` varchar(32) NOT NULL DEFAULT '' COMMENT '图片类型', + `scene` varchar(24) NOT NULL DEFAULT '' COMMENT '上传场景', + `driver` varchar(32) NOT NULL DEFAULT '' COMMENT '驱动', + `path` varchar(255) NOT NULL DEFAULT '' COMMENT '相对路径', + `url` varchar(255) NOT NULL DEFAULT '' COMMENT '访问地址', + `size` bigint(20) NOT NULL COMMENT '大小,单位:字节', + `name` varchar(255) NOT NULL DEFAULT '' COMMENT '文件名', + `created_at` timestamp NULL DEFAULT NULL, + PRIMARY KEY (`id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "users"); + put("name", "20230406_16_51_17_1111_users"); + put( + "sql", + """ + CREATE TABLE `users` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `email` varchar(32) NOT NULL DEFAULT '' COMMENT '邮件', + `name` varchar(24) NOT NULL DEFAULT '' COMMENT '真实姓名', + `avatar` varchar(255) NOT NULL DEFAULT '' COMMENT '头像', + `password` varchar(128) NOT NULL DEFAULT '' COMMENT '密码', + `salt` varchar(12) NOT NULL DEFAULT '' COMMENT 'salt', + `id_card` varchar(64) NOT NULL DEFAULT '' COMMENT '身份证号', + `credit1` int(11) NOT NULL DEFAULT '0' COMMENT '学分', + `create_ip` varchar(15) NOT NULL DEFAULT '' COMMENT '注册Ip', + `create_city` varchar(32) NOT NULL DEFAULT '' COMMENT '注册城市', + `is_active` tinyint(4) NOT NULL DEFAULT '0' COMMENT '激活[1:是,0:否]', + `is_lock` tinyint(4) NOT NULL DEFAULT '0' COMMENT '锁定[1:是,0:否]', + `is_verify` tinyint(4) NOT NULL DEFAULT '0' COMMENT '实名认证[1:是,0:否]', + `verify_at` timestamp NULL DEFAULT NULL COMMENT '实名认证时间', + `is_set_password` tinyint(4) NOT NULL DEFAULT '0' COMMENT '设置密码[1:是,0:否]', + `login_at` timestamp NULL DEFAULT NULL COMMENT '登录时间', + `created_at` timestamp NULL DEFAULT NULL, + `updated_at` timestamp NULL DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `email` (`email`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "admin_logs"); + put("name", "20230406_16_51_17_1111_admin_logs"); + put( + "sql", + """ + CREATE TABLE IF NOT EXISTS `admin_logs` + ( + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, + `admin_id` int(11) NOT NULL DEFAULT '0' COMMENT '管理员ID', + `admin_name` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '管理员姓名', + `module` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '模块', + `title` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '请求方法标题', + `opt` int(2) NOT NULL DEFAULT '0' COMMENT '操作指令(0其它 1新增 2修改 3删除 4登录 5退出登录)', + `method` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '请求方法', + `request_method` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '请求方式POST,GET,PUT,DELETE', + `url` varchar(266) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '请求URL', + `param` mediumtext COLLATE utf8mb4_unicode_ci COMMENT '请求参数', + `result` mediumtext COLLATE utf8mb4_unicode_ci COMMENT '返回参数', + `ip` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'ip', + `ip_area` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '地址', + `error_msg` mediumtext COLLATE utf8mb4_unicode_ci COMMENT '错误消息', + `created_at` timestamp NULL DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `a_m_o` (`admin_id`,`module`,`opt`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "course_attachment"); + put("name", "20230406_16_51_17_1111_course_attachment"); + put( + "sql", + """ + CREATE TABLE `course_attachment` + ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `course_id` int(11) NOT NULL DEFAULT '0' COMMENT '课程ID', + `sort` int(11) NOT NULL DEFAULT '0' COMMENT '升序', + `title` varchar(255) NOT NULL DEFAULT '' COMMENT '附件名', + `type` varchar(20) NOT NULL DEFAULT '' COMMENT '附件类型', + `rid` int(11) NOT NULL DEFAULT '0' COMMENT '资源id', + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + KEY `course_id` (`course_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """); + } + }); + add( + new HashMap<>() { + { + put("table", "course_attachment_download_log"); + put( + "name", + "20230406_16_51_17_1111_course_attachment_download_log"); + put( + "sql", + """ + CREATE TABLE `course_attachment_download_log` + ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `user_id` int(11) NOT NULL DEFAULT '0' COMMENT '学员ID', + `course_id` int(11) NOT NULL DEFAULT '0' COMMENT '课程ID', + `title` varchar(255) NOT NULL DEFAULT '' COMMENT '课程标题', + `courser_attachment_id` int(11) NOT NULL DEFAULT '0' COMMENT '课程附件id', + `rid` int(11) NOT NULL DEFAULT '0' COMMENT '资源id', + `ip` varchar(45) NOT NULL DEFAULT '' COMMENT '下载ip', + `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """); + } + }); + } + }; + + @Autowired private JdbcTemplate jdbcTemplate; + + @Autowired private MigrationService migrationService; + + @Override + public void run(String... args) throws Exception { + try { + // 数据库已创建的表 + List tables = jdbcTemplate.queryForList("show tables", String.class); + // 已创建表的记录 + List migrations = new ArrayList<>(); + if (tables.contains("migrations")) { + migrations = migrationService.all(); + } + + for (Map tableItem : TABLE_SQL) { + String tableName = tableItem.get("table"); + String migrationName = tableItem.get("name"); + if (migrations.contains(migrationName)) { + continue; + } + + if (tables.contains(tableName)) { + // 数据表已创建但是没有创建记录 + // 需要保存创建记录 + migrationService.store(migrationName); + continue; + } + + // 创建数据表 + jdbcTemplate.execute(tableItem.get("sql")); + // 记录写入到migrations表中 + migrationService.store(migrationName); + } + + } catch (Exception e) { + log.error("数据库迁移执行失败,错误信息:" + e.getMessage()); + } + } +} diff --git a/playedu-system/src/main/java/xyz/playedu/system/checks/AdminRoleCheck.java b/playedu-system/src/main/java/xyz/playedu/system/checks/SystemDataCheck.java similarity index 54% rename from playedu-system/src/main/java/xyz/playedu/system/checks/AdminRoleCheck.java rename to playedu-system/src/main/java/xyz/playedu/system/checks/SystemDataCheck.java index 9257f55..8102722 100644 --- a/playedu-system/src/main/java/xyz/playedu/system/checks/AdminRoleCheck.java +++ b/playedu-system/src/main/java/xyz/playedu/system/checks/SystemDataCheck.java @@ -15,40 +15,43 @@ */ package xyz.playedu.system.checks; +import lombok.extern.slf4j.Slf4j; + import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.ApplicationArguments; -import org.springframework.boot.ApplicationRunner; +import org.springframework.boot.CommandLineRunner; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; import xyz.playedu.common.constant.BackendConstant; import xyz.playedu.common.domain.AdminRole; import xyz.playedu.common.service.AdminRoleService; +import xyz.playedu.common.service.AdminUserService; -import java.util.Date; - -@Order(1010) @Component -public class AdminRoleCheck implements ApplicationRunner { +@Slf4j +@Order(12) +public class SystemDataCheck implements CommandLineRunner { @Autowired private AdminRoleService adminRoleService; - private static final AdminRole superRole = - new AdminRole() { - { - setName("超级管理员"); - setSlug(BackendConstant.SUPER_ADMIN_ROLE); - setCreatedAt(new Date()); - setCreatedAt(new Date()); - } - }; + @Autowired private AdminUserService adminUserService; @Override - public void run(ApplicationArguments args) throws Exception { - AdminRole adminRole = adminRoleService.getBySlug(BackendConstant.SUPER_ADMIN_ROLE); - if (adminRole != null) { // 已存在超级管理权限 - return; + public void run(String... args) throws Exception { + adminInit(); + } + + private void adminInit() { + try { + AdminRole superRole = adminRoleService.getBySlug(BackendConstant.SUPER_ADMIN_ROLE); + if (superRole != null) { + return; + } + Integer roleId = adminRoleService.initSuperAdminRole(); + adminUserService.createWithRoleIds( + "超级管理员", "admin@playedu.xyz", "playedu", 0, new Integer[] {roleId}); + } catch (Exception e) { + log.error("超级管理员初始化失败,错误信息:{}", e.getMessage()); } - adminRoleService.save(superRole); } } diff --git a/playedu-system/src/main/java/xyz/playedu/system/checks/UpgradeCheck.java b/playedu-system/src/main/java/xyz/playedu/system/checks/UpgradeCheck.java index 6812728..678b334 100644 --- a/playedu-system/src/main/java/xyz/playedu/system/checks/UpgradeCheck.java +++ b/playedu-system/src/main/java/xyz/playedu/system/checks/UpgradeCheck.java @@ -16,8 +16,7 @@ package xyz.playedu.system.checks; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.ApplicationArguments; -import org.springframework.boot.ApplicationRunner; +import org.springframework.boot.CommandLineRunner; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; @@ -29,14 +28,14 @@ import java.util.ArrayList; @Order(10000) @Component -public class UpgradeCheck implements ApplicationRunner { +public class UpgradeCheck implements CommandLineRunner { @Autowired private AppConfigService appConfigService; @Autowired private AdminPermissionService permissionService; @Override - public void run(ApplicationArguments args) throws Exception { + public void run(String... args) throws Exception { upgrade_v1_beta7(); } diff --git a/playedu-system/src/main/java/xyz/playedu/system/domain/Migration.java b/playedu-system/src/main/java/xyz/playedu/system/domain/Migration.java new file mode 100644 index 0000000..eb14238 --- /dev/null +++ b/playedu-system/src/main/java/xyz/playedu/system/domain/Migration.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2023 杭州白书科技有限公司 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package xyz.playedu.system.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; + +import java.io.Serializable; + +/** + * @TableName migrations + */ +@TableName(value = "migrations") +public class Migration implements Serializable { + /** */ + @TableId(type = IdType.AUTO) + private Integer id; + + /** */ + private String migration; + + @TableField(exist = false) + private static final long serialVersionUID = 1L; + + /** */ + public Integer getId() { + return id; + } + + /** */ + public void setId(Integer id) { + this.id = id; + } + + /** */ + public String getMigration() { + return migration; + } + + /** */ + public void setMigration(String migration) { + this.migration = migration; + } + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + if (that == null) { + return false; + } + if (getClass() != that.getClass()) { + return false; + } + Migration other = (Migration) that; + return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) + && (this.getMigration() == null + ? other.getMigration() == null + : this.getMigration().equals(other.getMigration())); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); + result = prime * result + ((getMigration() == null) ? 0 : getMigration().hashCode()); + return result; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", id=").append(id); + sb.append(", migration=").append(migration); + sb.append(", serialVersionUID=").append(serialVersionUID); + sb.append("]"); + return sb.toString(); + } +} diff --git a/playedu-system/src/main/java/xyz/playedu/system/mapper/MigrationMapper.java b/playedu-system/src/main/java/xyz/playedu/system/mapper/MigrationMapper.java new file mode 100644 index 0000000..d9966d6 --- /dev/null +++ b/playedu-system/src/main/java/xyz/playedu/system/mapper/MigrationMapper.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2023 杭州白书科技有限公司 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package xyz.playedu.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +import xyz.playedu.system.domain.Migration; + +/** + * @author tengyongzhi + * @description 针对表【migrations】的数据库操作Mapper + * @createDate 2023-08-27 12:40:00 @Entity xyz.playedu.system.domain.Migration + */ +public interface MigrationMapper extends BaseMapper {} diff --git a/playedu-system/src/main/java/xyz/playedu/system/service/MigrationService.java b/playedu-system/src/main/java/xyz/playedu/system/service/MigrationService.java new file mode 100644 index 0000000..dbc4e7c --- /dev/null +++ b/playedu-system/src/main/java/xyz/playedu/system/service/MigrationService.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2023 杭州白书科技有限公司 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package xyz.playedu.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; + +import xyz.playedu.system.domain.Migration; + +import java.util.List; + +/** + * @author tengyongzhi + * @description 针对表【migrations】的数据库操作Service + * @createDate 2023-08-27 12:40:00 + */ +public interface MigrationService extends IService { + List all(); + + void store(String name); +} diff --git a/playedu-system/src/main/java/xyz/playedu/system/service/impl/MigrationServiceImpl.java b/playedu-system/src/main/java/xyz/playedu/system/service/impl/MigrationServiceImpl.java new file mode 100644 index 0000000..ec34fcb --- /dev/null +++ b/playedu-system/src/main/java/xyz/playedu/system/service/impl/MigrationServiceImpl.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2023 杭州白书科技有限公司 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package xyz.playedu.system.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; + +import org.springframework.stereotype.Service; + +import xyz.playedu.system.domain.Migration; +import xyz.playedu.system.mapper.MigrationMapper; +import xyz.playedu.system.service.MigrationService; + +import java.util.List; + +/** + * @author tengyongzhi + * @description 针对表【migrations】的数据库操作Service实现 + * @createDate 2023-08-27 12:40:00 + */ +@Service +public class MigrationServiceImpl extends ServiceImpl + implements MigrationService { + @Override + public List all() { + return list().stream().map(Migration::getMigration).toList(); + } + + @Override + public void store(String name) { + Migration migration = new Migration(); + migration.setMigration(name); + save(migration); + } +} diff --git a/playedu-system/src/main/resources/mapper/MigrationMapper.xml b/playedu-system/src/main/resources/mapper/MigrationMapper.xml new file mode 100644 index 0000000..9e185a9 --- /dev/null +++ b/playedu-system/src/main/resources/mapper/MigrationMapper.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + id,migration + +