mirror of https://gitee.com/stylefeng/roses
【7.0.4】【demo】增加延时生效
parent
6721293ba8
commit
f6d58d538e
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue