|
@@ -1,12 +1,18 @@
|
|
|
package com.minto.app.organization.workpro.controller;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
import java.net.URLDecoder;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
+import java.nio.file.Paths;
|
|
|
import java.text.MessageFormat;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import javax.servlet.ServletContext;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
@@ -53,6 +59,9 @@ public class WorkproController{
|
|
|
@Autowired
|
|
|
private PrincipalService principalService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ServletContext servletContext;
|
|
|
+
|
|
|
@PostMapping("/sync")
|
|
|
public void syncSystem(HttpServletResponse response) throws IOException{
|
|
|
Map<String, Object> res = new HashMap<>();
|
|
@@ -123,4 +132,32 @@ public class WorkproController{
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ @GetMapping("/client/download")
|
|
|
+ @NeedlessCheckLogin
|
|
|
+ public void download(HttpServletResponse response) throws IOException{
|
|
|
+ String filePath = "/WEB-INF/lib/";
|
|
|
+ String fileName = "WorkProClient_Setup_V2.3.09.1800-20240719.exe";
|
|
|
+ String realPath = servletContext.getRealPath(filePath + fileName);
|
|
|
+
|
|
|
+ // 检查文件是否存在
|
|
|
+ Path path = Paths.get(realPath);
|
|
|
+ if(!Files.exists(path)){
|
|
|
+ response.sendError(HttpServletResponse.SC_NOT_FOUND, "File not found");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置响应头
|
|
|
+ response.setContentType("application/octet-stream");
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
|
|
|
+
|
|
|
+ // 流式传输文件
|
|
|
+ try(InputStream in = Files.newInputStream(path); OutputStream out = response.getOutputStream()){
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
+ int bytesRead;
|
|
|
+ while((bytesRead = in.read(buffer)) != -1){
|
|
|
+ out.write(buffer, 0, bytesRead);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|