cy
2022-06-21 129904537f66509f97b285e7eb4f42b3dc349dd0
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
package cn.ksource.web.controller.file;
 
import java.io.File;
import java.io.IOException;
import java.util.Map;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
 
import cn.ksource.core.util.ConvertUtil;
import cn.ksource.core.util.DownloadUtil;
import cn.ksource.web.facade.file.FileFacade;
 
/**
 * 文档管理控制器
 * @author lixiang
 * @date 2016-07-12
 */
@Controller
@RequestMapping("/business/pages/file")
public class FileController {
    @Resource(name="fileFacade")
    private FileFacade fileFacade;
    
    /**
     * 下载文件
     */
    @RequestMapping("downloadFile.html")
    public void downloadFile(HttpServletRequest request,HttpServletResponse response) {
        String fileId = request.getParameter("fileId");
        Map fileMsg = fileFacade.queryFileMsg(fileId);
        if(null!=fileMsg && fileMsg.size()>0) {
            String fileName = ConvertUtil.obj2StrBlank(fileMsg.get("FILE_NAME"));
            String filePath = ConvertUtil.obj2StrBlank(fileMsg.get("FILE_PATH"));
            String basePath = request.getSession().getServletContext().getRealPath("");
            System.out.println("path------------------------>"+basePath+filePath);
            File file = new File(basePath+filePath);
            try {
                DownloadUtil.download(response, file, fileName, false);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    
    /**
     * 下载DSL文件
     */
    @RequestMapping("downloadDslFile.html")
    public void downloadDslFile(HttpServletRequest request,HttpServletResponse response) {
        String fileId = request.getParameter("fileId");
        Map fileMsg = fileFacade.queryDslFileMsg(fileId);
        if(null!=fileMsg && fileMsg.size()>0) {
            String fileName = ConvertUtil.obj2StrBlank(fileMsg.get("FILE_NAME"));
            String filePath = ConvertUtil.obj2StrBlank(fileMsg.get("FILE_PATH"));
            String basePath = request.getSession().getServletContext().getRealPath("");
            System.out.println("path------------------------>"+basePath+filePath);
            File file = new File(basePath+filePath);
            try {
                DownloadUtil.download(response, file, fileName, false);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}