REQ-2135: 动态配置sql输出

This commit is contained in:
yanglin 2024-04-09 18:21:50 +08:00
parent 0035cecf9f
commit 5d1323281c
3 changed files with 10 additions and 27 deletions

View File

@ -94,6 +94,12 @@ public class PendingMessageBizConfig {
@Getter
private int expungeTodoLogSinceDaysAgo = 180;
@Getter
private boolean logExecSQL;
@Getter
private boolean formatExecSQL;
public boolean hasMessageDetailStyle(String code) {
return name2DetailStyle != null && name2DetailStyle.containsKey(code);
}

View File

@ -1,5 +1,6 @@
package cn.axzo.msg.center.message.service.todo.mybatis;
import cn.axzo.msg.center.inside.notices.config.PendingMessageBizConfig;
import com.alibaba.druid.sql.SQLUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -22,16 +23,16 @@ import java.sql.Statement;
@RequiredArgsConstructor
class LogExecSQLInterceptor implements Interceptor {
private final MyBatisProperties props;
private final PendingMessageBizConfig cfg;
@Override
public Object intercept(Invocation invocation) throws Throwable {
Object proceed = invocation.proceed();
if (props.isLogExecSQL()) {
if (cfg.isLogExecSQL()) {
String sql = SQLAccessor.getSQL(invocation);
if (StringUtils.isNotBlank(sql)) {
sql = sql.replaceAll("[\r\n]", " ");
if (props.isFormatSQL())
if (cfg.isFormatExecSQL())
log.info("\n{}", SQLUtils.formatMySql(sql));
else
log.info("{}", sql);

View File

@ -1,24 +0,0 @@
package cn.axzo.msg.center.message.service.todo.mybatis;
import com.alibaba.fastjson.JSON;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;
/**
* @author yanglin
*/
@Data
@RefreshScope
@Configuration
@ConfigurationProperties(prefix = "mybatis-plus.configuration")
public class MyBatisProperties {
private boolean logExecSQL;
private boolean formatSQL;
@Override
public String toString() {
return JSON.toJSONString(this);
}
}