package com.qmth.themis.backend.api;

import javax.annotation.Resource;

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 com.qmth.themis.business.bean.backend.InvigilateListPatrolReportBean;
import com.qmth.themis.business.service.TIeReportService;
import com.qmth.themis.business.util.RedisUtil;
import com.qmth.themis.common.util.Result;
import com.qmth.themis.common.util.ResultUtil;

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

/**
 * 监考报表
 *
 * @Description:
 * @Author: xiatian
 * @Date: 2020-08-28
 */
@Api(tags = "监考报表")
@RestController
@RequestMapping("/${prefix.url.admin}/report")
public class TIeReportController {

    @Resource
    private TIeReportService reportService;

    @Resource
    RedisUtil redisUtil;

    @ApiOperation(value = "考试概览")
    @RequestMapping(value = "/exam_view", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "结果信息")})
    public Result examView(@ApiParam(value = "考试id", required = true) @RequestParam Long examId,
                           @ApiParam(value = "考场场次id", required = false) @RequestParam(required = false) Long examActivityId,
                           @ApiParam(value = "虚拟考场代码", required = false) @RequestParam(required = false) String roomCode,
                           @ApiParam(value = "科目编码", required = false) @RequestParam(required = false) String courseCode,
                           @ApiParam(value = "姓名", required = false) @RequestParam(required = false) String name,
                           @ApiParam(value = "唯一码", required = false) @RequestParam(required = false) String identity) {
        return ResultUtil.ok(reportService.examView(examId, examActivityId, roomCode, courseCode, name, identity));
    }

    @ApiOperation(value = "情况统计")
    @RequestMapping(value = "/exam_view_count", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "结果信息")})
    public Result examViewCount(@ApiParam(value = "考试id", required = true) @RequestParam Long examId,
                                @ApiParam(value = "考场场次id", required = false) @RequestParam(required = false) Long examActivityId,
                                @ApiParam(value = "虚拟考场代码", required = false) @RequestParam(required = false) String roomCode,
                                @ApiParam(value = "科目编码", required = false) @RequestParam(required = false) String courseCode,
                                @ApiParam(value = "姓名", required = false) @RequestParam(required = false) String name,
                                @ApiParam(value = "唯一码", required = false) @RequestParam(required = false) String identity,
                                @ApiParam(value = "分页页码", required = true) @RequestParam int pageNumber,
                                @ApiParam(value = "分页数", required = true) @RequestParam int pageSize) {
        return ResultUtil.ok(reportService.examViewCount(examId, examActivityId, roomCode, courseCode, name, identity, pageNumber, pageSize));
    }


    @ApiOperation(value = "缺考名单")
    @RequestMapping(value = "/exam_deficiency_list", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "结果信息")})
    public Result examDeficiencyList(@ApiParam(value = "考试id", required = true) @RequestParam Long examId,
                                     @ApiParam(value = "考场场次id", required = false) @RequestParam(required = false) Long examActivityId,
                                     @ApiParam(value = "虚拟考场代码", required = false) @RequestParam(required = false) String roomCode,
                                     @ApiParam(value = "科目编码", required = false) @RequestParam(required = false) String courseCode,
                                     @ApiParam(value = "姓名", required = false) @RequestParam(required = false) String name,
                                     @ApiParam(value = "唯一码", required = false) @RequestParam(required = false) String identity,
                                     @ApiParam(value = "分页页码", required = true) @RequestParam int pageNumber,
                                     @ApiParam(value = "分页数", required = true) @RequestParam int pageSize) {
        return ResultUtil.ok(reportService.examDeficiencyList(examId, examActivityId, roomCode, courseCode, name, identity, pageNumber, pageSize));
    }

    @ApiOperation(value = "异常处理")
    @RequestMapping(value = "/exam_exception_list", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "结果信息")})
    public Result examExceptionList(@ApiParam(value = "考试id", required = true) @RequestParam Long examId,
                                    @ApiParam(value = "考场场次id", required = false) @RequestParam(required = false) Long examActivityId,
                                    @ApiParam(value = "虚拟考场代码", required = false) @RequestParam(required = false) String roomCode,
                                    @ApiParam(value = "科目编码", required = false) @RequestParam(required = false) String courseCode,
                                    @ApiParam(value = "姓名", required = false) @RequestParam(required = false) String name,
                                    @ApiParam(value = "唯一码", required = false) @RequestParam(required = false) String identity,
                                    @ApiParam(value = "分页页码", required = true) @RequestParam int pageNumber,
                                    @ApiParam(value = "分页数", required = true) @RequestParam int pageSize) {
        return ResultUtil.ok(reportService.examExceptionList(examId, examActivityId, roomCode, courseCode, name, identity, pageNumber, pageSize));
    }

    @ApiOperation(value = "异常处理明细")
    @RequestMapping(value = "/exam_exception_list_detail", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "结果信息")})
    public Result examExceptionListDetail(@ApiParam(value = "考生id", required = true) @RequestParam Long examStudentId) {
        return ResultUtil.ok(reportService.examExceptionDetailList(examStudentId));
    }

    @ApiOperation(value = "重考处理")
    @RequestMapping(value = "/exam_reexam_list", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "结果信息")})
    public Result examReexamList(@ApiParam(value = "考试id", required = true) @RequestParam Long examId,
                                 @ApiParam(value = "考场场次id", required = false) @RequestParam(required = false) Long examActivityId,
                                 @ApiParam(value = "虚拟考场代码", required = false) @RequestParam(required = false) String roomCode,
                                 @ApiParam(value = "科目编码", required = false) @RequestParam(required = false) String courseCode,
                                 @ApiParam(value = "姓名", required = false) @RequestParam(required = false) String name,
                                 @ApiParam(value = "唯一码", required = false) @RequestParam(required = false) String identity,
                                 @ApiParam(value = "分页页码", required = true) @RequestParam int pageNumber,
                                 @ApiParam(value = "分页数", required = true) @RequestParam int pageSize) {
        return ResultUtil.ok(reportService.examReexamList(examId, examActivityId, roomCode, courseCode, name, identity, pageNumber, pageSize));
    }

    @ApiOperation(value = "违纪名单")
    @RequestMapping(value = "/exam_breach_list", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "结果信息")})
    public Result examBreachList(@ApiParam(value = "考试id", required = true) @RequestParam Long examId,
                                 @ApiParam(value = "考场场次id", required = false) @RequestParam(required = false) Long examActivityId,
                                 @ApiParam(value = "虚拟考场代码", required = false) @RequestParam(required = false) String roomCode,
                                 @ApiParam(value = "科目编码", required = false) @RequestParam(required = false) String courseCode,
                                 @ApiParam(value = "姓名", required = false) @RequestParam(required = false) String name,
                                 @ApiParam(value = "唯一码", required = false) @RequestParam(required = false) String identity,
                                 @ApiParam(value = "分页页码", required = true) @RequestParam int pageNumber,
                                 @ApiParam(value = "分页数", required = true) @RequestParam int pageSize) {
        return ResultUtil.ok(reportService.examBreachList(examId, examActivityId, roomCode, courseCode, name, identity, pageNumber, pageSize));
    }

    @ApiOperation(value = "违纪名单明细")
    @RequestMapping(value = "/exam_breach_list_detail", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "结果信息")})
    public Result examBreachListDetail(@ApiParam(value = "考生id", required = true) @RequestParam Long examStudentId) {
        return ResultUtil.ok(reportService.examBreachListDetail(examStudentId));
    }

    @ApiOperation(value = "撤销违纪名单")
    @RequestMapping(value = "/exam_revoke_breach_list", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "结果信息")})
    public Result examRevokeBreachList(@ApiParam(value = "考试id", required = true) @RequestParam Long examId,
                                       @ApiParam(value = "考场场次id", required = false) @RequestParam(required = false) Long examActivityId,
                                       @ApiParam(value = "虚拟考场代码", required = false) @RequestParam(required = false) String roomCode,
                                       @ApiParam(value = "科目编码", required = false) @RequestParam(required = false) String courseCode,
                                       @ApiParam(value = "姓名", required = false) @RequestParam(required = false) String name,
                                       @ApiParam(value = "唯一码", required = false) @RequestParam(required = false) String identity,
                                       @ApiParam(value = "分页页码", required = true) @RequestParam int pageNumber,
                                       @ApiParam(value = "分页数", required = true) @RequestParam int pageSize) {
        return ResultUtil.ok(reportService.examRevokeBreachList(examId, examActivityId, roomCode, courseCode, name, identity, pageNumber, pageSize));
    }

    @ApiOperation(value = "撤销违纪名单明细")
    @RequestMapping(value = "/exam_revoke_breach_list_detail", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "结果信息")})
    public Result examRevokeBreachListDetail(@ApiParam(value = "考生id", required = true) @RequestParam Long examStudentId) {
        return ResultUtil.ok(reportService.examRevokeBreachListDetail(examStudentId));
    }

    @ApiOperation(value = "考生日志")
    @RequestMapping(value = "/exam_student_log_list", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "结果信息")})
    public Result examStudentLogList(@ApiParam(value = "考试id", required = true) @RequestParam Long examId,
                                     @ApiParam(value = "考场场次id", required = false) @RequestParam(required = false) Long examActivityId,
                                     @ApiParam(value = "虚拟考场代码", required = false) @RequestParam(required = false) String roomCode,
                                     @ApiParam(value = "科目编码", required = false) @RequestParam(required = false) String courseCode,
                                     @ApiParam(value = "姓名", required = false) @RequestParam(required = false) String name,
                                     @ApiParam(value = "唯一码", required = false) @RequestParam(required = false) String identity,
                                     @ApiParam(value = "分页页码", required = true) @RequestParam int pageNumber,
                                     @ApiParam(value = "分页数", required = true) @RequestParam int pageSize) {
        return ResultUtil.ok(reportService.examStudentLogList(examId, examActivityId, roomCode, courseCode, name, identity, pageNumber, pageSize));
    }

    @ApiOperation(value = "考生日志明细")
    @RequestMapping(value = "/exam_student_log_list_detail", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "结果信息")})
    public Result examStudentLogListDetail(@ApiParam(value = "考生id", required = true) @RequestParam Long examStudentId) {
        return ResultUtil.ok(reportService.examStudentLogListDetail(examStudentId));
    }

    @ApiOperation(value = "在线巡考报表接口")
    @RequestMapping(value = "/patrol", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "在线巡考报表信息", response = InvigilateListPatrolReportBean.class)})
    public Result patrolReport(@ApiParam(value = "考试批次id", required = false) @RequestParam(required = false) Long examId) {
        return ResultUtil.ok(reportService.patrolReport(examId, null));
    }

    @ApiOperation(value = "考情监控-人数")
    @RequestMapping(value = "/examination_monitor/count", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "结果信息")})
    public Result examinationMonitorCount() {
        return ResultUtil.ok(reportService.examinationMonitorCount());
    }
    
    @ApiOperation(value = "考情监控-预警分布")
    @RequestMapping(value = "/examination_monitor/warn_distribution", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "结果信息")})
    public Result warnDistribution() {
        return ResultUtil.ok(reportService.warnDistribution());
    }
    
    @ApiOperation(value = "考情监控-预警时间趋势")
    @RequestMapping(value = "/examination_monitor/warn_trend", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "结果信息")})
    public Result warnTrend() {
        return ResultUtil.ok(reportService.warnTrend());
    }
    
    @ApiOperation(value = "考情监控-预警消息")
    @RequestMapping(value = "/examination_monitor/warn_msg", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "结果信息")})
    public Result warnMsg() {
        return ResultUtil.ok(reportService.warnMsg());
    }
}
