package com.ym.mec.web.controller.education;

import com.ym.mec.biz.dal.entity.Employee;
import com.ym.mec.biz.dal.entity.Teacher;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.io.IOException;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ym.mec.biz.dal.enums.EmployeeOperateEnum;
import com.ym.mec.biz.dal.page.EmployeeQueryInfo;
import com.ym.mec.biz.service.EmployeeService;
import com.ym.mec.common.controller.BaseController;

/**
 * @Author Joburgess
 * @Date 2019/9/17
 */
@RequestMapping("employee")
@Api(tags = "员工管理")
@RestController
public class EmployeeController extends BaseController {

    @Autowired
    private EmployeeService employeeService;

    @ApiOperation(value = "根据部门获取下面的员工")
    @GetMapping("/queryEmployByOrganId")
    public Object queryEmployByOrganId(EmployeeQueryInfo queryInfo) throws IOException {
        return succeed(employeeService.queryEmployByOrganId(queryInfo));
    }

    @ApiOperation(value = "员工操作")
    @PostMapping("/employeeOperate")
    public Object employeeOperate(Long employeeId, EmployeeOperateEnum operate){
        employeeService.employeeOperate(employeeId,operate);
        return succeed();
    }

    @ApiOperation(value = "新增员工")
    @PostMapping("/add")
    public Object add(Employee employee) {
        try {
            employeeService.add(employee);
        } catch (Exception e) {
            e.printStackTrace();
            return failed(e.getMessage());
        }
        return succeed();
    }

    @ApiOperation(value = "修改员工")
    @PostMapping("/update")
    public Object update(Employee employee) {
        employee.setUpdateTime(new Date());
        employeeService.updateEmployee(employee);
        return succeed();
    }

    @ApiOperation(value = "删除员工")
    @PostMapping("/delete/{userId}")
    public Object update(@PathVariable("userId") Long userId) {
        employeeService.deleteEmployee(userId);
        return succeed();
    }
}
