From d332c0b175f353c597b8700cccbec74b45c7f9ec Mon Sep 17 00:00:00 2001 From: cherishsince Date: Mon, 17 Jun 2024 21:38:17 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91=E5=A4=84?= =?UTF-8?q?=E7=90=86=20todo=20=E8=BF=90=E8=A1=8C=E5=BC=82=E5=B8=B8=20actio?= =?UTF-8?q?n=20=E4=B8=8D=E8=83=BD=E6=93=8D=E4=BD=9C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ai/config/YudaoMidjourneyConfiguration.java | 3 ++- .../ai/config/YudaoMidjourneyProperties.java | 2 +- .../iocoder/yudao/module/ai/job/MidjourneyJob.java | 11 ++++++++--- .../ai/service/image/AiImageServiceImpl.java | 14 ++++++++------ .../core/model/midjourney/api/MidjourneyApi.java | 2 +- 5 files changed, 20 insertions(+), 12 deletions(-) rename yudao-module-ai/{yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework => yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module}/ai/config/YudaoMidjourneyConfiguration.java (88%) rename yudao-module-ai/{yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework => yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module}/ai/config/YudaoMidjourneyProperties.java (90%) diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/config/YudaoMidjourneyConfiguration.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/config/YudaoMidjourneyConfiguration.java similarity index 88% rename from yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/config/YudaoMidjourneyConfiguration.java rename to yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/config/YudaoMidjourneyConfiguration.java index 40a017bc7..fbdb49a67 100644 --- a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/config/YudaoMidjourneyConfiguration.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/config/YudaoMidjourneyConfiguration.java @@ -1,8 +1,9 @@ -package cn.iocoder.yudao.framework.ai.config; +package cn.iocoder.yudao.module.ai.config; import cn.iocoder.yudao.framework.ai.core.model.midjourney.MidjourneyConfig; import cn.iocoder.yudao.framework.ai.core.model.midjourney.api.MidjourneyApi; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/config/YudaoMidjourneyProperties.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/config/YudaoMidjourneyProperties.java similarity index 90% rename from yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/config/YudaoMidjourneyProperties.java rename to yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/config/YudaoMidjourneyProperties.java index 98e98eb6b..c58e20bd4 100644 --- a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/config/YudaoMidjourneyProperties.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/config/YudaoMidjourneyProperties.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.framework.ai.config; +package cn.iocoder.yudao.module.ai.config; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/job/MidjourneyJob.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/job/MidjourneyJob.java index ff6491575..023e500de 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/job/MidjourneyJob.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/job/MidjourneyJob.java @@ -4,7 +4,10 @@ import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum; import cn.iocoder.yudao.framework.ai.core.model.midjourney.api.MidjourneyApi; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; +import cn.iocoder.yudao.module.ai.controller.admin.image.vo.MidjourneyNotifyReqVO; import cn.iocoder.yudao.module.ai.dal.dataobject.image.AiImageDO; import cn.iocoder.yudao.module.ai.dal.mysql.image.AiImageMapper; import cn.iocoder.yudao.module.ai.enums.image.AiImageStatusEnum; @@ -38,7 +41,7 @@ public class MidjourneyJob implements JobHandler { // TODO @fan:这个方法,建议实现到 AiImageService,例如说 midjourneySync,返回 int 同步数量。 @Override - public String execute(String param) throws Exception { + public String execute(String param) { // 1、获取 midjourney 平台,状态在 “进行中” 的 image List imageList = imageMapper.selectByStatusAndPlatform(AiImageStatusEnum.IN_PROGRESS, AiPlatformEnum.MIDJOURNEY); log.info("Midjourney 同步 - 任务数量 {}!", imageList.size()); @@ -61,10 +64,12 @@ public class MidjourneyJob implements JobHandler { } // TODO @ 3.1 和 3.2 是不是融合下;get,然后判空,continue; // 3.2 获取通知对象 -// MidjourneyNotifyReqVO notifyReqVO = taskIdMap.get(aiImageDO.getTaskId()); + MidjourneyApi.NotifyRequest notifyRequest = taskIdMap.get(aiImageDO.getTaskId()); // 3.2 构建更新对象 // TODO @fan:建议 List 作为 imageService 去更新; -// updateImageList.add(imageService.buildUpdateImage(aiImageDO.getId(), notifyReqVO)); + // TODO @芋艿 BeanUtils.toBean 转换为 null + updateImageList.add(imageService.buildUpdateImage(aiImageDO.getId(), + JsonUtils.parseObject(JsonUtils.toJsonString(notifyRequest), MidjourneyNotifyReqVO.class))); } // 4、批了更新 updateImageList imageMapper.updateBatch(updateImageList); diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java index e38d609ab..706ef79ba 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java @@ -186,11 +186,13 @@ public class AiImageServiceImpl implements AiImageService { public AiImageDO buildUpdateImage(Long imageId, MidjourneyNotifyReqVO notifyReqVO) { // 1、转换状态 String imageStatus = null; - MidjourneyApi.TaskStatusEnum taskStatusEnum = MidjourneyApi.TaskStatusEnum.valueOf(notifyReqVO.getStatus()); - if (MidjourneyApi.TaskStatusEnum.SUCCESS == taskStatusEnum) { - imageStatus = AiImageStatusEnum.SUCCESS.getStatus(); - } else if (MidjourneyApi.TaskStatusEnum.FAILURE == taskStatusEnum) { - imageStatus = AiImageStatusEnum.FAIL.getStatus(); + if (StrUtil.isNotBlank(notifyReqVO.getStatus())) { + MidjourneyApi.TaskStatusEnum taskStatusEnum = MidjourneyApi.TaskStatusEnum.valueOf(notifyReqVO.getStatus()); + if (MidjourneyApi.TaskStatusEnum.SUCCESS == taskStatusEnum) { + imageStatus = AiImageStatusEnum.SUCCESS.getStatus(); + } else if (MidjourneyApi.TaskStatusEnum.FAILURE == taskStatusEnum) { + imageStatus = AiImageStatusEnum.FAIL.getStatus(); + } } // 2、上传图片 @@ -261,7 +263,7 @@ public class AiImageServiceImpl implements AiImageService { break; } } - if (isTrue) { + if (!isTrue) { throw exception(AI_IMAGE_CUSTOM_ID_NOT_EXISTS); } } diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/midjourney/api/MidjourneyApi.java b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/midjourney/api/MidjourneyApi.java index c00a9b85e..962776dad 100644 --- a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/midjourney/api/MidjourneyApi.java +++ b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/core/model/midjourney/api/MidjourneyApi.java @@ -202,7 +202,7 @@ public class MidjourneyApi { public enum ModelEnum { MIDJOURNEY("midjourney", "midjourney"), - NIJI("Niji", "Niji"), + NIJI("niji", "niji"), ;