Commit 3276ad007452566cd0b3c64353e80a5eb8b20b52

Authored by YunaiV
1 parent e68d4f54

优化 yudao-spring-boot-starter-web 的 API 日志封装,和 yudao-cloud 保持一致

Showing 25 changed files with 437 additions and 63 deletions
yudao-framework/yudao-spring-boot-starter-web/pom.xml
... ... @@ -53,6 +53,13 @@
53 53 <scope>provided</scope> <!-- 设置为 provided,主要是 GlobalExceptionHandler 使用 -->
54 54 </dependency>
55 55  
  56 + <!-- 业务组件 -->
  57 + <dependency>
  58 + <groupId>cn.iocoder.boot</groupId>
  59 + <artifactId>yudao-module-infra-api</artifactId> <!-- 需要使用它,进行操作日志的记录 -->
  60 + <version>${revision}</version>
  61 + </dependency>
  62 +
56 63 <!-- 服务保障相关 -->
57 64 <dependency>
58 65 <groupId>io.github.resilience4j</groupId>
... ...
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/config/YudaoApiLogAutoConfiguration.java
... ... @@ -2,9 +2,14 @@ package cn.iocoder.yudao.framework.apilog.config;
2 2  
3 3 import cn.iocoder.yudao.framework.apilog.core.filter.ApiAccessLogFilter;
4 4 import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkService;
  5 +import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkServiceImpl;
  6 +import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService;
  7 +import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkServiceImpl;
  8 +import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum;
5 9 import cn.iocoder.yudao.framework.web.config.WebProperties;
6 10 import cn.iocoder.yudao.framework.web.config.YudaoWebAutoConfiguration;
7   -import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum;
  11 +import cn.iocoder.yudao.module.infra.api.logger.ApiAccessLogApi;
  12 +import cn.iocoder.yudao.module.infra.api.logger.ApiErrorLogApi;
8 13 import org.springframework.beans.factory.annotation.Value;
9 14 import org.springframework.boot.autoconfigure.AutoConfigureAfter;
10 15 import org.springframework.boot.web.servlet.FilterRegistrationBean;
... ... @@ -17,6 +22,16 @@ import javax.servlet.Filter;
17 22 @AutoConfigureAfter(YudaoWebAutoConfiguration.class)
18 23 public class YudaoApiLogAutoConfiguration {
19 24  
  25 + @Bean
  26 + public ApiAccessLogFrameworkService apiAccessLogFrameworkService(ApiAccessLogApi apiAccessLogApi) {
  27 + return new ApiAccessLogFrameworkServiceImpl(apiAccessLogApi);
  28 + }
  29 +
  30 + @Bean
  31 + public ApiErrorLogFrameworkService apiErrorLogFrameworkService(ApiErrorLogApi apiErrorLogApi) {
  32 + return new ApiErrorLogFrameworkServiceImpl(apiErrorLogApi);
  33 + }
  34 +
20 35 /**
21 36 * 创建 ApiAccessLogFilter Bean,记录 API 请求日志
22 37 */
... ...
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/filter/ApiAccessLogFilter.java
... ... @@ -3,8 +3,8 @@ package cn.iocoder.yudao.framework.apilog.core.filter;
3 3 import cn.hutool.core.exceptions.ExceptionUtil;
4 4 import cn.hutool.core.map.MapUtil;
5 5 import cn.hutool.extra.servlet.ServletUtil;
  6 +import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLog;
6 7 import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkService;
7   -import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateReqDTO;
8 8 import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants;
9 9 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
10 10 import cn.iocoder.yudao.framework.common.util.date.DateUtils;
... ... @@ -66,16 +66,16 @@ public class ApiAccessLogFilter extends ApiRequestFilter {
66 66  
67 67 private void createApiAccessLog(HttpServletRequest request, Date beginTime,
68 68 Map<String, String> queryString, String requestBody, Exception ex) {
69   - ApiAccessLogCreateReqDTO accessLog = new ApiAccessLogCreateReqDTO();
  69 + ApiAccessLog accessLog = new ApiAccessLog();
70 70 try {
71 71 this.buildApiAccessLogDTO(accessLog, request, beginTime, queryString, requestBody, ex);
72   - apiAccessLogFrameworkService.createApiAccessLogAsync(accessLog);
  72 + apiAccessLogFrameworkService.createApiAccessLog(accessLog);
73 73 } catch (Throwable th) {
74 74 log.error("[createApiAccessLog][url({}) log({}) 发生异常]", request.getRequestURI(), toJsonString(accessLog), th);
75 75 }
76 76 }
77 77  
78   - private void buildApiAccessLogDTO(ApiAccessLogCreateReqDTO accessLog, HttpServletRequest request, Date beginTime,
  78 + private void buildApiAccessLogDTO(ApiAccessLog accessLog, HttpServletRequest request, Date beginTime,
79 79 Map<String, String> queryString, String requestBody, Exception ex) {
80 80 // 处理用户信息
81 81 accessLog.setUserId(WebFrameworkUtils.getLoginUserId(request));
... ...
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/service/ApiAccessLog.java 0 → 100644
  1 +package cn.iocoder.yudao.framework.apilog.core.service;
  2 +
  3 +import lombok.Data;
  4 +
  5 +import javax.validation.constraints.NotNull;
  6 +import java.util.Date;
  7 +
  8 +/**
  9 + * API 访问日志
  10 + *
  11 + * @author 芋道源码
  12 + */
  13 +@Data
  14 +public class ApiAccessLog {
  15 +
  16 + /**
  17 + * 链路追踪编号
  18 + */
  19 + private String traceId;
  20 + /**
  21 + * 用户编号
  22 + */
  23 + private Long userId;
  24 + /**
  25 + * 用户类型
  26 + */
  27 + private Integer userType;
  28 + /**
  29 + * 应用名
  30 + */
  31 + @NotNull(message = "应用名不能为空")
  32 + private String applicationName;
  33 +
  34 + /**
  35 + * 请求方法名
  36 + */
  37 + @NotNull(message = "http 请求方法不能为空")
  38 + private String requestMethod;
  39 + /**
  40 + * 访问地址
  41 + */
  42 + @NotNull(message = "访问地址不能为空")
  43 + private String requestUrl;
  44 + /**
  45 + * 请求参数
  46 + */
  47 + @NotNull(message = "请求参数不能为空")
  48 + private String requestParams;
  49 + /**
  50 + * 用户 IP
  51 + */
  52 + @NotNull(message = "ip 不能为空")
  53 + private String userIp;
  54 + /**
  55 + * 浏览器 UA
  56 + */
  57 + @NotNull(message = "User-Agent 不能为空")
  58 + private String userAgent;
  59 +
  60 + /**
  61 + * 开始请求时间
  62 + */
  63 + @NotNull(message = "开始请求时间不能为空")
  64 + private Date beginTime;
  65 + /**
  66 + * 结束请求时间
  67 + */
  68 + @NotNull(message = "结束请求时间不能为空")
  69 + private Date endTime;
  70 + /**
  71 + * 执行时长,单位:毫秒
  72 + */
  73 + @NotNull(message = "执行时长不能为空")
  74 + private Integer duration;
  75 + /**
  76 + * 结果码
  77 + */
  78 + @NotNull(message = "错误码不能为空")
  79 + private Integer resultCode;
  80 + /**
  81 + * 结果提示
  82 + */
  83 + private String resultMsg;
  84 +
  85 +}
... ...
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/service/ApiAccessLogFrameworkService.java
1 1 package cn.iocoder.yudao.framework.apilog.core.service;
2 2  
3   -import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateReqDTO;
4   -
5   -import javax.validation.Valid;
6   -
7 3 /**
8 4 * API 访问日志 Framework Service 接口
9 5 *
... ... @@ -14,8 +10,8 @@ public interface ApiAccessLogFrameworkService {
14 10 /**
15 11 * 创建 API 访问日志
16 12 *
17   - * @param createDTO 创建信息
  13 + * @param apiAccessLog API 访问日志
18 14 */
19   - void createApiAccessLogAsync(@Valid ApiAccessLogCreateReqDTO createDTO);
  15 + void createApiAccessLog(ApiAccessLog apiAccessLog);
20 16  
21 17 }
... ...
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/service/ApiAccessLogFrameworkServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.framework.apilog.core.service;
  2 +
  3 +import cn.hutool.core.bean.BeanUtil;
  4 +import cn.iocoder.yudao.module.infra.api.logger.ApiAccessLogApi;
  5 +import cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO;
  6 +import lombok.RequiredArgsConstructor;
  7 +import org.springframework.scheduling.annotation.Async;
  8 +
  9 +/**
  10 + * API 访问日志 Framework Service 实现类
  11 + *
  12 + * 基于 {@link ApiAccessLogApi} 服务,记录访问日志
  13 + *
  14 + * @author 芋道源码
  15 + */
  16 +@RequiredArgsConstructor
  17 +public class ApiAccessLogFrameworkServiceImpl implements ApiAccessLogFrameworkService {
  18 +
  19 + private final ApiAccessLogApi apiAccessLogApi;
  20 +
  21 + @Override
  22 + @Async
  23 + public void createApiAccessLog(ApiAccessLog apiAccessLog) {
  24 + ApiAccessLogCreateReqDTO reqDTO = BeanUtil.copyProperties(apiAccessLog, ApiAccessLogCreateReqDTO.class);
  25 + apiAccessLogApi.createApiAccessLog(reqDTO);
  26 + }
  27 +
  28 +}
... ...
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/service/ApiErrorLog.java 0 → 100644
  1 +package cn.iocoder.yudao.framework.apilog.core.service;
  2 +
  3 +import lombok.Data;
  4 +
  5 +import javax.validation.constraints.NotNull;
  6 +import java.util.Date;
  7 +
  8 +/**
  9 + * API 错误日志
  10 + *
  11 + * @author 芋道源码
  12 + */
  13 +@Data
  14 +public class ApiErrorLog {
  15 +
  16 + /**
  17 + * 链路编号
  18 + */
  19 + private String traceId;
  20 + /**
  21 + * 账号编号
  22 + */
  23 + private Long userId;
  24 + /**
  25 + * 用户类型
  26 + */
  27 + private Integer userType;
  28 + /**
  29 + * 应用名
  30 + */
  31 + @NotNull(message = "应用名不能为空")
  32 + private String applicationName;
  33 +
  34 + /**
  35 + * 请求方法名
  36 + */
  37 + @NotNull(message = "http 请求方法不能为空")
  38 + private String requestMethod;
  39 + /**
  40 + * 访问地址
  41 + */
  42 + @NotNull(message = "访问地址不能为空")
  43 + private String requestUrl;
  44 + /**
  45 + * 请求参数
  46 + */
  47 + @NotNull(message = "请求参数不能为空")
  48 + private String requestParams;
  49 + /**
  50 + * 用户 IP
  51 + */
  52 + @NotNull(message = "ip 不能为空")
  53 + private String userIp;
  54 + /**
  55 + * 浏览器 UA
  56 + */
  57 + @NotNull(message = "User-Agent 不能为空")
  58 + private String userAgent;
  59 +
  60 + /**
  61 + * 异常时间
  62 + */
  63 + @NotNull(message = "异常时间不能为空")
  64 + private Date exceptionTime;
  65 + /**
  66 + * 异常名
  67 + */
  68 + @NotNull(message = "异常名不能为空")
  69 + private String exceptionName;
  70 + /**
  71 + * 异常发生的类全名
  72 + */
  73 + @NotNull(message = "异常发生的类全名不能为空")
  74 + private String exceptionClassName;
  75 + /**
  76 + * 异常发生的类文件
  77 + */
  78 + @NotNull(message = "异常发生的类文件不能为空")
  79 + private String exceptionFileName;
  80 + /**
  81 + * 异常发生的方法名
  82 + */
  83 + @NotNull(message = "异常发生的方法名不能为空")
  84 + private String exceptionMethodName;
  85 + /**
  86 + * 异常发生的方法所在行
  87 + */
  88 + @NotNull(message = "异常发生的方法所在行不能为空")
  89 + private Integer exceptionLineNumber;
  90 + /**
  91 + * 异常的栈轨迹异常的栈轨迹
  92 + */
  93 + @NotNull(message = "异常的栈轨迹不能为空")
  94 + private String exceptionStackTrace;
  95 + /**
  96 + * 异常导致的根消息
  97 + */
  98 + @NotNull(message = "异常导致的根消息不能为空")
  99 + private String exceptionRootCauseMessage;
  100 + /**
  101 + * 异常导致的消息
  102 + */
  103 + @NotNull(message = "异常导致的消息不能为空")
  104 + private String exceptionMessage;
  105 +
  106 +
  107 +}
... ...
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/service/ApiErrorLogFrameworkService.java
1 1 package cn.iocoder.yudao.framework.apilog.core.service;
2 2  
3   -import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateReqDTO;
4   -
5   -import javax.validation.Valid;
6   -
7 3 /**
8 4 * API 错误日志 Framework Service 接口
9 5 *
... ... @@ -14,8 +10,8 @@ public interface ApiErrorLogFrameworkService {
14 10 /**
15 11 * 创建 API 错误日志
16 12 *
17   - * @param createDTO 创建信息
  13 + * @param apiErrorLog API 错误日志
18 14 */
19   - void createApiErrorLogAsync(@Valid ApiErrorLogCreateReqDTO createDTO);
  15 + void createApiErrorLog(ApiErrorLog apiErrorLog);
20 16  
21 17 }
... ...
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/service/ApiErrorLogFrameworkServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.framework.apilog.core.service;
  2 +
  3 +import cn.hutool.core.bean.BeanUtil;
  4 +import cn.iocoder.yudao.module.infra.api.logger.ApiErrorLogApi;
  5 +import cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO;
  6 +import lombok.RequiredArgsConstructor;
  7 +import org.springframework.scheduling.annotation.Async;
  8 +
  9 +/**
  10 + * API 错误日志 Framework Service 实现类
  11 + *
  12 + * 基于 {@link ApiErrorLogApi} 服务,记录错误日志
  13 + *
  14 + * @author 芋道源码
  15 + */
  16 +@RequiredArgsConstructor
  17 +public class ApiErrorLogFrameworkServiceImpl implements ApiErrorLogFrameworkService {
  18 +
  19 + private final ApiErrorLogApi apiErrorLogApi;
  20 +
  21 + @Override
  22 + @Async
  23 + public void createApiErrorLog(ApiErrorLog apiErrorLog) {
  24 + ApiErrorLogCreateReqDTO reqDTO = BeanUtil.copyProperties(apiErrorLog, ApiErrorLogCreateReqDTO.class);
  25 + apiErrorLogApi.createApiErrorLog(reqDTO);
  26 + }
  27 +
  28 +}
... ...
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java
... ... @@ -3,14 +3,14 @@ package cn.iocoder.yudao.framework.web.core.handler;
3 3 import cn.hutool.core.exceptions.ExceptionUtil;
4 4 import cn.hutool.core.map.MapUtil;
5 5 import cn.hutool.extra.servlet.ServletUtil;
  6 +import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLog;
  7 +import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService;
6 8 import cn.iocoder.yudao.framework.common.exception.ServiceException;
7 9 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
8   -import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService;
9   -import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateReqDTO;
10   -import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils;
11   -import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
12 10 import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
  11 +import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils;
13 12 import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
  13 +import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
14 14 import io.github.resilience4j.ratelimiter.RequestNotPermitted;
15 15 import lombok.AllArgsConstructor;
16 16 import lombok.extern.slf4j.Slf4j;
... ... @@ -229,18 +229,18 @@ public class GlobalExceptionHandler {
229 229  
230 230 private void createExceptionLog(HttpServletRequest req, Throwable e) {
231 231 // 插入错误日志
232   - ApiErrorLogCreateReqDTO errorLog = new ApiErrorLogCreateReqDTO();
  232 + ApiErrorLog errorLog = new ApiErrorLog();
233 233 try {
234 234 // 初始化 errorLog
235 235 initExceptionLog(errorLog, req, e);
236 236 // 执行插入 errorLog
237   - apiErrorLogFrameworkService.createApiErrorLogAsync(errorLog);
  237 + apiErrorLogFrameworkService.createApiErrorLog(errorLog);
238 238 } catch (Throwable th) {
239 239 log.error("[createExceptionLog][url({}) log({}) 发生异常]", req.getRequestURI(), JsonUtils.toJsonString(errorLog), th);
240 240 }
241 241 }
242 242  
243   - private void initExceptionLog(ApiErrorLogCreateReqDTO errorLog, HttpServletRequest request, Throwable e) {
  243 + private void initExceptionLog(ApiErrorLog errorLog, HttpServletRequest request, Throwable e) {
244 244 // 处理用户信息
245 245 errorLog.setUserId(WebFrameworkUtils.getLoginUserId(request));
246 246 errorLog.setUserType(WebFrameworkUtils.getLoginUserType(request));
... ...
yudao-module-infra/yudao-module-infra-api/pom.xml
... ... @@ -21,6 +21,13 @@
21 21 <groupId>cn.iocoder.boot</groupId>
22 22 <artifactId>yudao-common</artifactId>
23 23 </dependency>
  24 +
  25 + <!-- 参数校验 -->
  26 + <dependency>
  27 + <groupId>org.springframework.boot</groupId>
  28 + <artifactId>spring-boot-starter-validation</artifactId>
  29 + <optional>true</optional>
  30 + </dependency>
24 31 </dependencies>
25 32  
26 33 </project>
... ...
yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/logger/ApiAccessLogApi.java 0 → 100644
  1 +package cn.iocoder.yudao.module.infra.api.logger;
  2 +
  3 +import cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO;
  4 +
  5 +import javax.validation.Valid;
  6 +
  7 +/**
  8 + * API 访问日志的 API 接口
  9 + *
  10 + * @author 芋道源码
  11 + */
  12 +public interface ApiAccessLogApi {
  13 +
  14 + /**
  15 + * 创建 API 访问日志
  16 + *
  17 + * @param createDTO 创建信息
  18 + */
  19 + void createApiAccessLog(@Valid ApiAccessLogCreateReqDTO createDTO);
  20 +
  21 +}
... ...
yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/logger/ApiErrorLogApi.java 0 → 100644
  1 +package cn.iocoder.yudao.module.infra.api.logger;
  2 +
  3 +import cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO;
  4 +
  5 +import javax.validation.Valid;
  6 +
  7 +/**
  8 + * API 错误日志的 API 接口
  9 + *
  10 + * @author 芋道源码
  11 + */
  12 +public interface ApiErrorLogApi {
  13 +
  14 + /**
  15 + * 创建 API 错误日志
  16 + *
  17 + * @param createDTO 创建信息
  18 + */
  19 + void createApiErrorLog(@Valid ApiErrorLogCreateReqDTO createDTO);
  20 +
  21 +}
... ...
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/service/dto/ApiAccessLogCreateReqDTO.java renamed to yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/logger/dto/ApiAccessLogCreateReqDTO.java
1   -package cn.iocoder.yudao.framework.apilog.core.service.dto;
  1 +package cn.iocoder.yudao.module.infra.api.logger.dto;
2 2  
3 3 import lombok.Data;
4 4  
... ... @@ -6,7 +6,7 @@ import javax.validation.constraints.NotNull;
6 6 import java.util.Date;
7 7  
8 8 /**
9   - * API 访问日志创建 DTO
  9 + * API 访问日志
10 10 *
11 11 * @author 芋道源码
12 12 */
... ...
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/service/dto/ApiErrorLogCreateReqDTO.java renamed to yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/logger/dto/ApiErrorLogCreateReqDTO.java
1   -package cn.iocoder.yudao.framework.apilog.core.service.dto;
  1 +package cn.iocoder.yudao.module.infra.api.logger.dto;
2 2  
3 3 import lombok.Data;
4   -import lombok.experimental.Accessors;
5 4  
6 5 import javax.validation.constraints.NotNull;
7 6 import java.util.Date;
8 7  
9 8 /**
10   - * API 错误日志创建 DTO
  9 + * API 错误日志
11 10 *
12 11 * @author 芋道源码
13 12 */
14 13 @Data
15   -@Accessors(chain = true)
16 14 public class ApiErrorLogCreateReqDTO {
17 15  
18 16 /**
... ... @@ -105,4 +103,5 @@ public class ApiErrorLogCreateReqDTO {
105 103 @NotNull(message = "异常导致的消息不能为空")
106 104 private String exceptionMessage;
107 105  
  106 +
108 107 }
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/api/logger/ApiAccessLogApiImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.infra.api.logger;
  2 +
  3 +import cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO;
  4 +import cn.iocoder.yudao.module.infra.service.logger.ApiAccessLogService;
  5 +import org.springframework.stereotype.Service;
  6 +import org.springframework.validation.annotation.Validated;
  7 +
  8 +import javax.annotation.Resource;
  9 +
  10 +/**
  11 + * API 访问日志的 API 实现类
  12 + *
  13 + * @author 芋道源码
  14 + */
  15 +@Service
  16 +@Validated
  17 +public class ApiAccessLogApiImpl implements ApiAccessLogApi {
  18 +
  19 + @Resource
  20 + private ApiAccessLogService apiAccessLogService;
  21 +
  22 + @Override
  23 + public void createApiAccessLog(ApiAccessLogCreateReqDTO createDTO) {
  24 + apiAccessLogService.createApiAccessLog(createDTO);
  25 + }
  26 +
  27 +}
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/api/logger/ApiErrorLogApiImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.infra.api.logger;
  2 +
  3 +import cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO;
  4 +import cn.iocoder.yudao.module.infra.service.logger.ApiErrorLogService;
  5 +import org.springframework.stereotype.Service;
  6 +import org.springframework.validation.annotation.Validated;
  7 +
  8 +import javax.annotation.Resource;
  9 +
  10 +/**
  11 + * API 访问日志的 API 接口
  12 + *
  13 + * @author 芋道源码
  14 + */
  15 +@Service
  16 +@Validated
  17 +public class ApiErrorLogApiImpl implements ApiErrorLogApi {
  18 +
  19 + @Resource
  20 + private ApiErrorLogService apiErrorLogService;
  21 +
  22 + @Override
  23 + public void createApiErrorLog(ApiErrorLogCreateReqDTO createDTO) {
  24 + apiErrorLogService.createApiErrorLog(createDTO);
  25 + }
  26 +
  27 +}
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/logger/ApiAccessLogConvert.java
1 1 package cn.iocoder.yudao.module.infra.convert.logger;
2 2  
3   -import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateReqDTO;
4 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO;
5 5 import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogExcelVO;
6 6 import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogRespVO;
7 7 import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiAccessLogDO;
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/logger/ApiErrorLogConvert.java
1 1 package cn.iocoder.yudao.module.infra.convert.logger;
2 2  
3   -import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateReqDTO;
4 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO;
5 5 import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogExcelVO;
6 6 import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogRespVO;
7 7 import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiErrorLogDO;
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiAccessLogService.java
1 1 package cn.iocoder.yudao.module.infra.service.logger;
2 2  
3   -import cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkService;
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO;
4 5 import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogExportReqVO;
5 6 import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogPageReqVO;
6   -import cn.iocoder.yudao.framework.common.pojo.PageResult;
7 7 import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiAccessLogDO;
8 8  
9 9 import java.util.List;
... ... @@ -13,7 +13,14 @@ import java.util.List;
13 13 *
14 14 * @author 芋道源码
15 15 */
16   -public interface ApiAccessLogService extends ApiAccessLogFrameworkService {
  16 +public interface ApiAccessLogService {
  17 +
  18 + /**
  19 + * 创建 API 访问日志
  20 + *
  21 + * @param createReqDTO API 访问日志
  22 + */
  23 + void createApiAccessLog(ApiAccessLogCreateReqDTO createReqDTO);
17 24  
18 25 /**
19 26 * 获得 API 访问日志分页
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiAccessLogServiceImpl.java
1 1 package cn.iocoder.yudao.module.infra.service.logger;
2 2  
3   -import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateReqDTO;
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO;
4 5 import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogExportReqVO;
5 6 import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogPageReqVO;
6 7 import cn.iocoder.yudao.module.infra.convert.logger.ApiAccessLogConvert;
7 8 import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiAccessLogDO;
8 9 import cn.iocoder.yudao.module.infra.dal.mysql.logger.ApiAccessLogMapper;
9   -import cn.iocoder.yudao.framework.common.pojo.PageResult;
10   -import org.springframework.scheduling.annotation.Async;
11 10 import org.springframework.stereotype.Service;
12 11 import org.springframework.validation.annotation.Validated;
13 12  
... ... @@ -27,6 +26,12 @@ public class ApiAccessLogServiceImpl implements ApiAccessLogService {
27 26 private ApiAccessLogMapper apiAccessLogMapper;
28 27  
29 28 @Override
  29 + public void createApiAccessLog(ApiAccessLogCreateReqDTO createDTO) {
  30 + ApiAccessLogDO apiAccessLog = ApiAccessLogConvert.INSTANCE.convert(createDTO);
  31 + apiAccessLogMapper.insert(apiAccessLog);
  32 + }
  33 +
  34 + @Override
30 35 public PageResult<ApiAccessLogDO> getApiAccessLogPage(ApiAccessLogPageReqVO pageReqVO) {
31 36 return apiAccessLogMapper.selectPage(pageReqVO);
32 37 }
... ... @@ -36,11 +41,4 @@ public class ApiAccessLogServiceImpl implements ApiAccessLogService {
36 41 return apiAccessLogMapper.selectList(exportReqVO);
37 42 }
38 43  
39   - @Override
40   - @Async
41   - public void createApiAccessLogAsync(ApiAccessLogCreateReqDTO createDTO) {
42   - ApiAccessLogDO apiAccessLog = ApiAccessLogConvert.INSTANCE.convert(createDTO);
43   - apiAccessLogMapper.insert(apiAccessLog);
44   - }
45   -
46 44 }
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiErrorLogService.java
1 1 package cn.iocoder.yudao.module.infra.service.logger;
2 2  
3   -import cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService;
4 3 import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO;
5 5 import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogExportReqVO;
6 6 import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogPageReqVO;
7 7 import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiErrorLogDO;
... ... @@ -13,7 +13,14 @@ import java.util.List;
13 13 *
14 14 * @author 芋道源码
15 15 */
16   -public interface ApiErrorLogService extends ApiErrorLogFrameworkService {
  16 +public interface ApiErrorLogService {
  17 +
  18 + /**
  19 + * 创建 API 错误日志
  20 + *
  21 + * @param createReqDTO API 错误日志
  22 + */
  23 + void createApiErrorLog(ApiErrorLogCreateReqDTO createReqDTO);
17 24  
18 25 /**
19 26 * 获得 API 错误日志分页
... ...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiErrorLogServiceImpl.java
1 1 package cn.iocoder.yudao.module.infra.service.logger;
2 2  
3   -import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateReqDTO;
  3 +import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
  4 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  5 +import cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO;
4 6 import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogExportReqVO;
5 7 import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogPageReqVO;
6 8 import cn.iocoder.yudao.module.infra.convert.logger.ApiErrorLogConvert;
7 9 import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiErrorLogDO;
8 10 import cn.iocoder.yudao.module.infra.dal.mysql.logger.ApiErrorLogMapper;
9   -import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
10   -import cn.iocoder.yudao.framework.common.pojo.PageResult;
11 11 import cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants;
12 12 import cn.iocoder.yudao.module.infra.enums.logger.ApiErrorLogProcessStatusEnum;
13   -import org.springframework.scheduling.annotation.Async;
14 13 import org.springframework.stereotype.Service;
15 14 import org.springframework.validation.annotation.Validated;
16 15  
... ... @@ -31,6 +30,13 @@ public class ApiErrorLogServiceImpl implements ApiErrorLogService {
31 30 private ApiErrorLogMapper apiErrorLogMapper;
32 31  
33 32 @Override
  33 + public void createApiErrorLog(ApiErrorLogCreateReqDTO createDTO) {
  34 + ApiErrorLogDO apiErrorLog = ApiErrorLogConvert.INSTANCE.convert(createDTO);
  35 + apiErrorLog.setProcessStatus(ApiErrorLogProcessStatusEnum.INIT.getStatus());
  36 + apiErrorLogMapper.insert(apiErrorLog);
  37 + }
  38 +
  39 + @Override
34 40 public PageResult<ApiErrorLogDO> getApiErrorLogPage(ApiErrorLogPageReqVO pageReqVO) {
35 41 return apiErrorLogMapper.selectPage(pageReqVO);
36 42 }
... ... @@ -54,12 +60,4 @@ public class ApiErrorLogServiceImpl implements ApiErrorLogService {
54 60 .processUserId(processUserId).processTime(new Date()).build());
55 61 }
56 62  
57   - @Override
58   - @Async
59   - public void createApiErrorLogAsync(ApiErrorLogCreateReqDTO createDTO) {
60   - ApiErrorLogDO apiErrorLog = ApiErrorLogConvert.INSTANCE.convert(createDTO);
61   - apiErrorLog.setProcessStatus(ApiErrorLogProcessStatusEnum.INIT.getStatus());
62   - apiErrorLogMapper.insert(apiErrorLog);
63   - }
64   -
65 63 }
... ...
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/logger/ApiAccessLogServiceImplTest.java
1 1 package cn.iocoder.yudao.module.infra.service.logger;
2 2  
3 3 import cn.hutool.core.util.RandomUtil;
4   -import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateReqDTO;
5 4 import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
6 5 import cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants;
7 6 import cn.iocoder.yudao.framework.common.pojo.PageResult;
8 7 import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
9 8 import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
10 9 import cn.iocoder.yudao.framework.test.core.util.RandomUtils;
  10 +import cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO;
11 11 import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogExportReqVO;
12 12 import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogPageReqVO;
13 13 import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiAccessLogDO;
... ... @@ -155,7 +155,7 @@ public class ApiAccessLogServiceImplTest extends BaseDbUnitTest {
155 155 dto -> dto.setUserType(RandomUtil.randomEle(UserTypeEnum.values()).getValue()));
156 156  
157 157 // 调用
158   - apiAccessLogService.createApiAccessLogAsync(createDTO);
  158 + apiAccessLogService.createApiAccessLog(createDTO);
159 159 // 断言
160 160 ApiAccessLogDO infApiAccessLogDO = apiAccessLogMapper.selectOne(null);
161 161 assertNotNull(infApiAccessLogDO);
... ...
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/logger/ApiErrorLogServiceImplTest.java
1 1 package cn.iocoder.yudao.module.infra.service.logger;
2 2  
3 3 import cn.hutool.core.util.RandomUtil;
4   -import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateReqDTO;
5 4 import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
6 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
7 6 import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
8 7 import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
9 8 import cn.iocoder.yudao.framework.test.core.util.RandomUtils;
  9 +import cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO;
10 10 import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogExportReqVO;
11 11 import cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogPageReqVO;
12 12 import cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiErrorLogDO;
... ... @@ -187,7 +187,7 @@ public class ApiErrorLogServiceImplTest extends BaseDbUnitTest {
187 187 dto -> dto.setUserType(RandomUtil.randomEle(UserTypeEnum.values()).getValue()));
188 188  
189 189 // 调用
190   - apiErrorLogService.createApiErrorLogAsync(createDTO);
  190 + apiErrorLogService.createApiErrorLog(createDTO);
191 191 // 断言
192 192 ApiErrorLogDO infApiErrorLogDO = infApiErrorLogMapper.selectOne(null);
193 193 assertNotNull(infApiErrorLogDO);
... ...