|
|
@@ -12,6 +12,7 @@ import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.common.util.StringUtil;
|
|
|
import com.cyksj.mapper.*;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
+import com.cyksj.model.response.GrokConversationCountResponse;
|
|
|
import com.cyksj.model.views.GrokCarInfoView;
|
|
|
import com.cyksj.model.views.GrokUserView;
|
|
|
import com.cyksj.service.grok.GrokService;
|
|
|
@@ -172,6 +173,42 @@ public class GrokServiceImpl implements GrokService {
|
|
|
* @param relationId
|
|
|
* @return
|
|
|
*/
|
|
|
+ @Override
|
|
|
+ public GrokConversationCountResponse getConversationCountDetail(String userToken) {
|
|
|
+ GrokUser grokUser = grokUserMapper.selectOne(Wrappers.lambdaQuery(GrokUser.class)
|
|
|
+ .eq(GrokUser::getUserToken, userToken)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (grokUser == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("用户不存在或已过期");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ JSONObject json = getConversationCount(userToken);
|
|
|
+ if (json.containsKey("message")) {
|
|
|
+ throw BusinessRuntimeException.getInstance(json.getStr("message"));
|
|
|
+ }
|
|
|
+
|
|
|
+ Long count = Optional.ofNullable(json.getLong("count")).orElse(0L);
|
|
|
+ Integer limit = Optional.ofNullable(json.getInt("limit")).orElse(grokUser.getLimitNum());
|
|
|
+ Long time = Optional.ofNullable(json.getLong("time")).orElse(grokUser.getLimitTime());
|
|
|
+ Boolean isVip = Optional.ofNullable(json.getBool("isVip")).orElse(Boolean.TRUE.equals(grokUser.getIsVip()));
|
|
|
+ Long remaining = Optional.ofNullable(json.getLong("remaining"))
|
|
|
+ .orElse(limit == null ? 0L : Math.max(0L, limit - count));
|
|
|
+
|
|
|
+ GrokConversationCountResponse response = new GrokConversationCountResponse();
|
|
|
+ response.setCount(count);
|
|
|
+ response.setLimit(limit);
|
|
|
+ response.setRemaining(remaining);
|
|
|
+ response.setTime(time);
|
|
|
+ response.setIsVip(isVip);
|
|
|
+ return response;
|
|
|
+ } catch (BusinessRuntimeException e) {
|
|
|
+ throw e;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("调用Grok getConversationCount接口失败: {}", StringUtil.getErrorText(e));
|
|
|
+ throw BusinessRuntimeException.getInstance("获取对话次数失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private GroupsRelation getGroupsRelation(Long userId, Long relationId) {
|
|
|
List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
GroupsRelation groupsRelation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class).in(GroupsRelation::getUserId, userIdList).eq(GroupsRelation::getId, relationId));
|