wangqifan 4 лет назад
Родитель
Сommit
f082c0997a

+ 4 - 2
src/main/java/com/izouma/tcg/repo/card/CardCaseRepo.java

@@ -3,6 +3,8 @@ package com.izouma.tcg.repo.card;
 import com.izouma.tcg.domain.card.CardCase;
 import com.izouma.tcg.dto.cardCase.CaseDTO;
 import com.izouma.tcg.enums.CaseStatus;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Modifying;
@@ -22,13 +24,13 @@ public interface CardCaseRepo extends JpaRepository<CardCase, Long>, JpaSpecific
             "   s.id, s.startTime, s.images, s.customName, " +
             "   s.boxPrice, s.caseStatus, s.special, s.roomId, s.liveNow, s.instant,s.collectionId) " +
             "FROM CardCase s WHERE s.caseStatus = ?1 and s.seriesId = ?2 and s.del = false")
-    List<CaseDTO> customFindList1(CaseStatus caseStatus, Long seriesId);
+    Page<CaseDTO> customFindList1(CaseStatus caseStatus, Long seriesId, Pageable pageable);
 
     @Query("SELECT new com.izouma.tcg.dto.cardCase.CaseDTO(" +
             "   s.id, s.startTime, s.images, s.customName, " +
             "   s.boxPrice, s.caseStatus, s.special, s.roomId, s.liveNow, s.instant,s.collectionId) " +
             "FROM CardCase s WHERE s.caseStatus = ?1 and s.seriesId = ?3 and s.collectionId in ?2 and s.del = false ")
-    List<CaseDTO> customFindList2(CaseStatus caseStatus, Set<Long> collectionId, Long seriesId);
+    Page<CaseDTO> customFindList2(CaseStatus caseStatus, Set<Long> collectionId, Long seriesId, Pageable pageable);
 
     List<CardCase> findAllByRoomIdAndStoreId(Long roomId, Long storeId);
 }

+ 8 - 5
src/main/java/com/izouma/tcg/service/card/CardCaseService.java

@@ -31,6 +31,8 @@ import lombok.AllArgsConstructor;
 import org.apache.commons.beanutils.ConvertUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageImpl;
+import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
 
@@ -231,8 +233,8 @@ public class CardCaseService {
     }
 
 
-    public List<CardCaseDTO> showCardCasesMA(CaseStatus caseStatus, Long collectionId, String search, Long seriesId) {
-        List<CaseDTO> cardCases = new ArrayList<>();
+    public Page<CardCaseDTO> showCardCasesMA(CaseStatus caseStatus, Long collectionId, String search, Long seriesId, Pageable pageable) {
+        Page<CaseDTO> cardCases;
         Set<Long> collectionIds = new HashSet<>();
         if (StringUtils.isNotBlank(search)) {
             collectionIds = collectionRepo.findAllByNameLike("%" + search + "%").stream().map(Collection::getId)
@@ -242,12 +244,13 @@ public class CardCaseService {
             collectionIds.add(collectionId);
         }
         if (collectionId == null & StringUtils.isBlank(search)) {
-            cardCases = cardCaseRepo.customFindList1(caseStatus, seriesId);
+            cardCases = cardCaseRepo.customFindList1(caseStatus, seriesId, pageable);
         } else {
             cardCases = cardCaseRepo
-                    .customFindList2(caseStatus, collectionIds, seriesId);
+                    .customFindList2(caseStatus, collectionIds, seriesId, pageable);
         }
-        return getCustomSearchResult(cardCases);
+        return new PageImpl<>(getCustomSearchResult(cardCases.getContent()), cardCases.getPageable(), cardCases
+                .getTotalElements());
     }
 
     public Map<String, Object> showCaseInfoMA(Long caseId) {

+ 6 - 5
src/main/java/com/izouma/tcg/web/card/CardCaseController.java

@@ -17,6 +17,7 @@ import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.Authorization;
 import lombok.AllArgsConstructor;
 import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
@@ -65,8 +66,8 @@ public class CardCaseController extends BaseController {
 
     @GetMapping("/excel")
     @ResponseBody
-    public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
-        List<CardCaseDTO> data = showCardCasesMA(null, null, null, 103L);
+    public void excel(HttpServletResponse response, Pageable pageable) throws IOException {
+        List<CardCaseDTO> data = showCardCasesMA(null, null, null, 103L, pageable).getContent();
         ExcelUtils.export(response, data);
     }
 
@@ -79,9 +80,9 @@ public class CardCaseController extends BaseController {
 
     @GetMapping("/showCasesMA")
     @ApiOperation("获取卡箱列表")
-    public List<CardCaseDTO> showCardCasesMA(CaseStatus caseStatus, @RequestParam(required = false) Long collectionId,
-                                             @RequestParam(required = false) String search, @RequestParam(required = true) Long seriesId) {
-        return cardCaseService.showCardCasesMA(caseStatus, collectionId, search, seriesId);
+    public Page<CardCaseDTO> showCardCasesMA(CaseStatus caseStatus, @RequestParam(required = false) Long collectionId,
+                                             @RequestParam(required = false) String search, @RequestParam(required = true) Long seriesId, Pageable pageable) {
+        return cardCaseService.showCardCasesMA(caseStatus, collectionId, search, seriesId, pageable);
     }
 
     @GetMapping("/showInfoMA")