package com.qmth.distributed.print.api;

import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.distributed.print.business.bean.params.SyncDataParam;
import com.qmth.distributed.print.business.bean.result.EditResult;
import com.qmth.distributed.print.business.enums.ExamTaskSyncStatusEnum;
import com.qmth.distributed.print.business.enums.SyncCardTypeEnum;
import com.qmth.distributed.print.business.service.ExamPrintPlanService;
import com.qmth.teachcloud.common.annotation.OperationLogDetail;
import com.qmth.teachcloud.common.contant.SystemConstant;
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
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.*;

import javax.annotation.Resource;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

/**
 * <p>
 * 印刷计划推送管理 前端控制器
 * </p>
 *
 * @author xf
 * @since 2021-03-23
 */
@Api(tags = "印刷计划推送管理Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_EXAM + "/print_sync")
@Validated
public class ExamPrintPlanSyncController {
    @Resource
    private ExamPrintPlanService examPrintPlanService;

    /**
     * 查询需要同步的命题任务
     */
    @ApiOperation(value = "印刷计划推送管理-推送数据查询")
    @RequestMapping(value = "/list_sync", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "查询成功", response = Result.class)})
    public Result listSyncExamTask(@ApiParam(value = "学期ID") @RequestParam(required = false) Long semesterId,
                                   @ApiParam(value = "考试ID") @RequestParam(required = false) Long examId,
                                   @ApiParam(value = "学院ID") @RequestParam(required = false) Long orgId,
                                   @ApiParam(value = "题卡类型") @RequestParam(required = false) SyncCardTypeEnum cardType,
                                   @ApiParam(value = "推送状态") @RequestParam(required = false) ExamTaskSyncStatusEnum syncStatus,
                                   @ApiParam(value = "课程代码") @RequestParam(required = false) String courseCode,
                                   @ApiParam(value = "试卷编号") @RequestParam(required = false) String paperNumber,
                                   @ApiParam(value = "计划创建时间段开始时间") @RequestParam(required = false) Long startTime,
                                   @ApiParam(value = "计划创建时间段结束时间") @RequestParam(required = false) Long endTime,
                                   @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) {
        if (semesterId == null) {
            throw ExceptionResultEnum.ERROR.exception("请选择学期");
        }
        return ResultUtil.ok(examPrintPlanService.listSyncExamTask(semesterId, examId, orgId, cardType, syncStatus, courseCode, paperNumber, startTime, endTime, pageNumber, pageSize));
    }

    /**
     * 推送、批量推送-检验同步规则，并返回学院代码
     *
     * @param syncDataParam
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "印刷计划推送管理-检验同步规则，并返回学院代码")
    @RequestMapping(value = "/check_sync_mode", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = EditResult.class)})
    @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.PUSH)
    public Result checkSyncMode(@RequestBody SyncDataParam syncDataParam) {
        examPrintPlanService.checkSyncMode(syncDataParam);
        return ResultUtil.ok(true, "");
    }

    /**
     * 多计划合并同步
     *
     * @param syncDataParam
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "印刷计划推送管理-开始推送")
    @RequestMapping(value = "/sync_data_cloud", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = EditResult.class)})
    @OperationLogDetail(customizedOperationType = CustomizedOperationTypeEnum.PUSH)
    public Result syncDataCloud(@RequestBody SyncDataParam syncDataParam) {
        examPrintPlanService.syncDataCloud(syncDataParam);
        return ResultUtil.ok(true);
    }

}

