package com.ym.mec.web.controller;

import com.ym.mec.biz.dal.dto.ClassDateAdjustDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ym.mec.biz.dal.entity.CourseSchedule;
import com.ym.mec.biz.dal.page.StudentAttendanceQueryInfo;
import com.ym.mec.biz.service.CourseScheduleService;
import com.ym.mec.biz.service.StudentAttendanceService;
import com.ym.mec.common.controller.BaseController;

/**
 * @Author Joburgess
 * @Date 2019/9/10
 */
@RequestMapping("courseSchedule")
@Api(tags = "课程计划服务")
@RestController
public class CourseScheduleController extends BaseController {

    @Autowired
    private CourseScheduleService scheduleService;
    @Autowired
    private StudentAttendanceService studentAttendanceService;

    @ApiOperation(value = "排课")
    @PostMapping("/batchAddCourseSchedule/{musicGroupID}")
    public Object batchAddCourseSchedule(@RequestBody List<CourseSchedule> courseSchedules,
                                         @ApiParam(value = "乐团编号", required = true) @PathVariable("musicGroupID") Long musicGroupID){
        scheduleService.batchAddCourseSchedule(courseSchedules);
        return succeed();
    }

    @ApiOperation(value = "批量跟新排课")
    @PostMapping("/batchUpdateCourseSchedule/{musicGroupID}")
    public Object batchUpdateCourseSchedule(@RequestBody List<CourseSchedule> courseSchedules,
                                            @ApiParam(value = "乐团编号", required = true) @PathVariable("musicGroupID") Long musicGroupID){
        scheduleService.batchUpdateCourseSchedule(courseSchedules,musicGroupID);
        return succeed();
    }

    @ApiOperation(value = "根据月份获取乐团在该月有课的日期")
    @GetMapping("/getCourseScheduleDateByMonth")
        public Object getCourseScheduleDateByMonth(@ApiParam(value = "乐团编号", required = true) @RequestParam Long musicGroupID,
                                                   @ApiParam(value = "月份", required = true) @RequestParam Date month) {
        return succeed(scheduleService.getCourseScheduleDateByMonth(musicGroupID,month));
    }

    @ApiOperation(value = "根据日期获取当日排课")
    @GetMapping("/getCourseSchedulesWithDate")
    public Object getCourseSchedulesWithDate(@ApiParam(value = "日期", required = true) Date date){
        return succeed(scheduleService.getCourseSchedulesWithDate(date));
    }

    @ApiOperation(value = "根据课程ID查询正在或即将开始的课程")
    @GetMapping("/getCurrentCourseDetail/{courseID}")
    public Object getCurrentCourseDetail(@ApiParam(value = "课程ID", required = true) @PathVariable("courseID") Long courseID){
        return succeed(scheduleService.getCurrentCourseDetail(courseID));
    }

    @ApiOperation(value = "根据班级ID获取当前课程的学生")
    @GetMapping("/getCurrentCourseStudents")
    public Object getCurrentCourseStudents(@RequestBody StudentAttendanceQueryInfo queryInfo){
        return succeed(studentAttendanceService.getCurrentCourseStudents(queryInfo));
    }

    @ApiOperation(value = "课时调整")
    @PostMapping(value = "/classStartDateAdjust",consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Object classStartDateAdjust(ClassDateAdjustDto classDateAdjustDto){
        scheduleService.classStartDateAdjust(classDateAdjustDto);
        return succeed();
    }

    @ApiOperation(value = "课时交换")
    @GetMapping(value = "/courseSwap",consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Object courseSwap(Long courseScheduleId1,Long courseScheduleId2){
        scheduleService.courseSwap(courseScheduleId1,courseScheduleId2);
        return succeed();
    }

}
