diff --git a/src/main/java/cn/mafangui/hotel/HotelApplication.java b/src/main/java/cn/mafangui/hotel/HotelApplication.java index 223ccc4..109d5b9 100644 --- a/src/main/java/cn/mafangui/hotel/HotelApplication.java +++ b/src/main/java/cn/mafangui/hotel/HotelApplication.java @@ -1,5 +1,6 @@ package cn.mafangui.hotel; +import cn.mafangui.hotel.utils.StaticString; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/src/main/java/cn/mafangui/hotel/controller/AdminController.java b/src/main/java/cn/mafangui/hotel/controller/AdminController.java new file mode 100644 index 0000000..4c29b82 --- /dev/null +++ b/src/main/java/cn/mafangui/hotel/controller/AdminController.java @@ -0,0 +1,43 @@ +package cn.mafangui.hotel.controller; + +import cn.mafangui.hotel.entity.Room; +import cn.mafangui.hotel.entity.RoomType; +import cn.mafangui.hotel.service.RoomService; +import cn.mafangui.hotel.service.RoomTypeService; +import cn.mafangui.hotel.service.WorkerService; +import cn.mafangui.hotel.utils.StaticString; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping(value = "/admin") +public class AdminController { + + @Autowired + private WorkerService workerService; + @Autowired + private RoomService roomService; + + + /** + * 管理员登录 + * @param username + * @param password + * @return + */ + @RequestMapping(method = RequestMethod.POST,value = "/login") + public int login(String username,String password){ + if(workerService.login(username,password, StaticString.ADMIN) != null) + return 1; + else return 0; + } + + + + + +} diff --git a/src/main/java/cn/mafangui/hotel/controller/OperatorController.java b/src/main/java/cn/mafangui/hotel/controller/OperatorController.java new file mode 100644 index 0000000..ed6621b --- /dev/null +++ b/src/main/java/cn/mafangui/hotel/controller/OperatorController.java @@ -0,0 +1,30 @@ +package cn.mafangui.hotel.controller; + +import cn.mafangui.hotel.service.WorkerService; +import cn.mafangui.hotel.utils.StaticString; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping(value = "/operator") +public class OperatorController { + @Autowired + private WorkerService workerService; + + /** + * 管理员登录 + * @param username + * @param password + * @return + */ + @RequestMapping(method = RequestMethod.POST,value = "/login") + public int login(String username,String password){ + if(workerService.login(username,password, StaticString.OPERATOR) != null) + return 1; + else return 0; + } + + +} diff --git a/src/main/java/cn/mafangui/hotel/controller/RoomController.java b/src/main/java/cn/mafangui/hotel/controller/RoomController.java new file mode 100644 index 0000000..17680fc --- /dev/null +++ b/src/main/java/cn/mafangui/hotel/controller/RoomController.java @@ -0,0 +1,25 @@ +package cn.mafangui.hotel.controller; + +import cn.mafangui.hotel.entity.Room; +import cn.mafangui.hotel.service.RoomService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping(value = "/room") +public class RoomController { + + @Autowired + private RoomService roomService; + + @RequestMapping(value = "/all") + public List getAllRoom(){ + List result = roomService.selectAll(); + for (Room r:result) { + } + return result; + } +} diff --git a/src/main/java/cn/mafangui/hotel/controller/RoomTypeController.java b/src/main/java/cn/mafangui/hotel/controller/RoomTypeController.java new file mode 100644 index 0000000..7513282 --- /dev/null +++ b/src/main/java/cn/mafangui/hotel/controller/RoomTypeController.java @@ -0,0 +1,51 @@ +package cn.mafangui.hotel.controller; + +import cn.mafangui.hotel.entity.RoomType; +import cn.mafangui.hotel.service.RoomTypeService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping(value = "/roomType") +public class RoomTypeController { + + @Autowired + private RoomTypeService roomTypeService; + + + @RequestMapping(value = "/all") + public List getAllRoomType(){ + return roomTypeService.findAllType(); + } + + @RequestMapping(method = RequestMethod.POST,value = "/add") + public int addRoomType(String roomType,Double price,Double discount,int area, + int bedNum,String bedSize,int window,String remark){ + RoomType rt = new RoomType(roomType,remark,price,discount,area,bedNum,bedSize,window); + int result = 0; + result = roomTypeService.insert(rt); + return result; + } + + @RequestMapping(method = RequestMethod.POST,value = "/update") + public int updateRoomType(int typeId,String roomType,Double price,Double discount,int area, + int bedNum,String bedSize,int window,String remark){ + RoomType rt = new RoomType(roomType,remark,price,discount,area,bedNum,bedSize,window); + rt.setTypeId(typeId); + int result = 0; + result = roomTypeService.update(rt); + return result; + } + + @RequestMapping(method = RequestMethod.POST,value = "/delete") + public int deleteRoomType(int typeId){ + int result = 0; + result = roomTypeService.delete(typeId); + return result; + } + +} diff --git a/src/main/java/cn/mafangui/hotel/entity/RoomType.java b/src/main/java/cn/mafangui/hotel/entity/RoomType.java index 800afad..d481d23 100644 --- a/src/main/java/cn/mafangui/hotel/entity/RoomType.java +++ b/src/main/java/cn/mafangui/hotel/entity/RoomType.java @@ -113,6 +113,20 @@ public class RoomType { this.updateTime = updateTime; } + public RoomType() { + } + + public RoomType(String roomType, String remark, Double price, Double discount, Integer area, Integer bedNum, String bedSize, Integer window) { + this.roomType = roomType; + this.remark = remark; + this.price = price; + this.discount = discount; + this.area = area; + this.bedNum = bedNum; + this.bedSize = bedSize; + this.window = window; + } + @Override public String toString() { return "RoomType{" + diff --git a/src/main/java/cn/mafangui/hotel/mapper/WorkerMapper.java b/src/main/java/cn/mafangui/hotel/mapper/WorkerMapper.java index 7a91008..3a4cad1 100644 --- a/src/main/java/cn/mafangui/hotel/mapper/WorkerMapper.java +++ b/src/main/java/cn/mafangui/hotel/mapper/WorkerMapper.java @@ -20,7 +20,7 @@ public interface WorkerMapper { int updateByPrimaryKey(Worker record); - Worker selectByUsernameAndPassword(@Param("username") String username, @Param("password") String password); + Worker selectByUsernameAndPassword(@Param("username") String username, @Param("password") String password, @Param("role") String role); List selectByRole(String role); diff --git a/src/main/java/cn/mafangui/hotel/service/WorkerService.java b/src/main/java/cn/mafangui/hotel/service/WorkerService.java index e708683..f6e6037 100644 --- a/src/main/java/cn/mafangui/hotel/service/WorkerService.java +++ b/src/main/java/cn/mafangui/hotel/service/WorkerService.java @@ -11,5 +11,5 @@ public interface WorkerService { Worker selectById(int workerId); List findAll(); List selectByRole(String role); - Worker login(String username,String password); + Worker login(String username,String password,String role); } diff --git a/src/main/java/cn/mafangui/hotel/service/impl/WorkerServiceImpl.java b/src/main/java/cn/mafangui/hotel/service/impl/WorkerServiceImpl.java index 4bb79dd..bac282f 100644 --- a/src/main/java/cn/mafangui/hotel/service/impl/WorkerServiceImpl.java +++ b/src/main/java/cn/mafangui/hotel/service/impl/WorkerServiceImpl.java @@ -45,7 +45,7 @@ public class WorkerServiceImpl implements WorkerService { } @Override - public Worker login(String username, String password) { - return workerMapper.selectByUsernameAndPassword(username,password); + public Worker login(String username, String password,String role) { + return workerMapper.selectByUsernameAndPassword(username,password,role); } } diff --git a/src/main/java/cn/mafangui/hotel/utils/RoomStaticUtil.java b/src/main/java/cn/mafangui/hotel/utils/RoomStaticUtil.java new file mode 100644 index 0000000..e993a5f --- /dev/null +++ b/src/main/java/cn/mafangui/hotel/utils/RoomStaticUtil.java @@ -0,0 +1,17 @@ +package cn.mafangui.hotel.utils; + +public class RoomStaticUtil { + public static final int UNAVAILABLE = 0; + public static final int AVAILABLE = 1; + public static final int OCCUPIED = 2; + public static final int IN_USE = 3; + public static final String[] STATUS = {"UNAVAILABLE","AVAILABLE","OCCUPIED","IN_USE",}; + + public RoomStaticUtil(){ + + } + public static String getRoomStatic(){ + + return null; + } +} diff --git a/src/main/java/cn/mafangui/hotel/utils/StaticString.java b/src/main/java/cn/mafangui/hotel/utils/StaticString.java index 38bb68d..a055f40 100644 --- a/src/main/java/cn/mafangui/hotel/utils/StaticString.java +++ b/src/main/java/cn/mafangui/hotel/utils/StaticString.java @@ -1,5 +1,7 @@ package cn.mafangui.hotel.utils; +import java.util.Map; + public class StaticString { public static final String CODE = "code"; public static final String STATUS = "status"; @@ -10,4 +12,16 @@ public class StaticString { */ public static final String ADMIN = "admin"; public static final String OPERATOR = "operator"; + + /** + * 房间状态 + */ + public static final int AVAILABLE = 1; + public static final int OCCUPIED = 0; + public static final int IN_USE = -1; + public static final int UNAVAILABLE = -2; + + + + } diff --git a/src/main/resources/mybatis/mapper/WorkerMapper.xml b/src/main/resources/mybatis/mapper/WorkerMapper.xml index 925af31..5cc1c91 100644 --- a/src/main/resources/mybatis/mapper/WorkerMapper.xml +++ b/src/main/resources/mybatis/mapper/WorkerMapper.xml @@ -27,7 +27,7 @@