疯狂的狮子Li
2021-09-27 49fc74be5d4c65d34d29237b05e26a1a0238715e
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java
@@ -3,6 +3,7 @@
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;
@@ -10,6 +11,7 @@
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.JsonUtils;
@@ -48,7 +50,7 @@
 * @author Lion Li
 */
@Validated
@Api(value = "OSS云存储控制器", tags = {"OSS云存储管理"})
@Api(value = "OSS对象存储控制器", tags = {"OSS对象存储管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/oss")
@@ -58,24 +60,24 @@
   private final ISysConfigService iSysConfigService;
   /**
    * 查询OSS云存储列表
    * 查询OSS对象存储列表
    */
   @ApiOperation("查询OSS云存储列表")
   @ApiOperation("查询OSS对象存储列表")
   @PreAuthorize("@ss.hasPermi('system:oss:list')")
   @GetMapping("/list")
   public TableDataInfo<SysOssVo> list(@Validated SysOssBo bo) {
   public TableDataInfo<SysOssVo> list(@Validated(QueryGroup.class) SysOssBo bo) {
      return iSysOssService.queryPageList(bo);
   }
   /**
    * 上传OSS云存储
    * 上传OSS对象存储
    */
   @ApiOperation("上传OSS云存储")
   @ApiOperation("上传OSS对象存储")
   @ApiImplicitParams({
      @ApiImplicitParam(name = "file", value = "文件", dataType = "java.io.File", required = true),
   })
   @PreAuthorize("@ss.hasPermi('system:oss:upload')")
   @Log(title = "OSS云存储", businessType = BusinessType.INSERT)
   @Log(title = "OSS对象存储", businessType = BusinessType.INSERT)
   @RepeatSubmit
   @PostMapping("/upload")
   public AjaxResult<Map<String, String>> upload(@RequestPart("file") MultipartFile file) {
@@ -89,7 +91,7 @@
      return AjaxResult.success(map);
   }
   @ApiOperation("下载OSS云存储")
   @ApiOperation("下载OSS对象存储")
   @PreAuthorize("@ss.hasPermi('system:oss:download')")
   @GetMapping("/download/{ossId}")
   public void download(@PathVariable Long ossId, HttpServletResponse response) throws IOException {
@@ -100,18 +102,27 @@
      response.reset();
      response.addHeader("Access-Control-Allow-Origin", "*");
      response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
      FileUtils.setAttachmentResponseHeader(response, URLEncoder.encode(sysOss.getOriginalName(), StandardCharsets.UTF_8.toString()));
      FileUtils.setAttachmentResponseHeader(response, sysOss.getOriginalName());
      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));
   }
   /**
    * 删除OSS云存储
    * 删除OSS对象存储
    */
   @ApiOperation("删除OSS云存储")
   @ApiOperation("删除OSS对象存储")
   @PreAuthorize("@ss.hasPermi('system:oss:remove')")
   @Log(title = "OSS云存储" , businessType = BusinessType.DELETE)
   @Log(title = "OSS对象存储" , businessType = BusinessType.DELETE)
   @DeleteMapping("/{ossIds}")
   public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                           @PathVariable Long[] ossIds) {
@@ -123,7 +134,7 @@
    */
   @ApiOperation("变更图片列表预览状态")
   @PreAuthorize("@ss.hasPermi('system:oss:edit')")
   @Log(title = "OSS云存储" , businessType = BusinessType.UPDATE)
   @Log(title = "OSS对象存储" , businessType = BusinessType.UPDATE)
   @PutMapping("/changePreviewListResource")
   public AjaxResult<Void> changePreviewListResource(@RequestBody String body) {
      Map<String, Boolean> map = JsonUtils.parseMap(body);