fix(log): 优化API日志记录和查询功能

- 实现响应体结构化解析,根据RTYPE字段判断请求状态
- 修复前端查询条件触发时机和日期格式化问题
This commit is contained in:
yangyufu
2026-06-11 14:01:47 +08:00
parent d63437e01b
commit 6011afc791
4 changed files with 39 additions and 18 deletions

View File

@@ -1,6 +1,8 @@
package org.nl.modules.logging.aspect;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
@@ -69,12 +71,29 @@ public class ApiLogAspect {
Object result = joinPoint.proceed();
JSONObject jsonObject = JSONObject.parseObject(JSONUtil.toJsonStr(result));
JSONObject jsonObject1 = jsonObject.getJSONObject("body");
if(null == jsonObject1){
logEntity.setResponseStatus(400);
logEntity.setStatus("FAIL");
logEntity.setErrorMsg("返回信息为空,请确认!");
logEntity.setResponseBody("返回信息为空,请确认!");
}else{
String rtype = jsonObject1.getString("RTYPE");
if(rtype.equalsIgnoreCase("E")){
logEntity.setResponseStatus(400);
logEntity.setStatus("FAIL");
logEntity.setErrorMsg(JSONUtil.toJsonStr(result));
logEntity.setResponseBody(JSONUtil.toJsonStr(result));
}else{
logEntity.setResponseStatus(200);
logEntity.setStatus("SUCCESS");
logEntity.setResponseBody(JSONUtil.toJsonStr(result));
}
}
long costTime = System.currentTimeMillis() - startTime;
logEntity.setCostTime(costTime);
logEntity.setResponseStatus(200);
logEntity.setStatus("SUCCESS");
logEntity.setResponseBody(JSONUtil.toJsonStr(result));
return result;
} catch (Throwable throwable) {

View File

@@ -71,12 +71,14 @@ public class SysApiLogController {
wrapper.eq(SysApiLog::getStatus, query.getStatus());
}
if (query.getBeginTime() != null && !query.getBeginTime().isEmpty()) {
wrapper.ge(SysApiLog::getCreateTime, query.getBeginTime());
if (query.getBegin_time() != null && !query.getBegin_time().isEmpty()) {
String beginTime = query.getBegin_time() + " 00:00:00";
wrapper.ge(SysApiLog::getCreateTime, beginTime);
}
if (query.getEndTime() != null && !query.getEndTime().isEmpty()) {
wrapper.le(SysApiLog::getCreateTime, query.getEndTime());
if (query.getEnd_time() != null && !query.getEnd_time().isEmpty()) {
String endTime = query.getEnd_time() + " 23:59:59";
wrapper.le(SysApiLog::getCreateTime, endTime);
}
if (query.getKeyword() != null && !query.getKeyword().isEmpty()) {

View File

@@ -24,9 +24,9 @@ public class ApiLogQuery extends PageQuery {
private String status;
private String beginTime;
private String begin_time;
private String endTime;
private String end_time;
private String keyword;