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


import com.qmth.boot.api.annotation.Aac;
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.manage.Task;
import com.qmth.teachcloud.mark.dto.mark.score.SettingDto;
import com.qmth.teachcloud.mark.dto.mark.score.StudentObjectiveDetailDto;
import com.qmth.teachcloud.mark.params.MarkHeaderResult;
import com.qmth.teachcloud.mark.params.MarkResult;
import com.qmth.teachcloud.mark.service.MarkPaperService;
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.*;

import javax.annotation.Resource;

/**
 * <p>
 * 评卷任务检查 前端控制器
 * </p>
 *
 * @author xf
 * @since 2023-09-22
 */
@Api(tags = "评卷-评卷任务检查")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_MARK + "/inspected")
public class MarkInspectedController {

    @Resource
    private MarkStudentService markStudentService;
    @Resource
    private MarkPaperService markPaperService;

    /**
     * 配置获取
     */
    @ApiOperation(value = "配置获取")
    @RequestMapping(value = "/getSetting", method = RequestMethod.POST)
    public Result getSetting(@ApiParam(value = "考试ID", required = true) @RequestParam Long examId,
                             @ApiParam(value = "试卷编号", required = true) @RequestParam String paperNumber) {
        SettingDto settingDto = markPaperService.getSetting(examId, paperNumber);
        return ResultUtil.ok(settingDto);
    }

    /**
     * 客观题检查任务获取
     */
    @ApiOperation(value = "客观题检查任务获取")
    @RequestMapping(value = "/objective/getTask", method = RequestMethod.POST)
    public Result getObjectiveInspectedTask(@ApiParam(value = "考生ID", required = true) @RequestParam Long studentId) {
        StudentObjectiveDetailDto studentObjectiveDetailDto = markStudentService.getObjectiveInspectedTask(studentId);
        return ResultUtil.ok(studentObjectiveDetailDto);
    }

    /**
     * 客观题检查任务保存
     */
    @ApiOperation(value = "客观题检查任务保存")
    @RequestMapping(value = "/objective/saveTask", method = RequestMethod.POST)
    @OperationLogDetail(operationType = OperationTypeEnum.UPDATE, detail = "保存客观题检查任务操作，考生ID：{{studentId}}")
    public Result saveObjectiveInspectedTask(@ApiParam(value = "考生ID", required = true) @RequestParam Long studentId,
                                         @ApiParam(value = "客观题答案", required = true) @RequestParam String answers) {
        return ResultUtil.ok(markStudentService.saveObjectiveInspectedTask(studentId, answers));
    }

    /**
     * 主观题检查任务获取
     */
    @Aac(auth = false)
    @ApiOperation(value = "主观题检查任务获取")
    @RequestMapping(value = "/subjective/getTask", method = RequestMethod.POST)
    public Result getSubjectiveInspectedTask(@ApiParam(value = "考生ID", required = true) @RequestParam Long studentId) {
        Task task = markStudentService.getSubjectiveInspectedTask(studentId);
        return ResultUtil.ok(task);
    }

    /**
     * 主观题检查任务保存
     */
    @ApiOperation(value = "主观题检查任务保存")
    @RequestMapping(value = "/subjective/saveTask", method = RequestMethod.POST)
    @OperationLogDetail(operationType = OperationTypeEnum.UPDATE, detail = "保存主观题检查任务操作，考生ID：{{markResult.studentId}}")
    public Result saveSubjectiveInspectedTask(@RequestBody MarkHeaderResult markResult) {
        markStudentService.saveSubjectiveInspectedTask(markResult);
        return ResultUtil.ok(true);
    }
}
