mirror of
				https://github.com/FreeeBird/hotel.git
				synced 2025-10-31 20:44:52 +08:00 
			
		
		
		
	更新房间信息的接口
This commit is contained in:
		| @@ -3,18 +3,16 @@ package cn.mafangui.hotel.controller; | |||||||
|  |  | ||||||
| import cn.mafangui.hotel.entity.Room; | import cn.mafangui.hotel.entity.Room; | ||||||
| import cn.mafangui.hotel.service.RoomService; | import cn.mafangui.hotel.service.RoomService; | ||||||
|  | import cn.mafangui.hotel.utils.finalString; | ||||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||||
| import org.springframework.web.bind.annotation.RequestMapping; | import org.springframework.web.bind.annotation.RequestMapping; | ||||||
| import org.springframework.web.bind.annotation.RestController; | import org.springframework.web.bind.annotation.RestController; | ||||||
|  |  | ||||||
| import java.awt.print.PrinterException; |  | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| import java.util.List; |  | ||||||
|  |  | ||||||
| @RestController | @RestController | ||||||
| @RequestMapping(value = "roomInfo") | @RequestMapping(value = "/roomInfo") | ||||||
| public class RoomController { | public class RoomController { | ||||||
|  |  | ||||||
|     @Autowired |     @Autowired | ||||||
|     private RoomService roomService; |     private RoomService roomService; | ||||||
|  |  | ||||||
| @@ -29,15 +27,18 @@ public class RoomController { | |||||||
|      * @param roomStatus |      * @param roomStatus | ||||||
|      * @return |      * @return | ||||||
|      */ |      */ | ||||||
|     @RequestMapping(value = "add") |     @RequestMapping(value = "/add") | ||||||
|     public int addRoom(String roomNumber, int roomFloor, int roomType, String typeName, double roomPrice,double roomDiscount,String roomStatus){ |     public HashMap addRoom(String roomNumber, int roomFloor, int roomType, String typeName, double roomPrice,double roomDiscount,String roomStatus){ | ||||||
|         int result = 0; |         HashMap result = new HashMap(); | ||||||
|  |         int data = 0; | ||||||
|         Room room = new Room(roomNumber,roomFloor,roomType,typeName,roomPrice,roomDiscount,roomStatus); |         Room room = new Room(roomNumber,roomFloor,roomType,typeName,roomPrice,roomDiscount,roomStatus); | ||||||
|         try { |         try { | ||||||
|             result = roomService.addRoom(room); |             data = roomService.addRoom(room); | ||||||
|         }catch (Exception e){ |         }catch (Exception e){ | ||||||
|             result = -1; |             data = -1; | ||||||
|         } |         } | ||||||
|  |         result.put(finalString.CODE,20000); | ||||||
|  |         result.put(finalString.DATA,data); | ||||||
|         return result; |         return result; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -47,18 +48,21 @@ public class RoomController { | |||||||
|      * @param roomNumber |      * @param roomNumber | ||||||
|      * @return |      * @return | ||||||
|      */ |      */ | ||||||
|     @RequestMapping(value = "delete") |     @RequestMapping(value = "/delete") | ||||||
|     public int deleteRoom(int roomId,String roomNumber){ |     public HashMap deleteRoom(int roomId,String roomNumber){ | ||||||
|         int result = 0; |         HashMap result = new HashMap(); | ||||||
|  |         int data = 0; | ||||||
|         try { |         try { | ||||||
|             if (roomNumber == null || "".equals(roomNumber)){ |             if (roomNumber == null || "".equals(roomNumber)){ | ||||||
|                 result = roomService.deleteRoom(roomId); |                 data = roomService.deleteRoom(roomId); | ||||||
|             }else { |             }else { | ||||||
|                 result = roomService.deleteRoom(roomNumber); |                 data = roomService.deleteRoom(roomNumber); | ||||||
|             } |             } | ||||||
|         }catch (Exception e){ |         }catch (Exception e){ | ||||||
|             result = -1; |             data = -1; | ||||||
|         } |         } | ||||||
|  |         result.put(finalString.CODE,20000); | ||||||
|  |         result.put(finalString.DATA,data); | ||||||
|         return result; |         return result; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -74,16 +78,19 @@ public class RoomController { | |||||||
|      * @param roomStatus |      * @param roomStatus | ||||||
|      * @return |      * @return | ||||||
|      */ |      */ | ||||||
|     @RequestMapping(value = "update") |     @RequestMapping(value = "/update") | ||||||
|     public int updateRoom(int roomId,String roomNumber, int roomFloor, int roomType, String typeName, double roomPrice,double roomDiscount,String roomStatus){ |     public HashMap updateRoom(int roomId,String roomNumber, int roomFloor, int roomType, String typeName, double roomPrice,double roomDiscount,String roomStatus){ | ||||||
|         int result = 0; |         HashMap result = new HashMap(); | ||||||
|  |         int data = 0; | ||||||
|         Room room = new Room(roomNumber,roomFloor,roomType,typeName,roomPrice,roomDiscount,roomStatus); |         Room room = new Room(roomNumber,roomFloor,roomType,typeName,roomPrice,roomDiscount,roomStatus); | ||||||
|         room.setRoomId(roomId); |         room.setRoomId(roomId); | ||||||
|         try { |         try { | ||||||
|             result = roomService.updateRoom(room); |             data = roomService.updateRoom(room); | ||||||
|         }catch (Exception e){ |         }catch (Exception e){ | ||||||
|             result = -1; |             data = -1; | ||||||
|         } |         } | ||||||
|  |         result.put(finalString.CODE,20000); | ||||||
|  |         result.put(finalString.DATA,data); | ||||||
|         return result; |         return result; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -94,23 +101,44 @@ public class RoomController { | |||||||
|     @RequestMapping(value = "/all") |     @RequestMapping(value = "/all") | ||||||
|     public HashMap allRoom(){ |     public HashMap allRoom(){ | ||||||
|         HashMap result = new HashMap(); |         HashMap result = new HashMap(); | ||||||
|         result.put("data",roomService.findAll()); |         result.put(finalString.DATA,roomService.findAll()); | ||||||
|         result.put("code",20000); |         result.put(finalString.CODE,20000); | ||||||
|         return result; |         return result; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 根据状态查询房间信息 |      * 根据id | ||||||
|  |      * 查询房间信息 | ||||||
|  |      * @param roomId | ||||||
|  |      * @return | ||||||
|  |      */ | ||||||
|  |     @RequestMapping(value = "/withId") | ||||||
|  |     public HashMap findRoomById(int roomId){ | ||||||
|  |         HashMap result = new HashMap(); | ||||||
|  |         result.put(finalString.CODE,20000); | ||||||
|  |         try{ | ||||||
|  |             result.put(finalString.DATA,roomService.findById(roomId)); | ||||||
|  |         }catch (Exception e){ | ||||||
|  |             result.put(finalString.DATA,-1); | ||||||
|  |         } | ||||||
|  |         return result; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 根据房号查询房间信息 | ||||||
|      * @param roomNumber |      * @param roomNumber | ||||||
|      * @return |      * @return | ||||||
|      */ |      */ | ||||||
|     @RequestMapping(value = "/withRoomNumber") |     @RequestMapping(value = "/withRoomNumber") | ||||||
|     public Room findRoomByNumber(String roomNumber){ |     public HashMap findRoomByNumber(String roomNumber){ | ||||||
|  |         HashMap result = new HashMap(); | ||||||
|  |         result.put(finalString.CODE,20000); | ||||||
|         try{ |         try{ | ||||||
|             return roomService.findByNumber(roomNumber); |             result.put(finalString.DATA,roomService.findByNumber(roomNumber)); | ||||||
|         }catch (Exception e){ |         }catch (Exception e){ | ||||||
|             return null; |             result.put(finalString.DATA,-1); | ||||||
|         } |         } | ||||||
|  |         return result; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -119,12 +147,15 @@ public class RoomController { | |||||||
|      * @return |      * @return | ||||||
|      */ |      */ | ||||||
|     @RequestMapping(value = "/withStatus") |     @RequestMapping(value = "/withStatus") | ||||||
|     public List<Room> findRoomByStatus(String roomStatus){ |     public HashMap findRoomByStatus(String roomStatus){ | ||||||
|  |         HashMap result = new HashMap(); | ||||||
|  |         result.put(finalString.CODE,20000); | ||||||
|         try{ |         try{ | ||||||
|             return roomService.findByStatus(roomStatus); |             result.put(finalString.DATA,roomService.findByStatus(roomStatus)); | ||||||
|         }catch (Exception e){ |         }catch (Exception e){ | ||||||
|             return null; |             result.put(finalString.DATA,-1); | ||||||
|         } |         } | ||||||
|  |         return result; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -133,11 +164,14 @@ public class RoomController { | |||||||
|      * @return |      * @return | ||||||
|      */ |      */ | ||||||
|     @RequestMapping(value = "/withType") |     @RequestMapping(value = "/withType") | ||||||
|     public List<Room> findRoomByType(String typeName){ |     public HashMap findRoomByType(String typeName){ | ||||||
|  |         HashMap result = new HashMap(); | ||||||
|  |         result.put(finalString.CODE,20000); | ||||||
|         try{ |         try{ | ||||||
|             return roomService.findByType(typeName); |             result.put(finalString.DATA,roomService.findByType(typeName)); | ||||||
|         }catch (Exception e){ |         }catch (Exception e){ | ||||||
|             return null; |             result.put(finalString.DATA,-1); | ||||||
|         } |         } | ||||||
|  |         return result; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,6 +1,7 @@ | |||||||
| package cn.mafangui.hotel.utils; | package cn.mafangui.hotel.utils; | ||||||
|  |  | ||||||
| public class finalString { | public class finalString { | ||||||
|     private final String CODE = "code"; |     public static final String CODE = "code"; | ||||||
|     private final String DATA = "data"; |     public static final String DATA = "data"; | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user