package cn.com.qmth.examcloud.core.questions.api.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.com.qmth.examcloud.core.questions.dao.entity.ExtractConfig;
import cn.com.qmth.examcloud.core.questions.service.ExtractConfigService;
import cn.com.qmth.examcloud.support.cache.CacheHelper;
import cn.com.qmth.examcloud.support.cache.bean.BasePaperCacheBean;
import cn.com.qmth.examcloud.support.cache.bean.ExtractConfigCacheBean;
import cn.com.qmth.examcloud.support.cache.bean.ExtractConfigPaperCacheBean;
import cn.com.qmth.examcloud.support.cache.bean.QuestionAnswerCacheBean;
import cn.com.qmth.examcloud.support.cache.bean.QuestionCacheBean;
import cn.com.qmth.examcloud.web.support.ControllerSupport;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("${api_cqb}/cache-load")
public class CacheLoadController extends ControllerSupport {

	@Autowired
	private ExtractConfigService extractConfigService;

	@ApiOperation(value = "获取调卷规则")
	@PostMapping("/extract-config-list")
	public List<ExtractConfig> getExtractConfigList(@RequestParam Long examId) {
		return extractConfigService.findExtractConfig(examId);
	}

	@ApiOperation(value = "加载调卷规则缓存")
	@PostMapping("/extract-config-cache")
	public ExtractConfigCacheBean loadExtractConfig(@RequestParam Long examId, @RequestParam String courseCode) {
		return CacheHelper.getExtractConfig(examId, courseCode);
	}

	@ApiOperation(value = "加载调卷规则试卷结构缓存")
	@PostMapping("/extract-config-paper-cache")
	public ExtractConfigPaperCacheBean loadExtractConfigPaper(@RequestParam Long examId,
			@RequestParam String courseCode, @RequestParam String groupCode, @RequestParam String paperId) {
		return CacheHelper.getExtractConfigPaper(examId, courseCode, groupCode, paperId);
	}

	@ApiOperation(value = "加载试卷结构缓存")
	@PostMapping("/base-paper-cache")
	public BasePaperCacheBean loadBasePaper(@RequestParam String paperId) {
		return CacheHelper.getBasePaper(paperId);
	}

	@ApiOperation(value = "加载小题缓存")
	@PostMapping("/question-cache")
	public QuestionCacheBean loadQuestion(@RequestParam Long examId, @RequestParam String courseCode,
			@RequestParam String groupCode, @RequestParam String questionId) {
		return CacheHelper.getQuestion(examId, courseCode, groupCode, questionId);
	}

	@ApiOperation(value = "加载答案缓存")
	@PostMapping("/question-answer-cache")
	public QuestionAnswerCacheBean loadExtractConfig(@RequestParam String questionId) {
		return CacheHelper.getQuestionAnswer(questionId);
	}

}