refactor: 任务执行日志放入MongoDB
This commit is contained in:
parent
025a8c26da
commit
f72e30efb5
|
@ -1,11 +1,14 @@
|
|||
package cn.bunny.dao.entity.log;
|
||||
package cn.bunny.dao.entity.log.schedule;
|
||||
|
||||
import cn.bunny.dao.common.entity.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.bson.types.ObjectId;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
import org.springframework.data.mongodb.core.mapping.FieldType;
|
||||
import org.springframework.data.mongodb.core.mapping.MongoId;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -18,9 +21,13 @@ import lombok.experimental.Accessors;
|
|||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
@TableName("log_quartz_execute")
|
||||
@Document(collection = "log_quartz_execute")
|
||||
@Schema(name = "QuartzExecuteLog对象", title = "调度任务执行日志", description = "调度任务执行日志")
|
||||
public class ScheduleExecuteLog extends BaseEntity {
|
||||
public class ScheduleExecuteLog {
|
||||
|
||||
@Id
|
||||
@MongoId(targetType = FieldType.STRING)
|
||||
private ObjectId id;
|
||||
|
||||
@Schema(name = "jobName", title = "任务名称")
|
||||
private String jobName;
|
|
@ -1,4 +1,4 @@
|
|||
package cn.bunny.dao.entity.log;
|
||||
package cn.bunny.dao.entity.log.schedule;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
|
@ -1,55 +0,0 @@
|
|||
package cn.bunny.dao.entity.system;
|
||||
|
||||
import cn.bunny.dao.common.entity.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 系统日志表
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-05-31
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
@TableName("system_log")
|
||||
@Schema(name = "SystemLog对象", title = "系统日志表", description = "系统日志表")
|
||||
public class SystemLog extends BaseEntity {
|
||||
|
||||
@Schema(name = "classPath", title = "所在类路径")
|
||||
private String classPath;
|
||||
|
||||
@Schema(name = "methodName", title = "执行方法名称")
|
||||
private String methodName;
|
||||
|
||||
@Schema(name = "args", title = "入参内容")
|
||||
private String args;
|
||||
|
||||
@Schema(name = "result", title = "返回参数")
|
||||
private String result;
|
||||
|
||||
@Schema(name = "errorStack", title = "报错堆栈")
|
||||
private String errorStack;
|
||||
|
||||
@Schema(name = "errorMessage", title = "报错")
|
||||
private String errorMessage;
|
||||
|
||||
@Schema(name = "email", title = "邮箱")
|
||||
private String email;
|
||||
|
||||
@Schema(name = "nickname", title = "用户名")
|
||||
private String nickname;
|
||||
|
||||
@Schema(name = "token", title = "当前用户token")
|
||||
private String token;
|
||||
|
||||
@Schema(name = "ipAddress", title = "当前用户IP地址")
|
||||
private String ipAddress;
|
||||
|
||||
}
|
|
@ -1,16 +1,20 @@
|
|||
package cn.bunny.dao.vo.log;
|
||||
|
||||
import cn.bunny.dao.common.vo.BaseUserVo;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
@Schema(name = "QuartzExecuteLogVo对象", title = "调度任务执行日志返回对象", description = "调度任务执行日志返回对象")
|
||||
public class QuartzExecuteLogVo extends BaseUserVo {
|
||||
@Schema(name = "ScheduleExecuteLogVo对象", title = "调度任务执行日志返回对象", description = "调度任务执行日志返回对象")
|
||||
public class ScheduleExecuteLogVo {
|
||||
|
||||
@Schema(name = "id", title = "id")
|
||||
private String id;
|
||||
|
||||
@Schema(name = "jobName", title = "任务名称")
|
||||
private String jobName;
|
||||
|
@ -31,6 +35,6 @@ public class QuartzExecuteLogVo extends BaseUserVo {
|
|||
private String executeResult;
|
||||
|
||||
@Schema(name = "duration", title = "执行时间")
|
||||
private Integer duration;
|
||||
private Long duration;
|
||||
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
package cn.bunny.services.aop;
|
||||
|
||||
import cn.bunny.dao.entity.log.ScheduleExecuteLog;
|
||||
import cn.bunny.dao.entity.log.ScheduleExecuteLogJson;
|
||||
import cn.bunny.dao.entity.log.schedule.ScheduleExecuteLog;
|
||||
import cn.bunny.dao.entity.log.schedule.ScheduleExecuteLogJson;
|
||||
import cn.bunny.dao.pojo.constant.LocalDateTimeConstant;
|
||||
import cn.bunny.dao.pojo.enums.JobEnums;
|
||||
import cn.bunny.services.mapper.schedule.ScheduleExecuteLogMapper;
|
||||
import cn.bunny.services.repository.ScheduleExecuteLogRepository;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
|
@ -27,7 +27,7 @@ public class JobExecuteAop {
|
|||
private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(LocalDateTimeConstant.YYYY_MM_DD_HH_MM_SS);
|
||||
|
||||
@Autowired
|
||||
private ScheduleExecuteLogMapper scheduleExecuteLogMapper;
|
||||
private ScheduleExecuteLogRepository scheduleExecuteLogRepository;
|
||||
|
||||
@Around(value = "pointCut()")
|
||||
public Object aroundMethod(ProceedingJoinPoint joinPoint) {
|
||||
|
@ -65,7 +65,7 @@ public class JobExecuteAop {
|
|||
executeLogJson.setOperationTime(startExecuteTime);
|
||||
executeLogJson.setExecuteParams(jobDataMap);
|
||||
executeLog.setExecuteResult(JSON.toJSONString(executeLogJson));
|
||||
scheduleExecuteLogMapper.insert(executeLog);
|
||||
scheduleExecuteLogRepository.insert(executeLog);
|
||||
|
||||
// 执行...
|
||||
result = joinPoint.proceed();
|
||||
|
@ -98,7 +98,7 @@ public class JobExecuteAop {
|
|||
executeLog.setId(null);
|
||||
executeLog.setExecuteResult(JSON.toJSONString(executeLogJson));
|
||||
executeLog.setDuration(Duration.between(startLocalDateTime, endLocalDateTime).toSeconds());
|
||||
scheduleExecuteLogMapper.insert(executeLog);
|
||||
scheduleExecuteLogRepository.insert(executeLog);
|
||||
}
|
||||
|
||||
@Pointcut("execution(* cn.bunny.services.quartz.*.execute(..))")
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
package cn.bunny.services.controller.schedule;
|
||||
package cn.bunny.services.controller.log;
|
||||
|
||||
import cn.bunny.dao.dto.log.ScheduleExecuteLogDto;
|
||||
import cn.bunny.dao.entity.log.ScheduleExecuteLog;
|
||||
import cn.bunny.dao.pojo.result.PageResult;
|
||||
import cn.bunny.dao.pojo.result.Result;
|
||||
import cn.bunny.dao.pojo.result.ResultCodeEnum;
|
||||
import cn.bunny.dao.vo.log.QuartzExecuteLogVo;
|
||||
import cn.bunny.dao.vo.log.ScheduleExecuteLogVo;
|
||||
import cn.bunny.services.aop.annotation.ExcludeRequestLog;
|
||||
import cn.bunny.services.service.schedule.ScheduleExecuteLogService;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import cn.bunny.services.service.log.ScheduleExecuteLogService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
|
@ -37,20 +36,23 @@ public class ScheduleExecuteLogController {
|
|||
@ExcludeRequestLog
|
||||
@Operation(summary = "分页查询调度任务执行日志", description = "分页查询调度任务执行日志")
|
||||
@GetMapping("getQuartzExecuteLogList/{page}/{limit}")
|
||||
public Mono<Result<PageResult<QuartzExecuteLogVo>>> getQuartzExecuteLogList(
|
||||
public Mono<Result<PageResult<ScheduleExecuteLogVo>>> getQuartzExecuteLogList(
|
||||
@Parameter(name = "page", description = "当前页", required = true)
|
||||
@PathVariable("page") Integer page,
|
||||
@Parameter(name = "limit", description = "每页记录数", required = true)
|
||||
@PathVariable("limit") Integer limit,
|
||||
ScheduleExecuteLogDto dto) {
|
||||
Page<ScheduleExecuteLog> pageParams = new Page<>(page, limit);
|
||||
PageResult<QuartzExecuteLogVo> pageResult = scheduleExecuteLogService.getQuartzExecuteLogList(pageParams, dto);
|
||||
// 设置分页参数
|
||||
page = page - 1;
|
||||
PageRequest pageable = PageRequest.of(page < 0 ? 0 : page, limit);
|
||||
|
||||
PageResult<ScheduleExecuteLogVo> pageResult = scheduleExecuteLogService.getQuartzExecuteLogList(pageable, dto);
|
||||
return Mono.just(Result.success(pageResult));
|
||||
}
|
||||
|
||||
@Operation(summary = "删除调度任务执行日志", description = "删除调度任务执行日志")
|
||||
@DeleteMapping("deleteQuartzExecuteLog")
|
||||
public Mono<Result<String>> deleteQuartzExecuteLog(@RequestBody List<Long> ids) {
|
||||
public Mono<Result<String>> deleteQuartzExecuteLog(@RequestBody List<String> ids) {
|
||||
scheduleExecuteLogService.deleteQuartzExecuteLog(ids);
|
||||
return Mono.just(Result.success(ResultCodeEnum.DELETE_SUCCESS));
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package cn.bunny.services.controller.system;
|
||||
package cn.bunny.services.controller.log;
|
||||
|
||||
import cn.bunny.dao.dto.log.UserLoginLogDto;
|
||||
import cn.bunny.dao.entity.log.UserLoginLog;
|
||||
|
@ -8,7 +8,7 @@ import cn.bunny.dao.pojo.result.ResultCodeEnum;
|
|||
import cn.bunny.dao.vo.log.UserLoginLogLocalVo;
|
||||
import cn.bunny.dao.vo.log.UserLoginLogVo;
|
||||
import cn.bunny.services.aop.annotation.ExcludeRequestLog;
|
||||
import cn.bunny.services.service.system.UserLoginLogService;
|
||||
import cn.bunny.services.service.log.UserLoginLogService;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
|
@ -1,17 +1,16 @@
|
|||
package cn.bunny.services.controller.system;
|
||||
package cn.bunny.services.controller.log;
|
||||
|
||||
import cn.bunny.dao.dto.log.UserRequestLogDto;
|
||||
import cn.bunny.dao.pojo.result.PageResult;
|
||||
import cn.bunny.dao.pojo.result.Result;
|
||||
import cn.bunny.dao.vo.log.UserRequestLogVo;
|
||||
import cn.bunny.services.aop.annotation.ExcludeRequestLog;
|
||||
import cn.bunny.services.service.system.UserRequestLogService;
|
||||
import cn.bunny.services.service.log.UserRequestLogService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
|
@ -36,15 +35,18 @@ public class UserRequestLogController {
|
|||
@Operation(summary = "分页查询用户请求日志", description = "分页查询用户请求日志")
|
||||
@ExcludeRequestLog
|
||||
@GetMapping("getRequestLogList/{page}/{limit}")
|
||||
public Mono<Result<PageResult<UserRequestLogVo>>> getRequestLogList(
|
||||
public Result<PageResult<UserRequestLogVo>> getRequestLogList(
|
||||
@Parameter(name = "page", description = "当前页", required = true)
|
||||
@PathVariable("page") Integer page,
|
||||
@Parameter(name = "limit", description = "每页记录数", required = true)
|
||||
@PathVariable("limit") Integer limit,
|
||||
UserRequestLogDto dto) {
|
||||
Pageable pageable = PageRequest.of(page, limit);
|
||||
// 设置分页参数
|
||||
page = page - 1;
|
||||
PageRequest pageable = PageRequest.of(page < 0 ? 0 : page, limit);
|
||||
|
||||
PageResult<UserRequestLogVo> pageResult = userRequestLogService.getRequestLogList(pageable, dto);
|
||||
return Mono.just(Result.success(pageResult));
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除用户请求日志", description = "删除用户请求日志")
|
|
@ -1,40 +0,0 @@
|
|||
package cn.bunny.services.mapper.schedule;
|
||||
|
||||
import cn.bunny.dao.dto.log.ScheduleExecuteLogDto;
|
||||
import cn.bunny.dao.entity.log.ScheduleExecuteLog;
|
||||
import cn.bunny.dao.vo.log.QuartzExecuteLogVo;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 调度任务执行日志 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-10-18 12:56:39
|
||||
*/
|
||||
@Mapper
|
||||
public interface ScheduleExecuteLogMapper extends BaseMapper<ScheduleExecuteLog> {
|
||||
|
||||
/**
|
||||
* * 分页查询调度任务执行日志内容
|
||||
*
|
||||
* @param pageParams 调度任务执行日志分页参数
|
||||
* @param dto 调度任务执行日志查询表单
|
||||
* @return 调度任务执行日志分页结果
|
||||
*/
|
||||
IPage<QuartzExecuteLogVo> selectListByPage(@Param("page") Page<ScheduleExecuteLog> pageParams, @Param("dto") ScheduleExecuteLogDto dto);
|
||||
|
||||
/**
|
||||
* 物理删除调度任务执行日志
|
||||
*
|
||||
* @param ids 删除 id 列表
|
||||
*/
|
||||
void deleteBatchIdsWithPhysics(List<Long> ids);
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package cn.bunny.services.repository;
|
||||
|
||||
import cn.bunny.dao.entity.log.schedule.ScheduleExecuteLog;
|
||||
import org.bson.types.ObjectId;
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
|
||||
public interface ScheduleExecuteLogRepository extends MongoRepository<ScheduleExecuteLog, ObjectId> {
|
||||
|
||||
}
|
|
@ -5,5 +5,5 @@ import org.bson.types.ObjectId;
|
|||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
|
||||
public interface UserRequestLogRepository extends MongoRepository<UserRequestLog, ObjectId> {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package cn.bunny.services.service.log;
|
||||
|
||||
import cn.bunny.dao.dto.log.ScheduleExecuteLogDto;
|
||||
import cn.bunny.dao.pojo.result.PageResult;
|
||||
import cn.bunny.dao.vo.log.ScheduleExecuteLogVo;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 调度任务执行日志 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-10-18 12:56:39
|
||||
*/
|
||||
public interface ScheduleExecuteLogService {
|
||||
|
||||
/**
|
||||
* * 获取调度任务执行日志列表
|
||||
*
|
||||
* @return 调度任务执行日志返回列表
|
||||
*/
|
||||
PageResult<ScheduleExecuteLogVo> getQuartzExecuteLogList(PageRequest pageable, ScheduleExecuteLogDto dto);
|
||||
|
||||
/**
|
||||
* * 删除|批量删除调度任务执行日志类型
|
||||
*
|
||||
* @param ids 删除id列表
|
||||
*/
|
||||
void deleteQuartzExecuteLog(List<String> ids);
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package cn.bunny.services.service.system;
|
||||
package cn.bunny.services.service.log;
|
||||
|
||||
import cn.bunny.dao.dto.log.UserLoginLogDto;
|
||||
import cn.bunny.dao.entity.log.UserLoginLog;
|
|
@ -1,9 +1,9 @@
|
|||
package cn.bunny.services.service.system;
|
||||
package cn.bunny.services.service.log;
|
||||
|
||||
import cn.bunny.dao.dto.log.UserRequestLogDto;
|
||||
import cn.bunny.dao.pojo.result.PageResult;
|
||||
import cn.bunny.dao.vo.log.UserRequestLogVo;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -16,7 +16,7 @@ public interface UserRequestLogService {
|
|||
* @param dto 表单查询
|
||||
* @return 分页结果
|
||||
*/
|
||||
PageResult<UserRequestLogVo> getRequestLogList(Pageable pageable, UserRequestLogDto dto);
|
||||
PageResult<UserRequestLogVo> getRequestLogList(PageRequest pageable, UserRequestLogDto dto);
|
||||
|
||||
/**
|
||||
* 删除用户请求日志
|
|
@ -0,0 +1,78 @@
|
|||
package cn.bunny.services.service.log.impl;
|
||||
|
||||
import cn.bunny.dao.dto.log.ScheduleExecuteLogDto;
|
||||
import cn.bunny.dao.entity.log.schedule.ScheduleExecuteLog;
|
||||
import cn.bunny.dao.pojo.result.PageResult;
|
||||
import cn.bunny.dao.vo.log.ScheduleExecuteLogVo;
|
||||
import cn.bunny.services.repository.ScheduleExecuteLogRepository;
|
||||
import cn.bunny.services.service.log.ScheduleExecuteLogService;
|
||||
import org.bson.types.ObjectId;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 调度任务执行日志 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-10-18 12:56:39
|
||||
*/
|
||||
@Service
|
||||
public class ScheduleExecuteLogServiceImpl implements ScheduleExecuteLogService {
|
||||
|
||||
@Autowired
|
||||
private ScheduleExecuteLogRepository scheduleExecuteLogRepository;
|
||||
|
||||
/**
|
||||
* * 调度任务执行日志 服务实现类
|
||||
*
|
||||
* @param pageable 调度任务执行日志分页查询page对象
|
||||
* @param dto 调度任务执行日志分页查询对象
|
||||
* @return 查询分页调度任务执行日志返回对象
|
||||
*/
|
||||
@Override
|
||||
public PageResult<ScheduleExecuteLogVo> getQuartzExecuteLogList(PageRequest pageable, ScheduleExecuteLogDto dto) {
|
||||
// 封装条件
|
||||
ScheduleExecuteLog scheduleExecuteLog = new ScheduleExecuteLog();
|
||||
BeanUtils.copyProperties(dto, scheduleExecuteLog);
|
||||
|
||||
// 构建条件
|
||||
Example<ScheduleExecuteLog> example = Example.of(scheduleExecuteLog);
|
||||
Page<ScheduleExecuteLog> page = scheduleExecuteLogRepository.findAll(example, pageable);
|
||||
|
||||
// 设置返回结果
|
||||
List<ScheduleExecuteLogVo> list = page.getContent().stream().map(executeLog -> {
|
||||
ScheduleExecuteLogVo vo = new ScheduleExecuteLogVo();
|
||||
BeanUtils.copyProperties(executeLog, vo);
|
||||
|
||||
String hexString = executeLog.getId().toHexString();
|
||||
vo.setId(hexString);
|
||||
return vo;
|
||||
}).toList();
|
||||
|
||||
return PageResult.<ScheduleExecuteLogVo>builder()
|
||||
.list(list)
|
||||
.pageNo((long) page.getNumber())
|
||||
.pageSize((long) page.getSize())
|
||||
.total(page.getTotalElements())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除|批量删除调度任务执行日志
|
||||
*
|
||||
* @param ids 删除id列表
|
||||
*/
|
||||
@Override
|
||||
public void deleteQuartzExecuteLog(List<String> ids) {
|
||||
List<ObjectId> idList = ids.stream().map(ObjectId::new).toList();
|
||||
scheduleExecuteLogRepository.deleteAllById(idList);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package cn.bunny.services.service.system.impl;
|
||||
package cn.bunny.services.service.log.impl;
|
||||
|
||||
import cn.bunny.common.service.context.BaseContext;
|
||||
import cn.bunny.dao.dto.log.UserLoginLogDto;
|
||||
|
@ -7,7 +7,7 @@ import cn.bunny.dao.pojo.result.PageResult;
|
|||
import cn.bunny.dao.vo.log.UserLoginLogLocalVo;
|
||||
import cn.bunny.dao.vo.log.UserLoginLogVo;
|
||||
import cn.bunny.services.mapper.system.UserLoginLogMapper;
|
||||
import cn.bunny.services.service.system.UserLoginLogService;
|
||||
import cn.bunny.services.service.log.UserLoginLogService;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@ -1,17 +1,17 @@
|
|||
package cn.bunny.services.service.system.impl;
|
||||
package cn.bunny.services.service.log.impl;
|
||||
|
||||
import cn.bunny.dao.dto.log.UserRequestLogDto;
|
||||
import cn.bunny.dao.entity.log.UserRequestLog;
|
||||
import cn.bunny.dao.pojo.result.PageResult;
|
||||
import cn.bunny.dao.vo.log.UserRequestLogVo;
|
||||
import cn.bunny.services.repository.UserRequestLogRepository;
|
||||
import cn.bunny.services.service.system.UserRequestLogService;
|
||||
import cn.bunny.services.service.log.UserRequestLogService;
|
||||
import org.bson.types.ObjectId;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -30,7 +30,7 @@ public class UserRequestLogServiceImpl implements UserRequestLogService {
|
|||
* @return 分页结果
|
||||
*/
|
||||
@Override
|
||||
public PageResult<UserRequestLogVo> getRequestLogList(Pageable pageable, UserRequestLogDto dto) {
|
||||
public PageResult<UserRequestLogVo> getRequestLogList(PageRequest pageable, UserRequestLogDto dto) {
|
||||
// 封装条件
|
||||
UserRequestLog userRequestLog = new UserRequestLog();
|
||||
BeanUtils.copyProperties(dto, userRequestLog);
|
||||
|
@ -38,6 +38,7 @@ public class UserRequestLogServiceImpl implements UserRequestLogService {
|
|||
// 构建条件
|
||||
Example<UserRequestLog> example = Example.of(userRequestLog);
|
||||
Page<UserRequestLog> page = userRequestLogRepository.findAll(example, pageable);
|
||||
|
||||
List<UserRequestLogVo> content = page.getContent().stream().map(requestLog -> {
|
||||
UserRequestLogVo vo = new UserRequestLogVo();
|
||||
BeanUtils.copyProperties(requestLog, vo);
|
|
@ -1,35 +0,0 @@
|
|||
package cn.bunny.services.service.schedule;
|
||||
|
||||
import cn.bunny.dao.dto.log.ScheduleExecuteLogDto;
|
||||
import cn.bunny.dao.entity.log.ScheduleExecuteLog;
|
||||
import cn.bunny.dao.pojo.result.PageResult;
|
||||
import cn.bunny.dao.vo.log.QuartzExecuteLogVo;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 调度任务执行日志 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-10-18 12:56:39
|
||||
*/
|
||||
public interface ScheduleExecuteLogService extends IService<ScheduleExecuteLog> {
|
||||
|
||||
/**
|
||||
* * 获取调度任务执行日志列表
|
||||
*
|
||||
* @return 调度任务执行日志返回列表
|
||||
*/
|
||||
PageResult<QuartzExecuteLogVo> getQuartzExecuteLogList(Page<ScheduleExecuteLog> pageParams, ScheduleExecuteLogDto dto);
|
||||
|
||||
/**
|
||||
* * 删除|批量删除调度任务执行日志类型
|
||||
*
|
||||
* @param ids 删除id列表
|
||||
*/
|
||||
void deleteQuartzExecuteLog(List<Long> ids);
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
package cn.bunny.services.service.schedule.impl;
|
||||
|
||||
import cn.bunny.dao.dto.log.ScheduleExecuteLogDto;
|
||||
import cn.bunny.dao.entity.log.ScheduleExecuteLog;
|
||||
import cn.bunny.dao.pojo.result.PageResult;
|
||||
import cn.bunny.dao.vo.log.QuartzExecuteLogVo;
|
||||
import cn.bunny.services.mapper.schedule.ScheduleExecuteLogMapper;
|
||||
import cn.bunny.services.service.schedule.ScheduleExecuteLogService;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 调度任务执行日志 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author Bunny
|
||||
* @since 2024-10-18 12:56:39
|
||||
*/
|
||||
@Service
|
||||
public class ScheduleExecuteLogServiceImpl extends ServiceImpl<ScheduleExecuteLogMapper, ScheduleExecuteLog> implements ScheduleExecuteLogService {
|
||||
|
||||
/**
|
||||
* * 调度任务执行日志 服务实现类
|
||||
*
|
||||
* @param pageParams 调度任务执行日志分页查询page对象
|
||||
* @param dto 调度任务执行日志分页查询对象
|
||||
* @return 查询分页调度任务执行日志返回对象
|
||||
*/
|
||||
@Override
|
||||
public PageResult<QuartzExecuteLogVo> getQuartzExecuteLogList(Page<ScheduleExecuteLog> pageParams, ScheduleExecuteLogDto dto) {
|
||||
IPage<QuartzExecuteLogVo> page = baseMapper.selectListByPage(pageParams, dto);
|
||||
|
||||
return PageResult.<QuartzExecuteLogVo>builder()
|
||||
.list(page.getRecords())
|
||||
.pageNo(page.getCurrent())
|
||||
.pageSize(page.getSize())
|
||||
.total(page.getTotal())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除|批量删除调度任务执行日志
|
||||
*
|
||||
* @param ids 删除id列表
|
||||
*/
|
||||
@Override
|
||||
public void deleteQuartzExecuteLog(List<Long> ids) {
|
||||
baseMapper.deleteBatchIdsWithPhysics(ids);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,10 @@
|
|||
|
||||
_ _
|
||||
| |__ _ _ _ __ _ __ _ _ (_) __ ___ ____ _
|
||||
| '_ \| | | | '_ \| '_ \| | | | | |/ _` \ \ / / _` |
|
||||
| |_) | |_| | | | | | | | |_| | | | (_| |\ V | (_| |
|
||||
|_.__/ \__,_|_| |_|_| |_|\__, | _/ |\__,_| \_/ \__,_|
|
||||
|___/ |__/
|
||||
|___/ |__/
|
||||
${AnsiColor.BRIGHT_GREEN}
|
||||
SpringBoot Version: ${spring-boot.version}${spring-boot.formatted-version}
|
||||
${AnsiColor.BLACK}
|
|
@ -1,66 +0,0 @@
|
|||
<?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="cn.bunny.services.mapper.schedule.ScheduleExecuteLogMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="cn.bunny.dao.entity.log.ScheduleExecuteLog">
|
||||
<id column="id" property="id"/>
|
||||
<id column="create_time" property="createTime"/>
|
||||
<id column="update_time" property="updateTime"/>
|
||||
<id column="create_user" property="createUser"/>
|
||||
<id column="update_user" property="updateUser"/>
|
||||
<id column="is_deleted" property="isDeleted"/>
|
||||
<id column="job_name" property="jobName"/>
|
||||
<id column="job_group" property="jobGroup"/>
|
||||
<id column="job_class_name" property="jobClassName"/>
|
||||
<id column="cron_expression" property="cronExpression"/>
|
||||
<id column="trigger_name" property="triggerName"/>
|
||||
<id column="execute_result" property="executeResult"/>
|
||||
<id column="duration" property="duration"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, create_time, update_time, create_user, update_user, is_deleted, job_name, job_group, job_class_name, cron_expression, trigger_name, execute_result, duration
|
||||
</sql>
|
||||
|
||||
<!-- 分页查询调度任务执行日志内容 -->
|
||||
<select id="selectListByPage" resultType="cn.bunny.dao.vo.log.QuartzExecuteLogVo">
|
||||
select
|
||||
log.*,
|
||||
create_user.username as create_username,
|
||||
update_user.username as update_username
|
||||
from log_quartz_execute log
|
||||
left join sys_user create_user on create_user.id = log.create_user
|
||||
left join sys_user update_user on update_user.id = log.update_user
|
||||
<where>
|
||||
log.is_deleted = 0
|
||||
<if test="dto.jobName != null and dto.jobName != ''">
|
||||
and log.job_name like CONCAT('%',#{dto.jobName},'%')
|
||||
</if>
|
||||
<if test="dto.jobGroup != null and dto.jobGroup != ''">
|
||||
and log.job_group like CONCAT('%',#{dto.jobGroup},'%')
|
||||
</if>
|
||||
<if test="dto.jobClassName != null and dto.jobClassName != ''">
|
||||
and log.job_class_name like CONCAT('%',#{dto.jobClassName},'%')
|
||||
</if>
|
||||
<if test="dto.cronExpression != null and dto.cronExpression != ''">
|
||||
and log.cron_expression like CONCAT('%',#{dto.cronExpression},'%')
|
||||
</if>
|
||||
<if test="dto.triggerName != null and dto.triggerName != ''">
|
||||
and log.trigger_name like CONCAT('%',#{dto.triggerName},'%')
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<!-- 物理删除调度任务执行日志 -->
|
||||
<delete id="deleteBatchIdsWithPhysics">
|
||||
delete
|
||||
from log_quartz_execute
|
||||
where id in
|
||||
<foreach collection="ids" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,30 @@
|
|||
package cn.bunny.services.service.system.impl;
|
||||
|
||||
import cn.bunny.dao.entity.log.UserRequestLog;
|
||||
import cn.bunny.services.repository.UserRequestLogRepository;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
|
||||
@SpringBootTest
|
||||
class UserRequestLogServiceImplTest {
|
||||
|
||||
@Autowired
|
||||
private UserRequestLogRepository userRequestLogRepository;
|
||||
|
||||
@Test
|
||||
void getRequestLogList() {
|
||||
// 封装条件
|
||||
UserRequestLog userRequestLog = new UserRequestLog();
|
||||
PageRequest pageable = PageRequest.of(0, 150);
|
||||
|
||||
// 构建条件
|
||||
Example<UserRequestLog> example = Example.of(userRequestLog);
|
||||
Page<UserRequestLog> page = userRequestLogRepository.findAll(example, pageable);
|
||||
page.getContent().forEach(item -> System.out.println(JSON.toJSONString(item)));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue