【7.0.4】【demo】增加延时生效

pull/22/head
fengshuonan 2021-07-13 18:39:41 +08:00
parent 6721293ba8
commit f6d58d538e
3 changed files with 16 additions and 8 deletions

View File

@ -18,11 +18,6 @@ public class StartCalcUtil {
*/
public static Date startDate = null;
/**
*
*/
public static final long startInterValSeconds = 20;
/**
*
*
@ -39,7 +34,7 @@ public class StartCalcUtil {
* @author fengshuonan
* @date 2021/7/13 17:43
*/
public static boolean calcEnable(Date date) {
public static boolean calcEnable(Date date, long startInterValSeconds) {
return DateUtil.between(startDate, date, DateUnit.SECOND) > startInterValSeconds;
}

View File

@ -54,6 +54,15 @@ import java.util.Date;
@Intercepts({@Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class})})
public class DemoProfileSqlInterceptor implements Interceptor {
/**
*
*/
private final int projectStartInterval;
public DemoProfileSqlInterceptor(int projectStartInterval) {
this.projectStartInterval = projectStartInterval;
}
@Override
public Object intercept(Invocation invocation) throws Throwable {
@ -63,7 +72,7 @@ public class DemoProfileSqlInterceptor implements Interceptor {
}
// 如果是演示环境并且项目还没起来则直接放过sql
if (DemoConfigExpander.getDemoEnvFlag() && !StartCalcUtil.calcEnable(new Date())) {
if (DemoConfigExpander.getDemoEnvFlag() && !StartCalcUtil.calcEnable(new Date(), projectStartInterval)) {
return invocation.proceed();
}

View File

@ -26,6 +26,7 @@ package cn.stylefeng.roses.kernel.demo.starter;
import cn.stylefeng.roses.kernel.demo.interceptor.DemoProfileSqlInterceptor;
import cn.stylefeng.roses.kernel.demo.util.StartCalcUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -40,6 +41,9 @@ import java.util.Date;
@Configuration
public class GunsDemoAutoConfiguration {
@Value("${project.start.interval:20}")
private Integer projectStartInterval;
/**
* sql
*
@ -49,7 +53,7 @@ public class GunsDemoAutoConfiguration {
@Bean
public DemoProfileSqlInterceptor demoProfileSqlInterceptor() {
StartCalcUtil.init(new Date());
return new DemoProfileSqlInterceptor();
return new DemoProfileSqlInterceptor(projectStartInterval);
}
}