aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authormrfoxygmfr <mrfoxygmfr@sch9.ru>2025-05-04 11:56:37 +0300
committermrfoxygmfr <mrfoxygmfr@sch9.ru>2025-05-04 11:56:37 +0300
commit3005e34b8ec65bef44f722a9a0576227a41690fc (patch)
treebf0215f922693173436e48177d9280dc9d9f4275 /src/main/java
parent185c9d3102b401634bba4717b86dc0fbf3f1a039 (diff)
feat: operation creation, view and manage
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/ru/mrfoxygmfr/warehouse_accounting/http/controllers/OperationsController.java144
1 files changed, 127 insertions, 17 deletions
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<Product> 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<Product> 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);
}
}