package com.ym.mec.teacher.controller;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.dao.TeacherDao;
import com.ym.mec.biz.dal.dto.VipGroupApplyDto;
import com.ym.mec.biz.dal.dto.VipGroupCostCountParamsDto;
import com.ym.mec.biz.dal.entity.Teacher;
import com.ym.mec.biz.dal.page.StudentManageQueryInfo;
import com.ym.mec.biz.service.StudentManageService;
import com.ym.mec.biz.service.VipGroupService;
import com.ym.mec.common.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * @Author Joburgess
 * @Date 2019/9/21
 */
@Api(tags = "vip课-教师端")
@RequestMapping("teacherVipGroup")
@RestController
public class TeacherVipGroupController extends BaseController {

	@Autowired
	private VipGroupService vipGroupService;
	@Autowired
	private SysUserFeignService sysUserFeignService;
	@Autowired
	private TeacherDao teacherDao;
	@Autowired
	private StudentManageService studentManageService;

	@ApiOperation("vip课申请")
	@PostMapping("/vipGroupApply")
	public Object vipGroupApply(@RequestBody VipGroupApplyDto vipGroupApplyDto) {
		SysUser user = sysUserFeignService.queryUserInfo();
		if (Objects.isNull(user)) {
			return failed(HttpStatus.FORBIDDEN, "请登录");
		}
		Integer userId = user.getId();
		Teacher teacher = teacherDao.get(userId);
		vipGroupApplyDto.getVipGroupApplyBaseInfo().setUserId(userId);
		vipGroupApplyDto.getVipGroupApplyBaseInfo().setTeacherId(Long.valueOf(userId));
		vipGroupApplyDto.getVipGroupApplyBaseInfo().setOrganIdList(teacher.getTeacherOrganId().toString());
		vipGroupApplyDto.getVipGroupApplyBaseInfo().setOrganId(teacher.getTeacherOrganId());
		vipGroupService.createVipGroup(vipGroupApplyDto);
		return succeed();
	}

	@ApiOperation("获取vip课课程和课酬总费用")
	@PostMapping("/getVipGroupCostCount")
	public Object getVipGroupCostCount(VipGroupCostCountParamsDto vipGroupCostCountParamsDto) {
		// return succeed(vipGroupService.vipGroupCostCount(vipGroupCostCountParamsDto));
		return succeed();
	}

	@ApiOperation("获取vip课教学点")
	@PostMapping("/getSchools")
	public Object getSchools() {
		SysUser user = sysUserFeignService.queryUserInfo();
		if (Objects.isNull(user)) {
			return failed(HttpStatus.FORBIDDEN, "请登录");
		}
		return succeed(vipGroupService.querySchoolByUserId(user.getId()));
	}

	@ApiOperation(value = "获取教师所在分部学生列表")
	@GetMapping("/queryStudentsWithTeacher")
	public Object queryStudentsWithTeacher(StudentManageQueryInfo queryInfo){
		SysUser user = sysUserFeignService.queryUserInfo();
		if (Objects.isNull(user)) {
			return failed(HttpStatus.FORBIDDEN, "请登录");
		}
		queryInfo.setTeacherId(user.getId());
		return succeed(studentManageService.queryStudentsWithTeacher(queryInfo));
	}

}
