package com.ym.mec.education.controller;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.service.TeacherAttendanceService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.education.base.PageResponse;
import com.ym.mec.education.req.TeacherLeaveRecordReq;
import com.ym.mec.education.service.ITeacherAttendanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
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 java.util.Date;
import java.util.Objects;

/**
 * @program: mec
 * @description: 老师考勤 上课
 * @author: xw
 * @create: 2019-09-30 13:54
 */
@RestController
@RequestMapping("api/teacherAttendance")
@Api(tags = "老师考勤/上课")
public class TeacherAttendanceController extends BaseController {

    @Autowired
    private ITeacherAttendanceService teacherAttendanceService;
    @Autowired
    private TeacherAttendanceService iteacherAttendanceService;
    @Autowired
    private SysUserFeignService sysUserFeignService;

    @PostMapping("/list")
    @ApiOperation("老师上课记录列表")
    public PageResponse list(@RequestBody TeacherLeaveRecordReq teacherLeaveRecordReq) {
        return teacherAttendanceService.getPage(teacherLeaveRecordReq);
    }

    @PostMapping("/findTeacherAbnormalSignInCourseScheduleRecord")
    @ApiOperation("根据日期获取部门下异常签到的课程记录")
    public Object findTeacherAbnormalSignInCourseScheduleRecord(Date date, Integer signInStatus) {
        SysUser user = sysUserFeignService.queryUserInfo();
        if(Objects.isNull(user)){
            return failed(HttpStatus.FORBIDDEN,"请登录");
        }
        return succeed(iteacherAttendanceService.findTeacherAbnormalSignInCourseScheduleRecord(user.getOrganId(),date,signInStatus));
    }

    @PostMapping("/findTeacherAbnormalSignInDates")
    @ApiOperation("根据月份获取部门下异常签到的日期")
    public Object findTeacherAbnormalSignInDates(Date month) {
        SysUser user = sysUserFeignService.queryUserInfo();
        if(Objects.isNull(user)){
            return failed(HttpStatus.FORBIDDEN,"请登录");
        }
        return succeed(iteacherAttendanceService.findTeacherAbnormalSignInDates(user.getOrganId(),month));
    }

    @PostMapping("/countTeacherAbnormalSignInClassTimes")
    @ApiOperation("根据日期获取对应签到状态的课程数量")
    public Object countTeacherAbnormalSignInClassTimes(Date date) {
        SysUser user = sysUserFeignService.queryUserInfo();
        if(Objects.isNull(user)){
            return failed(HttpStatus.FORBIDDEN,"请登录");
        }
        return iteacherAttendanceService.countTeacherAbnormalSignInClassTimes(user.getOrganId(),date);
    }
}
