Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yudao-cloud
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
hblj
yudao-cloud
Commits
4c6e915d
提交
4c6e915d
authored
6月 14, 2022
作者:
YunaiV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化 yudao-spring-boot-starter-web 的 API 日志封装,和 yudao-cloud 保持一致
上级
284ee500
隐藏空白字符变更
内嵌
并排
正在显示
34 个修改的文件
包含
441 行增加
和
166 行删除
+441
-166
SmsTemplateAddPO.java
...oder/mall/system/application/po/sms/SmsTemplateAddPO.java
+0
-49
SmsTemplateUpdatePO.java
...r/mall/system/application/po/sms/SmsTemplateUpdatePO.java
+0
-53
pom.xml
yudao-framework/yudao-spring-boot-starter-web/pom.xml
+14
-1
YudaoApiLogAutoConfiguration.java
...framework/apilog/config/YudaoApiLogAutoConfiguration.java
+15
-0
YudaoApiLogRpcAutoConfiguration.java
...mework/apilog/config/YudaoApiLogRpcAutoConfiguration.java
+17
-0
ApiAccessLogFilter.java
...udao/framework/apilog/core/filter/ApiAccessLogFilter.java
+4
-4
ApiAccessLog.java
...der/yudao/framework/apilog/core/service/ApiAccessLog.java
+3
-3
ApiAccessLogFrameworkService.java
...ork/apilog/core/service/ApiAccessLogFrameworkService.java
+2
-6
ApiAccessLogFrameworkServiceImpl.java
...apilog/core/service/ApiAccessLogFrameworkServiceImpl.java
+30
-0
ApiErrorLog.java
...oder/yudao/framework/apilog/core/service/ApiErrorLog.java
+4
-5
ApiErrorLogFrameworkService.java
...work/apilog/core/service/ApiErrorLogFrameworkService.java
+2
-6
ApiErrorLogFrameworkServiceImpl.java
.../apilog/core/service/ApiErrorLogFrameworkServiceImpl.java
+30
-0
GlobalExceptionHandler.java
...ao/framework/web/core/handler/GlobalExceptionHandler.java
+4
-5
spring.factories
...-starter-web/src/main/resources/META-INF/spring.factories
+1
-0
pom.xml
yudao-module-infra/yudao-module-infra-api/pom.xml
+21
-0
ApiAccessLogApi.java
...ocoder/yudao/module/infra/api/logger/ApiAccessLogApi.java
+24
-0
ApiErrorLogApi.java
...iocoder/yudao/module/infra/api/logger/ApiErrorLogApi.java
+24
-0
ApiAccessLogCreateReqDTO.java
...module/infra/api/logger/dto/ApiAccessLogCreateReqDTO.java
+56
-0
ApiErrorLogCreateReqDTO.java
.../module/infra/api/logger/dto/ApiErrorLogCreateReqDTO.java
+69
-0
ApiConstants.java
...ava/cn/iocoder/yudao/module/infra/enums/ApiConstants.java
+1
-1
ApiAccessLogApiImpl.java
...er/yudao/module/infra/api/logger/ApiAccessLogApiImpl.java
+29
-0
ApiErrorLogApiImpl.java
...der/yudao/module/infra/api/logger/ApiErrorLogApiImpl.java
+31
-0
FileConfigController.http
...ule/infra/controller/admin/file/FileConfigController.http
+1
-1
ApiAccessLogConvert.java
...udao/module/infra/convert/logger/ApiAccessLogConvert.java
+2
-1
ApiErrorLogConvert.java
...yudao/module/infra/convert/logger/ApiErrorLogConvert.java
+2
-1
SecurityConfiguration.java
...nfra/framework/security/config/SecurityConfiguration.java
+5
-0
ApiAccessLogService.java
...udao/module/infra/service/logger/ApiAccessLogService.java
+10
-1
ApiAccessLogServiceImpl.java
.../module/infra/service/logger/ApiAccessLogServiceImpl.java
+8
-8
ApiErrorLogService.java
...yudao/module/infra/service/logger/ApiErrorLogService.java
+10
-1
ApiErrorLogServiceImpl.java
...o/module/infra/service/logger/ApiErrorLogServiceImpl.java
+9
-9
ApiAccessLogServiceImplTest.java
...ule/infra/service/logger/ApiAccessLogServiceImplTest.java
+4
-3
ApiErrorLogServiceImplTest.java
...dule/infra/service/logger/ApiErrorLogServiceImplTest.java
+4
-3
OperateLogCreateReqDTO.java
.../module/system/api/logger/dto/OperateLogCreateReqDTO.java
+1
-1
TmpConfiguration.java
...coder/yudao/module/system/framework/TmpConfiguration.java
+4
-4
没有找到文件。
moved/system/system-start/src/main/java/cn/iocoder/mall/system/application/po/sms/SmsTemplateAddPO.java
deleted
100644 → 0
浏览文件 @
284ee500
package
cn
.
iocoder
.
mall
.
system
.
application
.
po
.
sms
;
import
cn.iocoder.common.framework.validator.InEnum
;
import
cn.iocoder.mall.system.api.constant.SmsPlatformEnum
;
import
cn.iocoder.mall.system.api.constant.SmsTypeEnum
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.experimental.Accessors
;
import
javax.validation.constraints.NotNull
;
import
javax.validation.constraints.Size
;
import
java.io.Serializable
;
/**
* 短信模板 add
*
* @author Sin
* @time 2019/5/26 12:37 PM
*/
@ApiModel
(
"短信模板-添加"
)
@Data
@Accessors
(
chain
=
true
)
public
class
SmsTemplateAddPO
implements
Serializable
{
@ApiModelProperty
(
"短信签名id"
)
@NotNull
(
message
=
"短信短信签名id不能为空!"
)
private
Integer
smsSignId
;
@ApiModelProperty
(
"短信模板code"
)
@NotNull
@Size
(
min
=
3
,
max
=
50
,
message
=
"短信code在 3-50 之间"
)
private
String
templateCode
;
@ApiModelProperty
(
"短信模板"
)
@NotNull
@Size
(
min
=
3
,
max
=
255
,
message
=
"短信在 3-255 之间"
)
private
String
template
;
@ApiModelProperty
(
"短信模板-平台"
)
@NotNull
@InEnum
(
value
=
SmsPlatformEnum
.
class
)
private
Integer
platform
;
@ApiModelProperty
(
"短信模板-平台"
)
@NotNull
@InEnum
(
value
=
SmsTypeEnum
.
class
)
private
Integer
smsType
;
}
moved/system/system-start/src/main/java/cn/iocoder/mall/system/application/po/sms/SmsTemplateUpdatePO.java
deleted
100644 → 0
浏览文件 @
284ee500
package
cn
.
iocoder
.
mall
.
system
.
application
.
po
.
sms
;
import
cn.iocoder.common.framework.validator.InEnum
;
import
cn.iocoder.mall.system.api.constant.SmsPlatformEnum
;
import
cn.iocoder.mall.system.api.constant.SmsTypeEnum
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.experimental.Accessors
;
import
javax.validation.constraints.NotNull
;
import
javax.validation.constraints.Size
;
import
java.io.Serializable
;
/**
* 短信模板 add
*
* @author Sin
* @time 2019/5/26 12:37 PM
*/
@ApiModel
(
"短信模板-添加"
)
@Data
@Accessors
(
chain
=
true
)
public
class
SmsTemplateUpdatePO
implements
Serializable
{
@ApiModelProperty
(
"短信模板id"
)
@NotNull
(
message
=
"短信模板不能为空!"
)
private
Integer
id
;
@ApiModelProperty
(
"短信签名id"
)
@NotNull
(
message
=
"短信短信签名id不能为空!"
)
private
Integer
smsSignId
;
@ApiModelProperty
(
"短信模板code"
)
@NotNull
@Size
(
min
=
3
,
max
=
50
,
message
=
"短信code在 3-50 之间"
)
private
String
templateCode
;
@ApiModelProperty
(
"短信模板"
)
@NotNull
@Size
(
min
=
3
,
max
=
255
,
message
=
"短信在 3-255 之间"
)
private
String
template
;
@ApiModelProperty
(
"短信模板-平台"
)
@NotNull
@InEnum
(
value
=
SmsPlatformEnum
.
class
)
private
Integer
platform
;
@ApiModelProperty
(
"短信模板-平台"
)
@NotNull
@InEnum
(
value
=
SmsTypeEnum
.
class
)
private
Integer
smsType
;
}
yudao-framework/yudao-spring-boot-starter-web/pom.xml
浏览文件 @
4c6e915d
...
...
@@ -53,13 +53,26 @@
<scope>
provided
</scope>
<!-- 设置为 provided,主要是 GlobalExceptionHandler 使用 -->
</dependency>
<!-- RPC 远程调用相关 -->
<dependency>
<groupId>
cn.iocoder.cloud
</groupId>
<artifactId>
yudao-spring-boot-starter-rpc
</artifactId>
<optional>
true
</optional>
</dependency>
<!-- 业务组件 -->
<dependency>
<groupId>
cn.iocoder.cloud
</groupId>
<artifactId>
yudao-module-infra-api
</artifactId>
<!-- 需要使用它,进行操作日志的记录 -->
<version>
${revision}
</version>
</dependency>
<!-- 服务保障相关 -->
<dependency>
<groupId>
io.github.resilience4j
</groupId>
<artifactId>
resilience4j-ratelimiter
</artifactId>
<scope>
provided
</scope>
<!-- 设置为 provided,主要是 GlobalExceptionHandler 使用 -->
</dependency>
</dependencies>
</project>
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/config/YudaoApiLogAutoConfiguration.java
浏览文件 @
4c6e915d
...
...
@@ -2,9 +2,14 @@ package cn.iocoder.yudao.framework.apilog.config;
import
cn.iocoder.yudao.framework.apilog.core.filter.ApiAccessLogFilter
;
import
cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkService
;
import
cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkServiceImpl
;
import
cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService
;
import
cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkServiceImpl
;
import
cn.iocoder.yudao.framework.web.config.WebProperties
;
import
cn.iocoder.yudao.framework.web.config.YudaoWebAutoConfiguration
;
import
cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum
;
import
cn.iocoder.yudao.module.infra.api.logger.ApiAccessLogApi
;
import
cn.iocoder.yudao.module.infra.api.logger.ApiErrorLogApi
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
...
...
@@ -17,6 +22,16 @@ import javax.servlet.Filter;
@AutoConfigureAfter
(
YudaoWebAutoConfiguration
.
class
)
public
class
YudaoApiLogAutoConfiguration
{
@Bean
public
ApiAccessLogFrameworkService
apiAccessLogFrameworkService
(
ApiAccessLogApi
apiAccessLogApi
)
{
return
new
ApiAccessLogFrameworkServiceImpl
(
apiAccessLogApi
);
}
@Bean
public
ApiErrorLogFrameworkService
apiErrorLogFrameworkService
(
ApiErrorLogApi
apiErrorLogApi
)
{
return
new
ApiErrorLogFrameworkServiceImpl
(
apiErrorLogApi
);
}
/**
* 创建 ApiAccessLogFilter Bean,记录 API 请求日志
*/
...
...
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/config/YudaoApiLogRpcAutoConfiguration.java
0 → 100644
浏览文件 @
4c6e915d
package
cn
.
iocoder
.
yudao
.
framework
.
apilog
.
config
;
import
cn.iocoder.yudao.module.infra.api.logger.ApiAccessLogApi
;
import
cn.iocoder.yudao.module.infra.api.logger.ApiErrorLogApi
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.context.annotation.Configuration
;
/**
* API 日志使用到 Feign 的配置项
*
* @author 芋道源码
*/
@Configuration
(
proxyBeanMethods
=
false
)
@EnableFeignClients
(
clients
=
{
ApiAccessLogApi
.
class
,
// 主要是引入相关的 API 服务
ApiErrorLogApi
.
class
})
public
class
YudaoApiLogRpcAutoConfiguration
{
}
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/filter/ApiAccessLogFilter.java
浏览文件 @
4c6e915d
...
...
@@ -3,8 +3,8 @@ package cn.iocoder.yudao.framework.apilog.core.filter;
import
cn.hutool.core.exceptions.ExceptionUtil
;
import
cn.hutool.core.map.MapUtil
;
import
cn.hutool.extra.servlet.ServletUtil
;
import
cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLog
;
import
cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkService
;
import
cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateReqDTO
;
import
cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants
;
import
cn.iocoder.yudao.framework.common.pojo.CommonResult
;
import
cn.iocoder.yudao.framework.common.util.date.DateUtils
;
...
...
@@ -66,16 +66,16 @@ public class ApiAccessLogFilter extends ApiRequestFilter {
private
void
createApiAccessLog
(
HttpServletRequest
request
,
Date
beginTime
,
Map
<
String
,
String
>
queryString
,
String
requestBody
,
Exception
ex
)
{
ApiAccessLog
CreateReqDTO
accessLog
=
new
ApiAccessLogCreateReqDTO
();
ApiAccessLog
accessLog
=
new
ApiAccessLog
();
try
{
this
.
buildApiAccessLogDTO
(
accessLog
,
request
,
beginTime
,
queryString
,
requestBody
,
ex
);
apiAccessLogFrameworkService
.
createApiAccessLog
Async
(
accessLog
);
apiAccessLogFrameworkService
.
createApiAccessLog
(
accessLog
);
}
catch
(
Throwable
th
)
{
log
.
error
(
"[createApiAccessLog][url({}) log({}) 发生异常]"
,
request
.
getRequestURI
(),
toJsonString
(
accessLog
),
th
);
}
}
private
void
buildApiAccessLogDTO
(
ApiAccessLog
CreateReqDTO
accessLog
,
HttpServletRequest
request
,
Date
beginTime
,
private
void
buildApiAccessLogDTO
(
ApiAccessLog
accessLog
,
HttpServletRequest
request
,
Date
beginTime
,
Map
<
String
,
String
>
queryString
,
String
requestBody
,
Exception
ex
)
{
// 处理用户信息
accessLog
.
setUserId
(
WebFrameworkUtils
.
getLoginUserId
(
request
));
...
...
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/service/
dto/ApiAccessLogCreateReqDTO
.java
→
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/service/
ApiAccessLog
.java
浏览文件 @
4c6e915d
package
cn
.
iocoder
.
yudao
.
framework
.
apilog
.
core
.
service
.
dto
;
package
cn
.
iocoder
.
yudao
.
framework
.
apilog
.
core
.
service
;
import
lombok.Data
;
...
...
@@ -6,12 +6,12 @@ import javax.validation.constraints.NotNull;
import
java.util.Date
;
/**
* API 访问日志
创建 DTO
* API 访问日志
*
* @author 芋道源码
*/
@Data
public
class
ApiAccessLog
CreateReqDTO
{
public
class
ApiAccessLog
{
/**
* 链路追踪编号
...
...
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/service/ApiAccessLogFrameworkService.java
浏览文件 @
4c6e915d
package
cn
.
iocoder
.
yudao
.
framework
.
apilog
.
core
.
service
;
import
cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateReqDTO
;
import
javax.validation.Valid
;
/**
* API 访问日志 Framework Service 接口
*
...
...
@@ -14,8 +10,8 @@ public interface ApiAccessLogFrameworkService {
/**
* 创建 API 访问日志
*
* @param
createDTO 创建信息
* @param
apiAccessLog API 访问日志
*/
void
createApiAccessLog
Async
(
@Valid
ApiAccessLogCreateReqDTO
createDTO
);
void
createApiAccessLog
(
ApiAccessLog
apiAccessLog
);
}
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/service/ApiAccessLogFrameworkServiceImpl.java
0 → 100644
浏览文件 @
4c6e915d
package
cn
.
iocoder
.
yudao
.
framework
.
apilog
.
core
.
service
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.iocoder.yudao.framework.common.pojo.CommonResult
;
import
cn.iocoder.yudao.module.infra.api.logger.ApiAccessLogApi
;
import
cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.scheduling.annotation.Async
;
/**
* API 访问日志 Framework Service 实现类
*
* 基于 {@link ApiAccessLogApi} 远程服务,记录访问日志
*
* @author 芋道源码
*/
@RequiredArgsConstructor
public
class
ApiAccessLogFrameworkServiceImpl
implements
ApiAccessLogFrameworkService
{
private
final
ApiAccessLogApi
apiAccessLogApi
;
@Override
@Async
public
void
createApiAccessLog
(
ApiAccessLog
apiAccessLog
)
{
ApiAccessLogCreateReqDTO
reqDTO
=
BeanUtil
.
copyProperties
(
apiAccessLog
,
ApiAccessLogCreateReqDTO
.
class
);
CommonResult
<
Boolean
>
result
=
apiAccessLogApi
.
createApiAccessLog
(
reqDTO
);
result
.
checkError
();
}
}
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/service/
dto/ApiErrorLogCreateReqDTO
.java
→
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/service/
ApiErrorLog
.java
浏览文件 @
4c6e915d
package
cn
.
iocoder
.
yudao
.
framework
.
apilog
.
core
.
service
.
dto
;
package
cn
.
iocoder
.
yudao
.
framework
.
apilog
.
core
.
service
;
import
lombok.Data
;
import
lombok.experimental.Accessors
;
import
javax.validation.constraints.NotNull
;
import
java.util.Date
;
/**
* API 错误日志
创建 DTO
* API 错误日志
*
* @author 芋道源码
*/
@Data
@Accessors
(
chain
=
true
)
public
class
ApiErrorLogCreateReqDTO
{
public
class
ApiErrorLog
{
/**
* 链路编号
...
...
@@ -105,4 +103,5 @@ public class ApiErrorLogCreateReqDTO {
@NotNull
(
message
=
"异常导致的消息不能为空"
)
private
String
exceptionMessage
;
}
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/service/ApiErrorLogFrameworkService.java
浏览文件 @
4c6e915d
package
cn
.
iocoder
.
yudao
.
framework
.
apilog
.
core
.
service
;
import
cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateReqDTO
;
import
javax.validation.Valid
;
/**
* API 错误日志 Framework Service 接口
*
...
...
@@ -14,8 +10,8 @@ public interface ApiErrorLogFrameworkService {
/**
* 创建 API 错误日志
*
* @param
createDTO 创建信息
* @param
apiErrorLog API 错误日志
*/
void
createApiErrorLog
Async
(
@Valid
ApiErrorLogCreateReqDTO
createDTO
);
void
createApiErrorLog
(
ApiErrorLog
apiErrorLog
);
}
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/apilog/core/service/ApiErrorLogFrameworkServiceImpl.java
0 → 100644
浏览文件 @
4c6e915d
package
cn
.
iocoder
.
yudao
.
framework
.
apilog
.
core
.
service
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.iocoder.yudao.framework.common.pojo.CommonResult
;
import
cn.iocoder.yudao.module.infra.api.logger.ApiErrorLogApi
;
import
cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.scheduling.annotation.Async
;
/**
* API 错误日志 Framework Service 实现类
*
* 基于 {@link ApiErrorLogApi} 远程服务,记录错误日志
*
* @author 芋道源码
*/
@RequiredArgsConstructor
public
class
ApiErrorLogFrameworkServiceImpl
implements
ApiErrorLogFrameworkService
{
private
final
ApiErrorLogApi
apiErrorLogApi
;
@Override
@Async
public
void
createApiErrorLog
(
ApiErrorLog
apiErrorLog
)
{
ApiErrorLogCreateReqDTO
reqDTO
=
BeanUtil
.
copyProperties
(
apiErrorLog
,
ApiErrorLogCreateReqDTO
.
class
);
CommonResult
<
Boolean
>
result
=
apiErrorLogApi
.
createApiErrorLog
(
reqDTO
);
result
.
checkError
();
}
}
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/handler/GlobalExceptionHandler.java
浏览文件 @
4c6e915d
...
...
@@ -3,15 +3,14 @@ package cn.iocoder.yudao.framework.web.core.handler;
import
cn.hutool.core.exceptions.ExceptionUtil
;
import
cn.hutool.core.map.MapUtil
;
import
cn.hutool.extra.servlet.ServletUtil
;
import
cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLog
;
import
cn.iocoder.yudao.framework.common.exception.ServiceException
;
import
cn.iocoder.yudao.framework.common.pojo.CommonResult
;
import
cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService
;
import
cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateReqDTO
;
import
cn.iocoder.yudao.framework.common.util.monitor.TracerUtils
;
import
cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils
;
import
cn.iocoder.yudao.framework.common.util.json.JsonUtils
;
import
cn.iocoder.yudao.framework.common.util.servlet.ServletUtils
;
import
io.github.resilience4j.ratelimiter.RequestNotPermitted
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.exception.ExceptionUtils
;
...
...
@@ -230,18 +229,18 @@ public class GlobalExceptionHandler {
private
void
createExceptionLog
(
HttpServletRequest
req
,
Throwable
e
)
{
// 插入错误日志
ApiErrorLog
CreateReqDTO
errorLog
=
new
ApiErrorLogCreateReqDTO
();
ApiErrorLog
errorLog
=
new
ApiErrorLog
();
try
{
// 初始化 errorLog
initExceptionLog
(
errorLog
,
req
,
e
);
// 执行插入 errorLog
apiErrorLogFrameworkService
.
createApiErrorLog
Async
(
errorLog
);
apiErrorLogFrameworkService
.
createApiErrorLog
(
errorLog
);
}
catch
(
Throwable
th
)
{
log
.
error
(
"[createExceptionLog][url({}) log({}) 发生异常]"
,
req
.
getRequestURI
(),
JsonUtils
.
toJsonString
(
errorLog
),
th
);
}
}
private
void
initExceptionLog
(
ApiErrorLog
CreateReqDTO
errorLog
,
HttpServletRequest
request
,
Throwable
e
)
{
private
void
initExceptionLog
(
ApiErrorLog
errorLog
,
HttpServletRequest
request
,
Throwable
e
)
{
// 处理用户信息
errorLog
.
setUserId
(
WebFrameworkUtils
.
getLoginUserId
(
request
));
errorLog
.
setUserType
(
WebFrameworkUtils
.
getLoginUserType
(
request
));
...
...
yudao-framework/yudao-spring-boot-starter-web/src/main/resources/META-INF/spring.factories
浏览文件 @
4c6e915d
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.iocoder.yudao.framework.apilog.config.YudaoApiLogRpcAutoConfiguration,\
cn.iocoder.yudao.framework.apilog.config.YudaoApiLogAutoConfiguration,\
cn.iocoder.yudao.framework.jackson.config.YudaoJacksonAutoConfiguration,\
cn.iocoder.yudao.framework.swagger.config.YudaoSwaggerAutoConfiguration,\
...
...
yudao-module-infra/yudao-module-infra-api/pom.xml
浏览文件 @
4c6e915d
...
...
@@ -21,6 +21,27 @@
<groupId>
cn.iocoder.cloud
</groupId>
<artifactId>
yudao-common
</artifactId>
</dependency>
<!-- Web 相关 -->
<dependency>
<groupId>
io.swagger
</groupId>
<artifactId>
swagger-annotations
</artifactId>
<optional>
true
</optional>
</dependency>
<!-- 参数校验 -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-validation
</artifactId>
<optional>
true
</optional>
</dependency>
<!-- RPC 远程调用相关 -->
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-openfeign
</artifactId>
<optional>
true
</optional>
</dependency>
</dependencies>
</project>
yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/logger/ApiAccessLogApi.java
0 → 100644
浏览文件 @
4c6e915d
package
cn
.
iocoder
.
yudao
.
module
.
infra
.
api
.
logger
;
import
cn.iocoder.yudao.framework.common.pojo.CommonResult
;
import
cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO
;
import
cn.iocoder.yudao.module.infra.enums.ApiConstants
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
javax.validation.Valid
;
@FeignClient
(
name
=
ApiConstants
.
NAME
)
// TODO 芋艿:fallbackFactory =
@Api
(
tags
=
"RPC 服务 - API 访问日志"
)
public
interface
ApiAccessLogApi
{
String
PREFIX
=
ApiConstants
.
PREFIX
+
"/api-access-log"
;
@PostMapping
(
PREFIX
+
"/create"
)
@ApiOperation
(
"创建 API 访问日志"
)
CommonResult
<
Boolean
>
createApiAccessLog
(
@Valid
@RequestBody
ApiAccessLogCreateReqDTO
createDTO
);
}
yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/logger/ApiErrorLogApi.java
0 → 100644
浏览文件 @
4c6e915d
package
cn
.
iocoder
.
yudao
.
module
.
infra
.
api
.
logger
;
import
cn.iocoder.yudao.framework.common.pojo.CommonResult
;
import
cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO
;
import
cn.iocoder.yudao.module.infra.enums.ApiConstants
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
javax.validation.Valid
;
@FeignClient
(
name
=
ApiConstants
.
NAME
)
// TODO 芋艿:fallbackFactory =
@Api
(
tags
=
"RPC 服务 - API 异常日志"
)
public
interface
ApiErrorLogApi
{
String
PREFIX
=
ApiConstants
.
PREFIX
+
"/api-error-log"
;
@PostMapping
(
PREFIX
+
"/create"
)
@ApiOperation
(
"创建 API 异常日志"
)
CommonResult
<
Boolean
>
createApiErrorLog
(
@Valid
@RequestBody
ApiErrorLogCreateReqDTO
createDTO
);
}
yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/logger/dto/ApiAccessLogCreateReqDTO.java
0 → 100644
浏览文件 @
4c6e915d
package
cn
.
iocoder
.
yudao
.
module
.
infra
.
api
.
logger
.
dto
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
javax.validation.constraints.NotNull
;
import
java.util.Date
;
@ApiModel
(
"API 访问日志创建 Request DTO"
)
@Data
public
class
ApiAccessLogCreateReqDTO
{
@ApiModelProperty
(
value
=
"链路追踪编号"
,
example
=
"89aca178-a370-411c-ae02-3f0d672be4ab"
)
private
String
traceId
;
@ApiModelProperty
(
value
=
"用户编号"
,
required
=
true
,
example
=
"1024"
)
private
Long
userId
;
@ApiModelProperty
(
value
=
"用户类型"
,
required
=
true
,
example
=
"1"
)
private
Integer
userType
;
@ApiModelProperty
(
value
=
"应用名"
,
required
=
true
,
example
=
"system-server"
)
@NotNull
(
message
=
"应用名不能为空"
)
private
String
applicationName
;
@ApiModelProperty
(
value
=
"请求方法名"
,
required
=
true
,
example
=
"GET"
)
@NotNull
(
message
=
"http 请求方法不能为空"
)
private
String
requestMethod
;
@ApiModelProperty
(
value
=
"请求地址"
,
required
=
true
,
example
=
"/xxx/yyy"
)
@NotNull
(
message
=
"访问地址不能为空"
)
private
String
requestUrl
;
@ApiModelProperty
(
value
=
"请求参数"
,
required
=
true
)
@NotNull
(
message
=
"请求参数不能为空"
)
private
String
requestParams
;
@ApiModelProperty
(
value
=
"用户 IP"
,
required
=
true
,
example
=
"127.0.0.1"
)
@NotNull
(
message
=
"ip 不能为空"
)
private
String
userIp
;
@ApiModelProperty
(
value
=
"浏览器 UserAgent"
,
required
=
true
,
example
=
"Mozilla/5.0"
)
@NotNull
(
message
=
"User-Agent 不能为空"
)
private
String
userAgent
;
@ApiModelProperty
(
value
=
"开始时间"
,
required
=
true
)
@NotNull
(
message
=
"开始请求时间不能为空"
)
private
Date
beginTime
;
@ApiModelProperty
(
value
=
"结束时间"
,
required
=
true
)
@NotNull
(
message
=
"结束请求时间不能为空"
)
private
Date
endTime
;
@ApiModelProperty
(
value
=
"执行时长,单位:毫秒"
,
required
=
true
)
@NotNull
(
message
=
"执行时长不能为空"
)
private
Integer
duration
;
@ApiModelProperty
(
value
=
"结果码"
,
required
=
true
)
@NotNull
(
message
=
"错误码不能为空"
)
private
Integer
resultCode
;
@ApiModelProperty
(
value
=
"结果提示"
)
private
String
resultMsg
;
}
yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/api/logger/dto/ApiErrorLogCreateReqDTO.java
0 → 100644
浏览文件 @
4c6e915d
package
cn
.
iocoder
.
yudao
.
module
.
infra
.
api
.
logger
.
dto
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
javax.validation.constraints.NotNull
;
import
java.util.Date
;
@ApiModel
(
"API 错误日志创建 Request DTO"
)
@Data
public
class
ApiErrorLogCreateReqDTO
{
@ApiModelProperty
(
value
=
"链路追踪编号"
,
example
=
"89aca178-a370-411c-ae02-3f0d672be4ab"
)
private
String
traceId
;
@ApiModelProperty
(
value
=
"用户编号"
,
required
=
true
,
example
=
"1024"
)
private
Long
userId
;
@ApiModelProperty
(
value
=
"用户类型"
,
required
=
true
,
example
=
"1"
)
private
Integer
userType
;
@ApiModelProperty
(
value
=
"应用名"
,
required
=
true
,
example
=
"system-server"
)
@NotNull
(
message
=
"应用名不能为空"
)
private
String
applicationName
;
@ApiModelProperty
(
value
=
"请求方法名"
,
required
=
true
,
example
=
"GET"
)
@NotNull
(
message
=
"http 请求方法不能为空"
)
private
String
requestMethod
;
@ApiModelProperty
(
value
=
"请求地址"
,
required
=
true
,
example
=
"/xxx/yyy"
)
@NotNull
(
message
=
"访问地址不能为空"
)
private
String
requestUrl
;
@ApiModelProperty
(
value
=
"请求参数"
,
required
=
true
)
@NotNull
(
message
=
"请求参数不能为空"
)
private
String
requestParams
;
@ApiModelProperty
(
value
=
"用户 IP"
,
required
=
true
,
example
=
"127.0.0.1"
)
@NotNull
(
message
=
"ip 不能为空"
)
private
String
userIp
;
@ApiModelProperty
(
value
=
"浏览器 UserAgent"
,
required
=
true
,
example
=
"Mozilla/5.0"
)
@NotNull
(
message
=
"User-Agent 不能为空"
)
private
String
userAgent
;
@ApiModelProperty
(
value
=
"异常时间"
,
required
=
true
)
@NotNull
(
message
=
"异常时间不能为空"
)
private
Date
exceptionTime
;
@ApiModelProperty
(
value
=
"异常名"
,
required
=
true
)
@NotNull
(
message
=
"异常名不能为空"
)
private
String
exceptionName
;
@ApiModelProperty
(
value
=
"异常发生的类全名"
,
required
=
true
)
@NotNull
(
message
=
"异常发生的类全名不能为空"
)
private
String
exceptionClassName
;
@ApiModelProperty
(
value
=
"异常发生的类文件"
,
required
=
true
)
@NotNull
(
message
=
"异常发生的类文件不能为空"
)
private
String
exceptionFileName
;
@ApiModelProperty
(
value
=
"异常发生的方法名"
,
required
=
true
)
@NotNull
(
message
=
"异常发生的方法名不能为空"
)
private
String
exceptionMethodName
;
@ApiModelProperty
(
value
=
"异常发生的方法所在行"
,
required
=
true
)
@NotNull
(
message
=
"异常发生的方法所在行不能为空"
)
private
Integer
exceptionLineNumber
;
@ApiModelProperty
(
value
=
"异常的栈轨迹异常的栈轨迹"
,
required
=
true
)
@NotNull
(
message
=
"异常的栈轨迹不能为空"
)
private
String
exceptionStackTrace
;
@ApiModelProperty
(
value
=
"异常导致的根消息"
,
required
=
true
)
@NotNull
(
message
=
"异常导致的根消息不能为空"
)
private
String
exceptionRootCauseMessage
;
@ApiModelProperty
(
value
=
"异常导致的消息"
,
required
=
true
)
@NotNull
(
message
=
"异常导致的消息不能为空"
)
private
String
exceptionMessage
;
}
yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ApiConstants.java
浏览文件 @
4c6e915d
...
...
@@ -16,7 +16,7 @@ public class ApiConstants {
*/
public
static
final
String
NAME
=
"infra-server"
;
public
static
final
String
PREFIX
=
RpcConstants
.
RPC_API_PREFIX
+
"/
system
"
;
public
static
final
String
PREFIX
=
RpcConstants
.
RPC_API_PREFIX
+
"/
infra
"
;
public
static
final
String
VERSION
=
"1.0.0"
;
...
...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/api/logger/ApiAccessLogApiImpl.java
0 → 100644
浏览文件 @
4c6e915d
package
cn
.
iocoder
.
yudao
.
module
.
infra
.
api
.
logger
;
import
cn.iocoder.yudao.framework.common.pojo.CommonResult
;
import
cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO
;
import
cn.iocoder.yudao.module.infra.service.logger.ApiAccessLogService
;
import
org.apache.dubbo.config.annotation.DubboService
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
import
static
cn
.
iocoder
.
yudao
.
framework
.
common
.
pojo
.
CommonResult
.
success
;
import
static
cn
.
iocoder
.
yudao
.
module
.
system
.
enums
.
ApiConstants
.
VERSION
;
@RestController
// 提供 RESTful API 接口,给 Feign 调用
@DubboService
(
version
=
VERSION
)
// 提供 Dubbo RPC 接口,给 Dubbo Consumer 调用
@Validated
public
class
ApiAccessLogApiImpl
implements
ApiAccessLogApi
{
@Resource
private
ApiAccessLogService
apiAccessLogService
;
@Override
public
CommonResult
<
Boolean
>
createApiAccessLog
(
ApiAccessLogCreateReqDTO
createDTO
)
{
apiAccessLogService
.
createApiAccessLog
(
createDTO
);
return
success
(
true
);
}
}
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/api/logger/ApiErrorLogApiImpl.java
0 → 100644
浏览文件 @
4c6e915d
package
cn
.
iocoder
.
yudao
.
module
.
infra
.
api
.
logger
;
import
cn.iocoder.yudao.framework.common.pojo.CommonResult
;
import
cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO
;
import
cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO
;
import
cn.iocoder.yudao.module.infra.service.logger.ApiAccessLogService
;
import
cn.iocoder.yudao.module.infra.service.logger.ApiErrorLogService
;
import
org.apache.dubbo.config.annotation.DubboService
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
import
static
cn
.
iocoder
.
yudao
.
framework
.
common
.
pojo
.
CommonResult
.
success
;
import
static
cn
.
iocoder
.
yudao
.
module
.
system
.
enums
.
ApiConstants
.
VERSION
;
@RestController
// 提供 RESTful API 接口,给 Feign 调用
@DubboService
(
version
=
VERSION
)
// 提供 Dubbo RPC 接口,给 Dubbo Consumer 调用
@Validated
public
class
ApiErrorLogApiImpl
implements
ApiErrorLogApi
{
@Resource
private
ApiErrorLogService
apiErrorLogService
;
@Override
public
CommonResult
<
Boolean
>
createApiErrorLog
(
ApiErrorLogCreateReqDTO
createDTO
)
{
apiErrorLogService
.
createApiErrorLog
(
createDTO
);
return
success
(
true
);
}
}
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileConfigController.http
浏览文件 @
4c6e915d
...
...
@@ -39,7 +39,7 @@ Authorization: Bearer {{token}}
}
### 请求 /infra/file-config/test 接口 => 成功
GET {{
b
aseUrl}}/infra/file-config/test?id=2
GET {{
infaB
aseUrl}}/infra/file-config/test?id=2
Content-Type: application/json
tenant-id: {{adminTenentId}}
Authorization: Bearer {{token}}
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/convert/logger/ApiAccessLogConvert.java
浏览文件 @
4c6e915d
package
cn
.
iocoder
.
yudao
.
module
.
infra
.
convert
.
logger
;
import
cn.iocoder.yudao.framework.apilog.core.service.
dto.ApiAccessLogCreateReqDTO
;
import
cn.iocoder.yudao.framework.apilog.core.service.
ApiAccessLog
;
import
cn.iocoder.yudao.framework.common.pojo.PageResult
;
import
cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO
;
import
cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogExcelVO
;
import
cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogRespVO
;
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
浏览文件 @
4c6e915d
package
cn
.
iocoder
.
yudao
.
module
.
infra
.
convert
.
logger
;
import
cn.iocoder.yudao.framework.apilog.core.service.
dto.ApiErrorLogCreateReqDTO
;
import
cn.iocoder.yudao.framework.apilog.core.service.
ApiErrorLog
;
import
cn.iocoder.yudao.framework.common.pojo.PageResult
;
import
cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO
;
import
cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogExcelVO
;
import
cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogRespVO
;
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/framework/security/config/SecurityConfiguration.java
浏览文件 @
4c6e915d
package
cn
.
iocoder
.
yudao
.
module
.
infra
.
framework
.
security
.
config
;
import
cn.iocoder.yudao.framework.security.config.AuthorizeRequestsCustomizer
;
import
cn.iocoder.yudao.module.infra.enums.ApiConstants
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -37,6 +38,10 @@ public class SecurityConfiguration {
.
antMatchers
(
adminSeverContextPath
+
"/**"
).
anonymous
();
// 文件的获取接口,可匿名访问
registry
.
antMatchers
(
buildAdminApi
(
"/infra/file/*/get/**"
),
buildAppApi
(
"/infra/file/get/**"
)).
permitAll
();
// TODO 芋艿:这个每个项目都需要重复配置,得捉摸有没通用的方案
// RPC 服务的安全配置
registry
.
antMatchers
(
ApiConstants
.
PREFIX
+
"/**"
).
permitAll
();
}
};
...
...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiAccessLogService.java
浏览文件 @
4c6e915d
package
cn
.
iocoder
.
yudao
.
module
.
infra
.
service
.
logger
;
import
cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLog
;
import
cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkService
;
import
cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO
;
import
cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogExportReqVO
;
import
cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogPageReqVO
;
import
cn.iocoder.yudao.framework.common.pojo.PageResult
;
...
...
@@ -13,7 +15,14 @@ import java.util.List;
*
* @author 芋道源码
*/
public
interface
ApiAccessLogService
extends
ApiAccessLogFrameworkService
{
public
interface
ApiAccessLogService
{
/**
* 创建 API 访问日志
*
* @param createReqDTO API 访问日志
*/
void
createApiAccessLog
(
ApiAccessLogCreateReqDTO
createReqDTO
);
/**
* 获得 API 访问日志分页
...
...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiAccessLogServiceImpl.java
浏览文件 @
4c6e915d
package
cn
.
iocoder
.
yudao
.
module
.
infra
.
service
.
logger
;
import
cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateReqDTO
;
import
cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLog
;
import
cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO
;
import
cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogExportReqVO
;
import
cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogPageReqVO
;
import
cn.iocoder.yudao.module.infra.convert.logger.ApiAccessLogConvert
;
...
...
@@ -26,6 +27,12 @@ public class ApiAccessLogServiceImpl implements ApiAccessLogService {
@Resource
private
ApiAccessLogMapper
apiAccessLogMapper
;
@Override
public
void
createApiAccessLog
(
ApiAccessLogCreateReqDTO
createDTO
)
{
ApiAccessLogDO
apiAccessLog
=
ApiAccessLogConvert
.
INSTANCE
.
convert
(
createDTO
);
apiAccessLogMapper
.
insert
(
apiAccessLog
);
}
@Override
public
PageResult
<
ApiAccessLogDO
>
getApiAccessLogPage
(
ApiAccessLogPageReqVO
pageReqVO
)
{
return
apiAccessLogMapper
.
selectPage
(
pageReqVO
);
...
...
@@ -36,11 +43,4 @@ public class ApiAccessLogServiceImpl implements ApiAccessLogService {
return
apiAccessLogMapper
.
selectList
(
exportReqVO
);
}
@Override
@Async
public
void
createApiAccessLogAsync
(
ApiAccessLogCreateReqDTO
createDTO
)
{
ApiAccessLogDO
apiAccessLog
=
ApiAccessLogConvert
.
INSTANCE
.
convert
(
createDTO
);
apiAccessLogMapper
.
insert
(
apiAccessLog
);
}
}
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiErrorLogService.java
浏览文件 @
4c6e915d
package
cn
.
iocoder
.
yudao
.
module
.
infra
.
service
.
logger
;
import
cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLog
;
import
cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService
;
import
cn.iocoder.yudao.framework.common.pojo.PageResult
;
import
cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO
;
import
cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogExportReqVO
;
import
cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogPageReqVO
;
import
cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiErrorLogDO
;
...
...
@@ -13,7 +15,14 @@ import java.util.List;
*
* @author 芋道源码
*/
public
interface
ApiErrorLogService
extends
ApiErrorLogFrameworkService
{
public
interface
ApiErrorLogService
{
/**
* 创建 API 错误日志
*
* @param createReqDTO API 错误日志
*/
void
createApiErrorLog
(
ApiErrorLogCreateReqDTO
createReqDTO
);
/**
* 获得 API 错误日志分页
...
...
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiErrorLogServiceImpl.java
浏览文件 @
4c6e915d
package
cn
.
iocoder
.
yudao
.
module
.
infra
.
service
.
logger
;
import
cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateReqDTO
;
import
cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLog
;
import
cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO
;
import
cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogExportReqVO
;
import
cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogPageReqVO
;
import
cn.iocoder.yudao.module.infra.convert.logger.ApiErrorLogConvert
;
...
...
@@ -30,6 +31,13 @@ public class ApiErrorLogServiceImpl implements ApiErrorLogService {
@Resource
private
ApiErrorLogMapper
apiErrorLogMapper
;
@Override
public
void
createApiErrorLog
(
ApiErrorLogCreateReqDTO
createDTO
)
{
ApiErrorLogDO
apiErrorLog
=
ApiErrorLogConvert
.
INSTANCE
.
convert
(
createDTO
);
apiErrorLog
.
setProcessStatus
(
ApiErrorLogProcessStatusEnum
.
INIT
.
getStatus
());
apiErrorLogMapper
.
insert
(
apiErrorLog
);
}
@Override
public
PageResult
<
ApiErrorLogDO
>
getApiErrorLogPage
(
ApiErrorLogPageReqVO
pageReqVO
)
{
return
apiErrorLogMapper
.
selectPage
(
pageReqVO
);
...
...
@@ -54,12 +62,4 @@ public class ApiErrorLogServiceImpl implements ApiErrorLogService {
.
processUserId
(
processUserId
).
processTime
(
new
Date
()).
build
());
}
@Override
@Async
public
void
createApiErrorLogAsync
(
ApiErrorLogCreateReqDTO
createDTO
)
{
ApiErrorLogDO
apiErrorLog
=
ApiErrorLogConvert
.
INSTANCE
.
convert
(
createDTO
);
apiErrorLog
.
setProcessStatus
(
ApiErrorLogProcessStatusEnum
.
INIT
.
getStatus
());
apiErrorLogMapper
.
insert
(
apiErrorLog
);
}
}
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/logger/ApiAccessLogServiceImplTest.java
浏览文件 @
4c6e915d
package
cn
.
iocoder
.
yudao
.
module
.
infra
.
service
.
logger
;
import
cn.hutool.core.util.RandomUtil
;
import
cn.iocoder.yudao.framework.apilog.core.service.
dto.ApiAccessLogCreateReqDTO
;
import
cn.iocoder.yudao.framework.apilog.core.service.
ApiAccessLog
;
import
cn.iocoder.yudao.framework.common.enums.UserTypeEnum
;
import
cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeConstants
;
import
cn.iocoder.yudao.framework.common.pojo.PageResult
;
import
cn.iocoder.yudao.framework.common.util.object.ObjectUtils
;
import
cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest
;
import
cn.iocoder.yudao.framework.test.core.util.RandomUtils
;
import
cn.iocoder.yudao.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO
;
import
cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogExportReqVO
;
import
cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apiaccesslog.ApiAccessLogPageReqVO
;
import
cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiAccessLogDO
;
...
...
@@ -149,13 +150,13 @@ public class ApiAccessLogServiceImplTest extends BaseDbUnitTest {
}
@Test
public
void
testCreateApiAccessLog
Async
()
{
public
void
testCreateApiAccessLog
()
{
// 准备参数
ApiAccessLogCreateReqDTO
createDTO
=
RandomUtils
.
randomPojo
(
ApiAccessLogCreateReqDTO
.
class
,
dto
->
dto
.
setUserType
(
RandomUtil
.
randomEle
(
UserTypeEnum
.
values
()).
getValue
()));
// 调用
apiAccessLogService
.
createApiAccessLog
Async
(
createDTO
);
apiAccessLogService
.
createApiAccessLog
(
createDTO
);
// 断言
ApiAccessLogDO
infApiAccessLogDO
=
apiAccessLogMapper
.
selectOne
(
null
);
assertNotNull
(
infApiAccessLogDO
);
...
...
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/logger/ApiErrorLogServiceImplTest.java
浏览文件 @
4c6e915d
package
cn
.
iocoder
.
yudao
.
module
.
infra
.
service
.
logger
;
import
cn.hutool.core.util.RandomUtil
;
import
cn.iocoder.yudao.framework.apilog.core.service.
dto.ApiErrorLogCreateReqDTO
;
import
cn.iocoder.yudao.framework.apilog.core.service.
ApiErrorLog
;
import
cn.iocoder.yudao.framework.common.enums.UserTypeEnum
;
import
cn.iocoder.yudao.framework.common.pojo.PageResult
;
import
cn.iocoder.yudao.framework.common.util.object.ObjectUtils
;
import
cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest
;
import
cn.iocoder.yudao.framework.test.core.util.RandomUtils
;
import
cn.iocoder.yudao.module.infra.api.logger.dto.ApiErrorLogCreateReqDTO
;
import
cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogExportReqVO
;
import
cn.iocoder.yudao.module.infra.controller.admin.logger.vo.apierrorlog.ApiErrorLogPageReqVO
;
import
cn.iocoder.yudao.module.infra.dal.dataobject.logger.ApiErrorLogDO
;
...
...
@@ -181,13 +182,13 @@ public class ApiErrorLogServiceImplTest extends BaseDbUnitTest {
}
@Test
public
void
testCreateApiErrorLog
Async
()
{
public
void
testCreateApiErrorLog
()
{
// 准备参数
ApiErrorLogCreateReqDTO
createDTO
=
RandomUtils
.
randomPojo
(
ApiErrorLogCreateReqDTO
.
class
,
dto
->
dto
.
setUserType
(
RandomUtil
.
randomEle
(
UserTypeEnum
.
values
()).
getValue
()));
// 调用
apiErrorLogService
.
createApiErrorLog
Async
(
createDTO
);
apiErrorLogService
.
createApiErrorLog
(
createDTO
);
// 断言
ApiErrorLogDO
infApiErrorLogDO
=
infApiErrorLogMapper
.
selectOne
(
null
);
assertNotNull
(
infApiErrorLogDO
);
...
...
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/logger/dto/OperateLogCreateReqDTO.java
浏览文件 @
4c6e915d
...
...
@@ -13,7 +13,7 @@ import java.util.Map;
@Data
public
class
OperateLogCreateReqDTO
{
@ApiModelProperty
(
value
=
"链路追踪编号"
,
required
=
true
,
example
=
"89aca178-a370-411c-ae02-3f0d672be4ab"
)
@ApiModelProperty
(
value
=
"链路追踪编号"
,
example
=
"89aca178-a370-411c-ae02-3f0d672be4ab"
)
private
String
traceId
;
@ApiModelProperty
(
value
=
"用户编号"
,
required
=
true
,
example
=
"1024"
)
...
...
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/TmpConfiguration.java
浏览文件 @
4c6e915d
package
cn
.
iocoder
.
yudao
.
module
.
system
.
framework
;
import
cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLog
;
import
cn.iocoder.yudao.framework.apilog.core.service.ApiAccessLogFrameworkService
;
import
cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLog
;
import
cn.iocoder.yudao.framework.apilog.core.service.ApiErrorLogFrameworkService
;
import
cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateReqDTO
;
import
cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateReqDTO
;
import
cn.iocoder.yudao.module.infra.api.file.FileApi
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -25,7 +25,7 @@ public class TmpConfiguration {
public
ApiAccessLogFrameworkService
apiAccessLogFrameworkService
()
{
return
new
ApiAccessLogFrameworkService
()
{
@Override
public
void
createApiAccessLog
Async
(
ApiAccessLogCreateReqDTO
createDTO
)
{
public
void
createApiAccessLog
(
ApiAccessLog
apiAccessLog
)
{
}
};
...
...
@@ -35,7 +35,7 @@ public class TmpConfiguration {
public
ApiErrorLogFrameworkService
apiErrorLogFrameworkService
()
{
return
new
ApiErrorLogFrameworkService
()
{
@Override
public
void
createApiErrorLog
Async
(
ApiErrorLogCreateReqDTO
createDTO
)
{
public
void
createApiErrorLog
(
ApiErrorLog
apiErrorLog
)
{
}
};
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论