|
@@ -0,0 +1,65 @@
|
|
1
|
+package com.eitc.web.controller.common;
|
|
2
|
+
|
|
3
|
+import com.eitc.common.config.EitcConfig;
|
|
4
|
+import com.eitc.common.constant.Constants;
|
|
5
|
+import com.eitc.common.core.controller.BaseController;
|
|
6
|
+import com.eitc.common.utils.StringUtils;
|
|
7
|
+import com.eitc.common.utils.file.FileUtils;
|
|
8
|
+import org.slf4j.Logger;
|
|
9
|
+import org.slf4j.LoggerFactory;
|
|
10
|
+import org.springframework.http.MediaType;
|
|
11
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
12
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
13
|
+import org.springframework.web.bind.annotation.RestController;
|
|
14
|
+
|
|
15
|
+import javax.servlet.http.HttpServletRequest;
|
|
16
|
+import javax.servlet.http.HttpServletResponse;
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+/**
|
|
20
|
+ * 通用请求处理
|
|
21
|
+ *
|
|
22
|
+ * @author eitc
|
|
23
|
+ */
|
|
24
|
+@RestController
|
|
25
|
+@RequestMapping("/download")
|
|
26
|
+public class DownloadController extends BaseController {
|
|
27
|
+
|
|
28
|
+ /**
|
|
29
|
+ * 硬件app
|
|
30
|
+ */
|
|
31
|
+ @GetMapping("/hardware")
|
|
32
|
+ public void hardware(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
33
|
+ String resource = "/profile/app/huishitong.apk";
|
|
34
|
+ resourceDownload(resource, response);
|
|
35
|
+ }
|
|
36
|
+
|
|
37
|
+ @GetMapping("/hospital")
|
|
38
|
+ public void hospital(HttpServletResponse response) throws Exception {
|
|
39
|
+ String resource = "/profile/app/kouqiangyiyuan_1.0.0_1_240830_release.apk";
|
|
40
|
+ resourceDownload(resource, response);
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+ @GetMapping("/document")
|
|
44
|
+ public void document(HttpServletResponse response) throws Exception {
|
|
45
|
+ String resource = "/profile/app/document.pdf";
|
|
46
|
+ resourceDownload(resource, response);
|
|
47
|
+ }
|
|
48
|
+
|
|
49
|
+ public void resourceDownload(String resource, HttpServletResponse response) throws Exception {
|
|
50
|
+ // 禁止目录上跳级别
|
|
51
|
+ if (StringUtils.contains(resource, "..")) {
|
|
52
|
+ throw new Exception(StringUtils.format("资源文件({})非法,不允许下载。 ", resource));
|
|
53
|
+ }
|
|
54
|
+ // 本地资源路径
|
|
55
|
+ String localPath = EitcConfig.getProfile();
|
|
56
|
+ // 数据库资源地址
|
|
57
|
+ String downloadPath = localPath + StringUtils.substringAfter(resource, Constants.RESOURCE_PREFIX);
|
|
58
|
+ // 下载名称
|
|
59
|
+ String downloadName = StringUtils.substringAfterLast(downloadPath, "/");
|
|
60
|
+ response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
61
|
+ FileUtils.setAttachmentResponseHeader(response, downloadName);
|
|
62
|
+ FileUtils.writeBytes(downloadPath, response.getOutputStream());
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+}
|