feat: 2.6.0
1.优化工作流实时日志查询
This commit is contained in:
parent
007e783646
commit
2742fd0ff1
@ -18,6 +18,7 @@ import com.aizuda.easy.retry.server.common.util.DateUtils;
|
|||||||
import com.aizuda.easy.retry.server.job.task.dto.JobLogDTO;
|
import com.aizuda.easy.retry.server.job.task.dto.JobLogDTO;
|
||||||
import com.aizuda.easy.retry.server.job.task.dto.LogMetaDTO;
|
import com.aizuda.easy.retry.server.job.task.dto.LogMetaDTO;
|
||||||
import com.aizuda.easy.retry.server.model.dto.RetryTaskDTO;
|
import com.aizuda.easy.retry.server.model.dto.RetryTaskDTO;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import org.slf4j.MDC;
|
import org.slf4j.MDC;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
@ -98,7 +99,7 @@ public class EasyRetryServerLogbackAppender<E> extends UnsynchronizedAppenderBas
|
|||||||
.stream()
|
.stream()
|
||||||
.filter(logTaskDTO_ -> !Objects.isNull(logTaskDTO_.getValue()))
|
.filter(logTaskDTO_ -> !Objects.isNull(logTaskDTO_.getValue()))
|
||||||
.collect(Collectors.toMap(TaskLogFieldDTO::getName, TaskLogFieldDTO::getValue));
|
.collect(Collectors.toMap(TaskLogFieldDTO::getName, TaskLogFieldDTO::getValue));
|
||||||
jobLogDTO.setMessage(JsonUtil.toJsonString(messageMap));
|
jobLogDTO.setMessage(JsonUtil.toJsonString(Lists.newArrayList(messageMap)));
|
||||||
jobLogDTO.setTaskId(logMetaDTO.getTaskId());
|
jobLogDTO.setTaskId(logMetaDTO.getTaskId());
|
||||||
jobLogDTO.setJobId(logMetaDTO.getJobId());
|
jobLogDTO.setJobId(logMetaDTO.getJobId());
|
||||||
jobLogDTO.setGroupName(logMetaDTO.getGroupName());
|
jobLogDTO.setGroupName(logMetaDTO.getGroupName());
|
||||||
|
@ -26,7 +26,7 @@ public class JobLogController {
|
|||||||
|
|
||||||
@GetMapping("/log/list")
|
@GetMapping("/log/list")
|
||||||
@LoginRequired
|
@LoginRequired
|
||||||
public PageResult<List<JobLogResponseVO>> getJobLogPage(JobLogQueryVO jobQueryVO) {
|
public JobLogResponseVO getJobLogPage(JobLogQueryVO jobQueryVO) {
|
||||||
return jobLogService.getJobLogPage(jobQueryVO);
|
return jobLogService.getJobLogPage(jobQueryVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,9 @@ import lombok.EqualsAndHashCode;
|
|||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
public class JobLogQueryVO extends BaseQueryVO {
|
public class JobLogQueryVO extends BaseQueryVO {
|
||||||
|
private Long startId;
|
||||||
private Long jobId;
|
private Long jobId;
|
||||||
private Long taskBatchId;
|
private Long taskBatchId;
|
||||||
private Long taskId;
|
private Long taskId;
|
||||||
|
private Integer fromIndex;
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.aizuda.easy.retry.server.web.model.response;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author: www.byteblogs.com
|
* @author: www.byteblogs.com
|
||||||
@ -14,41 +15,12 @@ public class JobLogResponseVO {
|
|||||||
|
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
private Long key;
|
private Long nextStartId;
|
||||||
|
|
||||||
/**
|
private List message;
|
||||||
* 组名称
|
|
||||||
*/
|
|
||||||
private String groupName;
|
|
||||||
|
|
||||||
/**
|
private boolean isFinished;
|
||||||
* 任务信息id
|
|
||||||
*/
|
|
||||||
private Long jobId;
|
|
||||||
|
|
||||||
/**
|
private Integer fromIndex;
|
||||||
* 任务实例id
|
|
||||||
*/
|
|
||||||
private Long taskBatchId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 调度任务id
|
|
||||||
*/
|
|
||||||
private Long taskId;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建时间
|
|
||||||
*/
|
|
||||||
private LocalDateTime createDt;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 客户端信息
|
|
||||||
*/
|
|
||||||
private String clientAddress;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 调度信息
|
|
||||||
*/
|
|
||||||
private String message;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,5 +13,5 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public interface JobLogService {
|
public interface JobLogService {
|
||||||
|
|
||||||
PageResult<List<JobLogResponseVO>> getJobLogPage(JobLogQueryVO jobQueryVO);
|
JobLogResponseVO getJobLogPage(JobLogQueryVO jobQueryVO);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.aizuda.easy.retry.server.web.service.impl;
|
package com.aizuda.easy.retry.server.web.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
|
import com.aizuda.easy.retry.common.core.util.JsonUtil;
|
||||||
import com.aizuda.easy.retry.server.web.model.base.PageResult;
|
import com.aizuda.easy.retry.server.web.model.base.PageResult;
|
||||||
import com.aizuda.easy.retry.server.web.model.request.JobLogQueryVO;
|
import com.aizuda.easy.retry.server.web.model.request.JobLogQueryVO;
|
||||||
import com.aizuda.easy.retry.server.web.model.response.JobLogResponseVO;
|
import com.aizuda.easy.retry.server.web.model.response.JobLogResponseVO;
|
||||||
@ -9,11 +11,16 @@ import com.aizuda.easy.retry.template.datasource.persistence.mapper.JobLogMessag
|
|||||||
import com.aizuda.easy.retry.template.datasource.persistence.po.JobLogMessage;
|
import com.aizuda.easy.retry.template.datasource.persistence.po.JobLogMessage;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author: www.byteblogs.com
|
* @author: www.byteblogs.com
|
||||||
@ -27,26 +34,67 @@ public class JobLogServiceImpl implements JobLogService {
|
|||||||
private JobLogMessageMapper jobLogMessageMapper;
|
private JobLogMessageMapper jobLogMessageMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<List<JobLogResponseVO>> getJobLogPage(final JobLogQueryVO queryVO) {
|
public JobLogResponseVO getJobLogPage(final JobLogQueryVO queryVO) {
|
||||||
|
|
||||||
PageDTO<JobLogMessage> pageDTO = new PageDTO<>(queryVO.getPage(), queryVO.getSize());
|
PageDTO<JobLogMessage> pageDTO = new PageDTO<>(1, queryVO.getSize());
|
||||||
|
|
||||||
LambdaQueryWrapper<JobLogMessage> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<JobLogMessage> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
if (Objects.nonNull(queryVO.getJobId())) {
|
queryWrapper
|
||||||
queryWrapper.eq(JobLogMessage::getJobId, queryVO.getJobId());
|
.select(JobLogMessage::getId, JobLogMessage::getLogNum)
|
||||||
}
|
.ge(JobLogMessage::getId, queryVO.getStartId())
|
||||||
|
.eq(JobLogMessage::getJobId, queryVO.getJobId())
|
||||||
|
.eq(JobLogMessage::getTaskBatchId, queryVO.getTaskBatchId())
|
||||||
|
.eq(JobLogMessage::getTaskId, queryVO.getTaskId());
|
||||||
|
|
||||||
if (Objects.nonNull(queryVO.getTaskBatchId())) {
|
queryWrapper.orderByAsc(JobLogMessage::getRealTime).orderByDesc(JobLogMessage::getId);
|
||||||
queryWrapper.eq(JobLogMessage::getTaskBatchId, queryVO.getTaskBatchId());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Objects.nonNull(queryVO.getTaskId())) {
|
|
||||||
queryWrapper.eq(JobLogMessage::getTaskId, queryVO.getTaskId());
|
|
||||||
}
|
|
||||||
|
|
||||||
queryWrapper.orderByDesc(JobLogMessage::getId);
|
|
||||||
PageDTO<JobLogMessage> selectPage = jobLogMessageMapper.selectPage(pageDTO, queryWrapper);
|
PageDTO<JobLogMessage> selectPage = jobLogMessageMapper.selectPage(pageDTO, queryWrapper);
|
||||||
|
List<JobLogMessage> records = selectPage.getRecords();
|
||||||
|
if (CollectionUtils.isEmpty(records)) {
|
||||||
|
JobLogResponseVO jobLogResponseVO = new JobLogResponseVO();
|
||||||
|
jobLogResponseVO.setFinished(Boolean.TRUE);
|
||||||
|
return jobLogResponseVO;
|
||||||
|
}
|
||||||
|
|
||||||
return new PageResult<>(pageDTO, JobLogResponseVOConverter.INSTANCE.toJobLogResponseVOs(selectPage.getRecords()));
|
Integer fromIndex = Optional.ofNullable(queryVO.getFromIndex()).orElse(0);
|
||||||
|
JobLogMessage firstRecord = records.get(0);
|
||||||
|
List<Long> ids = Lists.newArrayList(firstRecord.getId());
|
||||||
|
int total = firstRecord.getLogNum() - fromIndex;
|
||||||
|
for (int i = 1; i < records.size(); i++) {
|
||||||
|
JobLogMessage record = records.get(i);
|
||||||
|
if (total + record.getLogNum() > queryVO.getSize()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
total += record.getLogNum();
|
||||||
|
ids.add(record.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
long nextStartId = 0;
|
||||||
|
List<String> messages = Lists.newArrayList();
|
||||||
|
List<JobLogMessage> jobLogMessages = jobLogMessageMapper.selectBatchIds(ids);
|
||||||
|
for (final JobLogMessage jobLogMessage : jobLogMessages) {
|
||||||
|
|
||||||
|
List<String> originalList = JsonUtil.parseObject(jobLogMessage.getMessage(), List.class);
|
||||||
|
int size = originalList.size() - fromIndex;
|
||||||
|
List<String> pageList = originalList.stream().skip(fromIndex).limit(queryVO.getSize())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
if (messages.size() + size >= queryVO.getSize()) {
|
||||||
|
messages.addAll(pageList);
|
||||||
|
nextStartId = jobLogMessage.getId();
|
||||||
|
fromIndex = Math.min(fromIndex + queryVO.getSize(), originalList.size() - 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
messages.addAll(pageList);
|
||||||
|
nextStartId = jobLogMessage.getId() + 1;
|
||||||
|
fromIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
JobLogResponseVO jobLogResponseVO = new JobLogResponseVO();
|
||||||
|
jobLogResponseVO.setMessage(messages);
|
||||||
|
jobLogResponseVO.setNextStartId(nextStartId);
|
||||||
|
jobLogResponseVO.setFromIndex(fromIndex);
|
||||||
|
return jobLogResponseVO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user