package com.keao.edu.user.controller;


import com.keao.edu.common.controller.BaseController;
import com.keao.edu.common.entity.HttpResponseResult;
import com.keao.edu.common.page.PageInfo;
import com.keao.edu.common.tenant.OrganContextHolder;
import com.keao.edu.common.tenant.TenantContextHolder;
import com.keao.edu.user.entity.Teacher;
import com.keao.edu.user.page.TeacherQueryInfo;
import com.keao.edu.user.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 系统配置控制层
 */
@RestController
@Api(tags = "教师服务")
@RequestMapping(value = "teacher")
public class TeacherController extends BaseController {

	@Autowired
	private TeacherService teacherService;

	@ApiOperation(value = "教师列表")
	@GetMapping(value = "list")
    @PreAuthorize("@pcs.hasPermissions('teacher/list')")
	public HttpResponseResult<PageInfo<Teacher>> list(TeacherQueryInfo queryInfo) {
		/*if(queryInfo.getOrganId() != null){
			queryInfo.setOrganIds(organizationService.getChildOrganIds(queryInfo.getOrganId(),true));
		}*/
		return succeed(teacherService.queryTeacherPage(queryInfo));
	}

	@ApiOperation(value = "修改教师")
	@PostMapping(value = "update")
    @PreAuthorize("@pcs.hasPermissions('teacher/update')")
	public HttpResponseResult update(@RequestBody Teacher teacher) {
		teacherService.updateTeacher(teacher);
		return succeed();
	}

	@ApiOperation(value = "新增教师")
	@PostMapping(value = "add")
    @PreAuthorize("@pcs.hasPermissions('teacher/add')")
	public HttpResponseResult add(@RequestBody Teacher teacher) {
		teacher.setTenantId(TenantContextHolder.getTenantId());
		teacher.setOrganId(OrganContextHolder.getOrganId());
		return succeed(teacherService.add(teacher));
	}

	@ApiOperation(value = "查询教师")
	@GetMapping(value = "get")
    @PreAuthorize("@pcs.hasPermissions('teacher/get')")
	public HttpResponseResult<Teacher> get(Integer id) {
		return succeed(teacherService.get(id));
	}

	@ApiOperation(value = "删除教师")
	@PostMapping(value = "del")
    @PreAuthorize("@pcs.hasPermissions('teacher/del')")
	public HttpResponseResult del(Integer id) {
		teacherService.del(id);
		return succeed();
	}
}
