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.enums.mark.MarkPaperStatus;
import com.qmth.teachcloud.mark.dto.mark.score.MarkPaperPackageDto;
import com.qmth.teachcloud.mark.service.MarkPaperService;
import com.qmth.teachcloud.common.util.Result;
import com.qmth.teachcloud.common.util.ResultUtil;
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 + "/paper")
public class MarkPaperController {

    @Resource
    private MarkPaperService markPaperService;

    /**
     * 结束阅卷
     */
    @ApiOperation(value = "结束/开始阅卷")
    @RequestMapping(value = "/finish", method = RequestMethod.POST)
    @OperationLogDetail(operationType = OperationTypeEnum.SAVE, detail = "结束/开始阅卷操作，考试ID：{{examId}}、试卷编号：{{paperNumbers}}、状态：{{status}}")
    public Result finish(@ApiParam(value = "考试ID", required = true) @RequestParam Long examId,
                         @ApiParam(value = "试卷编号", required = true) @RequestParam List<String> paperNumbers,
                         @ApiParam(value = "状态", required = true) @RequestParam MarkPaperStatus status) {
        return ResultUtil.ok(markPaperService.finishPaper(examId, paperNumbers, status));
    }

    /**
     * 签到表列表
     */
    @ApiOperation(value = "签到表列表")
    @RequestMapping(value = "/package/list", method = RequestMethod.POST)
    public Result finish(@ApiParam(value = "考试ID", required = true) @RequestParam Long examId,
                         @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber,
                         @ApiParam(value = "卷袋编号") @RequestParam(required = false) String packageCode,
                         @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
                         @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
        IPage<MarkPaperPackageDto> markPaperPackageDtoIPage = markPaperService.listPackage(examId, paperNumber, packageCode, pageNumber, pageSize);
        return ResultUtil.ok(markPaperPackageDtoIPage);
    }
}
