feat(ai-web): 将任务模板信息固化到任务对象中

保证每个任务对象都有对应的模板信息可以追溯,不会随着模板被修改而失效
This commit is contained in:
2025-07-05 18:45:24 +08:00
parent f3dfff5075
commit 187c565da4
4 changed files with 41 additions and 31 deletions

View File

@@ -38,11 +38,15 @@ create table hudi_collect_build_b12.service_ai_flow_task
id bigint not null comment '记录唯一标记',
created_time datetime(6) comment '记录创建时间',
modified_time datetime(6) comment '记录更新时间',
comment text comment '任务注释,用于额外说明',
error longtext comment '任务运行产生的报错',
input longtext comment '任务输入',
result longtext comment '任务运行结果',
status enum ('ERROR','FINISHED','RUNNING') not null comment '任务运行状态',
template_id bigint not null comment '流程任务对应的模板',
template_description varchar(255) comment '任务对应的模板功能、内容说明',
template_flow_graph longtext not null comment '任务对应的模板前端流程图数据',
template_input_schema longtext not null comment '任务对应的模板入参Schema',
template_name varchar(255) not null comment '任务对应的模板名称',
primary key (id)
) comment ='流程任务记录' charset = utf8mb4;

View File

@@ -13,7 +13,6 @@ import java.util.Map;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.web.bind.annotation.GetMapping;
@@ -37,17 +36,26 @@ public class TaskController extends SimpleControllerSupport<FlowTask, TaskContro
}
@GetMapping("input_data/{id}")
public AmisResponse<?> getInputSchema(@PathVariable("id") Long id) throws JsonProcessingException {
public AmisResponse<?> getInputData(@PathVariable("id") Long id) throws JsonProcessingException {
var task = flowTaskService.detailOrThrow(id);
return AmisResponse.responseSuccess(mapper.readValue(task.getInput(), Map.class));
}
@GetMapping("input_schema/{id}")
public AmisResponse<?> getInputSchema(@PathVariable("id") Long id) throws JsonProcessingException {
var task = flowTaskService.detailOrThrow(id);
return AmisResponse.responseSuccess(mapper.readValue(task.getTemplateInputSchema(), Map.class));
}
@Override
protected SaveItemMapper<FlowTask, SaveItem> saveItemMapper() {
return item -> {
FlowTask task = new FlowTask();
FlowTaskTemplate template = flowTaskTemplateService.detailOrThrow(item.getTemplateId());
task.setTemplate(template);
task.setTemplateName(template.getName());
task.setTemplateDescription(template.getDescription());
task.setTemplateInputSchema(template.getInputSchema());
task.setTemplateFlowGraph(template.getFlowGraph());
task.setInput(mapper.writeValueAsString(item.getInput()));
return task;
};
@@ -74,14 +82,11 @@ public class TaskController extends SimpleControllerSupport<FlowTask, TaskContro
@Data
@EqualsAndHashCode(callSuper = true)
public static class ListItem extends SimpleItem {
private Long templateId;
private String templateName;
private FlowTask.Status status;
@org.mapstruct.Mapper
public static abstract class Mapper {
@Mapping(target = "templateId", source = "task.template.id")
@Mapping(target = "templateName", source = "task.template.name")
public abstract ListItem from(FlowTask task);
}
}
@@ -94,8 +99,6 @@ public class TaskController extends SimpleControllerSupport<FlowTask, TaskContro
@org.mapstruct.Mapper
public static abstract class Mapper extends ListItem.Mapper {
@Mapping(target = "templateId", source = "task.template.id")
@Mapping(target = "templateName", source = "task.template.name")
public abstract DetailItem from(FlowTask task);
}
}

View File

@@ -3,14 +3,10 @@ package com.lanyuanxiaoyao.service.ai.web.entity;
import com.lanyuanxiaoyao.service.ai.web.base.entity.SimpleEntity;
import com.lanyuanxiaoyao.service.common.Constants;
import jakarta.persistence.Column;
import jakarta.persistence.ConstraintMode;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.ForeignKey;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;
@@ -28,10 +24,23 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
@Table(catalog = Constants.DATABASE_NAME, name = "service_ai_flow_task")
@Comment("流程任务记录")
public class FlowTask extends SimpleEntity {
@Comment("流程任务对应的模板")
@ManyToOne
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private FlowTaskTemplate template;
// 每个任务对应的模板都是唯一,避免模板修改之后任务的状态、运行等状态都无法展示
// 不管允许不允许任务重跑,这些都要保存下来
@Comment("任务对应的模板名称")
@Column(nullable = false)
private String templateName;
@Comment("任务对应的模板功能、内容说明")
private String templateDescription;
@Comment("任务对应的模板入参Schema")
@Column(nullable = false, columnDefinition = "longtext")
private String templateInputSchema;
@Comment("任务对应的模板前端流程图数据")
@Column(nullable = false, columnDefinition = "longtext")
private String templateFlowGraph = "{}";
@Comment("任务注释,用于额外说明")
@Column(columnDefinition = "text")
private String comment;
@Comment("任务输入")
@Column(columnDefinition = "longtext")
private String input;

View File

@@ -101,7 +101,7 @@ const FlowTask: React.FC = () => {
type: 'service',
schemaApi: {
method: 'get',
url: `${commonInfo.baseAiUrl}/flow_task/template/input_schema/\${templateId}`,
url: `${commonInfo.baseAiUrl}/flow_task/input_schema/\${id}`,
// @ts-ignore
adaptor: (payload, response, api, context) => {
return {
@@ -131,12 +131,6 @@ const FlowTask: React.FC = () => {
],
},
},
{
type: 'action',
label: '重新执行',
level: 'link',
size: 'sm',
},
{
type: 'action',
label: '删除',