mirror of
				https://github.com/FreeeBird/hotel.git
				synced 2025-10-31 20:44:52 +08:00 
			
		
		
		
	添加酒店信息的基本操作
This commit is contained in:
		| @@ -9,10 +9,7 @@ | |||||||
| ### 1.3 业务背景 | ### 1.3 业务背景 | ||||||
|   传统的酒店管理往往需要酒店管理人花大量时间和精力来处理顾客查询、顾客登记等等事务。而错误的查询、繁琐的登记和结账手续、费用的结算错误、空余客房不能及时提供等等问题,可能导致顾客的频繁投诉,从而影响酒店的出租率。这些问题都可以通过计算机辅助系统来解决。酒店管理的信息化,不仅是酒店现代化形象的标志,而且能够酒店员工的工作效率,加速资金周转、降低各项成本以及改善服务质量。并支持客户直接在线预订,为客户提供方便快捷的服务. |   传统的酒店管理往往需要酒店管理人花大量时间和精力来处理顾客查询、顾客登记等等事务。而错误的查询、繁琐的登记和结账手续、费用的结算错误、空余客房不能及时提供等等问题,可能导致顾客的频繁投诉,从而影响酒店的出租率。这些问题都可以通过计算机辅助系统来解决。酒店管理的信息化,不仅是酒店现代化形象的标志,而且能够酒店员工的工作效率,加速资金周转、降低各项成本以及改善服务质量。并支持客户直接在线预订,为客户提供方便快捷的服务. | ||||||
|  |  | ||||||
| ## 2 项目说明 | ## 2 项目功能 | ||||||
| ### 2.1 问题说明 |  | ||||||
| 由于酒店的客房有不同的档次,所以需要能够对客房进行分类处理。同时为了方便对客房价格的设置,需要提供一个能够对不同档次的客房能够进行预订价格、预订折扣、计时最低价格等的设置。需要提供一个客房设置功能,用来设置酒店的所有客房信息。在设置客房信息时,应该提供对不同房间的实际价格、实际折扣的设置。特别重要的是能够对房间的状态以及是否可用进行设置,这样能够方便酒店对客房的及时管理。需要提供一个入住登记和结账功能,并且能够对客户的登记时间、离店时间、客户资料、入住房间等信息进行登记。需要提供一个预定中心,能够处理客户的各种预定,如电话预定、总台面约、网上预定以及领导安排等等预定方式。需要提供一个客户管理功能,从而实现对酒店的客户信息的统一管理。最后还需要提供一个业务统计报表功能,能够对酒店一年中每月的住宿率进行统计,然后生成柱状图进行显示。 |  | ||||||
| ### 2.2 用户期望 |  | ||||||
| >酒店管理系统后台,供管理员管理系统之用 | >酒店管理系统后台,供管理员管理系统之用 | ||||||
| - 客房类型设置 | - 客房类型设置 | ||||||
| - 客房设置 | - 客房设置 | ||||||
|   | |||||||
							
								
								
									
										114
									
								
								src/main/java/cn/mafangui/hotel/controller/HotelController.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										114
									
								
								src/main/java/cn/mafangui/hotel/controller/HotelController.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,114 @@ | |||||||
|  | package cn.mafangui.hotel.controller; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | import cn.mafangui.hotel.entity.Hotel; | ||||||
|  | import cn.mafangui.hotel.service.HotelService; | ||||||
|  | import org.springframework.beans.factory.annotation.Autowired; | ||||||
|  | import org.springframework.web.bind.annotation.RequestMapping; | ||||||
|  | import org.springframework.web.bind.annotation.RestController; | ||||||
|  |  | ||||||
|  | import java.util.List; | ||||||
|  |  | ||||||
|  | @RestController | ||||||
|  | @RequestMapping(value = "/hotelInfo") | ||||||
|  | public class HotelController { | ||||||
|  |     @Autowired | ||||||
|  |     private HotelService hotelService; | ||||||
|  |     /** | ||||||
|  |      * 添加酒店信息 | ||||||
|  |      * @param hotelName | ||||||
|  |      * @param phone | ||||||
|  |      * @param telephone | ||||||
|  |      * @param email | ||||||
|  |      * @param address | ||||||
|  |      * @param website | ||||||
|  |      * @return | ||||||
|  |      */ | ||||||
|  |     @RequestMapping(value = "/add") | ||||||
|  |     public int addHotel(String hotelName,String phone,String telephone,String email,String address,String website){ | ||||||
|  |         int result = 0; | ||||||
|  |         Hotel hotel = new Hotel(hotelName,phone,telephone,email,address,website); | ||||||
|  |         try { | ||||||
|  |             result = hotelService.addHotel(hotel); | ||||||
|  |         }catch (Exception e){ | ||||||
|  |             result = -1; | ||||||
|  |         } | ||||||
|  |         return result; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 删除酒店信息 | ||||||
|  |      * @param hotelId | ||||||
|  |      * @return | ||||||
|  |      */ | ||||||
|  |     @RequestMapping(value = "/delete") | ||||||
|  |     public int deleteHotel(int hotelId){ | ||||||
|  |         int result = 0; | ||||||
|  |         try { | ||||||
|  |             result = hotelService.deleteHotel(hotelId); | ||||||
|  |         }catch (Exception e){ | ||||||
|  |             result = -1; | ||||||
|  |         } | ||||||
|  |         return result; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 更改酒店信息 | ||||||
|  |      * @param hotelName | ||||||
|  |      * @param phone | ||||||
|  |      * @param telephone | ||||||
|  |      * @param email | ||||||
|  |      * @param address | ||||||
|  |      * @param website | ||||||
|  |      * @return | ||||||
|  |      */ | ||||||
|  |     @RequestMapping(value = "/update") | ||||||
|  |     public int updateHotel(int hotelId,String hotelName,String phone,String telephone,String email,String address,String website){ | ||||||
|  |         int result = 0; | ||||||
|  |         Hotel hotel = new Hotel(hotelName,phone,telephone,email,address,website); | ||||||
|  |         hotel.setHotelId(hotelId); | ||||||
|  |         try{ | ||||||
|  |             result = hotelService.updateHotel(hotel); | ||||||
|  |         }catch (Exception e){ | ||||||
|  |             result = -1; | ||||||
|  |         } | ||||||
|  |         return result; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 根据id查询 | ||||||
|  |      * @param hotelId | ||||||
|  |      * @return | ||||||
|  |      */ | ||||||
|  |     @RequestMapping(value = "/withId") | ||||||
|  |     public Hotel selectHotel(int hotelId){ | ||||||
|  |         try { | ||||||
|  |             return hotelService.selectHotelById(hotelId); | ||||||
|  |         }catch (Exception e){ | ||||||
|  |             return null; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 根据酒店名查询 | ||||||
|  |      * @param hotelName | ||||||
|  |      * @return | ||||||
|  |      */ | ||||||
|  |     @RequestMapping(value = "/withName") | ||||||
|  |     public Hotel selectHotel(String hotelName){ | ||||||
|  |         try { | ||||||
|  |             return hotelService.selectHotelByName(hotelName); | ||||||
|  |         }catch (Exception e){ | ||||||
|  |             return null; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 所有酒店信息 | ||||||
|  |      * @return | ||||||
|  |      */ | ||||||
|  |     @RequestMapping(value = "/all") | ||||||
|  |     public List<Hotel> allHotel(){ | ||||||
|  |         return hotelService.findAllHotel(); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -92,4 +92,16 @@ public class Hotel { | |||||||
|     public void setUpdateTime(Date updateTime) { |     public void setUpdateTime(Date updateTime) { | ||||||
|         this.updateTime = updateTime; |         this.updateTime = updateTime; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     public Hotel() { | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public Hotel(String hotelName, String phone, String telephone, String email, String address, String website) { | ||||||
|  |         this.hotelName = hotelName; | ||||||
|  |         this.phone = phone; | ||||||
|  |         this.telephone = telephone; | ||||||
|  |         this.email = email; | ||||||
|  |         this.address = address; | ||||||
|  |         this.website = website; | ||||||
|  |     } | ||||||
| } | } | ||||||
| @@ -1,17 +1,20 @@ | |||||||
| package cn.mafangui.hotel.mapper; | package cn.mafangui.hotel.mapper; | ||||||
|  |  | ||||||
| import cn.mafangui.hotel.entity.Hotel; | import cn.mafangui.hotel.entity.Hotel; | ||||||
|  | import org.springframework.stereotype.Component; | ||||||
|  |  | ||||||
|  | import java.util.List; | ||||||
|  |  | ||||||
|  | @Component | ||||||
| public interface HotelMapper { | public interface HotelMapper { | ||||||
|     int deleteByPrimaryKey(Integer hotelId); |     int deleteByPrimaryKey(Integer hotelId); | ||||||
|  |  | ||||||
|     int insert(Hotel record); |  | ||||||
|  |  | ||||||
|     int insertSelective(Hotel record); |  | ||||||
|  |  | ||||||
|     Hotel selectByPrimaryKey(Integer hotelId); |  | ||||||
|  |  | ||||||
|     int updateByPrimaryKeySelective(Hotel record); |  | ||||||
|  |  | ||||||
|     int updateByPrimaryKey(Hotel record); |     int updateByPrimaryKey(Hotel record); | ||||||
|  |  | ||||||
|  |     int insert(Hotel record); | ||||||
|  |     int insertSelective(Hotel record); | ||||||
|  |     int updateByPrimaryKeySelective(Hotel record); | ||||||
|  |     Hotel selectByPrimaryKey(Integer hotelId); | ||||||
|  |     Hotel selectByName(String hotelName); | ||||||
|  |     List<Hotel> selectAll(); | ||||||
| } | } | ||||||
							
								
								
									
										16
									
								
								src/main/java/cn/mafangui/hotel/service/HotelService.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/main/java/cn/mafangui/hotel/service/HotelService.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | |||||||
|  | package cn.mafangui.hotel.service; | ||||||
|  |  | ||||||
|  | import cn.mafangui.hotel.entity.Hotel; | ||||||
|  |  | ||||||
|  | import java.util.List; | ||||||
|  |  | ||||||
|  | public interface HotelService { | ||||||
|  |  | ||||||
|  |     int addHotel(Hotel hotel); | ||||||
|  |     int deleteHotel(int hotelId); | ||||||
|  |     int updateHotel(Hotel hotel); | ||||||
|  |     Hotel selectHotelByName(String hotelName); | ||||||
|  |     Hotel selectHotelById(int hotelId); | ||||||
|  |     List<Hotel> findAllHotel(); | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -0,0 +1,45 @@ | |||||||
|  | package cn.mafangui.hotel.service.impl; | ||||||
|  |  | ||||||
|  | import cn.mafangui.hotel.entity.Hotel; | ||||||
|  | import cn.mafangui.hotel.mapper.HotelMapper; | ||||||
|  | import cn.mafangui.hotel.service.HotelService; | ||||||
|  | import org.springframework.beans.factory.annotation.Autowired; | ||||||
|  | import org.springframework.stereotype.Service; | ||||||
|  |  | ||||||
|  | import java.util.List; | ||||||
|  |  | ||||||
|  | @Service | ||||||
|  | public class HotelServiceImpl implements HotelService { | ||||||
|  |     @Autowired | ||||||
|  |     private HotelMapper hotelMapper; | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public int addHotel(Hotel hotel) { | ||||||
|  |         return hotelMapper.insertSelective(hotel); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public int deleteHotel(int hotelId) { | ||||||
|  |         return hotelMapper.deleteByPrimaryKey(hotelId); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public int updateHotel(Hotel hotel) { | ||||||
|  |         return hotelMapper.updateByPrimaryKeySelective(hotel); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public Hotel selectHotelByName(String hotelName) { | ||||||
|  |         return hotelMapper.selectByName(hotelName); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public Hotel selectHotelById(int hotelId) { | ||||||
|  |         return hotelMapper.selectByPrimaryKey(hotelId); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public List<Hotel> findAllHotel() { | ||||||
|  |         return hotelMapper.selectAll(); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -32,7 +32,7 @@ | |||||||
|       ) |       ) | ||||||
|     values (#{hotelId,jdbcType=INTEGER}, #{hotelName,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR},  |     values (#{hotelId,jdbcType=INTEGER}, #{hotelName,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR},  | ||||||
|       #{telephone,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR},  |       #{telephone,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR},  | ||||||
|       #{website,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP} |       #{website,jdbcType=VARCHAR}, now(),now() | ||||||
|       ) |       ) | ||||||
|   </insert> |   </insert> | ||||||
|   <insert id="insertSelective" parameterType="cn.mafangui.hotel.entity.Hotel"> |   <insert id="insertSelective" parameterType="cn.mafangui.hotel.entity.Hotel"> | ||||||
| @@ -59,12 +59,8 @@ | |||||||
|       <if test="website != null"> |       <if test="website != null"> | ||||||
|         website, |         website, | ||||||
|       </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="hotelId != null"> |       <if test="hotelId != null"> | ||||||
| @@ -88,12 +84,8 @@ | |||||||
|       <if test="website != null"> |       <if test="website != null"> | ||||||
|         #{website,jdbcType=VARCHAR}, |         #{website,jdbcType=VARCHAR}, | ||||||
|       </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.Hotel"> |   <update id="updateByPrimaryKeySelective" parameterType="cn.mafangui.hotel.entity.Hotel"> | ||||||
| @@ -138,4 +130,15 @@ | |||||||
|       update_time = #{updateTime,jdbcType=TIMESTAMP} |       update_time = #{updateTime,jdbcType=TIMESTAMP} | ||||||
|     where hotel_id = #{hotelId,jdbcType=INTEGER} |     where hotel_id = #{hotelId,jdbcType=INTEGER} | ||||||
|   </update> |   </update> | ||||||
|  |   <select id="selectAll"  resultMap="BaseResultMap"> | ||||||
|  |     select | ||||||
|  |     <include refid="Base_Column_List" /> | ||||||
|  |     from hotel_info | ||||||
|  |   </select> | ||||||
|  |   <select id="selectByName" parameterType="String"  resultMap="BaseResultMap"> | ||||||
|  |     select | ||||||
|  |     <include refid="Base_Column_List" /> | ||||||
|  |     from hotel_info | ||||||
|  |     where hotel_name = #{hotelName,jdbcType=VARCHAR} | ||||||
|  |   </select> | ||||||
| </mapper> | </mapper> | ||||||
| @@ -1,77 +0,0 @@ | |||||||
| package cn.mafangui.hotel.service.impl; |  | ||||||
|  |  | ||||||
| import cn.mafangui.hotel.entity.Room; |  | ||||||
| import cn.mafangui.hotel.service.RoomService; |  | ||||||
| import org.junit.Assert; |  | ||||||
| import org.junit.Before; |  | ||||||
| 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 RoomServiceImplTest { |  | ||||||
|     Room room = new Room(); |  | ||||||
|     @Autowired |  | ||||||
|     RoomService roomService; |  | ||||||
|     @Before |  | ||||||
|     public void setUp() throws Exception { |  | ||||||
|         room.setRoomId(4); |  | ||||||
|         room.setRoomNumber("102"); |  | ||||||
|         room.setRoomFloor(1); |  | ||||||
|         room.setRoomDiscount(10.0); |  | ||||||
|         room.setRoomPrice(119.0); |  | ||||||
|         room.setRoomStatus("已预订"); |  | ||||||
|         room.setRoomType(1); |  | ||||||
|         room.setTypeName("单人房"); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Test |  | ||||||
|     public void addRoom() { |  | ||||||
|         Assert.assertEquals(1, roomService.addRoom(room)); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Test |  | ||||||
|     public void deleteRoom() { |  | ||||||
|         Assert.assertEquals(1, roomService.deleteRoom(1)); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Test |  | ||||||
|     public void deleteRoom1() { |  | ||||||
|         Assert.assertEquals(1, roomService.deleteRoom("100")); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Test |  | ||||||
|     public void updateRoom() { |  | ||||||
|         Assert.assertEquals(1, roomService.updateRoom(room)); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Test |  | ||||||
|     public void findById() { |  | ||||||
|         Assert.assertEquals("102", roomService.findById(4).getRoomNumber()); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Test |  | ||||||
|     public void findByNumber() { |  | ||||||
|         Assert.assertEquals("单人房", roomService.findByNumber("102").getTypeName()); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Test |  | ||||||
|     public void findByStatus() { |  | ||||||
|         Assert.assertTrue(!roomService.findByStatus("空闲").isEmpty()); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Test |  | ||||||
|     public void findByType() { |  | ||||||
|         Assert.assertTrue(!roomService.findByType("单人房").isEmpty()); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Test |  | ||||||
|     public void findAll() { |  | ||||||
|         Assert.assertTrue(roomService.findAll().size() == 3); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,55 +0,0 @@ | |||||||
| package cn.mafangui.hotel.service.impl; |  | ||||||
|  |  | ||||||
| import cn.mafangui.hotel.entity.RoomType; |  | ||||||
| import cn.mafangui.hotel.mapper.RoomTypeMapper; |  | ||||||
| import org.junit.Assert; |  | ||||||
| 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.*; |  | ||||||
|  |  | ||||||
| @RunWith(SpringJUnit4ClassRunner.class) |  | ||||||
| @SpringBootTest |  | ||||||
| public class RoomTypeServiceImplTest { |  | ||||||
|  |  | ||||||
|     @Autowired |  | ||||||
|     private RoomTypeMapper roomTypeMapper; |  | ||||||
|  |  | ||||||
|     @Test |  | ||||||
|     public void addRoomType() { |  | ||||||
|         RoomType roomType = new RoomType(201,"豪华大床房",229.00,20.0); |  | ||||||
|         Assert.assertEquals(1, roomTypeMapper.insertSelective(roomType)); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Test |  | ||||||
|     public void delRoomType() { |  | ||||||
|         RoomType roomType = new RoomType(); |  | ||||||
|         roomType.setRoomType(201); |  | ||||||
|         Assert.assertEquals(1, roomTypeMapper.deleteByRoomType(roomType)); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Test |  | ||||||
|     public void updateRoomType() { |  | ||||||
|         RoomType roomType = new RoomType(); |  | ||||||
|         roomType.setRoomType(103); |  | ||||||
|         roomType.setBookingDiscount(20.0); |  | ||||||
|         Assert.assertEquals(1,roomTypeMapper.updateByRoomTypeSelective(roomType)); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Test |  | ||||||
|     public void selectByName() { |  | ||||||
|         RoomType roomType = new RoomType(); |  | ||||||
|         roomType.setRoomType(103); |  | ||||||
|         System.out.println(roomTypeMapper.selectByRoomType(roomType)); |  | ||||||
|         Assert.assertNotNull(roomTypeMapper.selectByRoomType(roomType)); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Test |  | ||||||
|     public void findAllType() { |  | ||||||
|         System.out.println(roomTypeMapper.findAll()); |  | ||||||
|         Assert.assertNotNull(roomTypeMapper.findAll()); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
		Reference in New Issue
	
	Block a user