Selaa lähdekoodia

Merge branch 'master' of http://47.100.18.120:3000/LiuQin/HotelDemo

陈远志 6 vuotta sitten
vanhempi
commit
33d8507074

+ 3 - 0
src/main/java/com/example/hotel/bl/user/AccountService.java

@@ -1,5 +1,6 @@
 package com.example.hotel.bl.user;
 
+import com.example.hotel.vo.OrderVO;
 import com.example.hotel.vo.UserForm;
 import com.example.hotel.vo.ResponseVO;
 import com.example.hotel.vo.UserVO;
@@ -22,4 +23,6 @@ public interface AccountService {
      */
     public UserVO login(UserForm userForm);
 
+
+
 }

+ 19 - 0
src/main/java/com/example/hotel/bl/user/ClientService.java

@@ -0,0 +1,19 @@
+package com.example.hotel.bl.user;
+
+import com.example.hotel.vo.OrderVO;
+
+import java.util.List;
+
+/**
+ * @Author: chenyizong
+ * @Date: 2020-02-29
+ */
+public interface ClientService {
+    /**
+     * 预订酒店添加订单
+     * @param orderVO
+     */
+    void addOrder(OrderVO orderVO);
+
+    List<OrderVO> retrieveOrders();
+}

+ 42 - 0
src/main/java/com/example/hotel/blImpl/user/ClientServiceImpl.java

@@ -0,0 +1,42 @@
+package com.example.hotel.blImpl.user;
+
+import com.example.hotel.bl.user.ClientService;
+import com.example.hotel.data.user.OrderMapper;
+import com.example.hotel.po.Order;
+import com.example.hotel.vo.OrderVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * @Author: chenyizong
+ * @Date: 2020-02-29
+ */
+@Service
+public class ClientServiceImpl implements ClientService {
+    @Autowired
+    OrderMapper orderMapper;
+
+    @Override
+    public void addOrder(OrderVO orderVO) {
+        Order order = new Order();
+        order.setUserId(orderVO.getUserId());
+        order.setHotelId(orderVO.getHotelId());
+        order.setCheckInnDate(orderVO.getCheckInnDate());
+        order.setCheckOutDate(orderVO.getCheckOutDate());
+        order.setRoomType(orderVO.getRoomType());
+        order.setRoomNum(orderVO.getRoomNum());
+        order.setHaveChild(orderVO.isHaveChild());
+        order.setCreateDate(orderVO.getCreateDate());
+
+        orderMapper.insertOrder(order);
+
+
+    }
+
+    @Override
+    public List<OrderVO> retrieveOrders() {
+        return orderMapper.selectAllOrder();
+    }
+}

+ 27 - 0
src/main/java/com/example/hotel/config/CORSConfig.java

@@ -0,0 +1,27 @@
+package com.example.hotel.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+/**
+ * @Author: chenyizong
+ * @Date: 2020-02-29
+ */
+@Configuration
+public class CORSConfig {
+
+    @Bean
+    public WebMvcConfigurer corsConfigurer(){
+        return new WebMvcConfigurer() {
+            @Override
+            public void addCorsMappings(CorsRegistry registry) {
+                registry.addMapping("/**")
+                        .allowedHeaders("*")
+                        .allowedMethods("*")
+                        .allowedOrigins("*");
+            }
+        };
+    }
+}

+ 6 - 3
src/main/java/com/example/hotel/controller/user/AccountController.java

@@ -2,22 +2,24 @@ package com.example.hotel.controller.user;
 
 import com.example.hotel.blImpl.user.AccountServiceImpl;
 import com.example.hotel.config.InterceptorConfiguration;
+import com.example.hotel.po.Hotel;
+import com.example.hotel.vo.OrderVO;
 import com.example.hotel.vo.UserForm;
 import com.example.hotel.vo.ResponseVO;
 import com.example.hotel.vo.UserVO;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpSession;
 
 
 @RestController()
+@RequestMapping("/api")
 public class AccountController {
     private final static String ACCOUNT_INFO_ERROR="用户名或密码错误";
     @Autowired
     private AccountServiceImpl accountService;
+
     @PostMapping("/login")
     public ResponseVO login(@RequestBody UserForm userForm, HttpSession session){
         UserVO user = accountService.login(userForm);
@@ -39,4 +41,5 @@ public class AccountController {
         session.removeAttribute(InterceptorConfiguration.SESSION_KEY);
         return "index";
     }
+
 }

+ 35 - 0
src/main/java/com/example/hotel/controller/user/ClientController.java

@@ -0,0 +1,35 @@
+package com.example.hotel.controller.user;
+
+import com.example.hotel.bl.user.ClientService;
+import com.example.hotel.util.Result;
+import com.example.hotel.vo.OrderVO;
+import com.example.hotel.vo.ResponseVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * @Author: chenyizong
+ * @Date: 2020-02-29
+ */
+
+
+@RestController()
+@RequestMapping("/api")
+public class ClientController {
+    @Autowired
+    private ClientService clientService;
+
+    @PostMapping("/hotel/reserve")
+    public ResponseVO reserveHotel(@RequestBody OrderVO orderVO){
+        clientService.addOrder(orderVO);
+        return ResponseVO.buildSuccess(orderVO);
+    }
+
+    @GetMapping("/order/all")
+    public ResponseEntity<?> retrieveAllOrders(){
+        return Result.ok(clientService.retrieveOrders());
+    }
+
+
+}

+ 20 - 0
src/main/java/com/example/hotel/data/user/OrderMapper.java

@@ -0,0 +1,20 @@
+package com.example.hotel.data.user;
+
+import com.example.hotel.po.Order;
+import com.example.hotel.vo.OrderVO;
+import org.apache.ibatis.annotations.Mapper;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+/**
+ * @Author: chenyizong
+ * @Date: 2020-02-29
+ */
+@Mapper
+@Repository
+public interface OrderMapper {
+    int insertOrder(Order order);
+
+    List<OrderVO> selectAllOrder();
+}

+ 101 - 0
src/main/java/com/example/hotel/po/Order.java

@@ -0,0 +1,101 @@
+package com.example.hotel.po;
+
+import java.util.Date;
+
+/**
+ * @Author: chenyizong
+ * @Date: 2020-02-29
+ */
+public class Order {
+    private Integer id;
+    private Integer userId;
+    private Integer hotelId;
+    private Date checkInnDate;
+    private Date checkOutDate;
+    private String roomType;
+    private Integer roomNum;
+    private Integer peopleNum;
+    private boolean haveChild;
+    private Date createDate;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getUserId() {
+        return userId;
+    }
+
+    public void setUserId(Integer userId) {
+        this.userId = userId;
+    }
+
+    public Integer getHotelId() {
+        return hotelId;
+    }
+
+    public void setHotelId(Integer hotelId) {
+        this.hotelId = hotelId;
+    }
+
+    public Date getCheckInnDate() {
+        return checkInnDate;
+    }
+
+    public void setCheckInnDate(Date checkInnDate) {
+        this.checkInnDate = checkInnDate;
+    }
+
+    public Date getCheckOutDate() {
+        return checkOutDate;
+    }
+
+    public void setCheckOutDate(Date checkOutDate) {
+        this.checkOutDate = checkOutDate;
+    }
+
+    public String getRoomType() {
+        return roomType;
+    }
+
+    public void setRoomType(String roomType) {
+        this.roomType = roomType;
+    }
+
+    public Integer getRoomNum() {
+        return roomNum;
+    }
+
+    public void setRoomNum(Integer roomNum) {
+        this.roomNum = roomNum;
+    }
+
+    public Integer getPeopleNum() {
+        return peopleNum;
+    }
+
+    public void setPeopleNum(Integer peopleNum) {
+        this.peopleNum = peopleNum;
+    }
+
+    public boolean isHaveChild() {
+        return haveChild;
+    }
+
+    public void setHaveChild(boolean haveChild) {
+        this.haveChild = haveChild;
+    }
+
+    public Date getCreateDate() {
+        return createDate;
+    }
+
+    public void setCreateDate(Date createDate) {
+        this.createDate = createDate;
+    }
+
+}

+ 101 - 0
src/main/java/com/example/hotel/vo/OrderVO.java

@@ -0,0 +1,101 @@
+package com.example.hotel.vo;
+
+import java.util.Date;
+
+/**
+ * @Author: chenyizong
+ * @Date: 2020-02-29
+ */
+public class OrderVO {
+    private Integer id;
+    private Integer userId;
+    private Integer hotelId;
+    private Date checkInnDate;
+    private Date checkOutDate;
+    private String roomType;
+    private Integer roomNum;
+    private Integer peopleNum;
+    private boolean haveChild;
+    private Date createDate;
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getUserId() {
+        return userId;
+    }
+
+    public void setUserId(Integer userId) {
+        this.userId = userId;
+    }
+
+    public Integer getHotelId() {
+        return hotelId;
+    }
+
+    public void setHotelId(Integer hotelId) {
+        this.hotelId = hotelId;
+    }
+    public Date getCheckInnDate() {
+        return checkInnDate;
+    }
+
+    public void setCheckInnDate(Date checkInnDate) {
+        this.checkInnDate = checkInnDate;
+    }
+
+    public Date getCheckOutDate() {
+        return checkOutDate;
+    }
+
+    public void setCheckOutDate(Date checkOutDate) {
+        this.checkOutDate = checkOutDate;
+    }
+
+    public String getRoomType() {
+        return roomType;
+    }
+
+    public void setRoomType(String roomType) {
+        this.roomType = roomType;
+    }
+
+    public Integer getRoomNum() {
+        return roomNum;
+    }
+
+    public void setRoomNum(Integer roomNum) {
+        this.roomNum = roomNum;
+    }
+
+    public Integer getPeopleNum() {
+        return peopleNum;
+    }
+
+    public void setPeopleNum(Integer peopleNum) {
+        this.peopleNum = peopleNum;
+    }
+
+    public boolean isHaveChild() {
+        return haveChild;
+    }
+
+    public void setHaveChild(boolean haveChild) {
+        this.haveChild = haveChild;
+    }
+
+    public Date getCreateDate() {
+        return createDate;
+    }
+
+    public void setCreateDate(Date createDate) {
+        this.createDate = createDate;
+    }
+
+
+}

+ 1 - 1
src/main/resources/application.yml

@@ -2,7 +2,7 @@ spring:
   datasource:
      url: jdbc:mysql://localhost:3306/Hotel?serverTimezone=CTT&characterEncoding=UTF-8
      username: root
-     password: root
+     password: 1598753
      driver-class-name: com.mysql.cj.jdbc.Driver
      max-active: 200
      max-idle: 20