zoujiajian před 9 měsíci
rodič
revize
aa4bad1bf4

+ 1 - 1
netflix-dao/src/main/java/com/cyksj/model/response/GptQuickLinkResp.java

@@ -24,5 +24,5 @@ public class GptQuickLinkResp {
 
 	private String code;
 
-	private Date expriryTime;
+	private Date expiryTime;
 }

+ 12 - 17
netflix-service/src/main/java/com/cyksj/service/gpt/impl/GptQuickLinkServiceImpl.java

@@ -2,11 +2,11 @@ package com.cyksj.service.gpt.impl;
 
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
-import cn.hutool.core.util.RandomUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.constant.Constant;
 import com.cyksj.common.exception.BusinessRuntimeException;
+import com.cyksj.common.util.StringUtil;
 import com.cyksj.mapper.GptQuickLinkRecordMapper;
 import com.cyksj.mapper.GroupsRelationMapper;
 import com.cyksj.model.entity.GptQuickLinkRecord;
@@ -51,29 +51,21 @@ public class GptQuickLinkServiceImpl implements GptQuickLinkService {
         if (getValidGptTicket(userIdList).isEmpty()) {
             throw new BusinessRuntimeException("您没有有效的GPT镜像车票");
         }
-
-        // 检查是否存在未过期的快捷链接
-        Date now = DateTime.now();
-        LambdaQueryWrapper<GptQuickLinkRecord> wrapper = Wrappers.lambdaQuery(GptQuickLinkRecord.class)
-                .in(GptQuickLinkRecord::getUserId, userIdList)
-                .gt(GptQuickLinkRecord::getExpiryTime, now)
-                .last("limit 1")
-                .orderByDesc(GptQuickLinkRecord::getId);
-        
-        GptQuickLinkRecord existingLink = gptQuickLinkRecordMapper.selectOne(wrapper);
-        if (existingLink != null) {
-            log.info("用户 {} 已存在未过期的快捷链接: {}", userId, existingLink.getCode());
-            return existingLink;
-        }
         //生成标识
-        String code = RandomUtil.randomString(6).toLowerCase();;
+        String code = StringUtil.randomString(6);;
         GptQuickLinkRecord quickLink = new GptQuickLinkRecord();
         quickLink.setUserId(userId);
         quickLink.setCode(code);
         // 创建新的快捷链接,有效期30天
-        quickLink.setExpiryTime(DateUtil.offsetDay(now, 30));
+        quickLink.setExpiryTime(DateUtil.offsetDay(DateTime.now(), 30));
         try {
             gptQuickLinkRecordMapper.insert(quickLink);
+            //将之前的链接变成失效
+            gptQuickLinkRecordMapper.update(null, Wrappers.lambdaUpdate(GptQuickLinkRecord.class)
+                    .set(GptQuickLinkRecord::getExpiryTime, DateTime.now())
+                    .in(GptQuickLinkRecord::getUserId, userIdList)
+                    .ne(GptQuickLinkRecord::getCode, code)
+                    .gt(GptQuickLinkRecord::getExpiryTime, DateTime.now()));
         } catch (DuplicateKeyException e) {
             throw BusinessRuntimeException.getInstance("系统繁忙,请重新生成!");
         }
@@ -99,6 +91,9 @@ public class GptQuickLinkServiceImpl implements GptQuickLinkService {
                 .eq(GptQuickLinkRecord::getCode, code)
                 .last("limit 1");
         GptQuickLinkRecord gptQuickLinkRecord = gptQuickLinkRecordMapper.selectOne(wrapper);
+        if (gptQuickLinkRecord == null) {
+            throw BusinessRuntimeException.getInstance("快捷链接不存在");
+        }
         GptQuickLinkResp resp = new GptQuickLinkResp();
         //成功
         Integer state = 1;

+ 5 - 7
netflix-web/src/main/java/com/cyksj/web/controller/api/GptQuickLinkController.java

@@ -8,15 +8,13 @@ import com.cyksj.model.response.GptQuickLinkResp;
 import com.cyksj.service.gpt.GptQuickLinkService;
 import com.cyksj.web.util.StpUserUtil;
 import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.*;
 
 /**
  * GPT快捷链接API控制器
  */
-@Slf4j
 @RestController
-@RequestMapping("/gpt/quickLink")
+@RequestMapping("/applets/gpt/quickLink")
 @RequiredArgsConstructor
 public class GptQuickLinkController {
     
@@ -34,7 +32,7 @@ public class GptQuickLinkController {
         GptQuickLinkRecord quickLink = gptQuickLinkService.createQuickLink(userId);
         GptQuickLinkResp resp = new GptQuickLinkResp();
         resp.setCode(quickLink.getCode());
-        resp.setExpriryTime(quickLink.getExpiryTime());
+        resp.setExpiryTime(quickLink.getExpiryTime());
         return GatewayResponse.SUCCESS.newBuilder().toResult(resp);
     }
     
@@ -52,7 +50,7 @@ public class GptQuickLinkController {
         }
         GptQuickLinkResp resp = new GptQuickLinkResp();
         resp.setCode(quickLink.getCode());
-        resp.setExpriryTime(quickLink.getExpiryTime());
+        resp.setExpiryTime(quickLink.getExpiryTime());
         return GatewayResponse.SUCCESS.newBuilder().toResult(resp);
     }
 
@@ -61,7 +59,7 @@ public class GptQuickLinkController {
      */
     @GetMapping("/get/chatGpt/page/{code}")
     public Result<GptQuickLinkResp> getCharGptPageByCode(@PathVariable String code) {
-        GptQuickLinkResp quickUrlByCode = gptQuickLinkService.getQuickUrlByCode(code);
-        return GatewayResponse.SUCCESS.newBuilder().toResult(quickUrlByCode);
+        GptQuickLinkResp resp = gptQuickLinkService.getQuickUrlByCode(code.trim());
+        return GatewayResponse.SUCCESS.newBuilder().toResult(resp);
     }
 }