mirror of
https://github.com/FreeeBird/hotel.git
synced 2025-05-06 19:49:26 +08:00
完成订单信息接口编写
This commit is contained in:
parent
f7ea1c33eb
commit
37dc55809e
@ -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;
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,9 +4,9 @@
|
||||
<resultMap id="BaseResultMap" type="cn.mafangui.hotel.entity.Order">
|
||||
<id column="order_id" jdbcType="INTEGER" property="orderId" />
|
||||
<result column="order_type" jdbcType="VARCHAR" property="orderType" />
|
||||
<result column="user_id" jdbcType="INTEGER" property="userId" />
|
||||
<result column="phone" jdbcType="VARCHAR" property="phone" />
|
||||
<result column="room_type" jdbcType="VARCHAR" property="roomType" />
|
||||
<result column="num_of_room" jdbcType="INTEGER" property="numOfRoom" />
|
||||
<result column="order_date" jdbcType="DATE" property="orderDate" />
|
||||
<result column="order_days" jdbcType="INTEGER" property="orderDays" />
|
||||
<result column="order_status" jdbcType="INTEGER" property="orderStatus" />
|
||||
@ -15,7 +15,7 @@
|
||||
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
order_id, order_type, phone, room_type, num_of_room, order_date, order_days, order_status,
|
||||
order_id, order_type, user_id, phone, room_type, order_date, order_days, order_status,
|
||||
order_cost, create_time, update_time
|
||||
</sql>
|
||||
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||
@ -24,6 +24,17 @@
|
||||
from order_info
|
||||
where order_id = #{orderId,jdbcType=INTEGER}
|
||||
</select>
|
||||
<select id="selectByUserId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from order_info
|
||||
where user_id = #{userId,jdbcType=INTEGER}
|
||||
</select>
|
||||
<select id="selectAll" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from order_info
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
|
||||
delete from order_info
|
||||
where order_id = #{orderId,jdbcType=INTEGER}
|
||||
@ -68,12 +79,8 @@
|
||||
<if test="orderCost != null">
|
||||
order_cost,
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
create_time,
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
update_time,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="orderId != null">
|
||||
@ -103,12 +110,8 @@
|
||||
<if test="orderCost != null">
|
||||
#{orderCost,jdbcType=DOUBLE},
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
#{createTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
#{updateTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
now(),
|
||||
now(),
|
||||
</trim>
|
||||
</insert>
|
||||
<update id="updateByPrimaryKeySelective" parameterType="cn.mafangui.hotel.entity.Order">
|
||||
@ -138,12 +141,7 @@
|
||||
<if test="orderCost != null">
|
||||
order_cost = #{orderCost,jdbcType=DOUBLE},
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
create_time = #{createTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
update_time = #{updateTime,jdbcType=TIMESTAMP},
|
||||
</if>
|
||||
update_time = now(),
|
||||
</set>
|
||||
where order_id = #{orderId,jdbcType=INTEGER}
|
||||
</update>
|
||||
@ -157,8 +155,7 @@
|
||||
order_days = #{orderDays,jdbcType=INTEGER},
|
||||
order_status = #{orderStatus,jdbcType=INTEGER},
|
||||
order_cost = #{orderCost,jdbcType=DOUBLE},
|
||||
create_time = #{createTime,jdbcType=TIMESTAMP},
|
||||
update_time = #{updateTime,jdbcType=TIMESTAMP}
|
||||
update_time = now()
|
||||
where order_id = #{orderId,jdbcType=INTEGER}
|
||||
</update>
|
||||
</mapper>
|
@ -24,12 +24,17 @@
|
||||
from user_info
|
||||
where user_id = #{userId,jdbcType=INTEGER}
|
||||
</select>
|
||||
<select id="selectAllUser" resultMap="BaseResultMap">
|
||||
select * from user_info
|
||||
where username != ''
|
||||
</select>
|
||||
<select id="selectAll" resultMap="BaseResultMap">
|
||||
select * from user_info
|
||||
</select>
|
||||
<select id="selectByUsernameAndPassword" parameterType="String" resultMap="BaseResultMap">
|
||||
select * from user_info
|
||||
where username = #{username,jdbcType=VARCHAR} and password = #{password,jdbcType=VARCHAR}
|
||||
where username != '' and password != '' and
|
||||
username = #{username,jdbcType=VARCHAR} and password = #{password,jdbcType=VARCHAR}
|
||||
</select>
|
||||
<select id="selectByUsername" parameterType="String" resultMap="BaseResultMap">
|
||||
select * from user_info
|
||||
|
Loading…
x
Reference in New Issue
Block a user