疯狂的狮子li
2021-07-12 cd34c87afa730c48e2b2be61d700b1fee409e02c
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java
@@ -18,10 +18,13 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
/**
 * 通用请求处理
 *
 *
 * @author ruoyi
 */
@RestController
@@ -34,7 +37,7 @@
    /**
     * 通用下载请求
     *
     *
     * @param fileName 文件名称
     * @param delete 是否删除
     */
@@ -49,13 +52,13 @@
            }
            String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
            String filePath = RuoYiConfig.getDownloadPath() + fileName;
         File file = new File(filePath);
            response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
            FileUtils.setAttachmentResponseHeader(response, realFileName);
            FileUtils.writeBytes(filePath, response.getOutputStream());
         FileUtils.writeToStream(file, response.getOutputStream());
            if (delete)
            {
                FileUtils.deleteFile(filePath);
            FileUtils.del(file);
            }
        }
        catch (Exception e)
@@ -77,10 +80,10 @@
            // 上传并返回新文件名称
            String fileName = FileUploadUtils.upload(filePath, file);
            String url = serverConfig.getUrl() + fileName;
            AjaxResult ajax = AjaxResult.success();
         Map<String,Object> ajax = new HashMap<>();
            ajax.put("fileName", fileName);
            ajax.put("url", url);
            return ajax;
            return AjaxResult.success(ajax);
        }
        catch (Exception e)
        {
@@ -108,8 +111,9 @@
            // 下载名称
            String downloadName = StrUtil.subAfter(downloadPath, "/",true);
            response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
         File file = new File(downloadPath);
            FileUtils.setAttachmentResponseHeader(response, downloadName);
            FileUtils.writeBytes(downloadPath, response.getOutputStream());
            FileUtils.writeToStream(file, response.getOutputStream());
        }
        catch (Exception e)
        {