|
|
@ -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) { |
|
|
|