matianxiang 1 mese fa
parent
commit
3499aebe56

+ 77 - 0
eitc-admin/src/main/java/com/eitc/web/controller/common/DownloadController.java

@@ -0,0 +1,77 @@
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
+    private static final Logger log = LoggerFactory.getLogger(DownloadController.class);
28
+
29
+    /**
30
+     * 硬件app
31
+     */
32
+    @GetMapping("/hardware")
33
+    public void hardware(HttpServletRequest request, HttpServletResponse response) {
34
+        try {
35
+            String resource = "/profile/app/huishitong.apk";
36
+            resourceDownload(resource, request, response);
37
+        } catch (Exception e) {
38
+            log.error("下载文件失败", e);
39
+        }
40
+    }
41
+
42
+    @GetMapping("/hospital")
43
+    public void hospital(HttpServletRequest request, HttpServletResponse response) {
44
+        try {
45
+            String resource = "/profile/app/kouqiangyiyuan_1.0.0_1_240830_release.apk";
46
+            resourceDownload(resource, request, response);
47
+        } catch (Exception e) {
48
+            log.error("下载文件失败", e);
49
+        }
50
+    }
51
+
52
+    @GetMapping("/document")
53
+    public void document(HttpServletRequest request, HttpServletResponse response) {
54
+        try {
55
+            String resource = "/profile/app/document.pdf";
56
+            resourceDownload(resource, request, response);
57
+        } catch (Exception e) {
58
+            log.error("下载文件失败", e);
59
+        }
60
+    }
61
+
62
+    public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response) throws Exception {
63
+            if (!FileUtils.checkAllowDownload(resource)) {
64
+                throw new Exception(StringUtils.format("资源文件({})非法,不允许下载。 ", resource));
65
+            }
66
+            // 本地资源路径
67
+            String localPath = EitcConfig.getProfile();
68
+            // 数据库资源地址
69
+            String downloadPath = localPath + StringUtils.substringAfter(resource, Constants.RESOURCE_PREFIX);
70
+            // 下载名称
71
+            String downloadName = StringUtils.substringAfterLast(downloadPath, "/");
72
+            response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
73
+            FileUtils.setAttachmentResponseHeader(response, downloadName);
74
+            FileUtils.writeBytes(downloadPath, response.getOutputStream());
75
+    }
76
+
77
+}

+ 1 - 0
eitc-framework/src/main/java/com/eitc/framework/config/SecurityConfig.java

@@ -112,6 +112,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
112 112
                 .authorizeRequests()
113 113
                 // 对于登录login 注册register 验证码captchaImage 允许匿名访问
114 114
                 .antMatchers("/login", "/register", "/captchaImage","/sys/clinict/downloadLocal/**").permitAll()
115
+                .antMatchers("/download/**").permitAll()
115 116
                 // 静态资源,可匿名访问
116 117
                 .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
117 118
                 .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()