|
@@ -1,9 +1,16 @@
|
|
package com.ozs.web.controller.common;
|
|
package com.ozs.web.controller.common;
|
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
+
|
|
|
|
+import com.ozs.common.core.domain.R;
|
|
|
|
+import com.ozs.common.utils.uuid.UUID;
|
|
|
|
+import io.swagger.annotations.Api;
|
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -26,10 +33,10 @@ import com.ozs.framework.config.ServerConfig;
|
|
*
|
|
*
|
|
* @author ruoyi
|
|
* @author ruoyi
|
|
*/
|
|
*/
|
|
|
|
+@Api(tags = "统用功能")
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("/common")
|
|
@RequestMapping("/common")
|
|
-public class CommonController
|
|
|
|
-{
|
|
|
|
|
|
+public class CommonController {
|
|
private static final Logger log = LoggerFactory.getLogger(CommonController.class);
|
|
private static final Logger log = LoggerFactory.getLogger(CommonController.class);
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -41,15 +48,12 @@ public class CommonController
|
|
* 通用下载请求
|
|
* 通用下载请求
|
|
*
|
|
*
|
|
* @param fileName 文件名称
|
|
* @param fileName 文件名称
|
|
- * @param delete 是否删除
|
|
|
|
|
|
+ * @param delete 是否删除
|
|
*/
|
|
*/
|
|
@GetMapping("/download")
|
|
@GetMapping("/download")
|
|
- public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
|
|
|
|
- {
|
|
|
|
- try
|
|
|
|
- {
|
|
|
|
- if (!FileUtils.checkAllowDownload(fileName))
|
|
|
|
- {
|
|
|
|
|
|
+ public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) {
|
|
|
|
+ try {
|
|
|
|
+ if (!FileUtils.checkAllowDownload(fileName)) {
|
|
throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
|
|
throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
|
|
}
|
|
}
|
|
String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
|
|
String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
|
|
@@ -58,13 +62,10 @@ public class CommonController
|
|
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
FileUtils.setAttachmentResponseHeader(response, realFileName);
|
|
FileUtils.setAttachmentResponseHeader(response, realFileName);
|
|
FileUtils.writeBytes(filePath, response.getOutputStream());
|
|
FileUtils.writeBytes(filePath, response.getOutputStream());
|
|
- if (delete)
|
|
|
|
- {
|
|
|
|
|
|
+ if (delete) {
|
|
FileUtils.deleteFile(filePath);
|
|
FileUtils.deleteFile(filePath);
|
|
}
|
|
}
|
|
- }
|
|
|
|
- catch (Exception e)
|
|
|
|
- {
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
log.error("下载文件失败", e);
|
|
log.error("下载文件失败", e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -73,10 +74,8 @@ public class CommonController
|
|
* 通用上传请求(单个)
|
|
* 通用上传请求(单个)
|
|
*/
|
|
*/
|
|
@PostMapping("/upload")
|
|
@PostMapping("/upload")
|
|
- public AjaxResult uploadFile(MultipartFile file) throws Exception
|
|
|
|
- {
|
|
|
|
- try
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult uploadFile(MultipartFile file) throws Exception {
|
|
|
|
+ try {
|
|
// 上传文件路径
|
|
// 上传文件路径
|
|
String filePath = PurchaseConfig.getUploadPath();
|
|
String filePath = PurchaseConfig.getUploadPath();
|
|
// 上传并返回新文件名称
|
|
// 上传并返回新文件名称
|
|
@@ -88,29 +87,26 @@ public class CommonController
|
|
ajax.put("newFileName", FileUtils.getName(fileName));
|
|
ajax.put("newFileName", FileUtils.getName(fileName));
|
|
ajax.put("originalFilename", file.getOriginalFilename());
|
|
ajax.put("originalFilename", file.getOriginalFilename());
|
|
return ajax;
|
|
return ajax;
|
|
- }
|
|
|
|
- catch (Exception e)
|
|
|
|
- {
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
return AjaxResult.error(e.getMessage());
|
|
return AjaxResult.error(e.getMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 通用上传请求(多个)
|
|
* 通用上传请求(多个)
|
|
*/
|
|
*/
|
|
@PostMapping("/uploads")
|
|
@PostMapping("/uploads")
|
|
- public AjaxResult uploadFiles(List<MultipartFile> files) throws Exception
|
|
|
|
- {
|
|
|
|
- try
|
|
|
|
- {
|
|
|
|
|
|
+ public AjaxResult uploadFiles(List<MultipartFile> files) throws Exception {
|
|
|
|
+ try {
|
|
// 上传文件路径
|
|
// 上传文件路径
|
|
String filePath = PurchaseConfig.getUploadPath();
|
|
String filePath = PurchaseConfig.getUploadPath();
|
|
List<String> urls = new ArrayList<String>();
|
|
List<String> urls = new ArrayList<String>();
|
|
List<String> fileNames = new ArrayList<String>();
|
|
List<String> fileNames = new ArrayList<String>();
|
|
List<String> newFileNames = new ArrayList<String>();
|
|
List<String> newFileNames = new ArrayList<String>();
|
|
List<String> originalFilenames = new ArrayList<String>();
|
|
List<String> originalFilenames = new ArrayList<String>();
|
|
- for (MultipartFile file : files)
|
|
|
|
- {
|
|
|
|
|
|
+ for (MultipartFile file : files) {
|
|
// 上传并返回新文件名称
|
|
// 上传并返回新文件名称
|
|
String fileName = FileUploadUtils.upload(filePath, file);
|
|
String fileName = FileUploadUtils.upload(filePath, file);
|
|
String url = serverConfig.getUrl() + fileName;
|
|
String url = serverConfig.getUrl() + fileName;
|
|
@@ -125,9 +121,7 @@ public class CommonController
|
|
ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER));
|
|
ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER));
|
|
ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER));
|
|
ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER));
|
|
return ajax;
|
|
return ajax;
|
|
- }
|
|
|
|
- catch (Exception e)
|
|
|
|
- {
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
return AjaxResult.error(e.getMessage());
|
|
return AjaxResult.error(e.getMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -137,12 +131,9 @@ public class CommonController
|
|
*/
|
|
*/
|
|
@GetMapping("/download/resource")
|
|
@GetMapping("/download/resource")
|
|
public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response)
|
|
public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response)
|
|
- throws Exception
|
|
|
|
- {
|
|
|
|
- try
|
|
|
|
- {
|
|
|
|
- if (!FileUtils.checkAllowDownload(resource))
|
|
|
|
- {
|
|
|
|
|
|
+ throws Exception {
|
|
|
|
+ try {
|
|
|
|
+ if (!FileUtils.checkAllowDownload(resource)) {
|
|
throw new Exception(StringUtils.format("资源文件({})非法,不允许下载。 ", resource));
|
|
throw new Exception(StringUtils.format("资源文件({})非法,不允许下载。 ", resource));
|
|
}
|
|
}
|
|
// 本地资源路径
|
|
// 本地资源路径
|
|
@@ -154,9 +145,7 @@ public class CommonController
|
|
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
FileUtils.setAttachmentResponseHeader(response, downloadName);
|
|
FileUtils.setAttachmentResponseHeader(response, downloadName);
|
|
FileUtils.writeBytes(downloadPath, response.getOutputStream());
|
|
FileUtils.writeBytes(downloadPath, response.getOutputStream());
|
|
- }
|
|
|
|
- catch (Exception e)
|
|
|
|
- {
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
log.error("下载文件失败", e);
|
|
log.error("下载文件失败", e);
|
|
}
|
|
}
|
|
}
|
|
}
|