From 342f603964aae28373f2cc830d4c164238e2fc39 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 30 May 2024 09:35:23 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BB=A3=E7=A0=81=E8=AF=84=E5=AE=A1?= =?UTF-8?q?=E3=80=91AI=EF=BC=9AAI=20=E7=BB=98=E5=9B=BE=E7=9A=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/module/ai/ErrorCodeConstants.java | 2 ++ .../module/ai/enums/AiImageStatusEnum.java | 26 +++++++++---------- .../admin/image/AiImageController.java | 13 +++++++--- .../admin/image/vo/AiImageDallRespVO.java | 7 ++--- .../admin/image/vo/AiImageListRespVO.java | 3 +++ .../ai/dal/dataobject/image/AiImageDO.java | 13 ++++++---- .../ai/dal/mysql/image/AiImageMapper.java | 6 ++--- .../ai/service/image/AiImageServiceImpl.java | 6 +++-- 8 files changed, 46 insertions(+), 30 deletions(-) diff --git a/yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/ErrorCodeConstants.java b/yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/ErrorCodeConstants.java index da48c61e5..5ec26f7ed 100644 --- a/yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/ErrorCodeConstants.java +++ b/yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/ErrorCodeConstants.java @@ -42,5 +42,7 @@ public interface ErrorCodeConstants { // ========== API 绘画 1-040-005-000 ========== + // TODO @fan:这个直接返回找不到图片就好了 ErrorCode AI_IMAGE_NOT_CREATE_USER = new ErrorCode(1_022_005_000, "不是创建用户,不能删除 image!"); + } diff --git a/yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/AiImageStatusEnum.java b/yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/AiImageStatusEnum.java index ad4ab4590..39df7b1a8 100644 --- a/yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/AiImageStatusEnum.java +++ b/yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/AiImageStatusEnum.java @@ -4,11 +4,9 @@ import lombok.AllArgsConstructor; import lombok.Getter; /** - * ai绘画状态 + * AI 绘画状态的枚举 * * @author fansili - * @time 2024/4/28 17:05 - * @since 1.0 */ @AllArgsConstructor @Getter @@ -16,22 +14,24 @@ public enum AiImageStatusEnum { IN_PROGRESS("10", "进行中"), COMPLETE("20", "完成"), - FAIL("30", "失败"), + FAIL("30", "失败"); - ; - - // TODO @fan:final 一下 + /** + * 状态 + */ private final String status; - + /** + * 状态名 + */ private final String name; - public static AiImageStatusEnum valueOfStatus(String status) { - for (AiImageStatusEnum itemEnum : AiImageStatusEnum.values()) { - if (itemEnum.getStatus().equals(status)) { - return itemEnum; + for (AiImageStatusEnum statusEnum : AiImageStatusEnum.values()) { + if (statusEnum.getStatus().equals(status)) { + return statusEnum; } } - throw new IllegalArgumentException("Invalid MessageType value: " + status); + throw new IllegalArgumentException("未知会话状态: " + status); } + } 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 6d15798e4..cee0954ce 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 @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.ai.controller.admin.image.vo.*; import cn.iocoder.yudao.module.ai.service.image.AiImageService; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; @@ -23,13 +24,15 @@ public class AiImageController { @Resource private AiImageService aiImageService; - @Operation(summary = "获取 - 我的分页列表", description = "dall3、midjourney") + // TODO @fan:方法名叫做,getImagePageMy ;我们的命名,还是以动名词哈。不考虑省略名词的原因,是担心一个 Service 扩多个模块,纯粹动词无法表达 + @Operation(summary = "获取【我的】绘图分页") @GetMapping("/my-page") public CommonResult> myPage(@Validated AiImageListReqVO req) { return success(aiImageService.list(req)); } - @Operation(summary = "获取 - 我的 image 信息", description = "...") + // TODO @fan:类似 /my-page 的建议 + @Operation(summary = "获取【我的】绘图记录", description = "...") @GetMapping("/get-my") public CommonResult getMy(@RequestParam("id") Long id) { return CommonResult.success(aiImageService.getMy(id)); @@ -64,9 +67,13 @@ public class AiImageController { return success(null); } - @Operation(summary = "删除绘画记录", description = "") + // TODO @fan:类似 /my-page 的建议 + // TODO @fan:目前如果没结果,返回 Boolean 哈 + @Operation(summary = "删除【我的】绘画记录") @DeleteMapping("/delete-my") + @Parameter(name = "id", required = true, description = "绘画编号", example = "1024") public CommonResult deleteMy(@RequestParam("id") Long id) { + // TODO @fan:这种一次性的 loginUserId,可以不用定义变量,直接当参数传递 Long loginUserId = getLoginUserId(); aiImageService.deleteMy(id, loginUserId); return success(null); diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageDallRespVO.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageDallRespVO.java index 934141339..a687192e6 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageDallRespVO.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageDallRespVO.java @@ -44,17 +44,18 @@ public class AiImageDallRespVO { @Schema(description = "是否发布", example = "public") private String publicStatus; - @Schema(description = "图片地址(自己服务器)", example = "http://") + @Schema(description = "图片地址(自己服务器)", example = "https://") private String picUrl; - @Schema(description = "绘画图片地址(绘画好的服务器)", example = "http://") + @Schema(description = "绘画图片地址(绘画好的服务器)", example = "https://") private String originalPicUrl; @Schema(description = "绘画错误信息", example = "图片错误信息") private String errorMessage; - // ============ 绘画请求参数 + // ============ 绘画请求参数 ============ + // todo @fan:下面的 style、mjNonceId 直接就不用注释啦,直接去看 DO 完事哈 /** * - style */ diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageListRespVO.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageListRespVO.java index c0bb20773..1ee14cb89 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageListRespVO.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageListRespVO.java @@ -12,6 +12,7 @@ import lombok.experimental.Accessors; import java.time.LocalDateTime; import java.util.Map; +// TODO @fan:可以考虑,复用 AiImageDallRespVO,统一成 AIImageRespVO /** * midjourney req * @@ -61,6 +62,8 @@ public class AiImageListRespVO extends PageParam { // ============ 绘画请求参数 + // todo @fan:下面的 style、mjNonceId 直接就不用注释啦,直接去看 DO 完事哈 + /** * - style */ diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/image/AiImageDO.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/image/AiImageDO.java index 1474fc683..259215cdc 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/image/AiImageDO.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/image/AiImageDO.java @@ -20,10 +20,12 @@ import java.util.Map; @Data public class AiImageDO extends BaseDO { + // TODO @fan:1)使用 java 注释哈,不要注解。2)关联、枚举字段,要关联到对应类,参考 AiChatMessageDO 的注释 + @TableId(type = IdType.AUTO) private Long id; - @Schema(description = "用户id") + @Schema(description = "用户编号") private Long userId; @Schema(description = "提示词") @@ -41,6 +43,7 @@ public class AiImageDO extends BaseDO { @Schema(description = "图片高度") private String height; + // TODO @fan:这种就注释绘画状态,然后枚举类关联下就好啦 @Schema(description = "绘画状态:提交、排队、绘画中、绘画完成、绘画失败") private String status; @@ -53,10 +56,7 @@ public class AiImageDO extends BaseDO { @Schema(description = "绘画图片地址(绘画好的服务器)") private String originalPicUrl; - @Schema(description = "绘画错误信息") - private String errorMessage; - - // ============ 绘画请求参数 + // ============ 绘画请求参数 ============ /** * - style @@ -75,5 +75,8 @@ public class AiImageDO extends BaseDO { @TableField(typeHandler = JacksonTypeHandler.class) private Map drawResponse; + @Schema(description = "绘画错误信息") + private String errorMessage; + } diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/image/AiImageMapper.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/image/AiImageMapper.java index 6cf8a80e7..f60668d21 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/image/AiImageMapper.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/image/AiImageMapper.java @@ -7,16 +7,14 @@ import org.apache.ibatis.annotations.Mapper; import org.springframework.stereotype.Repository; /** - * ai image + * AI 绘图 Mapper * * @author fansili - * @time 2024/4/28 14:01 - * @since 1.0 */ @Mapper public interface AiImageMapper extends BaseMapperX { - + // TODO @fan:这个建议,直接使用 update,service 拼接要改的状态哈 /** * 更新 - 根据 messageId * 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 93c1e51f0..1cce11642 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 @@ -200,10 +200,12 @@ public class AiImageServiceImpl implements AiImageService { // TODO @fan:1)需要校验存在;2)需要校验属于我; @Override - public void deleteMy(Long id, Long loginUserId) { + public void deleteMy(Long id, Long userId) { // 校验记录是否存在 + // TODO @fan:aiImageDO 这种命名 image 就 ok 拉,更简洁 + // TODO @fan:下面这个,可以返回图片不存在 AiImageDO aiImageDO = validateExists(id); - if (!aiImageDO.getUserId().equals(loginUserId)) { + if (!aiImageDO.getUserId().equals(userId)) { throw exception(ErrorCodeConstants.AI_IMAGE_NOT_CREATE_USER); } // 删除记录