mirror of
https://github.com/FreeeBird/hotel.git
synced 2025-11-02 05:24:46 +08:00
枚举类编写
This commit is contained in:
@@ -17,17 +17,38 @@ public class RoomTypeController {
|
||||
private RoomTypeService roomTypeService;
|
||||
|
||||
|
||||
/**
|
||||
* 所有房型
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/all")
|
||||
public List<RoomType> getAllRoomType(){
|
||||
return roomTypeService.findAllType();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查找房型
|
||||
* @param typeId
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/withId")
|
||||
public RoomType getById(int typeId){
|
||||
return roomTypeService.selectById(typeId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加房型
|
||||
* @param roomType
|
||||
* @param price
|
||||
* @param discount
|
||||
* @param area
|
||||
* @param bedNum
|
||||
* @param bedSize
|
||||
* @param window
|
||||
* @param remark
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST,value = "/add")
|
||||
public int addRoomType(String roomType,Double price,Double discount,int area,
|
||||
int bedNum,String bedSize,int window,String remark){
|
||||
@@ -38,6 +59,20 @@ public class RoomTypeController {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改房型
|
||||
* @param typeId
|
||||
* @param roomType
|
||||
* @param price
|
||||
* @param discount
|
||||
* @param area
|
||||
* @param bedNum
|
||||
* @param bedSize
|
||||
* @param window
|
||||
* @param rest
|
||||
* @param remark
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST,value = "/update")
|
||||
public int updateRoomType(int typeId,String roomType,Double price,Double discount,int area,
|
||||
int bedNum,String bedSize,int window,int rest,String remark){
|
||||
@@ -49,6 +84,11 @@ public class RoomTypeController {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除房型
|
||||
* @param typeId
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST,value = "/delete")
|
||||
public int deleteRoomType(int typeId){
|
||||
int result = 0;
|
||||
@@ -56,4 +96,13 @@ public class RoomTypeController {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找有余量的房型
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/restAll")
|
||||
public List<RoomType> findAllRestRoomType(){
|
||||
return roomTypeService.findAllRestType();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -127,6 +127,11 @@ public class UserController {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据username查找用户
|
||||
* @param username
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST,value = "/withUsername")
|
||||
public User getByUsername(String username){
|
||||
User user = userService.selectByUsername(username);
|
||||
@@ -134,11 +139,21 @@ public class UserController {
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查找用户
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.POST,value = "/withId")
|
||||
public User getById(int userId){
|
||||
return userService.selectById(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/delete")
|
||||
public int deleteUser(int userId){
|
||||
return userService.deleteUser(userId);
|
||||
|
||||
@@ -3,7 +3,27 @@ package cn.mafangui.hotel.enums;
|
||||
public enum OrderError {
|
||||
NONE(0,"没有空房"),
|
||||
;
|
||||
private int code;
|
||||
private String status;
|
||||
|
||||
OrderError(int code,String status) {
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
OrderError(int code, String status) {
|
||||
this.code = code;
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,5 +29,7 @@ public enum OrderStatus {
|
||||
}
|
||||
|
||||
OrderStatus(int code, String status) {
|
||||
this.code = code;
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ public enum Role {
|
||||
}
|
||||
|
||||
Role(String value, String role) {
|
||||
this.value = value;
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,5 +27,7 @@ public enum RoomStatus {
|
||||
|
||||
|
||||
RoomStatus(int code,String status) {
|
||||
this.code = code;
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.mafangui.hotel.mapper;
|
||||
|
||||
import cn.mafangui.hotel.entity.Order;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
@@ -23,7 +24,7 @@ public interface OrderMapper {
|
||||
|
||||
List<Order> selectByUserId(Integer userId);
|
||||
|
||||
List<Order> selectAllByUser(Integer userId,Integer orderStatus);
|
||||
List<Order> selectAllByUser(@Param("userId") Integer userId,@Param("orderStatus") Integer orderStatus);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.mafangui.hotel.mapper;
|
||||
|
||||
import cn.mafangui.hotel.entity.Room;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
@@ -24,5 +25,5 @@ public interface RoomMapper {
|
||||
|
||||
List<Room> selectAll();
|
||||
|
||||
Room randomSelectByTypeAndStatus(Integer typeId,Integer roomStatus);
|
||||
Room randomSelectByTypeAndStatus(@Param("typeId") Integer typeId,@Param("roomStatus") Integer roomStatus);
|
||||
}
|
||||
|
||||
@@ -22,4 +22,6 @@ public interface RoomTypeMapper {
|
||||
List<RoomType> selectAll();
|
||||
|
||||
RoomType selectByRoomType(String roomType);
|
||||
}
|
||||
|
||||
List<RoomType> selectAllWithRest();
|
||||
}
|
||||
|
||||
@@ -25,4 +25,6 @@ public interface RoomTypeService {
|
||||
int addRest(int typeId);
|
||||
|
||||
int minusRest(int typeId);
|
||||
|
||||
List<RoomType> findAllRestType();
|
||||
}
|
||||
|
||||
@@ -53,9 +53,9 @@ public class OrderServiceImpl implements OrderService {
|
||||
|
||||
/**
|
||||
* 订单支付
|
||||
* 1.更改订单状态
|
||||
* 2.修改房型余量
|
||||
* 3.修改房间状态
|
||||
* 1.更改订单状态 -3
|
||||
* 2.修改房型余量 -2
|
||||
* 3.修改房间状态 -1
|
||||
* @param orderId
|
||||
* @return
|
||||
*/
|
||||
@@ -63,8 +63,8 @@ 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 -1;
|
||||
if (roomTypeService.updateRest(order.getRoomTypeId(),-1) != 1) return -1;
|
||||
if (order == null | order.getOrderStatus() != OrderStatus.UNPAID.getCode()) return -3;
|
||||
if (roomTypeService.updateRest(order.getRoomTypeId(),-1) != 1) return -2;
|
||||
return roomService.orderRoom(order.getRoomTypeId());
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,8 @@ public class RoomTypeServiceImpl implements RoomTypeService {
|
||||
@Override
|
||||
public int updateRest(int typeId, int num) {
|
||||
RoomType rt =roomTypeMapper.selectByPrimaryKey(typeId);
|
||||
rt.setTypeId(rt.getRest() + num);
|
||||
if (rt.getRest() <= 0) return -1;
|
||||
rt.setRest(rt.getRest() + num);
|
||||
return roomTypeMapper.updateByPrimaryKeySelective(rt);
|
||||
}
|
||||
|
||||
@@ -64,4 +65,9 @@ public class RoomTypeServiceImpl implements RoomTypeService {
|
||||
rt.setTypeId(rt.getRest() -1);
|
||||
return roomTypeMapper.updateByPrimaryKeySelective(rt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RoomType> findAllRestType() {
|
||||
return roomTypeMapper.selectAllWithRest();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user