|
|
|
|
@@ -3,10 +3,8 @@ package com.lanyuanxiaoyao.service.ai.web.controller.task;
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import com.lanyuanxiaoyao.service.ai.core.entity.amis.AmisCrudResponse;
|
|
|
|
|
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.controller.query.Query;
|
|
|
|
|
import com.lanyuanxiaoyao.service.ai.web.base.entity.SimpleItem;
|
|
|
|
|
import com.lanyuanxiaoyao.service.ai.web.entity.FlowTaskTemplate;
|
|
|
|
|
import com.lanyuanxiaoyao.service.ai.web.service.task.FlowTaskTemplateService;
|
|
|
|
|
@@ -17,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.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
@@ -24,26 +24,19 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("flow_task/template")
|
|
|
|
|
public class TaskTemplateController extends SimpleControllerSupport<FlowTaskTemplate, TaskTemplateController.SaveItem, TaskTemplateController.ListItem, TaskTemplateController.DetailItem> {
|
|
|
|
|
private final FlowTaskTemplateService flowTaskTemplateService;
|
|
|
|
|
private final ObjectMapper mapper;
|
|
|
|
|
|
|
|
|
|
public TaskTemplateController(FlowTaskTemplateService flowTaskTemplateService, Jackson2ObjectMapperBuilder builder) {
|
|
|
|
|
super(flowTaskTemplateService);
|
|
|
|
|
this.flowTaskTemplateService = flowTaskTemplateService;
|
|
|
|
|
this.mapper = builder.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public AmisResponse<Long> save(SaveItem saveItem) throws Exception {
|
|
|
|
|
log.info("Save: {}", saveItem);
|
|
|
|
|
SaveItem.Mapper map = Mappers.getMapper(SaveItem.Mapper.class);
|
|
|
|
|
log.info("Mapper: {}", map.from(saveItem, mapper));
|
|
|
|
|
return super.save(saveItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public AmisCrudResponse list(Query query) throws Exception {
|
|
|
|
|
AmisCrudResponse list = super.list(query);
|
|
|
|
|
log.info("List: {}", list);
|
|
|
|
|
return list;
|
|
|
|
|
@PostMapping("update_flow_graph")
|
|
|
|
|
public AmisResponse<?> updateFlowGraph(@RequestBody UpdateGraphItem item) throws JsonProcessingException {
|
|
|
|
|
flowTaskTemplateService.updateFlowGraph(item.getId(), mapper.writeValueAsString(item.getGraph()));
|
|
|
|
|
return AmisResponse.responseSuccess();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@@ -97,14 +90,22 @@ public class TaskTemplateController extends SimpleControllerSupport<FlowTaskTemp
|
|
|
|
|
private String name;
|
|
|
|
|
private String description;
|
|
|
|
|
private Map<String, Object> inputSchema;
|
|
|
|
|
private Map<String, Object> flowGraph;
|
|
|
|
|
|
|
|
|
|
@org.mapstruct.Mapper
|
|
|
|
|
public static abstract class Mapper {
|
|
|
|
|
public abstract DetailItem from(FlowTaskTemplate template, @Context ObjectMapper mapper) throws Exception;
|
|
|
|
|
|
|
|
|
|
public Map<String, Object> mapInputSchema(String inputSchema, @Context ObjectMapper mapper) throws Exception {
|
|
|
|
|
return mapper.readValue(inputSchema, new TypeReference<>() {});
|
|
|
|
|
public Map<String, Object> mapJson(String source, @Context ObjectMapper mapper) throws Exception {
|
|
|
|
|
return mapper.readValue(source, new TypeReference<>() {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Data
|
|
|
|
|
public static class UpdateGraphItem {
|
|
|
|
|
private Long id;
|
|
|
|
|
private Map<String, Object> graph;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|