aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormrfoxygmfr <mrfoxygmfr@sch9.ru>2025-03-23 14:52:40 +0300
committermrfoxygmfr <mrfoxygmfr@sch9.ru>2025-03-23 14:52:40 +0300
commite06ab0f9e796e914529bdd55dbeb6f04846aed02 (patch)
tree28029cda8e86aff15afc4327e18a347ee0e76514
parent288c76476615ab162384f25d1155a3080a3a8b99 (diff)
feat(db/dao): create specifications for JPA
-rw-r--r--src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/OperationSpecs.java21
-rw-r--r--src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/PartnerSpecs.java21
-rw-r--r--src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/ProductSpecs.java41
-rw-r--r--src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/StorageSlotSpecs.java37
4 files changed, 120 insertions, 0 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
new file mode 100644
index 0000000..34b9ac5
--- /dev/null
+++ b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/OperationSpecs.java
@@ -0,0 +1,21 @@
+package ru.mrfoxygmfr.warehouse_accounting.db.dao.specs;
+
+import org.springframework.data.jpa.domain.Specification;
+import ru.mrfoxygmfr.warehouse_accounting.db.models.*;
+
+public class OperationSpecs {
+ public static Specification<Operation> operationTypeEqual(OperationType operationType) {
+ return (root, _, builder)
+ -> builder.equal(root.get(Operation_.type), operationType);
+ }
+
+ public static Specification<Operation> operationStatusEqual(OperationStatus operationStatus) {
+ return (root, _, builder)
+ -> builder.equal(root.get(Operation_.status), operationStatus);
+ }
+
+ public static Specification<Operation> operationPartnerNameLike(String partnerName) {
+ return (root, _, builder)
+ -> builder.equal(root.get(Operation_.partner).get(Partner_.name), partnerName);
+ }
+}
diff --git a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/PartnerSpecs.java b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/PartnerSpecs.java
new file mode 100644
index 0000000..c8d4c09
--- /dev/null
+++ b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/PartnerSpecs.java
@@ -0,0 +1,21 @@
+package ru.mrfoxygmfr.warehouse_accounting.db.dao.specs;
+
+import org.springframework.data.jpa.domain.Specification;
+import ru.mrfoxygmfr.warehouse_accounting.db.models.*;
+
+public class PartnerSpecs {
+ public static Specification<Partner> partnerNameLike(String nameFilter) {
+ return (root, _, builder)
+ -> builder.like(root.get(Partner_.name), "%" +nameFilter + "%");
+ }
+
+ public static Specification<Partner> partnerTaxNumberLike(String taxNumberFilter) {
+ return (root, _, builder)
+ -> builder.like(root.get(Partner_.taxNumber), "%" + taxNumberFilter + "%");
+ }
+
+ public static Specification<Partner> partnerTypeEqual(PartnerType typeFilter) {
+ return (root, _, builder)
+ -> builder.equal(root.get(Partner_.type), typeFilter);
+ }
+}
diff --git a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/ProductSpecs.java b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/ProductSpecs.java
new file mode 100644
index 0000000..ba37f6a
--- /dev/null
+++ b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/ProductSpecs.java
@@ -0,0 +1,41 @@
+package ru.mrfoxygmfr.warehouse_accounting.db.dao.specs;
+
+import org.springframework.data.jpa.domain.Specification;
+import ru.mrfoxygmfr.warehouse_accounting.db.models.*;
+
+public class ProductSpecs {
+ public static Specification<Product> productNameLike(String nameFilter) {
+ return (root, _, builder)
+ -> builder.like(root.get(Product_.name), "%" + nameFilter + "%");
+ }
+
+ public static Specification<Product> productHeightLess(long maxHeight) {
+ return (root, _, builder)
+ -> builder.lessThanOrEqualTo(root.get(Product_.height), maxHeight);
+ }
+
+ public static Specification<Product> productHeightGreater(long minHeight) {
+ return (root, _, builder)
+ -> builder.greaterThanOrEqualTo(root.get(Product_.height), minHeight);
+ }
+
+ public static Specification<Product> productWidthLess(long maxWidth) {
+ return (root, _, builder)
+ -> builder.lessThanOrEqualTo(root.get(Product_.width), maxWidth);
+ }
+
+ public static Specification<Product> productWidthGreater(long minWidth) {
+ return (root, _, builder)
+ -> builder.greaterThanOrEqualTo(root.get(Product_.width), minWidth);
+ }
+
+ public static Specification<Product> productDepthLess(long maxDepth) {
+ return (root, _, builder)
+ -> builder.lessThanOrEqualTo(root.get(Product_.depth), maxDepth);
+ }
+
+ public static Specification<Product> productDepthGreater(long minDepth) {
+ return (root, _, builder)
+ -> builder.greaterThanOrEqualTo(root.get(Product_.depth), minDepth);
+ }
+} \ No newline at end of file
diff --git a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/StorageSlotSpecs.java b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/StorageSlotSpecs.java
new file mode 100644
index 0000000..2dbd2cf
--- /dev/null
+++ b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/dao/specs/StorageSlotSpecs.java
@@ -0,0 +1,37 @@
+package ru.mrfoxygmfr.warehouse_accounting.db.dao.specs;
+
+import org.springframework.data.jpa.domain.Specification;
+import ru.mrfoxygmfr.warehouse_accounting.db.models.*;
+
+public class StorageSlotSpecs {
+
+ public static Specification<StorageSlot> storageSlotHeightLess(long maxHeight) {
+ return (root, _, builder)
+ -> builder.lessThanOrEqualTo(root.get(StorageSlot_.height), maxHeight);
+ }
+
+ public static Specification<StorageSlot> storageSlotHeightGreater(long minHeight) {
+ return (root, _, builder)
+ -> builder.greaterThanOrEqualTo(root.get(StorageSlot_.height), minHeight);
+ }
+
+ public static Specification<StorageSlot> storageSlotWidthLess(long maxWidth) {
+ return (root, _, builder)
+ -> builder.lessThanOrEqualTo(root.get(StorageSlot_.width), maxWidth);
+ }
+
+ public static Specification<StorageSlot> storageSlotWidthGreater(long minWidth) {
+ return (root, _, builder)
+ -> builder.greaterThanOrEqualTo(root.get(StorageSlot_.width), minWidth);
+ }
+
+ public static Specification<StorageSlot> storageSlotDepthLess(long maxDepth) {
+ return (root, _, builder)
+ -> builder.lessThanOrEqualTo(root.get(StorageSlot_.depth), maxDepth);
+ }
+
+ public static Specification<StorageSlot> storageSlotDepthGreater(long minDepth) {
+ return (root, _, builder)
+ -> builder.greaterThanOrEqualTo(root.get(StorageSlot_.depth), minDepth);
+ }
+}