Răsfoiți Sursa

fix gpt车队分页

zoujiajian 2 ani în urmă
părinte
comite
fcf16e99c2

+ 3 - 1
netflix-service/src/main/java/com/cyksj/service/chatgpt/ChatGptAccountService.java

@@ -7,10 +7,10 @@ import com.cyksj.model.request.gpt.ConversationRequest;
 import com.cyksj.model.response.ConversationLimitResponse;
 import com.cyksj.model.views.ChatGptUserView;
 import com.cyksj.model.views.ChatgptCarInfoView;
+import com.ejlchina.searcher.SearchResult;
 
 import java.time.LocalDateTime;
 import java.util.List;
-import java.util.Set;
 
 /**
  * @author chan
@@ -58,6 +58,8 @@ public interface ChatGptAccountService {
 
     ChatgptUser getCarChatGptUserWithToken(String userToken);
 
+    SearchResult<ChatgptCarInfoView> getCarInfoPage(String userToken, Integer limit, Boolean isPlus);
+
     List<ChatgptCarInfoView> getCarInfoList(String userToken, Integer limit, Boolean isPlus);
 
     ChatGptUserView getUserInfo(long userId, Long relationId);

+ 15 - 0
netflix-service/src/main/java/com/cyksj/service/chatgpt/impl/ChatGptAccountServiceImpl.java

@@ -29,6 +29,7 @@ import com.cyksj.service.chatgpt.ChatGptAccountService;
 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.MapUtils;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -40,6 +41,7 @@ import org.springframework.stereotype.Service;
 
 import javax.annotation.PostConstruct;
 import javax.imageio.stream.FileImageOutputStream;
+import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
 import java.nio.file.Files;
 import java.nio.file.Path;
@@ -108,6 +110,8 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
 
     private final SysConfigService sysConfigService;
 
+    private final HttpServletRequest request;
+
     @Override
     public String addAccount(Account account) {
         if (isAccountExists(account)) {
@@ -687,6 +691,17 @@ public class ChatGptAccountServiceImpl implements ChatGptAccountService {
         return null;
     }
 
+    /**
+     * 获取车队分页信息
+     */
+    @Override
+    public SearchResult<ChatgptCarInfoView> getCarInfoPage(String userToken, Integer limit, Boolean isPlus) {
+        SearchResult<ChatgptCarInfoView> chatgptCarInfoViews = beanSearcher.search(ChatgptCarInfoView.class, MapUtils.flatBuilder(request.getParameterMap()).field(ChatgptCarInfoView::getIsPlus, isPlus).orderBy(ChatgptCarInfoView::getScore).asc().build());
+
+        chatgptCarInfoViews.getDataList().forEach(this::buildChatgptCarInfoView);
+        return chatgptCarInfoViews;
+    }
+
     /**
      * 获取车队信息
      */

+ 3 - 3
netflix-web/src/main/java/com/cyksj/web/controller/mirror/MirrorController.java

@@ -249,15 +249,15 @@ public class MirrorController {
      * @return
      */
     @GetMapping("/gpt/cars")
-    public Result<List<ChatgptCarInfoView>> getCarInfoList(Long relationId,@RequestParam(defaultValue = "20") Integer limit,@RequestParam(defaultValue = "true") Boolean isPlus) {
+    public Result<SearchResult<ChatgptCarInfoView>> getCarInfoList(Long relationId,@RequestParam(defaultValue = "20") Integer limit,@RequestParam(defaultValue = "true") Boolean isPlus) {
         long userId = StpUserUtil.getLoginIdAsLong();
         //查看用户是否存在车票
         ChatgptUser carChatGptUser = chatGptAccountService.getCarChatGptUser(userId, relationId);
         if (carChatGptUser == null) {
             throw BusinessRuntimeException.getInstance("您还未购买车票");
         }
-        List<ChatgptCarInfoView> carInfoList = chatGptAccountService.getCarInfoList(carChatGptUser.getUserToken(),limit, isPlus);
-        for (ChatgptCarInfoView chatgptCarInfoView : carInfoList) {
+        SearchResult<ChatgptCarInfoView> carInfoList = chatGptAccountService.getCarInfoPage(carChatGptUser.getUserToken(),limit, isPlus);
+        for (ChatgptCarInfoView chatgptCarInfoView : carInfoList.getDataList()) {
             Double score = BigDecimal.valueOf(chatgptCarInfoView.getScore()).multiply(BigDecimal.valueOf(0.5)).setScale(0, RoundingMode.DOWN).doubleValue();
             chatgptCarInfoView.setScore(score);
             if (!"停运".equals(chatgptCarInfoView.getStatus())) {