|
|
@@ -12,10 +12,16 @@ 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;
|
|
|
import com.cyksj.service.sys.SysConfigService;
|
|
|
import com.cyksj.service.user.UserBindRelationService;
|
|
|
+import com.ejlchina.searcher.BeanSearcher;
|
|
|
+import com.ejlchina.searcher.SearchResult;
|
|
|
+import com.ejlchina.searcher.util.MapBuilder;
|
|
|
+import com.ejlchina.searcher.util.MapUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.dao.DuplicateKeyException;
|
|
|
@@ -24,7 +30,9 @@ import org.springframework.stereotype.Service;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.Optional;
|
|
|
|
|
|
/**
|
|
|
@@ -50,6 +58,8 @@ public class GrokServiceImpl implements GrokService {
|
|
|
|
|
|
private final SysConfigService sysConfigService;
|
|
|
|
|
|
+ private final BeanSearcher beanSearcher;
|
|
|
+
|
|
|
@Override
|
|
|
public GrokUserView getUserInfo(long userId, Long relationId) {
|
|
|
GrokUser grokUser = checkCarAccount(userId, relationId);
|
|
|
@@ -59,11 +69,12 @@ public class GrokServiceImpl implements GrokService {
|
|
|
GroupsTrips groupsTrips = getGroupsTrips(groupsRelation);
|
|
|
GoodsDonSku goodsDonSku = skuMapper.selectById(groupsTrips.getSkuId());
|
|
|
|
|
|
- GrokUserView view =GrokUserView.builder()
|
|
|
+ GrokUserView view = GrokUserView.builder()
|
|
|
.skuName(goodsDonSku.getSubTitle())
|
|
|
.expireTime(grokUser.getExpireTime())
|
|
|
.limitNum(grokUser.getLimitNum())
|
|
|
.limitTime(grokUser.getLimitTime())
|
|
|
+ .userToken(grokUser.getUserToken())
|
|
|
|
|
|
//.use(Math.min(grokUser.getLimitNum(), getConversationCount(grokUser.getUserToken(),grokUser.getLimitTime())))
|
|
|
.build();
|
|
|
@@ -131,6 +142,62 @@ public class GrokServiceImpl implements GrokService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String getCarLoginUrl(String domain, Long userId, Long relationId, String carId) {
|
|
|
+ GroupsRelation groupsRelation = getGroupsRelation(userId, relationId);
|
|
|
+ GroupsTrips groupsTrips = getGroupsTrips(groupsRelation);
|
|
|
+ GoodsDonSku goodsDonSku = skuMapper.selectById(groupsTrips.getSkuId());
|
|
|
+ if (goodsDonSku != null && goodsDonSku.getIsMirror() && goodsDonSku.getIsCar()) {
|
|
|
+ GrokUser grokUser = getGrokUser(userId, relationId, groupsRelation, goodsDonSku);
|
|
|
+
|
|
|
+ String DOMAIN = domain;
|
|
|
+ if (StrUtil.isEmpty(DOMAIN)) {
|
|
|
+ DOMAIN = "https://groknode.goodwillus.org";
|
|
|
+ try {
|
|
|
+ SysConfig sysConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class).eq(SysConfig::getSysKey, "mirror_xy_grok_domain"));
|
|
|
+ if (sysConfig != null) {
|
|
|
+ String sysValue = sysConfig.getSysValue();
|
|
|
+ if (JSONUtil.isJsonArray(sysValue)) {
|
|
|
+ List<String> domainList = JSONUtil.parseArray(sysValue).toList(String.class);
|
|
|
+ DOMAIN = domainList.get(RandomUtil.randomInt(domainList.size()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("随机抽取域名错误. msg:{}", StringUtil.getErrorText(e));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("domain:{},用户:{},所在车次:{},座位id:{},车队id:{},在{}获取跳转Grok镜像车队的登录url", DOMAIN, userId, groupsTrips.getId(), relationId, carId, DateTime.now());
|
|
|
+ return DOMAIN + "/auth/login?userToken=" + grokUser.getUserToken() + "&carid=" + carId;
|
|
|
+ } else {
|
|
|
+ throw BusinessRuntimeException.getInstance("服务器出了点问题");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SearchResult<GrokCarInfoView> getCarInfoList(Map<String, String[]> parameterMap, Integer limit) {
|
|
|
+ Map<String, String[]> params = new HashMap<>(parameterMap);
|
|
|
+ if (params.containsKey("status")) {
|
|
|
+ params.put("csStatus", params.remove("status"));
|
|
|
+ }
|
|
|
+ MapBuilder builder = MapUtils.flatBuilder(params)
|
|
|
+ .orderBy(GrokCarInfoView::getSort).asc()
|
|
|
+ .orderBy(GrokCarInfoView::getScore).asc();
|
|
|
+ if (!params.containsKey("limit")) {
|
|
|
+ builder.limit(0, limit);
|
|
|
+ }
|
|
|
+ SearchResult<GrokCarInfoView> carInfoList = beanSearcher.search(GrokCarInfoView.class, builder.build());
|
|
|
+ carInfoList.getDataList().forEach(this::buildGrokCarInfoView);
|
|
|
+ return carInfoList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void buildGrokCarInfoView(GrokCarInfoView view) {
|
|
|
+ view.setCarName(view.getCarId());
|
|
|
+ view.setStatus("空闲");
|
|
|
+ Double score = Optional.ofNullable(view.getScore()).orElse(0D);
|
|
|
+ view.setStatus(score >= 100 ? "繁忙" : "空闲");
|
|
|
+ view.setScore(Math.min(BigDecimal.valueOf(score).multiply(BigDecimal.valueOf(0.5)).setScale(0, RoundingMode.DOWN).doubleValue(), 200));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取车位信息
|
|
|
*
|
|
|
@@ -138,6 +205,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));
|
|
|
@@ -205,7 +308,7 @@ public class GrokServiceImpl implements GrokService {
|
|
|
|
|
|
public JSONObject getConversationCount(String userToken) {
|
|
|
try {
|
|
|
- String res = HttpUtil.get("http://147.79.20.183:9611/grok/getConversationCount?userToken=" + userToken);
|
|
|
+ String res = HttpUtil.get("http://208.98.56.214:9611/grok/getConversationCount?userToken=" + userToken);
|
|
|
return new JSONObject(res);
|
|
|
}catch (Exception e){
|
|
|
return new JSONObject("{\"count\": 0}");
|