完成订单信息接口编写

This commit is contained in:
freeebird 2018-11-16 10:45:29 +08:00
parent f7ea1c33eb
commit 37dc55809e
12 changed files with 261 additions and 39 deletions

View File

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

View File

@ -24,6 +24,9 @@ public class UserController {
@RequestMapping(method = RequestMethod.POST,value = "/login") @RequestMapping(method = RequestMethod.POST,value = "/login")
public int userLogin(String username,String password){ public int userLogin(String username,String password){
int result = 0; int result = 0;
if (username == null | username == "" | password == null | password == ""){
return -1;
}
if (userService.selectByUsernameAndPassword(username,password) != null){ if (userService.selectByUsernameAndPassword(username,password) != null){
result = 1; result = 1;
} }
@ -92,14 +95,23 @@ public class UserController {
} }
/** /**
* 所有用户 * 所有在记录的户和客
* @return * @return
*/ */
@RequestMapping(value = "/all") @RequestMapping(value = "/all")
public List<User> getAllUser(){ public List<User> getAll(){
return userService.selectAll(); return userService.selectAll();
} }
/**
* 所有注册用户
* @return
*/
@RequestMapping(value = "/allUser")
public List<User> getAllUser(){
return userService.selectAllUser();
}
/** /**
* 判断用户名是否存在 * 判断用户名是否存在
* @param username * @param username
@ -115,4 +127,9 @@ public class UserController {
return result; return result;
} }
@RequestMapping(value = "/delete")
public int deleteUser(int userId){
return userService.deleteUser(userId);
}
} }

View File

@ -7,11 +7,12 @@ public class Order {
private String orderType; private String orderType;
private int userId;
private String phone; private String phone;
private String roomType; private String roomType;
private Integer numOfRoom;
private Date orderDate; private Date orderDate;
@ -25,6 +26,14 @@ public class Order {
private Date updateTime; private Date updateTime;
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public Integer getOrderId() { public Integer getOrderId() {
return orderId; return orderId;
} }
@ -57,14 +66,6 @@ public class Order {
this.roomType = roomType == null ? null : roomType.trim(); this.roomType = roomType == null ? null : roomType.trim();
} }
public Integer getNumOfRoom() {
return numOfRoom;
}
public void setNumOfRoom(Integer numOfRoom) {
this.numOfRoom = numOfRoom;
}
public Date getOrderDate() { public Date getOrderDate() {
return orderDate; return orderDate;
} }
@ -112,4 +113,44 @@ public class Order {
public void setUpdateTime(Date updateTime) { public void setUpdateTime(Date updateTime) {
this.updateTime = 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 +
'}';
}
} }

View File

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

View File

@ -25,4 +25,6 @@ public interface UserMapper {
User selectByUsername(String username); User selectByUsername(String username);
List<User> selectAll(); List<User> selectAll();
List<User> selectAllUser();
} }

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

View File

@ -21,4 +21,6 @@ public interface UserService {
List<User> selectAll(); List<User> selectAll();
List<User> selectAllUser();
} }

View File

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

View File

@ -47,4 +47,9 @@ public class UserServiceImpl implements UserService {
public List<User> selectAll() { public List<User> selectAll() {
return userMapper.selectAll(); return userMapper.selectAll();
} }
@Override
public List<User> selectAllUser() {
return userMapper.selectAllUser();
}
} }

View File

@ -1,7 +1,5 @@
package cn.mafangui.hotel.utils; package cn.mafangui.hotel.utils;
import java.util.Map;
public class StaticString { public class StaticString {
public static final String CODE = "code"; public static final String CODE = "code";
public static final String STATUS = "status"; 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 AVAILABLE = 1;
public static final int OCCUPIED = 0; public static final int OCCUPIED = 2;
public static final int IN_USE = -1; public static final int IN_USE = 3;
public static final int UNAVAILABLE = -2; /**
* 订单状态
* 被用户删除-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;
} }

View File

@ -4,9 +4,9 @@
<resultMap id="BaseResultMap" type="cn.mafangui.hotel.entity.Order"> <resultMap id="BaseResultMap" type="cn.mafangui.hotel.entity.Order">
<id column="order_id" jdbcType="INTEGER" property="orderId" /> <id column="order_id" jdbcType="INTEGER" property="orderId" />
<result column="order_type" jdbcType="VARCHAR" property="orderType" /> <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="phone" jdbcType="VARCHAR" property="phone" />
<result column="room_type" jdbcType="VARCHAR" property="roomType" /> <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_date" jdbcType="DATE" property="orderDate" />
<result column="order_days" jdbcType="INTEGER" property="orderDays" /> <result column="order_days" jdbcType="INTEGER" property="orderDays" />
<result column="order_status" jdbcType="INTEGER" property="orderStatus" /> <result column="order_status" jdbcType="INTEGER" property="orderStatus" />
@ -15,7 +15,7 @@
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
</resultMap> </resultMap>
<sql id="Base_Column_List"> <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 order_cost, create_time, update_time
</sql> </sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
@ -24,6 +24,17 @@
from order_info from order_info
where order_id = #{orderId,jdbcType=INTEGER} where order_id = #{orderId,jdbcType=INTEGER}
</select> </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 id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from order_info delete from order_info
where order_id = #{orderId,jdbcType=INTEGER} where order_id = #{orderId,jdbcType=INTEGER}
@ -68,12 +79,8 @@
<if test="orderCost != null"> <if test="orderCost != null">
order_cost, order_cost,
</if> </if>
<if test="createTime != null">
create_time, create_time,
</if>
<if test="updateTime != null">
update_time, update_time,
</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="orderId != null"> <if test="orderId != null">
@ -103,12 +110,8 @@
<if test="orderCost != null"> <if test="orderCost != null">
#{orderCost,jdbcType=DOUBLE}, #{orderCost,jdbcType=DOUBLE},
</if> </if>
<if test="createTime != null"> now(),
#{createTime,jdbcType=TIMESTAMP}, now(),
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
</trim> </trim>
</insert> </insert>
<update id="updateByPrimaryKeySelective" parameterType="cn.mafangui.hotel.entity.Order"> <update id="updateByPrimaryKeySelective" parameterType="cn.mafangui.hotel.entity.Order">
@ -138,12 +141,7 @@
<if test="orderCost != null"> <if test="orderCost != null">
order_cost = #{orderCost,jdbcType=DOUBLE}, order_cost = #{orderCost,jdbcType=DOUBLE},
</if> </if>
<if test="createTime != null"> update_time = now(),
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
</set> </set>
where order_id = #{orderId,jdbcType=INTEGER} where order_id = #{orderId,jdbcType=INTEGER}
</update> </update>
@ -157,8 +155,7 @@
order_days = #{orderDays,jdbcType=INTEGER}, order_days = #{orderDays,jdbcType=INTEGER},
order_status = #{orderStatus,jdbcType=INTEGER}, order_status = #{orderStatus,jdbcType=INTEGER},
order_cost = #{orderCost,jdbcType=DOUBLE}, order_cost = #{orderCost,jdbcType=DOUBLE},
create_time = #{createTime,jdbcType=TIMESTAMP}, update_time = now()
update_time = #{updateTime,jdbcType=TIMESTAMP}
where order_id = #{orderId,jdbcType=INTEGER} where order_id = #{orderId,jdbcType=INTEGER}
</update> </update>
</mapper> </mapper>

View File

@ -24,12 +24,17 @@
from user_info from user_info
where user_id = #{userId,jdbcType=INTEGER} where user_id = #{userId,jdbcType=INTEGER}
</select> </select>
<select id="selectAllUser" resultMap="BaseResultMap">
select * from user_info
where username != ''
</select>
<select id="selectAll" resultMap="BaseResultMap"> <select id="selectAll" resultMap="BaseResultMap">
select * from user_info select * from user_info
</select> </select>
<select id="selectByUsernameAndPassword" parameterType="String" resultMap="BaseResultMap"> <select id="selectByUsernameAndPassword" parameterType="String" resultMap="BaseResultMap">
select * from user_info 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>
<select id="selectByUsername" parameterType="String" resultMap="BaseResultMap"> <select id="selectByUsername" parameterType="String" resultMap="BaseResultMap">
select * from user_info select * from user_info