package com.qmth.teachcloud.report.api;

import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.teachcloud.common.contant.SystemConstant;
import com.qmth.teachcloud.common.util.Result;
import com.qmth.teachcloud.common.util.ResultUtil;
import com.qmth.teachcloud.report.business.entity.TAExamCourse;
import com.qmth.teachcloud.report.business.entity.TAExamCourseTeacher;
import com.qmth.teachcloud.report.business.entity.TAExamTotal;
import com.qmth.teachcloud.report.business.enums.OrderEnum;
import com.qmth.teachcloud.report.business.service.TAExamCourseCollegeTeacherService;
import com.qmth.teachcloud.report.business.service.TAExamCourseService;
import com.qmth.teachcloud.report.business.service.TAExamTotalService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Api(tags = "数据驾驶舱Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/${prefix.url.reportSchool}")
public class DataDriveController {

    @Autowired
    private TAExamTotalService taExamTotalService;

    @Autowired
    private TAExamCourseService taExamCourseService;

    @Autowired
    private TAExamCourseCollegeTeacherService taExamCourseCollegeTeacherService;

    @ApiOperation(value = "全校考试总览-全校考试概况")
    @RequestMapping(value = "/exam/get_overview", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "全校考试总览-全校考试概况", response = TAExamTotal.class)})
    public Result getOverview(@ApiParam(value = "学期id", required = true) @RequestParam String semesterId,
                              @ApiParam(value = "考试ID", required = true) @RequestParam Long examId) {
        return ResultUtil.ok(taExamTotalService.getOverview(SystemConstant.convertIdToLong(semesterId), examId));
    }

    @ApiOperation(value = "全校考试总览-全校课程考试分析汇总")
    @RequestMapping(value = "/exam/get_course_summary", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "全校考试总览-全校考试概况", response = TAExamCourse.class)})
    public Result getCourseSummary(@ApiParam(value = "学期id", required = true) @RequestParam String semesterId,
                                   @ApiParam(value = "考试ID", required = true) @RequestParam Long examId,
                                   @ApiParam(value = "分页页码", required = true) @RequestParam Integer pageNumber,
                                   @ApiParam(value = "分页数量", required = true) @RequestParam Integer pageSize,
                                   @ApiParam(value = "排序列", required = false) @RequestParam(required = false) String column,
                                   @ApiParam(value = "排序规则", required = false) @RequestParam(required = false) OrderEnum order) {
        return ResultUtil.ok(taExamTotalService.getCourseSummary(SystemConstant.convertIdToLong(semesterId), examId, pageNumber, pageSize, column, order));
    }

    @ApiOperation(value = "全校考试总览-全校课程考试分析汇总-导出课程分析Excel报表")
    @RequestMapping(value = "/exam/export_course_summary", method = RequestMethod.POST)
    public void exportCourseSummary(@ApiParam(value = "学期id", required = true) @RequestParam String semesterId,
                                    @ApiParam(value = "考试ID", required = true) @RequestParam Long examId,
                                    @ApiParam(value = "排序列", required = false) @RequestParam(required = false) String column,
                                    @ApiParam(value = "排序规则", required = false) @RequestParam(required = false) OrderEnum order) throws Exception {
        taExamTotalService.exportCourseSummary(SystemConstant.convertIdToLong(semesterId), examId, column, order);
    }

    @ApiOperation(value = "全校课程考试分析-全校考试概况")
    @RequestMapping(value = "/course/get_overview", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "全校考试总览-全校考试概况", response = TAExamCourse.class)})
    public Result getOverview(@ApiParam(value = "学期id", required = true) @RequestParam String semesterId,
                              @ApiParam(value = "考试ID", required = true) @RequestParam Long examId,
                              @ApiParam(value = "课程代码", required = true) @RequestParam String courseCode) {
        return ResultUtil.ok(taExamCourseService.getOverview(SystemConstant.convertIdToLong(semesterId), examId, courseCode));
    }

    @ApiOperation(value = "全校课程考试分析-分数段分布情况")
    @RequestMapping(value = "/course/get_grade_distribute", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "全校课程考试分析-分数段分布情况", response = Map.class)})
    public Result getGradeDistribute(@ApiParam(value = "学期id", required = true) @RequestParam String semesterId,
                                     @ApiParam(value = "考试ID", required = true) @RequestParam Long examId,
                                     @ApiParam(value = "课程代码", required = true) @RequestParam String courseCode) {
        return ResultUtil.ok(taExamCourseService.getGradeDistribute(SystemConstant.convertIdToLong(semesterId), examId, courseCode));
    }

    @ApiOperation(value = "全校课程考试分析-教师各课堂成绩排名")
    @RequestMapping(value = "/course/list_teacher_class_rank", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "全校课程考试分析-教师各课堂成绩排名", response = TAExamCourseTeacher.class)})
    public Result listTeacherClassRank(@ApiParam(value = "学期id", required = true) @RequestParam String semesterId,
                                       @ApiParam(value = "考试ID", required = true) @RequestParam Long examId,
                                       @ApiParam(value = "课程代码", required = true) @RequestParam String courseCode,
                                       @ApiParam(value = "分页页码", required = true) @RequestParam Integer pageNumber,
                                       @ApiParam(value = "分页数量", required = true) @RequestParam Integer pageSize,
                                       @ApiParam(value = "排序列", required = false) @RequestParam(required = false) String column,
                                       @ApiParam(value = "排序规则", required = false) @RequestParam(required = false) OrderEnum order) {
        return ResultUtil.ok(taExamCourseCollegeTeacherService.listTeacherClassRank(SystemConstant.convertIdToLong(semesterId), examId, courseCode, pageNumber, pageSize, column, order));
    }

    @ApiOperation(value = "全校课程考试分析-考试概况-导出课程分析报表")
    @RequestMapping(value = "/course/export_data_analysis", method = RequestMethod.POST)
    public void exportDataAnalysis(@ApiParam(value = "学期id", required = true) @RequestParam String semesterId,
                                   @ApiParam(value = "考试ID", required = true) @RequestParam Long examId,
                                   @ApiParam(value = "课程代码", required = true) @RequestParam String courseCode) throws Exception {
        taExamTotalService.exportDataAnalysis(SystemConstant.convertIdToLong(semesterId), examId, courseCode);
    }

    @ApiOperation(value = "全校教师各课堂成绩排名")
    @RequestMapping(value = "/teacher/list_all_teacher_class_rank", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "全校课程考试分析-教师各课堂成绩排名", response = TAExamCourseTeacher.class)})
    public Result listAllTeacherClassRank(@ApiParam(value = "学期id", required = true) @RequestParam String semesterId,
                                          @ApiParam(value = "考试ID", required = true) @RequestParam Long examId,
                                          @ApiParam(value = "考查学院ID", required = true) @RequestParam(required = false) Long inspectCollegeId,
                                          @ApiParam(value = "课程代码", required = true) @RequestParam(required = false) String courseCode,
                                          @ApiParam(value = "教师ID", required = true) @RequestParam(required = false) Long teacherId,
                                          @ApiParam(value = "分页页码", required = true) @RequestParam Integer pageNumber,
                                          @ApiParam(value = "分页数量", required = true) @RequestParam Integer pageSize,
                                          @ApiParam(value = "排序列", required = false) @RequestParam(required = false) String column,
                                          @ApiParam(value = "排序规则", required = false) @RequestParam(required = false) OrderEnum order) {
        return ResultUtil.ok(taExamCourseCollegeTeacherService.listAllTeacherClassRank(SystemConstant.convertIdToLong(semesterId), examId, inspectCollegeId, courseCode, teacherId, pageNumber, pageSize, column, order));
    }
}
