Explorar o código

增加SystemInitializeEvent

zhou-hao %!s(int64=6) %!d(string=hai) anos
pai
achega
c39f124627

+ 11 - 0
hsweb-starter/hsweb-spring-boot-starter/src/main/java/org/hswebframework/web/starter/SystemInitializeAutoConfiguration.java

@@ -30,6 +30,7 @@ import org.hswebframework.web.ScriptScope;
 import org.hswebframework.web.datasource.DataSourceHolder;
 import org.hswebframework.web.datasource.DatabaseType;
 import org.hswebframework.web.service.Service;
+import org.hswebframework.web.starter.event.SystemInitializeEvent;
 import org.hswebframework.web.starter.init.SystemInitialize;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -37,6 +38,7 @@ import org.springframework.beans.factory.config.BeanPostProcessor;
 import org.springframework.boot.CommandLineRunner;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationEventPublisher;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.core.Ordered;
 import org.springframework.core.annotation.AnnotationUtils;
@@ -75,6 +77,9 @@ public class SystemInitializeAutoConfiguration implements CommandLineRunner, Bea
     @Autowired
     private ApplicationContext applicationContext;
 
+    @Autowired
+    private ApplicationEventPublisher eventPublisher;
+
     private List<DynamicScriptEngine> engines;
 
     @Autowired
@@ -158,6 +163,12 @@ public class SystemInitializeAutoConfiguration implements CommandLineRunner, Bea
 
         SimpleDatabase database = new SimpleDatabase(metaData, sqlExecutor);
         database.setAutoParse(true);
+
+        SystemInitializeEvent event = new SystemInitializeEvent(database);
+        eventPublisher.publishEvent(event);
+        if (event.isIgnore()) {
+            return;
+        }
         SystemInitialize initialize = new SystemInitialize(sqlExecutor, database, version);
 
         initialize.addScriptContext("db", jdbcUserName);

+ 21 - 0
hsweb-starter/hsweb-spring-boot-starter/src/main/java/org/hswebframework/web/starter/event/SystemInitializeEvent.java

@@ -0,0 +1,21 @@
+package org.hswebframework.web.starter.event;
+
+import lombok.Getter;
+import org.hswebframework.ezorm.rdb.RDBDatabase;
+
+@Getter
+public class SystemInitializeEvent {
+
+    public SystemInitializeEvent(RDBDatabase database){
+        this.database=database;
+    }
+
+    private RDBDatabase database;
+
+    private boolean ignore;
+
+    public void setIgnore(boolean ignore) {
+        this.ignore = ignore;
+    }
+
+}