From 4acdd8adb913f4970dbaf73bbe358cf067d5037d Mon Sep 17 00:00:00 2001 From: xupei Date: Mon, 23 Jun 2025 12:02:16 +0800 Subject: [PATCH] =?UTF-8?q?BUGFIX:1=E3=80=81=E7=A7=AF=E5=88=86=E6=89=A3?= =?UTF-8?q?=E9=99=A4=EF=BC=8C=E9=87=91=E9=A2=9D=E4=B8=8D=E5=AF=B9=202?= =?UTF-8?q?=E3=80=81=E5=9B=BE=E7=89=87=E5=88=86=E5=89=B2=E5=85=81=E8=AE=B8?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E4=B8=8A=E4=BC=A0=E5=9B=BE=E7=89=87id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ai/da/common/enums/CreditsEventsEnum.java | 10 ++++++++++ .../ai/da/controller/ElementController.java | 5 +++-- .../da/service/CollectionElementService.java | 2 +- .../impl/CollectionElementServiceImpl.java | 20 ++++++++++++++++--- .../da/service/impl/CreditsServiceImpl.java | 19 ++++++++++++++---- 5 files changed, 46 insertions(+), 10 deletions(-) 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