GptQuickLinkController.java 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package com.cyksj.web.controller.api;
  2. import com.cyksj.common.annotation.NoSubmit;
  3. import com.cyksj.dto.Result;
  4. import com.cyksj.enums.GatewayResponse;
  5. import com.cyksj.model.entity.GptQuickLinkRecord;
  6. import com.cyksj.model.response.GptQuickLinkResp;
  7. import com.cyksj.service.gpt.GptQuickLinkService;
  8. import com.cyksj.web.util.StpUserUtil;
  9. import lombok.RequiredArgsConstructor;
  10. import org.springframework.web.bind.annotation.*;
  11. /**
  12. * GPT快捷链接API控制器
  13. */
  14. @RestController
  15. @RequestMapping("/applets/gpt/quickLink")
  16. @RequiredArgsConstructor
  17. public class GptQuickLinkController {
  18. private final GptQuickLinkService gptQuickLinkService;
  19. /**
  20. * 创建或获取快捷链接
  21. */
  22. @NoSubmit
  23. @PostMapping("/create")
  24. public Result<GptQuickLinkResp> createQuickLink() {
  25. // 获取当前登录用户ID
  26. Long userId = StpUserUtil.getLoginIdAsLong();
  27. // 创建或获取快捷链接
  28. GptQuickLinkRecord quickLink = gptQuickLinkService.createQuickLink(userId);
  29. GptQuickLinkResp resp = new GptQuickLinkResp();
  30. resp.setCode(quickLink.getCode());
  31. resp.setExpiryTime(quickLink.getExpiryTime());
  32. return GatewayResponse.SUCCESS.newBuilder().toResult(resp);
  33. }
  34. /**
  35. * 获取最新的快捷链接
  36. */
  37. @GetMapping("/get")
  38. public Result<GptQuickLinkResp> getLatestQuickLink() {
  39. // 获取当前登录用户ID
  40. Long userId = StpUserUtil.getLoginIdAsLong();
  41. // 获取最新的快捷链接
  42. GptQuickLinkRecord quickLink = gptQuickLinkService.getLatestQuickLink(userId);
  43. if (quickLink == null) {
  44. return GatewayResponse.SUCCESS.newBuilder().toResult();
  45. }
  46. GptQuickLinkResp resp = new GptQuickLinkResp();
  47. resp.setCode(quickLink.getCode());
  48. resp.setExpiryTime(quickLink.getExpiryTime());
  49. return GatewayResponse.SUCCESS.newBuilder().toResult(resp);
  50. }
  51. /**
  52. * 通过快捷链接登录gpt镜像对话页
  53. */
  54. @GetMapping("/get/chatGpt/page/{code}")
  55. public Result<GptQuickLinkResp> getCharGptPageByCode(@PathVariable String code) {
  56. GptQuickLinkResp resp = gptQuickLinkService.getQuickUrlByCode(code.trim());
  57. return GatewayResponse.SUCCESS.newBuilder().toResult(resp);
  58. }
  59. }