From 3005e34b8ec65bef44f722a9a0576227a41690fc Mon Sep 17 00:00:00 2001 From: mrfoxygmfr Date: Sun, 4 May 2025 11:56:37 +0300 Subject: feat: operation creation, view and manage --- .../http/controllers/OperationsController.java | 144 ++++++++++++++++++--- src/main/resources/templates/operationEdit.html | 10 -- .../resources/templates/operationProductEdit.html | 28 ++++ .../resources/templates/operationProductNew.html | 85 ++++++++++++ .../resources/templates/operationProducts.html | 48 +++++++ src/main/resources/templates/operationView.html | 58 +++++++++ 6 files changed, 346 insertions(+), 27 deletions(-) delete mode 100644 src/main/resources/templates/operationEdit.html create mode 100644 src/main/resources/templates/operationProductEdit.html create mode 100644 src/main/resources/templates/operationProductNew.html create mode 100644 src/main/resources/templates/operationProducts.html create mode 100644 src/main/resources/templates/operationView.html diff --git a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/http/controllers/OperationsController.java b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/http/controllers/OperationsController.java index f4acdd1..6e29e09 100644 --- a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/http/controllers/OperationsController.java +++ b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/http/controllers/OperationsController.java @@ -4,11 +4,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.*; import ru.mrfoxygmfr.warehouse_accounting.db.dao.*; import ru.mrfoxygmfr.warehouse_accounting.db.dao.specs.OperationSpecs; +import ru.mrfoxygmfr.warehouse_accounting.db.dao.specs.ProductSpecs; import ru.mrfoxygmfr.warehouse_accounting.db.models.*; import java.util.List; @@ -17,6 +16,10 @@ import java.util.List; public class OperationsController { @Autowired private OperationDAO operationDAO; + @Autowired + private PartnerDAO partnerDAO; + @Autowired + private ProductDAO productDAO; @GetMapping(value = { "/", "/index", "/operations"}) public String operations(@RequestParam(name = "operationType", required = false) OperationType type, @@ -50,29 +53,136 @@ public class OperationsController { public String operation(@RequestParam(name = "id") Integer id, Model model) { Operation operation = operationDAO.findById(id).orElseThrow(); model.addAttribute("operation", operation); - return "operationEdit"; + return "operationView"; } @PostMapping("operation") public String operation( - @RequestParam(name = "id") Integer id, - @RequestParam(name = "type") String type, - @RequestParam(name = "status") String status, - @RequestParam(name = "partner_id") Integer partnerId, - @RequestParam(name = "responsible_id") Integer responsibleId, + @RequestParam(name = "operationId") Integer operationId, + @RequestParam(name = "operationResponsible") Integer responsibleId, + @RequestParam(name = "operationAddress") String address, Model model) { - Operation operation; - if (id != null) { - operation = operationDAO.findById(id).orElseThrow(); - } else { - operation = new Operation(); - } + Operation operation = operationDAO.findById(operationId).orElseThrow(); + + operation.setResponsible(operation.getPartner().getContacts().stream().filter( + contact -> contact.getId() == responsibleId + ).findFirst().orElseThrow()); + operation.setAddress(address); + + operationDAO.save(operation); return String.format("redirect:/operation?id=%d", operation.getId()); } @GetMapping("newOperation") - public String newOperation(Model model) { - return "operationEdit"; + public String newOperation(@RequestParam(name = "partnerId") Integer partnerId, + Model model) { + Partner partner = partnerDAO.findById(partnerId).orElseThrow(); + + Operation operation = new Operation(); + operation.setPartner(partner); + operation.setAddress(partner.getAddress()); + operation.setStatus(OperationStatus.CHECKOUT); + if (partner.getType() == PartnerType.ISSUER) { + operation.setType(OperationType.ISSUE); + } else { + operation.setType(OperationType.SUPPLY); + } + operation.setResponsible(partner.getContacts().stream().findFirst().orElseThrow()); + + operationDAO.save(operation); + return "redirect:/operations"; + } + + @RequestMapping("/operationProducts/{operationId}") + public String operationProducts(@PathVariable(value = "operationId") Integer operationId, + Model model) { + + Operation operation = operationDAO.findById(operationId).orElseThrow(); + model.addAttribute("products", operation.getProducts()); + model.addAttribute("operationId", operationId); + return "operationProducts"; + } + + @RequestMapping("/operationProducts/{operationId}/new/") + public String operationProductsNew(@PathVariable(value = "operationId") Integer operationId, + @RequestParam(name = "operationProductName", required = false) String name, + @RequestParam(name = "operationProductHeightLess", required = false) Integer heightLess, + @RequestParam(name = "operationProductHeightGreater", required = false) Integer heightGreater, + @RequestParam(name = "operationProductWidthLess", required = false) Integer widthLess, + @RequestParam(name = "operationProductWidthGreater", required = false) Integer widthGreater, + @RequestParam(name = "operationProductDepthLess", required = false) Integer depthLess, + @RequestParam(name = "operationProductDepthGreater", required = false) Integer depthGreater, + Model model) { + Specification spec = Specification.where(null); + if (name != null && !name.isEmpty()) { + spec = spec.and(ProductSpecs.productNameLike(name)); + model.addAttribute("operationProductNameFilter", name); + } + if (heightLess != null) { + spec = spec.and(ProductSpecs.productHeightLess(heightLess)); + model.addAttribute("operationProductHeightLessFilter", heightLess); + } + if (heightGreater != null) { + spec = spec.and(ProductSpecs.productHeightGreater(heightGreater)); + model.addAttribute("operationProductHeightGreaterFilter", heightGreater); + } + if (widthLess != null) { + spec = spec.and(ProductSpecs.productWidthLess(widthLess)); + model.addAttribute("operationProductWidthLessFilter", widthLess); + } + if (widthGreater != null) { + spec = spec.and(ProductSpecs.productWidthGreater(widthGreater)); + model.addAttribute("operationProductWidthGreaterFilter", widthGreater); + } + if (depthLess != null) { + spec = spec.and(ProductSpecs.productDepthLess(depthLess)); + model.addAttribute("operationProductDepthLessFilter", depthLess); + } + if (depthGreater != null) { + spec = spec.and(ProductSpecs.productDepthGreater(depthGreater)); + model.addAttribute("operationProductDepthGreaterFilter", depthGreater); + } + + List products = productDAO.findAll(spec); + model.addAttribute("products", products); + model.addAttribute("operationId", operationId); + return "operationProductNew"; + } + + @RequestMapping("/operationProducts/{operationId}/edit/") + public String operationProductsEdit_GET(@PathVariable(value = "operationId") Integer operationId, + @RequestParam(name = "id") Integer productId, + + Model model) { + + Operation operation = operationDAO.findById(operationId).orElseThrow(); + Product product = productDAO.findById(productId).orElseThrow(); + + model.addAttribute("product", product); + model.addAttribute("operation", operation); + model.addAttribute("amount", operation.getProducts().parallelStream().filter(p -> p.getProduct().getId() == productId).findFirst().orElse(new OperationProduct()).getAmount()); + return "operationProductEdit"; + } + + @RequestMapping(value="/operationProducts/{operationId}/edit/", method = RequestMethod.POST) + public String operationProductsEdit_POST(@PathVariable(value = "operationId") Integer operationId, + @RequestParam(name = "productId") Integer productId, + @RequestParam(name = "productAmount") Integer amount, + Model model) { + + Operation operation = operationDAO.findById(operationId).orElseThrow(); + Product product = productDAO.findById(productId).orElseThrow(); + + OperationProduct op = operation.getProducts().parallelStream() + .filter(p -> p.getProduct().getId() == productId) + .findAny() + .orElse(new OperationProduct(operation, product, amount)); + op.setAmount(amount); + + operation.updateProduct(op); + operationDAO.save(operation); + + return String.format("redirect:/operationProducts/%d", operationId); } } diff --git a/src/main/resources/templates/operationEdit.html b/src/main/resources/templates/operationEdit.html deleted file mode 100644 index 566549b..0000000 --- a/src/main/resources/templates/operationEdit.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Title - - - - - \ No newline at end of file diff --git a/src/main/resources/templates/operationProductEdit.html b/src/main/resources/templates/operationProductEdit.html new file mode 100644 index 0000000..f764c80 --- /dev/null +++ b/src/main/resources/templates/operationProductEdit.html @@ -0,0 +1,28 @@ + + +
+ + +
+ +
+
+ + + + +

+ +

+ + +
+
+ + +
+
+
+ + + \ No newline at end of file diff --git a/src/main/resources/templates/operationProductNew.html b/src/main/resources/templates/operationProductNew.html new file mode 100644 index 0000000..c5f68b7 --- /dev/null +++ b/src/main/resources/templates/operationProductNew.html @@ -0,0 +1,85 @@ + + +
+ + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Фильтры
Название + +
Высота + от + до +
Ширина + от + до +
Глубина + от + до +
+
+ + + + + + + + + + + + + + + + + + + +
НазваниеГабариты (В*Ш*Г)Добавить
Данному фильтру не удовлетворяет ни одного продукта.
+ + + + + + + + + +
+
+ +
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/operationProducts.html b/src/main/resources/templates/operationProducts.html new file mode 100644 index 0000000..f3997b4 --- /dev/null +++ b/src/main/resources/templates/operationProducts.html @@ -0,0 +1,48 @@ + + +
+ + +
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + +
НазваниеГабариты (В*Ш*Г)Количество
В операции нет ни одного продукта.
+ + + + + + + + + +
+
+ +
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/operationView.html b/src/main/resources/templates/operationView.html new file mode 100644 index 0000000..37631b8 --- /dev/null +++ b/src/main/resources/templates/operationView.html @@ -0,0 +1,58 @@ + + +
+ + +
+ +
+ + +
+ + +

+ +

+ + +

+
+ + +

+ + +

+ +

+

+

+ + +
+
+ + +
+
+
+ + + \ No newline at end of file -- cgit mrf-deployment