diff --git a/src/main/java/cn/mafangui/hotel/controller/RoomTypeController.java b/src/main/java/cn/mafangui/hotel/controller/RoomTypeController.java index 0facc6d..d37c360 100644 --- a/src/main/java/cn/mafangui/hotel/controller/RoomTypeController.java +++ b/src/main/java/cn/mafangui/hotel/controller/RoomTypeController.java @@ -17,17 +17,38 @@ public class RoomTypeController { private RoomTypeService roomTypeService; + /** + * 所有房型 + * @return + */ @RequestMapping(value = "/all") public List 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 findAllRestRoomType(){ + return roomTypeService.findAllRestType(); + } + } diff --git a/src/main/java/cn/mafangui/hotel/controller/UserController.java b/src/main/java/cn/mafangui/hotel/controller/UserController.java index 7409e94..fab6f28 100644 --- a/src/main/java/cn/mafangui/hotel/controller/UserController.java +++ b/src/main/java/cn/mafangui/hotel/controller/UserController.java @@ -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); diff --git a/src/main/java/cn/mafangui/hotel/enums/OrderError.java b/src/main/java/cn/mafangui/hotel/enums/OrderError.java index 5a01a2e..6b67d81 100644 --- a/src/main/java/cn/mafangui/hotel/enums/OrderError.java +++ b/src/main/java/cn/mafangui/hotel/enums/OrderError.java @@ -3,7 +3,27 @@ package cn.mafangui.hotel.enums; public enum OrderError { 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; } } diff --git a/src/main/java/cn/mafangui/hotel/enums/OrderStatus.java b/src/main/java/cn/mafangui/hotel/enums/OrderStatus.java index c612122..7d6479f 100644 --- a/src/main/java/cn/mafangui/hotel/enums/OrderStatus.java +++ b/src/main/java/cn/mafangui/hotel/enums/OrderStatus.java @@ -29,5 +29,7 @@ public enum OrderStatus { } OrderStatus(int code, String status) { + this.code = code; + this.status = status; } } diff --git a/src/main/java/cn/mafangui/hotel/enums/Role.java b/src/main/java/cn/mafangui/hotel/enums/Role.java index 9445b03..edeb716 100644 --- a/src/main/java/cn/mafangui/hotel/enums/Role.java +++ b/src/main/java/cn/mafangui/hotel/enums/Role.java @@ -25,6 +25,8 @@ public enum Role { } Role(String value, String role) { + this.value = value; + this.role = role; } } diff --git a/src/main/java/cn/mafangui/hotel/enums/RoomStatus.java b/src/main/java/cn/mafangui/hotel/enums/RoomStatus.java index 791075c..f92ab00 100644 --- a/src/main/java/cn/mafangui/hotel/enums/RoomStatus.java +++ b/src/main/java/cn/mafangui/hotel/enums/RoomStatus.java @@ -27,5 +27,7 @@ public enum RoomStatus { RoomStatus(int code,String status) { + this.code = code; + this.status = status; } } diff --git a/src/main/java/cn/mafangui/hotel/mapper/OrderMapper.java b/src/main/java/cn/mafangui/hotel/mapper/OrderMapper.java index a6a3429..6748993 100644 --- a/src/main/java/cn/mafangui/hotel/mapper/OrderMapper.java +++ b/src/main/java/cn/mafangui/hotel/mapper/OrderMapper.java @@ -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 selectByUserId(Integer userId); - List selectAllByUser(Integer userId,Integer orderStatus); + List selectAllByUser(@Param("userId") Integer userId,@Param("orderStatus") Integer orderStatus); } diff --git a/src/main/java/cn/mafangui/hotel/mapper/RoomMapper.java b/src/main/java/cn/mafangui/hotel/mapper/RoomMapper.java index 5bdf991..48a1bba 100644 --- a/src/main/java/cn/mafangui/hotel/mapper/RoomMapper.java +++ b/src/main/java/cn/mafangui/hotel/mapper/RoomMapper.java @@ -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 selectAll(); - Room randomSelectByTypeAndStatus(Integer typeId,Integer roomStatus); + Room randomSelectByTypeAndStatus(@Param("typeId") Integer typeId,@Param("roomStatus") Integer roomStatus); } diff --git a/src/main/java/cn/mafangui/hotel/mapper/RoomTypeMapper.java b/src/main/java/cn/mafangui/hotel/mapper/RoomTypeMapper.java index b3e54f3..dbc9d57 100644 --- a/src/main/java/cn/mafangui/hotel/mapper/RoomTypeMapper.java +++ b/src/main/java/cn/mafangui/hotel/mapper/RoomTypeMapper.java @@ -22,4 +22,6 @@ public interface RoomTypeMapper { List selectAll(); RoomType selectByRoomType(String roomType); -} \ No newline at end of file + + List selectAllWithRest(); +} diff --git a/src/main/java/cn/mafangui/hotel/service/RoomTypeService.java b/src/main/java/cn/mafangui/hotel/service/RoomTypeService.java index 91a164e..ed31fe4 100644 --- a/src/main/java/cn/mafangui/hotel/service/RoomTypeService.java +++ b/src/main/java/cn/mafangui/hotel/service/RoomTypeService.java @@ -25,4 +25,6 @@ public interface RoomTypeService { int addRest(int typeId); int minusRest(int typeId); + + List findAllRestType(); } diff --git a/src/main/java/cn/mafangui/hotel/service/impl/OrderServiceImpl.java b/src/main/java/cn/mafangui/hotel/service/impl/OrderServiceImpl.java index d0b2552..cfc208c 100644 --- a/src/main/java/cn/mafangui/hotel/service/impl/OrderServiceImpl.java +++ b/src/main/java/cn/mafangui/hotel/service/impl/OrderServiceImpl.java @@ -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()); } diff --git a/src/main/java/cn/mafangui/hotel/service/impl/RoomTypeServiceImpl.java b/src/main/java/cn/mafangui/hotel/service/impl/RoomTypeServiceImpl.java index eb59dc9..4b3e7fc 100644 --- a/src/main/java/cn/mafangui/hotel/service/impl/RoomTypeServiceImpl.java +++ b/src/main/java/cn/mafangui/hotel/service/impl/RoomTypeServiceImpl.java @@ -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 findAllRestType() { + return roomTypeMapper.selectAllWithRest(); + } } diff --git a/src/main/resources/mybatis/mapper/OrderMapper.xml b/src/main/resources/mybatis/mapper/OrderMapper.xml index baf1ff6..7ea1ce3 100644 --- a/src/main/resources/mybatis/mapper/OrderMapper.xml +++ b/src/main/resources/mybatis/mapper/OrderMapper.xml @@ -208,175 +208,4 @@ update_time = #{updateTime,jdbcType=TIMESTAMP} where order_id = #{orderId,jdbcType=INTEGER} - - - - - - - - - - - - - - - - order_id, order_type, user_id, name,phone, room_type, order_date, order_days, order_status, - order_cost, create_time, update_time - - - - - - - delete from order_info - where order_id = #{orderId,jdbcType=INTEGER} - - - 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 into order_info - - - order_id, - - - order_type, - - - user_id, - - - name, - - - phone, - - - room_type, - - - order_date, - - - order_days, - - - order_status, - - - order_cost, - - create_time, - update_time, - - - - #{orderId,jdbcType=INTEGER}, - - - #{orderType,jdbcType=VARCHAR}, - - - #{userId,jdbcType=INTEGER}, - - - #{name,jdbcType=VARCHAR}, - - - #{phone,jdbcType=VARCHAR}, - - - #{roomType,jdbcType=VARCHAR}, - - - #{orderDate,jdbcType=DATE}, - - - #{orderDays,jdbcType=INTEGER}, - - - #{orderStatus,jdbcType=INTEGER}, - - - #{orderCost,jdbcType=DOUBLE}, - - now(), - now(), - - - - update order_info - - - 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 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} - diff --git a/src/main/resources/mybatis/mapper/RoomMapper.xml b/src/main/resources/mybatis/mapper/RoomMapper.xml index fb89799..b0da6c8 100644 --- a/src/main/resources/mybatis/mapper/RoomMapper.xml +++ b/src/main/resources/mybatis/mapper/RoomMapper.xml @@ -38,7 +38,7 @@ diff --git a/src/main/resources/mybatis/mapper/RoomTypeMapper.xml b/src/main/resources/mybatis/mapper/RoomTypeMapper.xml index 54c54b5..4db1783 100644 --- a/src/main/resources/mybatis/mapper/RoomTypeMapper.xml +++ b/src/main/resources/mybatis/mapper/RoomTypeMapper.xml @@ -26,10 +26,20 @@ where type_id = #{typeId,jdbcType=INTEGER} + delete from room_type diff --git a/src/test/java/cn/mafangui/hotel/mapper/RoomMapperTest.java b/src/test/java/cn/mafangui/hotel/mapper/RoomMapperTest.java new file mode 100644 index 0000000..f480af8 --- /dev/null +++ b/src/test/java/cn/mafangui/hotel/mapper/RoomMapperTest.java @@ -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())); + } +} diff --git a/src/test/java/cn/mafangui/hotel/service/impl/OrderServiceImplTest.java b/src/test/java/cn/mafangui/hotel/service/impl/OrderServiceImplTest.java new file mode 100644 index 0000000..01e9b65 --- /dev/null +++ b/src/test/java/cn/mafangui/hotel/service/impl/OrderServiceImplTest.java @@ -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)); + } +} diff --git a/src/test/java/cn/mafangui/hotel/service/impl/RoomTypeServiceImplTest.java b/src/test/java/cn/mafangui/hotel/service/impl/RoomTypeServiceImplTest.java index 0f94a55..a7370c4 100644 --- a/src/test/java/cn/mafangui/hotel/service/impl/RoomTypeServiceImplTest.java +++ b/src/test/java/cn/mafangui/hotel/service/impl/RoomTypeServiceImplTest.java @@ -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 @@ -73,4 +71,4 @@ public class RoomTypeServiceImplTest { System.out.println(roomTypeService.findAllType()); Assert.assertNotNull(roomTypeService.findAllType()); } -} \ No newline at end of file +}