feat: 增加任务耗时展示
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
package com.lanyuanxiaoyao.leopard.server.controller;
|
||||
|
||||
import cn.hutool.core.date.BetweenFormatter;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.lanyuanxiaoyao.leopard.server.entity.Task;
|
||||
import com.lanyuanxiaoyao.leopard.server.service.TaskService;
|
||||
import com.lanyuanxiaoyao.service.template.controller.GlobalResponse;
|
||||
import com.lanyuanxiaoyao.service.template.controller.SimpleControllerSupport;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
@@ -46,30 +50,51 @@ public class TaskController extends SimpleControllerSupport<Task, Void, TaskCont
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function<Task, ListItem> listItemMapper() {
|
||||
return task -> new ListItem(
|
||||
task.getId(),
|
||||
task.getName(),
|
||||
task.getDescription(),
|
||||
task.getStatus(),
|
||||
task.getLaunchedTime(),
|
||||
task.getFinishedTime()
|
||||
private TaskCost calculateCost(LocalDateTime start, LocalDateTime finish) {
|
||||
if (ObjectUtil.isNull(start) || ObjectUtil.isNull(finish)) {
|
||||
return new TaskCost(null, null);
|
||||
}
|
||||
var duration = Duration.between(start, finish).toMillis();
|
||||
return new TaskCost(
|
||||
duration,
|
||||
DateUtil.formatBetween(duration, BetweenFormatter.Level.SECOND)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function<Task, ListItem> listItemMapper() {
|
||||
return task -> {
|
||||
var cost = calculateCost(task.getLaunchedTime(), task.getFinishedTime());
|
||||
return new ListItem(
|
||||
task.getId(),
|
||||
task.getName(),
|
||||
task.getDescription(),
|
||||
task.getStatus(),
|
||||
task.getLaunchedTime(),
|
||||
task.getFinishedTime(),
|
||||
cost.cost(),
|
||||
cost.costText()
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Function<Task, DetailItem> detailItemMapper() {
|
||||
return task -> new DetailItem(
|
||||
task.getId(),
|
||||
task.getName(),
|
||||
task.getDescription(),
|
||||
task.getStatus(),
|
||||
task.getError(),
|
||||
task.getResult(),
|
||||
task.getLaunchedTime(),
|
||||
task.getFinishedTime()
|
||||
);
|
||||
return task -> {
|
||||
var cost = calculateCost(task.getLaunchedTime(), task.getFinishedTime());
|
||||
return new DetailItem(
|
||||
task.getId(),
|
||||
task.getName(),
|
||||
task.getDescription(),
|
||||
task.getStatus(),
|
||||
task.getError(),
|
||||
task.getResult(),
|
||||
task.getLaunchedTime(),
|
||||
task.getFinishedTime(),
|
||||
cost.cost(),
|
||||
cost.costText()
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
public record ListItem(
|
||||
@@ -78,7 +103,9 @@ public class TaskController extends SimpleControllerSupport<Task, Void, TaskCont
|
||||
String description,
|
||||
Task.Status status,
|
||||
LocalDateTime launchedTime,
|
||||
LocalDateTime finishedTime
|
||||
LocalDateTime finishedTime,
|
||||
Long cost,
|
||||
String costText
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -90,10 +117,15 @@ public class TaskController extends SimpleControllerSupport<Task, Void, TaskCont
|
||||
String error,
|
||||
String result,
|
||||
LocalDateTime launchedTime,
|
||||
LocalDateTime finishedTime
|
||||
LocalDateTime finishedTime,
|
||||
Long cost,
|
||||
String costText
|
||||
) {
|
||||
}
|
||||
|
||||
public record ExecuteRequest(Long templateId, Map<String, Object> params) {
|
||||
}
|
||||
|
||||
public record TaskCost(Long cost, String costText) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user