【解决todo】将 login user 通过 controller 传入

This commit is contained in:
cherishsince 2024-05-30 10:15:02 +08:00
parent 8b1e1c047b
commit 26616ea7a7
2 changed files with 28 additions and 14 deletions

View File

@ -2,7 +2,9 @@ package cn.iocoder.yudao.module.ai.controller.admin.image;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.ai.controller.admin.image.vo.*;
import cn.iocoder.yudao.module.ai.dal.dataobject.image.AiImageDO;
import cn.iocoder.yudao.module.ai.service.image.AiImageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
@ -24,25 +26,33 @@ public class AiImageController {
@Resource
private AiImageService aiImageService;
// TODO @fan方法名叫做getImagePageMy 我们的命名还是以动名词哈不考虑省略名词的原因是担心一个 Service 扩多个模块纯粹动词无法表达
@Operation(summary = "获取【我的】绘图分页")
@GetMapping("/my-page")
public CommonResult<PageResult<AiImageListRespVO>> myPage(@Validated AiImageListReqVO req) {
return success(aiImageService.list(req));
public CommonResult<PageResult<AiImagePageMyRespVO>> getImagePageMy(@Validated AiImageListReqVO req) {
// 转换 resp
PageResult<AiImageDO> pageResult = aiImageService.getImagePageMy(getLoginUserId(), req);
// 转换 PageResult<AiImageListRespVO> 返回
PageResult<AiImagePageMyRespVO> result = new PageResult<>();
result.setTotal(pageResult.getTotal());
result.setList(BeanUtils.toBean(pageResult.getList(), AiImagePageMyRespVO.class));
return success(result);
}
// TODO @fan类似 /my-page 的建议
@Operation(summary = "获取【我的】绘图记录", description = "...")
@GetMapping("/get-my")
public CommonResult<AiImageListRespVO> getMy(@RequestParam("id") Long id) {
return CommonResult.success(aiImageService.getMy(id));
public CommonResult<AiImagePageMyRespVO> getMy(@RequestParam("id") Long id) {
// 获取 image 信息
AiImageDO imageDO = aiImageService.getMy(id);
// resp 并返回
return CommonResult.success(BeanUtils.toBean(imageDO, AiImagePageMyRespVO.class));
}
// TODO @fan建议把 dallDrawingmidjourney 融合成一个 draw 接口异步绘制然后返回一个 id 给前端前端通过 get 接口轮询直到获取到生成成功
@Operation(summary = "dall2/dall3绘画", description = "openAi dall3是付费的!")
@PostMapping("/dall")
public AiImageDallRespVO dall(@Validated @RequestBody AiImageDallReqVO req) {
return aiImageService.dall(req);
public CommonResult<Long> dall(@Validated @RequestBody AiImageDallReqVO req) {
return success(aiImageService.dall(getLoginUserId(), req));
}
@Operation(summary = "midjourney绘画", description = "midjourney图片绘画流程1、提交任务 2、获取完成的任务 3、选择对应功能 4、获取最终结果")
@ -73,9 +83,7 @@ public class AiImageController {
@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);
aiImageService.deleteMy(id, getLoginUserId());
return success(null);
}

View File

@ -1,7 +1,11 @@
package cn.iocoder.yudao.module.ai.service.image;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.ai.controller.admin.image.vo.*;
import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageDallReqVO;
import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageListReqVO;
import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageMidjourneyOperateReqVO;
import cn.iocoder.yudao.module.ai.controller.admin.image.vo.AiImageMidjourneyReqVO;
import cn.iocoder.yudao.module.ai.dal.dataobject.image.AiImageDO;
/**
* ai 作图
@ -15,10 +19,11 @@ public interface AiImageService {
/**
* ai绘画 - 列表
*
* @param loginUserId
* @param req
* @return
*/
PageResult<AiImageListRespVO> list(AiImageListReqVO req);
PageResult<AiImageDO> getImagePageMy(Long loginUserId, AiImageListReqVO req);
/**
* 获取 - image 信息
@ -26,14 +31,15 @@ public interface AiImageService {
* @param id
* @return
*/
AiImageListRespVO getMy(Long id);
AiImageDO getMy(Long id);
/**
* ai绘画 - dall2/dall3 绘画
*
* @param loginUserId
* @param req
*/
AiImageDallRespVO dall(AiImageDallReqVO req);
Long dall(Long loginUserId, AiImageDallReqVO req);
/**
* midjourney 图片生成