Commit 29ade63f873f45c448d8f337cf6c3493aa150fe9
1 parent
d0cec28b
【代码优化】AI:image 作品中心的代码
Showing
8 changed files
with
18 additions
and
16 deletions
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/AiImageController.java
| ... | ... | @@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.ai.controller.admin.image; |
| 3 | 3 | import cn.hutool.core.util.ObjUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.ai.core.model.midjourney.api.MidjourneyApi; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 6 | -import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 8 | 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 9 | 8 | import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageDrawReqVO; |
| ... | ... | @@ -41,7 +40,7 @@ public class AiImageController { |
| 41 | 40 | |
| 42 | 41 | @GetMapping("/my-page") |
| 43 | 42 | @Operation(summary = "获取【我的】绘图分页") |
| 44 | - public CommonResult<PageResult<AiImageRespVO>> getImagePageMy(@Validated PageParam pageReqVO) { | |
| 43 | + public CommonResult<PageResult<AiImageRespVO>> getImagePageMy(@Validated AiImagePageReqVO pageReqVO) { | |
| 45 | 44 | PageResult<AiImageDO> pageResult = imageService.getImagePageMy(getLoginUserId(), pageReqVO); |
| 46 | 45 | return success(BeanUtils.toBean(pageResult, AiImageRespVO.class)); |
| 47 | 46 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImagePageReqVO.java
| ... | ... | @@ -3,8 +3,6 @@ package cn.iocoder.yudao.module.ai.controller.admin.image.vo; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 4 | 4 | import io.swagger.v3.oas.annotations.media.Schema; |
| 5 | 5 | import lombok.Data; |
| 6 | -import lombok.EqualsAndHashCode; | |
| 7 | -import lombok.ToString; | |
| 8 | 6 | import org.springframework.format.annotation.DateTimeFormat; |
| 9 | 7 | |
| 10 | 8 | import java.time.LocalDateTime; |
| ... | ... | @@ -21,6 +19,9 @@ public class AiImagePageReqVO extends PageParam { |
| 21 | 19 | @Schema(description = "平台", example = "OpenAI") |
| 22 | 20 | private String platform; |
| 23 | 21 | |
| 22 | + @Schema(description = "提示词", example = "1") | |
| 23 | + private String prompt; | |
| 24 | + | |
| 24 | 25 | @Schema(description = "绘画状态", example = "1") |
| 25 | 26 | private Integer status; |
| 26 | 27 | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/image/AiImageMapper.java
| 1 | 1 | package cn.iocoder.yudao.module.ai.dal.mysql.image; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 6 | 5 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| ... | ... | @@ -19,7 +18,7 @@ import java.util.List; |
| 19 | 18 | public interface AiImageMapper extends BaseMapperX<AiImageDO> { |
| 20 | 19 | |
| 21 | 20 | default AiImageDO selectByTaskId(String taskId) { |
| 22 | - return this.selectOne(AiImageDO::getTaskId, taskId); | |
| 21 | + return selectOne(AiImageDO::getTaskId, taskId); | |
| 23 | 22 | } |
| 24 | 23 | |
| 25 | 24 | default PageResult<AiImageDO> selectPage(AiImagePageReqVO reqVO) { |
| ... | ... | @@ -32,9 +31,13 @@ public interface AiImageMapper extends BaseMapperX<AiImageDO> { |
| 32 | 31 | .orderByDesc(AiImageDO::getId)); |
| 33 | 32 | } |
| 34 | 33 | |
| 35 | - default PageResult<AiImageDO> selectPage(Long userId, PageParam pageReqVO) { | |
| 36 | - return selectPage(pageReqVO, new LambdaQueryWrapperX<AiImageDO>() | |
| 37 | - .eq(AiImageDO::getUserId, userId) | |
| 34 | + default PageResult<AiImageDO> selectPageMy(Long userId, AiImagePageReqVO reqVO) { | |
| 35 | + return selectPage(reqVO, new LambdaQueryWrapperX<AiImageDO>() | |
| 36 | + .likeIfPresent(AiImageDO::getPrompt, reqVO.getPrompt()) | |
| 37 | + // 情况一:公开 | |
| 38 | + .eq(Boolean.TRUE.equals(reqVO.getPublicStatus()), AiImageDO::getPublicStatus, reqVO.getPublicStatus()) | |
| 39 | + // 情况二:私有 | |
| 40 | + .eq(Boolean.FALSE.equals(reqVO.getPublicStatus()), AiImageDO::getUserId, userId) | |
| 38 | 41 | .orderByDesc(AiImageDO::getId)); |
| 39 | 42 | } |
| 40 | 43 | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageService.java
| 1 | 1 | package cn.iocoder.yudao.module.ai.service.image; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.ai.core.model.midjourney.api.MidjourneyApi; |
| 4 | -import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 5 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | 5 | import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageDrawReqVO; |
| 7 | 6 | import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImagePageReqVO; |
| ... | ... | @@ -27,7 +26,7 @@ public interface AiImageService { |
| 27 | 26 | * @param pageReqVO 分页条件 |
| 28 | 27 | * @return 绘图分页 |
| 29 | 28 | */ |
| 30 | - PageResult<AiImageDO> getImagePageMy(Long userId, PageParam pageReqVO); | |
| 29 | + PageResult<AiImageDO> getImagePageMy(Long userId, AiImagePageReqVO pageReqVO); | |
| 31 | 30 | |
| 32 | 31 | /** |
| 33 | 32 | * 获得绘图记录 | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java
| ... | ... | @@ -10,7 +10,6 @@ import cn.hutool.extra.spring.SpringUtil; |
| 10 | 10 | import cn.hutool.http.HttpUtil; |
| 11 | 11 | import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum; |
| 12 | 12 | import cn.iocoder.yudao.framework.ai.core.model.midjourney.api.MidjourneyApi; |
| 13 | -import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 14 | 13 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 15 | 14 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 16 | 15 | import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageDrawReqVO; |
| ... | ... | @@ -67,8 +66,8 @@ public class AiImageServiceImpl implements AiImageService { |
| 67 | 66 | private AiApiKeyService apiKeyService; |
| 68 | 67 | |
| 69 | 68 | @Override |
| 70 | - public PageResult<AiImageDO> getImagePageMy(Long userId, PageParam pageReqVO) { | |
| 71 | - return imageMapper.selectPage(userId, pageReqVO); | |
| 69 | + public PageResult<AiImageDO> getImagePageMy(Long userId, AiImagePageReqVO pageReqVO) { | |
| 70 | + return imageMapper.selectPageMy(userId, pageReqVO); | |
| 72 | 71 | } |
| 73 | 72 | |
| 74 | 73 | @Override | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/mindmap/AiMindMapServiceImpl.java
| ... | ... | @@ -124,7 +124,7 @@ public class AiMindMapServiceImpl implements AiMindMapService { |
| 124 | 124 | if (role != null && role.getModelId() != null) { |
| 125 | 125 | model = chatModalService.getChatModel(role.getModelId()); |
| 126 | 126 | } |
| 127 | - if (model != null) { | |
| 127 | + if (model == null) { | |
| 128 | 128 | model = chatModalService.getRequiredDefaultChatModel(); |
| 129 | 129 | } |
| 130 | 130 | Assert.notNull(model, "[AI] 获取不到模型"); | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/write/AiWriteServiceImpl.java
| ... | ... | @@ -114,7 +114,7 @@ public class AiWriteServiceImpl implements AiWriteService { |
| 114 | 114 | if (Objects.nonNull(writeRole) && Objects.nonNull(writeRole.getModelId())) { |
| 115 | 115 | model = chatModalService.getChatModel(writeRole.getModelId()); |
| 116 | 116 | } |
| 117 | - if (Objects.isNull(model)) { | |
| 117 | + if (model == null) { | |
| 118 | 118 | model = chatModalService.getRequiredDefaultChatModel(); |
| 119 | 119 | } |
| 120 | 120 | Assert.notNull(model, "[AI] 获取不到模型"); | ... | ... |
yudao-server/src/main/resources/application-local.yaml
| ... | ... | @@ -174,6 +174,7 @@ logging: |
| 174 | 174 | cn.iocoder.yudao.module.statistics.dal.mysql: debug |
| 175 | 175 | cn.iocoder.yudao.module.crm.dal.mysql: debug |
| 176 | 176 | cn.iocoder.yudao.module.erp.dal.mysql: debug |
| 177 | + cn.iocoder.yudao.module.ai.dal.mysql: debug | |
| 177 | 178 | org.springframework.context.support.PostProcessorRegistrationDelegate: ERROR # TODO 芋艿:先禁用,Spring Boot 3.X 存在部分错误的 WARN 提示 |
| 178 | 179 | |
| 179 | 180 | debug: false | ... | ... |