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 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 5 | 6 | import cn.iocoder.yudao.module.ai.controller.admin.image.vo.*; |
| 7 | +import cn.iocoder.yudao.module.ai.dal.dataobject.image.AiImageDO; | |
| 6 | 8 | import cn.iocoder.yudao.module.ai.service.image.AiImageService; |
| 7 | 9 | import io.swagger.v3.oas.annotations.Operation; |
| 8 | 10 | import io.swagger.v3.oas.annotations.Parameter; |
| ... | ... | @@ -24,25 +26,33 @@ public class AiImageController { |
| 24 | 26 | @Resource |
| 25 | 27 | private AiImageService aiImageService; |
| 26 | 28 | |
| 27 | - // TODO @fan:方法名叫做,getImagePageMy ;我们的命名,还是以动名词哈。不考虑省略名词的原因,是担心一个 Service 扩多个模块,纯粹动词无法表达 | |
| 28 | 29 | @Operation(summary = "获取【我的】绘图分页") |
| 29 | 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 | 41 | // TODO @fan:类似 /my-page 的建议 |
| 35 | 42 | @Operation(summary = "获取【我的】绘图记录", description = "...") |
| 36 | 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 | 51 | // TODO @fan:建议把 dallDrawing、midjourney 融合成一个 draw 接口,异步绘制;然后返回一个 id 给前端;前端通过 get 接口轮询,直到获取到生成成功 |
| 42 | 52 | @Operation(summary = "dall2/dall3绘画", description = "openAi dall3是付费的!") |
| 43 | 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 | 58 | @Operation(summary = "midjourney绘画", description = "midjourney图片绘画流程:1、提交任务 2、获取完成的任务 3、选择对应功能 4、获取最终结果") |
| ... | ... | @@ -73,9 +83,7 @@ public class AiImageController { |
| 73 | 83 | @DeleteMapping("/delete-my") |
| 74 | 84 | @Parameter(name = "id", required = true, description = "绘画编号", example = "1024") |
| 75 | 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 | 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 | 1 | package cn.iocoder.yudao.module.ai.service.image; |
| 2 | 2 | |
| 3 | 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 | 11 | * ai 作图 |
| ... | ... | @@ -15,10 +19,11 @@ public interface AiImageService { |
| 15 | 19 | /** |
| 16 | 20 | * ai绘画 - 列表 |
| 17 | 21 | * |
| 22 | + * @param loginUserId | |
| 18 | 23 | * @param req |
| 19 | 24 | * @return |
| 20 | 25 | */ |
| 21 | - PageResult<AiImageListRespVO> list(AiImageListReqVO req); | |
| 26 | + PageResult<AiImageDO> getImagePageMy(Long loginUserId, AiImageListReqVO req); | |
| 22 | 27 | |
| 23 | 28 | /** |
| 24 | 29 | * 获取 - image 信息 |
| ... | ... | @@ -26,14 +31,15 @@ public interface AiImageService { |
| 26 | 31 | * @param id |
| 27 | 32 | * @return |
| 28 | 33 | */ |
| 29 | - AiImageListRespVO getMy(Long id); | |
| 34 | + AiImageDO getMy(Long id); | |
| 30 | 35 | |
| 31 | 36 | /** |
| 32 | 37 | * ai绘画 - dall2/dall3 绘画 |
| 33 | 38 | * |
| 39 | + * @param loginUserId | |
| 34 | 40 | * @param req |
| 35 | 41 | */ |
| 36 | - AiImageDallRespVO dall(AiImageDallReqVO req); | |
| 42 | + Long dall(Long loginUserId, AiImageDallReqVO req); | |
| 37 | 43 | |
| 38 | 44 | /** |
| 39 | 45 | * midjourney 图片生成 | ... | ... |