|
|
@@ -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;
|