mirror of
				https://github.com/FreeeBird/hotel.git
				synced 2025-11-04 14:34:47 +08:00 
			
		
		
		
	完成房间类型接口编写,通过单元测试
This commit is contained in:
		@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -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<Room> getAllRoom(){
 | 
			
		||||
        List<Room> result = roomService.selectAll();
 | 
			
		||||
        for (Room r:result) {
 | 
			
		||||
        }
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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<RoomType> 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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -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{" +
 | 
			
		||||
 
 | 
			
		||||
@@ -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<Worker> selectByRole(String role);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -11,5 +11,5 @@ public interface WorkerService {
 | 
			
		||||
    Worker selectById(int workerId);
 | 
			
		||||
    List<Worker> findAll();
 | 
			
		||||
    List<Worker> selectByRole(String role);
 | 
			
		||||
    Worker login(String username,String password);
 | 
			
		||||
    Worker login(String username,String password,String role);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										17
									
								
								src/main/java/cn/mafangui/hotel/utils/RoomStaticUtil.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/main/java/cn/mafangui/hotel/utils/RoomStaticUtil.java
									
									
									
									
									
										Normal file
									
								
							@@ -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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user