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