浏览代码

添加对数据库定时自动备份的支持

liyan 3 年之前
父节点
当前提交
57e9c858dd

+ 1 - 0
apps/svs-all-in-one/build.gradle.kts

@@ -39,6 +39,7 @@ dependencies {
     implementation("com.belerweb:pinyin4j:2.5.1")
     implementation(project(path = ":services:service-system", configuration = "lib"))
     implementation(project(path = ":services:service-task", configuration = "lib"))
+    implementation(project(path = ":services:service-schedule", configuration = "lib"))
     implementation(project(path = ":shared", configuration = "lib"))
     implementation("com.squareup.okhttp3:okhttp:4.10.0-RC1")
     implementation("com.github.oshi:oshi-core:6.1.4")

+ 1 - 1
apps/svs-init/src/main/resources/sql/mysql/data.sql

@@ -5,4 +5,4 @@ values
     ('00000000-0000-0000-0000-000000000001', '0', 'admin', '系统管理员', '1', 1),
     ('00000000-0000-0000-0000-000000000002', '0', 'audit', '安全审计员', '1', 2),
     ('00000000-0000-0000-0000-000000000003', '0', 'secadm', '安全管理员', '1', 3) $$
-
+insert into SVS_SCHEDULE_TASK ( TASK_ID, TASK_CLASS_NAME, CRON_EXPRESSION, STATUS, CREATED_AT, UPDATED_AT) values ('DBBACKUP', 'llh.svs.core.services.sys.support.DBBackupScheduleTask', '0 0 0 1 * ?', '1', now(), now()) $$

+ 14 - 13
services/build.gradle.kts

@@ -91,26 +91,27 @@ project("service-system") {
     dependencies {
         implementation("com.github.oshi:oshi-core:6.1.4")
         implementation(project(path = ":services:service-task", configuration = "lib"))
+        implementation(project(path = ":services:service-schedule", configuration = "lib"))
     }
 }
 
 
 tasks.jar {
     archiveBaseName.set("svs-core-${project.name}")
-//    configure {
-    from(tasks.withType<JavaCompile>())
-    from(tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>())
-    include("llh/**")
-    exclude {
-        it.name.endsWith("Application.class")
-    }
-    exclude {
-        it.name.endsWith("ApplicationKt.class")
-    }
-    exclude {
-        it.name.endsWith("Application${'$'}Companion.class")
+    configure(subprojects) {
+        from(tasks.withType<JavaCompile>())
+        from(tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>())
+        include("llh/**")
+        exclude {
+            it.name.endsWith("Application.class")
+        }
+        exclude {
+            it.name.endsWith("ApplicationKt.class")
+        }
+        exclude {
+            it.name.endsWith("Application${'$'}Companion.class")
+        }
     }
-//    }
 }
 publishing {
     publications {

+ 20 - 0
services/service-system/src/main/kotlin/llh/svs/core/services/sys/support/DBBackupScheduleTask.kt

@@ -0,0 +1,20 @@
+package llh.svs.core.services.sys.support
+
+import llh.svs.core.services.schedule.support.ScheduledTask
+import llh.svs.core.services.sys.service.DBBackupService
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.stereotype.Component
+
+/**
+ * 数据库自动备份
+ */
+@Component
+class DBBackupScheduleTask : ScheduledTask {
+
+    @Autowired
+    lateinit var service: DBBackupService
+
+    override fun execute() {
+        service.backupDatabase(file = null)
+    }
+}

+ 0 - 11
src/main/kotlin/com/llh/svscore/SvsCoreApplication.kt

@@ -1,11 +0,0 @@
-package com.llh.svscore
-
-import org.springframework.boot.autoconfigure.SpringBootApplication
-import org.springframework.boot.runApplication
-
-@SpringBootApplication
-class SvsCoreApplication
-
-fun main(args: Array<String>) {
-    runApplication<SvsCoreApplication>(*args)
-}

+ 0 - 1
src/main/resources/application.properties

@@ -1 +0,0 @@
-

+ 0 - 13
src/test/kotlin/com/llh/svscore/SvsCoreApplicationTests.kt

@@ -1,13 +0,0 @@
-package com.llh.svscore
-
-import org.junit.jupiter.api.Test
-import org.springframework.boot.test.context.SpringBootTest
-
-@SpringBootTest
-class SvsCoreApplicationTests {
-
-    @Test
-    fun contextLoads() {
-    }
-
-}