fix<订单分类>
parent
5bdf84c53c
commit
2a99339bad
|
@ -26,12 +26,22 @@ public class OrdersServlet extends HttpServlet {
|
||||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
String action = req.getParameter("action");
|
String action = req.getParameter("action");
|
||||||
switch (action) {
|
switch (action) {
|
||||||
|
case "waiting":
|
||||||
|
ordersService.waiting(req, resp);
|
||||||
|
break;
|
||||||
|
case "sent":
|
||||||
|
ordersService.sent(req, resp);
|
||||||
|
break;
|
||||||
case "all":
|
case "all":
|
||||||
ordersService.allOrder(req, resp);
|
ordersService.allOrder(req, resp);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "my":
|
case "my":
|
||||||
ordersService.myOrder(req, resp);
|
ordersService.myOrder(req, resp);
|
||||||
break;
|
break;
|
||||||
|
case "deliver":
|
||||||
|
ordersService.deliver(req, resp);
|
||||||
|
break;
|
||||||
case "add":
|
case "add":
|
||||||
try {
|
try {
|
||||||
ordersService.checkOrder(req, resp);
|
ordersService.checkOrder(req, resp);
|
||||||
|
|
|
@ -13,7 +13,7 @@ public class OrdersDao {
|
||||||
|
|
||||||
|
|
||||||
public List<Orders> getAllOrders() {
|
public List<Orders> getAllOrders() {
|
||||||
String sql = "select id,user_id userId,order_date orderDate,total_price totalPrice,address ,remark from orders o ";
|
String sql = "select id,user_id userId,order_date orderDate,total_price totalPrice,address ,remark,status from orders o ";
|
||||||
try {
|
try {
|
||||||
return queryRunner.query(sql, new BeanListHandler<>(Orders.class));
|
return queryRunner.query(sql, new BeanListHandler<>(Orders.class));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -29,9 +29,9 @@ public class OrdersDao {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int addOrder(int userId,double price, String address, String remark) {
|
public int addOrder(int userId,double price, String address, String remark) {
|
||||||
String sql="insert into orders(user_id,order_date,total_price,address,remark) values(?,?,?,?,?)";
|
String sql="insert into orders(user_id,order_date,total_price,address,remark,status) values(?,?,?,?,?,?)";
|
||||||
try {
|
try {
|
||||||
return queryRunner.update(sql,userId, LocalDateTime.now(),price,address,remark);
|
return queryRunner.update(sql,userId, LocalDateTime.now(),price,address,remark,"待发货");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ public class OrdersDao {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Orders> getMyOrders(int userId) {
|
public List<Orders> getMyOrders(int userId) {
|
||||||
String sql = "select id,user_id userId,order_date orderDate,total_price totalPrice,address ,remark from orders o where user_id =?";
|
String sql = "select id,user_id userId,order_date orderDate,total_price totalPrice,address ,remark,status from orders o where user_id =?";
|
||||||
try {
|
try {
|
||||||
return queryRunner.query(sql, new BeanListHandler<>(Orders.class),userId);
|
return queryRunner.query(sql, new BeanListHandler<>(Orders.class),userId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -47,4 +47,33 @@ public class OrdersDao {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deliver(String orderId) {
|
||||||
|
String sql = "update orders set status = ? where id = ?";
|
||||||
|
try {
|
||||||
|
queryRunner.update(sql,"已发货",orderId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Orders> getOrdersOfWaiting() {
|
||||||
|
String sql = "select id,user_id userId,order_date orderDate,total_price totalPrice,address ,remark,status from orders o where status = '待发货'";
|
||||||
|
try {
|
||||||
|
return queryRunner.query(sql, new BeanListHandler<>(Orders.class));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Orders> getOrdersOfSent() {
|
||||||
|
String sql = "select id,user_id userId,order_date orderDate,total_price totalPrice,address ,remark,status from orders o where status = '已发货'";
|
||||||
|
try {
|
||||||
|
return queryRunner.query(sql, new BeanListHandler<>(Orders.class));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,4 +7,27 @@ public class Cart {
|
||||||
|
|
||||||
private Integer productId;
|
private Integer productId;
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserId(Integer userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getProductId() {
|
||||||
|
return productId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProductId(Integer productId) {
|
||||||
|
this.productId = productId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,16 +15,14 @@ public class Orders {
|
||||||
|
|
||||||
private String remark;
|
private String remark;
|
||||||
|
|
||||||
@Override
|
private String status;
|
||||||
public String toString() {
|
|
||||||
return "Orders{" +
|
public String getStatus() {
|
||||||
"id=" + id +
|
return status;
|
||||||
", userId=" + userId +
|
}
|
||||||
", orderDate=" + orderDate +
|
|
||||||
", totalPrice=" + totalPrice +
|
public void setStatus(String status) {
|
||||||
", address='" + address + '\'' +
|
this.status = status;
|
||||||
", remark='" + remark + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
|
|
|
@ -2,8 +2,10 @@ package example.service;
|
||||||
|
|
||||||
import example.model.Orders;
|
import example.model.Orders;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface IOrdersService {
|
public interface IOrdersService {
|
||||||
|
@ -15,4 +17,10 @@ public interface IOrdersService {
|
||||||
int addOrder(int userId,double price, String address, String remark);
|
int addOrder(int userId,double price, String address, String remark);
|
||||||
|
|
||||||
void myOrder(HttpServletRequest req, HttpServletResponse resp);
|
void myOrder(HttpServletRequest req, HttpServletResponse resp);
|
||||||
|
|
||||||
|
void deliver(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException;
|
||||||
|
|
||||||
|
void waiting(HttpServletRequest req, HttpServletResponse resp);
|
||||||
|
|
||||||
|
void sent(HttpServletRequest req, HttpServletResponse resp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,10 @@ import example.model.Orders;
|
||||||
import example.model.User;
|
import example.model.User;
|
||||||
import example.service.IOrdersService;
|
import example.service.IOrdersService;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class OrdersServiceImpl implements IOrdersService {
|
public class OrdersServiceImpl implements IOrdersService {
|
||||||
|
@ -63,4 +65,33 @@ public class OrdersServiceImpl implements IOrdersService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deliver(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
String orderId = req.getParameter("id");
|
||||||
|
ordersDao.deliver(orderId);
|
||||||
|
req.getRequestDispatcher("/orders?action=all").forward(req,resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void waiting(HttpServletRequest req, HttpServletResponse resp) {
|
||||||
|
List<Orders> allOrders = ordersDao.getOrdersOfWaiting();
|
||||||
|
req.setAttribute("Orders",allOrders);
|
||||||
|
try {
|
||||||
|
req.getRequestDispatcher("orders.jsp").forward(req,resp);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sent(HttpServletRequest req, HttpServletResponse resp) {
|
||||||
|
List<Orders> allOrders = ordersDao.getOrdersOfSent();
|
||||||
|
req.setAttribute("Orders",allOrders);
|
||||||
|
try {
|
||||||
|
req.getRequestDispatcher("orders.jsp").forward(req,resp);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,21 @@
|
||||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<script src="https://www.liyansheng.top/cdn/watermark.js"></script>
|
<script src="https://www.liyansheng.top/cdn/watermark.js"></script>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>订单列表</title>
|
<title>订单列表</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<h1>订单列表</h1>
|
<h1>订单列表</h1>
|
||||||
|
<a href="/orders?action=all">全部</a> |
|
||||||
|
<a href="/orders?action=waiting">待发货</a> |
|
||||||
|
<a href="/orders?action=sent">已发货</a>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
<table border="1">
|
<table border="1">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -19,6 +26,7 @@
|
||||||
<th>总金额</th>
|
<th>总金额</th>
|
||||||
<th>地址</th>
|
<th>地址</th>
|
||||||
<th>商品信息</th>
|
<th>商品信息</th>
|
||||||
|
<th>状态</th>
|
||||||
<th>操作</th>
|
<th>操作</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -31,8 +39,12 @@
|
||||||
<td>${order.totalPrice}</td>
|
<td>${order.totalPrice}</td>
|
||||||
<td>${order.address}</td>
|
<td>${order.address}</td>
|
||||||
<td>${order.remark}</td>
|
<td>${order.remark}</td>
|
||||||
|
<td>${order.status}</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="/orders?action=delete&id=${order.id}">删除</a>
|
<c:if test="${order.status!= '已发货'}">
|
||||||
|
<a href="/orders?action=deliver&id=${order.id}">
|
||||||
|
点击发货 </a>
|
||||||
|
</c:if>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</c:forEach>
|
</c:forEach>
|
||||||
|
@ -42,4 +54,5 @@
|
||||||
<br>
|
<br>
|
||||||
<a href="/">主页</a>
|
<a href="/">主页</a>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
Reference in New Issue