fix(log): 优化API日志记录和查询功能
- 实现响应体结构化解析,根据RTYPE字段判断请求状态 - 修复前端查询条件触发时机和日期格式化问题
This commit is contained in:
@@ -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();
|
||||
|
||||
long costTime = System.currentTimeMillis() - startTime;
|
||||
logEntity.setCostTime(costTime);
|
||||
|
||||
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);
|
||||
return result;
|
||||
|
||||
} catch (Throwable throwable) {
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
placeholder="请输入关键字查询"
|
||||
class="filter-item"
|
||||
style="width: 200px;"
|
||||
@keyup.enter.native="crud.toQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="接口走向">
|
||||
@@ -27,7 +26,6 @@
|
||||
size="mini"
|
||||
placeholder="请选择"
|
||||
class="filter-item"
|
||||
@change="crud.toQuery"
|
||||
>
|
||||
<el-option label="出站" :value="0" />
|
||||
<el-option label="入站" :value="1" />
|
||||
@@ -56,7 +54,6 @@
|
||||
size="mini"
|
||||
placeholder="请选择"
|
||||
class="filter-item"
|
||||
@change="crud.toQuery"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in bizCodeList"
|
||||
@@ -73,7 +70,6 @@
|
||||
size="mini"
|
||||
placeholder="请选择"
|
||||
class="filter-item"
|
||||
@change="crud.toQuery"
|
||||
>
|
||||
<el-option label="SUCCESS" value="SUCCESS" />
|
||||
<el-option label="FAIL" value="FAIL" />
|
||||
@@ -83,11 +79,10 @@
|
||||
<el-date-picker
|
||||
v-model="query.createTime"
|
||||
type="daterange"
|
||||
value-format="yyyy-MM-dd HH:mm:ss"
|
||||
range-separator="至"
|
||||
start-placeholder="开始日期"
|
||||
end-placeholder="结束日期"
|
||||
:default-time="['00:00:00', '23:59:59']"
|
||||
@change="crud.toQuery"
|
||||
value-format="yyyy-MM-dd"
|
||||
/>
|
||||
</el-form-item>
|
||||
<rrOperation />
|
||||
@@ -212,11 +207,16 @@ export default {
|
||||
name: 'SysApiLog',
|
||||
components: { rrOperation, crudOperation, pagination },
|
||||
cruds() {
|
||||
const today = new Date()
|
||||
const year = today.getFullYear()
|
||||
const month = String(today.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(today.getDate()).padStart(2, '0')
|
||||
const dateStr = `${year}-${month}-${day}`
|
||||
return CRUD({
|
||||
title: '接口日志',
|
||||
url: 'api/sysApiLog',
|
||||
query: {
|
||||
createTime: [new Date(), new Date()]
|
||||
createTime: [dateStr, dateStr]
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user