package com.qmth.distributed.print.api.mark;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.teachcloud.common.annotation.OperationLogDetail;
import com.qmth.teachcloud.common.contant.SystemConstant;
import com.qmth.teachcloud.common.enums.log.OperationTypeEnum;
import com.qmth.teachcloud.common.util.Result;
import com.qmth.teachcloud.common.util.ResultUtil;
import com.qmth.teachcloud.mark.dto.mark.score.StudentScoreDetailDto;
import com.qmth.teachcloud.mark.service.MarkStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
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;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

/**
 * <p>
 * 考试考生库 前端控制器
 * </p>
 *
 * @author xf
 * @since 2023-09-22
 */
@Api(tags = "评卷-考生")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_MARK + "/student")
public class MarkStudentController {

    @Resource
    MarkStudentService markStudentService;

    /**
     * 详情列表
     */
    @ApiOperation(value = "详情列表")
    @RequestMapping(value = "/score", method = RequestMethod.POST)
    public Result listStudentScore(@ApiParam(value = "考试ID", required = true) @RequestParam Long examId, @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber,
            @ApiParam(value = "学院") @RequestParam(required = false) String college, @ApiParam(value = "专业") @RequestParam(required = false) String majorName,
            @ApiParam(value = "班级") @RequestParam(required = false) String className, @ApiParam(value = "任课老师") @RequestParam(required = false) String teacher,
            @ApiParam(value = "0：无 1：客观题0分 2：客观题0分，主观题有分 3：主观题0分，客观题有分") @RequestParam(required = false) Integer filter,
            @ApiParam(value = "状态") @RequestParam(required = false) String status, @ApiParam(value = "是否违纪") @RequestParam(required = false) Boolean breach,
            @ApiParam(value = "总分开始") @RequestParam(required = false) Double startScore, @ApiParam(value = "总分结束") @RequestParam(required = false) Double endScore,
            @ApiParam(value = "主观题总分开始") @RequestParam(required = false) Double subjectiveStartScore,
            @ApiParam(value = "主观题总分结束") @RequestParam(required = false) Double subjectiveEndScore,
            @ApiParam(value = "客观题总分开始") @RequestParam(required = false) Double objectiveStartScore,
            @ApiParam(value = "客观题总分结束") @RequestParam(required = false) Double objectiveEndScore, @ApiParam(value = "小题得分") @RequestParam(required = false) Double subScore,
            @ApiParam(value = "客观题分小于x%") @RequestParam(required = false) Integer objectiveScoreRateLt, @ApiParam(value = "姓名") @RequestParam(required = false) String studentName,
            @ApiParam(value = "学号") @RequestParam(required = false) String studentCode, @ApiParam(value = "排序方式") @RequestParam(required = false) String orderType,
            @ApiParam(value = "排序字段") @RequestParam(required = false) String orderField, @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
            @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
        IPage<StudentScoreDetailDto> scoreListDtoIPage = markStudentService.pageStudentScore(examId, paperNumber,
                college, majorName, className, teacher, filter, status, breach, startScore, endScore,
                subjectiveStartScore, subjectiveEndScore, objectiveStartScore, objectiveEndScore, subScore,
                objectiveScoreRateLt, studentName, studentCode, orderType, orderField, pageNumber, pageSize);
        return ResultUtil.ok(scoreListDtoIPage);
    }

    @ApiOperation(value = "客观题统分")
    @RequestMapping(value = "/objective/calculate", method = RequestMethod.POST)
    @OperationLogDetail(operationType = OperationTypeEnum.SAVE, detail = "客观题统分操作，考试ID：{{examId}}、试卷编号：{{paperNumber}}")
    public Result calcObjectiveScore(@ApiParam(value = "考试ID", required = true) @RequestParam Long examId, @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber) {
        return ResultUtil.ok(markStudentService.calcObjectiveScore(examId, paperNumber));
    }
}