diff --git a/service-ai/service-ai-web/src/main/java/com/lanyuanxiaoyao/service/ai/web/controller/DataFileController.java b/service-ai/service-ai-web/src/main/java/com/lanyuanxiaoyao/service/ai/web/controller/DataFileController.java index 4f4185f..0e9eda9 100644 --- a/service-ai/service-ai-web/src/main/java/com/lanyuanxiaoyao/service/ai/web/controller/DataFileController.java +++ b/service-ai/service-ai-web/src/main/java/com/lanyuanxiaoyao/service/ai/web/controller/DataFileController.java @@ -21,7 +21,10 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.eclipse.collections.api.factory.Sets; import org.eclipse.collections.api.list.ImmutableList; +import org.eclipse.collections.api.set.ImmutableSet; +import org.mapstruct.factory.Mappers; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -56,6 +59,26 @@ public class DataFileController { this.sliceFolderPath = StrUtil.format("{}/slice", uploadFolderPath); } + @PostMapping("/detail") + public AmisResponse detail(@RequestBody DetailRequest request) { + var mapper = Mappers.getMapper(DetailResponse.Mapper.class); + return AmisResponse.responseCrudData(dataFileService.downloadFile(request.ids).collect(mapper::from)); + } + + @GetMapping("/detail") + public AmisResponse detail(@RequestParam("ids") String ids) { + if (StrUtil.isBlank(ids)) { + return AmisResponse.responseCrudData(Sets.immutable.empty()); + } + var mapper = Mappers.getMapper(DetailResponse.Mapper.class); + return AmisResponse.responseCrudData( + dataFileService.downloadFile( + Sets.immutable.ofAll(StrUtil.split(ids, ",")) + .collect(Long::parseLong) + ).collect(mapper::from) + ); + } + @PostMapping("") public AmisResponse upload(@RequestParam("file") MultipartFile file) throws IOException { String filename = file.getOriginalFilename(); @@ -170,6 +193,24 @@ public class DataFileController { } } + @Data + public static final class DetailRequest { + private ImmutableSet ids; + } + + @Data + public static final class DetailResponse { + private Long id; + private String filename; + private Long size; + private String md5; + + @org.mapstruct.Mapper + public interface Mapper { + DetailResponse from(DataFile file); + } + } + @Data public static final class StartRequest { private String name; diff --git a/service-web/client/src/pages/ai/task/FlowTask.tsx b/service-web/client/src/pages/ai/task/FlowTask.tsx index 5ac456d..2e73240 100644 --- a/service-web/client/src/pages/ai/task/FlowTask.tsx +++ b/service-web/client/src/pages/ai/task/FlowTask.tsx @@ -107,7 +107,7 @@ const FlowTask: React.FC = () => { return { ...payload, data: { - ...generateInputForm(payload.data, undefined, false), + ...generateInputForm(payload.data, undefined, false, true), id: 'db8a4d10-0c47-4e27-b1a4-d0f2e1c15992', initApi: { method: 'get', diff --git a/service-web/client/src/pages/ai/task/InputSchema.tsx b/service-web/client/src/pages/ai/task/InputSchema.tsx index 9ec1f01..a55f917 100644 --- a/service-web/client/src/pages/ai/task/InputSchema.tsx +++ b/service-web/client/src/pages/ai/task/InputSchema.tsx @@ -1,5 +1,5 @@ import type {Schema} from 'amis' -import {commonInfo} from '../../../util/amis.tsx' +import {commonInfo, formInputFileStaticColumns} from '../../../util/amis.tsx' export const typeMap: Record = { text: '文本', @@ -13,7 +13,7 @@ export type InputField = { description?: string } -export const generateInputForm: (inputSchema: Record, title?: string, border?: boolean, staticView?: boolean) => Schema = (inputSchema, title, border) => { +export const generateInputForm: (inputSchema: Record, title?: string, border?: boolean, staticView?: boolean) => Schema = (inputSchema, title, border, staticView) => { let items: Schema[] = [] for (const name of Object.keys(inputSchema)) { let field = inputSchema[name] @@ -34,18 +34,30 @@ export const generateInputForm: (inputSchema: Record, title? commonMeta.type = 'input-number' break case 'files': - items.push({ - ...commonMeta, - type: 'input-file', - autoUpload: false, - drag: true, - multiple: true, - joinValues: false, - extractValue: true, - accept: '*', - maxSize: 104857600, - receiver: `${commonInfo.baseAiUrl}/upload`, - }) + if (staticView) { + items.push({ + ...commonMeta, + type: 'control', + body: { + type: 'crud', + api: `${commonInfo.baseAiUrl}/upload/detail?ids=\${JOIN(inputData.${name}, ',')}`, + columns: formInputFileStaticColumns, + } + }) + } else { + items.push({ + ...commonMeta, + type: 'input-file', + autoUpload: false, + drag: true, + multiple: true, + joinValues: false, + extractValue: true, + accept: '*', + maxSize: 104857600, + receiver: `${commonInfo.baseAiUrl}/upload`, + }) + } break } } diff --git a/service-web/client/src/util/amis.tsx b/service-web/client/src/util/amis.tsx index 34cd420..a0c130a 100644 --- a/service-web/client/src/util/amis.tsx +++ b/service-web/client/src/util/amis.tsx @@ -2519,7 +2519,7 @@ export function pictureFromIds(field: string) { return `\${ARRAYMAP(${field},id => '${commonInfo.baseAiUrl}/upload/download/' + id)}` } -const formInputFileStaticColumns = [ +export const formInputFileStaticColumns = [ { name: 'filename', label: '文件名',