Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix order ddl, get productList, merchantList in order input, fix list…
… order html
  • Loading branch information
yennanliu committed Oct 15, 2023
commit d73644edf1193bc4d48f3c36e3577fdeb8ea3153
4 changes: 2 additions & 2 deletions springWarehouse/sql/ddl/order.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ CREATE TABLE IF NOT EXISTS orders (

INSERT INTO orders(id, merchant_id, product_id, amount, create_time, update_time)
VALUES
(uuid(), 1, 1, 1, now(), now()),
(uuid(), 2, 2, 1, now(), now()),
("213ac245-7a2a-453b-a4a7-149426b13f84", 1, 1, 1, now(), now()),
("d42b3224-b715-46af-9294-3b2ecc6ccc7a", 2, 2, 1, now(), now()),
(uuid(), 1, 3, 1, now(), now());
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yen.springWarehouse.bean.Order;
import com.yen.springWarehouse.bean.Product;
import com.yen.springWarehouse.bean.ProductType;
import com.yen.springWarehouse.service.MerchantService;
import com.yen.springWarehouse.service.OrderService;
import com.yen.springWarehouse.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

Expand All @@ -23,6 +25,28 @@ public class OrderController {
@Autowired
OrderService orderService;

@Autowired
MerchantService merchantService;

@Autowired
ProductService productService;

@GetMapping("/toInput")
public String input(Map<String, Object> map) {

map.put("merchantList", merchantService.list());
map.put("productList", productService.list());
map.put("Order", new Order()); // TODO : check necessary ?
return "order/input_order";
}

@PostMapping("/create")
public String create(Order order) {

log.info("(OrderController.create) Create new order : " + order.toString());
orderService.save(order);
return "redirect:/order/list";
}

@GetMapping("/list")
public String list(Map<String, Object> map, @RequestParam(value="pageNo", required=false, defaultValue="1") String pageNoStr) {
Expand Down Expand Up @@ -53,4 +77,21 @@ public String list(Map<String, Object> map, @RequestParam(value="pageNo", requir
return "order/list_order";
}

@GetMapping(value="/preUpdate/{orderNo}")
public String preUpdate(@PathVariable("orderNo") String orderNo, Map<String, Object> map) {

Order order = orderService.getById(orderNo);
map.put("order" , order);
map.put("orderList", orderService.list());
return "product/update_order";
}

@PostMapping(value="/update")
public String update(Order order) {

log.info("update order as {}", order);
orderService.updateById(order);
return "redirect:/order/list";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,33 @@
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Add New Merchant</title>
<title>Add New Order</title>
<link rel="stylesheet" type="text/css" th:href="@{/css/style.css}" />
<script type="text/javascript" th:src="@{/js/jquery-3.1.1.min.js}"></script>
</head>
<body style="padding:8px;">
<h3 class="title">Add New Merchant</h3>
<form th:action="@{/merchant/create}" method="post" th:object="${Merchant}">
<h3 class="title">Add New Order</h3>
<form th:action="@{/order/create}" method="post" th:object="${Order}">

<div>
<span>Merchant Name:</span>
<input type="text" name="name" placeholder="Merchant Name">
<span>merchant:</span>
<select name="merchantId">
<option>=Select merchant name=</option>
<option th:each="list:${merchantList}" th:value="${list.id}" th:text="${list.name}"></option>
</select>
</div>

<div>
<span>Merchant city:</span>
<input type="text" name="city" placeholder="Merchant city">
<span>Product:</span>
<select name="productId">
<option>=Select product name=</option>
<option th:each="list:${productList}" th:value="${list.id}" th:text="${list.name}"></option>
</select>
</div>

<div>
<span>Amount:</span>
<input type="text" name="amount" >
</div>
<div>
<input type="submit" value=" confirm "/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ <h3 class="title">Order Management</h3>
<tr>
<th>Id</th>
<th>Merchant Id</th>
<th>Product Id</th>
<th>Amount</th>
</tr>
<tr class="type" th:each="order : ${page.records}">
<td th:text="${order.id}" nowrap></td>
<td id="merchant" th:text="${order.merchantId}" nowrap></td>
<td id="product" th:text="${order.productId}" nowrap></td>
<td id="amount" th:text="${order.amount}" nowrap></td>
<td nowrap>
<button class="update" th:href="@{/order/preUpdate/{id}(id=${order.id})}" >修改</button>
Expand Down