1. 修改 readme.md
This commit is contained in:
parent
cff8492dc0
commit
734f138aae
|
|
@ -6,86 +6,76 @@
|
||||||
|
|
||||||
<groupId>com.chushang</groupId>
|
<groupId>com.chushang</groupId>
|
||||||
<artifactId>chushang-common-bom</artifactId>
|
<artifactId>chushang-common-bom</artifactId>
|
||||||
<version>${commonb.version}</version>
|
<version>1.0.0</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<commonb.version>1.0.0</commonb.version>
|
<common.version>1.0.0</common.version>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.chushang</groupId>
|
<groupId>com.chushang</groupId>
|
||||||
<artifactId>chushang-common-canal</artifactId>
|
<artifactId>chushang-common-canal</artifactId>
|
||||||
<version>${commonb.version}</version>
|
<version>${common.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.chushang</groupId>
|
<groupId>com.chushang</groupId>
|
||||||
<artifactId>chushang-common-core</artifactId>
|
<artifactId>chushang-common-core</artifactId>
|
||||||
<version>${commonb.version}</version>
|
<version>${common.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.chushang</groupId>
|
<groupId>com.chushang</groupId>
|
||||||
<artifactId>chushang-common-easy-es</artifactId>
|
<artifactId>chushang-common-easy-es</artifactId>
|
||||||
<version>${commonb.version}</version>
|
<version>${common.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.chushang</groupId>
|
<groupId>com.chushang</groupId>
|
||||||
<artifactId>chushang-common-excel</artifactId>
|
<artifactId>chushang-common-excel</artifactId>
|
||||||
<version>${commonb.version}</version>
|
<version>${common.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.chushang</groupId>
|
<groupId>com.chushang</groupId>
|
||||||
<artifactId>chushang-common-feign</artifactId>
|
<artifactId>chushang-common-feign</artifactId>
|
||||||
<version>${commonb.version}</version>
|
<version>${common.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.chushang</groupId>
|
<groupId>com.chushang</groupId>
|
||||||
<artifactId>chushang-common-mail</artifactId>
|
<artifactId>chushang-common-mail</artifactId>
|
||||||
<version>${commonb.version}</version>
|
<version>${common.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.chushang</groupId>
|
<groupId>com.chushang</groupId>
|
||||||
<artifactId>chushang-common-mongo</artifactId>
|
<artifactId>chushang-common-mongo</artifactId>
|
||||||
<version>${commonb.version}</version>
|
<version>${common.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.chushang</groupId>
|
<groupId>com.chushang</groupId>
|
||||||
<artifactId>chushang-common-mybatis</artifactId>
|
<artifactId>chushang-common-mybatis</artifactId>
|
||||||
<version>${commonb.version}</version>
|
<version>${common.version}</version>
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.chushang</groupId>
|
|
||||||
<artifactId>chushang-common-mybatis-join</artifactId>
|
|
||||||
<version>${commonb.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.chushang</groupId>
|
|
||||||
<artifactId>chushang-common-oss</artifactId>
|
|
||||||
<version>${commonb.version}</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.chushang</groupId>
|
<groupId>com.chushang</groupId>
|
||||||
<artifactId>chushang-common-log</artifactId>
|
<artifactId>chushang-common-log</artifactId>
|
||||||
<version>${commonb.version}</version>
|
<version>${common.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.chushang</groupId>
|
<groupId>com.chushang</groupId>
|
||||||
<artifactId>chushang-common-job</artifactId>
|
<artifactId>chushang-common-job</artifactId>
|
||||||
<version>${commonb.version}</version>
|
<version>${common.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.chushang</groupId>
|
<groupId>com.chushang</groupId>
|
||||||
<artifactId>chushang-common-redis</artifactId>
|
<artifactId>chushang-common-redis</artifactId>
|
||||||
<version>${commonb.version}</version>
|
<version>${common.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.chushang</groupId>
|
<groupId>com.chushang</groupId>
|
||||||
<artifactId>chushang-common-security</artifactId>
|
<artifactId>chushang-common-security</artifactId>
|
||||||
<version>${commonb.version}</version>
|
<version>${common.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ package com.chushang.common.core.constant;
|
||||||
|
|
||||||
public interface CommonConstants {
|
public interface CommonConstants {
|
||||||
|
|
||||||
String HEAD_TOKEN_KEY = "sanyi-token";
|
String HEAD_TOKEN_KEY = "cs-token";
|
||||||
|
|
||||||
String ACCOUNT_SYMBOL = ":";
|
String ACCOUNT_SYMBOL = ":";
|
||||||
|
|
||||||
|
|
@ -36,6 +36,10 @@ public interface CommonConstants {
|
||||||
|
|
||||||
String AT_SYMBOL = "@";
|
String AT_SYMBOL = "@";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 链路id
|
||||||
|
*/
|
||||||
|
String TRACE_ID = "traceId";
|
||||||
|
String SPAN = "span";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,4 +60,5 @@ public interface SecurityConstants {
|
||||||
*/
|
*/
|
||||||
String ROLE_PERMISSION = "role_permission";
|
String ROLE_PERMISSION = "role_permission";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -127,35 +127,4 @@ public class GlobalExceptionHandler
|
||||||
log.error("请求地址'{}',发生系统异常.", requestURI, e);
|
log.error("请求地址'{}',发生系统异常.", requestURI, e);
|
||||||
return AjaxResult.error(e.getMessage());
|
return AjaxResult.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 登录异常
|
|
||||||
*/
|
|
||||||
@ExceptionHandler(NotLoginException.class)
|
|
||||||
public AjaxResult handlerNotLoginException(NotLoginException e, HttpServletRequest request){
|
|
||||||
String requestURI = request.getRequestURI();
|
|
||||||
log.error("请求地址'{}',发生系统异常.", requestURI, e);
|
|
||||||
return AjaxResult.error(e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 权限异常
|
|
||||||
*/
|
|
||||||
@ExceptionHandler(NotPermissionException.class)
|
|
||||||
public AjaxResult handlerNotPermissionException(NotPermissionException e, HttpServletRequest request){
|
|
||||||
String requestURI = request.getRequestURI();
|
|
||||||
log.error("请求地址'{}',发生系统异常.", requestURI, e);
|
|
||||||
return AjaxResult.error(e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 角色异常
|
|
||||||
*/
|
|
||||||
@ExceptionHandler(NotRoleException.class)
|
|
||||||
public AjaxResult handlerNotRoleException(NotRoleException e, HttpServletRequest request){
|
|
||||||
String requestURI = request.getRequestURI();
|
|
||||||
log.error("请求地址'{}',发生系统异常.", requestURI, e);
|
|
||||||
return AjaxResult.error(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,30 +16,26 @@ import javax.servlet.ServletResponse;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.chushang.common.core.constant.CommonConstants;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.slf4j.MDC;
|
import org.slf4j.MDC;
|
||||||
|
|
||||||
public class MdcFilter implements Filter {
|
public class MdcFilter implements Filter {
|
||||||
private static final Logger log = LoggerFactory.getLogger(MdcFilter.class);
|
private static final Logger log = LoggerFactory.getLogger(MdcFilter.class);
|
||||||
public static final String TRECE_NAME = "trace";
|
|
||||||
public static final String SPAN_NAME = "span";
|
|
||||||
|
|
||||||
public MdcFilter() {
|
public MdcFilter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||||
HttpServletRequest req = (HttpServletRequest)request;
|
HttpServletRequest req = (HttpServletRequest)request;
|
||||||
String trace = req.getHeader("trace");
|
String trace = req.getHeader(CommonConstants.TRACE_ID);
|
||||||
String span = req.getHeader("span");
|
String span = req.getHeader(CommonConstants.SPAN);
|
||||||
String uri = req.getRequestURI();
|
String uri = req.getRequestURI();
|
||||||
String userAgent = req.getHeader("user-agent");
|
String userAgent = req.getHeader("user-agent");
|
||||||
if (!uri.contains(".") || userAgent.startsWith("Java")) {
|
if (!uri.contains(".") || userAgent.startsWith("Java")) {
|
||||||
MDC.put("trace", Objects.requireNonNullElseGet(trace, () -> UUID.randomUUID().toString().replaceAll("-", "")));
|
MDC.put(CommonConstants.TRACE_ID, Objects.requireNonNullElseGet(trace, () -> UUID.randomUUID().toString().replaceAll("-", "")));
|
||||||
|
MDC.put(CommonConstants.SPAN, Objects.requireNonNullElseGet(span, () -> UUID.randomUUID().toString().replaceAll("-", "")));
|
||||||
MDC.put("span", Objects.requireNonNullElseGet(span, () -> UUID.randomUUID().toString().replaceAll("-", "")));
|
|
||||||
|
|
||||||
log.info("Request -->URL:{},Param:{}", uri, JSONObject.toJSONString(request.getParameterMap()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
chain.doFilter(request, response);
|
chain.doFilter(request, response);
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import org.springframework.core.annotation.Order;
|
||||||
@Order(5)
|
@Order(5)
|
||||||
public class FeignHeaderInterceptor implements RequestInterceptor {
|
public class FeignHeaderInterceptor implements RequestInterceptor {
|
||||||
public static final String attrKey = "transfer";
|
public static final String attrKey = "transfer";
|
||||||
private static final ThreadLocal<JSONObject> header = ThreadLocal.withInitial(() -> new JSONObject());
|
private static final ThreadLocal<JSONObject> header = ThreadLocal.withInitial(JSONObject::new);
|
||||||
private static final byte[] hex = "0123456789ABCDEF".getBytes();
|
private static final byte[] hex = "0123456789ABCDEF".getBytes();
|
||||||
|
|
||||||
public FeignHeaderInterceptor() {
|
public FeignHeaderInterceptor() {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
package com.chushang.common.feign.interceptor;
|
package com.chushang.common.feign.interceptor;
|
||||||
|
|
||||||
|
import com.chushang.common.core.constant.CommonConstants;
|
||||||
import feign.RequestInterceptor;
|
import feign.RequestInterceptor;
|
||||||
import feign.RequestTemplate;
|
import feign.RequestTemplate;
|
||||||
import org.slf4j.MDC;
|
import org.slf4j.MDC;
|
||||||
|
|
@ -14,7 +15,7 @@ public class MdcInterceptor implements RequestInterceptor {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void apply(RequestTemplate template) {
|
public void apply(RequestTemplate template) {
|
||||||
template.header("trace", new String[]{MDC.get("trace")});
|
template.header(CommonConstants.TRACE_ID, MDC.get(CommonConstants.TRACE_ID));
|
||||||
template.header("span", new String[]{MDC.get("span")});
|
template.header(CommonConstants.SPAN, MDC.get(CommonConstants.SPAN));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ import java.util.List;
|
||||||
import javax.servlet.Filter;
|
import javax.servlet.Filter;
|
||||||
|
|
||||||
import com.chushang.common.feign.filter.TransferFilter;
|
import com.chushang.common.feign.filter.TransferFilter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||||
|
|
@ -22,7 +21,7 @@ public class TransferFilterRegistrar implements ImportBeanDefinitionRegistrar {
|
||||||
public TransferFilterRegistrar() {
|
public TransferFilterRegistrar() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerBeanDefinitions(@NotNull AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
|
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
|
||||||
Filter filter = new TransferFilter();
|
Filter filter = new TransferFilter();
|
||||||
List<String> patter = new ArrayList<>();
|
List<String> patter = new ArrayList<>();
|
||||||
patter.add("/*");
|
patter.add("/*");
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHan
|
||||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
|
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
|
||||||
import com.chushang.common.sentinel.handle.OnnUrlBlockHandler;
|
import com.chushang.common.sentinel.handle.OnnUrlBlockHandler;
|
||||||
import com.chushang.common.sentinel.ext.OnnSentinelFeign;
|
import com.chushang.common.sentinel.ext.OnnSentinelFeign;
|
||||||
import com.chushang.common.sentinel.ext.OnnSentinelFilterConfiguration;
|
|
||||||
import com.chushang.common.sentinel.parser.OnnHeaderRequestOriginParser;
|
import com.chushang.common.sentinel.parser.OnnHeaderRequestOriginParser;
|
||||||
import feign.Feign;
|
import feign.Feign;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||||
|
|
@ -40,7 +39,6 @@ import org.springframework.context.annotation.Scope;
|
||||||
* sentinel 配置
|
* sentinel 配置
|
||||||
*/
|
*/
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@Import(OnnSentinelFilterConfiguration.class)
|
|
||||||
@AutoConfigureBefore(SentinelFeignAutoConfiguration.class)
|
@AutoConfigureBefore(SentinelFeignAutoConfiguration.class)
|
||||||
public class SentinelAutoConfiguration {
|
public class SentinelAutoConfiguration {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,58 +0,0 @@
|
||||||
package com.chushang.common.sentinel.ext;
|
|
||||||
|
|
||||||
import com.alibaba.cloud.sentinel.SentinelProperties;
|
|
||||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.SentinelWebInterceptor;
|
|
||||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
|
|
||||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.DefaultBlockExceptionHandler;
|
|
||||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
|
|
||||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.UrlCleaner;
|
|
||||||
import com.alibaba.csp.sentinel.adapter.spring.webmvc.config.SentinelWebMvcConfig;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author lengleng
|
|
||||||
* @date 2021/12/4
|
|
||||||
*
|
|
||||||
* 避免 spring cloud 2021 不兼容 的问题
|
|
||||||
*/
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
|
|
||||||
public class OnnSentinelFilterConfiguration {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public SentinelWebInterceptor sentinelWebInterceptor(SentinelWebMvcConfig sentinelWebMvcConfig) {
|
|
||||||
return new SentinelWebInterceptor(sentinelWebMvcConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public SentinelWebMvcConfig sentinelWebMvcConfig(SentinelProperties properties,
|
|
||||||
Optional<UrlCleaner> urlCleanerOptional, Optional<BlockExceptionHandler> blockExceptionHandlerOptional,
|
|
||||||
Optional<RequestOriginParser> requestOriginParserOptional) {
|
|
||||||
SentinelWebMvcConfig sentinelWebMvcConfig = new SentinelWebMvcConfig();
|
|
||||||
sentinelWebMvcConfig.setHttpMethodSpecify(properties.getHttpMethodSpecify());
|
|
||||||
sentinelWebMvcConfig.setWebContextUnify(properties.getWebContextUnify());
|
|
||||||
|
|
||||||
if (blockExceptionHandlerOptional.isPresent()) {
|
|
||||||
blockExceptionHandlerOptional.ifPresent(sentinelWebMvcConfig::setBlockExceptionHandler);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (StringUtils.hasText(properties.getBlockPage())) {
|
|
||||||
sentinelWebMvcConfig.setBlockExceptionHandler(
|
|
||||||
((request, response, e) -> response.sendRedirect(properties.getBlockPage())));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sentinelWebMvcConfig.setBlockExceptionHandler(new DefaultBlockExceptionHandler());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
urlCleanerOptional.ifPresent(sentinelWebMvcConfig::setUrlCleaner);
|
|
||||||
requestOriginParserOptional.ifPresent(sentinelWebMvcConfig::setOriginParser);
|
|
||||||
return sentinelWebMvcConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -11,12 +11,6 @@
|
||||||
|
|
||||||
<artifactId>chushang-common-job</artifactId>
|
<artifactId>chushang-common-job</artifactId>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
调度任务通用配置信息
|
调度任务通用配置信息
|
||||||
</description>
|
</description>
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,6 @@
|
||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
<artifactId>chushang-common-log</artifactId>
|
<artifactId>chushang-common-log</artifactId>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.chushang</groupId>
|
<groupId>com.chushang</groupId>
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ import com.chushang.common.log.entity.SysLogEntity;
|
||||||
import com.chushang.common.log.enums.LogTypeEnum;
|
import com.chushang.common.log.enums.LogTypeEnum;
|
||||||
import com.chushang.common.log.service.SysLogService;
|
import com.chushang.common.log.service.SysLogService;
|
||||||
import com.chushang.security.utils.SecurityUtils;
|
import com.chushang.security.utils.SecurityUtils;
|
||||||
import com.chushang.system.entity.vo.LoginUser;
|
import com.chushang.security.entity.vo.LoginUser;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.JoinPoint;
|
||||||
|
|
|
||||||
|
|
@ -7,15 +7,9 @@
|
||||||
<groupId>com.chushang</groupId>
|
<groupId>com.chushang</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<packaging>jar</packaging>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>chushang-common-mybatis</artifactId>
|
<artifactId>chushang-common-mybatis</artifactId>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
</properties>
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- https://mvnrepository.com/artifact/org.apache.shardingsphere/sharding-jdbc-spring-boot-starter -->
|
<!-- https://mvnrepository.com/artifact/org.apache.shardingsphere/sharding-jdbc-spring-boot-starter -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
||||||
|
|
@ -1,210 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2011-2022, baomidou (jobob@qq.com).
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package com.baomidou.mybatisplus.core.config;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.FieldStrategy;
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
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.IdentifierGenerator;
|
|
||||||
import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
|
|
||||||
import com.baomidou.mybatisplus.core.injector.ISqlInjector;
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.Mapper;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.experimental.Accessors;
|
|
||||||
import org.apache.ibatis.session.SqlSessionFactory;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.ConcurrentSkipListSet;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mybatis 全局缓存
|
|
||||||
*
|
|
||||||
* @author Caratacus
|
|
||||||
* @since 2016-12-06
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Accessors(chain = true)
|
|
||||||
@SuppressWarnings("serial")
|
|
||||||
public class GlobalConfig implements Serializable {
|
|
||||||
/**
|
|
||||||
* 是否开启 LOGO
|
|
||||||
*/
|
|
||||||
private boolean banner = false;
|
|
||||||
/**
|
|
||||||
* 是否初始化 SqlRunner
|
|
||||||
*/
|
|
||||||
private boolean enableSqlRunner = false;
|
|
||||||
|
|
||||||
private boolean refreshMapper = false;
|
|
||||||
/**
|
|
||||||
* 数据库相关配置
|
|
||||||
*/
|
|
||||||
private DbConfig dbConfig;
|
|
||||||
/**
|
|
||||||
* SQL注入器
|
|
||||||
*/
|
|
||||||
private ISqlInjector sqlInjector = new DefaultSqlInjector();
|
|
||||||
/**
|
|
||||||
* Mapper父类
|
|
||||||
*/
|
|
||||||
private Class<?> superMapperClass = Mapper.class;
|
|
||||||
/**
|
|
||||||
* 仅用于缓存 SqlSessionFactory(外部勿进行set,set了也没用)
|
|
||||||
*/
|
|
||||||
private SqlSessionFactory sqlSessionFactory;
|
|
||||||
/**
|
|
||||||
* 缓存已注入CRUD的Mapper信息
|
|
||||||
*/
|
|
||||||
private Set<String> mapperRegistryCache = new ConcurrentSkipListSet<>();
|
|
||||||
/**
|
|
||||||
* 元对象字段填充控制器
|
|
||||||
*/
|
|
||||||
private MetaObjectHandler metaObjectHandler;
|
|
||||||
/**
|
|
||||||
* 参与 TableInfo 的初始化
|
|
||||||
*/
|
|
||||||
private PostInitTableInfoHandler postInitTableInfoHandler = new PostInitTableInfoHandler() {
|
|
||||||
};
|
|
||||||
/**
|
|
||||||
* 主键生成器
|
|
||||||
*/
|
|
||||||
private IdentifierGenerator identifierGenerator;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class DbConfig {
|
|
||||||
/**
|
|
||||||
* 主键类型
|
|
||||||
*/
|
|
||||||
private IdType idType = IdType.ASSIGN_ID;
|
|
||||||
/**
|
|
||||||
* 表名前缀
|
|
||||||
*/
|
|
||||||
private String tablePrefix;
|
|
||||||
/**
|
|
||||||
* schema
|
|
||||||
*
|
|
||||||
* @since 3.1.1
|
|
||||||
*/
|
|
||||||
private String schema;
|
|
||||||
/**
|
|
||||||
* db字段 format
|
|
||||||
* <p>
|
|
||||||
* 例: `%s`
|
|
||||||
* <p>
|
|
||||||
* 对主键无效
|
|
||||||
*
|
|
||||||
* @since 3.1.1
|
|
||||||
*/
|
|
||||||
private String columnFormat;
|
|
||||||
/**
|
|
||||||
* entity 的字段(property)的 format,只有在 column as property 这种情况下生效
|
|
||||||
* <p>
|
|
||||||
* 例: `%s`
|
|
||||||
* <p>
|
|
||||||
* 对主键无效
|
|
||||||
*
|
|
||||||
* @since 3.3.0
|
|
||||||
*/
|
|
||||||
private String propertyFormat;
|
|
||||||
/**
|
|
||||||
* 实验性功能,占位符替换,等同于 {@link com.baomidou.mybatisplus.extension.plugins.inner.ReplacePlaceholderInnerInterceptor},
|
|
||||||
* 只是这个属于启动时替换,用得地方多会启动慢一点点,不适用于其他的 {@link org.apache.ibatis.scripting.LanguageDriver}
|
|
||||||
*
|
|
||||||
* @since 3.4.2
|
|
||||||
*/
|
|
||||||
private boolean replacePlaceholder;
|
|
||||||
/**
|
|
||||||
* 转义符
|
|
||||||
* <p>
|
|
||||||
* 配合 {@link #replacePlaceholder} 使用时有效
|
|
||||||
* <p>
|
|
||||||
* 例: " 或 ' 或 `
|
|
||||||
*
|
|
||||||
* @since 3.4.2
|
|
||||||
*/
|
|
||||||
private String escapeSymbol;
|
|
||||||
/**
|
|
||||||
* 表名是否使用驼峰转下划线命名,只对表名生效
|
|
||||||
*/
|
|
||||||
private boolean tableUnderline = true;
|
|
||||||
/**
|
|
||||||
* 大写命名,对表名和字段名均生效
|
|
||||||
*/
|
|
||||||
private boolean capitalMode = false;
|
|
||||||
/**
|
|
||||||
* 表主键生成器
|
|
||||||
*/
|
|
||||||
private List<IKeyGenerator> keyGenerators;
|
|
||||||
/**
|
|
||||||
* 逻辑删除全局属性名
|
|
||||||
*/
|
|
||||||
private String logicDeleteField;
|
|
||||||
/**
|
|
||||||
* 逻辑删除全局值(默认 1、表示已删除)
|
|
||||||
*/
|
|
||||||
private String logicDeleteValue = "1";
|
|
||||||
/**
|
|
||||||
* 逻辑未删除全局值(默认 0、表示未删除)
|
|
||||||
*/
|
|
||||||
private String logicNotDeleteValue = "0";
|
|
||||||
/**
|
|
||||||
* 字段验证策略之 insert
|
|
||||||
*
|
|
||||||
* @since 3.1.2
|
|
||||||
*/
|
|
||||||
private FieldStrategy insertStrategy = FieldStrategy.NOT_NULL;
|
|
||||||
/**
|
|
||||||
* 字段验证策略之 update
|
|
||||||
*
|
|
||||||
* @since 3.1.2
|
|
||||||
*/
|
|
||||||
private FieldStrategy updateStrategy = FieldStrategy.NOT_NULL;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 字段验证策略之 select
|
|
||||||
*
|
|
||||||
* @since 3.1.2
|
|
||||||
* @deprecated 3.4.4
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private FieldStrategy selectStrategy;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 字段验证策略之 where
|
|
||||||
* 替代selectStrategy,保持与{@link TableField#whereStrategy()}一致
|
|
||||||
*
|
|
||||||
* @since 3.4.4
|
|
||||||
*/
|
|
||||||
private FieldStrategy whereStrategy = FieldStrategy.NOT_NULL;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 重写whereStrategy的get方法,适配低版本:
|
|
||||||
* - 如果用户自定义了selectStrategy则用用户自定义的,
|
|
||||||
* - 后续版本移除selectStrategy后,直接删除该方法即可。
|
|
||||||
*
|
|
||||||
* @return 字段作为查询条件时的验证策略
|
|
||||||
* @since 3.4.4
|
|
||||||
*/
|
|
||||||
public FieldStrategy getWhereStrategy() {
|
|
||||||
return selectStrategy == null ? whereStrategy : selectStrategy;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,483 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2011-2022, baomidou (jobob@qq.com).
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package com.baomidou.mybatisplus.extension.plugins.inner;
|
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.DbType;
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.*;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.DialectFactory;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.DialectModel;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.dialects.IDialect;
|
|
||||||
import com.baomidou.mybatisplus.extension.toolkit.JdbcUtils;
|
|
||||||
import com.baomidou.mybatisplus.extension.toolkit.PropertyMapper;
|
|
||||||
import com.baomidou.mybatisplus.extension.toolkit.SqlParserUtils;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import net.sf.jsqlparser.JSQLParserException;
|
|
||||||
import net.sf.jsqlparser.expression.Alias;
|
|
||||||
import net.sf.jsqlparser.expression.Expression;
|
|
||||||
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
|
|
||||||
import net.sf.jsqlparser.schema.Column;
|
|
||||||
import net.sf.jsqlparser.schema.Table;
|
|
||||||
import net.sf.jsqlparser.statement.select.*;
|
|
||||||
import org.apache.ibatis.cache.CacheKey;
|
|
||||||
import org.apache.ibatis.executor.Executor;
|
|
||||||
import org.apache.ibatis.logging.Log;
|
|
||||||
import org.apache.ibatis.logging.LogFactory;
|
|
||||||
import org.apache.ibatis.mapping.BoundSql;
|
|
||||||
import org.apache.ibatis.mapping.MappedStatement;
|
|
||||||
import org.apache.ibatis.mapping.ParameterMapping;
|
|
||||||
import org.apache.ibatis.mapping.ResultMap;
|
|
||||||
import org.apache.ibatis.session.Configuration;
|
|
||||||
import org.apache.ibatis.session.ResultHandler;
|
|
||||||
import org.apache.ibatis.session.RowBounds;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 分页拦截器
|
|
||||||
* <p>
|
|
||||||
* 默认对 left join 进行优化,虽然能优化count,但是加上分页的话如果1对多本身结果条数就是不正确的
|
|
||||||
*
|
|
||||||
* @author hubin
|
|
||||||
* @since 3.4.0
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@NoArgsConstructor
|
|
||||||
@SuppressWarnings({"rawtypes"})
|
|
||||||
public class PaginationInnerInterceptor implements InnerInterceptor {
|
|
||||||
/**
|
|
||||||
* 获取jsqlparser中count的SelectItem
|
|
||||||
*/
|
|
||||||
protected static final List<SelectItem> COUNT_SELECT_ITEM = Collections.singletonList(
|
|
||||||
new SelectExpressionItem(new Column().withColumnName("COUNT(*)")).withAlias(new Alias("total"))
|
|
||||||
);
|
|
||||||
protected static final Map<String, MappedStatement> countMsCache = new ConcurrentHashMap<>();
|
|
||||||
protected final Log logger = LogFactory.getLog(this.getClass());
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 溢出总页数后是否进行处理
|
|
||||||
*/
|
|
||||||
protected boolean overflow;
|
|
||||||
/**
|
|
||||||
* 单页分页条数限制
|
|
||||||
*/
|
|
||||||
protected Long maxLimit;
|
|
||||||
/**
|
|
||||||
* 数据库类型
|
|
||||||
* <p>
|
|
||||||
* 查看 {@link #findIDialect(Executor)} 逻辑
|
|
||||||
*/
|
|
||||||
private DbType dbType;
|
|
||||||
/**
|
|
||||||
* 方言实现类
|
|
||||||
* <p>
|
|
||||||
* 查看 {@link #findIDialect(Executor)} 逻辑
|
|
||||||
*/
|
|
||||||
private IDialect dialect;
|
|
||||||
/**
|
|
||||||
* 生成 countSql 优化掉 join
|
|
||||||
* 现在只支持 left join
|
|
||||||
*
|
|
||||||
* @since 3.4.2
|
|
||||||
*/
|
|
||||||
protected boolean optimizeJoin = true;
|
|
||||||
|
|
||||||
public PaginationInnerInterceptor(DbType dbType) {
|
|
||||||
this.dbType = dbType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PaginationInnerInterceptor(IDialect dialect) {
|
|
||||||
this.dialect = dialect;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 这里进行count,如果count为0这返回false(就是不再执行sql了)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean willDoQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
|
|
||||||
IPage<?> page = ParameterUtils.findPage(parameter).orElse(null);
|
|
||||||
if (page == null || page.getSize() < 0 || !page.searchCount()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
BoundSql countSql;
|
|
||||||
MappedStatement countMs = buildCountMappedStatement(ms, page.countId());
|
|
||||||
if (countMs != null) {
|
|
||||||
countSql = countMs.getBoundSql(parameter);
|
|
||||||
} else {
|
|
||||||
countMs = buildAutoCountMappedStatement(ms);
|
|
||||||
String countSqlStr = autoCountSql(page, boundSql.getSql());
|
|
||||||
PluginUtils.MPBoundSql mpBoundSql = PluginUtils.mpBoundSql(boundSql);
|
|
||||||
countSql = new BoundSql(countMs.getConfiguration(), countSqlStr, mpBoundSql.parameterMappings(), parameter);
|
|
||||||
PluginUtils.setAdditionalParameter(countSql, mpBoundSql.additionalParameters());
|
|
||||||
}
|
|
||||||
|
|
||||||
CacheKey cacheKey = executor.createCacheKey(countMs, parameter, rowBounds, countSql);
|
|
||||||
List<Object> result = executor.query(countMs, parameter, rowBounds, resultHandler, cacheKey, countSql);
|
|
||||||
long total = 0;
|
|
||||||
if (CollectionUtils.isNotEmpty(result)) {
|
|
||||||
// 个别数据库 count 没数据不会返回 0
|
|
||||||
Object o = result.get(0);
|
|
||||||
if (o != null) {
|
|
||||||
total = Long.parseLong(o.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
page.setTotal(total);
|
|
||||||
return continuePage(page);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void beforeQuery(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
|
|
||||||
IPage<?> page = ParameterUtils.findPage(parameter).orElse(null);
|
|
||||||
if (null == page) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理 orderBy 拼接
|
|
||||||
boolean addOrdered = false;
|
|
||||||
String buildSql = boundSql.getSql();
|
|
||||||
List<OrderItem> orders = page.orders();
|
|
||||||
if (CollectionUtils.isNotEmpty(orders)) {
|
|
||||||
addOrdered = true;
|
|
||||||
buildSql = this.concatOrderBy(buildSql, orders);
|
|
||||||
}
|
|
||||||
|
|
||||||
// size 小于 0 且不限制返回值则不构造分页sql
|
|
||||||
Long _limit = page.maxLimit() != null ? page.maxLimit() : maxLimit;
|
|
||||||
if (page.getSize() < 0 && null == _limit) {
|
|
||||||
if (addOrdered) {
|
|
||||||
PluginUtils.mpBoundSql(boundSql).sql(buildSql);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
handlerLimit(page, _limit);
|
|
||||||
IDialect dialect = findIDialect(executor);
|
|
||||||
|
|
||||||
final Configuration configuration = ms.getConfiguration();
|
|
||||||
DialectModel model = dialect.buildPaginationSql(buildSql, page.offset(), page.getSize());
|
|
||||||
PluginUtils.MPBoundSql mpBoundSql = PluginUtils.mpBoundSql(boundSql);
|
|
||||||
|
|
||||||
List<ParameterMapping> mappings = mpBoundSql.parameterMappings();
|
|
||||||
Map<String, Object> additionalParameter = mpBoundSql.additionalParameters();
|
|
||||||
model.consumers(mappings, configuration, additionalParameter);
|
|
||||||
mpBoundSql.sql(model.getDialectSql());
|
|
||||||
mpBoundSql.parameterMappings(mappings);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取分页方言类的逻辑
|
|
||||||
*
|
|
||||||
* @param executor Executor
|
|
||||||
* @return 分页方言类
|
|
||||||
*/
|
|
||||||
protected IDialect findIDialect(Executor executor) {
|
|
||||||
if (dialect != null) {
|
|
||||||
return dialect;
|
|
||||||
}
|
|
||||||
if (dbType != null) {
|
|
||||||
dialect = DialectFactory.getDialect(dbType);
|
|
||||||
return dialect;
|
|
||||||
}
|
|
||||||
return DialectFactory.getDialect(JdbcUtils.getDbType(executor));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取指定的 id 的 MappedStatement
|
|
||||||
*
|
|
||||||
* @param ms MappedStatement
|
|
||||||
* @param countId id
|
|
||||||
* @return MappedStatement
|
|
||||||
*/
|
|
||||||
protected MappedStatement buildCountMappedStatement(MappedStatement ms, String countId) {
|
|
||||||
if (StringUtils.isNotBlank(countId)) {
|
|
||||||
final String id = ms.getId();
|
|
||||||
if (!countId.contains(StringPool.DOT)) {
|
|
||||||
countId = id.substring(0, id.lastIndexOf(StringPool.DOT) + 1) + countId;
|
|
||||||
}
|
|
||||||
final Configuration configuration = ms.getConfiguration();
|
|
||||||
try {
|
|
||||||
return CollectionUtils.computeIfAbsent(countMsCache, countId, key -> configuration.getMappedStatement(key, false));
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.warn(String.format("can not find this countId: [\"%s\"]", countId));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构建 mp 自用自动的 MappedStatement
|
|
||||||
*
|
|
||||||
* @param ms MappedStatement
|
|
||||||
* @return MappedStatement
|
|
||||||
*/
|
|
||||||
protected MappedStatement buildAutoCountMappedStatement(MappedStatement ms) {
|
|
||||||
final String countId = ms.getId() + "_mpCount";
|
|
||||||
final Configuration configuration = ms.getConfiguration();
|
|
||||||
return CollectionUtils.computeIfAbsent(countMsCache, countId, key -> {
|
|
||||||
MappedStatement.Builder builder = new MappedStatement.Builder(configuration, key, ms.getSqlSource(), ms.getSqlCommandType());
|
|
||||||
builder.resource(ms.getResource());
|
|
||||||
builder.fetchSize(ms.getFetchSize());
|
|
||||||
builder.statementType(ms.getStatementType());
|
|
||||||
builder.timeout(ms.getTimeout());
|
|
||||||
builder.parameterMap(ms.getParameterMap());
|
|
||||||
builder.resultMaps(Collections.singletonList(new ResultMap.Builder(configuration, Constants.MYBATIS_PLUS, Long.class, Collections.emptyList()).build()));
|
|
||||||
builder.resultSetType(ms.getResultSetType());
|
|
||||||
builder.cache(ms.getCache());
|
|
||||||
builder.flushCacheRequired(ms.isFlushCacheRequired());
|
|
||||||
builder.useCache(ms.isUseCache());
|
|
||||||
return builder.build();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取自动优化的 countSql
|
|
||||||
*
|
|
||||||
* @param page 参数
|
|
||||||
* @param sql sql
|
|
||||||
* @return countSql
|
|
||||||
*/
|
|
||||||
protected String autoCountSql(IPage<?> page, String sql) {
|
|
||||||
if (!page.optimizeCountSql()) {
|
|
||||||
return lowLevelCountSql(sql);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Select select = (Select) CCJSqlParserUtil.parse(sql);
|
|
||||||
SelectBody selectBody = select.getSelectBody();
|
|
||||||
// https://github.com/baomidou/mybatis-plus/issues/3920 分页增加union语法支持
|
|
||||||
if (selectBody instanceof SetOperationList) {
|
|
||||||
return lowLevelCountSql(sql);
|
|
||||||
}
|
|
||||||
PlainSelect plainSelect = (PlainSelect) select.getSelectBody();
|
|
||||||
Distinct distinct = plainSelect.getDistinct();
|
|
||||||
GroupByElement groupBy = plainSelect.getGroupBy();
|
|
||||||
List<OrderByElement> orderBy = plainSelect.getOrderByElements();
|
|
||||||
|
|
||||||
if (CollectionUtils.isNotEmpty(orderBy)) {
|
|
||||||
boolean canClean = true;
|
|
||||||
if (groupBy != null) {
|
|
||||||
// 包含groupBy 不去除orderBy
|
|
||||||
canClean = false;
|
|
||||||
}
|
|
||||||
if (canClean) {
|
|
||||||
for (OrderByElement order : orderBy) {
|
|
||||||
// order by 里带参数,不去除order by
|
|
||||||
Expression expression = order.getExpression();
|
|
||||||
if (!(expression instanceof Column) && expression.toString().contains(StringPool.QUESTION_MARK)) {
|
|
||||||
canClean = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (canClean) {
|
|
||||||
plainSelect.setOrderByElements(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//#95 Github, selectItems contains #{} ${}, which will be translated to ?, and it may be in a function: power(#{myInt},2)
|
|
||||||
for (SelectItem item : plainSelect.getSelectItems()) {
|
|
||||||
if (item.toString().contains(StringPool.QUESTION_MARK)) {
|
|
||||||
return lowLevelCountSql(select.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 包含 distinct、groupBy不优化
|
|
||||||
if (distinct != null || null != groupBy) {
|
|
||||||
return lowLevelCountSql(select.toString());
|
|
||||||
}
|
|
||||||
// 包含 join 连表,进行判断是否移除 join 连表
|
|
||||||
if (optimizeJoin && page.optimizeJoinOfCountSql()) {
|
|
||||||
List<Join> joins = plainSelect.getJoins();
|
|
||||||
if (CollectionUtils.isNotEmpty(joins)) {
|
|
||||||
boolean canRemoveJoin = true;
|
|
||||||
String whereS = Optional.ofNullable(plainSelect.getWhere()).map(Expression::toString).orElse(StringPool.EMPTY);
|
|
||||||
// 不区分大小写
|
|
||||||
whereS = whereS.toLowerCase();
|
|
||||||
for (Join join : joins) {
|
|
||||||
if (!join.isLeft()) {
|
|
||||||
canRemoveJoin = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
FromItem rightItem = join.getRightItem();
|
|
||||||
String str = "";
|
|
||||||
if (rightItem instanceof Table) {
|
|
||||||
Table table = (Table) rightItem;
|
|
||||||
str = Optional.ofNullable(table.getAlias()).map(Alias::getName).orElse(table.getName()) + StringPool.DOT;
|
|
||||||
} else if (rightItem instanceof SubSelect) {
|
|
||||||
SubSelect subSelect = (SubSelect) rightItem;
|
|
||||||
/* 如果 left join 是子查询,并且子查询里包含 ?(代表有入参) 或者 where 条件里包含使用 join 的表的字段作条件,就不移除 join */
|
|
||||||
if (subSelect.toString().contains(StringPool.QUESTION_MARK)) {
|
|
||||||
canRemoveJoin = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
str = subSelect.getAlias().getName() + StringPool.DOT;
|
|
||||||
}
|
|
||||||
// 不区分大小写
|
|
||||||
str = str.toLowerCase();
|
|
||||||
|
|
||||||
if (whereS.contains(str)) {
|
|
||||||
/* 如果 where 条件里包含使用 join 的表的字段作条件,就不移除 join */
|
|
||||||
canRemoveJoin = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Expression expression : join.getOnExpressions()) {
|
|
||||||
if (expression.toString().contains(StringPool.QUESTION_MARK)) {
|
|
||||||
/* 如果 join 里包含 ?(代表有入参) 就不移除 join */
|
|
||||||
canRemoveJoin = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (canRemoveJoin) {
|
|
||||||
plainSelect.setJoins(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 优化 SQL
|
|
||||||
plainSelect.setSelectItems(COUNT_SELECT_ITEM);
|
|
||||||
return select.toString();
|
|
||||||
} catch (JSQLParserException e) {
|
|
||||||
// 无法优化使用原 SQL
|
|
||||||
logger.warn("optimize this sql to a count sql has exception, sql:\"" + sql + "\", exception:\n" + e.getCause());
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.warn("optimize this sql to a count sql has error, sql:\"" + sql + "\", exception:\n" + e);
|
|
||||||
}
|
|
||||||
return lowLevelCountSql(sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 无法进行count优化时,降级使用此方法
|
|
||||||
*
|
|
||||||
* @param originalSql 原始sql
|
|
||||||
* @return countSql
|
|
||||||
*/
|
|
||||||
protected String lowLevelCountSql(String originalSql) {
|
|
||||||
return SqlParserUtils.getOriginalCountSql(originalSql);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询SQL拼接Order By
|
|
||||||
*
|
|
||||||
* @param originalSql 需要拼接的SQL
|
|
||||||
* @return ignore
|
|
||||||
*/
|
|
||||||
public String concatOrderBy(String originalSql, List<OrderItem> orderList) {
|
|
||||||
try {
|
|
||||||
Select select = (Select) CCJSqlParserUtil.parse(originalSql);
|
|
||||||
SelectBody selectBody = select.getSelectBody();
|
|
||||||
if (selectBody instanceof PlainSelect) {
|
|
||||||
PlainSelect plainSelect = (PlainSelect) selectBody;
|
|
||||||
List<OrderByElement> orderByElements = plainSelect.getOrderByElements();
|
|
||||||
List<OrderByElement> orderByElementsReturn = addOrderByElements(orderList, orderByElements);
|
|
||||||
plainSelect.setOrderByElements(orderByElementsReturn);
|
|
||||||
return select.toString();
|
|
||||||
} else if (selectBody instanceof SetOperationList) {
|
|
||||||
SetOperationList setOperationList = (SetOperationList) selectBody;
|
|
||||||
List<OrderByElement> orderByElements = setOperationList.getOrderByElements();
|
|
||||||
List<OrderByElement> orderByElementsReturn = addOrderByElements(orderList, orderByElements);
|
|
||||||
setOperationList.setOrderByElements(orderByElementsReturn);
|
|
||||||
return select.toString();
|
|
||||||
} else if (selectBody instanceof WithItem) {
|
|
||||||
// todo: don't known how to resole
|
|
||||||
return originalSql;
|
|
||||||
} else {
|
|
||||||
return originalSql;
|
|
||||||
}
|
|
||||||
} catch (JSQLParserException e) {
|
|
||||||
logger.warn("failed to concat orderBy from IPage, exception:\n" + e.getCause());
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.warn("failed to concat orderBy from IPage, exception:\n" + e);
|
|
||||||
}
|
|
||||||
return originalSql;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected List<OrderByElement> addOrderByElements(List<OrderItem> orderList, List<OrderByElement> orderByElements) {
|
|
||||||
List<OrderByElement> additionalOrderBy = orderList.stream()
|
|
||||||
.filter(item -> StringUtils.isNotBlank(item.getColumn()))
|
|
||||||
.map(item -> {
|
|
||||||
OrderByElement element = new OrderByElement();
|
|
||||||
element.setExpression(new Column(item.getColumn()));
|
|
||||||
element.setAsc(item.isAsc());
|
|
||||||
element.setAscDescPresent(true);
|
|
||||||
return element;
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
if (CollectionUtils.isEmpty(orderByElements)) {
|
|
||||||
return additionalOrderBy;
|
|
||||||
}
|
|
||||||
// github pull/3550 优化排序,比如:默认 order by id 前端传了name排序,设置为 order by name,id
|
|
||||||
additionalOrderBy.addAll(orderByElements);
|
|
||||||
return additionalOrderBy;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* count 查询之后,是否继续执行分页
|
|
||||||
*
|
|
||||||
* @param page 分页对象
|
|
||||||
* @return 是否
|
|
||||||
*/
|
|
||||||
protected boolean continuePage(IPage<?> page) {
|
|
||||||
if (page.getTotal() <= 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (page.getCurrent() > page.getPages()) {
|
|
||||||
if (overflow) {
|
|
||||||
//溢出总页数处理
|
|
||||||
handlerOverflow(page);
|
|
||||||
} else {
|
|
||||||
// 超过最大范围,未设置溢出逻辑中断 list 执行
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理超出分页条数限制,默认归为限制数
|
|
||||||
*
|
|
||||||
* @param page IPage
|
|
||||||
*/
|
|
||||||
protected void handlerLimit(IPage<?> page, Long limit) {
|
|
||||||
final long size = page.getSize();
|
|
||||||
if (limit != null && limit > 0 && (size > limit || size < 0)) {
|
|
||||||
page.setSize(limit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 处理页数溢出,默认设置为第一页
|
|
||||||
*
|
|
||||||
* @param page IPage
|
|
||||||
*/
|
|
||||||
protected void handlerOverflow(IPage<?> page) {
|
|
||||||
page.setCurrent(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setProperties(Properties properties) {
|
|
||||||
PropertyMapper.newInstance(properties)
|
|
||||||
.whenNotBlank("overflow", Boolean::parseBoolean, this::setOverflow)
|
|
||||||
.whenNotBlank("dbType", DbType::getDbType, this::setDbType)
|
|
||||||
.whenNotBlank("dialect", ClassUtils::newInstance, this::setDialect)
|
|
||||||
.whenNotBlank("maxLimit", Long::parseLong, this::setMaxLimit)
|
|
||||||
.whenNotBlank("optimizeJoin", Boolean::parseBoolean, this::setOptimizeJoin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -28,6 +28,7 @@ import com.chushang.common.mybatis.resolver.SqlFilterArgumentResolver;
|
||||||
import org.apache.ibatis.session.SqlSessionFactory;
|
import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
@ -50,8 +51,11 @@ import java.util.Set;
|
||||||
@MapperScan({"com.chushang.**.mapper"})
|
@MapperScan({"com.chushang.**.mapper"})
|
||||||
public class MybatisAutoConfiguration implements WebMvcConfigurer {
|
public class MybatisAutoConfiguration implements WebMvcConfigurer {
|
||||||
|
|
||||||
@Autowired
|
// @Autowired
|
||||||
MybatisPlusProperties mybatisPlusProperties;
|
// MybatisPlusProperties mybatisPlusProperties;
|
||||||
|
// @Value("${mybatis-plus.global-config.refresh.enable:false}")
|
||||||
|
// private boolean refreshMapper;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SQL 过滤器避免SQL 注入
|
* SQL 过滤器避免SQL 注入
|
||||||
|
|
@ -84,19 +88,19 @@ public class MybatisAutoConfiguration implements WebMvcConfigurer {
|
||||||
return new MybatisPlusMetaObjectHandler();
|
return new MybatisPlusMetaObjectHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
// @Bean
|
||||||
public MybatisPlusMapperRefresh mybatisPlusMapperRefresh(ApplicationContext applicationContext, SqlSessionFactory sqlSessionFactory){
|
// public MybatisPlusMapperRefresh mybatisPlusMapperRefresh(ApplicationContext applicationContext, SqlSessionFactory sqlSessionFactory){
|
||||||
Set<Resource> mapperLocations = new LinkedHashSet<>();
|
// Set<Resource> mapperLocations = new LinkedHashSet<>();
|
||||||
for (String xx : mybatisPlusProperties.getMapperLocations()) {
|
// for (String xx : mybatisPlusProperties.getMapperLocations()) {
|
||||||
try {
|
// try {
|
||||||
mapperLocations.addAll(Arrays.asList(applicationContext.getResources(xx)));
|
// mapperLocations.addAll(Arrays.asList(applicationContext.getResources(xx)));
|
||||||
} catch (Exception ignored) {
|
// } catch (Exception ignored) {
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return new MybatisPlusMapperRefresh(mapperLocations.toArray(new Resource[mapperLocations.size()]),
|
// return new MybatisPlusMapperRefresh(mapperLocations.toArray(new Resource[mapperLocations.size()]),
|
||||||
sqlSessionFactory,
|
// sqlSessionFactory,
|
||||||
10,
|
// 10,
|
||||||
5);
|
// 5, refreshMapper);
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,14 +53,16 @@ public class MybatisPlusMapperRefresh implements Runnable {
|
||||||
* 刷新间隔时间
|
* 刷新间隔时间
|
||||||
*/
|
*/
|
||||||
private int sleepSeconds = 20;
|
private int sleepSeconds = 20;
|
||||||
|
private boolean refreshMapper;
|
||||||
|
|
||||||
public MybatisPlusMapperRefresh(Resource[] mapperLocations, SqlSessionFactory sqlSessionFactory, int delaySeconds,
|
public MybatisPlusMapperRefresh(Resource[] mapperLocations, SqlSessionFactory sqlSessionFactory, int delaySeconds,
|
||||||
int sleepSeconds) {
|
int sleepSeconds, boolean refreshMapper) {
|
||||||
this.mapperLocations = mapperLocations.clone();
|
this.mapperLocations = mapperLocations.clone();
|
||||||
this.sqlSessionFactory = sqlSessionFactory;
|
this.sqlSessionFactory = sqlSessionFactory;
|
||||||
this.delaySeconds = delaySeconds;
|
this.delaySeconds = delaySeconds;
|
||||||
this.sleepSeconds = sleepSeconds;
|
this.sleepSeconds = sleepSeconds;
|
||||||
this.configuration = sqlSessionFactory.getConfiguration();
|
this.configuration = sqlSessionFactory.getConfiguration();
|
||||||
|
this.refreshMapper = refreshMapper;
|
||||||
this.run();
|
this.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,10 +75,9 @@ public class MybatisPlusMapperRefresh implements Runnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final GlobalConfig globalConfig = GlobalConfigUtils.getGlobalConfig(configuration);
|
|
||||||
/*
|
/*
|
||||||
*/
|
*/
|
||||||
if (globalConfig.isRefreshMapper()) {
|
if (refreshMapper) {
|
||||||
beforeTime = SystemClock.now();
|
beforeTime = SystemClock.now();
|
||||||
final MybatisPlusMapperRefresh runnable = this;
|
final MybatisPlusMapperRefresh runnable = this;
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
|
|
|
||||||
|
|
@ -7,17 +7,15 @@ import com.chushang.redis.cache.PlusSpringCacheManager;
|
||||||
import com.chushang.redis.config.properties.RedissonProperties;
|
import com.chushang.redis.config.properties.RedissonProperties;
|
||||||
import com.chushang.redis.hanlder.KeyPrefixHandler;
|
import com.chushang.redis.hanlder.KeyPrefixHandler;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.redisson.codec.JsonJacksonCodec;
|
import org.redisson.codec.JsonJacksonCodec;
|
||||||
import org.redisson.spring.starter.RedissonAutoConfigurationCustomizer;
|
import org.redisson.spring.starter.RedissonAutoConfigurationCustomizer;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
||||||
import org.springframework.cache.CacheManager;
|
import org.springframework.cache.CacheManager;
|
||||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
|
||||||
import org.springframework.cache.annotation.EnableCaching;
|
import org.springframework.cache.annotation.EnableCaching;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
@ -29,15 +27,13 @@ import java.util.stream.Collectors;
|
||||||
* @date 2023/1/17 16:27
|
* @date 2023/1/17 16:27
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@AutoConfiguration
|
|
||||||
@EnableCaching
|
@EnableCaching
|
||||||
@RequiredArgsConstructor
|
@Component
|
||||||
@EnableConfigurationProperties(RedissonProperties.class)
|
public class RedisConfiguration {
|
||||||
public class RedisConfiguration extends CachingConfigurerSupport {
|
@Resource
|
||||||
|
private RedissonProperties redissonProperties;
|
||||||
private final RedissonProperties redissonProperties;
|
@Resource
|
||||||
private final ObjectMapper objectMapper;
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public RedissonAutoConfigurationCustomizer redissonCustomizer() {
|
public RedissonAutoConfigurationCustomizer redissonCustomizer() {
|
||||||
|
|
@ -52,6 +48,9 @@ public class RedisConfiguration extends CachingConfigurerSupport {
|
||||||
if (ObjectUtil.isNotNull(singleServerConfig)) {
|
if (ObjectUtil.isNotNull(singleServerConfig)) {
|
||||||
String address = singleServerConfig.getAddress();
|
String address = singleServerConfig.getAddress();
|
||||||
AssertUtil.invalidate(StringUtils.isEmpty(address), "redisson 配置错误");
|
AssertUtil.invalidate(StringUtils.isEmpty(address), "redisson 配置错误");
|
||||||
|
if (!address.contains("redis://")){
|
||||||
|
address = "redis://" + address;
|
||||||
|
}
|
||||||
// 使用单机模式
|
// 使用单机模式
|
||||||
config.useSingleServer()
|
config.useSingleServer()
|
||||||
.setClientName(redissonProperties.getClientName())
|
.setClientName(redissonProperties.getClientName())
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import lombok.NoArgsConstructor;
|
||||||
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 org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @auther: zhao
|
* @auther: zhao
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||||
com.chushang.redis.config.RedisConfiguration
|
com.chushang.redis.config.RedisConfiguration,\
|
||||||
|
com.chushang.redis.config.properties.RedissonProperties
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,9 @@
|
||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<packaging>jar</packaging>
|
|
||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
<artifactId>chushang-common-security</artifactId>
|
<artifactId>chushang-common-security</artifactId>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.chushang</groupId>
|
<groupId>com.chushang</groupId>
|
||||||
|
|
@ -24,8 +18,7 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.chushang</groupId>
|
<groupId>com.chushang</groupId>
|
||||||
<artifactId>system-feign</artifactId>
|
<artifactId>chushang-common-feign</artifactId>
|
||||||
<version>1.0.0</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import com.chushang.common.core.exception.auth.NotPermissionException;
|
||||||
import com.chushang.common.core.exception.auth.NotRoleException;
|
import com.chushang.common.core.exception.auth.NotRoleException;
|
||||||
import com.chushang.common.core.util.SpringUtils;
|
import com.chushang.common.core.util.SpringUtils;
|
||||||
import com.chushang.common.core.util.StringUtils;
|
import com.chushang.common.core.util.StringUtils;
|
||||||
import com.chushang.system.entity.vo.LoginUser;
|
import com.chushang.security.entity.vo.LoginUser;
|
||||||
import org.springframework.util.PatternMatchUtils;
|
import org.springframework.util.PatternMatchUtils;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package com.chushang.security.auth;
|
||||||
|
|
||||||
import com.chushang.security.annotation.RequiresPermissions;
|
import com.chushang.security.annotation.RequiresPermissions;
|
||||||
import com.chushang.security.annotation.RequiresRoles;
|
import com.chushang.security.annotation.RequiresRoles;
|
||||||
import com.chushang.system.entity.vo.LoginUser;
|
import com.chushang.security.entity.vo.LoginUser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Token 权限验证工具类
|
* Token 权限验证工具类
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package com.chushang.system.entity.vo;
|
package com.chushang.security.entity.vo;
|
||||||
|
|
||||||
import com.chushang.system.entity.po.SysUser;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
@ -11,7 +10,7 @@ import java.util.Set;
|
||||||
* by zhaowenyuan create 2022/5/19 12:09
|
* by zhaowenyuan create 2022/5/19 12:09
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class LoginUser implements Serializable
|
public class LoginUser<T> implements Serializable
|
||||||
{
|
{
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|
@ -58,7 +57,7 @@ public class LoginUser implements Serializable
|
||||||
/**
|
/**
|
||||||
* 用户信息
|
* 用户信息
|
||||||
*/
|
*/
|
||||||
private SysUser sysUser;
|
private T sysUser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前用户对应的 数据权限
|
* 当前用户对应的 数据权限
|
||||||
|
|
@ -6,7 +6,7 @@ import com.chushang.security.utils.SecurityUtils;
|
||||||
import com.chushang.common.core.constant.SecurityConstants;
|
import com.chushang.common.core.constant.SecurityConstants;
|
||||||
import com.chushang.common.core.util.ServletUtils;
|
import com.chushang.common.core.util.ServletUtils;
|
||||||
import com.chushang.common.core.util.StringUtils;
|
import com.chushang.common.core.util.StringUtils;
|
||||||
import com.chushang.system.entity.vo.LoginUser;
|
import com.chushang.security.entity.vo.LoginUser;
|
||||||
import org.springframework.web.method.HandlerMethod;
|
import org.springframework.web.method.HandlerMethod;
|
||||||
import org.springframework.web.servlet.AsyncHandlerInterceptor;
|
import org.springframework.web.servlet.AsyncHandlerInterceptor;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import com.chushang.common.core.constant.CacheConstants;
|
||||||
import com.chushang.common.core.constant.SecurityConstants;
|
import com.chushang.common.core.constant.SecurityConstants;
|
||||||
import com.chushang.common.core.util.*;
|
import com.chushang.common.core.util.*;
|
||||||
import com.chushang.security.utils.SecurityUtils;
|
import com.chushang.security.utils.SecurityUtils;
|
||||||
import com.chushang.system.entity.vo.LoginUser;
|
import com.chushang.security.entity.vo.LoginUser;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.redisson.api.RBucket;
|
import org.redisson.api.RBucket;
|
||||||
import org.redisson.api.RKeys;
|
import org.redisson.api.RKeys;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import com.chushang.common.core.constant.TokenConstants;
|
||||||
import com.chushang.common.core.util.ServletUtils;
|
import com.chushang.common.core.util.ServletUtils;
|
||||||
import com.chushang.common.core.util.StringUtils;
|
import com.chushang.common.core.util.StringUtils;
|
||||||
import com.chushang.security.auth.AuthUtil;
|
import com.chushang.security.auth.AuthUtil;
|
||||||
import com.chushang.system.entity.vo.LoginUser;
|
import com.chushang.security.entity.vo.LoginUser;
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
@ -17,7 +17,7 @@ import java.util.Set;
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
public class SecurityUtils
|
public class SecurityUtils<T>
|
||||||
{
|
{
|
||||||
public static final String PA_SA = "%s:%s";
|
public static final String PA_SA = "%s:%s";
|
||||||
/**
|
/**
|
||||||
|
|
@ -31,7 +31,7 @@ public class SecurityUtils
|
||||||
public static boolean isAdmin(){
|
public static boolean isAdmin(){
|
||||||
Integer userId = SecurityContextHolder.getUserId();
|
Integer userId = SecurityContextHolder.getUserId();
|
||||||
|
|
||||||
LoginUser loginUser = getLoginUser();
|
LoginUser<?> loginUser = getLoginUser();
|
||||||
Set<String> roles = loginUser.getRoles();
|
Set<String> roles = loginUser.getRoles();
|
||||||
// 包含 admin 的账号 或者 id == 1 的就是 admin -- 必须是 admin 的才是超管权限
|
// 包含 admin 的账号 或者 id == 1 的就是 admin -- 必须是 admin 的才是超管权限
|
||||||
boolean flag = roles.contains(AuthUtil.SUPER_ADMIN);
|
boolean flag = roles.contains(AuthUtil.SUPER_ADMIN);
|
||||||
|
|
|
||||||
|
|
@ -17,19 +17,7 @@
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>org.redisson</groupId>
|
|
||||||
<artifactId>redisson-spring-boot-starter</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.chushang</groupId>
|
|
||||||
<artifactId>system-feign</artifactId>
|
|
||||||
<version>1.0.0</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.chushang</groupId>
|
|
||||||
<artifactId>chushang-common-security</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<!--注册中心客户端-->
|
<!--注册中心客户端-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
|
@ -42,9 +30,12 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.chushang</groupId>
|
<groupId>com.chushang</groupId>
|
||||||
<artifactId>chushang-common-security</artifactId>
|
<artifactId>system-feign</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
<scope>compile</scope>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.chushang</groupId>
|
||||||
|
<artifactId>chushang-common-redis</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.chushang;
|
||||||
|
|
||||||
|
import com.chushang.common.core.enums.AppStartType;
|
||||||
|
import com.chushang.common.feign.annotation.EnableOnnFeignClients;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
|
import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||||
|
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 认证授权中心
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
@EnableDiscoveryClient
|
||||||
|
@EnableOnnFeignClients
|
||||||
|
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
|
||||||
|
@ServletComponentScan
|
||||||
|
public class AuthApplication extends SpringBootServletInitializer
|
||||||
|
{
|
||||||
|
private final static Logger log = LoggerFactory.getLogger(AuthApplication.class);
|
||||||
|
private final static String APP_NAME = "系统鉴权服务应用";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||||
|
log.info(AppStartType.START_FORMAT, AppStartType.web_server.type(), APP_NAME);
|
||||||
|
SpringApplicationBuilder run = application.sources(AuthApplication.class);
|
||||||
|
log.info(AppStartType.END_FORMAT, AppStartType.web_server.type(), APP_NAME);
|
||||||
|
return run;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
log.info(AppStartType.START_FORMAT, AppStartType.main.type(), APP_NAME);
|
||||||
|
SpringApplication.run(AuthApplication.class, args);
|
||||||
|
log.info(AppStartType.END_FORMAT, AppStartType.main.type(), APP_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
package com.chushang;
|
|
||||||
|
|
||||||
import com.chushang.common.feign.annotation.EnableOnnFeignClients;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
|
||||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 认证授权中心
|
|
||||||
*
|
|
||||||
* @author ruoyi
|
|
||||||
*/
|
|
||||||
@EnableDiscoveryClient
|
|
||||||
@EnableOnnFeignClients
|
|
||||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
|
|
||||||
public class SanyiAuthApplication
|
|
||||||
{
|
|
||||||
public static void main(String[] args)
|
|
||||||
{
|
|
||||||
SpringApplication.run(SanyiAuthApplication.class, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -8,7 +8,7 @@ import com.chushang.security.auth.AuthUtil;
|
||||||
import com.chushang.security.service.TokenService;
|
import com.chushang.security.service.TokenService;
|
||||||
import com.chushang.security.utils.SecurityUtils;
|
import com.chushang.security.utils.SecurityUtils;
|
||||||
import com.chushang.system.entity.bo.LoginBody;
|
import com.chushang.system.entity.bo.LoginBody;
|
||||||
import com.chushang.system.entity.vo.LoginUser;
|
import com.chushang.security.entity.vo.LoginUser;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
@ -24,7 +24,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor(onConstructor_ = @Autowired)
|
@RequiredArgsConstructor(onConstructor_ = @Autowired)
|
||||||
@RequestMapping(value = "")
|
|
||||||
public class UserController
|
public class UserController
|
||||||
{
|
{
|
||||||
final TokenService tokenService;
|
final TokenService tokenService;
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import com.chushang.security.utils.SecurityUtils;
|
||||||
import com.chushang.system.entity.enums.LoginStatusEnum;
|
import com.chushang.system.entity.enums.LoginStatusEnum;
|
||||||
import com.chushang.system.entity.po.SysLoginInfo;
|
import com.chushang.system.entity.po.SysLoginInfo;
|
||||||
import com.chushang.system.entity.po.SysUser;
|
import com.chushang.system.entity.po.SysUser;
|
||||||
import com.chushang.system.entity.vo.LoginUser;
|
import com.chushang.security.entity.vo.LoginUser;
|
||||||
import com.chushang.system.feign.RemoteLoginInfoService;
|
import com.chushang.system.feign.RemoteLoginInfoService;
|
||||||
import com.chushang.system.feign.RemoteUserService;
|
import com.chushang.system.feign.RemoteUserService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
@ -33,11 +33,11 @@ public class UserService {
|
||||||
/**
|
/**
|
||||||
* 登录
|
* 登录
|
||||||
*/
|
*/
|
||||||
public LoginUser login(String username, String password)
|
public LoginUser<SysUser> login(String username, String password)
|
||||||
{
|
{
|
||||||
// 查询用户信息
|
// 查询用户信息
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
Result<LoginUser> rLoginUser = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
|
Result<LoginUser<SysUser>> rLoginUser = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
log.info("time : {}",end - start);
|
log.info("time : {}",end - start);
|
||||||
if (Result.FAIL_CODE == rLoginUser.getCode()){
|
if (Result.FAIL_CODE == rLoginUser.getCode()){
|
||||||
|
|
@ -48,7 +48,7 @@ public class UserService {
|
||||||
recordLoginInfo(username, LoginStatusEnum.LOGIN_FAIL_STATUS, "登录用户不存在");
|
recordLoginInfo(username, LoginStatusEnum.LOGIN_FAIL_STATUS, "登录用户不存在");
|
||||||
throw new ResultException("登录用户:" + username + " 不存在");
|
throw new ResultException("登录用户:" + username + " 不存在");
|
||||||
}
|
}
|
||||||
LoginUser loginUser = rLoginUser.getData();
|
LoginUser<SysUser> loginUser = rLoginUser.getData();
|
||||||
SysUser sysUser = loginUser.getSysUser();
|
SysUser sysUser = loginUser.getSysUser();
|
||||||
Boolean status = sysUser.getStatus();
|
Boolean status = sysUser.getStatus();
|
||||||
if (!status)
|
if (!status)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,53 @@
|
||||||
|
server:
|
||||||
|
#开启优雅停机
|
||||||
|
shutdown: graceful
|
||||||
|
port: 8083
|
||||||
|
servlet:
|
||||||
|
context-path: /auth
|
||||||
|
tomcat:
|
||||||
|
uri-encoding: UTF-8
|
||||||
|
threads:
|
||||||
|
max: 800
|
||||||
|
min-spare: 100
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: @artifactId@
|
||||||
|
main:
|
||||||
|
allow-circular-references: true
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
|
cloud:
|
||||||
|
loadbalancer:
|
||||||
|
retry:
|
||||||
|
enabled: true
|
||||||
|
# feign 配置
|
||||||
|
feign:
|
||||||
|
sentinel:
|
||||||
|
enabled: true
|
||||||
|
okhttp:
|
||||||
|
enabled: true
|
||||||
|
httpclient:
|
||||||
|
enabled: false
|
||||||
|
client:
|
||||||
|
config:
|
||||||
|
default:
|
||||||
|
connectTimeout: 10000
|
||||||
|
readTimeout: 10000
|
||||||
|
compression:
|
||||||
|
request:
|
||||||
|
enabled: true
|
||||||
|
response:
|
||||||
|
enabled: true
|
||||||
|
# 暴露监控端点
|
||||||
|
management:
|
||||||
|
endpoints:
|
||||||
|
web:
|
||||||
|
exposure:
|
||||||
|
include: "*"
|
||||||
|
endpoint:
|
||||||
|
health:
|
||||||
|
show-details: ALWAYS
|
||||||
|
# 安全配置
|
||||||
|
logging:
|
||||||
|
config: classpath:logback-nacos.xml
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,32 +1,29 @@
|
||||||
server:
|
|
||||||
tomcat:
|
|
||||||
uri-encoding: UTF-8
|
|
||||||
threads:
|
|
||||||
max: 1000
|
|
||||||
min-spare: 30
|
|
||||||
connection-timeout: 5000ms
|
|
||||||
port: 8080
|
|
||||||
servlet:
|
|
||||||
context-path: /sanyi/auth
|
|
||||||
spring:
|
spring:
|
||||||
application:
|
config:
|
||||||
name: @artifactId@
|
import:
|
||||||
|
-: "classpath:application.yml"
|
||||||
cloud:
|
cloud:
|
||||||
|
loadbalancer:
|
||||||
|
cache:
|
||||||
|
enabled: false
|
||||||
nacos:
|
nacos:
|
||||||
|
server-addr: ${nacos.host}
|
||||||
|
username: ${nacos.username}
|
||||||
|
password: ${nacos.password}
|
||||||
discovery:
|
discovery:
|
||||||
server-addr: ${nacos.host}
|
server-addr: ${spring.cloud.nacos.server-addr}
|
||||||
namespace: ${nacos.namespace}
|
namespace: ${nacos.namespace}
|
||||||
group: ${nacos.group}
|
group: ${nacos.group}
|
||||||
|
service: ${spring.application.name}
|
||||||
config:
|
config:
|
||||||
|
server-addr: ${spring.cloud.nacos.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}
|
||||||
server-addr: ${spring.cloud.nacos.discovery.server-addr}
|
file-extension: yaml
|
||||||
file-extension: yml
|
refresh-enabled: true
|
||||||
shared-configs:
|
shared-configs:
|
||||||
- dataId: application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- dataId: application-common.${spring.cloud.nacos.config.file-extension}
|
||||||
group: ${nacos.group}
|
group: ${nacos.group}
|
||||||
|
refresh: ${spring.cloud.nacos.config.refresh-enabled}
|
||||||
profiles:
|
profiles:
|
||||||
active: @profiles.active@
|
active: @profiles.active@
|
||||||
main:
|
|
||||||
allow-bean-definition-overriding: true
|
|
||||||
# auth 应当为单独的服务器, sys 为另一单独服务器
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
<!-- 彩色日志格式 -->
|
<!-- 彩色日志格式 -->
|
||||||
<property name="CONSOLE_LOG_PATTERN"
|
<property name="CONSOLE_LOG_PATTERN"
|
||||||
value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
|
value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr([%X{traceId}]) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
|
||||||
<!-- 彩色日志依赖的渲染类 -->
|
<!-- 彩色日志依赖的渲染类 -->
|
||||||
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
|
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
|
||||||
<conversionRule conversionWord="wex"
|
<conversionRule conversionWord="wex"
|
||||||
|
|
@ -40,7 +40,7 @@
|
||||||
<maxFileSize>500MB</maxFileSize>
|
<maxFileSize>500MB</maxFileSize>
|
||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||||
<level>info</level>
|
<level>info</level>
|
||||||
|
|
@ -55,7 +55,7 @@
|
||||||
<maxFileSize>500MB</maxFileSize>
|
<maxFileSize>500MB</maxFileSize>
|
||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||||
<level>debug</level>
|
<level>debug</level>
|
||||||
|
|
@ -70,7 +70,7 @@
|
||||||
<maxFileSize>500MB</maxFileSize>
|
<maxFileSize>500MB</maxFileSize>
|
||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||||
<level>error</level>
|
<level>error</level>
|
||||||
|
|
@ -78,8 +78,7 @@
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<!--nacos 心跳 INFO 屏蔽-->
|
<!--nacos 心跳 INFO 屏蔽-->
|
||||||
<logger name="com.alibaba.nacos" level="OFF">
|
<logger name="com.alibaba.cloud.nacos" level="info">
|
||||||
<appender-ref ref="error"/>
|
|
||||||
</logger>
|
</logger>
|
||||||
|
|
||||||
<!-- 使用kafka启用下面配置 -->
|
<!-- 使用kafka启用下面配置 -->
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@
|
||||||
<groupId>commons-io</groupId>
|
<groupId>commons-io</groupId>
|
||||||
<artifactId>commons-io</artifactId>
|
<artifactId>commons-io</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.chushang;
|
||||||
|
|
||||||
|
import com.chushang.common.core.enums.AppStartType;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
|
import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||||
|
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||||
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* by zhaowenyuan create 2022/5/19 11:32
|
||||||
|
*/
|
||||||
|
@EnableDiscoveryClient
|
||||||
|
@SpringBootApplication
|
||||||
|
@ServletComponentScan
|
||||||
|
public class GatewayApplication extends SpringBootServletInitializer {
|
||||||
|
|
||||||
|
private final static Logger log = LoggerFactory.getLogger(GatewayApplication.class);
|
||||||
|
private final static String APP_NAME = "系统网关服务应用";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||||
|
log.info(AppStartType.START_FORMAT, AppStartType.web_server.type(), APP_NAME);
|
||||||
|
SpringApplicationBuilder run = application.sources(GatewayApplication.class);
|
||||||
|
log.info(AppStartType.END_FORMAT, AppStartType.web_server.type(), APP_NAME);
|
||||||
|
return run;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
log.info(AppStartType.START_FORMAT, AppStartType.main.type(), APP_NAME);
|
||||||
|
SpringApplication.run(GatewayApplication.class, args);
|
||||||
|
log.info(AppStartType.END_FORMAT, AppStartType.main.type(), APP_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
package com.chushang;
|
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* by zhaowenyuan create 2022/5/19 11:32
|
|
||||||
*/
|
|
||||||
@EnableDiscoveryClient
|
|
||||||
@SpringBootApplication
|
|
||||||
public class SanyiGatewayApplication {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
SpringApplication.run(SanyiGatewayApplication.class, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -24,7 +24,7 @@ public class RouterFunctionConfiguration {
|
||||||
public RouterFunction routerFunction() {
|
public RouterFunction routerFunction() {
|
||||||
return RouterFunctions.route(
|
return RouterFunctions.route(
|
||||||
RequestPredicates
|
RequestPredicates
|
||||||
.GET("/api/sanyi/captcha.jpg")
|
.GET("/api/captcha.jpg")
|
||||||
.and(RequestPredicates.accept(MediaType.TEXT_PLAIN))
|
.and(RequestPredicates.accept(MediaType.TEXT_PLAIN))
|
||||||
, validateCodeHandler
|
, validateCodeHandler
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
package com.chushang.gateway.filter;
|
package com.chushang.gateway.filter;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import com.chushang.common.core.constant.CommonConstants;
|
import com.chushang.common.core.constant.CommonConstants;
|
||||||
import com.chushang.common.core.util.IPUtils;
|
import com.chushang.common.core.util.IPUtils;
|
||||||
|
import com.chushang.common.core.util.IdUtils;
|
||||||
|
import com.chushang.common.core.util.ServletUtils;
|
||||||
|
import com.chushang.common.core.util.StringUtils;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||||
|
|
@ -13,6 +17,8 @@ import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zhangran
|
* @author zhangran
|
||||||
* @date 2021/7/13
|
* @date 2021/7/13
|
||||||
|
|
@ -30,14 +36,15 @@ public class ApiLoggingFilter implements GlobalFilter, Ordered {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||||
|
setTraceId(exchange);
|
||||||
exchange.getAttributes().put(START_TIME, System.currentTimeMillis());
|
exchange.getAttributes().put(START_TIME, System.currentTimeMillis());
|
||||||
return chain.filter(exchange).then(Mono.fromRunnable(() -> {
|
return chain.filter(exchange.mutate().build()).then(Mono.fromRunnable(() -> {
|
||||||
|
ServerHttpRequest request = exchange.getRequest();
|
||||||
if (log.isInfoEnabled()) {
|
if (log.isInfoEnabled()) {
|
||||||
String info = String.format("Method:{%s} Host:{%s} Path:{%s} Query:{%s}",
|
String info = String.format("Method:{%s} Host:{%s} Path:{%s} Query:{%s}",
|
||||||
exchange.getRequest().getMethod().name(), exchange.getRequest().getURI().getHost(),
|
exchange.getRequest().getMethod().name(), exchange.getRequest().getURI().getHost(),
|
||||||
exchange.getRequest().getURI().getPath(), exchange.getRequest().getQueryParams());
|
exchange.getRequest().getURI().getPath(), exchange.getRequest().getQueryParams());
|
||||||
ServerHttpRequest request = exchange.getRequest();
|
String token = request.getHeaders().getFirst(CommonConstants.HEAD_TOKEN_KEY);
|
||||||
String sanyiToken = request.getHeaders().getFirst(CommonConstants.HEAD_TOKEN_KEY);
|
|
||||||
Long startTime = exchange.getAttribute(START_TIME);
|
Long startTime = exchange.getAttribute(START_TIME);
|
||||||
if (startTime != null) {
|
if (startTime != null) {
|
||||||
Long executeTime = (System.currentTimeMillis() - startTime);
|
Long executeTime = (System.currentTimeMillis() - startTime);
|
||||||
|
|
@ -50,12 +57,22 @@ public class ApiLoggingFilter implements GlobalFilter, Ordered {
|
||||||
// 状态码
|
// 状态码
|
||||||
int code = statusCode != null ? statusCode.value() : 500;
|
int code = statusCode != null ? statusCode.value() : 500;
|
||||||
// 此处 添加 到 plumelog 中, 进行数据统计
|
// 此处 添加 到 plumelog 中, 进行数据统计
|
||||||
log.info("来自IP地址: {}的请求接口: {}, 请求信息: {},请求人: {} , 响应状态码: {}, 请求耗时: {}ms", ip, api, info, sanyiToken, code, executeTime);
|
log.info("来自IP地址: {}的请求接口: {}, 请求信息: {},请求人: {} , 响应状态码: {}, 请求耗时: {}ms", ip, api, info, token, code, executeTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void setTraceId(ServerWebExchange exchange){
|
||||||
|
String traceId = exchange.getAttribute(CommonConstants.TRACE_ID);
|
||||||
|
if (StringUtils.isEmpty(traceId)){
|
||||||
|
log.info("traceId : {}", traceId);
|
||||||
|
traceId = IdUtils.getId(32);
|
||||||
|
exchange.getAttributes().put(CommonConstants.TRACE_ID, ServletUtils.urlEncode(traceId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getOrder() {
|
public int getOrder() {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package com.chushang.gateway.filter;
|
package com.chushang.gateway.filter;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
import com.chushang.gateway.config.GatewayContext;
|
import com.chushang.gateway.config.GatewayContext;
|
||||||
import io.netty.buffer.ByteBufAllocator;
|
import io.netty.buffer.ByteBufAllocator;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
@ -43,7 +45,7 @@ import java.util.Objects;
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SanyiRequestGlobalFilter implements GlobalFilter, Ordered
|
public class RequestGlobalFilter implements GlobalFilter, Ordered
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -39,9 +39,8 @@ public class GatewayExceptionHandler implements ErrorWebExceptionHandler
|
||||||
{
|
{
|
||||||
msg = "服务未找到";
|
msg = "服务未找到";
|
||||||
}
|
}
|
||||||
else if (ex instanceof ResponseStatusException)
|
else if (ex instanceof ResponseStatusException responseStatusException)
|
||||||
{
|
{
|
||||||
ResponseStatusException responseStatusException = (ResponseStatusException) ex;
|
|
||||||
msg = responseStatusException.getMessage();
|
msg = responseStatusException.getMessage();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -49,7 +48,7 @@ public class GatewayExceptionHandler implements ErrorWebExceptionHandler
|
||||||
msg = "内部服务器错误";
|
msg = "内部服务器错误";
|
||||||
}
|
}
|
||||||
|
|
||||||
log.error("[网关异常处理]请求路径:{},异常信息:{}", exchange.getRequest().getPath(), ex);
|
log.error("[网关异常处理]请求路径:{},异常信息:", exchange.getRequest().getPath(), ex);
|
||||||
|
|
||||||
return ServletUtils.webFluxResponseWriter(response, msg);
|
return ServletUtils.webFluxResponseWriter(response, msg);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ public class ValidateCodeServiceImpl implements ValidateCodeService {
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@Override
|
@Override
|
||||||
public void checkCaptcha(String code, String uuid) throws ResultException, ExecutionException, InterruptedException {
|
public void checkCaptcha(String code, String uuid) throws ResultException, ExecutionException, InterruptedException {
|
||||||
if (!"sanyi".equals(code)) {
|
if (!"chushang".equals(code)) {
|
||||||
if (StringUtils.isEmpty(code)) {
|
if (StringUtils.isEmpty(code)) {
|
||||||
throw new ResultException("验证码不能为空");
|
throw new ResultException("验证码不能为空");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,104 @@
|
||||||
|
server:
|
||||||
|
#开启优雅停机
|
||||||
|
shutdown: graceful
|
||||||
|
port: 9999
|
||||||
|
servlet:
|
||||||
|
context-path: /api
|
||||||
|
tomcat:
|
||||||
|
uri-encoding: UTF-8
|
||||||
|
threads:
|
||||||
|
max: 800
|
||||||
|
min-spare: 100
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: @artifactId@
|
||||||
|
main:
|
||||||
|
allow-circular-references: true
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
|
cloud:
|
||||||
|
loadbalancer:
|
||||||
|
retry:
|
||||||
|
enabled: true
|
||||||
|
gateway:
|
||||||
|
discovery:
|
||||||
|
locator:
|
||||||
|
# 配置之后访问时无需大写
|
||||||
|
lower-case-service-id: true
|
||||||
|
enabled: true # 是否开启,默认为 false 关闭
|
||||||
|
# 跨域配置
|
||||||
|
globalcors:
|
||||||
|
corsConfigurations:
|
||||||
|
'[/**]':
|
||||||
|
allowedOrigins: '*'
|
||||||
|
allowedHeaders: '*'
|
||||||
|
allowedMethods:
|
||||||
|
- GET
|
||||||
|
- HEAD
|
||||||
|
- POST
|
||||||
|
- PUT
|
||||||
|
- DELETE
|
||||||
|
- OPTIONS
|
||||||
|
add-to-simple-url-handler-mapping: true
|
||||||
|
routes:
|
||||||
|
# 认证中心
|
||||||
|
- id: auth-service
|
||||||
|
uri: lb://auth-service
|
||||||
|
predicates:
|
||||||
|
- Path=/api/auth/**
|
||||||
|
filters:
|
||||||
|
- StripPrefix=1
|
||||||
|
# 验证码处理
|
||||||
|
- CacheRequestFilter
|
||||||
|
- ValidateCodeFilter
|
||||||
|
# 系统模块
|
||||||
|
- id: system-service
|
||||||
|
uri: lb://system-service
|
||||||
|
predicates:
|
||||||
|
- Path=/api/system/**
|
||||||
|
filters:
|
||||||
|
- StripPrefix=1
|
||||||
|
# 定时任务
|
||||||
|
- id: job-service
|
||||||
|
uri: lb://job-service
|
||||||
|
predicates:
|
||||||
|
- Path=/api/job/**
|
||||||
|
filters:
|
||||||
|
- StripPrefix=1
|
||||||
|
#default-filters:
|
||||||
|
# - DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin
|
||||||
|
# # 默认限流
|
||||||
|
# - name: RequestRateLimiter
|
||||||
|
# args:
|
||||||
|
# # how many requests per second you want a user to be allowed to do, without any dropped requests
|
||||||
|
# # 每秒允许用户执行多少请求,不允许删除任何请求,这是令牌桶被填满的速率
|
||||||
|
# redis-rate-limiter.replenishRate: 10
|
||||||
|
# # the maximum number of requests a user is allowed to do in a single second
|
||||||
|
# # 用户在一秒钟内允许执行的最大请求数,这是令牌桶可以容纳的令牌数量。将此值设置为0将阻止所有请求。
|
||||||
|
# redis-rate-limiter.burstCapacity: 20
|
||||||
|
# # how many tokens a request costs. This is the number of tokens taken from the bucket for each request and defaults to 1.
|
||||||
|
# # 一个请求需要多少令牌 这是为每个请求从桶中获取的令牌数量,默认为1。
|
||||||
|
# redis-rate-limiter.requestedTokens: 1
|
||||||
|
# key-resolver: "#{@remoteAddrKeyResolver}"
|
||||||
|
# 安全配置
|
||||||
|
security:
|
||||||
|
# 验证码
|
||||||
|
captcha:
|
||||||
|
enabled: true
|
||||||
|
type: char
|
||||||
|
# 防止XSS攻击
|
||||||
|
xss:
|
||||||
|
enabled: true
|
||||||
|
#excludeUrls:
|
||||||
|
# - /api/auth/login
|
||||||
|
# 不校验白名单
|
||||||
|
ignore:
|
||||||
|
whites:
|
||||||
|
- /auth/logout
|
||||||
|
- /auth/login
|
||||||
|
- /auth/register
|
||||||
|
- /manager/remote/**
|
||||||
|
- /demo/**
|
||||||
|
logging:
|
||||||
|
config: classpath:logback-nacos.xml
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,35 +1,29 @@
|
||||||
server:
|
|
||||||
tomcat:
|
|
||||||
uri-encoding: UTF-8
|
|
||||||
threads:
|
|
||||||
max: 1000
|
|
||||||
min-spare: 30
|
|
||||||
connection-timeout: 50000ms
|
|
||||||
port: 9999
|
|
||||||
servlet:
|
|
||||||
context-path: /api/sanyi
|
|
||||||
spring:
|
spring:
|
||||||
# codec:
|
config:
|
||||||
# max-in-memory-size: 5242880
|
import:
|
||||||
application:
|
-: "classpath:application.yml"
|
||||||
name: @artifactId@
|
|
||||||
cloud:
|
cloud:
|
||||||
|
loadbalancer:
|
||||||
|
cache:
|
||||||
|
enabled: false
|
||||||
nacos:
|
nacos:
|
||||||
|
server-addr: ${nacos.host}
|
||||||
|
username: ${nacos.username}
|
||||||
|
password: ${nacos.password}
|
||||||
discovery:
|
discovery:
|
||||||
server-addr: ${nacos.host}
|
server-addr: ${spring.cloud.nacos.server-addr}
|
||||||
namespace: ${nacos.namespace}
|
namespace: ${nacos.namespace}
|
||||||
group: ${nacos.group}
|
group: ${nacos.group}
|
||||||
|
service: ${spring.application.name}
|
||||||
config:
|
config:
|
||||||
|
server-addr: ${spring.cloud.nacos.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}
|
||||||
server-addr: ${spring.cloud.nacos.discovery.server-addr}
|
file-extension: yaml
|
||||||
file-extension: yml
|
refresh-enabled: true
|
||||||
shared-configs:
|
shared-configs:
|
||||||
- dataId: application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- dataId: application-common.${spring.cloud.nacos.config.file-extension}
|
||||||
group: ${nacos.group}
|
group: ${nacos.group}
|
||||||
|
refresh: ${spring.cloud.nacos.config.refresh-enabled}
|
||||||
profiles:
|
profiles:
|
||||||
active: @profiles.active@
|
active: @profiles.active@
|
||||||
main:
|
|
||||||
allow-bean-definition-overriding: true
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
<!-- 彩色日志格式 -->
|
<!-- 彩色日志格式 -->
|
||||||
<property name="CONSOLE_LOG_PATTERN"
|
<property name="CONSOLE_LOG_PATTERN"
|
||||||
value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
|
value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr([%X{traceId}]) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
|
||||||
<!-- 彩色日志依赖的渲染类 -->
|
<!-- 彩色日志依赖的渲染类 -->
|
||||||
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
|
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
|
||||||
<conversionRule conversionWord="wex"
|
<conversionRule conversionWord="wex"
|
||||||
|
|
@ -40,7 +40,7 @@
|
||||||
<maxFileSize>500MB</maxFileSize>
|
<maxFileSize>500MB</maxFileSize>
|
||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||||
<level>info</level>
|
<level>info</level>
|
||||||
|
|
@ -55,7 +55,7 @@
|
||||||
<maxFileSize>500MB</maxFileSize>
|
<maxFileSize>500MB</maxFileSize>
|
||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||||
<level>debug</level>
|
<level>debug</level>
|
||||||
|
|
@ -70,7 +70,7 @@
|
||||||
<maxFileSize>500MB</maxFileSize>
|
<maxFileSize>500MB</maxFileSize>
|
||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||||
<level>error</level>
|
<level>error</level>
|
||||||
|
|
@ -78,22 +78,21 @@
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<!--nacos 心跳 INFO 屏蔽-->
|
<!--nacos 心跳 INFO 屏蔽-->
|
||||||
<logger name="com.alibaba.nacos" level="OFF">
|
<logger name="com.alibaba.cloud.nacos" level="info">
|
||||||
<appender-ref ref="error"/>
|
|
||||||
</logger>
|
</logger>
|
||||||
|
|
||||||
<!-- 使用kafka启用下面配置 -->
|
<!-- 使用kafka启用下面配置 -->
|
||||||
<!-- <appender name="plumelog" class="com.plumelog.logback.appender.KafkaAppender">-->
|
<!-- <appender name="plumelog" class="com.plumelog.logback.appender.KafkaAppender">-->
|
||||||
<!-- <appName>${spring.application.name}</appName>-->
|
<!-- <appName>${spring.application.name}</appName>-->
|
||||||
<!-- <kafkaHosts>${log.hosts}</kafkaHosts>-->
|
<!-- <kafkaHosts>${log.hosts}</kafkaHosts>-->
|
||||||
<!-- </appender>-->
|
<!-- </appender>-->
|
||||||
|
|
||||||
<!--redis-->
|
<!--redis-->
|
||||||
<!-- <appender name="redisPlumelog" class="com.plumelog.logback.appender.RedisAppender">-->
|
<!-- <appender name="redisPlumelog" class="com.plumelog.logback.appender.RedisAppender">-->
|
||||||
<!-- <appName>${spring.application.name}</appName>-->
|
<!-- <appName>${spring.application.name}</appName>-->
|
||||||
<!-- <redisHost>${log.redis.hosts}</redisHost>-->
|
<!-- <redisHost>${log.redis.hosts}</redisHost>-->
|
||||||
<!-- <redisAuth>${log.redis.auth}</redisAuth>-->
|
<!-- <redisAuth>${log.redis.auth}</redisAuth>-->
|
||||||
<!-- </appender>-->
|
<!-- </appender>-->
|
||||||
|
|
||||||
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
|
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
|
||||||
<root level="info">
|
<root level="info">
|
||||||
|
|
@ -102,6 +101,6 @@
|
||||||
<appender-ref ref="debug"/>
|
<appender-ref ref="debug"/>
|
||||||
<appender-ref ref="error"/>
|
<appender-ref ref="error"/>
|
||||||
<!-- 输出plumelog -->
|
<!-- 输出plumelog -->
|
||||||
<!-- <appender-ref ref="redisPlumelog"/>-->
|
<!-- <appender-ref ref="redisPlumelog"/>-->
|
||||||
</root>
|
</root>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import com.chushang.SanyiGatewayApplication;
|
import com.chushang.GatewayApplication;
|
||||||
import com.chushang.gateway.service.ValidateCodeService;
|
import com.chushang.gateway.service.ValidateCodeService;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
@ -11,7 +11,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||||
* @author by zhaowenyuan create 2022/8/23 12:10
|
* @author by zhaowenyuan create 2022/8/23 12:10
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = SanyiGatewayApplication.class)
|
@SpringBootTest(classes = GatewayApplication.class)
|
||||||
public class RedisTest {
|
public class RedisTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,6 @@
|
||||||
<groupId>com.chushang</groupId>
|
<groupId>com.chushang</groupId>
|
||||||
<artifactId>chushang-common-mybatis</artifactId>
|
<artifactId>chushang-common-mybatis</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.chushang</groupId>
|
|
||||||
<artifactId>chushang-common-redis</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.minio</groupId>
|
<groupId>io.minio</groupId>
|
||||||
<artifactId>minio</artifactId>
|
<artifactId>minio</artifactId>
|
||||||
|
|
|
||||||
|
|
@ -13,20 +13,6 @@
|
||||||
<groupId>com.chushang</groupId>
|
<groupId>com.chushang</groupId>
|
||||||
<artifactId>oss-feign</artifactId>
|
<artifactId>oss-feign</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.chushang</groupId>
|
|
||||||
<artifactId>chushang-common-security</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<!--注册中心客户端-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<!--配置中心客户端-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,15 @@ package com.chushang.oss;
|
||||||
import com.chushang.common.core.enums.AppStartType;
|
import com.chushang.common.core.enums.AppStartType;
|
||||||
import com.chushang.common.feign.annotation.EnableOnnFeignClients;
|
import com.chushang.common.feign.annotation.EnableOnnFeignClients;
|
||||||
import com.chushang.common.feign.annotation.EnableTransferFeign;
|
import com.chushang.common.feign.annotation.EnableTransferFeign;
|
||||||
import com.chushang.security.annotation.EnableCustomConfig;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @auther: zhao
|
* @auther: zhao
|
||||||
* @date: 2024/4/29 10:50
|
* @date: 2024/4/29 10:50
|
||||||
|
|
@ -17,7 +19,6 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
@EnableDiscoveryClient
|
@EnableDiscoveryClient
|
||||||
@EnableOnnFeignClients
|
@EnableOnnFeignClients
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableCustomConfig
|
|
||||||
@EnableTransferFeign
|
@EnableTransferFeign
|
||||||
public class OssApplication {
|
public class OssApplication {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,8 @@
|
||||||
package com.chushang.oss.service.impl;
|
package com.chushang.oss.service.impl;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.redisson.api.RedissonClient;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @auther: zhao
|
* @auther: zhao
|
||||||
* @date: 2024/4/29 10:25
|
* @date: 2024/4/29 10:25
|
||||||
|
|
@ -14,7 +11,5 @@ import javax.annotation.Resource;
|
||||||
@Service
|
@Service
|
||||||
public class FileSourceService {
|
public class FileSourceService {
|
||||||
|
|
||||||
@Resource
|
|
||||||
RedissonClient redissonClient;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,91 @@
|
||||||
|
server:
|
||||||
|
#开启优雅停机
|
||||||
|
shutdown: graceful
|
||||||
|
port: 8085
|
||||||
|
servlet:
|
||||||
|
context-path: /cs/system
|
||||||
|
tomcat:
|
||||||
|
uri-encoding: UTF-8
|
||||||
|
threads:
|
||||||
|
max: 800
|
||||||
|
min-spare: 100
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: @artifactId@
|
||||||
|
# 如果需要使用读写分离, 此处需要改造, 有没有办法不用改?
|
||||||
|
datasource:
|
||||||
|
type: com.zaxxer.hikari.HikariDataSource
|
||||||
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
|
username: ${conf.jdbc.cs.master.username}
|
||||||
|
password: ${conf.jdbc.cs.master.password}
|
||||||
|
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:
|
||||||
|
restart:
|
||||||
|
enabled: true
|
||||||
|
jackson:
|
||||||
|
default-property-inclusion: ALWAYS
|
||||||
|
time-zone: GMT+8
|
||||||
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
|
# mybaits-plus配置
|
||||||
|
mybatis-plus:
|
||||||
|
# 全局刷新 mapper
|
||||||
|
mapper-locations: classpath:/mapper/**/*.xml
|
||||||
|
global-config:
|
||||||
|
refresh:
|
||||||
|
enable: true
|
||||||
|
db-config:
|
||||||
|
id-type: auto
|
||||||
|
table-underline: true
|
||||||
|
logic-delete-value: 1
|
||||||
|
logic-not-delete-value: 0
|
||||||
|
configuration:
|
||||||
|
map-underscore-to-camel-case: true
|
||||||
|
cache-enabled: false
|
||||||
|
call-setters-on-nulls: true
|
||||||
|
jdbc-type-for-null: 'null'
|
||||||
|
default-enum-type-handler: com.baomidou.mybatisplus.core.handlers.MybatisEnumTypeHandler
|
||||||
|
#log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||||
|
# feign 配置
|
||||||
|
feign:
|
||||||
|
sentinel:
|
||||||
|
enabled: true
|
||||||
|
okhttp:
|
||||||
|
enabled: true
|
||||||
|
httpclient:
|
||||||
|
enabled: false
|
||||||
|
client:
|
||||||
|
config:
|
||||||
|
default:
|
||||||
|
connectTimeout: 10000
|
||||||
|
readTimeout: 10000
|
||||||
|
compression:
|
||||||
|
request:
|
||||||
|
enabled: true
|
||||||
|
response:
|
||||||
|
enabled: true
|
||||||
|
# 暴露监控端点
|
||||||
|
management:
|
||||||
|
endpoints:
|
||||||
|
web:
|
||||||
|
exposure:
|
||||||
|
include: "*"
|
||||||
|
endpoint:
|
||||||
|
health:
|
||||||
|
show-details: ALWAYS
|
||||||
|
|
||||||
|
# 日志监听配置 -- 如果启用的话,需要配置 kafka 的路径
|
||||||
|
logging:
|
||||||
|
config: classpath:logback-nacos.xml
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -9,10 +9,19 @@ server:
|
||||||
servlet:
|
servlet:
|
||||||
context-path: /sanyi/oss
|
context-path: /sanyi/oss
|
||||||
spring:
|
spring:
|
||||||
|
config:
|
||||||
|
import:
|
||||||
|
-: "classpath:application.yml"
|
||||||
|
|
||||||
application:
|
application:
|
||||||
name: @artifactId@
|
name: @artifactId@
|
||||||
cloud:
|
cloud:
|
||||||
|
loadbalancer:
|
||||||
|
cache:
|
||||||
|
enabled: false
|
||||||
nacos:
|
nacos:
|
||||||
|
username: nacos
|
||||||
|
password: nacos
|
||||||
discovery:
|
discovery:
|
||||||
server-addr: ${nacos.host}
|
server-addr: ${nacos.host}
|
||||||
namespace: ${nacos.namespace}
|
namespace: ${nacos.namespace}
|
||||||
|
|
@ -21,10 +30,12 @@ spring:
|
||||||
namespace: ${spring.cloud.nacos.discovery.namespace}
|
namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||||
group: ${spring.cloud.nacos.discovery.group}
|
group: ${spring.cloud.nacos.discovery.group}
|
||||||
server-addr: ${spring.cloud.nacos.discovery.server-addr}
|
server-addr: ${spring.cloud.nacos.discovery.server-addr}
|
||||||
file-extension: yml
|
file-extension: yaml
|
||||||
|
refresh-enabled: true
|
||||||
shared-configs:
|
shared-configs:
|
||||||
- dataId: application-common.${spring.cloud.nacos.config.file-extension}
|
- dataId: application-common.${spring.cloud.nacos.config.file-extension}
|
||||||
group: ${nacos.group}
|
group: ${spring.cloud.nacos.discovery.group}
|
||||||
|
refresh: ${spring.cloud.nacos.config.refresh-enabled}
|
||||||
profiles:
|
profiles:
|
||||||
active: @profiles.active@
|
active: @profiles.active@
|
||||||
main:
|
main:
|
||||||
|
|
|
||||||
|
|
@ -31,5 +31,20 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<!--注册中心客户端-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!--配置中心客户端-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
@ -23,5 +23,34 @@
|
||||||
<module>system-feign</module>
|
<module>system-feign</module>
|
||||||
<module>system-service</module>
|
<module>system-service</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
<dependencies>
|
||||||
|
<!--监控客户端-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>de.codecentric</groupId>
|
||||||
|
<artifactId>spring-boot-admin-starter-client</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!--注册中心客户端-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!--配置中心客户端-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
@ -25,5 +25,9 @@
|
||||||
<groupId>com.chushang</groupId>
|
<groupId>com.chushang</groupId>
|
||||||
<artifactId>chushang-common-feign</artifactId>
|
<artifactId>chushang-common-feign</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.chushang</groupId>
|
||||||
|
<artifactId>chushang-common-security</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
@ -2,8 +2,9 @@ package com.chushang.system.feign;
|
||||||
|
|
||||||
import com.chushang.common.core.constant.SecurityConstants;
|
import com.chushang.common.core.constant.SecurityConstants;
|
||||||
import com.chushang.common.core.web.Result;
|
import com.chushang.common.core.web.Result;
|
||||||
|
import com.chushang.security.entity.vo.LoginUser;
|
||||||
import com.chushang.system.constants.SystemConstants;
|
import com.chushang.system.constants.SystemConstants;
|
||||||
import com.chushang.system.entity.vo.LoginUser;
|
import com.chushang.system.entity.po.SysUser;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
|
@ -26,6 +27,6 @@ public interface RemoteUserService {
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@GetMapping("/info/{username}")
|
@GetMapping("/info/{username}")
|
||||||
Result<LoginUser> getUserInfo(@PathVariable(value = "username") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
Result<LoginUser<SysUser>> getUserInfo(@PathVariable(value = "username") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,45 @@
|
||||||
package com.chushang.system;
|
package com.chushang.system;
|
||||||
|
|
||||||
|
import com.chushang.common.core.enums.AppStartType;
|
||||||
import com.chushang.common.feign.annotation.EnableOnnFeignClients;
|
import com.chushang.common.feign.annotation.EnableOnnFeignClients;
|
||||||
|
import com.chushang.common.feign.annotation.EnableTransferFeign;
|
||||||
import com.chushang.security.annotation.EnableCustomConfig;
|
import com.chushang.security.annotation.EnableCustomConfig;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
|
import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||||
|
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||||
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author by zhaowenyuan create 2022/8/18 17:08
|
* @author by zhaowenyuan create 2022/8/18 17:08
|
||||||
*/
|
*/
|
||||||
@EnableDiscoveryClient
|
@EnableDiscoveryClient
|
||||||
@EnableOnnFeignClients
|
@EnableOnnFeignClients
|
||||||
|
@EnableTransactionManagement
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableCustomConfig
|
@EnableCustomConfig
|
||||||
public class SystemApplication {
|
//启用服务调用的参数传递,包含链路追踪日志
|
||||||
|
@EnableTransferFeign
|
||||||
|
@ServletComponentScan
|
||||||
|
public class SystemApplication extends SpringBootServletInitializer {
|
||||||
|
private final static Logger log = LoggerFactory.getLogger(SystemApplication.class);
|
||||||
|
private final static String APP_NAME = "系统管理服务应用";
|
||||||
|
|
||||||
public static void main(String[] args)
|
@Override
|
||||||
{
|
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||||
|
log.info(AppStartType.START_FORMAT, AppStartType.web_server.type(), APP_NAME);
|
||||||
|
SpringApplicationBuilder run = application.sources(SystemApplication.class);
|
||||||
|
log.info(AppStartType.END_FORMAT, AppStartType.web_server.type(), APP_NAME);
|
||||||
|
return run;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
log.info(AppStartType.START_FORMAT, AppStartType.main.type(), APP_NAME);
|
||||||
SpringApplication.run(SystemApplication.class, args);
|
SpringApplication.run(SystemApplication.class, args);
|
||||||
|
log.info(AppStartType.END_FORMAT, AppStartType.main.type(), APP_NAME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import com.chushang.security.utils.SecurityUtils;
|
||||||
import com.chushang.system.annotation.DataScope;
|
import com.chushang.system.annotation.DataScope;
|
||||||
import com.chushang.system.entity.po.SysRole;
|
import com.chushang.system.entity.po.SysRole;
|
||||||
import com.chushang.system.entity.po.SysUser;
|
import com.chushang.system.entity.po.SysUser;
|
||||||
import com.chushang.system.entity.vo.LoginUser;
|
import com.chushang.security.entity.vo.LoginUser;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.JoinPoint;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
|
@ -71,7 +71,7 @@ public class DataScopeAspect {
|
||||||
|
|
||||||
protected void handleDataScope(final JoinPoint joinPoint) {
|
protected void handleDataScope(final JoinPoint joinPoint) {
|
||||||
// 获取当前的用户
|
// 获取当前的用户
|
||||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
LoginUser<SysUser> loginUser = SecurityUtils.getLoginUser();
|
||||||
if (StringUtils.isNotNull(loginUser)) {
|
if (StringUtils.isNotNull(loginUser)) {
|
||||||
SysUser currentUser = loginUser.getSysUser();
|
SysUser currentUser = loginUser.getSysUser();
|
||||||
// 如果是超级管理员,则不过滤数据
|
// 如果是超级管理员,则不过滤数据
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import com.chushang.security.utils.SecurityUtils;
|
||||||
import com.chushang.system.entity.dto.ListMenuDTO;
|
import com.chushang.system.entity.dto.ListMenuDTO;
|
||||||
import com.chushang.system.entity.po.SysMenu;
|
import com.chushang.system.entity.po.SysMenu;
|
||||||
import com.chushang.system.entity.po.SysUser;
|
import com.chushang.system.entity.po.SysUser;
|
||||||
import com.chushang.system.entity.vo.LoginUser;
|
import com.chushang.security.entity.vo.LoginUser;
|
||||||
import com.chushang.system.service.ISysMenuService;
|
import com.chushang.system.service.ISysMenuService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
@ -153,7 +153,7 @@ public class MenuController {
|
||||||
@GetMapping("/getRouters")
|
@GetMapping("/getRouters")
|
||||||
public AjaxResult getRouters()
|
public AjaxResult getRouters()
|
||||||
{
|
{
|
||||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
LoginUser<SysUser> loginUser = SecurityUtils.getLoginUser();
|
||||||
SysUser sysUser = loginUser.getSysUser();
|
SysUser sysUser = loginUser.getSysUser();
|
||||||
List<SysMenu> menus = menuService.selectMenuTreeByUserId(sysUser);
|
List<SysMenu> menus = menuService.selectMenuTreeByUserId(sysUser);
|
||||||
return AjaxResult.success(menuService.buildMenus(menus));
|
return AjaxResult.success(menuService.buildMenus(menus));
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import com.chushang.system.entity.dto.ListUserDTO;
|
||||||
import com.chushang.system.entity.po.SysRole;
|
import com.chushang.system.entity.po.SysRole;
|
||||||
import com.chushang.system.entity.po.SysUser;
|
import com.chushang.system.entity.po.SysUser;
|
||||||
import com.chushang.system.entity.po.SysUserData;
|
import com.chushang.system.entity.po.SysUserData;
|
||||||
import com.chushang.system.entity.vo.LoginUser;
|
import com.chushang.security.entity.vo.LoginUser;
|
||||||
import com.chushang.system.feign.RemoteUserService;
|
import com.chushang.system.feign.RemoteUserService;
|
||||||
import com.chushang.system.service.ISysPermissionService;
|
import com.chushang.system.service.ISysPermissionService;
|
||||||
import com.chushang.system.service.ISysRoleService;
|
import com.chushang.system.service.ISysRoleService;
|
||||||
|
|
@ -100,7 +100,7 @@ public class UserController implements RemoteUserService {
|
||||||
@PutMapping("/profile")
|
@PutMapping("/profile")
|
||||||
public AjaxResult updateProfile(@RequestBody SysUser user)
|
public AjaxResult updateProfile(@RequestBody SysUser user)
|
||||||
{
|
{
|
||||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
LoginUser<SysUser> loginUser = SecurityUtils.getLoginUser();
|
||||||
String username = user.getUsername();
|
String username = user.getUsername();
|
||||||
if (!sysUserService.checkUsername(username)){
|
if (!sysUserService.checkUsername(username)){
|
||||||
SysUser sysUser = loginUser.getSysUser();
|
SysUser sysUser = loginUser.getSysUser();
|
||||||
|
|
@ -198,7 +198,7 @@ public class UserController implements RemoteUserService {
|
||||||
@PutMapping("/updatePwd")
|
@PutMapping("/updatePwd")
|
||||||
public AjaxResult updatePwd(@RequestBody @Valid PasswordForm form)
|
public AjaxResult updatePwd(@RequestBody @Valid PasswordForm form)
|
||||||
{
|
{
|
||||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
LoginUser<SysUser> loginUser = SecurityUtils.getLoginUser();
|
||||||
SysUser sysUser = loginUser.getSysUser();
|
SysUser sysUser = loginUser.getSysUser();
|
||||||
|
|
||||||
if (!SecurityUtils.matchesPassword(form.getOldPassword(), sysUser.getSalt(), sysUser.getPassword())){
|
if (!SecurityUtils.matchesPassword(form.getOldPassword(), sysUser.getSalt(), sysUser.getPassword())){
|
||||||
|
|
@ -285,7 +285,7 @@ public class UserController implements RemoteUserService {
|
||||||
|
|
||||||
@InnerAuth
|
@InnerAuth
|
||||||
@GetMapping("/info/{username}")
|
@GetMapping("/info/{username}")
|
||||||
public Result<LoginUser> getUserInfo(@PathVariable("username") String username, String source)
|
public Result<LoginUser<SysUser>> getUserInfo(@PathVariable("username") String username, String source)
|
||||||
{
|
{
|
||||||
SysUser sysUser = sysUserService.selectUserByUserName(username);
|
SysUser sysUser = sysUserService.selectUserByUserName(username);
|
||||||
if (StringUtils.isNull(sysUser)) {
|
if (StringUtils.isNull(sysUser)) {
|
||||||
|
|
@ -297,7 +297,7 @@ public class UserController implements RemoteUserService {
|
||||||
// 权限集合
|
// 权限集合
|
||||||
Set<String> permissions = permissionService.getMenuPermission(sysUser);
|
Set<String> permissions = permissionService.getMenuPermission(sysUser);
|
||||||
|
|
||||||
LoginUser sysUserVo = new LoginUser();
|
LoginUser<SysUser> sysUserVo = new LoginUser<>();
|
||||||
sysUserVo.setUserId(sysUser.getUserId());
|
sysUserVo.setUserId(sysUser.getUserId());
|
||||||
sysUserVo.setUsername(sysUser.getUsername());
|
sysUserVo.setUsername(sysUser.getUsername());
|
||||||
sysUserVo.setSysUser(sysUser);
|
sysUserVo.setSysUser(sysUser);
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import com.chushang.system.entity.bo.CancelUserRole;
|
||||||
import com.chushang.system.entity.dto.ListRoleDTO;
|
import com.chushang.system.entity.dto.ListRoleDTO;
|
||||||
import com.chushang.system.entity.po.SysRole;
|
import com.chushang.system.entity.po.SysRole;
|
||||||
import com.chushang.system.entity.po.SysUser;
|
import com.chushang.system.entity.po.SysUser;
|
||||||
import com.chushang.system.entity.vo.LoginUser;
|
import com.chushang.security.entity.vo.LoginUser;
|
||||||
import com.chushang.system.service.ISysRoleDeptService;
|
import com.chushang.system.service.ISysRoleDeptService;
|
||||||
import com.chushang.system.service.ISysRoleService;
|
import com.chushang.system.service.ISysRoleService;
|
||||||
import com.chushang.system.service.ISysUserRoleService;
|
import com.chushang.system.service.ISysUserRoleService;
|
||||||
|
|
@ -106,7 +106,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public void saveRole(SysRole role) {
|
public void saveRole(SysRole role) {
|
||||||
LoginUser loginUser = SecurityUtils.getLoginUser();
|
LoginUser<SysUser> loginUser = SecurityUtils.getLoginUser();
|
||||||
SysUser sysUser = loginUser.getSysUser();
|
SysUser sysUser = loginUser.getSysUser();
|
||||||
Integer deptId = sysUser.getDeptId();
|
Integer deptId = sysUser.getDeptId();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ server:
|
||||||
shutdown: graceful
|
shutdown: graceful
|
||||||
port: 8085
|
port: 8085
|
||||||
servlet:
|
servlet:
|
||||||
context-path: /cs/system
|
context-path: /system
|
||||||
tomcat:
|
tomcat:
|
||||||
uri-encoding: UTF-8
|
uri-encoding: UTF-8
|
||||||
threads:
|
threads:
|
||||||
|
|
@ -16,9 +16,9 @@ spring:
|
||||||
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.cs.master.username}
|
username: ${config.jdbc.cs.master.username}
|
||||||
password: ${conf.jdbc.cs.master.password}
|
password: ${config.jdbc.cs.master.password}
|
||||||
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
|
url: jdbc:mysql://${config.jdbc.cs.master.host}:${config.jdbc.cs.master.port}/${config.jdbc.cs.master.database}?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
||||||
hikari:
|
hikari:
|
||||||
# 最大线程池数量
|
# 最大线程池数量
|
||||||
maximum-pool-size: 30
|
maximum-pool-size: 30
|
||||||
|
|
@ -39,8 +39,11 @@ spring:
|
||||||
date-format: yyyy-MM-dd HH:mm:ss
|
date-format: yyyy-MM-dd HH:mm:ss
|
||||||
# mybaits-plus配置
|
# mybaits-plus配置
|
||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
|
# 全局刷新 mapper
|
||||||
mapper-locations: classpath:/mapper/**/*.xml
|
mapper-locations: classpath:/mapper/**/*.xml
|
||||||
global-config:
|
global-config:
|
||||||
|
refresh:
|
||||||
|
enable: true
|
||||||
db-config:
|
db-config:
|
||||||
id-type: auto
|
id-type: auto
|
||||||
table-underline: true
|
table-underline: true
|
||||||
|
|
@ -80,3 +83,9 @@ management:
|
||||||
endpoint:
|
endpoint:
|
||||||
health:
|
health:
|
||||||
show-details: ALWAYS
|
show-details: ALWAYS
|
||||||
|
|
||||||
|
# 日志监听配置 -- 如果启用的话,需要配置 kafka 的路径
|
||||||
|
logging:
|
||||||
|
config: classpath:logback-nacos.xml
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
spring:
|
||||||
|
config:
|
||||||
|
import:
|
||||||
|
-: "classpath:application.yml"
|
||||||
|
cloud:
|
||||||
|
loadbalancer:
|
||||||
|
cache:
|
||||||
|
enabled: false
|
||||||
|
nacos:
|
||||||
|
server-addr: ${nacos.host}
|
||||||
|
username: ${nacos.username}
|
||||||
|
password: ${nacos.password}
|
||||||
|
discovery:
|
||||||
|
server-addr: ${nacos.host}
|
||||||
|
namespace: ${nacos.namespace}
|
||||||
|
group: ${nacos.group}
|
||||||
|
service: ${spring.application.name}
|
||||||
|
config:
|
||||||
|
server-addr: ${spring.cloud.nacos.discovery.server-addr}
|
||||||
|
namespace: ${spring.cloud.nacos.discovery.namespace}
|
||||||
|
group: ${spring.cloud.nacos.discovery.group}
|
||||||
|
file-extension: yaml
|
||||||
|
refresh-enabled: true
|
||||||
|
prefix: ${spring.application.name}
|
||||||
|
shared-configs:
|
||||||
|
- dataId: application-common.${spring.cloud.nacos.config.file-extension}
|
||||||
|
group: ${spring.cloud.nacos.discovery.group}
|
||||||
|
refresh: ${spring.cloud.nacos.config.refresh-enabled}
|
||||||
|
extension-configs:
|
||||||
|
- data-id: ${spring.application.name}.${spring.cloud.nacos.config.file-extension}
|
||||||
|
group: ${spring.cloud.nacos.discovery.group}
|
||||||
|
refresh: ${spring.cloud.nacos.config.refresh-enabled}
|
||||||
|
profiles:
|
||||||
|
active: @profiles.active@
|
||||||
|
|
@ -8,29 +8,22 @@ spring:
|
||||||
enabled: false
|
enabled: false
|
||||||
nacos:
|
nacos:
|
||||||
server-addr: ${nacos.host}
|
server-addr: ${nacos.host}
|
||||||
username: nacos
|
username: ${nacos.username}
|
||||||
password: nacos
|
password: ${nacos.password}
|
||||||
discovery:
|
discovery:
|
||||||
server-addr: ${nacos.host}
|
server-addr: ${spring.cloud.nacos.server-addr}
|
||||||
namespace: ${nacos.namespace}
|
namespace: ${nacos.namespace}
|
||||||
group: ${nacos.group}
|
group: ${nacos.group}
|
||||||
service: ${spring.application.name}
|
service: ${spring.application.name}
|
||||||
config:
|
config:
|
||||||
server-addr: ${spring.cloud.nacos.discovery.server-addr}
|
server-addr: ${spring.cloud.nacos.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: yaml
|
file-extension: yaml
|
||||||
refresh-enabled: true
|
refresh-enabled: true
|
||||||
prefix: ${spring.application.name}
|
|
||||||
shared-configs:
|
shared-configs:
|
||||||
- dataId: application-common.${spring.cloud.nacos.config.file-extension}
|
- dataId: application-common.${spring.cloud.nacos.config.file-extension}
|
||||||
group: ${nacos.group}
|
group: ${nacos.group}
|
||||||
refresh: ${spring.cloud.nacos.config.refresh-enabled}
|
refresh: ${spring.cloud.nacos.config.refresh-enabled}
|
||||||
extension-configs:
|
|
||||||
- data-id: ${spring.application.name}.${spring.cloud.nacos.config.file-extension}
|
|
||||||
group: ${spring.cloud.nacos.discovery.group}
|
|
||||||
refresh: ${spring.cloud.nacos.config.refresh-enabled}
|
|
||||||
profiles:
|
profiles:
|
||||||
active: @profiles.active@
|
active: @profiles.active@
|
||||||
main:
|
|
||||||
allow-bean-definition-overriding: true
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
|
||||||
<configuration debug="false" scan="false">
|
<configuration debug="false" scan="false">
|
||||||
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
|
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
|
||||||
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue=""/>
|
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue=""/>
|
||||||
|
|
@ -11,15 +13,24 @@
|
||||||
<property name="log.redis.auth" value="${plumelog.redis.auth}" />
|
<property name="log.redis.auth" value="${plumelog.redis.auth}" />
|
||||||
<property name="log.path" value="logs/${spring.application.name}"/>
|
<property name="log.path" value="logs/${spring.application.name}"/>
|
||||||
|
|
||||||
|
<!-- 彩色日志格式 -->
|
||||||
|
<property name="CONSOLE_LOG_PATTERN"
|
||||||
|
value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr([%X{traceId}]) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
|
||||||
|
<!-- 彩色日志依赖的渲染类 -->
|
||||||
|
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
|
||||||
|
<conversionRule conversionWord="wex"
|
||||||
|
converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>
|
||||||
|
<conversionRule conversionWord="wEx"
|
||||||
|
converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>
|
||||||
|
|
||||||
<!-- Console log output -->
|
<!-- Console log output -->
|
||||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>%boldCyan(%d{yyyy-MM-dd HH:mm:ss.SSS}) TRACE[%X{trace:-}/%X{span:-}] [%highlight(%-5p)][%cyan(%t)][%magenta(%c{50})-%boldMagenta(%M)][%cn] - %msg%n</pattern>
|
<Pattern>${CONSOLE_LOG_PATTERN}</Pattern>
|
||||||
<!-- 设置字符集 -->
|
<!-- 设置字符集 -->
|
||||||
<charset>UTF-8</charset>
|
<charset>UTF-8</charset>
|
||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<!-- Log file info output -->
|
<!-- Log file info output -->
|
||||||
<appender name="info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
<appender name="info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
<file>${log.path}/info.log</file>
|
<file>${log.path}/info.log</file>
|
||||||
|
|
@ -29,7 +40,7 @@
|
||||||
<maxFileSize>500MB</maxFileSize>
|
<maxFileSize>500MB</maxFileSize>
|
||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern> TRACE[%X{trace:-}/%X{span:-}] %date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||||
<level>info</level>
|
<level>info</level>
|
||||||
|
|
@ -44,7 +55,7 @@
|
||||||
<maxFileSize>500MB</maxFileSize>
|
<maxFileSize>500MB</maxFileSize>
|
||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>TRACE[%X{trace:-}/%X{span:-}] %date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||||
<level>debug</level>
|
<level>debug</level>
|
||||||
|
|
@ -59,7 +70,7 @@
|
||||||
<maxFileSize>500MB</maxFileSize>
|
<maxFileSize>500MB</maxFileSize>
|
||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern> TRACE[%X{trace:-}/%X{span:-}] %date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||||
<level>error</level>
|
<level>error</level>
|
||||||
|
|
@ -67,8 +78,7 @@
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<!--nacos 心跳 INFO 屏蔽-->
|
<!--nacos 心跳 INFO 屏蔽-->
|
||||||
<logger name="com.alibaba.nacos" level="OFF">
|
<logger name="com.alibaba.cloud.nacos" level="info">
|
||||||
<appender-ref ref="error"/>
|
|
||||||
</logger>
|
</logger>
|
||||||
|
|
||||||
<!-- 使用kafka启用下面配置 -->
|
<!-- 使用kafka启用下面配置 -->
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import com.chushang.system.entity.enums.AuthTypeEnum;
|
||||||
import com.chushang.system.entity.po.SysMenu;
|
import com.chushang.system.entity.po.SysMenu;
|
||||||
import com.chushang.system.entity.po.SysUser;
|
import com.chushang.system.entity.po.SysUser;
|
||||||
import com.chushang.system.entity.po.SysUserData;
|
import com.chushang.system.entity.po.SysUserData;
|
||||||
import com.chushang.system.entity.vo.LoginUser;
|
import com.chushang.security.entity.vo.LoginUser;
|
||||||
import com.chushang.system.entity.vo.RouterVo;
|
import com.chushang.system.entity.vo.RouterVo;
|
||||||
import com.chushang.system.service.*;
|
import com.chushang.system.service.*;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
|
||||||
|
|
@ -17,5 +17,16 @@
|
||||||
<module>chushang-module-system</module>
|
<module>chushang-module-system</module>
|
||||||
<module>chushang-module-oss</module>
|
<module>chushang-module-oss</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
<dependencies>
|
||||||
|
<!-- 链路-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-sleuth</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
63
pom.xml
63
pom.xml
|
|
@ -18,12 +18,26 @@
|
||||||
|
|
||||||
<profiles>
|
<profiles>
|
||||||
<profile>
|
<profile>
|
||||||
<id>local-dev</id>
|
<id>cloud</id>
|
||||||
<properties>
|
<properties>
|
||||||
<profiles.active>cloud</profiles.active>
|
<profiles.active>cloud</profiles.active>
|
||||||
<nacos.host>192.168.116.115:8848</nacos.host>
|
<nacos.host>192.168.110.75:8848</nacos.host>
|
||||||
<nacos.namespace>cloud</nacos.namespace>
|
<nacos.namespace>5512c576-2976-4334-b6f5-fe7c3014f654</nacos.namespace>
|
||||||
<nacos.group>DEFAULT_GROUP</nacos.group>
|
<nacos.group>DEFAULT_GROUP</nacos.group>
|
||||||
|
<nacos.username>nacos</nacos.username>
|
||||||
|
<nacos.password>nacos@123</nacos.password>
|
||||||
|
<sentinel-transport.dashboard>localhost:5003</sentinel-transport.dashboard>
|
||||||
|
</properties>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>local</id>
|
||||||
|
<properties>
|
||||||
|
<profiles.active>local</profiles.active>
|
||||||
|
<nacos.host>192.168.116.115:8848</nacos.host>
|
||||||
|
<nacos.namespace>ece94e7d-4792-48d2-b1f8-06334b530944</nacos.namespace>
|
||||||
|
<nacos.group>DEFAULT_GROUP</nacos.group>
|
||||||
|
<nacos.username>nacos</nacos.username>
|
||||||
|
<nacos.password>nacos</nacos.password>
|
||||||
<sentinel-transport.dashboard>localhost:5003</sentinel-transport.dashboard>
|
<sentinel-transport.dashboard>localhost:5003</sentinel-transport.dashboard>
|
||||||
</properties>
|
</properties>
|
||||||
</profile>
|
</profile>
|
||||||
|
|
@ -33,6 +47,10 @@
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<spring-boot.version>2.7.14</spring-boot.version>
|
||||||
|
<spring-cloud.version>2021.0.5</spring-cloud.version>
|
||||||
|
<spring-cloud-alibaba.version>2021.0.5.0</spring-cloud-alibaba.version>
|
||||||
|
<spring-boot-maven-plugin.version>2.7.14</spring-boot-maven-plugin.version>
|
||||||
|
|
||||||
<hutool.version>5.8.9</hutool.version>
|
<hutool.version>5.8.9</hutool.version>
|
||||||
<spring.checkstyle.plugin>0.0.28</spring.checkstyle.plugin>
|
<spring.checkstyle.plugin>0.0.28</spring.checkstyle.plugin>
|
||||||
|
|
@ -51,10 +69,7 @@
|
||||||
<jsqparser.version>4.3</jsqparser.version>
|
<jsqparser.version>4.3</jsqparser.version>
|
||||||
<easy-es.version>2.0.0-beta8</easy-es.version>
|
<easy-es.version>2.0.0-beta8</easy-es.version>
|
||||||
<es.version>7.14.0</es.version>
|
<es.version>7.14.0</es.version>
|
||||||
<spring-boot.version>2.7.14</spring-boot.version>
|
|
||||||
<arthas.version>3.6.7</arthas.version>
|
<arthas.version>3.6.7</arthas.version>
|
||||||
<spring-cloud.version>2021.0.5</spring-cloud.version>
|
|
||||||
<spring-cloud-alibaba.version>2021.0.5.0</spring-cloud-alibaba.version>
|
|
||||||
<mysql.version>8.0.33</mysql.version>
|
<mysql.version>8.0.33</mysql.version>
|
||||||
<bitwalker.version>1.21</bitwalker.version>
|
<bitwalker.version>1.21</bitwalker.version>
|
||||||
<kaptcha.version>2.3.2</kaptcha.version>
|
<kaptcha.version>2.3.2</kaptcha.version>
|
||||||
|
|
@ -83,7 +98,7 @@
|
||||||
<com-jcraft-jsch.version>0.1.55</com-jcraft-jsch.version>
|
<com-jcraft-jsch.version>0.1.55</com-jcraft-jsch.version>
|
||||||
<fastjson2.version>2.0.43</fastjson2.version>
|
<fastjson2.version>2.0.43</fastjson2.version>
|
||||||
|
|
||||||
<spring-boot-maven-plugin.version>2.7.14</spring-boot-maven-plugin.version>
|
|
||||||
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
|
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
|
||||||
<maven-surefire-plugin.version>3.1.0</maven-surefire-plugin.version>
|
<maven-surefire-plugin.version>3.1.0</maven-surefire-plugin.version>
|
||||||
<maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
|
<maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
|
||||||
|
|
@ -103,12 +118,6 @@
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- arthas -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.taobao.arthas</groupId>
|
|
||||||
<artifactId>arthas-spring-boot-starter</artifactId>
|
|
||||||
<scope>runtime</scope>
|
|
||||||
</dependency>
|
|
||||||
<!--配置文件处理器-->
|
<!--配置文件处理器-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|
@ -141,27 +150,6 @@
|
||||||
<groupId>javax.xml.bind</groupId>
|
<groupId>javax.xml.bind</groupId>
|
||||||
<artifactId>jaxb-api</artifactId>
|
<artifactId>jaxb-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--监控客户端-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>de.codecentric</groupId>
|
|
||||||
<artifactId>spring-boot-admin-starter-client</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<!-- spring-boot-devtools -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-devtools</artifactId>
|
|
||||||
<optional>true</optional> <!-- 表示依赖不会传递 -->
|
|
||||||
</dependency>
|
|
||||||
<!--注册中心客户端-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<!--配置中心客户端-->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
|
||||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<!-- 依赖声明 -->
|
<!-- 依赖声明 -->
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
|
@ -248,6 +236,13 @@
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- arthas -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.taobao.arthas</groupId>
|
||||||
|
<artifactId>arthas-spring-boot-starter</artifactId>
|
||||||
|
<version>${spring-boot.version}</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue