aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/OperationSpecs.java18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/OperationSpecs.java b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/OperationSpecs.java
index 34b9ac5..7b2d6d0 100644
--- a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/OperationSpecs.java
+++ b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/OperationSpecs.java
@@ -1,5 +1,6 @@
package ru.mrfoxygmfr.warehouse_accounting.db.dao.specs;
+import jakarta.persistence.criteria.*;
import org.springframework.data.jpa.domain.Specification;
import ru.mrfoxygmfr.warehouse_accounting.db.models.*;
@@ -15,7 +16,20 @@ public class OperationSpecs {
}
public static Specification<Operation> operationPartnerNameLike(String partnerName) {
- return (root, _, builder)
- -> builder.equal(root.get(Operation_.partner).get(Partner_.name), partnerName);
+ return (root, _, builder) -> {
+ Join<Operation, Partner> withPartner = root.join(Operation_.partner);
+ return builder.like(withPartner.get(Partner_.name), "%" + partnerName + "%");
+ };
+ }
+
+ public static Specification<Operation> operationProductsContainsLike(String productName) {
+ return (root, query, builder) -> {
+ assert query != null;
+ Subquery<Product> subquery = query.subquery(Product.class);
+ Root<Product> from = subquery.from(Product.class);
+ subquery.select(from).where(ProductSpecs.productNameLike(productName).toPredicate(from, query, builder));
+ SetJoin<Operation, OperationProduct> withProducts = root.join(Operation_.products);
+ return builder.in(withProducts.get(OperationProduct_.product)).value(subquery);
+ };
}
}