Procházet zdrojové kódy

封存中类目的搜索

sunkean před 3 roky
rodič
revize
40361f458e

+ 17 - 3
src/main/java/com/izouma/nineth/service/AssetService.java

@@ -25,6 +25,7 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageImpl;
+import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.scheduling.annotation.Async;
@@ -70,8 +71,20 @@ public class AssetService {
     private UserBalanceService      userBalanceService;
 
     public Page<Asset> all(PageQuery pageQuery) {
-        Page<Asset> all = assetRepo
-                .findAll(JpaUtils.toSpecification(pageQuery, Asset.class), JpaUtils.toPageRequest(pageQuery));
+
+        Map<String, Object> query = pageQuery.getQuery();
+        Specification<Asset> specification = JpaUtils.toSpecification(pageQuery, Asset.class);
+        PageRequest pageRequest = JpaUtils.toPageRequest(pageQuery);
+        if (query.containsKey("lock")) {
+            LocalDateTime now = LocalDateTime.now();
+            query.remove("lock");
+                specification = specification.and((Specification<Asset>) (root, criteriaQuery, criteriaBuilder) -> {
+                    List<Predicate> and = new ArrayList<>();
+                    and.add(criteriaBuilder.greaterThan(root.get("lockTo"), now));
+                    return criteriaBuilder.and(and.toArray(new Predicate[0]));
+                });
+        }
+        Page<Asset> all = assetRepo.findAll(specification, pageRequest);
 //        Map<String, Object> query = pageQuery.getQuery();
 //        if (query.containsKey("userId")) {
 //            List<Long> orderId = orderRepo
@@ -83,7 +96,8 @@ public class AssetService {
 //                return asset;
 //            });
 //        }
-        return all;
+        return new PageWrapper<>(all.getContent(), all.getPageable().getPageNumber(),
+                all.getPageable().getPageSize(), all.getTotalElements()).toPage();
     }
 
     public List<AssetDTO> userSummary(PageQuery pageQuery) {