parent
e6201b00c1
commit
1dadf93449
@ -0,0 +1,25 @@
|
||||
package cn.iocoder.mall.dubbo.config;
|
||||
|
||||
import cn.iocoder.mall.dubbo.core.web.DubboRouterTagWebInterceptor;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
|
||||
public class DubboWebAutoConfiguration implements WebMvcConfigurer {
|
||||
|
||||
// ========== 拦截器相关 ==========
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
try {
|
||||
registry.addInterceptor(new DubboRouterTagWebInterceptor()).order(-1000);
|
||||
} catch (NoSuchBeanDefinitionException e) {
|
||||
// logger.warn("[addInterceptors][无法获取 AccessLogInterceptor 拦截器,因此不启动 AccessLog 的记录]");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* 占坑
|
||||
*/
|
||||
package cn.iocoder.mall.dubbo.core;
|
||||
@ -0,0 +1,25 @@
|
||||
package cn.iocoder.mall.dubbo.core.router;
|
||||
|
||||
/**
|
||||
* Dubbo 路由 Tag 的上下文
|
||||
*
|
||||
* @see cn.iocoder.mall.dubbo.core.filter.DubboRouterTagFilter
|
||||
* @see cn.iocoder.mall.dubbo.core.web.DubboRouterTagWebInterceptor
|
||||
*/
|
||||
public class DubboRouterTagContextHolder {
|
||||
|
||||
private static ThreadLocal<String> tagContext = new ThreadLocal<>();
|
||||
|
||||
public static void setTag(String tag) {
|
||||
tagContext.set(tag);
|
||||
}
|
||||
|
||||
public static String getTag() {
|
||||
return tagContext.get();
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
tagContext.remove();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1 +1,2 @@
|
||||
dubboExceptionFilter=cn.iocoder.mall.dubbo.core.filter.DubboProviderExceptionFilter
|
||||
dubboRouterTagFilter=cn.iocoder.mall.dubbo.core.filter.DubboRouterTagFilter
|
||||
|
||||
@ -0,0 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
cn.iocoder.mall.dubbo.config.DubboWebAutoConfiguration
|
||||
@ -1,34 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>onemall</artifactId>
|
||||
<groupId>cn.iocoder.mall</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>mall-cache</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>2.7.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson</artifactId>
|
||||
<version>3.10.6</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
@ -1,29 +0,0 @@
|
||||
package cn.iocoder.mall.system.rest.convert.errorcode;
|
||||
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.system.biz.bo.errorcode.ErrorCodeBO;
|
||||
import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodeAddDTO;
|
||||
import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodePageDTO;
|
||||
import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodeUpdateDTO;
|
||||
import cn.iocoder.mall.system.rest.request.errorcode.ErrorCodeAddRequest;
|
||||
import cn.iocoder.mall.system.rest.request.errorcode.ErrorCodePageRequest;
|
||||
import cn.iocoder.mall.system.rest.response.errorcode.ErrorCodePageResponse;
|
||||
import cn.iocoder.mall.system.rest.request.errorcode.ErrorCodeUpdateRequest;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* @author ding
|
||||
*/
|
||||
@Mapper
|
||||
public interface ErrorCodeConvert {
|
||||
ErrorCodeConvert INSTANCE = Mappers.getMapper(ErrorCodeConvert.class);
|
||||
|
||||
ErrorCodeAddDTO convert(ErrorCodeAddRequest bean);
|
||||
|
||||
ErrorCodeUpdateDTO convert(ErrorCodeUpdateRequest bean);
|
||||
|
||||
ErrorCodePageDTO convert(ErrorCodePageRequest bean);
|
||||
|
||||
PageResult<ErrorCodePageResponse> convertPage(PageResult<ErrorCodeBO> bean);
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
package cn.iocoder.mall.system.rpc.convert.errorcode;
|
||||
|
||||
import cn.iocoder.mall.system.biz.bo.errorcode.ErrorCodeBO;
|
||||
import cn.iocoder.mall.system.biz.dto.errorcode.ErrorCodeAddDTO;
|
||||
import cn.iocoder.mall.system.rpc.request.errorcode.ErrorCodeAddRequest;
|
||||
import cn.iocoder.mall.system.rpc.response.errorcode.ErrorCodeResponse;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ErrorCodeConvert {
|
||||
|
||||
ErrorCodeConvert INSTANCE = Mappers.getMapper(ErrorCodeConvert.class);
|
||||
|
||||
List<ErrorCodeResponse> convert(List<ErrorCodeBO> bean);
|
||||
|
||||
ErrorCodeAddDTO convert(ErrorCodeAddRequest errorCodeAddRequest);
|
||||
|
||||
List<ErrorCodeAddDTO> convertList(List<ErrorCodeAddRequest> bean);
|
||||
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
package cn.iocoder.mall.system.rpc.convert.systemlog;
|
||||
|
||||
import cn.iocoder.mall.system.biz.dto.system.AccessLogAddDTO;
|
||||
import cn.iocoder.mall.system.biz.dto.system.ExceptionLogAddDTO;
|
||||
import cn.iocoder.mall.system.rpc.request.systemlog.AccessLogAddRequest;
|
||||
import cn.iocoder.mall.system.rpc.request.systemlog.ExceptionLogAddRequest;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface SystemLogConvert {
|
||||
|
||||
SystemLogConvert INSTANCE = Mappers.getMapper(SystemLogConvert.class);
|
||||
|
||||
AccessLogAddDTO convert(AccessLogAddRequest bean);
|
||||
|
||||
ExceptionLogAddDTO convert(ExceptionLogAddRequest bean);
|
||||
|
||||
}
|
||||
@ -1,94 +0,0 @@
|
||||
package cn.iocoder.mall.admin.service;
|
||||
|
||||
import cn.iocoder.common.framework.util.StringUtil;
|
||||
import cn.iocoder.common.framework.vo.PageResult;
|
||||
import cn.iocoder.mall.system.api.SystemLogService;
|
||||
import cn.iocoder.mall.system.api.bo.systemlog.AccessLogBO;
|
||||
import cn.iocoder.mall.system.api.bo.systemlog.AccessLogPageBO;
|
||||
import cn.iocoder.mall.system.api.dto.systemlog.AccessLogAddDTO;
|
||||
import cn.iocoder.mall.system.api.dto.systemlog.AccessLogPageDTO;
|
||||
import cn.iocoder.mall.system.api.dto.systemlog.ExceptionLogAddDTO;
|
||||
import cn.iocoder.mall.admin.convert.AccessLogConvert;
|
||||
import cn.iocoder.mall.admin.dao.AccessLogMapper;
|
||||
import cn.iocoder.mall.admin.dao.ExceptionLogMapper;
|
||||
import cn.iocoder.mall.admin.dataobject.AccessLogDO;
|
||||
import cn.iocoder.mall.admin.dataobject.ExceptionLogDO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Service
|
||||
@org.apache.dubbo.config.annotation.Service(validation = "true", version = "${dubbo.provider.AdminAccessLogService.version}")
|
||||
public class SystemLogServiceImpl implements SystemLogService {
|
||||
|
||||
/**
|
||||
* 请求参数最大长度。
|
||||
*/
|
||||
private static final Integer QUERY_STRING_MAX_LENGTH = 4096;
|
||||
/**
|
||||
* 请求地址最大长度。
|
||||
*/
|
||||
private static final Integer URI_MAX_LENGTH = 4096;
|
||||
/**
|
||||
* User-Agent 最大长度。
|
||||
*/
|
||||
private static final Integer USER_AGENT_MAX_LENGTH = 1024;
|
||||
|
||||
@Autowired
|
||||
private AccessLogMapper accessLogMapper;
|
||||
@Autowired
|
||||
private ExceptionLogMapper exceptionLogMapper;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void addAccessLog(AccessLogAddDTO adminAccessLogAddDTO) {
|
||||
// 创建 AdminAccessLogDO
|
||||
AccessLogDO accessLog = AccessLogConvert.INSTANCE.convert(adminAccessLogAddDTO);
|
||||
accessLog.setCreateTime(new Date());
|
||||
// 截取最大长度
|
||||
if (accessLog.getUri().length() > URI_MAX_LENGTH) {
|
||||
accessLog.setUri(StringUtil.substring(accessLog.getUri(), URI_MAX_LENGTH));
|
||||
}
|
||||
if (accessLog.getQueryString().length() > QUERY_STRING_MAX_LENGTH) {
|
||||
accessLog.setQueryString(StringUtil.substring(accessLog.getQueryString(), QUERY_STRING_MAX_LENGTH));
|
||||
}
|
||||
if (accessLog.getUserAgent().length() > USER_AGENT_MAX_LENGTH) {
|
||||
accessLog.setUserAgent(StringUtil.substring(accessLog.getUserAgent(), USER_AGENT_MAX_LENGTH));
|
||||
}
|
||||
// 插入
|
||||
accessLogMapper.insert(accessLog);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void addExceptionLog(ExceptionLogAddDTO exceptionLogAddDTO) {
|
||||
// 创建 AdminAccessLogDO
|
||||
ExceptionLogDO exceptionLog = AccessLogConvert.INSTANCE.convert(exceptionLogAddDTO);
|
||||
exceptionLog.setCreateTime(new Date());
|
||||
// 截取最大长度
|
||||
if (exceptionLog.getUri().length() > URI_MAX_LENGTH) {
|
||||
exceptionLog.setUri(StringUtil.substring(exceptionLog.getUri(), URI_MAX_LENGTH));
|
||||
}
|
||||
if (exceptionLog.getQueryString().length() > QUERY_STRING_MAX_LENGTH) {
|
||||
exceptionLog.setQueryString(StringUtil.substring(exceptionLog.getQueryString(), QUERY_STRING_MAX_LENGTH));
|
||||
}
|
||||
if (exceptionLog.getUserAgent().length() > USER_AGENT_MAX_LENGTH) {
|
||||
exceptionLog.setUserAgent(StringUtil.substring(exceptionLog.getUserAgent(), USER_AGENT_MAX_LENGTH));
|
||||
}
|
||||
// 插入
|
||||
exceptionLogMapper.insert(exceptionLog);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("Duplicates")
|
||||
public AccessLogPageBO getAccessLogPage(AccessLogPageDTO accessLogPageDTO) {
|
||||
AccessLogPageBO accessLogPageBO = new AccessLogPageBO();
|
||||
PageResult<AccessLogBO> accessLogPageBOPageResult = AccessLogConvert.INSTANCE.convert(
|
||||
accessLogMapper.selectPage(accessLogPageDTO));
|
||||
accessLogPageBO.setList(accessLogPageBOPageResult.getList());
|
||||
accessLogPageBO.setTotal(accessLogPageBOPageResult.getTotal());
|
||||
return accessLogPageBO;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in new issue