新增业务外部接口日志管理
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package com.ruoyi.system.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 业务外部接口调用日志。
|
||||
*/
|
||||
@Data
|
||||
public class SysApiLog {
|
||||
|
||||
private Long logId;
|
||||
private Long callerUserId;
|
||||
private String callerUsername;
|
||||
private String apiUrl;
|
||||
private String httpMethod;
|
||||
private String contentType;
|
||||
private String requestHeaders;
|
||||
private String requestParams;
|
||||
private Integer responseStatus;
|
||||
private String responseHeaders;
|
||||
private String responseBody;
|
||||
private String callStatus;
|
||||
private String errorMsg;
|
||||
private Long costTime;
|
||||
private Date callTime;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.ruoyi.system.domain.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 接口日志查询条件。
|
||||
*/
|
||||
@Data
|
||||
public class SysApiLogQueryDTO {
|
||||
|
||||
private String apiUrl;
|
||||
private String httpMethod;
|
||||
private String callStatus;
|
||||
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date beginTime;
|
||||
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date endTime;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.ruoyi.system.domain.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 接口日志完整详情。
|
||||
*/
|
||||
@Data
|
||||
public class SysApiLogDetailVO {
|
||||
|
||||
private Long logId;
|
||||
private Long callerUserId;
|
||||
private String callerUsername;
|
||||
private String apiUrl;
|
||||
private String httpMethod;
|
||||
private String contentType;
|
||||
private String requestHeaders;
|
||||
private String requestParams;
|
||||
private Integer responseStatus;
|
||||
private String responseHeaders;
|
||||
private String responseBody;
|
||||
private String callStatus;
|
||||
private String errorMsg;
|
||||
private Long costTime;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date callTime;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.ruoyi.system.domain.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 接口日志列表项,不包含请求响应大字段。
|
||||
*/
|
||||
@Data
|
||||
public class SysApiLogListVO {
|
||||
|
||||
private Long logId;
|
||||
private Long callerUserId;
|
||||
private String callerUsername;
|
||||
private String apiUrl;
|
||||
private String httpMethod;
|
||||
private Integer responseStatus;
|
||||
private String callStatus;
|
||||
private Long costTime;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date callTime;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.ruoyi.system.mapper;
|
||||
|
||||
import com.ruoyi.system.domain.SysApiLog;
|
||||
import com.ruoyi.system.domain.dto.SysApiLogQueryDTO;
|
||||
import com.ruoyi.system.domain.vo.SysApiLogDetailVO;
|
||||
import com.ruoyi.system.domain.vo.SysApiLogListVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 接口日志数据层。
|
||||
*/
|
||||
public interface SysApiLogMapper {
|
||||
|
||||
int insertApiLog(SysApiLog apiLog);
|
||||
|
||||
List<SysApiLogListVO> selectApiLogList(SysApiLogQueryDTO queryDTO);
|
||||
|
||||
SysApiLogDetailVO selectApiLogById(Long logId);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.ruoyi.system.service;
|
||||
|
||||
import com.ruoyi.system.domain.SysApiLog;
|
||||
import com.ruoyi.system.domain.dto.SysApiLogQueryDTO;
|
||||
import com.ruoyi.system.domain.vo.SysApiLogDetailVO;
|
||||
import com.ruoyi.system.domain.vo.SysApiLogListVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 接口日志服务。
|
||||
*/
|
||||
public interface ISysApiLogService {
|
||||
|
||||
void recordApiLog(SysApiLog apiLog);
|
||||
|
||||
List<SysApiLogListVO> selectApiLogList(SysApiLogQueryDTO queryDTO);
|
||||
|
||||
SysApiLogDetailVO selectApiLogById(Long logId);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import com.ruoyi.system.domain.SysApiLog;
|
||||
import com.ruoyi.system.domain.dto.SysApiLogQueryDTO;
|
||||
import com.ruoyi.system.domain.vo.SysApiLogDetailVO;
|
||||
import com.ruoyi.system.domain.vo.SysApiLogListVO;
|
||||
import com.ruoyi.system.mapper.SysApiLogMapper;
|
||||
import com.ruoyi.system.service.ISysApiLogService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 接口日志服务实现。
|
||||
*/
|
||||
@Service
|
||||
public class SysApiLogServiceImpl implements ISysApiLogService {
|
||||
|
||||
@Resource
|
||||
private SysApiLogMapper apiLogMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||
public void recordApiLog(SysApiLog apiLog) {
|
||||
apiLogMapper.insertApiLog(apiLog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysApiLogListVO> selectApiLogList(SysApiLogQueryDTO queryDTO) {
|
||||
return apiLogMapper.selectApiLogList(queryDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysApiLogDetailVO selectApiLogById(Long logId) {
|
||||
return apiLogMapper.selectApiLogById(logId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.system.mapper.SysApiLogMapper">
|
||||
|
||||
<insert id="insertApiLog" parameterType="com.ruoyi.system.domain.SysApiLog" useGeneratedKeys="true" keyProperty="logId">
|
||||
insert into sys_api_log (
|
||||
caller_user_id, caller_username, api_url, http_method, content_type,
|
||||
request_headers, request_params, response_status, response_headers,
|
||||
response_body, call_status, error_msg, cost_time, call_time
|
||||
) values (
|
||||
#{callerUserId}, #{callerUsername}, #{apiUrl}, #{httpMethod}, #{contentType},
|
||||
#{requestHeaders}, #{requestParams}, #{responseStatus}, #{responseHeaders},
|
||||
#{responseBody}, #{callStatus}, #{errorMsg}, #{costTime}, #{callTime}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<select id="selectApiLogList" parameterType="com.ruoyi.system.domain.dto.SysApiLogQueryDTO"
|
||||
resultType="com.ruoyi.system.domain.vo.SysApiLogListVO">
|
||||
select log_id as logId,
|
||||
caller_user_id as callerUserId,
|
||||
caller_username as callerUsername,
|
||||
api_url as apiUrl,
|
||||
http_method as httpMethod,
|
||||
response_status as responseStatus,
|
||||
call_status as callStatus,
|
||||
cost_time as costTime,
|
||||
call_time as callTime
|
||||
from sys_api_log
|
||||
<where>
|
||||
<if test="apiUrl != null and apiUrl != ''">
|
||||
and api_url like concat('%', #{apiUrl}, '%')
|
||||
</if>
|
||||
<if test="httpMethod != null and httpMethod != ''">
|
||||
and http_method = #{httpMethod}
|
||||
</if>
|
||||
<if test="callStatus != null and callStatus != ''">
|
||||
and call_status = #{callStatus}
|
||||
</if>
|
||||
<if test="beginTime != null">
|
||||
and call_time >= #{beginTime}
|
||||
</if>
|
||||
<if test="endTime != null">
|
||||
and call_time <= #{endTime}
|
||||
</if>
|
||||
</where>
|
||||
order by call_time desc, log_id desc
|
||||
</select>
|
||||
|
||||
<select id="selectApiLogById" parameterType="Long"
|
||||
resultType="com.ruoyi.system.domain.vo.SysApiLogDetailVO">
|
||||
select log_id as logId,
|
||||
caller_user_id as callerUserId,
|
||||
caller_username as callerUsername,
|
||||
api_url as apiUrl,
|
||||
http_method as httpMethod,
|
||||
content_type as contentType,
|
||||
request_headers as requestHeaders,
|
||||
request_params as requestParams,
|
||||
response_status as responseStatus,
|
||||
response_headers as responseHeaders,
|
||||
response_body as responseBody,
|
||||
call_status as callStatus,
|
||||
error_msg as errorMsg,
|
||||
cost_time as costTime,
|
||||
call_time as callTime
|
||||
from sys_api_log
|
||||
where log_id = #{logId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user