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.controller;
 | 
			
		||||
 | 
			
		||||
import cn.mafangui.hotel.entity.Worker;
 | 
			
		||||
import cn.mafangui.hotel.service.WorkerService;
 | 
			
		||||
import cn.mafangui.hotel.utils.StaticString;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
@@ -7,18 +8,14 @@ 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 = "/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)
 | 
			
		||||
@@ -26,6 +23,39 @@ public class OperatorController {
 | 
			
		||||
        else return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @RequestMapping(method = RequestMethod.POST,value = "/delete")
 | 
			
		||||
    public int deleteOperator(int workerId){
 | 
			
		||||
        return workerService.delete(workerId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @RequestMapping(value = "/all")
 | 
			
		||||
    public List<Worker> getAllOperator(){
 | 
			
		||||
        return workerService.selectByRole(StaticString.OPERATOR);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @RequestMapping(method = RequestMethod.POST,value = "/withId")
 | 
			
		||||
    public Worker getOperator(int workerId){
 | 
			
		||||
        return workerService.selectById(workerId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @RequestMapping(method = RequestMethod.POST,value = "/add")
 | 
			
		||||
    public int addOperator(String username,String password,String name,String gender,String phone,String email,String address){
 | 
			
		||||
        Worker worker = new Worker(username,password,name,gender,phone,email,address);
 | 
			
		||||
        worker.setRole(StaticString.OPERATOR);
 | 
			
		||||
        return workerService.insert(worker);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @RequestMapping(method = RequestMethod.POST,value = "/update")
 | 
			
		||||
    public int updateOperator(int workerId,String name,String gender,String phone,String email,String address){
 | 
			
		||||
        Worker worker = new Worker();
 | 
			
		||||
        worker.setWorkerId(workerId);
 | 
			
		||||
        worker.setName(name);
 | 
			
		||||
        worker.setGender(gender);
 | 
			
		||||
        worker.setPhone(phone);
 | 
			
		||||
        worker.setEmail(email);
 | 
			
		||||
        worker.setAddress(address);
 | 
			
		||||
        return workerService.updateById(worker);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // TODO
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -123,6 +123,19 @@ public class Worker {
 | 
			
		||||
        this.updateTime = updateTime;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Worker() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Worker(String username, String password, String name, String gender, String phone, String email, String address) {
 | 
			
		||||
        this.username = username;
 | 
			
		||||
        this.password = password;
 | 
			
		||||
        this.name = name;
 | 
			
		||||
        this.gender = gender;
 | 
			
		||||
        this.phone = phone;
 | 
			
		||||
        this.email = email;
 | 
			
		||||
        this.address = address;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        return "Worker{" +
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user