package com.qmth.distributed.print.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.distributed.print.business.entity.TSyncExamLog;
import com.qmth.distributed.print.business.service.TSyncExamLogService;
import com.qmth.teachcloud.common.annotation.OperationLogDetail;
import com.qmth.teachcloud.common.contant.SystemConstant;
import com.qmth.teachcloud.common.enums.log.CustomizedOperationTypeEnum;
import com.qmth.teachcloud.common.util.Result;
import com.qmth.teachcloud.common.util.ResultUtil;
import io.swagger.annotations.*;
import org.springframework.validation.annotation.Validated;
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>
 */
@Api(tags = "成绩归档Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_SYNC)
@Validated
public class TSyncExamLogController {

    @Resource
    TSyncExamLogService tSyncExamLogService;

    @ApiOperation(value = "成绩归档查询汇总列表")
    @ApiResponses({@ApiResponse(code = 200, message = "成绩查询汇总信息", response = TSyncExamLog.class)})
    @RequestMapping(value = "/log/list", method = RequestMethod.POST)
    public Result list(@ApiParam(value = "学期ID", required = false) @RequestParam(required = false) String semesterId,
                       @ApiParam(value = "考试ID", required = false) @RequestParam(required = false) String examId,
                       @ApiParam(value = "页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
                       @ApiParam(value = "数量", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {
        return ResultUtil.ok(tSyncExamLogService.list(new Page<>(pageNumber, pageSize), SystemConstant.convertIdToLong(semesterId), SystemConstant.convertIdToLong(examId)));
    }


    @ApiOperation(value = "同步")
    @ApiResponses({@ApiResponse(code = 200, message = "同步异步任务信息", response = TSyncExamLog.class)})
    @RequestMapping(value = "/log/sync", method = RequestMethod.POST)
    public Result sync(@ApiParam(value = "学期ID", required = true) @RequestParam Long semesterId,
                       @ApiParam(value = "考试ID", required = true) @RequestParam Long examId,
                       @ApiParam(value = "云阅卷考试ID", required = true) @RequestParam Long thirdRelateId) {
        tSyncExamLogService.syncStudentScore(semesterId, examId, thirdRelateId);
        return ResultUtil.ok();
    }
}
