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

pull/22/head
fengshuonan 2021-07-13 17:50:10 +08:00
parent 9424dca6c3
commit 6721293ba8
3 changed files with 57 additions and 3 deletions

View File

@ -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;
}
}

View File

@ -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;
/** /**
* sqlselect * sqlselect
@ -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");

View File

@ -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();
} }