From 54e3a9a1f93d1e58a0c5265f9712e526669788ab Mon Sep 17 00:00:00 2001 From: wyz Date: Mon, 11 Jan 2021 13:44:50 +0800 Subject: [PATCH] done --- README.md | 20 ++ pom.xml | 46 ++-- .../com/wyz/demo/controller/OrderController.java | 47 ++++- .../com/wyz/demo/controller/UserController.java | 2 +- .../java/com/wyz/demo/dao/OrderRepository.java | 16 +- src/main/java/com/wyz/demo/dao/UserRepository.java | 6 +- src/main/java/com/wyz/demo/dto/OrderDTO.java | 10 +- .../java/com/wyz/demo/service/OrderService.java | 26 ++- .../wyz/demo/service/impl/OrderServiceImpl.java | 67 +++++- src/main/java/com/wyz/demo/vo/CommonOrderVO.java | 16 ++ src/main/java/com/wyz/demo/vo/DetailOrderVO.java | 17 ++ src/main/java/com/wyz/demo/vo/OrderVO.java | 18 -- src/main/java/com/wyz/demo/vo/SelfOrderVO.java | 18 ++ src/main/resources/mapper/OrderMapper.xml | 20 +- src/main/resources/mapper/UserMapper.xml | 9 +- src/main/resources/static/BookInfo.html | 3 +- src/main/resources/static/Cart.html | 3 +- src/main/resources/static/FriendLink.html | 9 +- src/main/resources/static/Index.html | 145 ++++++++++--- src/main/resources/static/Login.html | 3 +- src/main/resources/static/NewOrder.html | 33 ++- src/main/resources/static/Order.html | 16 +- src/main/resources/static/OrderInfo.html | 188 ++++++++++------- src/main/resources/static/PickedOrder.html | 232 +++++++++++++++++++++ src/main/resources/static/Register.html | 3 +- src/main/resources/static/UserInfo.html | 7 +- 26 files changed, 764 insertions(+), 216 deletions(-) create mode 100644 src/main/java/com/wyz/demo/vo/CommonOrderVO.java create mode 100644 src/main/java/com/wyz/demo/vo/DetailOrderVO.java delete mode 100644 src/main/java/com/wyz/demo/vo/OrderVO.java create mode 100644 src/main/java/com/wyz/demo/vo/SelfOrderVO.java create mode 100644 src/main/resources/static/PickedOrder.html diff --git a/README.md b/README.md index e743da0..193cc1b 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,26 @@ +## 自定义订单状态 + +0:未接单 unpick + +1:已接单 pick + +2:已送达 arrived + +3:已完成 completed + +4:已取消 canceled + +5:已中止 terminated + + + + + + + ## 后端接收ajax数据 2021/01/08 diff --git a/pom.xml b/pom.xml index b56a6ea..40a7f54 100644 --- a/pom.xml +++ b/pom.xml @@ -70,29 +70,29 @@ spring-boot-maven-plugin - - - com.spotify - dockerfile-maven-plugin - 1.4.6 - - - default - - build - push - - - - - betaberry/common - 0.0.1 - - app.jar - - - - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/com/wyz/demo/controller/OrderController.java b/src/main/java/com/wyz/demo/controller/OrderController.java index 1032cda..8d7ad5d 100644 --- a/src/main/java/com/wyz/demo/controller/OrderController.java +++ b/src/main/java/com/wyz/demo/controller/OrderController.java @@ -2,13 +2,12 @@ package com.wyz.demo.controller; import com.wyz.demo.dto.OrderDTO; import com.wyz.demo.service.OrderService; -import com.wyz.demo.vo.OrderVO; +import com.wyz.demo.vo.CommonOrderVO; +import com.wyz.demo.vo.DetailOrderVO; +import com.wyz.demo.vo.SelfOrderVO; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpSession; import java.util.List; @@ -24,16 +23,16 @@ public class OrderController { /** - * 查询订单 + * 查询某个用户自己的订单 */ - @RequestMapping(value = "/getAll", produces = "application/json") - public List getAll(HttpSession sess){ + @RequestMapping(value = "/own", produces = "application/json") + public List getOwnOrders(HttpSession sess){ String username = (String)sess.getAttribute("username"); if(username==null){ log.error("{session中没有用户名:还未登录}"); return null; }else{ - List orders = orderService.getAll(username); + List orders = orderService.getOrdersByUsername(username); return orders; } } @@ -48,4 +47,34 @@ public class OrderController { orderService.addOrder(orderDTO,sess); } + + /** + * 返回全部待接单的订单,在主页上显示 + */ + @RequestMapping(value = "/all") + public List getAllUnpickOrders(){ + return orderService.getAllUnpickOrders(); + } + + + /** + * 获取订单详情 + */ + @GetMapping(value = "/detail") + public DetailOrderVO getDetailOrder(@RequestParam("orderId") int orderId){ + log.info("请求订单号:{} 的详细信息",orderId); + + return orderService.getDetailOrder(orderId); + } + + + /** + * 接单 + */ + @RequestMapping(value = "/pick") + public void pickOrder(@RequestParam("orderId") int orderId, HttpSession sess){ + orderService.pickOrder(orderId, sess); + } + + } diff --git a/src/main/java/com/wyz/demo/controller/UserController.java b/src/main/java/com/wyz/demo/controller/UserController.java index 0c4730a..426ca17 100644 --- a/src/main/java/com/wyz/demo/controller/UserController.java +++ b/src/main/java/com/wyz/demo/controller/UserController.java @@ -58,7 +58,7 @@ public class UserController { @PostMapping(value = "/login") public Message login(@RequestBody UserDTO u, HttpServletResponse resp, HttpSession sess){ - log.info("this is userDTO: {}",u); + log.info("请求登录的-userDTO: {}",u); Message msg = userService.checkUser(u, resp, sess); return msg; diff --git a/src/main/java/com/wyz/demo/dao/OrderRepository.java b/src/main/java/com/wyz/demo/dao/OrderRepository.java index 4838208..118afcd 100644 --- a/src/main/java/com/wyz/demo/dao/OrderRepository.java +++ b/src/main/java/com/wyz/demo/dao/OrderRepository.java @@ -1,6 +1,7 @@ package com.wyz.demo.dao; import com.wyz.demo.po.OrderPO; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -8,10 +9,23 @@ public interface OrderRepository { // 根据用户id查订单 - public List getOrders(int sender_id); + public List getOrdersByUserId(int sender_id); // 提交订单 public void addOrder(OrderPO orderPO); + + // 返回所有 未接单 的订单 + public List getAllUnpickOrders(); + + + // 根据id查订单 + public OrderPO getOrderById(int id); + + + // 有用户接单 + public void pickOrder(@Param("id") int order_id, @Param("receiver_id")int receiver_id); + + } diff --git a/src/main/java/com/wyz/demo/dao/UserRepository.java b/src/main/java/com/wyz/demo/dao/UserRepository.java index 72feee0..cc2222d 100644 --- a/src/main/java/com/wyz/demo/dao/UserRepository.java +++ b/src/main/java/com/wyz/demo/dao/UserRepository.java @@ -14,7 +14,7 @@ public interface UserRepository { /** * 判断用户名是否存在 - * 根据用户名获取用户 + * 根据 username 获取用户 * @return */ public UserPO getUserByUsername(String username); @@ -35,8 +35,8 @@ public interface UserRepository { public String getUsernameById(int id); -// // 查找用户: 根据id -// public UserPO findUserById(int id); + // 查找用户: 根据id 获取 用户 + public UserPO getUserById(int id); } diff --git a/src/main/java/com/wyz/demo/dto/OrderDTO.java b/src/main/java/com/wyz/demo/dto/OrderDTO.java index 8670429..2138db0 100644 --- a/src/main/java/com/wyz/demo/dto/OrderDTO.java +++ b/src/main/java/com/wyz/demo/dto/OrderDTO.java @@ -7,9 +7,9 @@ import java.util.Date; @Data public class OrderDTO implements Serializable { - public String description; // 订单描述 - public Date when; // 快递要什么时候送到 - public String location; // 快递在哪里 - public int price; // 价钱 - public String comment; // 备注 + String description; // 订单描述 + Date when; // 快递要什么时候送到 + String location; // 快递在哪里 + int price; // 价钱 + String comment; // 备注 } diff --git a/src/main/java/com/wyz/demo/service/OrderService.java b/src/main/java/com/wyz/demo/service/OrderService.java index 34a7606..0c0d350 100644 --- a/src/main/java/com/wyz/demo/service/OrderService.java +++ b/src/main/java/com/wyz/demo/service/OrderService.java @@ -1,7 +1,10 @@ package com.wyz.demo.service; import com.wyz.demo.dto.OrderDTO; -import com.wyz.demo.vo.OrderVO; +import com.wyz.demo.vo.CommonOrderVO; +import com.wyz.demo.vo.DetailOrderVO; +import com.wyz.demo.vo.SelfOrderVO; +import org.springframework.web.bind.annotation.RequestParam; import javax.servlet.http.HttpSession; import java.util.List; @@ -9,13 +12,30 @@ import java.util.List; public interface OrderService { /** - * 获取全部订单 + * 获取某个用户自己的全部订单 */ - public List getAll(String username); + public List getOrdersByUsername(String username); /** * 提交订单 */ public void addOrder(OrderDTO orderDTO, HttpSession sess); + + + /** + * 获取所有未接单的订单,在主页上显示 + */ + public List getAllUnpickOrders(); + + + /** + * 获取订单详情页 + */ + public DetailOrderVO getDetailOrder(int orderId); + + /** + * 接单 + */ + public void pickOrder(int order_id, HttpSession sess); } diff --git a/src/main/java/com/wyz/demo/service/impl/OrderServiceImpl.java b/src/main/java/com/wyz/demo/service/impl/OrderServiceImpl.java index 0dbf734..beb0fee 100644 --- a/src/main/java/com/wyz/demo/service/impl/OrderServiceImpl.java +++ b/src/main/java/com/wyz/demo/service/impl/OrderServiceImpl.java @@ -4,8 +4,11 @@ import com.wyz.demo.dao.OrderRepository; import com.wyz.demo.dao.UserRepository; import com.wyz.demo.dto.OrderDTO; import com.wyz.demo.po.OrderPO; +import com.wyz.demo.po.UserPO; import com.wyz.demo.service.OrderService; -import com.wyz.demo.vo.OrderVO; +import com.wyz.demo.vo.CommonOrderVO; +import com.wyz.demo.vo.DetailOrderVO; +import com.wyz.demo.vo.SelfOrderVO; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -30,14 +33,14 @@ public class OrderServiceImpl implements OrderService { * @Param username 用户名 */ @Override - public List getAll(String username) { + public List getOrdersByUsername(String username) { int sender_id = userRepository.getIdByUsername(username); - List orders = orderRepository.getOrders(sender_id); + List orders = orderRepository.getOrdersByUserId(sender_id); - List res = new ArrayList<>(); + List res = new ArrayList<>(); for (OrderPO orderPO : orders) { - OrderVO orderVO = new OrderVO(); + SelfOrderVO orderVO = new SelfOrderVO(); orderVO.setTimestamp(orderPO.getTimestamp()); orderVO.setDescription(orderPO.getDescription()); @@ -69,4 +72,58 @@ public class OrderServiceImpl implements OrderService { orderRepository.addOrder(orderPO); } + + @Override + public List getAllUnpickOrders() { + + List orderPOs = orderRepository.getAllUnpickOrders(); + + List commonOrderVOs = new ArrayList<>(); + + for (OrderPO orderPO : orderPOs) { +// log.info("获取全部订单:{}",orderPO); + CommonOrderVO commonOrderVO = new CommonOrderVO(); + + + commonOrderVO.setId(orderPO.getId()); + commonOrderVO.setDescription(orderPO.getDescription()); + commonOrderVO.setWhen(orderPO.getWhen()); + commonOrderVO.setLocation(orderPO.getLocation()); + commonOrderVO.setSender(userRepository.getUsernameById(orderPO.getSenderId())); + commonOrderVO.setPrice(orderPO.getPrice()); + + commonOrderVOs.add(commonOrderVO); + } + + return commonOrderVOs; + } + + @Override + public DetailOrderVO getDetailOrder(int orderId) { + OrderPO orderPO = orderRepository.getOrderById(orderId); + UserPO userPO = userRepository.getUserById(orderPO.getSenderId()); + + + DetailOrderVO detailOrderVO = new DetailOrderVO(); + + detailOrderVO.setDescription(orderPO.getDescription()); + detailOrderVO.setWhen(orderPO.getWhen()); + detailOrderVO.setLocation(orderPO.getLocation()); + detailOrderVO.setSender(userPO.getUsername()); + detailOrderVO.setPhone(userPO.getPhone()); + detailOrderVO.setComment(orderPO.getComment()); + detailOrderVO.setPrice(orderPO.getPrice()); + + + return detailOrderVO; + } + + @Override + public void pickOrder(int order_id, HttpSession sess) { + String receiver = (String)sess.getAttribute("username"); + int receiver_id = userRepository.getIdByUsername(receiver); + orderRepository.pickOrder(order_id, receiver_id); + } + + } diff --git a/src/main/java/com/wyz/demo/vo/CommonOrderVO.java b/src/main/java/com/wyz/demo/vo/CommonOrderVO.java new file mode 100644 index 0000000..9e8b441 --- /dev/null +++ b/src/main/java/com/wyz/demo/vo/CommonOrderVO.java @@ -0,0 +1,16 @@ +package com.wyz.demo.vo; + + +import lombok.Data; + +import java.util.Date; + +@Data +public class CommonOrderVO { + int id; + String description; + Date when; + String location; + String sender; + int price; +} diff --git a/src/main/java/com/wyz/demo/vo/DetailOrderVO.java b/src/main/java/com/wyz/demo/vo/DetailOrderVO.java new file mode 100644 index 0000000..9b302d3 --- /dev/null +++ b/src/main/java/com/wyz/demo/vo/DetailOrderVO.java @@ -0,0 +1,17 @@ +package com.wyz.demo.vo; + + +import lombok.Data; + +import java.util.Date; + +@Data +public class DetailOrderVO { + String description; + Date when; + String location; + String sender; + String phone; + String comment; + int price; +} diff --git a/src/main/java/com/wyz/demo/vo/OrderVO.java b/src/main/java/com/wyz/demo/vo/OrderVO.java deleted file mode 100644 index 5f439b9..0000000 --- a/src/main/java/com/wyz/demo/vo/OrderVO.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.wyz.demo.vo; - - -import lombok.Data; - -import java.util.Date; - -@Data -public class OrderVO { - Date timestamp; - String description; - int price; - String receiver; - String status; -} - - - diff --git a/src/main/java/com/wyz/demo/vo/SelfOrderVO.java b/src/main/java/com/wyz/demo/vo/SelfOrderVO.java new file mode 100644 index 0000000..12b7392 --- /dev/null +++ b/src/main/java/com/wyz/demo/vo/SelfOrderVO.java @@ -0,0 +1,18 @@ +package com.wyz.demo.vo; + + +import lombok.Data; + +import java.util.Date; + +@Data +public class SelfOrderVO { + Date timestamp; + String description; + int price; + String receiver; + String status; +} + + + diff --git a/src/main/resources/mapper/OrderMapper.xml b/src/main/resources/mapper/OrderMapper.xml index 5aa94e3..27a9d63 100644 --- a/src/main/resources/mapper/OrderMapper.xml +++ b/src/main/resources/mapper/OrderMapper.xml @@ -22,13 +22,25 @@ - select * from `order` where sender_id = #{sender_id} - - - + + + + + + diff --git a/src/main/resources/mapper/UserMapper.xml b/src/main/resources/mapper/UserMapper.xml index fd4db79..db44696 100644 --- a/src/main/resources/mapper/UserMapper.xml +++ b/src/main/resources/mapper/UserMapper.xml @@ -7,21 +7,24 @@ - insert into user (username,password,phone) values (#{username},#{password}, #{phone}) + insert into `user` (username,password,phone) values (#{username},#{password}, #{phone}) + \ No newline at end of file diff --git a/src/main/resources/static/BookInfo.html b/src/main/resources/static/BookInfo.html index 6a71980..54e23b1 100644 --- a/src/main/resources/static/BookInfo.html +++ b/src/main/resources/static/BookInfo.html @@ -72,9 +72,10 @@