diff --git a/src/main/java/com/ai/da/common/enums/CreditsEventsEnum.java b/src/main/java/com/ai/da/common/enums/CreditsEventsEnum.java index 2bff5ae3..de5834a1 100644 --- a/src/main/java/com/ai/da/common/enums/CreditsEventsEnum.java +++ b/src/main/java/com/ai/da/common/enums/CreditsEventsEnum.java @@ -5,6 +5,9 @@ import lombok.Getter; import java.util.Arrays; import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; @AllArgsConstructor @Getter @@ -65,4 +68,11 @@ public enum CreditsEventsEnum { return Arrays.asList(SLOGAN.name, LOGO.name, PATTERN.name, MOOD_BOARD.name, SKETCH_BOARD.name, TO_PRODUCT_IMAGE.name, RELIGHT.name, IMAGE_TO_SKETCH.name, POSE_TRANSFORMATION.name); } + + private static final Map BY_TASK_NAME = Arrays.stream(values()) + .collect(Collectors.toMap(CreditsEventsEnum::getName, Function.identity())); + + public static CreditsEventsEnum getByTaskName(String taskName){ + return BY_TASK_NAME.get(taskName); + } } diff --git a/src/main/java/com/ai/da/controller/ElementController.java b/src/main/java/com/ai/da/controller/ElementController.java index 96010a03..8912a006 100644 --- a/src/main/java/com/ai/da/controller/ElementController.java +++ b/src/main/java/com/ai/da/controller/ElementController.java @@ -114,7 +114,8 @@ public class ElementController { public Response> selectedImageSeg( @RequestPart(value = "file", required = false) MultipartFile[] file, @RequestParam(value = "type", required = false) @Pattern(regexp = "sketch|product", message = "类型必须是sketch或product") String type, - @RequestParam(value = "id", required = false) Long id) { + @RequestParam(value = "id", required = false) Long id, + @RequestParam(value = "sourceType", required = false) @Pattern(regexp = "library|upload", message = "id是从library中获取的还是上传的") String sourceType) { // 过滤空文件 List nonEmptyFiles = Arrays.stream(file) .filter(item -> !item.isEmpty()) @@ -127,7 +128,7 @@ public class ElementController { throw new BusinessException("不能同时提供文件上传和ID"); } - return Response.success(collectionElementService.selectedImageSeg(nonEmptyFiles, id, type)); + return Response.success(collectionElementService.selectedImageSeg(nonEmptyFiles, id, type, sourceType)); } } diff --git a/src/main/java/com/ai/da/service/CollectionElementService.java b/src/main/java/com/ai/da/service/CollectionElementService.java index 3090b504..2e45351c 100644 --- a/src/main/java/com/ai/da/service/CollectionElementService.java +++ b/src/main/java/com/ai/da/service/CollectionElementService.java @@ -139,6 +139,6 @@ public interface CollectionElementService extends IService { List getByProjectId(Long projectId); - List selectedImageSeg(List files, Long id, String type); + List selectedImageSeg(List files, Long id, String type, String sourceType); } diff --git a/src/main/java/com/ai/da/service/impl/CollectionElementServiceImpl.java b/src/main/java/com/ai/da/service/impl/CollectionElementServiceImpl.java index a5d9aca7..b9de700b 100644 --- a/src/main/java/com/ai/da/service/impl/CollectionElementServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/CollectionElementServiceImpl.java @@ -991,13 +991,14 @@ public class CollectionElementServiceImpl extends ServiceImpl selectedImageSeg(List files, Long id, String type) { + public List selectedImageSeg(List files, Long id, String type, String sourceType) { Long accountId = UserContext.getUserHolder().getId(); List resp = new ArrayList<>(); List imageDates = new ArrayList<>(); boolean isUploadMode = !files.isEmpty(); Library library = null; + CollectionElement collectionElement = null; // 判断是否是上传的图片 if (isUploadMode) { @@ -1017,7 +1018,7 @@ public class CollectionElementServiceImpl extends ServiceImpl restoredList = Arrays.asList(library.getSegmentedData().split(",")); resp.add(createCollectionElementVO(accountId, id, library.getLevel1Type(), library.getUrl(), restoredList)); } + } else if (Objects.nonNull(id) && sourceType.equals("upload")) { + collectionElement = collectionElementMapper.selectById(id); + // 判断id对应的数据是否存在 + if (Objects.isNull(collectionElement)) { + throw new BusinessException("get.file.failed"); + } + // 上传的图片分割数据没存(原因:上传的数据一般不会被再次使用,存储意义不大;上传存储表中数据复杂,添加字段,浪费多) + ImageSegmentation.ImageDate imageDate = new ImageSegmentation().new ImageDate(); + imageDate.setImage_url(collectionElement.getUrl()); + imageDate.setImage_type(type); + imageDates.add(imageDate); } // 处理需要分割的图片 @@ -1052,13 +1064,15 @@ public class CollectionElementServiceImpl extends ServiceImpl updateWrapper = new UpdateWrapper<>(); updateWrapper.lambda() @@ -348,7 +360,6 @@ public class CreditsServiceImpl extends ServiceImpl