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.enums.log.OperationTypeEnum;
import com.qmth.teachcloud.mark.dto.mark.manage.MarkQualityChartDto;
import com.qmth.teachcloud.mark.dto.mark.manage.MarkQualityDto;
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.mark.service.MarkUserGroupService;
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;
import java.util.List;

/**
 * <p>
 * 评卷质量 前端控制器
 * </p>
 *
 * @author xf
 * @since 2023-09-22
 */
@Api(tags = "评卷-评卷质量")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_MARK + "/quality")
public class MarkQualityController {

    @Resource
    private MarkUserGroupService markUserGroupService;

    /**
     * 评卷质量列表查询
     */
    @ApiOperation(value = "评卷质量列表")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public Result classSummary(@ApiParam(value = "考试ID", required = true) @RequestParam Long examId,
                               @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber,
                               @ApiParam(value = "分组号") @RequestParam(required = false) Integer groupNumber,
                               @ApiParam(value = "评卷员") @RequestParam(required = false) String loginName,
                               @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
                               @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
        IPage<MarkQualityDto> markQualityDtoIPage = markUserGroupService.pageQuality(examId, paperNumber, groupNumber, loginName, pageNumber, pageSize);
        return ResultUtil.ok(markQualityDtoIPage);
    }

    /**
     * 重新计算质量监控
     */
    @ApiOperation(value = "重新计算质量监控")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @OperationLogDetail(operationType = OperationTypeEnum.SAVE, detail = "重新计算质量监控，考试ID：{{examId}}、试卷编号：{{paperNumber}}、分组号：{{groupNumber}}")
    public Result update(@ApiParam(value = "考试ID", required = true) @RequestParam Long examId,
                         @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber,
                         @ApiParam(value = "分组号") @RequestParam(required = false) Integer groupNumber) {
        markUserGroupService.updateQuality(examId, paperNumber, groupNumber);
        return ResultUtil.ok(true);
    }

    /**
     * 评卷质量列表查询
     */
    @ApiOperation(value = "评卷质量列表")
    @RequestMapping(value = "/chart", method = RequestMethod.POST)
    public Result chart(@ApiParam(value = "考试ID", required = true) @RequestParam Long examId,
                               @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber,
                               @ApiParam(value = "分组号") @RequestParam(required = false) Integer groupNumber) {
        List<MarkQualityChartDto> markQualityChartDtoList = markUserGroupService.listQualityChart(examId, paperNumber, groupNumber);
        return ResultUtil.ok(markQualityChartDtoList);
    }
}
