package com.cyksj.web.controller.api; import com.cyksj.common.annotation.NoSubmit; import com.cyksj.dto.Result; import com.cyksj.enums.GatewayResponse; import com.cyksj.model.entity.GptQuickLinkRecord; import com.cyksj.model.response.GptQuickLinkResp; import com.cyksj.service.gpt.GptQuickLinkService; import com.cyksj.web.util.StpUserUtil; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; /** * GPT快捷链接API控制器 */ @RestController @RequestMapping("/applets/gpt/quickLink") @RequiredArgsConstructor public class GptQuickLinkController { private final GptQuickLinkService gptQuickLinkService; /** * 创建或获取快捷链接 */ @NoSubmit @PostMapping("/create") public Result createQuickLink() { // 获取当前登录用户ID Long userId = StpUserUtil.getLoginIdAsLong(); // 创建或获取快捷链接 GptQuickLinkRecord quickLink = gptQuickLinkService.createQuickLink(userId); GptQuickLinkResp resp = new GptQuickLinkResp(); resp.setCode(quickLink.getCode()); resp.setExpiryTime(quickLink.getExpiryTime()); return GatewayResponse.SUCCESS.newBuilder().toResult(resp); } /** * 获取最新的快捷链接 */ @GetMapping("/get") public Result getLatestQuickLink() { // 获取当前登录用户ID Long userId = StpUserUtil.getLoginIdAsLong(); // 获取最新的快捷链接 GptQuickLinkRecord quickLink = gptQuickLinkService.getLatestQuickLink(userId); if (quickLink == null) { return GatewayResponse.SUCCESS.newBuilder().toResult(); } GptQuickLinkResp resp = new GptQuickLinkResp(); resp.setCode(quickLink.getCode()); resp.setExpiryTime(quickLink.getExpiryTime()); return GatewayResponse.SUCCESS.newBuilder().toResult(resp); } /** * 通过快捷链接登录gpt镜像对话页 */ @GetMapping("/get/chatGpt/page/{code}") public Result getCharGptPageByCode(@PathVariable String code) { GptQuickLinkResp resp = gptQuickLinkService.getQuickUrlByCode(code.trim()); return GatewayResponse.SUCCESS.newBuilder().toResult(resp); } }