package com.ym.mec.teacher.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Objects;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.entity.CourseScheduleEvaluate;
import com.ym.mec.biz.dal.page.CourseScheduleQueryInfo;
import com.ym.mec.biz.dal.page.ImGroupNoticeQueryInfo;
import com.ym.mec.biz.service.ClassGroupService;
import com.ym.mec.biz.service.CourseScheduleEvaluateService;
import com.ym.mec.biz.service.ImGroupNoticeService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;

/**
 * @Author Joburgess
 * @Date 2019/10/17
 */
@Api(tags = "班级服务")
@RequestMapping("classGroup")
@RestController
public class ClassGroupController extends BaseController {

    @Autowired
    private ClassGroupService classGroupService;
    @Autowired
    private CourseScheduleEvaluateService courseScheduleEvaluateService;
    @Autowired
    private SysUserFeignService sysUserFeignService;
    @Autowired
    private ImGroupNoticeService imGroupNoticeService;

    @ApiOperation(value = "教师关联班级获取")
    @GetMapping("/findTeacherClassGroups")
    public Object findTeacherClassGroups(String type,String status){
        return succeed(classGroupService.findTeacherClassGroups(type,status));
    }

    @ApiOperation(value = "获取教师班级详情界面头部信息")
    @GetMapping("/findTeacherClassGroupInfo")
    public Object findTeacherClassGroupInfo(@ApiParam(value = "班级编号", required = true)Integer classGroupId){
        return succeed(classGroupService.findTeacherClassGroupInfo(classGroupId));
    }

    @ApiOperation(value = "获取班级对应学生列表")
    @GetMapping("/findTeacherClassStudents")
    public Object findTeacherClassStudents(CourseScheduleQueryInfo queryInfo){
        return succeed(classGroupService.findTeacherClassStudents(queryInfo));
    }

    @ApiOperation(value = "提交陪练报告")
    @PostMapping(value = "/addStudyReport")
    public HttpResponseResult addStudyReport(@RequestBody CourseScheduleEvaluate courseScheduleEvaluate) {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if(Objects.isNull(sysUser)){
            return failed(HttpStatus.FORBIDDEN,"请登录");
        }
        if(courseScheduleEvaluate.getClassGroupId()==null || courseScheduleEvaluate.getClassGroupId()<0){
            return failed(HttpStatus.BAD_REQUEST,"班级id必须大于0");
        }
        if(courseScheduleEvaluate.getItem()==null || courseScheduleEvaluate.getItem().isEmpty()){
            return failed(HttpStatus.BAD_REQUEST,"课程评价选项不能为空");
        }
        courseScheduleEvaluate.setTeacherId(sysUser.getId());
        return succeed(courseScheduleEvaluateService.addStudyReport(courseScheduleEvaluate));
    }

    @ApiOperation(value = "根据群编号，获取用户群名片")
    @GetMapping("/getUserInfoWithUserId")
    public Object getUserInfoWithUserId(Integer groupId,Integer userId) {
        if (groupId == null || userId == null) {
            return failed("参数校验错误");
        }
        return succeed(classGroupService.getUserInfoWithUserId(groupId,userId));
    }

    @ApiOperation(value = "获取最新一条群公告")
    @RequestMapping("/getNewNotice")
    public Object getNewNotice(Long groupId) {
        return succeed(imGroupNoticeService.queryLatestNotice(groupId));
    }

    @ApiOperation(value = "获取群公告列表")
    @RequestMapping("/queryNoticePage")
    public Object queryPage(ImGroupNoticeQueryInfo queryInfo) {
        return succeed(imGroupNoticeService.queryPage(queryInfo));
    }

}
