package com.qmth.qrzk.web.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
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 com.qmth.qrzk.dao.repositories.PaperRepo;
import com.qmth.qrzk.paper.model.Paper;
import com.qmth.qrzk.repository.utils.FileTool;

@RestController
@RequestMapping("papers")
public class PaperController {

	@Autowired private PaperRepo paperRepo;
	
	/**
	 * 下载电子文档
	 * @param response
	 * @param id 试卷id
	 * @param fileType 类型：0合卷，1分卷，2标答
	 * @throws IOException
	 */
	@RequestMapping(value="{id}/files",method=RequestMethod.GET)
	public void download(HttpServletResponse response,@PathVariable long id,@RequestParam int fileType)
		throws IOException{
		Paper paper = paperRepo.findOne(id);
		String fileName = null;
		switch(fileType){
			case 0:
				fileName = paper.getPaperPath();
				break;
			case 1:
//				fileName = paper.getSeparatePaperPath();
				fileName = paper.getWpPaperPath();//国考供卷部分，张璇要求把“分卷”改成“网评卷”
				break;
			case 2:
				fileName = paper.getStandardAnswerPath();
				break;
		}
		FileTool.downLoad(response, fileName);
	}
}
