Browse Source

update cancel order

master
朱天祥 1 year ago
parent
commit
70f47206b2
3 changed files with 48 additions and 0 deletions
  1. +4
    -0
      src/main/java/cn/edu/ecnu/stu/bookstore/mapper/OrderMapper.java
  2. +21
    -0
      src/main/java/cn/edu/ecnu/stu/bookstore/pojo/OrderBookDO.java
  3. +23
    -0
      src/main/java/cn/edu/ecnu/stu/bookstore/service/impl/OrderService.java

+ 4
- 0
src/main/java/cn/edu/ecnu/stu/bookstore/mapper/OrderMapper.java View File

@ -2,6 +2,7 @@ package cn.edu.ecnu.stu.bookstore.mapper;
import cn.edu.ecnu.stu.bookstore.pojo.Book;
import cn.edu.ecnu.stu.bookstore.pojo.Order;
import cn.edu.ecnu.stu.bookstore.pojo.OrderBookDO;
import cn.edu.ecnu.stu.bookstore.pojo.OrderStatus;
import org.apache.ibatis.annotations.*;
@ -30,4 +31,7 @@ public interface OrderMapper {
int checkOrder(@Param("orderId") String orderId, @Param("buyerId") Integer buyerId);
int selectStatus(@Param("orderId") String orderId);
@Select("select order_id, bookId, count, single_price from t_order_book where order_id = #{orderId}")
List<OrderBookDO> getBookListByOrder(@Param("orderId") String orderId);
}

+ 21
- 0
src/main/java/cn/edu/ecnu/stu/bookstore/pojo/OrderBookDO.java View File

@ -0,0 +1,21 @@
package cn.edu.ecnu.stu.bookstore.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class OrderBookDO {
private String orderId;
private String bookId;
private Integer count;
private BigDecimal singlePrice;
}

+ 23
- 0
src/main/java/cn/edu/ecnu/stu/bookstore/service/impl/OrderService.java View File

@ -2,13 +2,17 @@ package cn.edu.ecnu.stu.bookstore.service.impl;
import cn.edu.ecnu.stu.bookstore.component.AppException;
import cn.edu.ecnu.stu.bookstore.component.Constants;
import cn.edu.ecnu.stu.bookstore.mapper.BookMapper;
import cn.edu.ecnu.stu.bookstore.mapper.OrderMapper;
import cn.edu.ecnu.stu.bookstore.pojo.Order;
import cn.edu.ecnu.stu.bookstore.pojo.OrderBookDO;
import cn.edu.ecnu.stu.bookstore.pojo.OrderStatus;
import cn.edu.ecnu.stu.bookstore.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@ -19,6 +23,13 @@ public class OrderService {
@Autowired
private OrderMapper orderMapper;
@Autowired
@Lazy
private OrderService orderService;
@Autowired
private BookMapper bookMapper;
public List<Order> getOrderList(Integer status) {
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
return orderMapper.select(user.getId(), status == null ? null : OrderStatus.getByValue(status));
@ -28,7 +39,19 @@ public class OrderService {
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if(orderMapper.checkOrder(orderId, user.getId()) != 1)
throw new AppException(Constants.CLIENT_ERROR, Constants.AUTHORITY_ERROR);
Order order = orderMapper.selectById(orderId);
List<OrderBookDO> books = orderMapper.getBookListByOrder(orderId);
orderService.updateOrderAndStockLevel(order, books);
}
@Transactional
public void updateOrderAndStockLevel(Order order, List<OrderBookDO> books) {
String orderId = order.getOrderId();
String storeId = order.getStoreId();
orderMapper.updateOrderStatus(orderId, OrderStatus.CANCEL);
for (OrderBookDO book : books) {
bookMapper.addStockLevel(storeId, book.getBookId(), book.getCount());
}
}
public void add(Order order) {

Loading…
Cancel
Save