Commit 26616ea7a7deca95dafceaed6a246ffebf6d686b
1 parent
8b1e1c04
【解决todo】将 login user 通过 controller 传入
Showing
2 changed files
with
28 additions
and
14 deletions
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/AiImageController.java
| @@ -2,7 +2,9 @@ package cn.iocoder.yudao.module.ai.controller.admin.image; | @@ -2,7 +2,9 @@ package cn.iocoder.yudao.module.ai.controller.admin.image; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 5 | import cn.iocoder.yudao.module.ai.controller.admin.image.vo.*; | 6 | import cn.iocoder.yudao.module.ai.controller.admin.image.vo.*; |
| 7 | +import cn.iocoder.yudao.module.ai.dal.dataobject.image.AiImageDO; | ||
| 6 | import cn.iocoder.yudao.module.ai.service.image.AiImageService; | 8 | import cn.iocoder.yudao.module.ai.service.image.AiImageService; |
| 7 | import io.swagger.v3.oas.annotations.Operation; | 9 | import io.swagger.v3.oas.annotations.Operation; |
| 8 | import io.swagger.v3.oas.annotations.Parameter; | 10 | import io.swagger.v3.oas.annotations.Parameter; |
| @@ -24,25 +26,33 @@ public class AiImageController { | @@ -24,25 +26,33 @@ public class AiImageController { | ||
| 24 | @Resource | 26 | @Resource |
| 25 | private AiImageService aiImageService; | 27 | private AiImageService aiImageService; |
| 26 | 28 | ||
| 27 | - // TODO @fan:方法名叫做,getImagePageMy ;我们的命名,还是以动名词哈。不考虑省略名词的原因,是担心一个 Service 扩多个模块,纯粹动词无法表达 | ||
| 28 | @Operation(summary = "获取【我的】绘图分页") | 29 | @Operation(summary = "获取【我的】绘图分页") |
| 29 | @GetMapping("/my-page") | 30 | @GetMapping("/my-page") |
| 30 | - public CommonResult<PageResult<AiImageListRespVO>> myPage(@Validated AiImageListReqVO req) { | ||
| 31 | - return success(aiImageService.list(req)); | 31 | + public CommonResult<PageResult<AiImagePageMyRespVO>> getImagePageMy(@Validated AiImageListReqVO req) { |
| 32 | + // 转换 resp | ||
| 33 | + PageResult<AiImageDO> pageResult = aiImageService.getImagePageMy(getLoginUserId(), req); | ||
| 34 | + // 转换 PageResult<AiImageListRespVO> 返回 | ||
| 35 | + PageResult<AiImagePageMyRespVO> result = new PageResult<>(); | ||
| 36 | + result.setTotal(pageResult.getTotal()); | ||
| 37 | + result.setList(BeanUtils.toBean(pageResult.getList(), AiImagePageMyRespVO.class)); | ||
| 38 | + return success(result); | ||
| 32 | } | 39 | } |
| 33 | 40 | ||
| 34 | // TODO @fan:类似 /my-page 的建议 | 41 | // TODO @fan:类似 /my-page 的建议 |
| 35 | @Operation(summary = "获取【我的】绘图记录", description = "...") | 42 | @Operation(summary = "获取【我的】绘图记录", description = "...") |
| 36 | @GetMapping("/get-my") | 43 | @GetMapping("/get-my") |
| 37 | - public CommonResult<AiImageListRespVO> getMy(@RequestParam("id") Long id) { | ||
| 38 | - return CommonResult.success(aiImageService.getMy(id)); | 44 | + public CommonResult<AiImagePageMyRespVO> getMy(@RequestParam("id") Long id) { |
| 45 | + // 获取 image 信息 | ||
| 46 | + AiImageDO imageDO = aiImageService.getMy(id); | ||
| 47 | + // 转 resp 并返回 | ||
| 48 | + return CommonResult.success(BeanUtils.toBean(imageDO, AiImagePageMyRespVO.class)); | ||
| 39 | } | 49 | } |
| 40 | 50 | ||
| 41 | // TODO @fan:建议把 dallDrawing、midjourney 融合成一个 draw 接口,异步绘制;然后返回一个 id 给前端;前端通过 get 接口轮询,直到获取到生成成功 | 51 | // TODO @fan:建议把 dallDrawing、midjourney 融合成一个 draw 接口,异步绘制;然后返回一个 id 给前端;前端通过 get 接口轮询,直到获取到生成成功 |
| 42 | @Operation(summary = "dall2/dall3绘画", description = "openAi dall3是付费的!") | 52 | @Operation(summary = "dall2/dall3绘画", description = "openAi dall3是付费的!") |
| 43 | @PostMapping("/dall") | 53 | @PostMapping("/dall") |
| 44 | - public AiImageDallRespVO dall(@Validated @RequestBody AiImageDallReqVO req) { | ||
| 45 | - return aiImageService.dall(req); | 54 | + public CommonResult<Long> dall(@Validated @RequestBody AiImageDallReqVO req) { |
| 55 | + return success(aiImageService.dall(getLoginUserId(), req)); | ||
| 46 | } | 56 | } |
| 47 | 57 | ||
| 48 | @Operation(summary = "midjourney绘画", description = "midjourney图片绘画流程:1、提交任务 2、获取完成的任务 3、选择对应功能 4、获取最终结果") | 58 | @Operation(summary = "midjourney绘画", description = "midjourney图片绘画流程:1、提交任务 2、获取完成的任务 3、选择对应功能 4、获取最终结果") |
| @@ -73,9 +83,7 @@ public class AiImageController { | @@ -73,9 +83,7 @@ public class AiImageController { | ||
| 73 | @DeleteMapping("/delete-my") | 83 | @DeleteMapping("/delete-my") |
| 74 | @Parameter(name = "id", required = true, description = "绘画编号", example = "1024") | 84 | @Parameter(name = "id", required = true, description = "绘画编号", example = "1024") |
| 75 | public CommonResult<Void> deleteMy(@RequestParam("id") Long id) { | 85 | public CommonResult<Void> deleteMy(@RequestParam("id") Long id) { |
| 76 | - // TODO @fan:这种一次性的 loginUserId,可以不用定义变量,直接当参数传递 | ||
| 77 | - Long loginUserId = getLoginUserId(); | ||
| 78 | - aiImageService.deleteMy(id, loginUserId); | 86 | + aiImageService.deleteMy(id, getLoginUserId()); |
| 79 | return success(null); | 87 | return success(null); |
| 80 | } | 88 | } |
| 81 | 89 |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageService.java
| 1 | package cn.iocoder.yudao.module.ai.service.image; | 1 | package cn.iocoder.yudao.module.ai.service.image; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | -import cn.iocoder.yudao.module.ai.controller.admin.image.vo.*; | 4 | +import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageDallReqVO; |
| 5 | +import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageListReqVO; | ||
| 6 | +import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageMidjourneyOperateReqVO; | ||
| 7 | +import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageMidjourneyReqVO; | ||
| 8 | +import cn.iocoder.yudao.module.ai.dal.dataobject.image.AiImageDO; | ||
| 5 | 9 | ||
| 6 | /** | 10 | /** |
| 7 | * ai 作图 | 11 | * ai 作图 |
| @@ -15,10 +19,11 @@ public interface AiImageService { | @@ -15,10 +19,11 @@ public interface AiImageService { | ||
| 15 | /** | 19 | /** |
| 16 | * ai绘画 - 列表 | 20 | * ai绘画 - 列表 |
| 17 | * | 21 | * |
| 22 | + * @param loginUserId | ||
| 18 | * @param req | 23 | * @param req |
| 19 | * @return | 24 | * @return |
| 20 | */ | 25 | */ |
| 21 | - PageResult<AiImageListRespVO> list(AiImageListReqVO req); | 26 | + PageResult<AiImageDO> getImagePageMy(Long loginUserId, AiImageListReqVO req); |
| 22 | 27 | ||
| 23 | /** | 28 | /** |
| 24 | * 获取 - image 信息 | 29 | * 获取 - image 信息 |
| @@ -26,14 +31,15 @@ public interface AiImageService { | @@ -26,14 +31,15 @@ public interface AiImageService { | ||
| 26 | * @param id | 31 | * @param id |
| 27 | * @return | 32 | * @return |
| 28 | */ | 33 | */ |
| 29 | - AiImageListRespVO getMy(Long id); | 34 | + AiImageDO getMy(Long id); |
| 30 | 35 | ||
| 31 | /** | 36 | /** |
| 32 | * ai绘画 - dall2/dall3 绘画 | 37 | * ai绘画 - dall2/dall3 绘画 |
| 33 | * | 38 | * |
| 39 | + * @param loginUserId | ||
| 34 | * @param req | 40 | * @param req |
| 35 | */ | 41 | */ |
| 36 | - AiImageDallRespVO dall(AiImageDallReqVO req); | 42 | + Long dall(Long loginUserId, AiImageDallReqVO req); |
| 37 | 43 | ||
| 38 | /** | 44 | /** |
| 39 | * midjourney 图片生成 | 45 | * midjourney 图片生成 |