|
@@ -1,6 +1,7 @@
|
|
|
package com.cyksj.service.chatgpt.impl;
|
|
package com.cyksj.service.chatgpt.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.lang.UUID;
|
|
import cn.hutool.core.lang.UUID;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
import cn.hutool.http.HttpRequest;
|
|
|
import cn.hutool.http.HttpResponse;
|
|
import cn.hutool.http.HttpResponse;
|
|
@@ -89,6 +90,8 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
|
|
|
|
|
private final BeanSearcher beanSearcher;
|
|
private final BeanSearcher beanSearcher;
|
|
|
|
|
|
|
|
|
|
+ private final ChatgptUserTokenPrepareMapper chatgptUserTokenPrepareMapper;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public String addAccount(Account account) {
|
|
public String addAccount(Account account) {
|
|
|
if (isAccountExists(account)) {
|
|
if (isAccountExists(account)) {
|
|
@@ -211,8 +214,8 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
|
|
|
|
|
if (goodsDonSku != null && goodsDonSku.getIsMirror()) {
|
|
if (goodsDonSku != null && goodsDonSku.getIsMirror()) {
|
|
|
ChatgptUser chatgptUser = getChatgptUser(userId, relationId, groupsRelation, groupsTrips, goodsDonSku);
|
|
ChatgptUser chatgptUser = getChatgptUser(userId, relationId, groupsRelation, groupsTrips, goodsDonSku);
|
|
|
- if(214610L == relationId){
|
|
|
|
|
- return "https://cdn.galaxydvd.com/login_token?access_token=" + chatgptUser.getUserToken();
|
|
|
|
|
|
|
+ if (214610L == relationId) {
|
|
|
|
|
+ return "https://cdn.galaxydvd.com/login_token?access_token=" + chatgptUser.getUserToken();
|
|
|
}
|
|
}
|
|
|
return GPT_DOMAIN + "/login_token?access_token=" + chatgptUser.getUserToken();
|
|
return GPT_DOMAIN + "/login_token?access_token=" + chatgptUser.getUserToken();
|
|
|
} else {
|
|
} else {
|
|
@@ -239,6 +242,18 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
throw BusinessRuntimeException.getInstance("服务器出了点问题");
|
|
throw BusinessRuntimeException.getInstance("服务器出了点问题");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据userToken获取车队登录url
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public String getCarLoginUrlWithToken(String userToken, String carId) {
|
|
|
|
|
+ ChatgptUser chatgptUser = getCarChatGptUserWithToken(userToken);
|
|
|
|
|
+ if (chatgptUser != null) {
|
|
|
|
|
+ return CAR_GPT_DOMAIN + "/auth/logintoken?carid=" + carId + "&usertoken=" + chatgptUser.getUserToken();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("服务出了点问题");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取车位信息
|
|
* 获取车位信息
|
|
@@ -337,6 +352,36 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
return chatgptUser;
|
|
return chatgptUser;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 创建chatgptUser 无需车队
|
|
|
|
|
+ */
|
|
|
|
|
+ public ChatgptUser generateChatGptUserUnderPrepare(ChatgptUserTokenPrepare prepare) {
|
|
|
|
|
+ ChatgptUser chatgptUser = new ChatgptUser();
|
|
|
|
|
+ GoodsDonSku goodsDonSku = skuMapper.selectById(prepare.getSkuId());
|
|
|
|
|
+ if (goodsDonSku == null) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("车队规格不存在,请联系客服..");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (goodsDonSku.getIsCar()) {
|
|
|
|
|
+ chatgptUser.setIsCar(true);
|
|
|
|
|
+ chatgptUser.setLimitNum(goodsDonSku.getGptLimitNum());
|
|
|
|
|
+ chatgptUser.setLimitTime(goodsDonSku.getGptLimitTime());
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ chatgptUser.setExpireTime(DateUtil.offsetMonth(DateTime.now(), goodsDonSku.getMonths()));
|
|
|
|
|
+ chatgptUser.setIsPlus(1);
|
|
|
|
|
+ chatgptUser.setName(prepare.getName());
|
|
|
|
|
+ chatgptUser.setImg(prepare.getImg());
|
|
|
|
|
+ chatgptUser.setUserToken(prepare.getUserToken());
|
|
|
|
|
+ chatgptUserMapper.insert(chatgptUser);
|
|
|
|
|
+
|
|
|
|
|
+ prepare.setStatus(true);
|
|
|
|
|
+ chatgptUserTokenPrepareMapper.updateById(prepare);
|
|
|
|
|
+ log.info("用户激活userToken:{}成功", prepare.getUserToken());
|
|
|
|
|
+ } catch (DuplicateKeyException e) {
|
|
|
|
|
+ }
|
|
|
|
|
+ return chatgptUser;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private void updateChatgptUser(GroupsRelation groupsRelation, User user, ChatgptUser chatgptUser) {
|
|
private void updateChatgptUser(GroupsRelation groupsRelation, User user, ChatgptUser chatgptUser) {
|
|
|
chatgptUser.setName(user.getNickname());
|
|
chatgptUser.setName(user.getNickname());
|
|
|
chatgptUser.setImg(getWxImg(user.getHeadimgurl(), user));
|
|
chatgptUser.setImg(getWxImg(user.getHeadimgurl(), user));
|
|
@@ -377,9 +422,9 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
public void saveConversationRecord(String userToken, ConversationRequest conversationRequest) {
|
|
public void saveConversationRecord(String userToken, ConversationRequest conversationRequest) {
|
|
|
LambdaQueryWrapper<ChatgptSession> wrapper = Wrappers.lambdaQuery(ChatgptSession.class);
|
|
LambdaQueryWrapper<ChatgptSession> wrapper = Wrappers.lambdaQuery(ChatgptSession.class);
|
|
|
|
|
|
|
|
- if(StringUtils.isNotBlank(conversationRequest.getCarId())){
|
|
|
|
|
|
|
+ if (StringUtils.isNotBlank(conversationRequest.getCarId())) {
|
|
|
wrapper.eq(ChatgptSession::getCarId, conversationRequest.getCarId());
|
|
wrapper.eq(ChatgptSession::getCarId, conversationRequest.getCarId());
|
|
|
- }else {
|
|
|
|
|
|
|
+ } else {
|
|
|
ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class).eq(ChatgptUser::getUserToken, userToken));
|
|
ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class).eq(ChatgptUser::getUserToken, userToken));
|
|
|
if (chatgptUser.getSessionId() != null) {
|
|
if (chatgptUser.getSessionId() != null) {
|
|
|
wrapper.eq(ChatgptSession::getId, chatgptUser.getSessionId());
|
|
wrapper.eq(ChatgptSession::getId, chatgptUser.getSessionId());
|
|
@@ -399,7 +444,7 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
chatgptUserConversationRecord.setModel(conversationRequest.getModel());
|
|
chatgptUserConversationRecord.setModel(conversationRequest.getModel());
|
|
|
chatgptUserConversationRecordMapper.insert(chatgptUserConversationRecord);
|
|
chatgptUserConversationRecordMapper.insert(chatgptUserConversationRecord);
|
|
|
|
|
|
|
|
- if(StringUtils.isNotBlank(chatgptSession.getCarId())){
|
|
|
|
|
|
|
+ if (StringUtils.isNotBlank(chatgptSession.getCarId())) {
|
|
|
updateExperienceAndScore(chatgptSession.getCarId(), !"text-davinci-002-render-sha".equals(conversationRequest.getModel()), System.currentTimeMillis());
|
|
updateExperienceAndScore(chatgptSession.getCarId(), !"text-davinci-002-render-sha".equals(conversationRequest.getModel()), System.currentTimeMillis());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -458,7 +503,6 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取指定用户ID在滑动窗口内的提问次数
|
|
* 获取指定用户ID在滑动窗口内的提问次数
|
|
|
*
|
|
*
|
|
@@ -532,6 +576,15 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Boolean checkCarAccountWithToken(String userToken) {
|
|
|
|
|
+
|
|
|
|
|
+ ChatgptUser chatgptUser = getCarChatGptUserWithToken(userToken);
|
|
|
|
|
+
|
|
|
|
|
+ return chatgptUser != null;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public ChatgptUser getCarChatGptUser(long userId, Long relationId) {
|
|
public ChatgptUser getCarChatGptUser(long userId, Long relationId) {
|
|
|
GroupsRelation groupsRelation = getGroupsRelation(userId, relationId);
|
|
GroupsRelation groupsRelation = getGroupsRelation(userId, relationId);
|
|
@@ -539,7 +592,29 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
GoodsDonSku goodsDonSku = skuMapper.selectById(groupsTrips.getSkuId());
|
|
GoodsDonSku goodsDonSku = skuMapper.selectById(groupsTrips.getSkuId());
|
|
|
|
|
|
|
|
if (goodsDonSku != null && goodsDonSku.getIsMirror() && goodsDonSku.getIsCar()) {
|
|
if (goodsDonSku != null && goodsDonSku.getIsMirror() && goodsDonSku.getIsCar()) {
|
|
|
- ChatgptUser chatgptUser = getChatgptCarUser(userId, relationId, groupsRelation, goodsDonSku);
|
|
|
|
|
|
|
+ return getChatgptCarUser(userId, relationId, groupsRelation, goodsDonSku);
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public ChatgptUser getCarChatGptUserWithToken(String userToken) {
|
|
|
|
|
+ ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class).eq(ChatgptUser::getUserToken, userToken).last(" limit 1"));
|
|
|
|
|
+ if (chatgptUser == null) {
|
|
|
|
|
+ //是否是用户token预备账号
|
|
|
|
|
+ ChatgptUserTokenPrepare chatgptUserTokenPrepare = chatgptUserTokenPrepareMapper.selectOne(Wrappers.lambdaQuery(ChatgptUserTokenPrepare.class)
|
|
|
|
|
+ .eq(ChatgptUserTokenPrepare::getUserToken, userToken).last("limit 1"));
|
|
|
|
|
+ if (chatgptUserTokenPrepare != null) {
|
|
|
|
|
+ chatgptUser = generateChatGptUserUnderPrepare(chatgptUserTokenPrepare);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (chatgptUser != null) {
|
|
|
|
|
+ if(!chatgptUser.getIsCar()){
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("您非车队用户,请购买车队套餐");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (chatgptUser.getRelationId() != null) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("非渠道用户,请通过官网登录!");
|
|
|
|
|
+ }
|
|
|
return chatgptUser;
|
|
return chatgptUser;
|
|
|
}
|
|
}
|
|
|
return null;
|
|
return null;
|
|
@@ -621,9 +696,9 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
} else {
|
|
} else {
|
|
|
initFleets(false);
|
|
initFleets(false);
|
|
|
}
|
|
}
|
|
|
- lowestScorecarIds = redisService.zRangeWithScores(RedisService.key.CHATGPT_CAR_SCORES.getName(), 0L, 20 - 1);
|
|
|
|
|
|
|
+ lowestScorecarIds = redisService.zRangeWithScores(RedisService.key.CHATGPT_CAR_SCORES.getName(), 0L, count - 1);
|
|
|
Map<Object, Double> collect = lowestScorecarIds.stream().collect(Collectors.toMap(ZSetOperations.TypedTuple::getValue, ZSetOperations.TypedTuple::getScore));
|
|
Map<Object, Double> collect = lowestScorecarIds.stream().collect(Collectors.toMap(ZSetOperations.TypedTuple::getValue, ZSetOperations.TypedTuple::getScore));
|
|
|
- List<ChatgptSession> chatgptSessions = chatgptSessionMapper.selectList(Wrappers.lambdaQuery(ChatgptSession.class).eq(ChatgptSession::getIsPlus,1).in(ChatgptSession::getCarId, collect.keySet()));
|
|
|
|
|
|
|
+ List<ChatgptSession> chatgptSessions = chatgptSessionMapper.selectList(Wrappers.lambdaQuery(ChatgptSession.class).in(ChatgptSession::getCarId, collect.keySet()));
|
|
|
return chatgptSessions.stream().map((chatgptSession)-> buildChatgptCarInfoView(chatgptSession.getCarId(),chatgptSession.getCarName(), chatgptSession.getIsPlus(), collect.get(chatgptSession.getCarId())))
|
|
return chatgptSessions.stream().map((chatgptSession)-> buildChatgptCarInfoView(chatgptSession.getCarId(),chatgptSession.getCarName(), chatgptSession.getIsPlus(), collect.get(chatgptSession.getCarId())))
|
|
|
.sorted(Comparator.comparing(ChatgptCarInfoView::getScore)).collect(Collectors.toCollection(LinkedHashSet::new));
|
|
.sorted(Comparator.comparing(ChatgptCarInfoView::getScore)).collect(Collectors.toCollection(LinkedHashSet::new));
|
|
|
}
|
|
}
|
|
@@ -653,7 +728,7 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
ChatgptCarInfoView view = new ChatgptCarInfoView();
|
|
ChatgptCarInfoView view = new ChatgptCarInfoView();
|
|
|
view.setCarId(carId);
|
|
view.setCarId(carId);
|
|
|
// 假设以下方法从Redis或其他服务获取数据
|
|
// 假设以下方法从Redis或其他服务获取数据
|
|
|
- view.setScore(Math.min(score,100));
|
|
|
|
|
|
|
+ view.setScore(Math.min(score, 100));
|
|
|
view.setStatus(score >= 50 ? "繁忙" : "空闲"); // 或“繁忙”
|
|
view.setStatus(score >= 50 ? "繁忙" : "空闲"); // 或“繁忙”
|
|
|
|
|
|
|
|
view.setType(isPlus == 1 ? "plus" : "3.5");
|
|
view.setType(isPlus == 1 ? "plus" : "3.5");
|
|
@@ -687,6 +762,21 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
throw BusinessRuntimeException.getInstance("您还未购买该车票");
|
|
throw BusinessRuntimeException.getInstance("您还未购买该车票");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public ChatGptUserView getUserInfoWithToken(String userToken) {
|
|
|
|
|
+ if (checkCarAccountWithToken(userToken)) {
|
|
|
|
|
+ ChatgptUser chatgptUser = getCarChatGptUserWithToken(userToken);
|
|
|
|
|
+ return ChatGptUserView.builder()
|
|
|
|
|
+ .skuName("")
|
|
|
|
|
+ .expireTime(chatgptUser.getExpireTime())
|
|
|
|
|
+ .limitNum(chatgptUser.getLimitNum())
|
|
|
|
|
+ .limitTime(chatgptUser.getLimitTime())
|
|
|
|
|
+ .use(getConversationCount(chatgptUser.getUserToken(), chatgptUser.getLimitTime()))
|
|
|
|
|
+ .build();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("您还未购买该车票");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void genTitleSync(String conversationId, String carid, String userToken) {
|
|
public void genTitleSync(String conversationId, String carid, String userToken) {
|
|
@@ -705,12 +795,12 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void carLimited(String carId, String userToken, Long expTime) {
|
|
public void carLimited(String carId, String userToken, Long expTime) {
|
|
|
- if(carId == null){
|
|
|
|
|
|
|
+ if (carId == null) {
|
|
|
if (StringUtils.isNotBlank(userToken)) {
|
|
if (StringUtils.isNotBlank(userToken)) {
|
|
|
ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class).eq(ChatgptUser::getUserToken, userToken));
|
|
ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class).eq(ChatgptUser::getUserToken, userToken));
|
|
|
if (chatgptUser != null && chatgptUser.getSessionId() != null) {
|
|
if (chatgptUser != null && chatgptUser.getSessionId() != null) {
|
|
|
ChatgptSession chatgptSession = chatgptSessionMapper.selectById(chatgptUser.getSessionId());
|
|
ChatgptSession chatgptSession = chatgptSessionMapper.selectById(chatgptUser.getSessionId());
|
|
|
- if(chatgptSession != null){
|
|
|
|
|
|
|
+ if (chatgptSession != null) {
|
|
|
carId = chatgptSession.getCarId();
|
|
carId = chatgptSession.getCarId();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|