xiongzhu 3 년 전
부모
커밋
901020ae84

+ 7 - 2
src/main/java/com/izouma/nineth/service/PurchaseLevelService.java

@@ -2,9 +2,11 @@ package com.izouma.nineth.service;
 
 import com.izouma.nineth.domain.PurchaseLevel;
 import com.izouma.nineth.dto.PageQuery;
+import com.izouma.nineth.dto.PageWrapper;
 import com.izouma.nineth.repo.PurchaseLevelRepo;
 import com.izouma.nineth.utils.JpaUtils;
 import lombok.AllArgsConstructor;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.data.domain.Page;
 import org.springframework.stereotype.Service;
 
@@ -14,7 +16,10 @@ public class PurchaseLevelService {
 
     private PurchaseLevelRepo purchaseLevelRepo;
 
-    public Page<PurchaseLevel> all(PageQuery pageQuery) {
-        return purchaseLevelRepo.findAll(JpaUtils.toSpecification(pageQuery, PurchaseLevel.class), JpaUtils.toPageRequest(pageQuery));
+    @Cacheable(value = "purchaseLevelList", key = "#pageQuery.hashCode()")
+    public PageWrapper<PurchaseLevel> all(PageQuery pageQuery) {
+        Page<PurchaseLevel> page = purchaseLevelRepo.findAll(JpaUtils.toSpecification(pageQuery, PurchaseLevel.class), JpaUtils.toPageRequest(pageQuery));
+        return new PageWrapper<>(page.getContent(), page.getPageable().getPageNumber(),
+                page.getPageable().getPageSize(), page.getTotalElements());
     }
 }

+ 1 - 3
src/main/java/com/izouma/nineth/web/PurchaseLevelController.java

@@ -8,7 +8,6 @@ import com.izouma.nineth.service.PurchaseLevelService;
 import com.izouma.nineth.utils.ObjUtils;
 import com.izouma.nineth.utils.excel.ExcelUtils;
 import lombok.AllArgsConstructor;
-import org.springframework.cache.annotation.Cacheable;
 import org.springframework.data.domain.Page;
 import org.springframework.web.bind.annotation.*;
 
@@ -36,10 +35,9 @@ public class PurchaseLevelController extends BaseController {
 
 
     //@PreAuthorize("hasRole('ADMIN')")
-    @Cacheable(value = "purchaseLevelList", key = "#pageQuery.hashCode()")
     @PostMapping("/all")
     public Page<PurchaseLevel> all(@RequestBody PageQuery pageQuery) {
-        return purchaseLevelService.all(pageQuery);
+        return purchaseLevelService.all(pageQuery).toPage();
     }
 
     @GetMapping("/get/{id}")