枚举类编写

This commit is contained in:
freeebird 2018-11-29 11:51:42 +08:00
parent ed0f7f87aa
commit 1cdb072ec6
18 changed files with 214 additions and 191 deletions

View File

@ -17,17 +17,38 @@ public class RoomTypeController {
private RoomTypeService roomTypeService; private RoomTypeService roomTypeService;
/**
* 所有房型
* @return
*/
@RequestMapping(value = "/all") @RequestMapping(value = "/all")
public List<RoomType> getAllRoomType(){ public List<RoomType> getAllRoomType(){
return roomTypeService.findAllType(); return roomTypeService.findAllType();
} }
/**
* 根据id查找房型
* @param typeId
* @return
*/
@RequestMapping(value = "/withId") @RequestMapping(value = "/withId")
public RoomType getById(int typeId){ public RoomType getById(int typeId){
return roomTypeService.selectById(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") @RequestMapping(method = RequestMethod.POST,value = "/add")
public int addRoomType(String roomType,Double price,Double discount,int area, public int addRoomType(String roomType,Double price,Double discount,int area,
int bedNum,String bedSize,int window,String remark){ int bedNum,String bedSize,int window,String remark){
@ -38,6 +59,20 @@ public class RoomTypeController {
return result; 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") @RequestMapping(method = RequestMethod.POST,value = "/update")
public int updateRoomType(int typeId,String roomType,Double price,Double discount,int area, public int updateRoomType(int typeId,String roomType,Double price,Double discount,int area,
int bedNum,String bedSize,int window,int rest,String remark){ int bedNum,String bedSize,int window,int rest,String remark){
@ -49,6 +84,11 @@ public class RoomTypeController {
return result; return result;
} }
/**
* 删除房型
* @param typeId
* @return
*/
@RequestMapping(method = RequestMethod.POST,value = "/delete") @RequestMapping(method = RequestMethod.POST,value = "/delete")
public int deleteRoomType(int typeId){ public int deleteRoomType(int typeId){
int result = 0; int result = 0;
@ -56,4 +96,13 @@ public class RoomTypeController {
return result; return result;
} }
/**
* 查找有余量的房型
* @return
*/
@RequestMapping(value = "/restAll")
public List<RoomType> findAllRestRoomType(){
return roomTypeService.findAllRestType();
}
} }

View File

@ -127,6 +127,11 @@ public class UserController {
return result; return result;
} }
/**
* 根据username查找用户
* @param username
* @return
*/
@RequestMapping(method = RequestMethod.POST,value = "/withUsername") @RequestMapping(method = RequestMethod.POST,value = "/withUsername")
public User getByUsername(String username){ public User getByUsername(String username){
User user = userService.selectByUsername(username); User user = userService.selectByUsername(username);
@ -134,11 +139,21 @@ public class UserController {
return user; return user;
} }
/**
* 根据id查找用户
* @param userId
* @return
*/
@RequestMapping(method = RequestMethod.POST,value = "/withId") @RequestMapping(method = RequestMethod.POST,value = "/withId")
public User getById(int userId){ public User getById(int userId){
return userService.selectById(userId); return userService.selectById(userId);
} }
/**
* 删除用户
* @param userId
* @return
*/
@RequestMapping(value = "/delete") @RequestMapping(value = "/delete")
public int deleteUser(int userId){ public int deleteUser(int userId){
return userService.deleteUser(userId); return userService.deleteUser(userId);

View File

@ -3,7 +3,27 @@ package cn.mafangui.hotel.enums;
public enum OrderError { public enum OrderError {
NONE(0,"没有空房"), 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;
} }
} }

View File

@ -29,5 +29,7 @@ public enum OrderStatus {
} }
OrderStatus(int code, String status) { OrderStatus(int code, String status) {
this.code = code;
this.status = status;
} }
} }

View File

@ -25,6 +25,8 @@ public enum Role {
} }
Role(String value, String role) { Role(String value, String role) {
this.value = value;
this.role = role;
} }
} }

View File

@ -27,5 +27,7 @@ public enum RoomStatus {
RoomStatus(int code,String status) { RoomStatus(int code,String status) {
this.code = code;
this.status = status;
} }
} }

View File

@ -1,6 +1,7 @@
package cn.mafangui.hotel.mapper; package cn.mafangui.hotel.mapper;
import cn.mafangui.hotel.entity.Order; import cn.mafangui.hotel.entity.Order;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;
@ -23,7 +24,7 @@ public interface OrderMapper {
List<Order> selectByUserId(Integer userId); List<Order> selectByUserId(Integer userId);
List<Order> selectAllByUser(Integer userId,Integer orderStatus); List<Order> selectAllByUser(@Param("userId") Integer userId,@Param("orderStatus") Integer orderStatus);
} }

View File

@ -1,6 +1,7 @@
package cn.mafangui.hotel.mapper; package cn.mafangui.hotel.mapper;
import cn.mafangui.hotel.entity.Room; import cn.mafangui.hotel.entity.Room;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;
@ -24,5 +25,5 @@ public interface RoomMapper {
List<Room> selectAll(); List<Room> selectAll();
Room randomSelectByTypeAndStatus(Integer typeId,Integer roomStatus); Room randomSelectByTypeAndStatus(@Param("typeId") Integer typeId,@Param("roomStatus") Integer roomStatus);
} }

View File

@ -22,4 +22,6 @@ public interface RoomTypeMapper {
List<RoomType> selectAll(); List<RoomType> selectAll();
RoomType selectByRoomType(String roomType); RoomType selectByRoomType(String roomType);
}
List<RoomType> selectAllWithRest();
}

View File

@ -25,4 +25,6 @@ public interface RoomTypeService {
int addRest(int typeId); int addRest(int typeId);
int minusRest(int typeId); int minusRest(int typeId);
List<RoomType> findAllRestType();
} }

View File

@ -53,9 +53,9 @@ public class OrderServiceImpl implements OrderService {
/** /**
* 订单支付 * 订单支付
* 1.更改订单状态 * 1.更改订单状态 -3
* 2.修改房型余量 * 2.修改房型余量 -2
* 3.修改房间状态 * 3.修改房间状态 -1
* @param orderId * @param orderId
* @return * @return
*/ */
@ -63,8 +63,8 @@ public class OrderServiceImpl implements OrderService {
@Transactional @Transactional
public int payOrder(int orderId) { public int payOrder(int orderId) {
Order order = orderMapper.selectByPrimaryKey(orderId); Order order = orderMapper.selectByPrimaryKey(orderId);
if (order == null | order.getOrderStatus() != OrderStatus.UNPAID.getCode()) return -1; if (order == null | order.getOrderStatus() != OrderStatus.UNPAID.getCode()) return -3;
if (roomTypeService.updateRest(order.getRoomTypeId(),-1) != 1) return -1; if (roomTypeService.updateRest(order.getRoomTypeId(),-1) != 1) return -2;
return roomService.orderRoom(order.getRoomTypeId()); return roomService.orderRoom(order.getRoomTypeId());
} }

View File

@ -47,7 +47,8 @@ public class RoomTypeServiceImpl implements RoomTypeService {
@Override @Override
public int updateRest(int typeId, int num) { public int updateRest(int typeId, int num) {
RoomType rt =roomTypeMapper.selectByPrimaryKey(typeId); 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); return roomTypeMapper.updateByPrimaryKeySelective(rt);
} }
@ -64,4 +65,9 @@ public class RoomTypeServiceImpl implements RoomTypeService {
rt.setTypeId(rt.getRest() -1); rt.setTypeId(rt.getRest() -1);
return roomTypeMapper.updateByPrimaryKeySelective(rt); return roomTypeMapper.updateByPrimaryKeySelective(rt);
} }
@Override
public List<RoomType> findAllRestType() {
return roomTypeMapper.selectAllWithRest();
}
} }

View File

@ -208,175 +208,4 @@
update_time = #{updateTime,jdbcType=TIMESTAMP} update_time = #{updateTime,jdbcType=TIMESTAMP}
where order_id = #{orderId,jdbcType=INTEGER} where order_id = #{orderId,jdbcType=INTEGER}
</update> </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 &gt;= -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> </mapper>

View File

@ -38,7 +38,7 @@
<select id="randomSelectByTypeAndStatus" parameterType="Integer" resultMap="BaseResultMap"> <select id="randomSelectByTypeAndStatus" parameterType="Integer" resultMap="BaseResultMap">
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
from room_info from room_info
where type_id = #{typeId,jdbcType=INTEGER} and room_status = #{roomStatus,jdbcType=INTEGER} where type_id = #{typeId,jdbcType=INTEGER} and room_status = #{roomStatus,jdbcType=INTEGER}
ORDER BY RAND() LIMIT 1 ORDER BY RAND() LIMIT 1
</select> </select>

View File

@ -26,10 +26,20 @@
where type_id = #{typeId,jdbcType=INTEGER} where type_id = #{typeId,jdbcType=INTEGER}
</select> </select>
<select id="selectAll" resultMap="BaseResultMap"> <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>
<select id="selectByRoomType" parameterType="String" resultMap="BaseResultMap"> <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> </select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer"> <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from room_type delete from room_type

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

View File

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

View File

@ -44,12 +44,10 @@ public class RoomTypeServiceImplTest {
@Test @Test
public void update() { public void update() {
String typeName = "single"; RoomType rt =roomTypeService.selectById(2);
int id = 1; rt.setRest(rt.getRest() -1);
RoomType roomType = new RoomType(); System.out.println(rt);
roomType.setTypeId(id); System.out.println(roomTypeService.update(rt));
roomType.setRoomType(typeName);
Assert.assertEquals(1,roomTypeService.update(roomType));
} }
@Test @Test
@ -73,4 +71,4 @@ public class RoomTypeServiceImplTest {
System.out.println(roomTypeService.findAllType()); System.out.println(roomTypeService.findAllType());
Assert.assertNotNull(roomTypeService.findAllType()); Assert.assertNotNull(roomTypeService.findAllType());
} }
} }