package com.qmth.distributed.print.api;

import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.distributed.print.business.bean.result.PrintPlanBrief;
import com.qmth.distributed.print.business.service.ConditionService;
import com.qmth.teachcloud.common.contant.SystemConstant;
import com.qmth.teachcloud.common.entity.*;
import com.qmth.teachcloud.common.enums.ExamCategoryEnum;
import com.qmth.teachcloud.common.util.Result;
import com.qmth.teachcloud.common.util.ResultUtil;
import com.qmth.teachcloud.mark.service.ScanConditionService;
import io.swagger.annotations.*;
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 java.util.List;
import java.util.Map;

/**
 * 查询条件
 */
@Api(tags = "查询条件Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_BASIC + "/condition")
public class ConditionController {

    @Resource
    private ConditionService conditionService;

    @Resource
    private ScanConditionService scanConditionService;

    @ApiOperation(value = "学期")
    @RequestMapping(value = "/list_semester", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "查询成功", response = BasicSemester.class) })
    public Result listSemester(@ApiParam(value = "启用/禁用") @RequestParam(required = false, defaultValue = "true") Boolean enable) {
        return ResultUtil.ok(conditionService.listSemester(enable));
    }

    @ApiOperation(value = "考试")
    @RequestMapping(value = "/list_exam", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "查询成功", response = BasicExam.class) })
    public Result listExam(@ApiParam(value = "学期ID") @RequestParam(required = false) Long semesterId, @ApiParam(value = "考试类型") @RequestParam(required = false) ExamCategoryEnum category,
            @ApiParam(value = "启用/禁用") @RequestParam(required = false, defaultValue = "true") Boolean enable) {
        return ResultUtil.ok(conditionService.listExam(semesterId, category, enable));
    }

    @ApiOperation(value = "课程")
    @RequestMapping(value = "/list_course", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "查询成功", response = BasicCourse.class) })
    public Result listCourse(@ApiParam(value = "学期ID") @RequestParam(required = false) Long semesterId, @ApiParam(value = "考试ID") @RequestParam(required = false) Long examId,
            @ApiParam(value = "启用/禁用") @RequestParam(required = false) Boolean enable, @RequestParam(value = "printPlanId", required = false) List<String> printPlanId) {
        return ResultUtil.ok(conditionService.listCourse(semesterId, examId, enable, printPlanId));
    }

    @ApiOperation(value = "试卷编号")
    @RequestMapping(value = "/list_paper_number", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "查询成功", response = String.class) })
    public Result listPaperNumber(@ApiParam(value = "学期ID") @RequestParam(required = false) Long semesterId, @ApiParam(value = "考试ID") @RequestParam(required = false) Long examId,
            @ApiParam(value = "课程代码") @RequestParam(required = false) String courseCode, @RequestParam(value = "printPlanId", required = false) List<String> printPlanId) {
        return ResultUtil.ok(conditionService.listPaperNumber(semesterId, examId, courseCode, printPlanId));
    }

    @ApiOperation(value = "印刷计划")
    @RequestMapping(value = "/list_print_plan", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "查询成功", response = PrintPlanBrief.class) })
    public Result listPrintPlan(@ApiParam(value = "学期ID") @RequestParam(required = false) Long semesterId, @ApiParam(value = "考试ID") @RequestParam(required = false) Long examId,
            @ApiParam(value = "source") @RequestParam(required = false) String source) {
        return ResultUtil.ok(conditionService.listPrintPlan(semesterId, examId, source));
    }

    @ApiOperation(value = "班级")
    @RequestMapping(value = "/list_clazz", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "查询成功", response = BasicClazz.class) })
    public Result listClazz(@ApiParam(value = "学期ID") @RequestParam(required = false) Long semesterId, @ApiParam(value = "考试ID") @RequestParam(required = false) Long examId,
            @ApiParam(value = "课程代码") @RequestParam(required = false) String courseCode, @ApiParam(value = "班级名称") @RequestParam(required = false) String clazzName) {
        return ResultUtil.ok(conditionService.listClazz(semesterId, examId, courseCode, clazzName));
    }

    @ApiOperation(value = "学院")
    @RequestMapping(value = "/list_college", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "查询成功", response = SysOrg.class) })
    public Result listCollege() {
        return ResultUtil.ok(conditionService.listCollege());
    }

    @ApiOperation(value = "扫描-获取学期、考试列表")
    @RequestMapping(value = "/scan/semester/list", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "查询成功", response = Map.class) })
    public Result scanSemesterList(@ApiParam(value = "启用/禁用") @RequestParam(required = false, defaultValue = "true") Boolean enable) {
        return ResultUtil.ok(scanConditionService.scanSemesterList(enable));
    }

    @ApiOperation(value = "扫描-获取课程、试卷编号列表")
    @RequestMapping(value = "/scan/course/list", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "查询成功", response = Map.class) })
    public Result scanCourseList(@ApiParam(value = "考试ID", required = true) @RequestParam(value = "examId") Long examId) {
        return ResultUtil.ok(scanConditionService.scanCourseList(examId));
    }

    @ApiOperation(value = "扫描-获取校区、考场")
    @RequestMapping(value = "/scan/campus/list", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "查询成功", response = Map.class) })
    public Result scanCampusList(@ApiParam(value = "考试ID", required = true) @RequestParam(value = "examId") Long examId,
            @ApiParam(value = "课程代码") @RequestParam(value = "courseCode", required = false) String courseCode, @ApiParam(value = "试卷编号") @RequestParam(value = "coursePaperId", required = false) String coursePaperId) {
        return ResultUtil.ok(scanConditionService.scanCampusList(examId, courseCode, coursePaperId));
    }

    @ApiOperation(value = "教学班字典")
    @RequestMapping(value = "/list_basic_teach_clazz", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "查询成功", response = Map.class) })
    public Result listBasicTeachClazz(@ApiParam(value = "考试ID", required = true) @RequestParam(value = "examId") String examId,
            @ApiParam(value = "课程编号") @RequestParam(value = "courseCode", required = false) String courseCode,
            @ApiParam(value = "名称") @RequestParam(value = "clazzName", required = false) String clazzName) {
        return ResultUtil.ok(
                conditionService.listBasicTeachClazz(SystemConstant.convertIdToLong(examId), courseCode, clazzName));
    }
}
