Commit e4a0512b5185f99cb88576d0f062a61c477eef0b
1 parent
f347b15a
【优化】AI Image 分页列表、get-my 返回 resp 结构
Showing
7 changed files
with
88 additions
and
56 deletions
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/AiImageController.java
| @@ -38,8 +38,8 @@ public class AiImageController { | @@ -38,8 +38,8 @@ public class AiImageController { | ||
| 38 | // TODO @fan:建议把 dallDrawing、midjourney 融合成一个 draw 接口,异步绘制;然后返回一个 id 给前端;前端通过 get 接口轮询,直到获取到生成成功 | 38 | // TODO @fan:建议把 dallDrawing、midjourney 融合成一个 draw 接口,异步绘制;然后返回一个 id 给前端;前端通过 get 接口轮询,直到获取到生成成功 |
| 39 | @Operation(summary = "dall2/dall3绘画", description = "openAi dall3是付费的!") | 39 | @Operation(summary = "dall2/dall3绘画", description = "openAi dall3是付费的!") |
| 40 | @PostMapping("/dall") | 40 | @PostMapping("/dall") |
| 41 | - public AiImageDallRespVO dallDrawing(@Validated @RequestBody AiImageDallReqVO req) { | ||
| 42 | - return aiImageService.dallDrawing(req); | 41 | + public AiImageDallRespVO dall(@Validated @RequestBody AiImageDallReqVO req) { |
| 42 | + return aiImageService.dall(req); | ||
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | @Operation(summary = "midjourney绘画", description = "midjourney图片绘画流程:1、提交任务 2、获取完成的任务 3、选择对应功能 4、获取最终结果") | 45 | @Operation(summary = "midjourney绘画", description = "midjourney图片绘画流程:1、提交任务 2、获取完成的任务 3、选择对应功能 4、获取最终结果") |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageDallRespVO.java
| 1 | package cn.iocoder.yudao.module.ai.controller.admin.image.vo; | 1 | package cn.iocoder.yudao.module.ai.controller.admin.image.vo; |
| 2 | 2 | ||
| 3 | import io.swagger.v3.oas.annotations.media.Schema; | 3 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | -import jakarta.validation.constraints.NotNull; | ||
| 5 | -import jakarta.validation.constraints.Size; | ||
| 6 | import lombok.Data; | 4 | import lombok.Data; |
| 7 | import lombok.experimental.Accessors; | 5 | import lombok.experimental.Accessors; |
| 8 | 6 | ||
| 7 | +import java.util.Map; | ||
| 8 | + | ||
| 9 | /** | 9 | /** |
| 10 | * dall2/dall2 绘画 | 10 | * dall2/dall2 绘画 |
| 11 | * | 11 | * |
| @@ -17,31 +17,57 @@ import lombok.experimental.Accessors; | @@ -17,31 +17,57 @@ import lombok.experimental.Accessors; | ||
| 17 | @Accessors(chain = true) | 17 | @Accessors(chain = true) |
| 18 | public class AiImageDallRespVO { | 18 | public class AiImageDallRespVO { |
| 19 | 19 | ||
| 20 | - @Schema(description = "提示词") | ||
| 21 | - @NotNull(message = "提示词不能为空!") | ||
| 22 | - @Size(max = 1200, message = "提示词最大1200") | 20 | + @Schema(description = "id编号", example = "1") |
| 21 | + private Long id; | ||
| 22 | + | ||
| 23 | + @Schema(description = "用户id", example = "1") | ||
| 24 | + private Long userId; | ||
| 25 | + | ||
| 26 | + @Schema(description = "提示词", example = "南极的小企鹅") | ||
| 23 | private String prompt; | 27 | private String prompt; |
| 24 | 28 | ||
| 25 | - @Schema(description = "模型") | ||
| 26 | - @NotNull(message = "模型不能为空") | 29 | + @Schema(description = "平台", example = "openai") |
| 30 | + private String platform; | ||
| 31 | + | ||
| 32 | + @Schema(description = "模型", example = "dall2") | ||
| 27 | private String model; | 33 | private String model; |
| 28 | 34 | ||
| 29 | - @Schema(description = "风格") | ||
| 30 | - private String style; | 35 | + @Schema(description = "图片宽度", example = "1024") |
| 36 | + private String width; | ||
| 37 | + | ||
| 38 | + @Schema(description = "图片高度", example = "1024") | ||
| 39 | + private String height; | ||
| 31 | 40 | ||
| 32 | - @Schema(description = "图片size 1024x1024 ...") | ||
| 33 | - private String size; | 41 | + @Schema(description = "绘画状态:10 进行中、20 绘画完成、30 绘画失败", example = "10") |
| 42 | + private String status; | ||
| 34 | 43 | ||
| 35 | - @Schema(description = "图片地址(自己服务器)") | 44 | + @Schema(description = "是否发布", example = "public") |
| 45 | + private String publicStatus; | ||
| 46 | + | ||
| 47 | + @Schema(description = "图片地址(自己服务器)", example = "http://") | ||
| 36 | private String picUrl; | 48 | private String picUrl; |
| 37 | 49 | ||
| 38 | - @Schema(description = "可以访问图像的URL。") | 50 | + @Schema(description = "绘画图片地址(绘画好的服务器)", example = "http://") |
| 39 | private String originalPicUrl; | 51 | private String originalPicUrl; |
| 40 | 52 | ||
| 41 | - @Schema(description = "图片base64。") | ||
| 42 | - private String base64; | ||
| 43 | - | ||
| 44 | - @Schema(description = "错误信息。") | 53 | + @Schema(description = "绘画错误信息", example = "图片错误信息") |
| 45 | private String errorMessage; | 54 | private String errorMessage; |
| 46 | 55 | ||
| 56 | + // ============ 绘画请求参数 | ||
| 57 | + | ||
| 58 | + /** | ||
| 59 | + * - style | ||
| 60 | + */ | ||
| 61 | + @Schema(description = "绘画请求参数") | ||
| 62 | + private Map<String, Object> drawRequest; | ||
| 63 | + | ||
| 64 | + /** | ||
| 65 | + * - mjNonceId | ||
| 66 | + * - mjOperationId | ||
| 67 | + * - mjOperationName | ||
| 68 | + * - mjOperations | ||
| 69 | + */ | ||
| 70 | + @Schema(description = "绘画请求响应参数") | ||
| 71 | + private Map<String, Object> drawResponse; | ||
| 72 | + | ||
| 47 | } | 73 | } |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageListReqVO.java
| @@ -5,7 +5,7 @@ import lombok.Data; | @@ -5,7 +5,7 @@ import lombok.Data; | ||
| 5 | import lombok.experimental.Accessors; | 5 | import lombok.experimental.Accessors; |
| 6 | 6 | ||
| 7 | /** | 7 | /** |
| 8 | - * midjourney req | 8 | + * AI Image 我的图片列表 req |
| 9 | * | 9 | * |
| 10 | * @author fansili | 10 | * @author fansili |
| 11 | * @time 2024/4/28 17:42 | 11 | * @time 2024/4/28 17:42 |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageListRespVO.java
| @@ -10,6 +10,7 @@ import lombok.Data; | @@ -10,6 +10,7 @@ import lombok.Data; | ||
| 10 | import lombok.experimental.Accessors; | 10 | import lombok.experimental.Accessors; |
| 11 | 11 | ||
| 12 | import java.time.LocalDateTime; | 12 | import java.time.LocalDateTime; |
| 13 | +import java.util.Map; | ||
| 13 | 14 | ||
| 14 | /** | 15 | /** |
| 15 | * midjourney req | 16 | * midjourney req |
| @@ -22,56 +23,57 @@ import java.time.LocalDateTime; | @@ -22,56 +23,57 @@ import java.time.LocalDateTime; | ||
| 22 | @Accessors(chain = true) | 23 | @Accessors(chain = true) |
| 23 | public class AiImageListRespVO extends PageParam { | 24 | public class AiImageListRespVO extends PageParam { |
| 24 | 25 | ||
| 26 | + @Schema(description = "id编号", example = "1") | ||
| 25 | private Long id; | 27 | private Long id; |
| 26 | 28 | ||
| 27 | - @Schema(description = "用户id") | 29 | + @Schema(description = "用户id", example = "1") |
| 28 | private Long userId; | 30 | private Long userId; |
| 29 | 31 | ||
| 30 | - @Schema(description = "提示词") | 32 | + @Schema(description = "提示词", example = "南极的小企鹅") |
| 31 | private String prompt; | 33 | private String prompt; |
| 32 | 34 | ||
| 33 | - @Schema(description = "模型 dall2/dall3、MJ、NIJI") | ||
| 34 | - private String model; | 35 | + @Schema(description = "平台", example = "openai") |
| 36 | + private String platform; | ||
| 35 | 37 | ||
| 36 | - @Schema(description = "生成图像的尺寸大小。对于dall-e-2模型,尺寸可为256x256, 512x512, 或 1024x1024。对于dall-e-3模型,尺寸可为1024x1024, 1792x1024, 或 1024x1792。") | ||
| 37 | - private String size; | 38 | + @Schema(description = "模型", example = "dall2") |
| 39 | + private String model; | ||
| 38 | 40 | ||
| 39 | - @Schema(description = "风格") | ||
| 40 | - private String style; | 41 | + @Schema(description = "图片宽度", example = "1024") |
| 42 | + private String width; | ||
| 41 | 43 | ||
| 42 | - @Schema(description = "图片地址(自己服务器)") | ||
| 43 | - private String picUrl; | 44 | + @Schema(description = "图片高度", example = "1024") |
| 45 | + private String height; | ||
| 44 | 46 | ||
| 45 | - @Schema(description = "绘画状态:提交、排队、绘画中、绘画完成、绘画失败") | 47 | + @Schema(description = "绘画状态:10 进行中、20 绘画完成、30 绘画失败", example = "10") |
| 46 | private String status; | 48 | private String status; |
| 47 | 49 | ||
| 48 | - @Schema(description = "绘画图片地址(绘画好的服务器)") | ||
| 49 | - private String originalPicUrl; | ||
| 50 | - | ||
| 51 | - @Schema(description = "绘画错误信息") | ||
| 52 | - private String errorMessage; | ||
| 53 | - | ||
| 54 | - @Schema(description = "是否发布") | 50 | + @Schema(description = "是否发布", example = "public") |
| 55 | private String publicStatus; | 51 | private String publicStatus; |
| 56 | 52 | ||
| 57 | - @Schema(description = "创建时间") | ||
| 58 | - private LocalDateTime createTime; | ||
| 59 | - | ||
| 60 | - @Schema(description = "更新时间") | ||
| 61 | - private LocalDateTime updateTime; | ||
| 62 | - | ||
| 63 | - // ============ mj 需要字段 | ||
| 64 | - | ||
| 65 | - @Schema(description = "用户操作的Nonce编号(MJ返回)") | ||
| 66 | - private String mjNonceId; | 53 | + @Schema(description = "图片地址(自己服务器)", example = "http://") |
| 54 | + private String picUrl; | ||
| 67 | 55 | ||
| 68 | - @Schema(description = "用户操作的操作编号(MJ返回)") | ||
| 69 | - private String mjOperationId; | 56 | + @Schema(description = "绘画图片地址(绘画好的服务器)", example = "http://") |
| 57 | + private String originalPicUrl; | ||
| 70 | 58 | ||
| 71 | - @Schema(description = "用户操作的操作名字(MJ返回)") | ||
| 72 | - private String mjOperationName; | 59 | + @Schema(description = "绘画错误信息", example = "图片错误信息") |
| 60 | + private String errorMessage; | ||
| 73 | 61 | ||
| 74 | - @Schema(description = "mj图片生产成功保存的 components json 数组") | ||
| 75 | - private String mjOperations; | 62 | + // ============ 绘画请求参数 |
| 63 | + | ||
| 64 | + /** | ||
| 65 | + * - style | ||
| 66 | + */ | ||
| 67 | + @Schema(description = "绘画请求参数") | ||
| 68 | + private Map<String, Object> drawRequest; | ||
| 69 | + | ||
| 70 | + /** | ||
| 71 | + * - mjNonceId | ||
| 72 | + * - mjOperationId | ||
| 73 | + * - mjOperationName | ||
| 74 | + * - mjOperations | ||
| 75 | + */ | ||
| 76 | + @Schema(description = "绘画请求响应参数") | ||
| 77 | + private Map<String, Object> drawResponse; | ||
| 76 | 78 | ||
| 77 | } | 79 | } |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/image/AiImageDO.java
| @@ -2,8 +2,10 @@ package cn.iocoder.yudao.module.ai.dal.dataobject.image; | @@ -2,8 +2,10 @@ package cn.iocoder.yudao.module.ai.dal.dataobject.image; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 4 | import com.baomidou.mybatisplus.annotation.IdType; | 4 | import com.baomidou.mybatisplus.annotation.IdType; |
| 5 | +import com.baomidou.mybatisplus.annotation.TableField; | ||
| 5 | import com.baomidou.mybatisplus.annotation.TableId; | 6 | import com.baomidou.mybatisplus.annotation.TableId; |
| 6 | import com.baomidou.mybatisplus.annotation.TableName; | 7 | import com.baomidou.mybatisplus.annotation.TableName; |
| 8 | +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; | ||
| 7 | import io.swagger.v3.oas.annotations.media.Schema; | 9 | import io.swagger.v3.oas.annotations.media.Schema; |
| 8 | import lombok.Data; | 10 | import lombok.Data; |
| 9 | 11 | ||
| @@ -60,6 +62,7 @@ public class AiImageDO extends BaseDO { | @@ -60,6 +62,7 @@ public class AiImageDO extends BaseDO { | ||
| 60 | * - style | 62 | * - style |
| 61 | */ | 63 | */ |
| 62 | @Schema(description = "绘画请求参数") | 64 | @Schema(description = "绘画请求参数") |
| 65 | + @TableField(typeHandler = JacksonTypeHandler.class) | ||
| 63 | private Map<String, Object> drawRequest; | 66 | private Map<String, Object> drawRequest; |
| 64 | 67 | ||
| 65 | /** | 68 | /** |
| @@ -69,6 +72,7 @@ public class AiImageDO extends BaseDO { | @@ -69,6 +72,7 @@ public class AiImageDO extends BaseDO { | ||
| 69 | * - mjOperations | 72 | * - mjOperations |
| 70 | */ | 73 | */ |
| 71 | @Schema(description = "绘画请求响应参数") | 74 | @Schema(description = "绘画请求响应参数") |
| 75 | + @TableField(typeHandler = JacksonTypeHandler.class) | ||
| 72 | private Map<String, Object> drawResponse; | 76 | private Map<String, Object> drawResponse; |
| 73 | 77 | ||
| 74 | } | 78 | } |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageService.java
| @@ -33,7 +33,7 @@ public interface AiImageService { | @@ -33,7 +33,7 @@ public interface AiImageService { | ||
| 33 | * | 33 | * |
| 34 | * @param req | 34 | * @param req |
| 35 | */ | 35 | */ |
| 36 | - AiImageDallRespVO dallDrawing(AiImageDallReqVO req); | 36 | + AiImageDallRespVO dall(AiImageDallReqVO req); |
| 37 | 37 | ||
| 38 | /** | 38 | /** |
| 39 | * midjourney 图片生成 | 39 | * midjourney 图片生成 |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java
| @@ -115,7 +115,7 @@ public class AiImageServiceImpl implements AiImageService { | @@ -115,7 +115,7 @@ public class AiImageServiceImpl implements AiImageService { | ||
| 115 | 115 | ||
| 116 | // TODO @fan:1)loginUserId 通过 controller 传入; | 116 | // TODO @fan:1)loginUserId 通过 controller 传入; |
| 117 | @Override | 117 | @Override |
| 118 | - public AiImageDallRespVO dallDrawing(AiImageDallReqVO req) { | 118 | + public AiImageDallRespVO dall(AiImageDallReqVO req) { |
| 119 | Long loginUserId = SecurityFrameworkUtils.getLoginUserId(); | 119 | Long loginUserId = SecurityFrameworkUtils.getLoginUserId(); |
| 120 | // 保存数据库 | 120 | // 保存数据库 |
| 121 | // TODO @fan:1)使用 BeanUtils;2)使用链式调用哈; | 121 | // TODO @fan:1)使用 BeanUtils;2)使用链式调用哈; |