疯狂的狮子li
2021-09-27 b082da73a1e0259738ccb33ebf7d80cad3dc3a10
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java
@@ -1,8 +1,10 @@
package com.ruoyi.web.controller.system;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpException;
import cn.hutool.http.HttpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.annotation.Log;
@@ -29,7 +31,6 @@
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -62,7 +63,7 @@
    * 查询OSS对象存储列表
    */
   @ApiOperation("查询OSS对象存储列表")
   @PreAuthorize("@ss.hasPermi('system:oss:list')")
   @SaCheckPermission("system:oss:list")
   @GetMapping("/list")
   public TableDataInfo<SysOssVo> list(@Validated(QueryGroup.class) SysOssBo bo) {
      return iSysOssService.queryPageList(bo);
@@ -75,7 +76,7 @@
   @ApiImplicitParams({
      @ApiImplicitParam(name = "file", value = "文件", dataType = "java.io.File", required = true),
   })
   @PreAuthorize("@ss.hasPermi('system:oss:upload')")
   @SaCheckPermission("system:oss:upload")
   @Log(title = "OSS对象存储", businessType = BusinessType.INSERT)
   @RepeatSubmit
   @PostMapping("/upload")
@@ -91,7 +92,7 @@
   }
   @ApiOperation("下载OSS对象存储")
   @PreAuthorize("@ss.hasPermi('system:oss:download')")
   @SaCheckPermission("system:oss:download")
   @GetMapping("/download/{ossId}")
   public void download(@PathVariable Long ossId, HttpServletResponse response) throws IOException {
      SysOss sysOss = iSysOssService.getById(ossId);
@@ -103,7 +104,16 @@
      response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
      FileUtils.setAttachmentResponseHeader(response, URLEncoder.encode(sysOss.getOriginalName(), StandardCharsets.UTF_8.toString()));
      response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE + "; charset=UTF-8");
      long data = HttpUtil.download(sysOss.getUrl(), response.getOutputStream(), false);
      long data;
      try {
         data = HttpUtil.download(sysOss.getUrl(), response.getOutputStream(), false);
      } catch (HttpException e) {
         if (e.getMessage().contains("403")) {
            throw new ServiceException("无读取权限, 请在对应的OSS开启'公有读'权限!");
         } else {
            throw new ServiceException(e.getMessage());
         }
      }
      response.setContentLength(Convert.toInt(data));
   }
@@ -111,7 +121,7 @@
    * 删除OSS对象存储
    */
   @ApiOperation("删除OSS对象存储")
   @PreAuthorize("@ss.hasPermi('system:oss:remove')")
   @SaCheckPermission("system:oss:remove")
   @Log(title = "OSS对象存储" , businessType = BusinessType.DELETE)
   @DeleteMapping("/{ossIds}")
   public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
@@ -123,7 +133,7 @@
    * 变更图片列表预览状态
    */
   @ApiOperation("变更图片列表预览状态")
   @PreAuthorize("@ss.hasPermi('system:oss:edit')")
   @SaCheckPermission("system:oss:edit")
   @Log(title = "OSS对象存储" , businessType = BusinessType.UPDATE)
   @PutMapping("/changePreviewListResource")
   public AjaxResult<Void> changePreviewListResource(@RequestBody String body) {