Commit 671c3016c80a3cb302277f244517007bed5f195d
1 parent
39ecc7a0
【增加】根据多个id获取 image 信息,用于前端轮训任务
Showing
3 changed files
with
34 additions
and
0 deletions
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/AiImageController.java
| 1 | package cn.iocoder.yudao.module.ai.controller.admin.image; | 1 | package cn.iocoder.yudao.module.ai.controller.admin.image; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 3 | import cn.hutool.core.util.ObjUtil; | 4 | import cn.hutool.core.util.ObjUtil; |
| 4 | import cn.iocoder.yudao.framework.ai.core.model.midjourney.api.MidjourneyApi; | 5 | import cn.iocoder.yudao.framework.ai.core.model.midjourney.api.MidjourneyApi; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| @@ -25,6 +26,10 @@ import org.springframework.security.access.prepost.PreAuthorize; | @@ -25,6 +26,10 @@ import org.springframework.security.access.prepost.PreAuthorize; | ||
| 25 | import org.springframework.validation.annotation.Validated; | 26 | import org.springframework.validation.annotation.Validated; |
| 26 | import org.springframework.web.bind.annotation.*; | 27 | import org.springframework.web.bind.annotation.*; |
| 27 | 28 | ||
| 29 | +import java.util.Collections; | ||
| 30 | +import java.util.List; | ||
| 31 | +import java.util.Objects; | ||
| 32 | + | ||
| 28 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 33 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 29 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | 34 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| 30 | 35 | ||
| @@ -54,6 +59,19 @@ public class AiImageController { | @@ -54,6 +59,19 @@ public class AiImageController { | ||
| 54 | return success(BeanUtils.toBean(image, AiImageRespVO.class)); | 59 | return success(BeanUtils.toBean(image, AiImageRespVO.class)); |
| 55 | } | 60 | } |
| 56 | 61 | ||
| 62 | + @Operation(summary = "获取【我的】绘图记录 - ids") | ||
| 63 | + @GetMapping("/get-my-ids") | ||
| 64 | + public CommonResult<List<AiImageRespVO>> getImageMyIds(@RequestParam("ids") List<Long> ids) { | ||
| 65 | + List<AiImageDO> imageList = imageService.getImageByIds(ids); | ||
| 66 | + if (CollUtil.isEmpty(imageList)) { | ||
| 67 | + return success(Collections.emptyList()); | ||
| 68 | + } | ||
| 69 | + List<AiImageDO> userImageList = imageList.stream() | ||
| 70 | + .map(item -> ObjUtil.equal(getLoginUserId(), item.getUserId()) ? item : null) | ||
| 71 | + .filter(Objects::nonNull).toList(); | ||
| 72 | + return success(BeanUtils.toBean(userImageList, AiImageRespVO.class)); | ||
| 73 | + } | ||
| 74 | + | ||
| 57 | @Operation(summary = "生成图片") | 75 | @Operation(summary = "生成图片") |
| 58 | @PostMapping("/draw") | 76 | @PostMapping("/draw") |
| 59 | public CommonResult<Long> drawImage(@Validated @RequestBody AiImageDrawReqVO drawReqVO) { | 77 | public CommonResult<Long> drawImage(@Validated @RequestBody AiImageDrawReqVO drawReqVO) { |
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; | @@ -5,12 +5,15 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam; | ||
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageDrawReqVO; | 6 | import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageDrawReqVO; |
| 7 | import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImagePageReqVO; | 7 | import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImagePageReqVO; |
| 8 | +import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageRespVO; | ||
| 8 | import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageUpdatePublicStatusReqVO; | 9 | import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageUpdatePublicStatusReqVO; |
| 9 | import cn.iocoder.yudao.module.ai.controller.admin.image.vo.midjourney.AiMidjourneyActionReqVO; | 10 | import cn.iocoder.yudao.module.ai.controller.admin.image.vo.midjourney.AiMidjourneyActionReqVO; |
| 10 | import cn.iocoder.yudao.module.ai.controller.admin.image.vo.midjourney.AiMidjourneyImagineReqVO; | 11 | import cn.iocoder.yudao.module.ai.controller.admin.image.vo.midjourney.AiMidjourneyImagineReqVO; |
| 11 | import cn.iocoder.yudao.module.ai.dal.dataobject.image.AiImageDO; | 12 | import cn.iocoder.yudao.module.ai.dal.dataobject.image.AiImageDO; |
| 12 | import jakarta.validation.Valid; | 13 | import jakarta.validation.Valid; |
| 13 | 14 | ||
| 15 | +import java.util.List; | ||
| 16 | + | ||
| 14 | /** | 17 | /** |
| 15 | * AI 绘图 Service 接口 | 18 | * AI 绘图 Service 接口 |
| 16 | * | 19 | * |
| @@ -36,6 +39,14 @@ public interface AiImageService { | @@ -36,6 +39,14 @@ public interface AiImageService { | ||
| 36 | AiImageDO getImage(Long id); | 39 | AiImageDO getImage(Long id); |
| 37 | 40 | ||
| 38 | /** | 41 | /** |
| 42 | + * 获得绘图记录 - 多个 | ||
| 43 | + * | ||
| 44 | + * @param ids | ||
| 45 | + * @return | ||
| 46 | + */ | ||
| 47 | + List<AiImageDO> getImageByIds(List<Long> ids); | ||
| 48 | + | ||
| 49 | + /** | ||
| 39 | * 绘制图片 | 50 | * 绘制图片 |
| 40 | * | 51 | * |
| 41 | * @param userId 用户编号 | 52 | * @param userId 用户编号 |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java
| @@ -75,6 +75,11 @@ public class AiImageServiceImpl implements AiImageService { | @@ -75,6 +75,11 @@ public class AiImageServiceImpl implements AiImageService { | ||
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | @Override | 77 | @Override |
| 78 | + public List<AiImageDO> getImageByIds(List<Long> ids) { | ||
| 79 | + return imageMapper.selectBatchIds(ids); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + @Override | ||
| 78 | public Long drawImage(Long userId, AiImageDrawReqVO drawReqVO) { | 83 | public Long drawImage(Long userId, AiImageDrawReqVO drawReqVO) { |
| 79 | // 1. 保存数据库 | 84 | // 1. 保存数据库 |
| 80 | AiImageDO image = BeanUtils.toBean(drawReqVO, AiImageDO.class).setUserId(userId).setPublicStatus(false) | 85 | AiImageDO image = BeanUtils.toBean(drawReqVO, AiImageDO.class).setUserId(userId).setPublicStatus(false) |