package com.qmth.teachcloud.report.api;

import com.alibaba.fastjson.JSON;
import com.qmth.boot.api.annotation.Aac;
import com.qmth.boot.api.annotation.BOOL;
import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.teachcloud.common.util.Result;
import com.qmth.teachcloud.common.util.ResultUtil;
import com.qmth.teachcloud.report.business.bean.dto.printOpen.*;
import com.qmth.teachcloud.report.business.bean.params.CalculateParams;
import com.qmth.teachcloud.report.business.service.AnalyzeDataCalculateService;
import com.qmth.teachcloud.report.business.service.AnalyzeDataCheckService;
import com.qmth.teachcloud.report.business.service.AnalyzeDataGetAndEditService;
import com.qmth.teachcloud.report.business.service.CallPrintOpenApiService;
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 java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * @Description: 需要删除的controllor
 * @Author: CaoZixuan
 * @Date:
 */
@Api(tags = "测试请求分布式印刷开放接口Controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/test/call")
@Validated
@Deprecated
public class TestCallPrintOpenApiController {
    @Resource
    CallPrintOpenApiService callPrintOpenApiService;
    @Resource
    AnalyzeDataCalculateService analyzeDataCalculateService;
    @Resource
    AnalyzeDataCheckService analyzeDataCheckService;
    @Resource
    AnalyzeDataGetAndEditService analyzeDataGetAndEditService;

    @ApiOperation(value = "试卷配置")
    @ApiResponses({@ApiResponse(code = 200, message = "试卷配置", response = Object.class)})
    @RequestMapping(value = "/paper_config", method = RequestMethod.POST)
    @Aac(auth = BOOL.FALSE)
    public Result paperConfig(@ApiParam(value = "考试id", required = true) @RequestParam Long thirdExamId,
                              @ApiParam(value = "科目编号", required = true) @RequestParam String courseCode) throws IOException {
        PaperConfig paperConfig = callPrintOpenApiService.callPaperConfig(2L,thirdExamId, courseCode);
        System.out.println(JSON.toJSONString(paperConfig));
        return ResultUtil.ok();
    }

    @ApiOperation(value = "维度配置")
    @ApiResponses({@ApiResponse(code = 200, message = "试卷配置", response = Object.class)})
    @RequestMapping(value = "/paper_dimension", method = RequestMethod.POST)
    @Aac(auth = BOOL.FALSE)
    public Result paperDimension(@ApiParam(value = "考试id", required = true) @RequestParam Long thirdExamId,
                                 @ApiParam(value = "科目编号", required = true) @RequestParam String courseCode) throws IOException {
        List<PaperDimension> paperDimensionList = callPrintOpenApiService.callPaperDimension(2L,thirdExamId, courseCode);
        System.out.println(JSON.toJSONString(paperDimensionList));
        return ResultUtil.ok();
    }

    @ApiOperation(value = "蓝图配置")
    @ApiResponses({@ApiResponse(code = 200, message = "试卷配置", response = Object.class)})
    @RequestMapping(value = "/paper_struct", method = RequestMethod.POST)
    @Aac(auth = BOOL.FALSE)
    public Result paperStruct(@ApiParam(value = "考试id", required = true) @RequestParam Long thirdExamId,
                              @ApiParam(value = "科目编号", required = true) @RequestParam String courseCode) throws IOException {
        List<PaperStructure> paperStructureList = callPrintOpenApiService.callPaperStruct(2L,thirdExamId, courseCode);
        System.out.println(JSON.toJSONString(paperStructureList));
        return ResultUtil.ok();
    }

    @ApiOperation(value = "模块配置")
    @ApiResponses({@ApiResponse(code = 200, message = "试卷配置", response = Object.class)})
    @RequestMapping(value = "/paper_module", method = RequestMethod.POST)
    @Aac(auth = BOOL.FALSE)
    public Result paperModule(@ApiParam(value = "考试id", required = true) @RequestParam Long thirdExamId,
                              @ApiParam(value = "科目编号", required = true) @RequestParam String courseCode) throws IOException {
        List<PaperEvaluation> paperEvaluationList = callPrintOpenApiService.callPaperModule(2L,thirdExamId, courseCode);
        System.out.println(JSON.toJSONString(paperEvaluationList));
        return ResultUtil.ok();
    }

    @ApiOperation(value = "考生成绩")
    @ApiResponses({@ApiResponse(code = 200, message = "考生成绩", response = Object.class)})
    @RequestMapping(value = "/exam_student_score", method = RequestMethod.POST)
    @Aac(auth = BOOL.FALSE)
    public Result examStudentScore(@ApiParam(value = "考试id", required = true) @RequestParam Long thirdExamId,
                                   @ApiParam(value = "科目编号", required = true) @RequestParam String courseCode) throws IOException {
        List<ExamStudentScore> examStudentScoreList = callPrintOpenApiService.callExamStudentScore(2L,thirdExamId, courseCode);
        System.out.println(JSON.toJSONString(examStudentScoreList));
        return ResultUtil.ok();
    }

    @ApiOperation(value = "获取和新增数据")
    @ApiResponses({@ApiResponse(code = 200, message = "获取和新增数据", response = Object.class)})
    @RequestMapping(value = "/insert_analyze_data", method = RequestMethod.POST)
    @Aac(auth = BOOL.FALSE)
    public Result insertAnalyzeData(@ApiParam(value = "考试id", required = true) @RequestParam Long examId,
                                    @ApiParam(value = "科目编号", required = true) @RequestParam String courseCode,
                                    @ApiParam(value = "学校id", required = true) @RequestParam Long schoolId) throws IOException {
        analyzeDataGetAndEditService.dataGetAndEdit(examId, courseCode, schoolId);
        return ResultUtil.ok();
    }

    @ApiOperation(value = "数据检验和分析触发器")
    @ApiResponses({@ApiResponse(code = 200, message = "数据检验和分析触发器", response = Object.class)})
    @RequestMapping(value = "/check_and_trigger", method = RequestMethod.POST)
    @Aac(auth = BOOL.FALSE)
    public Result checkAndTrigger(@ApiParam(value = "考试id", required = true) @RequestParam Long examId,
                                  @ApiParam(value = "科目编号", required = true) @RequestParam List<String> courseCode,
                                  @ApiParam(value = "学校id", required = true) @RequestParam Long schoolId) throws IOException {
        CalculateParams calculateParams = new CalculateParams();
        calculateParams.setSchoolId(schoolId);
        calculateParams.setCourseCode(courseCode);
        calculateParams.setExamId(examId);
        analyzeDataCheckService.analyzeDataCheck(calculateParams);
        return ResultUtil.ok();
    }

    @ApiOperation(value = "数据计算")
    @ApiResponses({@ApiResponse(code = 200, message = "数据计算", response = Object.class)})
    @RequestMapping(value = "/calculate", method = RequestMethod.POST)
    @Aac(auth = BOOL.FALSE)
    public Result calculate(@ApiParam(value = "考试id", required = true) @RequestParam Long examId,
                            @ApiParam(value = "科目编号", required = true) @RequestParam List<String> courseCode,
                            @ApiParam(value = "学校id", required = true) @RequestParam Long schoolId) throws IOException, InvocationTargetException, InstantiationException, IllegalAccessException, NoSuchMethodException {
        CalculateParams calculateParams = new CalculateParams();
        calculateParams.setSchoolId(schoolId);
        calculateParams.setCourseCode(courseCode);
        calculateParams.setExamId(examId);
        analyzeDataCalculateService.dataCalculateStart(calculateParams);
        return ResultUtil.ok();
    }
}
