package com.qmth.teachcloud.report.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qmth.boot.api.annotation.Aac;
import com.qmth.boot.api.annotation.BOOL;
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.bean.result.TBExamStudentResult;
import com.qmth.teachcloud.report.business.service.TBExamStudentService;
import com.qmth.teachcloud.report.business.utils.EncrypAES;
import io.swagger.annotations.*;
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 javax.annotation.Resource;

@Api(tags = "学生报告Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/${prefix.url.reportExamStudent}")
public class StudentReportController {

    @Resource
    TBExamStudentService tbExamStudentService;

    @ApiOperation(value = "学生报告预览-列表接口")
    @RequestMapping(value = "/report/list", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "考生信息", response = TBExamStudentResult.class)})
    public Result reportList(@ApiParam(value = "学校id", required = false) @RequestParam(required = false) String schoolId,
                             @ApiParam(value = "考试id", required = true) @RequestParam(required = false) String examId,
                             @ApiParam(value = "考察学院id", required = true) @RequestParam(required = false) String inspectCollegeId,
                             @ApiParam(value = "科目编码", required = true) @RequestParam(required = false) String courseCode,
                             @ApiParam(value = "班级id", required = true) @RequestParam(required = false) String clazzId,
                             @ApiParam(value = "是否缺考", required = true) @RequestParam(required = false) Boolean isAbsent,
                             @ApiParam(value = "学号", required = true) @RequestParam(required = false) String studentCode,
                             @ApiParam(value = "分页页码", required = true) @RequestParam int pageNumber,
                             @ApiParam(value = "分页数", required = true) @RequestParam int pageSize) {
        return ResultUtil.ok(tbExamStudentService.reportList(new Page<>(pageNumber, pageSize), SystemConstant.convertIdToLong(schoolId),
                SystemConstant.convertIdToLong(examId),
                SystemConstant.convertIdToLong(inspectCollegeId),
                courseCode,
                SystemConstant.convertIdToLong(clazzId),
                isAbsent, studentCode));
    }

    @ApiOperation(value = "学生报告-个人成绩总览接口")
    @RequestMapping(value = "/report/result", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "考生信息", response = TBExamStudentResult.class)})
    @Aac(auth = BOOL.FALSE)
    public Result reportResult(@ApiParam(value = "学校id", required = false) @RequestParam(required = false) String schoolId,
                               @ApiParam(value = "学号", required = true) @RequestParam String studentCode) {
        studentCode = EncrypAES.decrypt(studentCode);
        return ResultUtil.ok(tbExamStudentService.reportResult(SystemConstant.convertIdToLong(schoolId), studentCode));
    }

    @ApiOperation(value = "学生报告接口")
    @RequestMapping(value = "/report/mark", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "考生信息", response = TBExamStudentResult.class)})
    @Aac(auth = BOOL.FALSE)
    public Result reportMark(@ApiParam(value = "学校id", required = false) @RequestParam(required = false) String schoolId,
                             @ApiParam(value = "学号", required = true) @RequestParam String studentCode,
                             @ApiParam(value = "考试id", required = true) @RequestParam String examId,
                             @ApiParam(value = "科目编码", required = true) @RequestParam String courseCode) {
        return ResultUtil.ok(tbExamStudentService.reportMark(SystemConstant.convertIdToLong(schoolId), studentCode, examId, courseCode));
    }
}
