mirror of https://gitee.com/stylefeng/roses
【7.0.4】【demo】增加延时生效
parent
9424dca6c3
commit
6721293ba8
|
@ -0,0 +1,46 @@
|
||||||
|
package cn.stylefeng.roses.kernel.demo.util;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUnit;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开始时间的计时工具
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2021/7/13 17:34
|
||||||
|
*/
|
||||||
|
public class StartCalcUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 项目开始启动时间
|
||||||
|
*/
|
||||||
|
public static Date startDate = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 项目启动时间预估
|
||||||
|
*/
|
||||||
|
public static final long startInterValSeconds = 20;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化项目开始时间
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2021/7/13 17:42
|
||||||
|
*/
|
||||||
|
public static void init(Date date) {
|
||||||
|
startDate = date;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算是否项目已经启动
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2021/7/13 17:43
|
||||||
|
*/
|
||||||
|
public static boolean calcEnable(Date date) {
|
||||||
|
return DateUtil.between(startDate, date, DateUnit.SECOND) > startInterValSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -28,6 +28,7 @@ import cn.stylefeng.roses.kernel.auth.api.expander.AuthConfigExpander;
|
||||||
import cn.stylefeng.roses.kernel.demo.exception.DemoException;
|
import cn.stylefeng.roses.kernel.demo.exception.DemoException;
|
||||||
import cn.stylefeng.roses.kernel.demo.exception.enums.DemoExceptionEnum;
|
import cn.stylefeng.roses.kernel.demo.exception.enums.DemoExceptionEnum;
|
||||||
import cn.stylefeng.roses.kernel.demo.expander.DemoConfigExpander;
|
import cn.stylefeng.roses.kernel.demo.expander.DemoConfigExpander;
|
||||||
|
import cn.stylefeng.roses.kernel.demo.util.StartCalcUtil;
|
||||||
import cn.stylefeng.roses.kernel.rule.util.HttpServletUtil;
|
import cn.stylefeng.roses.kernel.rule.util.HttpServletUtil;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.PluginUtils;
|
import com.baomidou.mybatisplus.core.toolkit.PluginUtils;
|
||||||
import org.apache.ibatis.executor.statement.StatementHandler;
|
import org.apache.ibatis.executor.statement.StatementHandler;
|
||||||
|
@ -42,6 +43,7 @@ import org.apache.ibatis.reflection.SystemMetaObject;
|
||||||
import org.springframework.util.AntPathMatcher;
|
import org.springframework.util.AntPathMatcher;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 演示环境的sql过滤器,只放开select语句,其他语句都不放过
|
* 演示环境的sql过滤器,只放开select语句,其他语句都不放过
|
||||||
|
@ -60,6 +62,11 @@ public class DemoProfileSqlInterceptor implements Interceptor {
|
||||||
return invocation.proceed();
|
return invocation.proceed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果是演示环境,并且项目还没起来,则直接放过sql
|
||||||
|
if (DemoConfigExpander.getDemoEnvFlag() && !StartCalcUtil.calcEnable(new Date())) {
|
||||||
|
return invocation.proceed();
|
||||||
|
}
|
||||||
|
|
||||||
StatementHandler statementHandler = PluginUtils.realTarget(invocation.getTarget());
|
StatementHandler statementHandler = PluginUtils.realTarget(invocation.getTarget());
|
||||||
MetaObject metaStatementHandler = SystemMetaObject.forObject(statementHandler);
|
MetaObject metaStatementHandler = SystemMetaObject.forObject(statementHandler);
|
||||||
MappedStatement mappedStatement = (MappedStatement) metaStatementHandler.getValue("delegate.mappedStatement");
|
MappedStatement mappedStatement = (MappedStatement) metaStatementHandler.getValue("delegate.mappedStatement");
|
||||||
|
|
|
@ -25,11 +25,12 @@
|
||||||
package cn.stylefeng.roses.kernel.demo.starter;
|
package cn.stylefeng.roses.kernel.demo.starter;
|
||||||
|
|
||||||
import cn.stylefeng.roses.kernel.demo.interceptor.DemoProfileSqlInterceptor;
|
import cn.stylefeng.roses.kernel.demo.interceptor.DemoProfileSqlInterceptor;
|
||||||
import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
|
import cn.stylefeng.roses.kernel.demo.util.StartCalcUtil;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 演示环境的自动配置
|
* 演示环境的自动配置
|
||||||
*
|
*
|
||||||
|
@ -37,7 +38,6 @@ import org.springframework.context.annotation.Configuration;
|
||||||
* @date 2020/12/1 21:51
|
* @date 2020/12/1 21:51
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@AutoConfigureAfter(MybatisPlusAutoConfiguration.class)
|
|
||||||
public class GunsDemoAutoConfiguration {
|
public class GunsDemoAutoConfiguration {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,6 +48,7 @@ public class GunsDemoAutoConfiguration {
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public DemoProfileSqlInterceptor demoProfileSqlInterceptor() {
|
public DemoProfileSqlInterceptor demoProfileSqlInterceptor() {
|
||||||
|
StartCalcUtil.init(new Date());
|
||||||
return new DemoProfileSqlInterceptor();
|
return new DemoProfileSqlInterceptor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue