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


import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.teachcloud.common.annotation.OperationLogDetail;
import com.qmth.teachcloud.mark.dto.mark.setting.MarkUserClassDto;
import com.qmth.teachcloud.common.bean.params.mark.setting.MarkClassUserParams;
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.service.MarkUserClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 评卷班级(分班阅) 前端控制器
 * </p>
 *
 * @author xf
 * @since 2023-09-22
 */
@Api(tags = "评卷-分班阅管理")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_MARK + "/class")
public class MarkClassController extends BaseController {

    @Resource
    private MarkUserClassService markUserClassService;

    /**
     * 查询
     */
    @ApiOperation(value = "查询")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public Result list(@ApiParam(value = "考试ID", required = true) @RequestParam Long examId,
                       @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber) {
        MarkUserClassDto markUserClassDto = markUserClassService.listMarkUserClassByExamIdAndPaperNumber(examId, paperNumber);
        return ResultUtil.ok(markUserClassDto);
    }

    /**
     * 查询
     */
    @ApiOperation(value = "提交")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @OperationLogDetail(operationType = OperationTypeEnum.ADD,detail = "分班阅提交操作，考试ID：{{markClassUserParams.examId}}、试卷编号：{{markClassUserParams.paperNumber}}")
    public Result save(@RequestBody MarkClassUserParams markClassUserParams) {
        validMarkPaperForMark(markClassUserParams.getExamId(), markClassUserParams.getPaperNumber());
        return ResultUtil.ok(markUserClassService.saveMarkClassUser(markClassUserParams));
    }
}
