|
@@ -13,6 +13,7 @@ import com.cyksj.model.views.ChatGptUserConversationRecordHistoryView;
|
|
|
import com.cyksj.model.views.MidjouneyCarInfoView;
|
|
import com.cyksj.model.views.MidjouneyCarInfoView;
|
|
|
import com.cyksj.model.views.MidjourneyUserConversationRecordHistoryView;
|
|
import com.cyksj.model.views.MidjourneyUserConversationRecordHistoryView;
|
|
|
import com.cyksj.model.views.MidjourneyUserView;
|
|
import com.cyksj.model.views.MidjourneyUserView;
|
|
|
|
|
+import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.service.midjourney.MidjourneyService;
|
|
import com.cyksj.service.midjourney.MidjourneyService;
|
|
|
import com.cyksj.service.user.UserBindRelationService;
|
|
import com.cyksj.service.user.UserBindRelationService;
|
|
|
import com.cyksj.web.util.StpUserUtil;
|
|
import com.cyksj.web.util.StpUserUtil;
|
|
@@ -28,6 +29,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
|
|
|
+import java.util.Comparator;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/** server/镜像服务/mj绘画
|
|
/** server/镜像服务/mj绘画
|
|
@@ -51,6 +53,8 @@ public class MidjourneyController {
|
|
|
|
|
|
|
|
private final UserBindRelationService userBindRelationService;
|
|
private final UserBindRelationService userBindRelationService;
|
|
|
|
|
|
|
|
|
|
+ private final RedisService redisService;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
//-------------------------alpha -----------------------
|
|
//-------------------------alpha -----------------------
|
|
|
|
|
|
|
@@ -61,7 +65,7 @@ public class MidjourneyController {
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
@GetMapping("/mj/cars")
|
|
@GetMapping("/mj/cars")
|
|
|
- public Result<SearchResult<MidjouneyCarInfoView>> getCarInfoList(Long relationId, @RequestParam(defaultValue = "true") Boolean isPlus) {
|
|
|
|
|
|
|
+ public Result<SearchResult<MidjouneyCarInfoView>> getCarInfoList(Long relationId,Boolean taskNumAsc) {
|
|
|
long userId = StpUserUtil.getLoginIdAsLong();
|
|
long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
//查看用户是否存在车票
|
|
//查看用户是否存在车票
|
|
|
MidjourneyUser midjourneyUser = midjourneyService.getUser(userId, relationId);
|
|
MidjourneyUser midjourneyUser = midjourneyService.getUser(userId, relationId);
|
|
@@ -69,10 +73,36 @@ public class MidjourneyController {
|
|
|
throw BusinessRuntimeException.getInstance("您还未购买车票");
|
|
throw BusinessRuntimeException.getInstance("您还未购买车票");
|
|
|
}
|
|
}
|
|
|
SearchResult<MidjouneyCarInfoView> carInfoList = beanSearcher.search(MidjouneyCarInfoView.class,MapUtils.flatBuilder(request.getParameterMap()).build());
|
|
SearchResult<MidjouneyCarInfoView> carInfoList = beanSearcher.search(MidjouneyCarInfoView.class,MapUtils.flatBuilder(request.getParameterMap()).build());
|
|
|
-
|
|
|
|
|
|
|
+ carInfoList.getDataList().forEach(midjouneyCarInfoView -> {
|
|
|
|
|
+ midjouneyCarInfoView.setTaskNum(getCarConversationCount(midjouneyCarInfoView.getCarId(), 5L));
|
|
|
|
|
+ });
|
|
|
|
|
+ if(taskNumAsc){
|
|
|
|
|
+ carInfoList.getDataList().sort(Comparator.comparing(MidjouneyCarInfoView::getTaskNum));
|
|
|
|
|
+ }else {
|
|
|
|
|
+ carInfoList.getDataList().sort(Comparator.comparing(MidjouneyCarInfoView::getTaskNum).reversed());
|
|
|
|
|
+ }
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(carInfoList);
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(carInfoList);
|
|
|
}
|
|
}
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取指定车队ID在滑动窗口内的提问次数
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param carId 车队ID
|
|
|
|
|
+ * @return 滑动窗口内的请求次数
|
|
|
|
|
+ */
|
|
|
|
|
+ private Long getCarConversationCount(String carId, Long limitTime) {
|
|
|
|
|
+ // 定义键名
|
|
|
|
|
+ String key = RedisService.key.MIDJOURNEY_CAR_TASK.getName() + carId;
|
|
|
|
|
+ long timestamp = System.currentTimeMillis();
|
|
|
|
|
+
|
|
|
|
|
+ long windowStartMillis = timestamp - (limitTime * 60 * 1000);
|
|
|
|
|
|
|
|
|
|
+ // 清除时间窗口之前的请求记录(可选,根据需要决定是否在此处清理过期记录)
|
|
|
|
|
+ redisService.zRemoveRangeByScore(key, 0, windowStartMillis);
|
|
|
|
|
+
|
|
|
|
|
+ // 获取当前窗口内的请求次数
|
|
|
|
|
+ Long currentSize = redisService.zCard(key);
|
|
|
|
|
+ return currentSize != null ? currentSize : 0L;
|
|
|
|
|
+ }
|
|
|
/**
|
|
/**
|
|
|
* 获取mj车票信息
|
|
* 获取mj车票信息
|
|
|
*/
|
|
*/
|