派生自 projectDept/qhighschool

EricsHu
2022-12-05 068fc7f2e81178e55fa191a13709af64b1a163f6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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<ExerciseDeepAnalysis> 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(","));
 
        
    }
    
    
    
    
}