ChatGptAccountServiceImpl.java 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  1. package com.cyksj.service.chatgpt.impl;
  2. import cn.hutool.core.date.DateTime;
  3. import cn.hutool.core.date.DateUnit;
  4. import cn.hutool.core.date.DateUtil;
  5. import cn.hutool.core.lang.UUID;
  6. import cn.hutool.core.util.RandomUtil;
  7. import cn.hutool.http.HttpRequest;
  8. import cn.hutool.http.HttpResponse;
  9. import cn.hutool.http.HttpUtil;
  10. import cn.hutool.http.Method;
  11. import cn.hutool.json.JSONObject;
  12. import cn.hutool.json.JSONUtil;
  13. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  14. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  15. import com.cyksj.common.constant.Constant;
  16. import com.cyksj.common.exception.BusinessRuntimeException;
  17. import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
  18. import com.cyksj.common.util.Jsons;
  19. import com.cyksj.common.util.StringUtil;
  20. import com.cyksj.mapper.*;
  21. import com.cyksj.mapper.station.CollegeStudentStationUseTicketRecordMapper;
  22. import com.cyksj.model.entity.*;
  23. import com.cyksj.model.request.gpt.ConversationRequest;
  24. import com.cyksj.model.response.ConversationLimitResponse;
  25. import com.cyksj.model.views.ChatGptUserConversationRecordHistoryView;
  26. import com.cyksj.model.views.ChatGptUserView;
  27. import com.cyksj.model.views.ChatgptCarInfoView;
  28. import com.cyksj.redis.RedisService;
  29. import com.cyksj.service.chatgpt.ChatGptAccountService;
  30. import com.cyksj.service.sys.SysConfigService;
  31. import com.cyksj.service.user.UserBindRelationService;
  32. import com.ejlchina.searcher.BeanSearcher;
  33. import com.ejlchina.searcher.SearchResult;
  34. import com.ejlchina.searcher.util.MapUtils;
  35. import lombok.RequiredArgsConstructor;
  36. import lombok.extern.slf4j.Slf4j;
  37. import org.apache.commons.lang3.StringUtils;
  38. import org.springframework.beans.factory.annotation.Value;
  39. import org.springframework.dao.DuplicateKeyException;
  40. import org.springframework.data.redis.core.ZSetOperations;
  41. import org.springframework.stereotype.Service;
  42. import javax.annotation.PostConstruct;
  43. import javax.imageio.stream.FileImageOutputStream;
  44. import java.math.BigDecimal;
  45. import java.nio.file.Files;
  46. import java.nio.file.Path;
  47. import java.time.LocalDateTime;
  48. import java.util.*;
  49. import java.util.stream.Collectors;
  50. /**
  51. * @author chan
  52. * @date 2024/3/19 11:01
  53. */
  54. @Service
  55. @Slf4j
  56. @RequiredArgsConstructor
  57. public class ChatGptAccountServiceImpl implements ChatGptAccountService {
  58. @Value("${chatgpt.domain}")
  59. private String GPT_DOMAIN;
  60. @Value("${chatgpt.car.domain}")
  61. private String CAR_GPT_DOMAIN;
  62. private static final String GPT_PROXY = "https://chat-chan-87jztgkf257d.xyhelper.net";
  63. private static final int MAX_REQUESTS = 40; // 3小时内最大请求次数
  64. private static final long WINDOW_SIZE = 3 * 60 * 60; // 3小时窗口的秒数
  65. private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
  66. private final RedisService redisService;
  67. private final ChatgptUserMapper chatgptUserMapper;
  68. private final ChatgptSessionMapper chatgptSessionMapper;
  69. private final GroupsRelationMapper groupsRelationMapper;
  70. private final GroupsMapper groupsMapper;
  71. private final GoodsDonSkuMapper skuMapper;
  72. private final UserMapper userMapper;
  73. private final UserBindRelationService userBindRelationService;
  74. private final ChatgptUserConversationRecordMapper chatgptUserConversationRecordMapper;
  75. private final ChatgptUserConversationMapper chatgptUserConversationMapper;
  76. private final AccountMapper accountMapper;
  77. private final BeanSearcher beanSearcher;
  78. private final ChatgptUserTokenPrepareMapper chatgptUserTokenPrepareMapper;
  79. private final ChatgptUserCarUsedRecordMapper chatgptUserCarUsedRecordMapper;
  80. private final CollegeStudentStationUseTicketRecordMapper collegeStudentStationUseTicketRecordMapper;
  81. private final UpgradePackageMapper upgradePackageMapper;
  82. private final OrderDonMapper orderDonMapper;
  83. private final SysConfigService sysConfigService;
  84. @Override
  85. public String addAccount(Account account) {
  86. if (isAccountExists(account)) {
  87. throw BusinessRuntimeException.getInstance("镜像服务该账号已存在.");
  88. }
  89. String refreshToken = "";
  90. String officialSession = "";
  91. try {
  92. JSONObject loginResult = getLoginResult(account);
  93. if (StringUtils.isBlank(loginResult.getStr("accessToken"))) {
  94. throw BusinessRuntimeException.getInstance(loginResult.getStr("detail"));
  95. }
  96. refreshToken = loginResult.getStr("refresh_token");
  97. officialSession = loginResult.toString();
  98. } catch (Exception e) {
  99. throw BusinessRuntimeException.getInstance("登录获取token错误 error:" + e.getMessage());
  100. }
  101. createChatgptSession(account, officialSession);
  102. return refreshToken;
  103. }
  104. @Override
  105. public String getGptSession(String account, String password) {
  106. String officialSession = "";
  107. try {
  108. Account at = new Account();
  109. at.setAccount(account);
  110. at.setPassword(password);
  111. JSONObject loginResult = getLoginResult(at);
  112. if (StringUtils.isBlank(loginResult.getStr("accessToken"))) {
  113. throw BusinessRuntimeException.getInstance(loginResult.getStr("detail"));
  114. }
  115. officialSession = loginResult.toString();
  116. } catch (Exception e) {
  117. throw BusinessRuntimeException.getInstance("登录获取token错误 error:" + e.getMessage());
  118. }
  119. return officialSession;
  120. }
  121. /**
  122. * 判断账号是否存在
  123. *
  124. * @param account 账号
  125. * @return 是否存在
  126. */
  127. private boolean isAccountExists(Account account) {
  128. Integer count = chatgptSessionMapper.selectCount(Wrappers.lambdaQuery(ChatgptSession.class).eq(ChatgptSession::getEmail, account.getAccount()));
  129. return count > 0;
  130. }
  131. /**
  132. * 获取登录结果
  133. *
  134. * @param account
  135. * @return
  136. * @throws Exception
  137. */
  138. private JSONObject getLoginResult(Account account) throws Exception {
  139. HttpRequest request = new HttpRequest(GPT_PROXY + "/getsession");
  140. request.form("username", account.getAccount());
  141. request.form("password", account.getPassword());
  142. request.header("Content-Type", "application/x-www-form-urlencoded");
  143. HttpResponse execute = request.method(Method.POST).execute();
  144. return new JSONObject(execute.body());
  145. }
  146. /**
  147. * 创建chatgptSession
  148. *
  149. * @param account
  150. * @param officialSession
  151. */
  152. private void createChatgptSession(Account account, String officialSession) {
  153. ChatgptSession chatgptSession = new ChatgptSession();
  154. chatgptSession.setOfficialSession(officialSession);
  155. chatgptSession.setEmail(account.getAccount());
  156. chatgptSession.setPassword(account.getPassword());
  157. chatgptSession.setIsPlus(1);
  158. chatgptSession.setAccountId(account.getId());
  159. chatgptSession.setStatus(1);
  160. chatgptSessionMapper.insert(chatgptSession);
  161. }
  162. /**
  163. * 更新账号
  164. *
  165. * @param account
  166. */
  167. @Override
  168. public void upAccount(Account account) {
  169. ChatgptSession chatgptSession = chatgptSessionMapper.selectOne(Wrappers.lambdaQuery(ChatgptSession.class).eq(ChatgptSession::getEmail, account.getAccount()));
  170. if (chatgptSession != null) {
  171. if (StringUtils.isNotBlank(account.getGptRefreshToken())) {
  172. chatgptSession.setOfficialSession(account.getGptRefreshToken());
  173. }
  174. chatgptSession.setEmail(account.getAccount());
  175. chatgptSession.setPassword(account.getPassword());
  176. chatgptSession.setIsPlus(1);
  177. chatgptSession.setAccountId(account.getId());
  178. chatgptSession.setStatus(1);
  179. chatgptSessionMapper.updateById(chatgptSession);
  180. }
  181. }
  182. /**
  183. * 获取登录url
  184. *
  185. * @param userId
  186. * @param relationId
  187. * @return
  188. */
  189. @Override
  190. public String getLoginUrl(Long userId, Long relationId) {
  191. GroupsRelation groupsRelation = getGroupsRelation(userId, relationId);
  192. GroupsTrips groupsTrips = getGroupsTrips(groupsRelation);
  193. GoodsDonSku goodsDonSku = skuMapper.selectById(groupsTrips.getSkuId());
  194. log.info("用户:{},所在车次:{},座位id:{},在{}获取跳转GPT镜像的登录url", userId, groupsTrips.getId(), relationId, DateTime.now());
  195. if (goodsDonSku != null && goodsDonSku.getIsMirror()) {
  196. ChatgptUser chatgptUser = getChatgptUser(userId, relationId, groupsRelation, groupsTrips, goodsDonSku);
  197. if (214610L == relationId) {
  198. return "https://cdn.galaxydvd.com/login_token?access_token=" + chatgptUser.getUserToken();
  199. }
  200. return GPT_DOMAIN + "/login_token?access_token=" + chatgptUser.getUserToken();
  201. } else {
  202. throw BusinessRuntimeException.getInstance("服务器出了点问题");
  203. }
  204. }
  205. /**
  206. * 获取车队登录url
  207. *
  208. * @param userId
  209. * @param carId
  210. * @return
  211. */
  212. @Override
  213. public String getCarLoginUrl(Long userId, Long relationId, String carId) {
  214. GroupsRelation groupsRelation = getGroupsRelation(userId, relationId);
  215. GroupsTrips groupsTrips = getGroupsTrips(groupsRelation);
  216. GoodsDonSku goodsDonSku = skuMapper.selectById(groupsTrips.getSkuId());
  217. if (goodsDonSku != null && goodsDonSku.getIsMirror() && goodsDonSku.getIsCar()) {
  218. ChatgptUser chatgptUser = getChatgptCarUser(userId, relationId, groupsRelation, goodsDonSku);
  219. String DOMAIN = "https://chat.galaxydvd.com";
  220. if(goodsDonSku.getId() == 444){
  221. DOMAIN = "https://car.galaxydvd.com";
  222. }else {
  223. try {
  224. SysConfig sysConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class).eq(SysConfig::getSysKey, "mirror_gpt_domain"));
  225. if (sysConfig != null) {
  226. String sysValue = sysConfig.getSysValue();
  227. if (JSONUtil.isJsonArray(sysValue)) {
  228. List<String> domainList = JSONUtil.parseArray(sysValue).toList(String.class);
  229. DOMAIN = domainList.get(RandomUtil.randomInt(domainList.size()));
  230. }
  231. }
  232. }catch (Exception e){
  233. log.error("随机抽取域名错误. msg:{}", StringUtil.getErrorText(e));
  234. }
  235. }
  236. log.info("domain:{},用户:{},所在车次:{},座位id:{},在{}获取跳转GPT镜像的登录url", DOMAIN, userId, groupsTrips.getId(), relationId, DateTime.now());
  237. return DOMAIN + "/auth/logintoken?carid=" + carId + "&usertoken=" + chatgptUser.getUserToken();
  238. } else {
  239. throw BusinessRuntimeException.getInstance("服务器出了点问题");
  240. }
  241. }
  242. /**
  243. * 根据userToken获取车队登录url
  244. */
  245. @Override
  246. public String getCarLoginUrlWithToken(String userToken, String carId) {
  247. ChatgptUser chatgptUser = getCarChatGptUserWithToken(userToken);
  248. if (chatgptUser != null) {
  249. String DOMAIN = "https://chat.galaxydvd.com";
  250. log.info("domain:{},渠道用户:{},在{}获取跳转GPT镜像的登录url", DOMAIN, userToken, DateTime.now());
  251. return DOMAIN + "/auth/logintoken?carid=" + carId + "&usertoken=" + chatgptUser.getUserToken();
  252. } else {
  253. throw BusinessRuntimeException.getInstance("服务出了点问题");
  254. }
  255. }
  256. /**
  257. * 获取车位信息
  258. *
  259. * @param userId
  260. * @param relationId
  261. * @return
  262. */
  263. private GroupsRelation getGroupsRelation(Long userId, Long relationId) {
  264. List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
  265. GroupsRelation groupsRelation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class).in(GroupsRelation::getUserId, userIdList).eq(GroupsRelation::getId, relationId));
  266. if (groupsRelation == null) {
  267. throw BusinessRuntimeException.getInstance("车票不存在");
  268. }
  269. return groupsRelation;
  270. }
  271. /**
  272. * 获取车队信息
  273. *
  274. * @param groupsRelation
  275. * @return
  276. */
  277. private GroupsTrips getGroupsTrips(GroupsRelation groupsRelation) {
  278. GroupsTrips groupsTrips = groupsMapper.selectById(groupsRelation.getGroupsId());
  279. if (groupsTrips == null) {
  280. throw BusinessRuntimeException.getInstance("车队异常");
  281. }
  282. return groupsTrips;
  283. }
  284. private ChatgptUser getChatgptUser(Long userId, Long relationId, GroupsRelation groupsRelation, GroupsTrips groupsTrips, GoodsDonSku goodsDonSku) {
  285. ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class).eq(ChatgptUser::getRelationId, relationId));
  286. User user = userMapper.selectById(userId);
  287. if (chatgptUser == null) {
  288. chatgptUser = createChatgptUser(groupsRelation, groupsTrips, user, goodsDonSku);
  289. } else {
  290. updateChatgptUser(groupsRelation, user, chatgptUser);
  291. }
  292. return chatgptUser;
  293. }
  294. private ChatgptUser getChatgptCarUser(Long userId, Long relationId, GroupsRelation groupsRelation, GoodsDonSku goodsDonSku) {
  295. ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class).eq(ChatgptUser::getRelationId, relationId));
  296. User user = userMapper.selectById(userId);
  297. if (chatgptUser == null) {
  298. chatgptUser = createChatgptUser(groupsRelation, null, user, goodsDonSku);
  299. } else {
  300. updateChatgptUser(groupsRelation, user, chatgptUser);
  301. }
  302. return chatgptUser;
  303. }
  304. /**
  305. * 创建chatgptUser
  306. */
  307. private synchronized ChatgptUser createChatgptUser(GroupsRelation groupsRelation, GroupsTrips groupsTrips, User user, GoodsDonSku goodsDonSku) {
  308. ChatgptUser chatgptUser = new ChatgptUser();
  309. if (!goodsDonSku.getIsCar()) {
  310. ChatgptSession chatgptSession = chatgptSessionMapper.selectOne(Wrappers.lambdaQuery(ChatgptSession.class).eq(ChatgptSession::getAccountId, groupsTrips.getAccountId()));
  311. if (chatgptSession == null) {
  312. Account account = accountMapper.selectById(groupsTrips.getAccountId());
  313. String officialSession = "";
  314. try {
  315. JSONObject loginResult = getLoginResult(account);
  316. if (StringUtils.isBlank(loginResult.getStr("accessToken"))) {
  317. throw BusinessRuntimeException.getInstance(loginResult.getStr("detail"));
  318. }
  319. officialSession = loginResult.toString();
  320. } catch (Exception e) {
  321. throw BusinessRuntimeException.getInstance("配置账号错误 msg: " + e.getMessage());
  322. }
  323. createChatgptSession(account, officialSession);
  324. chatgptSession = chatgptSessionMapper.selectOne(Wrappers.lambdaQuery(ChatgptSession.class).eq(ChatgptSession::getAccountId, groupsTrips.getAccountId()));
  325. }
  326. chatgptUser.setSessionId(chatgptSession.getId());
  327. }
  328. if (goodsDonSku.getIsCar()) {
  329. chatgptUser.setIsCar(true);
  330. chatgptUser.setLimitNum(goodsDonSku.getGptLimitNum());
  331. chatgptUser.setLimitTime(goodsDonSku.getGptLimitTime());
  332. }
  333. try {
  334. chatgptUser.setExpireTime(groupsRelation.getExpiryTime());
  335. chatgptUser.setIsPlus(1);
  336. chatgptUser.setName(user.getNickname());
  337. chatgptUser.setImg(getWxImg(user.getHeadimgurl(), user));
  338. chatgptUser.setRelationId(groupsRelation.getId());
  339. chatgptUser.setUserToken(UUID.randomUUID().toString());
  340. chatgptUserMapper.insert(chatgptUser);
  341. //是否是大学生限时车队
  342. Date expiryTime = groupsRelation.getExpiryTime();
  343. Date startTime = groupsRelation.getStartTime();
  344. //大学生站 1天免费试用
  345. if (DateUtil.between(startTime, expiryTime, DateUnit.DAY) <= 1) {
  346. CollegeStudentStationUseTicketRecord useTicketRecord = new CollegeStudentStationUseTicketRecord();
  347. useTicketRecord.setUserId(user.getId());
  348. useTicketRecord.setUserToken(chatgptUser.getUserToken());
  349. collegeStudentStationUseTicketRecordMapper.insert(useTicketRecord);
  350. }
  351. } catch (DuplicateKeyException e) {
  352. log.error("重复插入镜像用户:{}token,errmsg:{}", user.getNickname(), StringUtil.getErrorText(e));
  353. }
  354. return chatgptUser;
  355. }
  356. /**
  357. * 创建chatgptUser 无需车队
  358. */
  359. public ChatgptUser generateChatGptUserUnderPrepare(ChatgptUserTokenPrepare prepare) {
  360. ChatgptUser chatgptUser = new ChatgptUser();
  361. GoodsDonSku goodsDonSku = skuMapper.selectById(prepare.getSkuId());
  362. if (goodsDonSku == null) {
  363. throw BusinessRuntimeException.getInstance("车队规格不存在,请联系客服..");
  364. }
  365. if (goodsDonSku.getIsCar()) {
  366. chatgptUser.setIsCar(true);
  367. chatgptUser.setLimitNum(goodsDonSku.getGptLimitNum());
  368. chatgptUser.setLimitTime(goodsDonSku.getGptLimitTime());
  369. }
  370. try {
  371. chatgptUser.setExpireTime(DateUtil.offsetMonth(DateTime.now(), goodsDonSku.getMonths()));
  372. chatgptUser.setIsPlus(1);
  373. chatgptUser.setName(prepare.getName());
  374. chatgptUser.setImg(prepare.getImg());
  375. chatgptUser.setUserToken(prepare.getUserToken());
  376. chatgptUserMapper.insert(chatgptUser);
  377. prepare.setStatus(true);
  378. chatgptUserTokenPrepareMapper.updateById(prepare);
  379. log.info("用户激活userToken:{}成功", prepare.getUserToken());
  380. } catch (DuplicateKeyException e) {
  381. log.error("重复插入镜像车队用户:{}token,errmsg:{}" + chatgptUser.getId(), StringUtil.getErrorText(e));
  382. }
  383. return chatgptUser;
  384. }
  385. private void updateChatgptUser(GroupsRelation groupsRelation, User user, ChatgptUser chatgptUser) {
  386. chatgptUser.setName(user.getNickname());
  387. chatgptUser.setImg(getWxImg(user.getHeadimgurl(), user));
  388. chatgptUser.setExpireTime(groupsRelation.getExpiryTime());
  389. chatgptUserMapper.updateById(chatgptUser);
  390. }
  391. /**
  392. * 更换wx头像至oss
  393. */
  394. private String getWxImg(String headimgurl, User user) {
  395. if (headimgurl.contains("thirdwx.qlogo.cn")) {
  396. try {
  397. byte[] body = HttpUtil.downloadBytes(headimgurl);
  398. Path tempFile = Files.createTempFile("wxheadimg-" + user.getId(), ".jpeg");
  399. try (FileImageOutputStream imageOutput = new FileImageOutputStream(tempFile.toFile())) {
  400. imageOutput.write(body, 0, body.length);
  401. }
  402. Map<String, Object> paramMap = new HashMap<>();
  403. paramMap.put("file", tempFile.toFile());
  404. JSONObject result = JSONUtil.parseObj(HttpUtil.post("https://files.liuliangbang.vip/pic/ups", paramMap));
  405. return result.getJSONObject("value").getJSONArray("saved").getJSONObject(0).getJSONObject("info").getStr("cdnUrl");
  406. } catch (Exception ex) {
  407. log.error("上传微信头像错误!msg:{}", StringUtil.getErrorText(ex));
  408. return "./avatars.png";
  409. }
  410. } else {
  411. return user.getHeadimgurl();
  412. }
  413. }
  414. @Override
  415. public ChatgptUser findByUserTokenAndExpireTimeAfter(String userToken, LocalDateTime now) {
  416. return chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class).eq(ChatgptUser::getUserToken, userToken).gt(ChatgptUser::getExpireTime, now));
  417. }
  418. @Override
  419. public void saveConversationRecord(String userToken, ConversationRequest conversationRequest) {
  420. LambdaQueryWrapper<ChatgptSession> wrapper = Wrappers.lambdaQuery(ChatgptSession.class);
  421. ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class).eq(ChatgptUser::getUserToken, userToken));
  422. if (StringUtils.isNotBlank(conversationRequest.getCarId())) {
  423. wrapper.eq(ChatgptSession::getCarId, conversationRequest.getCarId());
  424. } else {
  425. if (chatgptUser.getSessionId() != null) {
  426. wrapper.eq(ChatgptSession::getId, chatgptUser.getSessionId());
  427. }
  428. }
  429. ChatgptSession chatgptSession = chatgptSessionMapper.selectOne(wrapper);
  430. ChatgptUserConversationRecord chatgptUserConversationRecord = new ChatgptUserConversationRecord();
  431. chatgptUserConversationRecord.setUserToken(userToken);
  432. chatgptUserConversationRecord.setCarId(chatgptSession.getCarId());
  433. chatgptUserConversationRecord.setCarName(chatgptSession.getCarName());
  434. if (StringUtils.isNotBlank(conversationRequest.getConversation_id())) {
  435. chatgptUserConversationRecord.setConversationId(conversationRequest.getConversation_id());
  436. }
  437. chatgptUserConversationRecord.setModel(conversationRequest.getModel());
  438. chatgptUserConversationRecordMapper.insert(chatgptUserConversationRecord);
  439. if(!"text-davinci-002-render-sha".equals(conversationRequest.getModel())){
  440. String key = RedisService.key.CHATGPT_CONVERSATION_LIMIT.getName() + ":" + userToken;
  441. long currentTimeMillis = System.currentTimeMillis();
  442. redisService.del();
  443. if(redisService.hasKey("chatgpt:team:clears_in:" + chatgptSession.getCarId())){
  444. redisService.del("chatgpt:team:clears_in:" + chatgptSession.getCarId());
  445. }
  446. if (redisService.hasKey("chatgpt:clears_in:" + chatgptSession.getCarId())) {
  447. redisService.del("chatgpt:clears_in:" + chatgptSession.getCarId());
  448. }
  449. // 如果未超过限制,记录当前请求的时间戳
  450. redisService.zAdd(key, currentTimeMillis, currentTimeMillis);
  451. // 设置ZSet的过期时间,窗口大小加上一段冗余时间
  452. redisService.expire(key, (chatgptUser.getLimitTime() * 60 * 60) + 20);
  453. }
  454. if (StringUtils.isNotBlank(chatgptSession.getCarId())) {
  455. updateExperienceAndScore(chatgptSession.getCarId(), !"text-davinci-002-render-sha".equals(conversationRequest.getModel()), System.currentTimeMillis());
  456. }
  457. }
  458. @Override
  459. public ConversationLimitResponse conversationLimit(String userToken, String model, String carId, ChatgptUser chatgptUser, Boolean isCar) {
  460. ConversationLimitResponse conversationLimitResponse = new ConversationLimitResponse();
  461. conversationLimitResponse.setLimited(false);
  462. if (!"text-davinci-002-render-sha".equals(model)) {
  463. //如果不为车队 直接返回
  464. if (chatgptUser.getIsCar()) {
  465. conversationLimitResponse = isConversationAllowed(userToken, chatgptUser.getLimitNum(), chatgptUser.getLimitTime());
  466. }
  467. }
  468. return conversationLimitResponse;
  469. }
  470. /**
  471. * 检查是否允许进行进行提问
  472. *
  473. * @param userToken 用户token
  474. * @return true 如果允许请求,false 如果请求被限制
  475. */
  476. public ConversationLimitResponse isConversationAllowed(String userToken, int limit, Long limitTime) {
  477. String key = RedisService.key.CHATGPT_CONVERSATION_LIMIT.getName() + ":" + userToken;
  478. long currentTimeMillis = System.currentTimeMillis();
  479. long windowStartMillis = currentTimeMillis - (limitTime * 60 * 60) * 1000;
  480. ConversationLimitResponse conversationLimitResponse = new ConversationLimitResponse();
  481. // 清除时间窗口之前的请求记录
  482. redisService.zRemoveRangeByScore(key, 0, windowStartMillis);
  483. Long currentSize = redisService.zCard(key);
  484. if (currentSize != null && currentSize >= limit) {
  485. // 如果当前请求次数超过限制,则拒绝请求
  486. Set<Object> times = redisService.zRangeByScore(key, 0, currentTimeMillis, 0, 1);
  487. Long oldestTime = (Long) times.stream().findFirst().orElse(null);
  488. if (oldestTime != null) {
  489. // 下一次可用时间是最早请求时间之后的3小时
  490. long nextAvailableTime = oldestTime + (limitTime * 60 * 60 * 1000);
  491. conversationLimitResponse.setNextAvailableTime(nextAvailableTime);
  492. }
  493. conversationLimitResponse.setLimited(true);
  494. //用户次数使用限制
  495. ChatgptUserCarUsedRecord chatgptUserCarUsedRecord = new ChatgptUserCarUsedRecord();
  496. chatgptUserCarUsedRecord.setUserToken(userToken);
  497. chatgptUserCarUsedRecord.setIsUserLimit(true);
  498. chatgptUserCarUsedRecordMapper.insert(chatgptUserCarUsedRecord);
  499. return conversationLimitResponse;
  500. } else {
  501. conversationLimitResponse.setLimited(false);
  502. return conversationLimitResponse;
  503. }
  504. }
  505. /**
  506. * 获取指定用户ID在滑动窗口内的提问次数
  507. *
  508. * @param userToken 用户token
  509. * @return 滑动窗口内的请求次数
  510. */
  511. @Override
  512. public Long getConversationCount(String userToken, Long limitTime) {
  513. String key = RedisService.key.CHATGPT_CONVERSATION_LIMIT.getName() + ":" + userToken;
  514. long currentTimeMillis = System.currentTimeMillis();
  515. long windowStartMillis = currentTimeMillis - (limitTime * 60 * 60) * 1000;
  516. // 清除时间窗口之前的请求记录(可选,根据需要决定是否在此处清理过期记录)
  517. redisService.zRemoveRangeByScore(key, 0, windowStartMillis);
  518. // 获取当前窗口内的请求次数
  519. Long currentSize = redisService.zCard(key);
  520. return currentSize != null ? currentSize : 0L;
  521. }
  522. /**
  523. * 获取指定车队ID在滑动窗口内的提问次数
  524. *
  525. * @param carId 车队ID
  526. * @return 滑动窗口内的请求次数
  527. */
  528. private Long getCarConversationCount(String carId, Long limitTime) {
  529. // 定义键名
  530. String key = RedisService.key.CHATGPT_CAR_HIGH_CHAT.getName() + carId;
  531. long timestamp = System.currentTimeMillis();
  532. long windowStartMillis = timestamp - (limitTime * 60 * 60 * 1000);
  533. // 清除时间窗口之前的请求记录(可选,根据需要决定是否在此处清理过期记录)
  534. redisService.zRemoveRangeByScore(key, 0, windowStartMillis);
  535. // 获取当前窗口内的请求次数
  536. Long currentSize = redisService.zCard(key);
  537. return currentSize != null ? currentSize : 0L;
  538. }
  539. @Override
  540. public ChatgptSession checkSession(String carId) {
  541. ChatgptSession chatgptSession = chatgptSessionMapper.selectOne(Wrappers.lambdaQuery(ChatgptSession.class).eq(ChatgptSession::getCarId, carId).eq(ChatgptSession::getIsCar, true).last(" limit 1"));
  542. if (chatgptSession == null) {
  543. throw BusinessRuntimeException.getInstance("车队不存在");
  544. }
  545. return chatgptSession;
  546. }
  547. private Long carOaiLimit(String carId, Boolean isTeam) {
  548. if(isTeam && redisService.hasKey("chatgpt:team:clears_in:" + carId)){
  549. return redisService.getExpire("chatgpt:team:clears_in:" + carId);
  550. }
  551. if (redisService.hasKey("chatgpt:clears_in:" + carId)) {
  552. return redisService.getExpire("chatgpt:clears_in:" + carId);
  553. }
  554. return 0L;
  555. }
  556. @Override
  557. public Boolean checkCarAccount(long userId, Long relationId) {
  558. GroupsRelation groupsRelation = getGroupsRelation(userId, relationId);
  559. GroupsTrips groupsTrips = getGroupsTrips(groupsRelation);
  560. GoodsDonSku goodsDonSku = skuMapper.selectById(groupsTrips.getSkuId());
  561. if (goodsDonSku != null && goodsDonSku.getGoodsId() == 18 && goodsDonSku.getIsMirror() && goodsDonSku.getIsCar()) {
  562. ChatgptUser chatgptUser = getChatgptCarUser(userId, relationId, groupsRelation, goodsDonSku);
  563. return true;
  564. } else {
  565. return false;
  566. }
  567. }
  568. @Override
  569. public Boolean checkCarAccountWithToken(String userToken) {
  570. ChatgptUser chatgptUser = getCarChatGptUserWithToken(userToken);
  571. return chatgptUser != null;
  572. }
  573. @Override
  574. public ChatgptUser getCarChatGptUser(long userId, Long relationId) {
  575. GroupsRelation groupsRelation = getGroupsRelation(userId, relationId);
  576. GroupsTrips groupsTrips = getGroupsTrips(groupsRelation);
  577. GoodsDonSku goodsDonSku = skuMapper.selectById(groupsTrips.getSkuId());
  578. if (goodsDonSku != null && goodsDonSku.getIsMirror() && goodsDonSku.getIsCar()) {
  579. return getChatgptCarUser(userId, relationId, groupsRelation, goodsDonSku);
  580. }
  581. return null;
  582. }
  583. @Override
  584. public ChatgptUser getCarChatGptUserWithToken(String userToken) {
  585. ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class).eq(ChatgptUser::getUserToken, userToken).last(" limit 1"));
  586. if (chatgptUser == null) {
  587. //是否是用户token预备账号
  588. ChatgptUserTokenPrepare chatgptUserTokenPrepare = chatgptUserTokenPrepareMapper.selectOne(Wrappers.lambdaQuery(ChatgptUserTokenPrepare.class)
  589. .eq(ChatgptUserTokenPrepare::getUserToken, userToken).last("limit 1"));
  590. if (chatgptUserTokenPrepare != null) {
  591. chatgptUser = generateChatGptUserUnderPrepare(chatgptUserTokenPrepare);
  592. }
  593. }
  594. if (chatgptUser != null) {
  595. if(!chatgptUser.getIsCar()){
  596. throw BusinessRuntimeException.getInstance("您非车队用户,请购买车队套餐");
  597. }
  598. if (chatgptUser.getRelationId() != null) {
  599. throw BusinessRuntimeException.getInstance("非渠道用户,请通过官网登录!");
  600. }
  601. return chatgptUser;
  602. }
  603. return null;
  604. }
  605. /**
  606. * 获取车队信息
  607. */
  608. @Override
  609. public List<ChatgptCarInfoView> getCarInfoList(String userToken, Integer limit, Boolean isPlus) {
  610. List<ChatgptCarInfoView> lowestScoreFleets = getLowestScoreFleets(limit, isPlus);
  611. return lowestScoreFleets;
  612. }
  613. // 更新体验并计算评分
  614. public void updateExperienceAndScore(String carId, boolean isHighLevel, long timestamp) {
  615. // 定义键名
  616. String key = isHighLevel ? RedisService.key.CHATGPT_CAR_HIGH_CHAT.getName() + carId : RedisService.key.CHATGPT_CAR_LOW_CHAT.getName() + carId;
  617. double scoreToAdd = isHighLevel ? 2.0 : 1.0; // 分数更新规则
  618. // 更新体验数据
  619. redisService.zAdd(key, timestamp, String.valueOf(timestamp));
  620. // 清理旧数据(可选)和重新计算评分(根据需要实现)
  621. cleanupOldExperiencesAndRecalculateScore(carId, timestamp);
  622. }
  623. // 清理旧数据和重新计算评分
  624. public void cleanupOldExperiencesAndRecalculateScore(String carId, long currentTimestamp) {
  625. long threeHoursAgo = currentTimestamp - (3 * 60 * 60 * 1000); // 3小时前的时间戳
  626. // 清理高级体验旧数据
  627. redisService.zRemoveRangeByScore(RedisService.key.CHATGPT_CAR_HIGH_CHAT.getName() + carId, 0, threeHoursAgo);
  628. // 清理低级体验旧数据
  629. redisService.zRemoveRangeByScore(RedisService.key.CHATGPT_CAR_LOW_CHAT.getName() + carId, 0, threeHoursAgo);
  630. // 重新计算评分
  631. recalculateScore(carId, currentTimestamp);
  632. }
  633. // 重新计算指定车队的评分
  634. private void recalculateScore(String carId, long currentTimestamp) {
  635. // 实际应用中,你需要根据高级体验和低级体验的数量重新计算得分
  636. Double highExperienceScore = (double) redisService.zCount(RedisService.key.CHATGPT_CAR_HIGH_CHAT.getName() + carId, currentTimestamp - (3 * 60 * 60 * 1000), currentTimestamp) * 2;
  637. Double lowExperienceScore = (double) redisService.zCount(RedisService.key.CHATGPT_CAR_LOW_CHAT.getName() + carId, currentTimestamp - (3 * 60 * 60 * 1000), currentTimestamp);
  638. double newScore = highExperienceScore + lowExperienceScore;
  639. if(carId.contains("T")){
  640. newScore = BigDecimal.valueOf(newScore).divide(BigDecimal.valueOf(5), 2, BigDecimal.ROUND_HALF_UP).doubleValue();
  641. }
  642. redisService.zAdd(RedisService.key.CHATGPT_CAR_SCORES.getName(), newScore, carId);
  643. }
  644. // 获取得分最低的N个车队的方法
  645. public List<ChatgptCarInfoView> getLowestScoreFleets(int count, Boolean isPlus) {
  646. List<ChatgptCarInfoView> chatgptCarInfoViews = beanSearcher.searchList(ChatgptCarInfoView.class, MapUtils.builder().field(ChatgptCarInfoView::getIsPlus, isPlus).orderBy(ChatgptCarInfoView::getScore).asc().limit(0, count).build());
  647. chatgptCarInfoViews.forEach(this::buildChatgptCarInfoView);
  648. return chatgptCarInfoViews;
  649. }
  650. public void initFleets(Boolean flag) {
  651. LambdaQueryWrapper<ChatgptSession> wrapper = Wrappers.lambdaQuery(ChatgptSession.class);
  652. if (flag) {
  653. Set<ZSetOperations.TypedTuple<Object>> fleets = redisService.zRangeWithScores(RedisService.key.CHATGPT_CAR_SCORES.getName(), 0L, -1);
  654. List<Object> collect = fleets.stream().map(ZSetOperations.TypedTuple::getValue).collect(Collectors.toList());
  655. wrapper.notIn(collect.size() > 0, ChatgptSession::getCarId, collect);
  656. }
  657. //如果存在未存在redis中的车辆则同步进 chatgpt:car:scores
  658. List<ChatgptSession> chatgptSessions = chatgptSessionMapper.selectList(wrapper.eq(ChatgptSession::getIsCar, true));
  659. chatgptSessions.forEach((chatgptSession) -> {
  660. if (!redisService.checkValueExistsInZSet(RedisService.key.CHATGPT_CAR_SCORES.getName(), chatgptSession.getCarId())) {
  661. redisService.zAdd(RedisService.key.CHATGPT_CAR_SCORES.getName(), 0, chatgptSession.getCarId());
  662. }
  663. });
  664. }
  665. // 构建ChatgptCarInfoView对象
  666. private ChatgptCarInfoView buildChatgptCarInfoView(ChatgptCarInfoView view) {
  667. // 在这里根据carId获取相关信息并填充到ChatgptCarInfoView对象中
  668. view.setStatus(view.getScore() >= 50 ? "繁忙" : "空闲"); // 或“繁忙”
  669. if(view.getCarName().contains("T") && view.getIsPlus() == 1){
  670. view.setType("Team");
  671. Long team = carOaiLimit(view.getCarId(), true);
  672. if (team != 0L) {
  673. view.setTeamExpTime(new DateTime(System.currentTimeMillis() + team * 1000));
  674. }
  675. Long aLong = carOaiLimit(view.getCarId(), false);
  676. if (aLong != 0L) {
  677. view.setExpTime(new DateTime(System.currentTimeMillis() + aLong * 1000));
  678. }
  679. if (view.getExpTime() != null && view.getTeamExpTime() != null) {
  680. view.setStatus("全部停运");
  681. }else if(view.getExpTime() != null || view.getTeamExpTime() != null) {
  682. view.setStatus("部分停运");
  683. }
  684. }else {
  685. view.setType(view.getIsPlus() == 1 ? "Plus" : "3.5");
  686. Long aLong = carOaiLimit(view.getCarId(), false);
  687. if (aLong != 0L) {
  688. view.setStatus("停运");
  689. view.setExpTime(new DateTime(System.currentTimeMillis() + aLong * 1000));
  690. }
  691. }
  692. int use = getCarConversationCount(view.getCarId(), 3L).intValue();
  693. view.setUse(use);
  694. view.setScore(Math.min(view.getScore(), 200));
  695. return view;
  696. }
  697. @Override
  698. public ChatGptUserView getUserInfo(long userId, Long relationId) {
  699. if (checkCarAccount(userId, relationId)) {
  700. GroupsRelation groupsRelation = getGroupsRelation(userId, relationId);
  701. GroupsTrips groupsTrips = getGroupsTrips(groupsRelation);
  702. GoodsDonSku goodsDonSku = skuMapper.selectById(groupsTrips.getSkuId());
  703. ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class).eq(ChatgptUser::getRelationId, relationId));
  704. Integer count = upgradePackageMapper.selectCount(Wrappers.lambdaQuery(UpgradePackage.class).apply("JSON_CONTAINS(sku_ids,'\"" + groupsTrips.getSkuId() + "\"')")
  705. .gt(UpgradePackage::getNum, chatgptUser.getLimitNum())
  706. .eq(UpgradePackage::getStatus, Boolean.TRUE)
  707. .eq(UpgradePackage::getGptType, 0)
  708. .eq(UpgradePackage::getDeleted, Boolean.TRUE));
  709. Boolean upgrade = count > 0 ? true : false;
  710. OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
  711. .eq(OrderDon::getRelationId, relationId)
  712. .eq(OrderDon::getUserId, groupsRelation.getUserId())
  713. .notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
  714. .orderByDesc(OrderDon::getId)
  715. .last("limit 1"));
  716. Long orderId = null;
  717. if (orderDon != null) {
  718. orderId = orderDon.getId();
  719. }
  720. BigDecimal packagePrice = null;
  721. if (chatgptUser.getPackageId() != 0) {
  722. UpgradePackage upgradePackage = upgradePackageMapper.selectById(chatgptUser.getPackageId());
  723. packagePrice = upgradePackage.getPrice();
  724. }
  725. return ChatGptUserView.builder()
  726. .skuName(goodsDonSku.getSubTitle())
  727. .expireTime(chatgptUser.getExpireTime())
  728. .limitNum(chatgptUser.getLimitNum())
  729. .limitTime(chatgptUser.getLimitTime())
  730. .upgrade(upgrade)
  731. .orderId(orderId)
  732. .goodsId(goodsDonSku.getGoodsId())
  733. .skuId(goodsDonSku.getId())
  734. .months(goodsDonSku.getMonths())
  735. .use(Math.min(chatgptUser.getLimitNum(), getConversationCount(chatgptUser.getUserToken(), chatgptUser.getLimitTime())))
  736. .packageId(chatgptUser.getPackageId())
  737. .packagePrice(packagePrice)
  738. .build();
  739. } else {
  740. throw BusinessRuntimeException.getInstance("您还未购买该车票");
  741. }
  742. }
  743. @Override
  744. public ChatGptUserView getUserInfoWithToken(String userToken) {
  745. if (checkCarAccountWithToken(userToken)) {
  746. ChatgptUser chatgptUser = getCarChatGptUserWithToken(userToken);
  747. return ChatGptUserView.builder()
  748. .skuName("")
  749. .expireTime(chatgptUser.getExpireTime())
  750. .limitNum(chatgptUser.getLimitNum())
  751. .limitTime(chatgptUser.getLimitTime())
  752. .use(getConversationCount(chatgptUser.getUserToken(), chatgptUser.getLimitTime()))
  753. .build();
  754. } else {
  755. throw BusinessRuntimeException.getInstance("您还未购买该车票");
  756. }
  757. }
  758. @Override
  759. public void genTitleSync(String conversationId, String carid, String userToken) {
  760. //同步对话
  761. if (!StringUtils.isAnyBlank(conversationId, carid, userToken)) {
  762. ChatgptUserConversationRecord chatgptUserConversationRecord = chatgptUserConversationRecordMapper.selectOne(Wrappers.lambdaQuery(ChatgptUserConversationRecord.class)
  763. .isNull(ChatgptUserConversationRecord::getConversationId)
  764. .eq(ChatgptUserConversationRecord::getCarId, carid)
  765. .eq(ChatgptUserConversationRecord::getUserToken, userToken)
  766. .orderByDesc(ChatgptUserConversationRecord::getId)
  767. .last(" limit 1"));
  768. if (chatgptUserConversationRecord != null) {
  769. chatgptUserConversationRecord.setConversationId(conversationId);
  770. chatgptUserConversationRecordMapper.updateById(chatgptUserConversationRecord);
  771. }
  772. }
  773. }
  774. @Override
  775. public void carLimited(String carId, String userToken, Long expTime, Boolean isTeam) {
  776. if (carId == null) {
  777. if (StringUtils.isNotBlank(userToken)) {
  778. ChatgptUser chatgptUser = chatgptUserMapper.selectOne(Wrappers.lambdaQuery(ChatgptUser.class).eq(ChatgptUser::getUserToken, userToken));
  779. if (chatgptUser != null && chatgptUser.getSessionId() != null) {
  780. ChatgptSession chatgptSession = chatgptSessionMapper.selectById(chatgptUser.getSessionId());
  781. if (chatgptSession != null) {
  782. carId = chatgptSession.getCarId();
  783. }
  784. }
  785. }
  786. }
  787. if(isTeam){
  788. redisService.set("chatgpt:team:clears_in:" + carId, expTime, expTime);
  789. }else {
  790. redisService.set("chatgpt:clears_in:" + carId, expTime, expTime);
  791. }
  792. try {
  793. //记录用户触发限制
  794. ChatgptUserCarUsedRecord chatgptUserCarUsedRecord = new ChatgptUserCarUsedRecord();
  795. chatgptUserCarUsedRecord.setUserToken(userToken);
  796. chatgptUserCarUsedRecord.setCarId(carId);
  797. String highCarChatKey = RedisService.key.CHATGPT_CAR_HIGH_CHAT.getName() + carId;
  798. String lowCarChatKey = RedisService.key.CHATGPT_CAR_LOW_CHAT.getName() + carId;
  799. Long highCarChatNum = redisService.zCard(highCarChatKey);
  800. if (highCarChatNum != null) {
  801. chatgptUserCarUsedRecord.setGptFour(Integer.parseInt(highCarChatNum.toString()));
  802. }
  803. Long lowCarChatNum = redisService.zCard(lowCarChatKey);
  804. if (lowCarChatNum != null) {
  805. chatgptUserCarUsedRecord.setGpt(Integer.parseInt(lowCarChatNum.toString()));
  806. }
  807. chatgptUserCarUsedRecordMapper.insert(chatgptUserCarUsedRecord);
  808. log.info("记录userToken:{}访问对应镜像车队carId:{}操作成功", userToken, carId);
  809. } catch (Exception e) {
  810. log.info("记录userToken:{}访问对应镜像车队carId:{}操作失败e:{}", userToken, carId, StringUtil.getErrorText(e));
  811. }
  812. }
  813. @PostConstruct
  814. public void init() {
  815. //如果存在未存在redis中的车辆则同步进 chatgpt:car:scores
  816. TASK_EXECUTOR.execute(() -> {
  817. Set<ZSetOperations.TypedTuple<Object>> lowestScorecarIds = redisService.zRangeWithScores(RedisService.key.CHATGPT_CAR_SCORES.getName(), 0L, -1);
  818. List<Object> collect = lowestScorecarIds.stream().map(ZSetOperations.TypedTuple::getValue).collect(Collectors.toList());
  819. List<ChatgptSession> chatgptSessions = chatgptSessionMapper.selectList(Wrappers.lambdaQuery(ChatgptSession.class).notIn(collect.size() > 0, ChatgptSession::getCarId, collect).eq(ChatgptSession::getIsPlus, 1).eq(ChatgptSession::getIsCar, true));
  820. chatgptSessions.forEach((chatgptSession) -> {
  821. if (!redisService.checkValueExistsInZSet(RedisService.key.CHATGPT_CAR_SCORES.getName(), chatgptSession.getCarId())) {
  822. redisService.zAdd(RedisService.key.CHATGPT_CAR_SCORES.getName(), 0, chatgptSession.getCarId());
  823. }
  824. });
  825. });
  826. }
  827. }