From fe8d5e521a1d4b707c8d7d99733842fefb9f491c Mon Sep 17 00:00:00 2001 From: freeebird <1032796097@qq.com> Date: Thu, 29 Nov 2018 12:08:38 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E6=94=AF=E4=BB=98=E5=AE=8C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hotel/service/impl/OrderServiceImpl.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/cn/mafangui/hotel/service/impl/OrderServiceImpl.java b/src/main/java/cn/mafangui/hotel/service/impl/OrderServiceImpl.java index cfc208c..bb4876d 100644 --- a/src/main/java/cn/mafangui/hotel/service/impl/OrderServiceImpl.java +++ b/src/main/java/cn/mafangui/hotel/service/impl/OrderServiceImpl.java @@ -13,6 +13,7 @@ import cn.mafangui.hotel.service.RoomTypeService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.interceptor.TransactionAspectSupport; import java.util.List; @@ -63,9 +64,23 @@ public class OrderServiceImpl implements OrderService { @Transactional public int payOrder(int orderId) { Order order = orderMapper.selectByPrimaryKey(orderId); - if (order == null | order.getOrderStatus() != OrderStatus.UNPAID.getCode()) return -3; - if (roomTypeService.updateRest(order.getRoomTypeId(),-1) != 1) return -2; - return roomService.orderRoom(order.getRoomTypeId()); + if (order == null | order.getOrderStatus() != OrderStatus.UNPAID.getCode()) { + return -3; + } + if (roomTypeService.updateRest(order.getRoomTypeId(),-1) != 1){ + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + return -2; + } + if (roomService.orderRoom(order.getRoomTypeId()) != 1){ + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + return -1; + } + order.setOrderStatus(OrderStatus.PAID.getCode()); + if (orderMapper.updateByPrimaryKeySelective(order) != 1){ + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + return 0; + } + return 1; } @Override