mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-27 01:32:03 +08:00
【代码评审】AI:AI 绘图的逻辑
This commit is contained in:
parent
e4a0512b51
commit
342f603964
@ -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!");
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<PageResult<AiImageListRespVO>> 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<AiImageListRespVO> 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<Void> deleteMy(@RequestParam("id") Long id) {
|
||||
// TODO @fan:这种一次性的 loginUserId,可以不用定义变量,直接当参数传递
|
||||
Long loginUserId = getLoginUserId();
|
||||
aiImageService.deleteMy(id, loginUserId);
|
||||
return success(null);
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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<String, Object> drawResponse;
|
||||
|
||||
@Schema(description = "绘画错误信息")
|
||||
private String errorMessage;
|
||||
|
||||
}
|
||||
|
||||
|
@ -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<AiImageDO> {
|
||||
|
||||
|
||||
// TODO @fan:这个建议,直接使用 update,service 拼接要改的状态哈
|
||||
/**
|
||||
* 更新 - 根据 messageId
|
||||
*
|
||||
|
@ -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);
|
||||
}
|
||||
// 删除记录
|
||||
|
Loading…
Reference in New Issue
Block a user