Browse Source

fix: 无查询条件查询数据

jay 2 years ago
parent
commit
fe7bf483c2

+ 20 - 3
iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IJPACommData.java

@@ -5,13 +5,17 @@ import cc.iotkit.common.api.Paging;
 import cc.iotkit.common.utils.MapstructUtils;
 import cc.iotkit.data.ICommonData;
 import cc.iotkit.data.util.PageBuilder;
+import cc.iotkit.data.util.PredicateBuilder;
 import cc.iotkit.model.Id;
+import com.querydsl.core.types.Predicate;
 import org.springframework.data.domain.Example;
+import org.springframework.data.domain.ExampleMatcher;
 import org.springframework.data.domain.Page;
 import org.springframework.data.jpa.repository.JpaRepository;
 
 import java.util.Collection;
 import java.util.List;
+import java.util.Objects;
 import java.util.Optional;
 
 /**
@@ -79,8 +83,12 @@ public  interface IJPACommData< T extends Id<ID>, ID> extends ICommonData<T , ID
     @Override
     default Paging<T>  findAll(PageRequest<T> pageRequest) {
         Example example = genExample(pageRequest.getData());
-
-        Page<T> all = getBaseRepository().findAll(example, PageBuilder.toPageable(pageRequest));
+        Page<T> all = null;
+        if(Objects.isNull(example)){
+            all = getBaseRepository().findAll(PageBuilder.toPageable(pageRequest));
+        }else{
+            all =getBaseRepository().findAll(example, PageBuilder.toPageable(pageRequest));
+        }
         return  PageBuilder.toPaging(all, getTClass());
     }
 
@@ -90,8 +98,14 @@ public  interface IJPACommData< T extends Id<ID>, ID> extends ICommonData<T , ID
     @Override
     default List<T> findAllByCondition(T data) {
         Example example = genExample(data);
+        List all = null;
+        if(Objects.isNull(example)){
+             all = getBaseRepository().findAll();
+
+        }else{
+             all = getBaseRepository().findAll(example);
 
-        List all = getBaseRepository().findAll(example);
+        }
         return MapstructUtils.convert(all, getTClass());
     }
 
@@ -111,6 +125,9 @@ public  interface IJPACommData< T extends Id<ID>, ID> extends ICommonData<T , ID
 
 
     default Example genExample(T data) {
+        if(Objects.isNull(data)){
+            return null;
+        }
         return Example.of(MapstructUtils.convert(data, getJpaRepositoryClass()));
     }