feat: 增加任务耗时展示
This commit is contained in:
7
.idea/codeStyles/Project.xml
generated
7
.idea/codeStyles/Project.xml
generated
@@ -1,5 +1,11 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<JSCodeStyleSettings version="0">
|
||||
<option name="USE_SEMICOLON_AFTER_STATEMENT" value="false" />
|
||||
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
||||
<option name="USE_DOUBLE_QUOTES" value="false" />
|
||||
<option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
|
||||
</JSCodeStyleSettings>
|
||||
<JavaCodeStyleSettings>
|
||||
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="100" />
|
||||
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="100" />
|
||||
@@ -25,7 +31,6 @@
|
||||
<option name="USE_SEMICOLON_AFTER_STATEMENT" value="false" />
|
||||
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
||||
<option name="USE_DOUBLE_QUOTES" value="false" />
|
||||
<option name="FORCE_QUOTE_STYlE" value="true" />
|
||||
<option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
|
||||
</TypeScriptCodeStyleSettings>
|
||||
<codeStyleSettings language="CSS">
|
||||
|
||||
@@ -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) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,13 @@ function TaskList() {
|
||||
width: 100,
|
||||
...remoteMappings('task_status', 'status'),
|
||||
},
|
||||
{
|
||||
label: '耗时',
|
||||
type: 'tpl',
|
||||
align: 'center',
|
||||
width: 150,
|
||||
tpl: "${IF(costText, costText, '/')}",
|
||||
},
|
||||
{
|
||||
name: 'launchedTime',
|
||||
label: '启动时间',
|
||||
|
||||
Reference in New Issue
Block a user