【代码优化】AI:图片轮询实现

This commit is contained in:
YunaiV 2024-06-29 07:57:01 +08:00
parent d860560318
commit 2c61acf913
3 changed files with 7 additions and 8 deletions

View File

@ -61,7 +61,7 @@ public class AiImageController {
@Operation(summary = "获取【我的】绘图记录列表") @Operation(summary = "获取【我的】绘图记录列表")
@Parameter(name = "ids", required = true, description = "绘画编号数组", example = "1024,2048") @Parameter(name = "ids", required = true, description = "绘画编号数组", example = "1024,2048")
public CommonResult<List<AiImageRespVO>> getImageListMyByIds(@RequestParam("ids") List<Long> ids) { public CommonResult<List<AiImageRespVO>> getImageListMyByIds(@RequestParam("ids") List<Long> ids) {
List<AiImageDO> imageList = imageService.getImageByIds(ids); List<AiImageDO> imageList = imageService.getImageList(ids);
imageList.removeIf(item -> !ObjUtil.equal(getLoginUserId(), item.getUserId())); imageList.removeIf(item -> !ObjUtil.equal(getLoginUserId(), item.getUserId()));
return success(BeanUtils.toBean(imageList, AiImageRespVO.class)); return success(BeanUtils.toBean(imageList, AiImageRespVO.class));
} }

View File

@ -5,7 +5,6 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult; 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.AiImageDrawReqVO;
import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImagePageReqVO; 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.AiImageUpdatePublicStatusReqVO;
import cn.iocoder.yudao.module.ai.controller.admin.image.vo.midjourney.AiMidjourneyActionReqVO; 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.controller.admin.image.vo.midjourney.AiMidjourneyImagineReqVO;
@ -39,12 +38,12 @@ public interface AiImageService {
AiImageDO getImage(Long id); AiImageDO getImage(Long id);
/** /**
* 获得绘图记录 - 多个 * 获得绘图列表
* *
* @param ids * @param ids 绘图编号数组
* @return * @return 绘图记录列表
*/ */
List<AiImageDO> getImageByIds(List<Long> ids); List<AiImageDO> getImageList(List<Long> ids);
/** /**
* 绘制图片 * 绘制图片

View File

@ -76,7 +76,7 @@ public class AiImageServiceImpl implements AiImageService {
} }
@Override @Override
public List<AiImageDO> getImageByIds(List<Long> ids) { public List<AiImageDO> getImageList(List<Long> ids) {
if (CollUtil.isEmpty(ids)) { if (CollUtil.isEmpty(ids)) {
return Collections.emptyList(); return Collections.emptyList();
} }
@ -128,7 +128,7 @@ public class AiImageServiceImpl implements AiImageService {
} else if (ObjUtil.equal(draw.getPlatform(), AiPlatformEnum.STABLE_DIFFUSION.getPlatform())) { } else if (ObjUtil.equal(draw.getPlatform(), AiPlatformEnum.STABLE_DIFFUSION.getPlatform())) {
// https://platform.stability.ai/docs/api-reference#tag/Text-to-Image/operation/textToImage // https://platform.stability.ai/docs/api-reference#tag/Text-to-Image/operation/textToImage
return StabilityAiImageOptions.builder().withModel(draw.getModel()) return StabilityAiImageOptions.builder().withModel(draw.getModel())
.withHeight(draw.getHeight()).withWidth(draw.getWidth()) // TODO @芋艿各种参数 .withHeight(draw.getHeight()).withWidth(draw.getWidth()) // TODO @各种参数的接入
.build(); .build();
} }
throw new IllegalArgumentException("不支持的 AI 平台:" + draw.getPlatform()); throw new IllegalArgumentException("不支持的 AI 平台:" + draw.getPlatform());