diff options
author | mrfoxygmfr <mrfoxygmfr@sch9.ru> | 2025-03-24 12:21:40 +0300 |
---|---|---|
committer | mrfoxygmfr <mrfoxygmfr@sch9.ru> | 2025-03-24 12:21:40 +0300 |
commit | 63303b61b6810b76cd16e2ad2c72b9e527813c28 (patch) | |
tree | 7dbf3f4b2279388c2fd50e8b8e9e83bfdeb85352 | |
parent | 2e5df4f22c9dd1997eb61ce1e92b483a4a9ccd4e (diff) |
feat(db/dao): new specs for operations
-rw-r--r-- | src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/OperationSpecs.java | 18 |
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); + }; } } |