package com.keao.edu.user.controller;


import com.keao.edu.auth.api.client.SysUserFeignService;
import com.keao.edu.auth.api.entity.SysUser;
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.page.QueryInfo;
import com.keao.edu.user.api.entity.Student;
import com.keao.edu.user.dto.StudentExamPaymentDto;
import com.keao.edu.user.page.StudentApplyQueryInfo;
import com.keao.edu.user.service.StudentService;
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.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统配置控制层
 */
@RestController
@Api(tags = "学员服务")
@RequestMapping(value = "student")
public class StudentController extends BaseController {

	@Autowired
	private StudentService studentService;
	@Autowired
	private SysUserFeignService sysUserFeignService;

	@ApiOperation(value = "学员列表")
	@GetMapping(value = "list")
    @PreAuthorize("@pcs.hasPermissions('student/list')")
	public HttpResponseResult<PageInfo<Student>> list(QueryInfo queryInfo) {
		return succeed(studentService.queryStudentPage(queryInfo));
	}

	@ApiOperation(value = "学员报考列表")
	@PostMapping(value = "applyList")
    @PreAuthorize("@pcs.hasPermissions('student/applyList')")
	public HttpResponseResult<PageInfo<StudentExamPaymentDto>> applyList(StudentApplyQueryInfo queryInfo) {
		return succeed(studentService.queryApplyList(queryInfo));
	}

	@ApiOperation(value = "查询学员")
	@GetMapping(value = "get")
    @PreAuthorize("@pcs.hasPermissions('student/get')")
	public HttpResponseResult<Student> get(Integer id) {
		return succeed(studentService.get(id));
	}

	@ApiOperation(value = "学员报名")
	@PostMapping(value = "apply")
	public HttpResponseResult apply(Integer organId,String phone) {
		Student student = new Student(organId, phone);
		studentService.addStudent(student);
		return succeed();
	}

	@ApiOperation(value = "获取学生信息")
	@GetMapping(value = "getStudent")
	public HttpResponseResult<Student> getStudent() {
		SysUser user = sysUserFeignService.queryUserInfo();
		return succeed(studentService.getStudent(user.getId()));
	}
}
