mirror of
https://github.com/FreeeBird/hotel.git
synced 2025-11-02 21:44:50 +08:00
删除部门类,修改房间、房型、订单相关接口
This commit is contained in:
@@ -16,6 +16,8 @@ public interface OrderService {
|
||||
|
||||
int update(Order record);
|
||||
|
||||
int payOrder(int orderId);
|
||||
|
||||
List<Order> selectByUserId(int userId);
|
||||
|
||||
List<Order> AllOrders();
|
||||
|
||||
@@ -13,4 +13,8 @@ public interface RoomService {
|
||||
List<Room> selectByStatus(int roomStatus);
|
||||
List<Room> selectByType(int typeId);
|
||||
List<Room> selectAll();
|
||||
|
||||
int orderRoom(int typeId);
|
||||
int inRoom(int typeId);
|
||||
int outRoom(int typeId);
|
||||
}
|
||||
|
||||
@@ -19,4 +19,10 @@ public interface RoomTypeService {
|
||||
RoomType selectById(int typeId);
|
||||
|
||||
List<RoomType> findAllType();
|
||||
|
||||
int updateRest(int typeId,int num);
|
||||
|
||||
int addRest(int typeId);
|
||||
|
||||
int minusRest(int typeId);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
package cn.mafangui.hotel.service.impl;
|
||||
|
||||
import cn.mafangui.hotel.entity.Order;
|
||||
import cn.mafangui.hotel.entity.Room;
|
||||
import cn.mafangui.hotel.entity.RoomType;
|
||||
import cn.mafangui.hotel.enums.OrderStatus;
|
||||
import cn.mafangui.hotel.mapper.OrderMapper;
|
||||
import cn.mafangui.hotel.mapper.RoomMapper;
|
||||
import cn.mafangui.hotel.mapper.RoomTypeMapper;
|
||||
import cn.mafangui.hotel.service.OrderService;
|
||||
import cn.mafangui.hotel.service.RoomService;
|
||||
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 java.util.List;
|
||||
|
||||
@@ -13,9 +21,18 @@ public class OrderServiceImpl implements OrderService {
|
||||
|
||||
@Autowired
|
||||
private OrderMapper orderMapper;
|
||||
@Autowired
|
||||
private RoomTypeService roomTypeService;
|
||||
@Autowired
|
||||
private RoomService roomService;
|
||||
|
||||
@Override
|
||||
public int insert(Order order) {
|
||||
return orderMapper.insert(order);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addOrder(Order order) {
|
||||
return orderMapper.insertSelective(order);
|
||||
}
|
||||
|
||||
@@ -34,18 +51,37 @@ public class OrderServiceImpl implements OrderService {
|
||||
return orderMapper.updateByPrimaryKeySelective(order);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单支付
|
||||
* 1.更改订单状态
|
||||
* 2.修改房型余量
|
||||
* 3.修改房间状态
|
||||
* @param orderId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int payOrder(int orderId) {
|
||||
Order order = orderMapper.selectByPrimaryKey(orderId);
|
||||
if (order == null | order.getOrderStatus() != OrderStatus.UNPAID.getCode()) return -1;
|
||||
if (roomTypeService.updateRest(order.getRoomTypeId(),-1) != 1) return -1;
|
||||
return roomService.orderRoom(order.getRoomTypeId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Order> selectByUserId(int userId) {
|
||||
return orderMapper.selectByUserId(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Order> selectAll() {
|
||||
public List<Order> AllOrders() {
|
||||
return orderMapper.selectAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Order> userSelectAll(int userId) {
|
||||
return orderMapper.userSelectAll(userId);
|
||||
public List<Order> UsersAllOrders(int userId) {
|
||||
return orderMapper.selectAllByUser(userId, OrderStatus.WAS_DELETED.getCode());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package cn.mafangui.hotel.service.impl;
|
||||
|
||||
import cn.mafangui.hotel.entity.Room;
|
||||
import cn.mafangui.hotel.enums.RoomStatus;
|
||||
import cn.mafangui.hotel.mapper.RoomMapper;
|
||||
import cn.mafangui.hotel.service.RoomService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -47,4 +49,30 @@ public class RoomServiceImpl implements RoomService {
|
||||
public List<Room> selectAll() {
|
||||
return roomMapper.selectAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public int orderRoom(int typeId) {
|
||||
Room room = roomMapper.randomSelectByTypeAndStatus(typeId,RoomStatus.AVAILABLE.getCode());
|
||||
if (room == null) return -1;
|
||||
room.setRoomStatus(RoomStatus.ORDERED.getCode());
|
||||
return roomMapper.updateByPrimaryKeySelective(room);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int inRoom(int typeId) {
|
||||
Room room = roomMapper.randomSelectByTypeAndStatus(typeId,RoomStatus.ORDERED.getCode());
|
||||
if (room == null) return -1;
|
||||
room.setRoomStatus(RoomStatus.IN_USE.getCode());
|
||||
return roomMapper.updateByPrimaryKeySelective(room);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int outRoom(int typeId) {
|
||||
Room room = roomMapper.randomSelectByTypeAndStatus(typeId,RoomStatus.IN_USE.getCode());
|
||||
if (room == null) return -1;
|
||||
room.setRoomStatus(RoomStatus.AVAILABLE.getCode());
|
||||
return roomMapper.updateByPrimaryKeySelective(room);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,4 +43,25 @@ public class RoomTypeServiceImpl implements RoomTypeService {
|
||||
public List<RoomType> findAllType() {
|
||||
return roomTypeMapper.selectAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateRest(int typeId, int num) {
|
||||
RoomType rt =roomTypeMapper.selectByPrimaryKey(typeId);
|
||||
rt.setTypeId(rt.getRest() + num);
|
||||
return roomTypeMapper.updateByPrimaryKeySelective(rt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addRest(int typeId) {
|
||||
RoomType rt =roomTypeMapper.selectByPrimaryKey(typeId);
|
||||
rt.setTypeId(rt.getRest() +1);
|
||||
return roomTypeMapper.updateByPrimaryKeySelective(rt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int minusRest(int typeId) {
|
||||
RoomType rt =roomTypeMapper.selectByPrimaryKey(typeId);
|
||||
rt.setTypeId(rt.getRest() -1);
|
||||
return roomTypeMapper.updateByPrimaryKeySelective(rt);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user