优化日志管理接口
parent
9c3eb1493d
commit
20be213faf
|
@ -51,7 +51,7 @@ public class ApiAccessFilter extends OncePerRequestFilter {
|
|||
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
|
||||
if (uriName != null && userSetting != null && userSetting.getLogInDatabase() != null && userSetting.getLogInDatabase()) {
|
||||
if (!servletRequest.getRequestURI().startsWith("/api/log") && uriName != null && userSetting != null && userSetting.getLogInDatabase() != null && userSetting.getLogInDatabase()) {
|
||||
|
||||
LogDto logDto = new LogDto();
|
||||
logDto.setName(uriName);
|
||||
|
|
|
@ -18,7 +18,7 @@ public interface ILogService {
|
|||
* @param endTime 结束时间
|
||||
* @return 日志列表
|
||||
*/
|
||||
PageInfo<LogDto> getAll(int page, int count, String query, String type, String startTime, String endTime);
|
||||
PageInfo<LogDto> getAll(int page, int count, String query, String type, String startTime, String endTime, Boolean result);
|
||||
|
||||
/**
|
||||
* 添加日志
|
||||
|
@ -31,4 +31,5 @@ public interface ILogService {
|
|||
*/
|
||||
int clear();
|
||||
|
||||
void deleteById(int id);
|
||||
}
|
||||
|
|
|
@ -18,9 +18,9 @@ public class LogServiceImpl implements ILogService {
|
|||
private LogMapper logMapper;
|
||||
|
||||
@Override
|
||||
public PageInfo<LogDto> getAll(int page, int count, String query, String type, String startTime, String endTime) {
|
||||
public PageInfo<LogDto> getAll(int page, int count, String query, String type, String startTime, String endTime, Boolean result) {
|
||||
PageHelper.startPage(page, count);
|
||||
List<LogDto> all = logMapper.query(query, type, startTime, endTime);
|
||||
List<LogDto> all = logMapper.query(query, type, startTime, endTime, result);
|
||||
return new PageInfo<>(all);
|
||||
}
|
||||
|
||||
|
@ -33,4 +33,9 @@ public class LogServiceImpl implements ILogService {
|
|||
public int clear() {
|
||||
return logMapper.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteById(int id) {
|
||||
logMapper.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,14 +24,23 @@ public interface LogMapper {
|
|||
@Select(value = {"<script>" +
|
||||
" SELECT * FROM wvp_log " +
|
||||
" WHERE 1=1 " +
|
||||
" <if test=\"query != null\"> AND (name LIKE concat('%',#{query},'%'))</if> " +
|
||||
" <if test=\"type != null\" > AND type = #{type}</if>" +
|
||||
" <if test=\"startTime != null\" > AND create_time >= #{startTime} </if>" +
|
||||
" <if test=\"endTime != null\" > AND create_time <= #{endTime} </if>" +
|
||||
" <if test='query != null'> AND (name LIKE concat('%',#{query},'%'))</if> " +
|
||||
" <if test='type != null' > AND type = #{type}</if>" +
|
||||
" <if test='startTime != null' > AND create_time >= #{startTime} </if>" +
|
||||
" <if test='endTime != null' > AND create_time <= #{endTime} </if>" +
|
||||
" <if test='result != null and result == true' > AND result = '200 OK' </if>" +
|
||||
" <if test='result != null and result == false' > AND result != '200 OK' </if>" +
|
||||
" ORDER BY create_time DESC " +
|
||||
" </script>"})
|
||||
List<LogDto> query(@Param("query") String query, @Param("type") String type, @Param("startTime") String startTime, @Param("endTime") String endTime);
|
||||
List<LogDto> query(@Param("query") String query, @Param("type") String type,
|
||||
@Param("startTime") String startTime,
|
||||
@Param("endTime") String endTime,
|
||||
@Param("result") Boolean result
|
||||
);
|
||||
|
||||
@Delete("DELETE FROM wvp_log")
|
||||
int clear();
|
||||
|
||||
@Delete("DELETE FROM wvp_log where id = #{id}")
|
||||
void deleteById(@Param("id") int id);
|
||||
}
|
||||
|
|
|
@ -57,11 +57,15 @@ public class LogController {
|
|||
@RequestParam(required = false) String query,
|
||||
@RequestParam(required = false) String type,
|
||||
@RequestParam(required = false) String startTime,
|
||||
@RequestParam(required = false) String endTime
|
||||
@RequestParam(required = false) String endTime,
|
||||
@RequestParam(required = false) Boolean result
|
||||
) {
|
||||
if (ObjectUtils.isEmpty(query)) {
|
||||
query = null;
|
||||
}
|
||||
if (ObjectUtils.isEmpty(type)) {
|
||||
type = null;
|
||||
}
|
||||
|
||||
if (!userSetting.getLogInDatabase()) {
|
||||
logger.warn("自动记录日志功能已关闭,查询结果可能不完整。");
|
||||
|
@ -79,7 +83,17 @@ public class LogController {
|
|||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "endTime格式为" + DateUtil.PATTERN);
|
||||
}
|
||||
|
||||
return logService.getAll(page, count, query, type, startTime, endTime);
|
||||
return logService.getAll(page, count, query, type, startTime, endTime, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除日志
|
||||
*
|
||||
*/
|
||||
@Operation(summary = "删除日志", security = @SecurityRequirement(name = JwtUtils.HEADER))
|
||||
@DeleteMapping("/delete")
|
||||
public void delete(@RequestBody LogDto logDto) {
|
||||
logService.deleteById(logDto.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue