From 671c3016c80a3cb302277f244517007bed5f195d Mon Sep 17 00:00:00 2001 From: cherishsince Date: Thu, 27 Jun 2024 17:52:53 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=A2=9E=E5=8A=A0=E3=80=91=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E5=A4=9A=E4=B8=AAid=E8=8E=B7=E5=8F=96=20image=20?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=EF=BC=8C=E7=94=A8=E4=BA=8E=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E8=BD=AE=E8=AE=AD=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/image/AiImageController.java | 18 ++++++++++++++++++ .../ai/service/image/AiImageService.java | 11 +++++++++++ .../ai/service/image/AiImageServiceImpl.java | 5 +++++ 3 files changed, 34 insertions(+) diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/AiImageController.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/AiImageController.java index 3d80b845b..69ffb2d40 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/AiImageController.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/AiImageController.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.ai.controller.admin.image; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjUtil; import cn.iocoder.yudao.framework.ai.core.model.midjourney.api.MidjourneyApi; import cn.iocoder.yudao.framework.common.pojo.CommonResult; @@ -25,6 +26,10 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import java.util.Collections; +import java.util.List; +import java.util.Objects; + import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; @@ -54,6 +59,19 @@ public class AiImageController { return success(BeanUtils.toBean(image, AiImageRespVO.class)); } + @Operation(summary = "获取【我的】绘图记录 - ids") + @GetMapping("/get-my-ids") + public CommonResult> getImageMyIds(@RequestParam("ids") List ids) { + List imageList = imageService.getImageByIds(ids); + if (CollUtil.isEmpty(imageList)) { + return success(Collections.emptyList()); + } + List userImageList = imageList.stream() + .map(item -> ObjUtil.equal(getLoginUserId(), item.getUserId()) ? item : null) + .filter(Objects::nonNull).toList(); + return success(BeanUtils.toBean(userImageList, AiImageRespVO.class)); + } + @Operation(summary = "生成图片") @PostMapping("/draw") public CommonResult drawImage(@Validated @RequestBody AiImageDrawReqVO drawReqVO) { diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageService.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageService.java index ebd8ebd6b..f65bb3ee3 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageService.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageService.java @@ -5,12 +5,15 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageDrawReqVO; import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImagePageReqVO; +import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageRespVO; import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageUpdatePublicStatusReqVO; import cn.iocoder.yudao.module.ai.controller.admin.image.vo.midjourney.AiMidjourneyActionReqVO; import cn.iocoder.yudao.module.ai.controller.admin.image.vo.midjourney.AiMidjourneyImagineReqVO; import cn.iocoder.yudao.module.ai.dal.dataobject.image.AiImageDO; import jakarta.validation.Valid; +import java.util.List; + /** * AI 绘图 Service 接口 * @@ -35,6 +38,14 @@ public interface AiImageService { */ AiImageDO getImage(Long id); + /** + * 获得绘图记录 - 多个 + * + * @param ids + * @return + */ + List getImageByIds(List ids); + /** * 绘制图片 * 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 7f8697274..42cba8084 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 @@ -74,6 +74,11 @@ public class AiImageServiceImpl implements AiImageService { return imageMapper.selectById(id); } + @Override + public List getImageByIds(List ids) { + return imageMapper.selectBatchIds(ids); + } + @Override public Long drawImage(Long userId, AiImageDrawReqVO drawReqVO) { // 1. 保存数据库