mirror of
				https://github.com/FreeeBird/hotel.git
				synced 2025-11-04 14:34:47 +08:00 
			
		
		
		
	完成订单信息接口编写
This commit is contained in:
		@@ -0,0 +1,62 @@
 | 
			
		||||
package cn.mafangui.hotel.controller;
 | 
			
		||||
 | 
			
		||||
import cn.mafangui.hotel.entity.Order;
 | 
			
		||||
import cn.mafangui.hotel.service.OrderService;
 | 
			
		||||
import cn.mafangui.hotel.utils.StaticString;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.web.bind.annotation.RequestMapping;
 | 
			
		||||
import org.springframework.web.bind.annotation.RestController;
 | 
			
		||||
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
@RestController
 | 
			
		||||
@RequestMapping(value = "/order")
 | 
			
		||||
public class OrderController {
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private OrderService orderService;
 | 
			
		||||
 | 
			
		||||
    @RequestMapping(value = "/add")
 | 
			
		||||
    public int addOrder(String orderType,int userId, String phone, String roomType,
 | 
			
		||||
                        Integer numOfRoom, Date orderDate, Integer orderDays, Integer orderStatus, Double orderCost){
 | 
			
		||||
        Order order = new Order(orderType,userId,phone,roomType,orderDate,orderDays,orderStatus,orderCost);
 | 
			
		||||
        return orderService.insert(order);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @RequestMapping(value = "/delete")
 | 
			
		||||
    public int deleteOrder(int orderId){
 | 
			
		||||
        return orderService.delete(orderId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @RequestMapping(value = "/hide")
 | 
			
		||||
    public int hideOrder(int orderId){
 | 
			
		||||
        Order order = new Order();
 | 
			
		||||
        order.setOrderId(orderId);
 | 
			
		||||
        order.setOrderStatus(StaticString.WAS_DELETE);
 | 
			
		||||
        return orderService.update(order);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @RequestMapping(value = "/update")
 | 
			
		||||
    public int updateOrder(int orderId,String orderType,String roomType,
 | 
			
		||||
                            Date orderDate, Integer orderDays, Integer orderStatus, Double orderCost){
 | 
			
		||||
        Order order = new Order(orderType,roomType,orderDate,orderDays,orderStatus,orderCost);
 | 
			
		||||
        order.setOrderId(orderId);
 | 
			
		||||
        return orderService.update(order);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @RequestMapping(value = "/all")
 | 
			
		||||
    public List<Order> getAllOrder(){
 | 
			
		||||
        return orderService.selectAll();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @RequestMapping(value = "/withUserId")
 | 
			
		||||
    public List<Order> getByUser(int userId){
 | 
			
		||||
        return orderService.selectByUserId(userId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @RequestMapping(value = "/withId")
 | 
			
		||||
    public Order getById(int orderId){
 | 
			
		||||
        return orderService.selectById(orderId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -24,6 +24,9 @@ public class UserController {
 | 
			
		||||
    @RequestMapping(method = RequestMethod.POST,value = "/login")
 | 
			
		||||
    public int userLogin(String username,String password){
 | 
			
		||||
        int result = 0;
 | 
			
		||||
        if (username == null | username == "" | password == null | password == ""){
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
        if (userService.selectByUsernameAndPassword(username,password) != null){
 | 
			
		||||
            result = 1;
 | 
			
		||||
        }
 | 
			
		||||
@@ -92,14 +95,23 @@ public class UserController {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 所有用户
 | 
			
		||||
     * 所有在记录的用户和客户
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    @RequestMapping(value = "/all")
 | 
			
		||||
    public List<User> getAllUser(){
 | 
			
		||||
    public List<User> getAll(){
 | 
			
		||||
        return userService.selectAll();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 所有注册用户
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    @RequestMapping(value = "/allUser")
 | 
			
		||||
    public List<User> getAllUser(){
 | 
			
		||||
        return userService.selectAllUser();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 判断用户名是否存在
 | 
			
		||||
     * @param username
 | 
			
		||||
@@ -115,4 +127,9 @@ public class UserController {
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @RequestMapping(value = "/delete")
 | 
			
		||||
    public int deleteUser(int userId){
 | 
			
		||||
        return userService.deleteUser(userId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -7,11 +7,12 @@ public class Order {
 | 
			
		||||
 | 
			
		||||
    private String orderType;
 | 
			
		||||
 | 
			
		||||
    private int userId;
 | 
			
		||||
 | 
			
		||||
    private String phone;
 | 
			
		||||
 | 
			
		||||
    private String roomType;
 | 
			
		||||
 | 
			
		||||
    private Integer numOfRoom;
 | 
			
		||||
 | 
			
		||||
    private Date orderDate;
 | 
			
		||||
 | 
			
		||||
@@ -25,6 +26,14 @@ public class Order {
 | 
			
		||||
 | 
			
		||||
    private Date updateTime;
 | 
			
		||||
 | 
			
		||||
    public int getUserId() {
 | 
			
		||||
        return userId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setUserId(int userId) {
 | 
			
		||||
        this.userId = userId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Integer getOrderId() {
 | 
			
		||||
        return orderId;
 | 
			
		||||
    }
 | 
			
		||||
@@ -57,14 +66,6 @@ public class Order {
 | 
			
		||||
        this.roomType = roomType == null ? null : roomType.trim();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Integer getNumOfRoom() {
 | 
			
		||||
        return numOfRoom;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setNumOfRoom(Integer numOfRoom) {
 | 
			
		||||
        this.numOfRoom = numOfRoom;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Date getOrderDate() {
 | 
			
		||||
        return orderDate;
 | 
			
		||||
    }
 | 
			
		||||
@@ -112,4 +113,44 @@ public class Order {
 | 
			
		||||
    public void setUpdateTime(Date updateTime) {
 | 
			
		||||
        this.updateTime = updateTime;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Order() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Order(String orderType, int userId, String phone, String roomType, Date orderDate, Integer orderDays, Integer orderStatus, Double orderCost) {
 | 
			
		||||
        this.orderType = orderType;
 | 
			
		||||
        this.userId = userId;
 | 
			
		||||
        this.phone = phone;
 | 
			
		||||
        this.roomType = roomType;
 | 
			
		||||
        this.orderDate = orderDate;
 | 
			
		||||
        this.orderDays = orderDays;
 | 
			
		||||
        this.orderStatus = orderStatus;
 | 
			
		||||
        this.orderCost = orderCost;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Order(String orderType, String roomType, Date orderDate, Integer orderDays, Integer orderStatus, Double orderCost) {
 | 
			
		||||
        this.orderType = orderType;
 | 
			
		||||
        this.roomType = roomType;
 | 
			
		||||
        this.orderDate = orderDate;
 | 
			
		||||
        this.orderDays = orderDays;
 | 
			
		||||
        this.orderStatus = orderStatus;
 | 
			
		||||
        this.orderCost = orderCost;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        return "Order{" +
 | 
			
		||||
                "orderId=" + orderId +
 | 
			
		||||
                ", orderType='" + orderType + '\'' +
 | 
			
		||||
                ", userId=" + userId +
 | 
			
		||||
                ", phone='" + phone + '\'' +
 | 
			
		||||
                ", roomType='" + roomType + '\'' +
 | 
			
		||||
                ", orderDate=" + orderDate +
 | 
			
		||||
                ", orderDays=" + orderDays +
 | 
			
		||||
                ", orderStatus=" + orderStatus +
 | 
			
		||||
                ", orderCost=" + orderCost +
 | 
			
		||||
                ", createTime=" + createTime +
 | 
			
		||||
                ", updateTime=" + updateTime +
 | 
			
		||||
                '}';
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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,10 @@ public interface OrderMapper {
 | 
			
		||||
    int updateByPrimaryKeySelective(Order record);
 | 
			
		||||
 | 
			
		||||
    int updateByPrimaryKey(Order record);
 | 
			
		||||
 | 
			
		||||
    List<Order> selectByUserId(int userId);
 | 
			
		||||
 | 
			
		||||
    List<Order> selectAll();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -25,4 +25,6 @@ public interface UserMapper {
 | 
			
		||||
    User selectByUsername(String username);
 | 
			
		||||
 | 
			
		||||
    List<User> selectAll();
 | 
			
		||||
 | 
			
		||||
    List<User> selectAllUser();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										20
									
								
								src/main/java/cn/mafangui/hotel/service/OrderService.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								src/main/java/cn/mafangui/hotel/service/OrderService.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
package cn.mafangui.hotel.service;
 | 
			
		||||
 | 
			
		||||
import cn.mafangui.hotel.entity.Order;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
public interface OrderService {
 | 
			
		||||
 | 
			
		||||
    int insert(Order order);
 | 
			
		||||
 | 
			
		||||
    int delete(Integer orderId);
 | 
			
		||||
 | 
			
		||||
    Order selectById(Integer orderId);
 | 
			
		||||
 | 
			
		||||
    int update(Order record);
 | 
			
		||||
 | 
			
		||||
    List<Order> selectByUserId(int userId);
 | 
			
		||||
 | 
			
		||||
    List<Order> selectAll();
 | 
			
		||||
}
 | 
			
		||||
@@ -21,4 +21,6 @@ public interface UserService {
 | 
			
		||||
 | 
			
		||||
    List<User> selectAll();
 | 
			
		||||
 | 
			
		||||
    List<User> selectAllUser();
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,46 @@
 | 
			
		||||
package cn.mafangui.hotel.service.impl;
 | 
			
		||||
 | 
			
		||||
import cn.mafangui.hotel.entity.Order;
 | 
			
		||||
import cn.mafangui.hotel.mapper.OrderMapper;
 | 
			
		||||
import cn.mafangui.hotel.service.OrderService;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
public class OrderServiceImpl implements OrderService {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private OrderMapper orderMapper;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int insert(Order order) {
 | 
			
		||||
        return orderMapper.insertSelective(order);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int delete(Integer orderId) {
 | 
			
		||||
        return orderMapper.deleteByPrimaryKey(orderId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public Order selectById(Integer orderId) {
 | 
			
		||||
        return orderMapper.selectByPrimaryKey(orderId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int update(Order order) {
 | 
			
		||||
        return orderMapper.updateByPrimaryKeySelective(order);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<Order> selectByUserId(int userId) {
 | 
			
		||||
        return orderMapper.selectByUserId(userId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<Order> selectAll() {
 | 
			
		||||
        return orderMapper.selectAll();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -47,4 +47,9 @@ public class UserServiceImpl implements UserService {
 | 
			
		||||
    public List<User> selectAll() {
 | 
			
		||||
        return userMapper.selectAll();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<User> selectAllUser() {
 | 
			
		||||
        return userMapper.selectAllUser();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,5 @@
 | 
			
		||||
package cn.mafangui.hotel.utils;
 | 
			
		||||
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
public class StaticString {
 | 
			
		||||
    public static final String CODE = "code";
 | 
			
		||||
    public static final String STATUS = "status";
 | 
			
		||||
@@ -15,13 +13,30 @@ public class StaticString {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 房间状态
 | 
			
		||||
     * 不可用
 | 
			
		||||
     * 空闲可用
 | 
			
		||||
     * 已被预订
 | 
			
		||||
     * 已被入住
 | 
			
		||||
     */
 | 
			
		||||
    public static final int UNAVAILABLE = 0;
 | 
			
		||||
    public static final int AVAILABLE = 1;
 | 
			
		||||
    public static final int OCCUPIED = 0;
 | 
			
		||||
    public static final int IN_USE = -1;
 | 
			
		||||
    public static final int UNAVAILABLE = -2;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public static final int OCCUPIED = 2;
 | 
			
		||||
    public static final int IN_USE = 3;
 | 
			
		||||
    /**
 | 
			
		||||
     * 订单状态
 | 
			
		||||
     * 被用户删除-2
 | 
			
		||||
     * 被取消-1
 | 
			
		||||
     * 未付款0
 | 
			
		||||
     * 已付款1
 | 
			
		||||
     * 已入住2
 | 
			
		||||
     * 超时3
 | 
			
		||||
     */
 | 
			
		||||
    public static final int WAS_DELETE = -2;
 | 
			
		||||
    public static final int WAS_CANCELED = -1;
 | 
			
		||||
    public static final int UNPAID = 0;
 | 
			
		||||
    public static final int PAID = 1;
 | 
			
		||||
    public static final int WAS_USED = 2;
 | 
			
		||||
    public static final int OVERTIME = 3;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user