Explorar el Código

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/main/java/com/example/hotel/bl/hotel/HotelService.java
#	src/main/java/com/example/hotel/blImpl/hotel/HotelServiceImpl.java
#	src/main/java/com/example/hotel/controller/hotel/HotelController.java
CHENYIZONG hace 6 años
padre
commit
d6785a1eed

+ 17 - 1
README.md

@@ -8,7 +8,21 @@
 
 Eg. 1.feature/酒店信息管理    2.hotfix/订单流程更改 
 
-每次commit时,添加的描述信息需要有一个特定的前缀,限定在以下范围(feat|doc|test|docs|chore|refactor|fix|style| perf): xxx    注意冒号后面有一个空格
+每次commit时,添加的描述信息需要有一个特定的前缀,限定在以下范围(feat|doc|test|docs|chore|refactor|fix|style| perf): xxx    **注意冒号后面有一个空格**
+
+feat - 新功能(feature)
+
+doc- 文档(documentation)
+
+style- 格式(不影响代码运行的变动)
+
+refactor- 重构(即不是新增功能,也不是修改bug的代码变动)
+
+fix- 修补bug
+
+test- 增加测试
+
+chore- 构建过程或辅助工具的变动
 
 Eg. 1.feat: 查看酒店信息功能完成  2.fix: 浏览酒店bug修复
 
@@ -16,6 +30,8 @@ Eg. 1.feat: 查看酒店信息功能完成  2.fix: 浏览酒店bug修复
 
 [https://github.com/xirong/my-git/blob/master/git-workflow-tutorial.md#23-gitflow%E5%B7%A5%E4%BD%9C%E6%B5%81](https://github.com/xirong/my-git/blob/master/git-workflow-tutorial.md#23-gitflow工作流)
 
+http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html
+
 
 
 ### 开发规范

+ 3 - 23
src/main/java/com/example/hotel/bl/hotel/HotelService.java

@@ -1,7 +1,7 @@
 package com.example.hotel.bl.hotel;
 
-import com.example.hotel.enums.RoomType;
 import com.example.hotel.po.HotelRoom;
+import com.example.hotel.util.ServiceException;
 import com.example.hotel.vo.HotelVO;
 
 import java.util.List;
@@ -11,16 +11,9 @@ public interface HotelService {
     /**
      * 添加酒店
      * @param hotelVO
+     * @throws
      */
-    void addHotel(HotelVO hotelVO);
-
-    /**
-     * 预订酒店修改剩余客房信息
-     * @param hotelId
-     * @param roomType
-     * @param rooms
-     */
-    void updateRoomInfo(Integer hotelId, String roomType,Integer rooms);
+    void addHotel(HotelVO hotelVO) throws ServiceException;
 
     /**
      * 列表获取酒店信息
@@ -35,17 +28,4 @@ public interface HotelService {
      */
     HotelVO retrieveHotelDetails(Integer hotelId);
 
-    /**
-     * 添加酒店客房信息
-     * @param hotelRoom
-     */
-    void addHotelRoomInfo(HotelRoom hotelRoom);
-
-    /**
-     * 查看酒店剩余某种房间数量
-     * @param hotelId
-     * @param roomType
-     * @return
-     */
-    int getRoomCurNum(Integer hotelId,String roomType);
 }

+ 21 - 0
src/main/java/com/example/hotel/bl/hotel/RoomService.java

@@ -0,0 +1,21 @@
+package com.example.hotel.bl.hotel;
+
+import com.example.hotel.po.HotelRoom;
+
+import java.util.List;
+
+public interface RoomService {
+
+    /**
+     * 获取某个酒店的全部房间信息
+     * @param hotelId
+     * @return
+     */
+    List<HotelRoom> retrieveHotelRoomInfo(Integer hotelId);
+
+    /**
+     * 添加酒店客房信息
+     * @param hotelRoom
+     */
+    void insertRoomInfo(HotelRoom hotelRoom);
+}

+ 14 - 19
src/main/java/com/example/hotel/blImpl/hotel/HotelServiceImpl.java

@@ -1,14 +1,18 @@
 package com.example.hotel.blImpl.hotel;
 
 import com.example.hotel.bl.hotel.HotelService;
+import com.example.hotel.bl.hotel.RoomService;
+import com.example.hotel.bl.user.AccountService;
 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.enums.UserType;
 import com.example.hotel.po.Hotel;
 import com.example.hotel.po.HotelRoom;
 import com.example.hotel.po.User;
+import com.example.hotel.util.ServiceException;
 import com.example.hotel.vo.HotelVO;
 import com.example.hotel.vo.RoomVO;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,12 +26,18 @@ public class HotelServiceImpl implements HotelService {
 
     @Autowired
     private HotelMapper hotelMapper;
-    @Autowired
-    private RoomMapper roomMapper;
 
+    @Autowired
+    private AccountService accountService;
+    @Autowired
+    private RoomService roomService;
 
     @Override
-    public void addHotel(HotelVO hotelVO) {
+    public void addHotel(HotelVO hotelVO) throws ServiceException {
+        User manager = accountService.getUserInfo(hotelVO.getManagerId());
+        if(manager == null || !manager.getUserType().equals(UserType.HotelManager)){
+            throw new ServiceException("管理员不存在或者无权限!创建酒店失败!");
+        }
         Hotel hotel = new Hotel();
         hotel.setDescription(hotelVO.getDescription());
         hotel.setAddress(hotelVO.getAddress());
@@ -38,12 +48,6 @@ public class HotelServiceImpl implements HotelService {
         hotel.setBizRegion(BizRegion.valueOf(hotelVO.getBizRegion()));
         hotel.setHotelStar(HotelStar.valueOf(hotelVO.getHotelStar()));
         hotelMapper.insertHotel(hotel);
-
-    }
-
-    @Override
-    public void updateRoomInfo(Integer hotelId, String roomType, Integer rooms) {
-        roomMapper.updateRoomInfo(hotelId,roomType,rooms);
     }
 
     @Override
@@ -55,7 +59,7 @@ public class HotelServiceImpl implements HotelService {
     @Override
     public HotelVO retrieveHotelDetails(Integer hotelId) {
         HotelVO hotelVO = hotelMapper.selectById(hotelId);
-        List<HotelRoom> rooms = roomMapper.selectRoomsByHotelId(hotelId);
+        List<HotelRoom> rooms = roomService.retrieveHotelRoomInfo(hotelId);
         List<RoomVO> roomVOS = rooms.stream().map(r -> {
             RoomVO roomVO = new RoomVO();
             roomVO.setId(r.getId());
@@ -70,13 +74,4 @@ public class HotelServiceImpl implements HotelService {
         return hotelVO;
     }
 
-    @Override
-    public void addHotelRoomInfo(HotelRoom hotelRoom) {
-        roomMapper.insertRoom(hotelRoom);
-    }
-
-    @Override
-    public int getRoomCurNum(Integer hotelId, String roomType) {
-        return roomMapper.getRoomCurNum(hotelId,roomType);
-    }
 }

+ 28 - 0
src/main/java/com/example/hotel/blImpl/hotel/RoomServiceImpl.java

@@ -0,0 +1,28 @@
+package com.example.hotel.blImpl.hotel;
+
+import com.example.hotel.bl.hotel.RoomService;
+import com.example.hotel.data.hotel.RoomMapper;
+import com.example.hotel.po.HotelRoom;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class RoomServiceImpl implements RoomService {
+
+    @Autowired
+    private RoomMapper roomMapper;
+
+    @Override
+    public List<HotelRoom> retrieveHotelRoomInfo(Integer hotelId) {
+        return roomMapper.selectRoomsByHotelId(hotelId);
+    }
+
+    @Override
+    public void insertRoomInfo(HotelRoom hotelRoom) {
+        roomMapper.insertRoom(hotelRoom);
+    }
+
+
+}

+ 8 - 3
src/main/java/com/example/hotel/controller/hotel/HotelController.java

@@ -1,7 +1,9 @@
 package com.example.hotel.controller.hotel;
 
 import com.example.hotel.bl.hotel.HotelService;
+import com.example.hotel.bl.hotel.RoomService;
 import com.example.hotel.po.HotelRoom;
+import com.example.hotel.util.ServiceException;
 import com.example.hotel.vo.HotelVO;
 import com.example.hotel.vo.ResponseVO;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -13,9 +15,12 @@ public class HotelController {
 
     @Autowired
     private HotelService hotelService;
+    @Autowired
+    private RoomService roomService;
+
 
     @PostMapping("/addHotel")
-    public ResponseVO createHotel(@RequestBody HotelVO hotelVO) {
+    public ResponseVO createHotel(@RequestBody HotelVO hotelVO) throws ServiceException {
 
         hotelService.addHotel(hotelVO);
         return ResponseVO.buildSuccess(true);
@@ -28,8 +33,8 @@ public class HotelController {
 
     @PostMapping("/roomInfo")
     public ResponseVO addRoomInfo(@RequestBody HotelRoom hotelRoom) {
-        hotelService.addHotelRoomInfo(hotelRoom);
-        return ResponseVO.buildSuccess(true);
+        roomService.insertRoomInfo(hotelRoom);
+        return ResponseVO.buildSuccess();
     }
 
     @GetMapping("/{hotelId}/detail")

+ 32 - 0
src/main/java/com/example/hotel/util/ServiceException.java

@@ -0,0 +1,32 @@
+package com.example.hotel.util;
+
+import org.springframework.http.HttpStatus;
+
+public class ServiceException extends Exception {
+    private int error;
+
+    public ServiceException() {
+        this(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
+    }
+
+    public ServiceException(int error) {
+        this(error, message(error));
+    }
+
+    public ServiceException(String message) {
+        this(HttpStatus.INTERNAL_SERVER_ERROR.value(), message);
+    }
+
+    public ServiceException(int error, String message) {
+        super(message);
+        this.error = error;
+    }
+
+    private static String message(int error) {
+        try {
+            return HttpStatus.valueOf(error).getReasonPhrase();
+        } catch (IllegalArgumentException e) {
+            return HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase();
+        }
+    }
+}

+ 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: 123456
+     password: root
      driver-class-name: com.mysql.cj.jdbc.Driver
      max-active: 200
      max-idle: 20