feat(ai-web): 完成执行任务的创建
This commit is contained in:
@@ -2,19 +2,22 @@ package com.lanyuanxiaoyao.service.ai.web.controller.task;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.lanyuanxiaoyao.service.ai.core.entity.amis.AmisResponse;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.controller.SimpleControllerSupport;
|
||||
import com.lanyuanxiaoyao.service.ai.web.base.entity.SimpleItem;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.FlowTask;
|
||||
import com.lanyuanxiaoyao.service.ai.web.entity.FlowTaskTemplate;
|
||||
import com.lanyuanxiaoyao.service.ai.web.service.task.FlowTaskService;
|
||||
import com.lanyuanxiaoyao.service.ai.web.service.task.FlowTaskTemplateService;
|
||||
import java.util.Map;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.mapstruct.Context;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -22,15 +25,23 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
@RequestMapping("flow_task")
|
||||
public class TaskController extends SimpleControllerSupport<FlowTask, TaskController.SaveItem, TaskController.ListItem, TaskController.DetailItem> {
|
||||
private final FlowTaskService flowTaskService;
|
||||
private final FlowTaskTemplateService flowTaskTemplateService;
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
public TaskController(FlowTaskService flowTaskService, FlowTaskTemplateService flowTaskTemplateService, Jackson2ObjectMapperBuilder builder) {
|
||||
super(flowTaskService);
|
||||
this.flowTaskService = flowTaskService;
|
||||
this.flowTaskTemplateService = flowTaskTemplateService;
|
||||
this.mapper = builder.build();
|
||||
}
|
||||
|
||||
@GetMapping("input_data/{id}")
|
||||
public AmisResponse<?> getInputSchema(@PathVariable("id") Long id) throws JsonProcessingException {
|
||||
var task = flowTaskService.detailOrThrow(id);
|
||||
return AmisResponse.responseSuccess(mapper.readValue(task.getInput(), Map.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SaveItemMapper<FlowTask, SaveItem> saveItemMapper() {
|
||||
return item -> {
|
||||
@@ -45,13 +56,13 @@ public class TaskController extends SimpleControllerSupport<FlowTask, TaskContro
|
||||
@Override
|
||||
protected ListItemMapper<FlowTask, ListItem> listItemMapper() {
|
||||
ListItem.Mapper map = Mappers.getMapper(ListItem.Mapper.class);
|
||||
return task -> map.from(task, mapper);
|
||||
return map::from;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DetailItemMapper<FlowTask, DetailItem> detailItemMapper() {
|
||||
DetailItem.Mapper map = Mappers.getMapper(DetailItem.Mapper.class);
|
||||
return task -> map.from(task, mapper);
|
||||
return map::from;
|
||||
}
|
||||
|
||||
@Data
|
||||
@@ -64,17 +75,14 @@ public class TaskController extends SimpleControllerSupport<FlowTask, TaskContro
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class ListItem extends SimpleItem {
|
||||
private Long templateId;
|
||||
private Object input;
|
||||
private String templateName;
|
||||
private FlowTask.Status status;
|
||||
|
||||
@org.mapstruct.Mapper
|
||||
public static abstract class Mapper {
|
||||
@Mapping(target = "templateId", source = "task.template.id")
|
||||
public abstract ListItem from(FlowTask task, @Context ObjectMapper mapper) throws JsonProcessingException;
|
||||
|
||||
protected Object mapInput(String input, @Context ObjectMapper mapper) throws JsonProcessingException {
|
||||
return mapper.readValue(input, Object.class);
|
||||
}
|
||||
@Mapping(target = "templateName", source = "task.template.name")
|
||||
public abstract ListItem from(FlowTask task);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +95,8 @@ 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")
|
||||
public abstract DetailItem from(FlowTask task, @Context ObjectMapper mapper) throws JsonProcessingException;
|
||||
@Mapping(target = "templateName", source = "task.template.name")
|
||||
public abstract DetailItem from(FlowTask task);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.mapstruct.Context;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -33,6 +35,12 @@ public class TaskTemplateController extends SimpleControllerSupport<FlowTaskTemp
|
||||
this.mapper = builder.build();
|
||||
}
|
||||
|
||||
@GetMapping("input_schema/{id}")
|
||||
public AmisResponse<?> getInputSchema(@PathVariable("id") Long id) throws JsonProcessingException {
|
||||
var template = flowTaskTemplateService.detailOrThrow(id);
|
||||
return AmisResponse.responseSuccess(mapper.readValue(template.getInputSchema(), Map.class));
|
||||
}
|
||||
|
||||
@PostMapping("update_flow_graph")
|
||||
public AmisResponse<?> updateFlowGraph(@RequestBody UpdateGraphItem item) throws JsonProcessingException {
|
||||
flowTaskTemplateService.updateFlowGraph(item.getId(), mapper.writeValueAsString(item.getGraph()));
|
||||
@@ -41,7 +49,7 @@ public class TaskTemplateController extends SimpleControllerSupport<FlowTaskTemp
|
||||
|
||||
@Override
|
||||
protected SaveItemMapper<FlowTaskTemplate, SaveItem> saveItemMapper() {
|
||||
SaveItem.Mapper map = Mappers.getMapper(SaveItem.Mapper.class);
|
||||
var map = Mappers.getMapper(SaveItem.Mapper.class);
|
||||
return item -> map.from(item, mapper);
|
||||
}
|
||||
|
||||
@@ -52,7 +60,7 @@ public class TaskTemplateController extends SimpleControllerSupport<FlowTaskTemp
|
||||
|
||||
@Override
|
||||
protected DetailItemMapper<FlowTaskTemplate, DetailItem> detailItemMapper() {
|
||||
DetailItem.Mapper map = Mappers.getMapper(DetailItem.Mapper.class);
|
||||
var map = Mappers.getMapper(DetailItem.Mapper.class);
|
||||
return template -> map.from(template, mapper);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ public class FlowTaskTemplateService extends SimpleServiceSupport<FlowTaskTempla
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateFlowGraph(Long id, String flowGraph) {
|
||||
FlowTaskTemplate template = detailOrThrow(id);
|
||||
var template = detailOrThrow(id);
|
||||
template.setFlowGraph(flowGraph);
|
||||
save(template);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user