Procházet zdrojové kódy

查看酒店详细信息&&添加酒店客房信息

YPLee před 6 roky
rodič
revize
898bbc901b

+ 14 - 0
src/main/java/com/example/hotel/bl/hotel/HotelService.java

@@ -1,5 +1,6 @@
 package com.example.hotel.bl.hotel;
 
+import com.example.hotel.po.HotelRoom;
 import com.example.hotel.vo.HotelVO;
 
 import java.util.List;
@@ -17,4 +18,17 @@ public interface HotelService {
      * @return
      */
     List<HotelVO> retrieveHotels();
+
+    /**
+     * 获取某家酒店详细信息
+     * @param hotelId
+     * @return
+     */
+    HotelVO retrieveHotelDetails(Integer hotelId);
+
+    /**
+     * 添加酒店客房信息
+     * @param hotelRoom
+     */
+    void addHotelRoomInfo(HotelRoom hotelRoom);
 }

+ 29 - 2
src/main/java/com/example/hotel/blImpl/hotel/HotelServiceImpl.java

@@ -2,15 +2,19 @@ package com.example.hotel.blImpl.hotel;
 
 import com.example.hotel.bl.hotel.HotelService;
 import com.example.hotel.data.hotel.HotelMapper;
+import com.example.hotel.data.hotel.RoomMapper;
 import com.example.hotel.data.user.AccountMapper;
 import com.example.hotel.enums.BizRegion;
 import com.example.hotel.enums.HotelStar;
 import com.example.hotel.po.Hotel;
+import com.example.hotel.po.HotelRoom;
 import com.example.hotel.vo.HotelVO;
+import com.example.hotel.vo.RoomVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
+import java.util.stream.Collectors;
 
 @Service
 public class HotelServiceImpl implements HotelService {
@@ -19,8 +23,8 @@ public class HotelServiceImpl implements HotelService {
     private AccountMapper accountMapper;
     @Autowired
     private HotelMapper hotelMapper;
-
-
+    @Autowired
+    private RoomMapper roomMapper;
 
 
     @Override
@@ -45,4 +49,27 @@ public class HotelServiceImpl implements HotelService {
 
         return hotelMapper.selectAllHotel();
     }
+
+    @Override
+    public HotelVO retrieveHotelDetails(Integer hotelId) {
+        HotelVO hotelVO = hotelMapper.selectById(hotelId);
+        List<HotelRoom> rooms = roomMapper.selectRoomsByHotelId(hotelId);
+        List<RoomVO> roomVOS = rooms.stream().map(r -> {
+            RoomVO roomVO = new RoomVO();
+            roomVO.setId(r.getId());
+            roomVO.setPrice(r.getPrice());
+            roomVO.setRoomType(r.getRoomType().toString());
+            roomVO.setCurNum(r.getCurNum());
+            roomVO.setTotal(r.getTotal());
+            return roomVO;
+        }).collect(Collectors.toList());
+        hotelVO.setRooms(roomVOS);
+
+        return hotelVO;
+    }
+
+    @Override
+    public void addHotelRoomInfo(HotelRoom hotelRoom) {
+        roomMapper.insertRoom(hotelRoom);
+    }
 }

+ 15 - 1
src/main/java/com/example/hotel/controller/hotel/HotelController.java

@@ -1,6 +1,7 @@
 package com.example.hotel.controller.hotel;
 
 import com.example.hotel.bl.hotel.HotelService;
+import com.example.hotel.po.HotelRoom;
 import com.example.hotel.util.Result;
 import com.example.hotel.vo.HotelVO;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -23,7 +24,20 @@ public class HotelController {
 
     @GetMapping("/all")
     public ResponseEntity<?> retrieveAllHotels(){
-
         return Result.ok(hotelService.retrieveHotels());
     }
+
+    @PostMapping("/roomInfo")
+    public ResponseEntity<?> addRoomInfo(@RequestBody HotelRoom hotelRoom) {
+        hotelService.addHotelRoomInfo(hotelRoom);
+        return Result.ok();
+    }
+
+    @GetMapping("/{hotelId}/detail")
+    public ResponseEntity<?> retrieveHotelDetail(@PathVariable Integer hotelId) {
+
+        return Result.ok(hotelService.retrieveHotelDetails(hotelId));
+    }
+
+
 }

+ 2 - 0
src/main/java/com/example/hotel/data/hotel/HotelMapper.java

@@ -3,6 +3,7 @@ package com.example.hotel.data.hotel;
 import com.example.hotel.po.Hotel;
 import com.example.hotel.vo.HotelVO;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
 import java.util.List;
@@ -15,4 +16,5 @@ public interface HotelMapper {
 
     List<HotelVO> selectAllHotel();
 
+    HotelVO selectById(@Param("id") Integer id);
 }

+ 2 - 0
src/main/java/com/example/hotel/data/hotel/RoomMapper.java

@@ -4,10 +4,12 @@ import com.example.hotel.po.Hotel;
 import com.example.hotel.po.HotelRoom;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
 
 import java.util.List;
 
 @Mapper
+@Repository
 public interface RoomMapper {
 
     int insertRoom(HotelRoom hotelRoom);

+ 13 - 3
src/main/java/com/example/hotel/enums/RoomType.java

@@ -1,7 +1,17 @@
 package com.example.hotel.enums;
 
 public enum RoomType {
-    BigBed,
-    DoubleBed,
-    Family
+    BigBed("大床房"),
+    DoubleBed("双床房"),
+    Family("家庭房");
+    private String value;
+
+    RoomType(String value) {
+        this.value = value;
+    }
+
+    @Override
+    public String toString() {
+        return value;
+    }
 }

+ 10 - 10
src/main/java/com/example/hotel/po/HotelRoom.java

@@ -4,8 +4,8 @@ import com.example.hotel.enums.RoomType;
 
 public class HotelRoom {
     private Integer id;
-    private RoomType type;
-    private Integer hotel_id;
+    private RoomType roomType;
+    private Integer hotelId;
     private double price;
     /**
      * 当前剩余可预定房间数
@@ -24,20 +24,20 @@ public class HotelRoom {
         this.id = id;
     }
 
-    public RoomType getType() {
-        return type;
+    public RoomType getRoomType() {
+        return roomType;
     }
 
-    public void setType(RoomType type) {
-        this.type = type;
+    public void setRoomType(RoomType roomType) {
+        this.roomType = roomType;
     }
 
-    public Integer getHotel_id() {
-        return hotel_id;
+    public Integer getHotelId() {
+        return hotelId;
     }
 
-    public void setHotel_id(Integer hotel_id) {
-        this.hotel_id = hotel_id;
+    public void setHotelId(Integer hotelId) {
+        this.hotelId = hotelId;
     }
 
     public double getPrice() {

+ 1 - 1
src/main/java/com/example/hotel/vo/HotelVO.java

@@ -2,6 +2,7 @@ package com.example.hotel.vo;
 
 import com.example.hotel.enums.BizRegion;
 import com.example.hotel.enums.HotelStar;
+import com.example.hotel.po.HotelRoom;
 import com.example.hotel.po.User;
 
 import java.util.List;
@@ -83,7 +84,6 @@ public class HotelVO {
         this.phoneNum = phoneNum;
     }
 
-
     public List<RoomVO> getRooms() {
         return rooms;
     }

+ 18 - 0
src/main/java/com/example/hotel/vo/RoomVO.java

@@ -6,6 +6,8 @@ public class RoomVO {
     private Integer id;
     private String roomType;
     private Double price;
+    private Integer curNum;
+    private Integer total;
 
     public Integer getId() {
         return id;
@@ -30,4 +32,20 @@ public class RoomVO {
     public void setPrice(Double price) {
         this.price = price;
     }
+
+    public Integer getCurNum() {
+        return curNum;
+    }
+
+    public void setCurNum(Integer curNum) {
+        this.curNum = curNum;
+    }
+
+    public Integer getTotal() {
+        return total;
+    }
+
+    public void setTotal(Integer total) {
+        this.total = total;
+    }
 }

+ 3 - 0
src/main/resources/dataImpl/hotel/HotelMapper.xml

@@ -11,6 +11,9 @@
     <select id="selectAllHotel" resultMap="Hotel">
         select * from Hotel
     </select>
+    <select id="selectById" resultMap="Hotel">
+        select * from Hotel where id=#{id}
+    </select>
 
 
     <resultMap id="Hotel" type="com.example.hotel.vo.HotelVO">

+ 3 - 3
src/main/resources/dataImpl/hotel/RoomMapper.xml

@@ -5,7 +5,7 @@
     <insert id="insertRoom" parameterType="com.example.hotel.po.HotelRoom"
     useGeneratedKeys="true" keyProperty="id">
         insert into Room(roomType,price,curNum,total,hotel_id)
-        values (#{roomType},#{price},#{curNum},#{total},#{hotel_id]})
+        values (#{roomType},#{price},#{curNum},#{total},#{hotelId})
     </insert>
 
     <select id="selectRoomsByHotelId" resultMap="room">
@@ -15,11 +15,11 @@
 
     <resultMap id="room" type="com.example.hotel.po.HotelRoom">
         <id column="id" property="id"></id>
-        <result column="roomType" property="type"></result>
+        <result column="roomType" property="roomType"></result>
         <result column="price" property="price"></result>
         <result column="curNum" property="curNum"></result>
         <result column="total" property="total"></result>
-        <result column="hotel_id" property="hotel_id"></result>
+        <result column="hotel_id" property="hotelId"></result>
     </resultMap>