package com.qxueyou.scc.exercise.action; import java.io.BufferedOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.List; import javax.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; 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.ResponseBody; import com.qxueyou.scc.base.dao.CommonDAO; import com.qxueyou.scc.base.model.Result; import com.qxueyou.scc.exercise.model.ExerciseDeepAnalysis; import com.qxueyou.scc.exercise.service.IExerciseDeepAnaService; import com.qxueyou.scc.sys.service.IOssService; /** * 练习深度解析控制 * @author ody * */ @Controller @RequestMapping(value = "/exercise/ExerciseDeepAna") public class ExerciseDeepAnaController { @Autowired private CommonDAO commonDAO; @Autowired IOssService ossService; @Autowired IExerciseDeepAnaService exerciseDeepAnaService; /** * 练习深度解析主页 * * @return */ @RequestMapping(method = RequestMethod.GET) public String listPage() { return "/exercise/ExerciseDeepAna"; } /** * 列表加载解析数据 * @param signId * @return */ @RequestMapping(value = "data",method = RequestMethod.GET) public @ResponseBody List queryList() { String hql = "from ExerciseDeepAnalysis e where e.deleteFlag is false order by createTime desc "; return commonDAO.find(hql, ExerciseDeepAnalysis.class); } /** * 下载文档 * * @return * @throws IOException */ @RequestMapping(value = "downloadDoc/{deepAnaId}", method = RequestMethod.GET) public String downloadDoc(@PathVariable String deepAnaId,HttpServletResponse response) throws IOException { ExerciseDeepAnalysis obj = commonDAO.read(ExerciseDeepAnalysis.class, deepAnaId); String docPath = obj.getDocPath(); InputStream is = ossService.getObject(docPath); String fileName = docPath.substring(docPath.lastIndexOf("/") + 1, docPath.length()); response.reset(); response.setContentType("application/msword;charset=utf-8"); response.setHeader("Content-Disposition", "attachment;filename="+ new String(fileName.getBytes(), "iso-8859-1")); OutputStream os = new BufferedOutputStream(response.getOutputStream()); byte[] tempBytes = new byte[1024]; int readTemp = 0; while((readTemp = is.read(tempBytes)) != -1){ os.write(tempBytes, 0, readTemp); } is.close(); os.flush(); os.close(); return null; } /** * 文档处理完毕 修改状态 * @param deepAnalysisIds * @return * @throws IOException */ @RequestMapping(value = "handleSuccess", method = RequestMethod.GET) public @ResponseBody Result handleSuccess(String deepAnalysisIds) throws IOException { return exerciseDeepAnaService.updateExerciseDocStatus(deepAnalysisIds.split(",")); } }