|
@@ -6,6 +6,7 @@ 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.vo.FileDownVo;
|
|
import com.ozs.system.domain.SysFileInfo;
|
|
import com.ozs.system.domain.SysFileInfo;
|
|
import com.ozs.system.service.SysFileService;
|
|
import com.ozs.system.service.SysFileService;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
@@ -13,10 +14,8 @@ 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;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.http.MediaType;
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import com.ozs.common.config.PurchaseConfig;
|
|
import com.ozs.common.config.PurchaseConfig;
|
|
import com.ozs.common.constant.Constants;
|
|
import com.ozs.common.constant.Constants;
|
|
@@ -50,22 +49,23 @@ public class CommonController {
|
|
/**
|
|
/**
|
|
* 通用下载请求
|
|
* 通用下载请求
|
|
*
|
|
*
|
|
- * @param fileName 文件名称
|
|
|
|
- * @param delete 是否删除
|
|
|
|
*/
|
|
*/
|
|
- @GetMapping("/download")
|
|
|
|
- public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) {
|
|
|
|
|
|
+ @PostMapping("/download")
|
|
|
|
+ public void fileDownload(@RequestBody FileDownVo vo, HttpServletResponse response, HttpServletRequest request) {
|
|
try {
|
|
try {
|
|
- if (!FileUtils.checkAllowDownload(fileName)) {
|
|
|
|
- throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
|
|
|
|
|
|
+ if(ObjectUtils.isEmpty(vo)){
|
|
|
|
+ throw new Exception("参数不能为空");
|
|
}
|
|
}
|
|
- String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
|
|
|
|
- String filePath = PurchaseConfig.getDownloadPath() + fileName.substring("/profile/upload/".length(),fileName.length());
|
|
|
|
|
|
+ if (!FileUtils.checkAllowDownload(vo.getFileName())) {
|
|
|
|
+ throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", vo.getFileName()));
|
|
|
|
+ }
|
|
|
|
+ String realFileName = System.currentTimeMillis() + vo.getFileName().substring(vo.getFileName().indexOf("_") + 1);
|
|
|
|
+ String filePath = PurchaseConfig.getDownloadPath() + vo.getFileName().substring("/profile/upload/".length(),vo.getFileName().length());
|
|
|
|
|
|
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 (vo.getDelete()) {
|
|
FileUtils.deleteFile(filePath);
|
|
FileUtils.deleteFile(filePath);
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|