import requests
import app
class EmpApi:
    def __init__(self):
        self.emp_url = app.HOST + "/api/sys/user"
        #如果我们调用员工管理模块的相关接口时，先调用login.py,获取的app.HEADERS才能有令牌
        self.headers = app.HEADERS

    def add_emp(self, username, mobile):
        data = {"username": username,
                "mobile": mobile,
                "timeOfEntry": "2019-12-04",
                "formOfEmployment": 1,
                "workNumber": "10433",
                "departmentName": "测试",
                "departmentId": "1066239766607040512",
                "correctionTime": "2020-01-15T16:00:00.000Z"}
        #发送添加员工接口请求
        response=requests.post(self.emp_url,json=data,headers=self.headers)
        #返回添加员工接口的响应数据
        return response
    def query_emp(self):
        #查询员工接口
        url=self.emp_url+"/"+app.EMP_ID
        return requests.get(url,headers=self.headers)
    def modify_emp(self,username):
        #修改员工的URL应该和查询员工是一样的，所以拼接的时候也需要加上"/"
        url=self.emp_url+"/"+app.EMP_ID
        #从外部接收要修改的username，拼接成json数据
        data={
            "username":username
        }
        #返回查询结果
        return requests.put(url,json=data,headers=self.headers)
    def delete_emp(self):
        url=self.emp_url+"/"+app.EMP_ID
        #调用删除的http接口并返回响应数据
        return requests.delete(url,headers=self.headers)

