|
|
@@ -2,13 +2,19 @@ package com.ruoyi.web.controller.tool;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
import com.ruoyi.common.config.RuoYiConfig;
|
|
|
import com.ruoyi.common.enums.FileType;
|
|
|
+import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.common.utils.file.FileUploadUtils;
|
|
|
import com.ruoyi.common.utils.file.FileUtils;
|
|
|
import com.ruoyi.framework.config.ServerConfig;
|
|
|
+import com.ruoyi.web.controller.common.CommonController;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
@@ -39,6 +45,8 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
@RequestMapping("/system/file")
|
|
|
public class TUnifyFileController extends BaseController
|
|
|
{
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(TUnifyFileController.class);
|
|
|
+
|
|
|
@Autowired
|
|
|
private ITUnifyFileService tUnifyFileService;
|
|
|
|
|
|
@@ -146,6 +154,31 @@ public class TUnifyFileController extends BaseController
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @GetMapping("/download/{id}")
|
|
|
+ public void fileDownload(@PathVariable("id")String id, HttpServletResponse response, HttpServletRequest request){
|
|
|
+ try
|
|
|
+ {
|
|
|
+ TUnifyFile tUnifyFile = tUnifyFileService.selectTUnifyFileById(id);
|
|
|
+
|
|
|
+ String fileName = tUnifyFile.getUploadName();
|
|
|
+ if (!FileUtils.checkAllowDownload(tUnifyFile.getNewUploadName()))
|
|
|
+ {
|
|
|
+ throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ",fileName));
|
|
|
+ }
|
|
|
+ String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
|
|
|
+ String filePath = RuoYiConfig.getDownloadPath() + fileName;
|
|
|
+ response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
+ FileUtils.setAttachmentResponseHeader(response, realFileName);
|
|
|
+ FileUtils.writeBytes(filePath, response.getOutputStream());
|
|
|
+ FileUtils.deleteFile(filePath);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ log.error("下载文件失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 根据附件业务ID()获取附件详情信息列表
|
|
|
*/
|