!110 feat(syslog): 操作日志新增操作结果列,记录成功失败并追加失败原因
Merge pull request !110 from wsm/feature/log_oper_res_add
This commit is contained in:
@@ -66,6 +66,11 @@ public class LogDTO implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private Integer userSecurityLevel;
|
private Integer userSecurityLevel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作结果(1成功,0失败)
|
||||||
|
*/
|
||||||
|
private Integer operateResult;
|
||||||
|
|
||||||
public LogDTO(){
|
public LogDTO(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,18 +78,36 @@ public class AutoLogAspect {
|
|||||||
@Around("logPointCut()")
|
@Around("logPointCut()")
|
||||||
public Object around(ProceedingJoinPoint point) throws Throwable {
|
public Object around(ProceedingJoinPoint point) throws Throwable {
|
||||||
long beginTime = System.currentTimeMillis();
|
long beginTime = System.currentTimeMillis();
|
||||||
|
boolean success = true;
|
||||||
|
String errorMsg = null;
|
||||||
|
Object result = null;
|
||||||
|
try {
|
||||||
//执行方法
|
//执行方法
|
||||||
Object result = point.proceed();
|
result = point.proceed();
|
||||||
|
} catch (Exception e) {
|
||||||
|
//方法抛异常:记录失败,但不吞异常,保持原业务行为
|
||||||
|
success = false;
|
||||||
|
errorMsg = e.getMessage();
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
//update-begin-author:wsm date:20260805 for:判定操作结果,返回值 Result.error 也视为失败
|
||||||
|
if (success && result instanceof Result) {
|
||||||
|
Result<?> res = (Result<?>) result;
|
||||||
|
if (!res.isSuccess()) {
|
||||||
|
success = false;
|
||||||
|
errorMsg = res.getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//update-end-author:wsm date:20260805 for:判定操作结果,返回值 Result.error 也视为失败
|
||||||
//执行时长(毫秒)
|
//执行时长(毫秒)
|
||||||
long time = System.currentTimeMillis() - beginTime;
|
long time = System.currentTimeMillis() - beginTime;
|
||||||
|
|
||||||
//保存日志
|
//保存日志
|
||||||
saveSysLog(point, time, result);
|
saveSysLog(point, time, success, errorMsg, result);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveSysLog(ProceedingJoinPoint joinPoint, long time, Object obj) {
|
private void saveSysLog(ProceedingJoinPoint joinPoint, long time, boolean success, String errorMsg, Object obj) {
|
||||||
try {
|
try {
|
||||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||||
Method method = signature.getMethod();
|
Method method = signature.getMethod();
|
||||||
@@ -107,6 +125,15 @@ public class AutoLogAspect {
|
|||||||
dto.setLogContent(content);
|
dto.setLogContent(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//update-begin-author:wsm date:20260805 for:记录操作结果,失败原因追加到日志内容
|
||||||
|
dto.setOperateResult(success ? CommonConstant.OPERATE_RESULT_SUCCESS : CommonConstant.OPERATE_RESULT_FAIL);
|
||||||
|
if (!success && oConvertUtils.isNotEmpty(errorMsg)) {
|
||||||
|
String reason = errorMsg.length() > 500 ? errorMsg.substring(0, 500) : errorMsg;
|
||||||
|
String content = dto.getLogContent() == null ? "" : dto.getLogContent();
|
||||||
|
dto.setLogContent(content + ",失败原因:" + reason);
|
||||||
|
}
|
||||||
|
//update-end-author:wsm date:20260805 for:记录操作结果,失败原因追加到日志内容
|
||||||
|
|
||||||
//请求的方法名
|
//请求的方法名
|
||||||
String className = joinPoint.getTarget().getClass().getName();
|
String className = joinPoint.getTarget().getClass().getName();
|
||||||
String methodName = signature.getName();
|
String methodName = signature.getName();
|
||||||
|
|||||||
@@ -76,6 +76,16 @@ public interface CommonConstant {
|
|||||||
*/
|
*/
|
||||||
int OPERATE_TYPE_6 = 6;
|
int OPERATE_TYPE_6 = 6;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作结果: 成功
|
||||||
|
*/
|
||||||
|
int OPERATE_RESULT_SUCCESS = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作结果: 失败
|
||||||
|
*/
|
||||||
|
int OPERATE_RESULT_FAIL = 0;
|
||||||
|
|
||||||
|
|
||||||
/** {@code 500 Server Error} (HTTP/1.0 - RFC 1945) */
|
/** {@code 500 Server Error} (HTTP/1.0 - RFC 1945) */
|
||||||
Integer SC_INTERNAL_SERVER_ERROR_500 = 500;
|
Integer SC_INTERNAL_SERVER_ERROR_500 = 500;
|
||||||
|
|||||||
+2
-1
@@ -4,13 +4,14 @@
|
|||||||
|
|
||||||
<!-- 保存日志11 -->
|
<!-- 保存日志11 -->
|
||||||
<insert id="saveLog" parameterType="Object">
|
<insert id="saveLog" parameterType="Object">
|
||||||
insert into sys_log (id, log_type, log_content, method, operate_type, request_url, request_type, request_param, ip, userid, username, cost_time, create_time,create_by, tenant_id, client_type, user_security_level)
|
insert into sys_log (id, log_type, log_content, method, operate_type, operate_result, request_url, request_type, request_param, ip, userid, username, cost_time, create_time,create_by, tenant_id, client_type, user_security_level)
|
||||||
values(
|
values(
|
||||||
#{dto.id,jdbcType=VARCHAR},
|
#{dto.id,jdbcType=VARCHAR},
|
||||||
#{dto.logType,jdbcType=INTEGER},
|
#{dto.logType,jdbcType=INTEGER},
|
||||||
#{dto.logContent,jdbcType=VARCHAR},
|
#{dto.logContent,jdbcType=VARCHAR},
|
||||||
#{dto.method,jdbcType=VARCHAR},
|
#{dto.method,jdbcType=VARCHAR},
|
||||||
#{dto.operateType,jdbcType=INTEGER},
|
#{dto.operateType,jdbcType=INTEGER},
|
||||||
|
#{dto.operateResult,jdbcType=INTEGER},
|
||||||
#{dto.requestUrl,jdbcType=VARCHAR},
|
#{dto.requestUrl,jdbcType=VARCHAR},
|
||||||
#{dto.requestType,jdbcType=VARCHAR},
|
#{dto.requestType,jdbcType=VARCHAR},
|
||||||
#{dto.requestParam,jdbcType=VARCHAR},
|
#{dto.requestParam,jdbcType=VARCHAR},
|
||||||
|
|||||||
+5
@@ -125,4 +125,9 @@ public class SysLog implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private Integer userSecurityLevel;
|
private Integer userSecurityLevel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作结果(1成功,0失败)
|
||||||
|
*/
|
||||||
|
private Integer operateResult;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ YYYYMMDD_描述.sql
|
|||||||
| 2026-07-09 | DML | `20260709_新增督办状态字典.sql` | 新增 super_status 字典(未开始/督办中/已完成) |
|
| 2026-07-09 | DML | `20260709_新增督办状态字典.sql` | 新增 super_status 字典(未开始/督办中/已完成) |
|
||||||
| 2026-07-09 | DML | `20260709_新增反馈任务状态字典.sql` | 新增 feedback_status 字典(未开始/进行中/已完成) |
|
| 2026-07-09 | DML | `20260709_新增反馈任务状态字典.sql` | 新增 feedback_status 字典(未开始/进行中/已完成) |
|
||||||
| 2026-08-05 | DDL | `20260805_系统日志表新增操作人密级字段.sql` | sys_log 新增 user_security_level 列,记录操作人密级 |
|
| 2026-08-05 | DDL | `20260805_系统日志表新增操作人密级字段.sql` | sys_log 新增 user_security_level 列,记录操作人密级 |
|
||||||
|
| 2026-08-05 | DDL | `20260805_系统日志表新增操作结果字段.sql` | sys_log 新增 operate_result 列,记录操作日志成功/失败 |
|
||||||
|
|
||||||
## 使用方式
|
## 使用方式
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
-- 系统日志表新增操作结果字段
|
||||||
|
-- @AutoLog 标注的方法执行成功/失败时记录:1成功,0失败
|
||||||
|
-- 失败原因追加到 log_content
|
||||||
|
-- 变更日期:2026-08-05
|
||||||
|
ALTER TABLE `sys_log`
|
||||||
|
ADD COLUMN `operate_result` tinyint(1) NULL DEFAULT NULL COMMENT '操作结果(1成功,0失败)' AFTER `operate_type`;
|
||||||
Reference in New Issue
Block a user