Browse Source

上传酒店信息&&列表查看酒店信息

YPLee 6 years ago
parent
commit
f9c81b06df

+ 25 - 0
.gitignore

@@ -0,0 +1,25 @@
+/target/
+!.mvn/wrapper/maven-wrapper.jar
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+.DS_Store
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+/build/

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

@@ -0,0 +1,20 @@
+package com.example.hotel.bl.hotel;
+
+import com.example.hotel.vo.HotelVO;
+
+import java.util.List;
+
+public interface HotelService {
+
+    /**
+     * 添加酒店
+     * @param hotelVO
+     */
+    void addHotel(HotelVO hotelVO);
+
+    /**
+     * 列表获取酒店信息
+     * @return
+     */
+    List<HotelVO> retrieveHotels();
+}

+ 48 - 0
src/main/java/com/example/hotel/blImpl/hotel/HotelServiceImpl.java

@@ -0,0 +1,48 @@
+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.user.AccountMapper;
+import com.example.hotel.enums.BizRegion;
+import com.example.hotel.enums.HotelStar;
+import com.example.hotel.po.Hotel;
+import com.example.hotel.vo.HotelVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class HotelServiceImpl implements HotelService {
+
+    @Autowired
+    private AccountMapper accountMapper;
+    @Autowired
+    private HotelMapper hotelMapper;
+
+
+
+
+    @Override
+    public void addHotel(HotelVO hotelVO) {
+
+        // TODO: 2020-02-28 检查user是否为管理员
+        Hotel hotel = new Hotel();
+        hotel.setDescription(hotelVO.getDescription());
+        hotel.setAddress(hotelVO.getAddress());
+        hotel.setHotelName(hotelVO.getName());
+        hotel.setPhoneNum(hotelVO.getPhoneNum());
+        hotel.setManagerId(hotelVO.getManagerId());
+        hotel.setRate(hotelVO.getRate());
+        hotel.setBizRegion(BizRegion.valueOf(hotelVO.getBizRegion()));
+        hotel.setHotelStar(HotelStar.valueOf(hotelVO.getHotelStar()));
+        hotelMapper.insertHotel(hotel);
+
+    }
+
+    @Override
+    public List<HotelVO> retrieveHotels() {
+
+        return hotelMapper.selectAllHotel();
+    }
+}

+ 1 - 0
src/main/java/com/example/hotel/blImpl/user/AccountServiceImpl.java

@@ -20,6 +20,7 @@ public class AccountServiceImpl implements AccountService {
         try {
             accountMapper.createNewAccount(userForm.getEmail(), userForm.getPassword());
         } catch (Exception e) {
+            System.out.println(e.getMessage());
             return ResponseVO.buildFailure(ACCOUNT_EXIST);
         }
         return ResponseVO.buildSuccess();

+ 1 - 1
src/main/java/com/example/hotel/config/InterceptorConfiguration.java

@@ -9,7 +9,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  * @author huwen
  * @date 2019/3/23
  */
-@Configuration
+
 public class InterceptorConfiguration implements WebMvcConfigurer {
     public final static String SESSION_KEY = "user";
 

+ 29 - 0
src/main/java/com/example/hotel/controller/hotel/HotelController.java

@@ -0,0 +1,29 @@
+package com.example.hotel.controller.hotel;
+
+import com.example.hotel.bl.hotel.HotelService;
+import com.example.hotel.util.Result;
+import com.example.hotel.vo.HotelVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+@RestController
+@RequestMapping("/api/hotel")
+public class HotelController {
+
+    @Autowired
+    private HotelService hotelService;
+
+    @PostMapping()
+    public ResponseEntity<?> createHotel(@RequestBody HotelVO hotelVO) {
+
+        hotelService.addHotel(hotelVO);
+        return Result.ok();
+    }
+
+    @GetMapping("/all")
+    public ResponseEntity<?> retrieveAllHotels(){
+
+        return Result.ok(hotelService.retrieveHotels());
+    }
+}

+ 1 - 0
src/main/java/com/example/hotel/controller/user/AccountController.java

@@ -28,6 +28,7 @@ public class AccountController {
         session.setAttribute(InterceptorConfiguration.SESSION_KEY,userForm);
         return ResponseVO.buildSuccess(user);
     }
+
     @PostMapping("/register")
     public ResponseVO registerAccount(@RequestBody UserForm userForm){
         return accountService.registerAccount(userForm);

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

@@ -0,0 +1,18 @@
+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.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Mapper
+@Repository
+public interface HotelMapper {
+
+    int insertHotel(Hotel hotel);
+
+    List<HotelVO> selectAllHotel();
+
+}

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

@@ -0,0 +1,16 @@
+package com.example.hotel.data.hotel;
+
+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 java.util.List;
+
+@Mapper
+public interface RoomMapper {
+
+    int insertRoom(HotelRoom hotelRoom);
+
+    List<HotelRoom> selectRoomsByHotelId(@Param("hotelId") Integer hotelId);
+}

+ 5 - 6
src/main/java/com/example/hotel/data/user/AccountMapper.java

@@ -3,21 +3,20 @@ package com.example.hotel.data.user;
 import com.example.hotel.vo.UserVO;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
 
-/**
- * @author huwen
- * @date 2019/3/23
- */
 @Mapper
+@Repository
 public interface AccountMapper {
 
     /**
      * 创建一个新的账号
-     * @param username
+     * @param email
      * @param password
      * @return
      */
-    public int createNewAccount(@Param("username") String username, @Param("password") String password);
+    public int createNewAccount(@Param("email") String email, @Param("password") String password);
 
     /**
      * 根据用户名查找账号

+ 20 - 0
src/main/java/com/example/hotel/enums/HotelService.java

@@ -0,0 +1,20 @@
+package com.example.hotel.enums;
+
+public enum HotelService {
+    WiFi("Wifi"),
+
+    HotWater("热水"),
+
+    WakeUp("叫醒服务");
+
+    private String value;
+
+    HotelService(String value){
+        this.value = value;
+    }
+
+    @Override
+    public String toString() {
+        return value;
+    }
+}

+ 14 - 3
src/main/java/com/example/hotel/enums/HotelStar.java

@@ -1,7 +1,18 @@
 package com.example.hotel.enums;
 
 public enum HotelStar {
-    Five,
-    Four,
-    Three;
+    Five("五星级"),
+    Four("四星级"),
+    Three("三星级");
+
+    private String value;
+
+    HotelStar(String value) {
+        this.value = value;
+    }
+
+    @Override
+    public String toString() {
+        return value;
+    }
 }

+ 1 - 4
src/main/java/com/example/hotel/interceptor/SessionInterceptor.java

@@ -7,10 +7,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 
-/**
- * @author huwen
- * @date 2019/3/23
- */
+
 public class SessionInterceptor extends HandlerInterceptorAdapter {
     @Override
     public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object handler) throws Exception{

+ 74 - 1
src/main/java/com/example/hotel/po/Hotel.java

@@ -5,7 +5,7 @@ import com.example.hotel.enums.HotelStar;
 
 public class Hotel {
     private Integer id;
-    private String name;
+    private String hotelName;
     private String address;
     /**
      * 商圈
@@ -15,8 +15,81 @@ public class Hotel {
     private Double rate;
     private String description;
     private String phoneNum;
+    /**
+     * 酒店管理员id
+     */
+    private Integer managerId;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getHotelName() {
+        return hotelName;
+    }
+
+    public void setHotelName(String hotelName) {
+        this.hotelName = hotelName;
+    }
+
+    public String getAddress() {
+        return address;
+    }
+
+    public void setAddress(String address) {
+        this.address = address;
+    }
+
+    public BizRegion getBizRegion() {
+        return bizRegion;
+    }
 
+    public void setBizRegion(BizRegion bizRegion) {
+        this.bizRegion = bizRegion;
+    }
 
+    public HotelStar getHotelStar() {
+        return hotelStar;
+    }
 
+    public void setHotelStar(HotelStar hotelStar) {
+        this.hotelStar = hotelStar;
+    }
 
+    public Double getRate() {
+        return rate;
+    }
+
+    public void setRate(Double rate) {
+        this.rate = rate;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public String getPhoneNum() {
+        return phoneNum;
+    }
+
+    public void setPhoneNum(String phoneNum) {
+        this.phoneNum = phoneNum;
+    }
+
+    public Integer getManagerId() {
+        return managerId;
+    }
+
+    public void setManagerId(Integer managerId) {
+        this.managerId = managerId;
+    }
 }
+

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

@@ -5,12 +5,12 @@ import com.example.hotel.enums.RoomType;
 public class HotelRoom {
     private Integer id;
     private RoomType type;
-    private Hotel hotel;
+    private Integer hotel_id;
     private double price;
     /**
      * 当前剩余可预定房间数
      */
-    private int active;
+    private int curNum;
     /**
      * 某类型房间总数
      */
@@ -32,12 +32,12 @@ public class HotelRoom {
         this.type = type;
     }
 
-    public Hotel getHotel() {
-        return hotel;
+    public Integer getHotel_id() {
+        return hotel_id;
     }
 
-    public void setHotel(Hotel hotel) {
-        this.hotel = hotel;
+    public void setHotel_id(Integer hotel_id) {
+        this.hotel_id = hotel_id;
     }
 
     public double getPrice() {
@@ -48,12 +48,12 @@ public class HotelRoom {
         this.price = price;
     }
 
-    public int getActive() {
-        return active;
+    public int getCurNum() {
+        return curNum;
     }
 
-    public void setActive(int active) {
-        this.active = active;
+    public void setCurNum(int curNum) {
+        this.curNum = curNum;
     }
 
     public int getTotal() {

+ 22 - 0
src/main/java/com/example/hotel/util/Result.java

@@ -0,0 +1,22 @@
+package com.example.hotel.util;
+
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+
+public class Result {
+    public static ResponseEntity<?> ok(Object object) {
+        return ResponseEntity.ok(object);
+    }
+
+    public static ResponseEntity<?> ok() {
+        return ok(null);
+    }
+
+    public static ResponseEntity<?> error(HttpStatus status, String msg) {
+        return ResponseEntity.status(status).body(msg);
+    }
+
+    public static ResponseEntity<?> error(HttpStatus status) {
+        return error(status, null);
+    }
+}

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

@@ -0,0 +1,102 @@
+package com.example.hotel.vo;
+
+import com.example.hotel.enums.BizRegion;
+import com.example.hotel.enums.HotelStar;
+import com.example.hotel.po.User;
+
+import java.util.List;
+
+public class HotelVO {
+    private Integer id;
+    private String name;
+    private String address;
+    private String bizRegion;
+    private String hotelStar;
+    private Double rate;
+    private String description;
+    private String phoneNum;
+    private Integer managerId;
+
+    private List<RoomVO> rooms;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getAddress() {
+        return address;
+    }
+
+    public void setAddress(String address) {
+        this.address = address;
+    }
+
+    public String getBizRegion() {
+        return bizRegion;
+    }
+
+    public void setBizRegion(String bizRegion) {
+        this.bizRegion = bizRegion;
+    }
+
+    public Double getRate() {
+        return rate;
+    }
+
+    public void setRate(Double rate) {
+        this.rate = rate;
+    }
+
+    public String getHotelStar() {
+        return hotelStar;
+    }
+
+    public void setHotelStar(String hotelStar) {
+        this.hotelStar = hotelStar;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public String getPhoneNum() {
+        return phoneNum;
+    }
+
+    public void setPhoneNum(String phoneNum) {
+        this.phoneNum = phoneNum;
+    }
+
+
+    public List<RoomVO> getRooms() {
+        return rooms;
+    }
+
+    public void setRooms(List<RoomVO> rooms) {
+        this.rooms = rooms;
+    }
+
+    public Integer getManagerId() {
+        return managerId;
+    }
+
+    public void setManagerId(Integer managerId) {
+        this.managerId = managerId;
+    }
+}

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

@@ -0,0 +1,33 @@
+package com.example.hotel.vo;
+
+import com.example.hotel.enums.RoomType;
+
+public class RoomVO {
+    private Integer id;
+    private String roomType;
+    private Double price;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getRoomType() {
+        return roomType;
+    }
+
+    public void setRoomType(String roomType) {
+        this.roomType = roomType;
+    }
+
+    public Double getPrice() {
+        return price;
+    }
+
+    public void setPrice(Double price) {
+        this.price = price;
+    }
+}

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

@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.example.hotel.data.hotel.HotelMapper">
+    <insert id="insertHotel" parameterType="com.example.hotel.po.Hotel"
+    useGeneratedKeys="true" keyProperty="id">
+        insert into Hotel(address,bizRegion,hotelDescription,hotelStar,hotelName,phoneNum,
+        rate,manager_id)
+        values (#{address},#{bizRegion},#{description},#{hotelStar},#{hotelName},#{phoneNum},#{rate},#{managerId})
+    </insert>
+
+    <select id="selectAllHotel" resultMap="Hotel">
+        select * from Hotel
+    </select>
+
+
+    <resultMap id="Hotel" type="com.example.hotel.vo.HotelVO">
+        <id column="id" property="id"></id>
+        <result column="address" property="address"></result>
+        <result column="bizRegion" property="bizRegion"></result>
+        <result column="hotelDescription" property="description"></result>
+        <result column="hotelStar" property="hotelStar"></result>
+        <result column="hotelName" property="name"></result>
+        <result column="phoneNum" property="phoneNum"></result>
+        <result column="rate" property="rate"></result>
+        <result column="manager_id" property="managerId"></result>
+
+    </resultMap>
+
+
+</mapper>

+ 26 - 0
src/main/resources/dataImpl/hotel/RoomMapper.xml

@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.example.hotel.data.hotel.RoomMapper">
+
+    <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]})
+    </insert>
+
+    <select id="selectRoomsByHotelId" resultMap="room">
+        select * from Room where hotel_id=#{hotelId}
+    </select>
+
+
+    <resultMap id="room" type="com.example.hotel.po.HotelRoom">
+        <id column="id" property="id"></id>
+        <result column="roomType" property="type"></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>
+    </resultMap>
+
+
+</mapper>

+ 3 - 3
src/main/resources/dataImpl/user/AccountMapper.xml

@@ -2,11 +2,11 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.example.hotel.data.user.AccountMapper">
     <insert id="createNewAccount" useGeneratedKeys="true" keyProperty="id">
-        insert into user(username,password)
-        values(#{username},#{password})
+        insert into User(email,password)
+        values(#{email},#{password})
     </insert>
     <select id="getAccountByName" resultMap="User">
-        select * from user where username=#{username}
+        select * from User where username=#{username}
     </select>
 
     <resultMap id="User" type="com.example.hotel.po.User">