删除部门类,修改房间、房型、订单相关接口

This commit is contained in:
freeebird
2018-11-28 18:48:04 +08:00
parent 556e257d45
commit ed0f7f87aa
18 changed files with 189 additions and 198 deletions

View File

@@ -5,6 +5,9 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* 跨域
*/
@Configuration
public class GlobalCrosConfig {
@Bean
@@ -28,4 +31,4 @@ public class GlobalCrosConfig {
}
};
}
}
}

View File

@@ -3,8 +3,10 @@ package cn.mafangui.hotel;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication
@EnableTransactionManagement
@MapperScan(basePackages = "cn.mafangui.hotel.mapper")
public class HotelApplication {

View File

@@ -6,6 +6,7 @@ import cn.mafangui.hotel.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
@@ -87,6 +88,16 @@ public class OrderController {
return orderService.update(order);
}
/**
* 订单支付
* @param orderId
* @return
*/
@RequestMapping(method = RequestMethod.POST,value = "/pay")
public int payOrder(int orderId){
return orderService.payOrder(orderId);
}
/**
* 取消订单
* @param orderId

View File

@@ -1,55 +0,0 @@
package cn.mafangui.hotel.entity;
import java.util.Date;
public class Department {
private Integer departmentId;
private String departmentName;
private String remark;
private Date createTime;
private Date updateTime;
public Integer getDepartmentId() {
return departmentId;
}
public void setDepartmentId(Integer departmentId) {
this.departmentId = departmentId;
}
public String getDepartmentName() {
return departmentName;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName == null ? null : departmentName.trim();
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark == null ? null : remark.trim();
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
}

View File

@@ -0,0 +1,9 @@
package cn.mafangui.hotel.enums;
public enum OrderError {
NONE(0,"没有空房"),
;
OrderError(int code,String status) {
}
}

View File

@@ -1,17 +0,0 @@
package cn.mafangui.hotel.mapper;
import cn.mafangui.hotel.entity.Department;
public interface DepartmentMapper {
int deleteByPrimaryKey(Integer departmentId);
int insert(Department record);
int insertSelective(Department record);
Department selectByPrimaryKey(Integer departmentId);
int updateByPrimaryKeySelective(Department record);
int updateByPrimaryKey(Department record);
}

View File

@@ -1,7 +1,11 @@
package cn.mafangui.hotel.mapper;
import cn.mafangui.hotel.entity.Order;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public interface OrderMapper {
int deleteByPrimaryKey(Integer orderId);
@@ -14,4 +18,12 @@ public interface OrderMapper {
int updateByPrimaryKeySelective(Order record);
int updateByPrimaryKey(Order record);
}
List<Order> selectAll();
List<Order> selectByUserId(Integer userId);
List<Order> selectAllByUser(Integer userId,Integer orderStatus);
}

View File

@@ -23,4 +23,6 @@ public interface RoomMapper {
List<Room> selectByStatus(Integer roomStatus);
List<Room> selectAll();
}
Room randomSelectByTypeAndStatus(Integer typeId,Integer roomStatus);
}

View File

@@ -16,6 +16,8 @@ public interface OrderService {
int update(Order record);
int payOrder(int orderId);
List<Order> selectByUserId(int userId);
List<Order> AllOrders();

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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());
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}