diff options
author | mrfoxygmfr <mrfoxygmfr@sch9.ru> | 2025-03-24 12:21:16 +0300 |
---|---|---|
committer | mrfoxygmfr <mrfoxygmfr@sch9.ru> | 2025-03-24 12:21:16 +0300 |
commit | 2e5df4f22c9dd1997eb61ce1e92b483a4a9ccd4e (patch) | |
tree | 0e74e051840122292cf8435934382630ba0e77f4 | |
parent | d1d78f21b24fb0da43b6360466d189491a477496 (diff) |
feat(db/models): addProduct method for Operation
-rw-r--r-- | src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/Operation.java | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/Operation.java b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/Operation.java index 22116f8..31ec626 100644 --- a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/Operation.java +++ b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/db/models/Operation.java @@ -6,7 +6,9 @@ import org.hibernate.annotations.CreationTimestamp; import org.hibernate.annotations.UpdateTimestamp; import java.sql.Timestamp; +import java.util.HashSet; import java.util.Set; +import java.util.stream.Collectors; @Entity @Table(name = "operations") @@ -61,4 +63,21 @@ public class Operation { @OneToMany(mappedBy = "operation", cascade=CascadeType.ALL, orphanRemoval = true) @ToString.Exclude private Set<OperationProduct> products; + + public void updateProduct(OperationProduct product) { + if (products == null) { + products = new HashSet<>(); + } + + products = products.parallelStream() + .filter((p) -> p.getProduct() != product.getProduct()) + .collect(Collectors.toSet()); + + if (product.getAmount() == 0) { + return; + } + + products.add(product); + product.setOperation(this); + } } |