работает, невероятное
This commit is contained in:
parent
cf46765fb9
commit
12ac235025
@ -0,0 +1,52 @@
|
||||
package com.example.demo.supply.Order;
|
||||
|
||||
import com.example.demo.supply.Product.Product;
|
||||
import com.example.demo.supply.Supplier.Supplier;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class OrderDtoForCreate {
|
||||
private Long id;
|
||||
private Date dateOfOrder;
|
||||
private long supplierId;
|
||||
private List<Long> productsId;
|
||||
|
||||
public OrderDtoForCreate(){
|
||||
}
|
||||
|
||||
public OrderDtoForCreate(Order order){
|
||||
this.id = order.getId();
|
||||
this.dateOfOrder = order.getDateOfOrder();
|
||||
this.supplierId = order.getSupplier().getId();
|
||||
this.productsId = order.getProducts().stream().map(Product::getId).toList();
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Date getDateOfOrder() {
|
||||
return dateOfOrder;
|
||||
}
|
||||
|
||||
public void setDateOfOrder(Date dateOfOrder) {
|
||||
this.dateOfOrder = dateOfOrder;
|
||||
}
|
||||
|
||||
public long getSupplierId() {
|
||||
return supplierId;
|
||||
}
|
||||
|
||||
public void setSupplierId(long supplierId) {
|
||||
this.supplierId = supplierId;
|
||||
}
|
||||
|
||||
public List<Long> getProductsId() {
|
||||
return productsId;
|
||||
}
|
||||
|
||||
public void setProductsId(List<Long> productsId) {
|
||||
this.productsId = productsId;
|
||||
}
|
||||
}
|
@ -10,7 +10,6 @@ import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/order")
|
||||
@ -33,40 +32,48 @@ public class OrderMvcController {
|
||||
orderService.findAllOrders().stream()
|
||||
.map(OrderDto::new)
|
||||
.toList());
|
||||
// model.addAttribute("products",
|
||||
// pro.findAllOrders().stream()
|
||||
// .map(OrderDto::new)
|
||||
// .toList());
|
||||
return "order";
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public String getOrder(@PathVariable Long id,
|
||||
Model model) {
|
||||
model.addAttribute("orderId", id);
|
||||
model.addAttribute("orderDto", new OrderDto(orderService.findOrder(id)));
|
||||
return "product-edit";
|
||||
@GetMapping("/dop")
|
||||
public String getSuppliers(Model model,
|
||||
@RequestParam(required = false) Long id) {
|
||||
if(id == null || id <= 0) {
|
||||
model.addAttribute("productDto", new ProductDto());
|
||||
model.addAttribute("suppliers", null);
|
||||
model.addAttribute("selectedProduct", null);
|
||||
}
|
||||
else{
|
||||
ProductDto product = new ProductDto(productService.findProduct(id));
|
||||
model.addAttribute("productDto", product);
|
||||
model.addAttribute("selectedProduct", null);
|
||||
model.addAttribute("suppliers", orderService.suppliers(id).stream().map(SupplierDto::new).toList());
|
||||
}
|
||||
model.addAttribute("products", productService.findAllProducts().stream().map(ProductDto::new).toList());
|
||||
// model.addAttribute("orderDto", new OrderDto(orderService.findOrder(id)));
|
||||
return "order-dop";
|
||||
}
|
||||
|
||||
@PostMapping("/")
|
||||
public String createOrder(@ModelAttribute @Valid OrderDto orderDto,
|
||||
BindingResult bindingResult,
|
||||
Model model) {
|
||||
@GetMapping("/add")
|
||||
public String addOrder(Model model) {
|
||||
model.addAttribute("orderDto", new OrderDtoForCreate());
|
||||
model.addAttribute("selectedSupplier", null);
|
||||
model.addAttribute("suppliers", supplierService.findAllSuppliers().stream().map(SupplierDto::new).toList());
|
||||
model.addAttribute("products", productService.findAllProducts().stream().map(ProductDto::new).toList());
|
||||
return "order-add";
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
public String saveOrder(Model model,
|
||||
@ModelAttribute("orderDto") @Valid OrderDtoForCreate order,
|
||||
BindingResult bindingResult) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
model.addAttribute("errors", bindingResult.getAllErrors());
|
||||
return "order-add";
|
||||
}
|
||||
|
||||
List<SupplierDto> suppliers =supplierService.findAllSuppliers().stream()
|
||||
.map(SupplierDto::new).toList();
|
||||
|
||||
orderService.addOrder(orderDto.getSupplier().getId());
|
||||
Order newOrder = orderService.addOrder(supplierService.findSupplier(order.getSupplierId()).getId());
|
||||
for(Long obj: order.getProductsId())
|
||||
orderService.addProduct(newOrder.getId(), obj);
|
||||
return "redirect:/order";
|
||||
}
|
||||
//
|
||||
// @PostMapping("/delete/{id}")
|
||||
// public String deleteProduct(@PathVariable Long id) {
|
||||
// orderService.deleteProduct(id);
|
||||
// return "redirect:/product";
|
||||
// }
|
||||
}
|
||||
|
@ -8,6 +8,6 @@ import org.springframework.data.jpa.repository.Query;
|
||||
import java.util.List;
|
||||
|
||||
public interface OrderRepository extends JpaRepository<Order, Long> {
|
||||
@Query("SELECT distinct o.supplier FROM Order o join Product p where p = ?1")
|
||||
@Query("SELECT o.supplier FROM Order o where ?1 member of o.products")
|
||||
List<Supplier> getSomeSuppliers(Product product);
|
||||
}
|
||||
|
@ -34,6 +34,8 @@
|
||||
th:classappend="${#strings.equals(activeLink, '/supplier')} ? 'active' : ''">Поставщики</a>
|
||||
<a class="nav-link" href="/order"
|
||||
th:classappend="${#strings.equals(activeLink, '/order')} ? 'active' : ''">Заказы</a>
|
||||
<a class="nav-link" href="/order/dop"
|
||||
th:classappend="${#strings.equals(activeLink, '/order')} ? 'active' : ''">Доп задание</a>
|
||||
<a class="nav-link" href="/swagger-ui/index.html" target="_blank">Документация REST API</a>
|
||||
<a class="nav-link" href="/h2-console/" target="_blank">Консоль H2</a>
|
||||
</ul>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.thymeleaf.org"
|
||||
layout:decorate="~{default}">
|
||||
<head>
|
||||
</head>
|
||||
|
@ -1,135 +1,37 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.thymeleaf.org"
|
||||
layout:decorate="~{default}">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content" class="mw-100">
|
||||
<form action="#" th:action="@{/car/{id}(id=${id})}" method="post" class="mb-3">
|
||||
<div class="d-flex justify-content-center">
|
||||
|
||||
<div style="margin-left: 2vw;">
|
||||
<button type="submit" class="btn btn-outline-dark text-center button-fixed">
|
||||
<span>Создать</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div style="margin-left: 2vw;">
|
||||
<a class="btn btn-outline-dark text-center button-fixed" th:href="@{/order}">
|
||||
Отмена
|
||||
</a>
|
||||
</div>
|
||||
<div layout:fragment="content">
|
||||
<form action="#" th:action="@{/order/create}" th:object="${orderDto}" method="post">
|
||||
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-primary btn-success">Создать</button>
|
||||
<a class="btn btn-primary btn-danger" th:href="@{/order}">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="supplier" class="form-label">Поставщик</label>
|
||||
<select id="supplier" class="form-select" th:field="*{supplierId}" th:name="${selectedSupplier}">
|
||||
<option th:each="value: ${suppliers}" th:selected="${selectedSupplier != null and selectedSupplier == value.id}" th:value="${value.id}" th:text=" ${value.name}"></option>
|
||||
</select>
|
||||
</div>
|
||||
<p class="d-flex justify-content-between">
|
||||
<label>Продукты:</label>
|
||||
<div th:each="product : ${products}">
|
||||
<input type="checkbox" name="genres" th:text="${product.name} + '(Цена: ' + ${product.cost} + ') '"
|
||||
th:value="${product.id} "
|
||||
th:field="*{productsId}"
|
||||
/>
|
||||
</div>
|
||||
</p>
|
||||
|
||||
</form>
|
||||
|
||||
<div class="d-flex container-fluid ">
|
||||
<div style="width: 45vw; margin-right: 2vw" class="container-fluid">
|
||||
|
||||
<form action="#" th:action="@{/car/{id}(id=${id})}" method="post" >
|
||||
<input name="wpName" type="hidden" th:value="${name}" />
|
||||
<input name="PW" type="hidden" th:value="W" />
|
||||
<div class="mb-3">
|
||||
<label for="idW" class="form-label">Покупатель</label>
|
||||
<select class="form-select" id = "idW" th:name="idPW">
|
||||
<option th:each="value: ${buyers}"
|
||||
th:value="${value.id}"
|
||||
th:text="${value.buyerFirstName} + ' ' + ${value.buyerSecondName}">
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-outline-dark text-center button-fixed">
|
||||
<span>Добавить продукт</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<table class="table" >
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">id</th>
|
||||
<th scope="col">Название</th>
|
||||
<th scope="col">Цена</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="product, iterator: ${carBuyers}">
|
||||
<td th:text="${iterator.index} + 1"></td>
|
||||
<td th:text="${product.name}"></td>
|
||||
<td th:text="${product.cost}"></td>
|
||||
<td>
|
||||
<div>
|
||||
<a type="button" class="btn btn-outline-dark text-center button-fixed"
|
||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${product.id}').click()|">
|
||||
<i class="fa fa-trash"></i>
|
||||
</a>
|
||||
</div>
|
||||
<form th:action="@{'/car/' + ${id} + '?PW=W&wpName='+ ${name} +'&idPW=' + ${product.id} + '&delete=true'}" method="post">
|
||||
<button th:id="'remove-' + ${product.id}" type="submit" style="display: none">
|
||||
Удалить
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
<div style="width: 45vw; margin-left: 2vw" class="container-fluid">
|
||||
<form action="#" th:action="@{/car/{id}(id=${id})}" method="post" class="mb-3">
|
||||
<input name="wpName" type="hidden" th:value="${name}" />
|
||||
<input type="hidden" th:value="P" name="PW"/>
|
||||
<div class="mb-3">
|
||||
<label for="idP" class="form-label">Магазин</label>
|
||||
<select class="form-select" id = "idP" th:name="idPW">
|
||||
<option th:each="store, iterator: ${stores}"
|
||||
th:value="${store.id}"
|
||||
th:text="${store.storeName}">
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-outline-dark text-center button-fixed">
|
||||
<span>Добавить</span>
|
||||
</button>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
<table class="table" id="tbl-items">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">id</th>
|
||||
<th scope="col">Название</th>
|
||||
<th scope="col">Цена</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="carStore, iterator: ${carStores}">
|
||||
<td th:text="${iterator.index} + 1"></td>
|
||||
<td th:text="${carStore.storeName}"></td>
|
||||
<td>
|
||||
<div>
|
||||
<a type="button" class="btn btn-outline-dark text-center button-fixed"
|
||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${carStore.id}').click()|">
|
||||
<i class="fa fa-trash"></i>
|
||||
</a>
|
||||
</div>
|
||||
<form th:action="@{'/car/' + ${id} + '?PW=P&wpName='+ ${name} + '&idPW=' + ${carStore.id} + '&delete=true'}" method="post">
|
||||
<button class = "btn btn-outline-dark text-center button-fixed" th:id="'remove-' + ${carStore.id}" type="submit" style="display: none">
|
||||
Удалить
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
61
demo/src/main/resources/templates/order-dop.html
Normal file
61
demo/src/main/resources/templates/order-dop.html
Normal file
@ -0,0 +1,61 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.thymeleaf.org"
|
||||
layout:decorate="~{default}">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<form action="#" th:action="@{/order/dop}" th:object="${productDto}" method="get">
|
||||
<div class="mb-3">
|
||||
<label for="author" class="form-label">Продукт</label>
|
||||
|
||||
<select id="author" class="form-select" th:field="*{id}" th:name="${selectedProduct}">
|
||||
<option th:each="value: ${products}" th:selected="${selectedProduct != null and selectedProduct == value.id}" th:value="${value.id}" th:text="${value.name}"></option>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-success button-fixed">Сформировать</button>
|
||||
</form>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">ID</th>
|
||||
<th scope="col">Название</th>
|
||||
<th scope="col">Лицензия</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
<tr th:each="supplier, iterator: ${suppliers}">
|
||||
<th scope="row" th:text="${iterator.index} + 1"/>
|
||||
<td th:text="${supplier.id}"/>
|
||||
<td th:text="${supplier.name}"/>
|
||||
<td th:text="${supplier.license}"/>
|
||||
<td style="width: 10%">
|
||||
<div class="btn-group" role="group" aria-label="Basic example">
|
||||
<a class="btn btn-warning button-fixed button-sm"
|
||||
th:href="@{/supplier/edit/{id}(id=${supplier.id})}">
|
||||
<i class="fa fa-pencil" aria-hidden="true"></i> Изменить
|
||||
</a>
|
||||
<button type="button" class="btn btn-danger button-fixed button-sm"
|
||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${supplier.id}').click()|">
|
||||
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
|
||||
</button>
|
||||
</div>
|
||||
<form th:action="@{/supplier/delete/{id}(id=${supplier.id})}" method="post">
|
||||
<button th:id="'remove-' + ${supplier.id}" type="submit" style="display: none">
|
||||
Удалить
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -1,6 +1,6 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.thymeleaf.org"
|
||||
layout:decorate="~{default}">
|
||||
<head>
|
||||
</head>
|
||||
@ -8,7 +8,7 @@
|
||||
<div layout:fragment="content">
|
||||
<div>
|
||||
<a class="btn btn-success button-fixed"
|
||||
th:href="@{/order/}">
|
||||
th:href="@{/order/add}">
|
||||
<i class="fa-solid fa-plus"></i> Создать заказ
|
||||
</a>
|
||||
</div>
|
||||
@ -24,21 +24,13 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="product, iterator: ${orders}">
|
||||
<tr th:each="order, iterator: ${orders}">
|
||||
<th scope="row" th:text="${iterator.index} + 1"/>
|
||||
<td th:text="${order.id}"/>
|
||||
<td th:text="${order.dateOfOrder}" />
|
||||
<td th:text="${order.supplier}" />
|
||||
<td th:text="${order.supplier.name}" />
|
||||
<td>
|
||||
<li th:each="product : ${order.products}" th:text="${product.name}"></li>
|
||||
|
||||
<!-- <select class="form-select" size="3" aria-label="size 3 select example">-->
|
||||
<!-- <option selected>Open this select menu</option>-->
|
||||
<!-- <option value="1">One</option>-->
|
||||
<!-- <option value="2">Two</option>-->
|
||||
<!-- <option value="3">Three</option>-->
|
||||
<!-- </select>-->
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.thymeleaf.org"
|
||||
layout:decorate="~{default}">
|
||||
<head>
|
||||
</head>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.thymeleaf.org"
|
||||
layout:decorate="~{default}">
|
||||
<head>
|
||||
</head>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.thymeleaf.org"
|
||||
layout:decorate="~{default}">
|
||||
<head>
|
||||
</head>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.thymeleaf.org"
|
||||
layout:decorate="~{default}">
|
||||
<head>
|
||||
</head>
|
||||
|
Loading…
x
Reference in New Issue
Block a user