mirror of
https://github.com/FreeeBird/hotel.git
synced 2025-05-06 19:49:26 +08:00
枚举类编写
This commit is contained in:
parent
ed0f7f87aa
commit
1cdb072ec6
@ -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;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -208,175 +208,4 @@
|
||||
update_time = #{updateTime,jdbcType=TIMESTAMP}
|
||||
where order_id = #{orderId,jdbcType=INTEGER}
|
||||
</update>
|
||||
<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="name" jdbcType="VARCHAR" property="name" />
|
||||
<result column="phone" jdbcType="VARCHAR" property="phone" />
|
||||
<result column="room_type" jdbcType="VARCHAR" property="roomType" />
|
||||
<result column="order_date" jdbcType="DATE" property="orderDate" />
|
||||
<result column="order_days" jdbcType="INTEGER" property="orderDays" />
|
||||
<result column="order_status" jdbcType="INTEGER" property="orderStatus" />
|
||||
<result column="order_cost" jdbcType="DOUBLE" property="orderCost" />
|
||||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
|
||||
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
order_id, order_type, user_id, name,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">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
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>
|
||||
<select id="userSelectAll" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||
select
|
||||
*
|
||||
from order_info
|
||||
where order_status >= -2 and user_id = #{userId,jdbcType=VARCHAR}
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
|
||||
delete from order_info
|
||||
where order_id = #{orderId,jdbcType=INTEGER}
|
||||
</delete>
|
||||
<insert id="insert" parameterType="cn.mafangui.hotel.entity.Order">
|
||||
insert into order_info (order_id, order_type,name, phone,
|
||||
room_type, order_date,
|
||||
order_days, order_status, order_cost,
|
||||
create_time, update_time)
|
||||
values (#{orderId,jdbcType=INTEGER}, #{orderType,jdbcType=VARCHAR},
|
||||
#{name,jdbcType=VARCHAR},#{phone,jdbcType=VARCHAR},
|
||||
#{roomType,jdbcType=VARCHAR},#{orderDate,jdbcType=DATE},
|
||||
#{orderDays,jdbcType=INTEGER}, #{orderStatus,jdbcType=INTEGER}, #{orderCost,jdbcType=DOUBLE},
|
||||
#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="cn.mafangui.hotel.entity.Order">
|
||||
insert into order_info
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="orderId != null">
|
||||
order_id,
|
||||
</if>
|
||||
<if test="orderType != null">
|
||||
order_type,
|
||||
</if>
|
||||
<if test="userId != null">
|
||||
user_id,
|
||||
</if>
|
||||
<if test="name != null">
|
||||
name,
|
||||
</if>
|
||||
<if test="phone != null">
|
||||
phone,
|
||||
</if>
|
||||
<if test="roomType != null">
|
||||
room_type,
|
||||
</if>
|
||||
<if test="orderDate != null">
|
||||
order_date,
|
||||
</if>
|
||||
<if test="orderDays != null">
|
||||
order_days,
|
||||
</if>
|
||||
<if test="orderStatus != null">
|
||||
order_status,
|
||||
</if>
|
||||
<if test="orderCost != null">
|
||||
order_cost,
|
||||
</if>
|
||||
create_time,
|
||||
update_time,
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="orderId != null">
|
||||
#{orderId,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="orderType != null">
|
||||
#{orderType,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="userId != null">
|
||||
#{userId,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="name != null">
|
||||
#{name,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="phone != null">
|
||||
#{phone,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="roomType != null">
|
||||
#{roomType,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="orderDate != null">
|
||||
#{orderDate,jdbcType=DATE},
|
||||
</if>
|
||||
<if test="orderDays != null">
|
||||
#{orderDays,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="orderStatus != null">
|
||||
#{orderStatus,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="orderCost != null">
|
||||
#{orderCost,jdbcType=DOUBLE},
|
||||
</if>
|
||||
now(),
|
||||
now(),
|
||||
</trim>
|
||||
</insert>
|
||||
<update id="updateByPrimaryKeySelective" parameterType="cn.mafangui.hotel.entity.Order">
|
||||
update order_info
|
||||
<set>
|
||||
<if test="orderType != null">
|
||||
order_type = #{orderType,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="name != null">
|
||||
name = #{name,jdbcType=VARCHAR}
|
||||
</if>
|
||||
<if test="phone != null">
|
||||
phone = #{phone,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="roomType != null">
|
||||
room_type = #{roomType,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="orderDate != null">
|
||||
order_date = #{orderDate,jdbcType=DATE},
|
||||
</if>
|
||||
<if test="orderDays != null">
|
||||
order_days = #{orderDays,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="orderStatus != null">
|
||||
order_status = #{orderStatus,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="orderCost != null">
|
||||
order_cost = #{orderCost,jdbcType=DOUBLE},
|
||||
</if>
|
||||
update_time = now(),
|
||||
</set>
|
||||
where order_id = #{orderId,jdbcType=INTEGER}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="cn.mafangui.hotel.entity.Order">
|
||||
update order_info
|
||||
set order_type = #{orderType,jdbcType=VARCHAR},
|
||||
name = #{name,jdbcType=VARCHAR},
|
||||
phone = #{phone,jdbcType=VARCHAR},
|
||||
room_type = #{roomType,jdbcType=VARCHAR},
|
||||
order_date = #{orderDate,jdbcType=DATE},
|
||||
order_days = #{orderDays,jdbcType=INTEGER},
|
||||
order_status = #{orderStatus,jdbcType=INTEGER},
|
||||
order_cost = #{orderCost,jdbcType=DOUBLE},
|
||||
update_time = now()
|
||||
where order_id = #{orderId,jdbcType=INTEGER}
|
||||
</update>
|
||||
</mapper>
|
||||
|
@ -26,10 +26,20 @@
|
||||
where type_id = #{typeId,jdbcType=INTEGER}
|
||||
</select>
|
||||
<select id="selectAll" resultMap="BaseResultMap">
|
||||
select * from room_type
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from room_type
|
||||
</select>
|
||||
<select id="selectAllWithRest" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from room_type where rest > 0
|
||||
</select>
|
||||
<select id="selectByRoomType" parameterType="String" resultMap="BaseResultMap">
|
||||
select * from room_type where room_type = #{roomType,jdbcType=VARCHAR}
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from room_type
|
||||
where room_type = #{roomType,jdbcType=VARCHAR}
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
|
||||
delete from room_type
|
||||
|
62
src/test/java/cn/mafangui/hotel/mapper/RoomMapperTest.java
Normal file
62
src/test/java/cn/mafangui/hotel/mapper/RoomMapperTest.java
Normal file
@ -0,0 +1,62 @@
|
||||
package cn.mafangui.hotel.mapper;
|
||||
|
||||
import cn.mafangui.hotel.entity.Room;
|
||||
import cn.mafangui.hotel.enums.RoomStatus;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@SpringBootTest
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class RoomMapperTest {
|
||||
|
||||
@Autowired
|
||||
private RoomMapper rm;
|
||||
|
||||
@Test
|
||||
public void deleteByPrimaryKey() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void insert() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void insertSelective() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selectByPrimaryKey() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateByPrimaryKeySelective() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateByPrimaryKey() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selectByType() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selectByStatus() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selectAll() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void randomSelectByTypeAndStatus() {
|
||||
System.out.println(RoomStatus.AVAILABLE.getCode());
|
||||
System.out.println(RoomStatus.AVAILABLE.getStatus());
|
||||
System.out.println(rm.randomSelectByTypeAndStatus(2, RoomStatus.AVAILABLE.getCode()));
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package cn.mafangui.hotel.service.impl;
|
||||
|
||||
import cn.mafangui.hotel.service.OrderService;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
|
||||
@SpringBootTest
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class OrderServiceImplTest {
|
||||
@Autowired
|
||||
private OrderService orderService;
|
||||
|
||||
@Test
|
||||
public void payOrder() {
|
||||
int orderId = 19;
|
||||
System.out.println(orderService.payOrder(orderId));
|
||||
}
|
||||
}
|
@ -44,12 +44,10 @@ public class RoomTypeServiceImplTest {
|
||||
|
||||
@Test
|
||||
public void update() {
|
||||
String typeName = "single";
|
||||
int id = 1;
|
||||
RoomType roomType = new RoomType();
|
||||
roomType.setTypeId(id);
|
||||
roomType.setRoomType(typeName);
|
||||
Assert.assertEquals(1,roomTypeService.update(roomType));
|
||||
RoomType rt =roomTypeService.selectById(2);
|
||||
rt.setRest(rt.getRest() -1);
|
||||
System.out.println(rt);
|
||||
System.out.println(roomTypeService.update(rt));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user