1. 初始化
This commit is contained in:
parent
a5945b24e1
commit
72c4a0374c
|
|
@ -19,6 +19,7 @@ import com.baomidou.mybatisplus.annotation.FieldStrategy;
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||||
|
import com.baomidou.mybatisplus.core.handlers.PostInitTableInfoHandler;
|
||||||
import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator;
|
import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator;
|
||||||
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
|
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
|
||||||
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
|
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
|
||||||
|
|
@ -77,6 +78,11 @@ public class GlobalConfig implements Serializable {
|
||||||
* 元对象字段填充控制器
|
* 元对象字段填充控制器
|
||||||
*/
|
*/
|
||||||
private MetaObjectHandler metaObjectHandler;
|
private MetaObjectHandler metaObjectHandler;
|
||||||
|
/**
|
||||||
|
* 参与 TableInfo 的初始化
|
||||||
|
*/
|
||||||
|
private PostInitTableInfoHandler postInitTableInfoHandler = new PostInitTableInfoHandler() {
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
* 主键生成器
|
* 主键生成器
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -58,8 +58,6 @@ import java.util.stream.Collectors;
|
||||||
*
|
*
|
||||||
* @author hubin
|
* @author hubin
|
||||||
* @since 3.4.0
|
* @since 3.4.0
|
||||||
*
|
|
||||||
* 修改无法使用原生sql 的 warn 打印
|
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
|
@ -69,7 +67,7 @@ public class PaginationInnerInterceptor implements InnerInterceptor {
|
||||||
* 获取jsqlparser中count的SelectItem
|
* 获取jsqlparser中count的SelectItem
|
||||||
*/
|
*/
|
||||||
protected static final List<SelectItem> COUNT_SELECT_ITEM = Collections.singletonList(
|
protected static final List<SelectItem> COUNT_SELECT_ITEM = Collections.singletonList(
|
||||||
new SelectExpressionItem(new Column().withColumnName("COUNT(*)")).withAlias(new Alias("total"))
|
new SelectExpressionItem(new Column().withColumnName("COUNT(*)")).withAlias(new Alias("total"))
|
||||||
);
|
);
|
||||||
protected static final Map<String, MappedStatement> countMsCache = new ConcurrentHashMap<>();
|
protected static final Map<String, MappedStatement> countMsCache = new ConcurrentHashMap<>();
|
||||||
protected final Log logger = LogFactory.getLog(this.getClass());
|
protected final Log logger = LogFactory.getLog(this.getClass());
|
||||||
|
|
@ -333,13 +331,22 @@ public class PaginationInnerInterceptor implements InnerInterceptor {
|
||||||
}
|
}
|
||||||
// 不区分大小写
|
// 不区分大小写
|
||||||
str = str.toLowerCase();
|
str = str.toLowerCase();
|
||||||
String onExpressionS = join.getOnExpression().toString();
|
|
||||||
/* 如果 join 里包含 ?(代表有入参) 或者 where 条件里包含使用 join 的表的字段作条件,就不移除 join */
|
if (whereS.contains(str)) {
|
||||||
if (onExpressionS.contains(StringPool.QUESTION_MARK) || whereS.contains(str)) {
|
/* 如果 where 条件里包含使用 join 的表的字段作条件,就不移除 join */
|
||||||
canRemoveJoin = false;
|
canRemoveJoin = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (Expression expression : join.getOnExpressions()) {
|
||||||
|
if (expression.toString().contains(StringPool.QUESTION_MARK)) {
|
||||||
|
/* 如果 join 里包含 ?(代表有入参) 就不移除 join */
|
||||||
|
canRemoveJoin = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canRemoveJoin) {
|
if (canRemoveJoin) {
|
||||||
plainSelect.setJoins(null);
|
plainSelect.setJoins(null);
|
||||||
}
|
}
|
||||||
|
|
@ -350,7 +357,7 @@ public class PaginationInnerInterceptor implements InnerInterceptor {
|
||||||
return select.toString();
|
return select.toString();
|
||||||
} catch (JSQLParserException e) {
|
} catch (JSQLParserException e) {
|
||||||
// 无法优化使用原 SQL
|
// 无法优化使用原 SQL
|
||||||
logger.warn("无法优化使用原生sql");
|
logger.warn("optimize this sql to a count sql has exception, sql:\"" + sql + "\", exception:\n" + e.getCause());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.warn("optimize this sql to a count sql has error, sql:\"" + sql + "\", exception:\n" + e);
|
logger.warn("optimize this sql to a count sql has error, sql:\"" + sql + "\", exception:\n" + e);
|
||||||
}
|
}
|
||||||
|
|
@ -405,14 +412,14 @@ public class PaginationInnerInterceptor implements InnerInterceptor {
|
||||||
|
|
||||||
protected List<OrderByElement> addOrderByElements(List<OrderItem> orderList, List<OrderByElement> orderByElements) {
|
protected List<OrderByElement> addOrderByElements(List<OrderItem> orderList, List<OrderByElement> orderByElements) {
|
||||||
List<OrderByElement> additionalOrderBy = orderList.stream()
|
List<OrderByElement> additionalOrderBy = orderList.stream()
|
||||||
.filter(item -> StringUtils.isNotBlank(item.getColumn()))
|
.filter(item -> StringUtils.isNotBlank(item.getColumn()))
|
||||||
.map(item -> {
|
.map(item -> {
|
||||||
OrderByElement element = new OrderByElement();
|
OrderByElement element = new OrderByElement();
|
||||||
element.setExpression(new Column(item.getColumn()));
|
element.setExpression(new Column(item.getColumn()));
|
||||||
element.setAsc(item.isAsc());
|
element.setAsc(item.isAsc());
|
||||||
element.setAscDescPresent(true);
|
element.setAscDescPresent(true);
|
||||||
return element;
|
return element;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
if (CollectionUtils.isEmpty(orderByElements)) {
|
if (CollectionUtils.isEmpty(orderByElements)) {
|
||||||
return additionalOrderBy;
|
return additionalOrderBy;
|
||||||
}
|
}
|
||||||
|
|
@ -467,10 +474,10 @@ public class PaginationInnerInterceptor implements InnerInterceptor {
|
||||||
@Override
|
@Override
|
||||||
public void setProperties(Properties properties) {
|
public void setProperties(Properties properties) {
|
||||||
PropertyMapper.newInstance(properties)
|
PropertyMapper.newInstance(properties)
|
||||||
.whenNotBlank("overflow", Boolean::parseBoolean, this::setOverflow)
|
.whenNotBlank("overflow", Boolean::parseBoolean, this::setOverflow)
|
||||||
.whenNotBlank("dbType", DbType::getDbType, this::setDbType)
|
.whenNotBlank("dbType", DbType::getDbType, this::setDbType)
|
||||||
.whenNotBlank("dialect", ClassUtils::newInstance, this::setDialect)
|
.whenNotBlank("dialect", ClassUtils::newInstance, this::setDialect)
|
||||||
.whenNotBlank("maxLimit", Long::parseLong, this::setMaxLimit)
|
.whenNotBlank("maxLimit", Long::parseLong, this::setMaxLimit)
|
||||||
.whenNotBlank("optimizeJoin", Boolean::parseBoolean, this::setOptimizeJoin);
|
.whenNotBlank("optimizeJoin", Boolean::parseBoolean, this::setOptimizeJoin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package com.chushang.redis.config;
|
package com.chushang.redis.config;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.chushang.common.core.exception.utils.AssertUtil;
|
import com.chushang.common.core.exception.utils.AssertUtil;
|
||||||
import com.chushang.common.core.util.StringUtils;
|
import com.chushang.common.core.util.StringUtils;
|
||||||
|
|
@ -55,6 +54,7 @@ public class RedisConfiguration extends CachingConfigurerSupport {
|
||||||
AssertUtil.invalidate(StringUtils.isEmpty(address), "redisson 配置错误");
|
AssertUtil.invalidate(StringUtils.isEmpty(address), "redisson 配置错误");
|
||||||
// 使用单机模式
|
// 使用单机模式
|
||||||
config.useSingleServer()
|
config.useSingleServer()
|
||||||
|
.setClientName(redissonProperties.getClientName())
|
||||||
//设置redis key前缀
|
//设置redis key前缀
|
||||||
.setNameMapper(new KeyPrefixHandler(redissonProperties.getPrefix()))
|
.setNameMapper(new KeyPrefixHandler(redissonProperties.getPrefix()))
|
||||||
.setTimeout(redissonProperties.getTimeout())
|
.setTimeout(redissonProperties.getTimeout())
|
||||||
|
|
@ -77,6 +77,7 @@ public class RedisConfiguration extends CachingConfigurerSupport {
|
||||||
config.useClusterServers()
|
config.useClusterServers()
|
||||||
//设置redis key前缀
|
//设置redis key前缀
|
||||||
.setNameMapper(new KeyPrefixHandler(redissonProperties.getPrefix()))
|
.setNameMapper(new KeyPrefixHandler(redissonProperties.getPrefix()))
|
||||||
|
.setClientName(redissonProperties.getClientName())
|
||||||
.setTimeout(redissonProperties.getTimeout())
|
.setTimeout(redissonProperties.getTimeout())
|
||||||
.setPassword(redissonProperties.getPassword())
|
.setPassword(redissonProperties.getPassword())
|
||||||
.setUsername(redissonProperties.getUsername())
|
.setUsername(redissonProperties.getUsername())
|
||||||
|
|
@ -93,6 +94,7 @@ public class RedisConfiguration extends CachingConfigurerSupport {
|
||||||
}
|
}
|
||||||
config.useSentinelServers()
|
config.useSentinelServers()
|
||||||
.setNameMapper(new KeyPrefixHandler(redissonProperties.getPrefix()))
|
.setNameMapper(new KeyPrefixHandler(redissonProperties.getPrefix()))
|
||||||
|
.setClientName(redissonProperties.getClientName())
|
||||||
.setTimeout(redissonProperties.getTimeout())
|
.setTimeout(redissonProperties.getTimeout())
|
||||||
.setUsername(redissonProperties.getUsername())
|
.setUsername(redissonProperties.getUsername())
|
||||||
.setPassword(redissonProperties.getPassword())
|
.setPassword(redissonProperties.getPassword())
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,10 @@ package com.chushang.redis.config.properties;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import org.redisson.config.ClusterServersConfig;
|
|
||||||
import org.redisson.config.ReadMode;
|
|
||||||
import org.redisson.config.SentinelServersConfig;
|
|
||||||
import org.redisson.config.SubscriptionMode;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @auther: zhao
|
* @auther: zhao
|
||||||
* @date: 2024/4/29 15:52
|
* @date: 2024/4/29 15:52
|
||||||
|
|
@ -19,7 +13,7 @@ import java.util.List;
|
||||||
@Data
|
@Data
|
||||||
@RefreshScope
|
@RefreshScope
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConfigurationProperties(prefix = "redis.config")
|
@ConfigurationProperties(prefix = "config.redis")
|
||||||
public class RedissonProperties {
|
public class RedissonProperties {
|
||||||
|
|
||||||
private String prefix;
|
private String prefix;
|
||||||
|
|
|
||||||
|
|
@ -7,17 +7,29 @@ server:
|
||||||
tomcat:
|
tomcat:
|
||||||
uri-encoding: UTF-8
|
uri-encoding: UTF-8
|
||||||
threads:
|
threads:
|
||||||
max: 200
|
max: 800
|
||||||
min-spare: 25
|
min-spare: 100
|
||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
name: @artifactId@
|
name: @artifactId@
|
||||||
|
# 如果需要使用读写分离, 此处需要改造, 有没有办法不用改?
|
||||||
datasource:
|
datasource:
|
||||||
type: com.zaxxer.hikari.HikariDataSource
|
type: com.zaxxer.hikari.HikariDataSource
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
username: ${conf.jdbc.cacc.master.username}
|
username: ${conf.jdbc.cs.master.username}
|
||||||
password: ${conf.jdbc.cacc.master.password}
|
password: ${conf.jdbc.cs.master.password}
|
||||||
url: jdbc:mysql://${conf.jdbc.cacc.master.host}:${conf.jdbc.cacc.master.port}/${conf.jdbc.cacc.master.database}?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
|
url: jdbc:mysql://${conf.jdbc.cs.master.host}:${conf.jdbc.cs.master.port}/${conf.jdbc.cs.master.database}?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
|
||||||
|
hikari:
|
||||||
|
# 最大线程池数量
|
||||||
|
maximum-pool-size: 30
|
||||||
|
# 最小线程池数量
|
||||||
|
minimum-idle: 5
|
||||||
|
# 检测连接
|
||||||
|
connection-test-query: SELECT 1
|
||||||
|
# 连接超时时间 默认30分钟
|
||||||
|
connection-timeout: 30000
|
||||||
|
# 连接最大生存期间, 默认30分钟
|
||||||
|
#max-lifetime: 300000
|
||||||
devtools:
|
devtools:
|
||||||
restart:
|
restart:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,7 @@
|
||||||
server:
|
|
||||||
tomcat:
|
|
||||||
uri-encoding: UTF-8
|
|
||||||
threads:
|
|
||||||
max: 200
|
|
||||||
min-spare: 25
|
|
||||||
connection-timeout: 5000ms
|
|
||||||
spring:
|
spring:
|
||||||
|
config:
|
||||||
|
import:
|
||||||
|
-: "classpath:application.yml"
|
||||||
cloud:
|
cloud:
|
||||||
loadbalancer:
|
loadbalancer:
|
||||||
cache:
|
cache:
|
||||||
|
|
@ -23,7 +19,7 @@ spring:
|
||||||
server-addr: ${spring.cloud.nacos.discovery.server-addr}
|
server-addr: ${spring.cloud.nacos.discovery.server-addr}
|
||||||
namespace: ${spring.cloud.nacos.discovery.namespace}
|
namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||||
group: ${spring.cloud.nacos.discovery.group}
|
group: ${spring.cloud.nacos.discovery.group}
|
||||||
file-extension: yml
|
file-extension: yaml
|
||||||
refresh-enabled: true
|
refresh-enabled: true
|
||||||
prefix: ${spring.application.name}
|
prefix: ${spring.application.name}
|
||||||
shared-configs:
|
shared-configs:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue