From dd25573ebce3450d90d0012a30b12a5185bc7310 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期五, 08 七月 2022 15:49:15 +0800
Subject: [PATCH] update 使用 @param 注释替换 @Parameter 注解 fix 修复 token 无法传递 与 无法持久化问题

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java |  179 +++++++++++++++++++++++++++++------------------------------
 1 files changed, 89 insertions(+), 90 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java
index 609d41f..85faa16 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysOssController.java
@@ -1,33 +1,27 @@
 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;
-import com.ruoyi.common.annotation.RepeatSubmit;
 import com.ruoyi.common.core.controller.BaseController;
-import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.domain.PageQuery;
+import com.ruoyi.common.core.domain.R;
 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;
 import com.ruoyi.common.utils.file.FileUtils;
-import com.ruoyi.oss.constant.CloudConstant;
-import com.ruoyi.system.domain.SysConfig;
 import com.ruoyi.system.domain.SysOss;
 import com.ruoyi.system.domain.bo.SysOssBo;
 import com.ruoyi.system.domain.vo.SysOssVo;
-import com.ruoyi.system.service.ISysConfigService;
 import com.ruoyi.system.service.ISysOssService;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiImplicitParams;
-import io.swagger.annotations.ApiOperation;
+import io.swagger.v3.oas.annotations.tags.Tag;
 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;
@@ -35,10 +29,9 @@
 import javax.servlet.http.HttpServletResponse;
 import javax.validation.constraints.NotEmpty;
 import java.io.IOException;
-import java.net.URLEncoder;
-import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -47,89 +40,95 @@
  * @author Lion Li
  */
 @Validated
-@Api(value = "OSS浜戝瓨鍌ㄦ帶鍒跺櫒", tags = {"OSS浜戝瓨鍌ㄧ鐞�"})
-@RequiredArgsConstructor(onConstructor_ = @Autowired)
+@Tag(name = "瀵硅薄瀛樺偍鎺у埗鍣�", description = "瀵硅薄瀛樺偍绠$悊")
+@RequiredArgsConstructor
 @RestController
 @RequestMapping("/system/oss")
 public class SysOssController extends BaseController {
 
-	private final ISysOssService iSysOssService;
-	private final ISysConfigService iSysConfigService;
+    private final ISysOssService iSysOssService;
 
-	/**
-	 * 鏌ヨOSS浜戝瓨鍌ㄥ垪琛�
-	 */
-	@ApiOperation("鏌ヨOSS浜戝瓨鍌ㄥ垪琛�")
-	@PreAuthorize("@ss.hasPermi('system:oss:list')")
-	@GetMapping("/list")
-	public TableDataInfo<SysOssVo> list(@Validated SysOssBo bo) {
-		return iSysOssService.queryPageList(bo);
-	}
+    /**
+     * 鏌ヨOSS瀵硅薄瀛樺偍鍒楄〃
+     */
+    @SaCheckPermission("system:oss:list")
+    @GetMapping("/list")
+    public TableDataInfo<SysOssVo> list(@Validated(QueryGroup.class) SysOssBo bo, PageQuery pageQuery) {
+        return iSysOssService.queryPageList(bo, pageQuery);
+    }
 
-	/**
-	 * 涓婁紶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)
-	@RepeatSubmit
-	@PostMapping("/upload")
-	public AjaxResult<Map<String, String>> upload(@RequestPart("file") MultipartFile file) {
-		if (file.isEmpty()) {
-			throw new ServiceException("涓婁紶鏂囦欢涓嶈兘涓虹┖");
-		}
-		SysOss oss = iSysOssService.upload(file);
-		Map<String, String> map = new HashMap<>(2);
-		map.put("url", oss.getUrl());
-		map.put("fileName", oss.getFileName());
-		return AjaxResult.success(map);
-	}
+    /**
+     * 鏌ヨOSS瀵硅薄鍩轰簬id涓�
+     *
+     * @param ossIds OSS瀵硅薄ID涓�
+     */
+    @SaCheckPermission("system:oss:list")
+    @GetMapping("/listByIds/{ossIds}")
+    public R<List<SysOssVo>> listByIds(@NotEmpty(message = "涓婚敭涓嶈兘涓虹┖")
+                                       @PathVariable Long[] ossIds) {
+        List<SysOssVo> list = iSysOssService.listByIds(Arrays.asList(ossIds));
+        return R.ok(list);
+    }
 
-	@ApiOperation("涓嬭浇OSS浜戝瓨鍌�")
-	@PreAuthorize("@ss.hasPermi('system:oss:download')")
-	@GetMapping("/download/{ossId}")
-	public void download(@PathVariable Long ossId, HttpServletResponse response) throws IOException {
-		SysOss sysOss = iSysOssService.getById(ossId);
-		if (sysOss == null) {
-			throw new ServiceException("鏂囦欢鏁版嵁涓嶅瓨鍦�!");
-		}
-		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()));
-		response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE + "; charset=UTF-8");
-		long data = HttpUtil.download(sysOss.getUrl(), response.getOutputStream(), false);
-		response.setContentLength(Convert.toInt(data));
-	}
+    /**
+     * 涓婁紶OSS瀵硅薄瀛樺偍
+     *
+     * @param file 鏂囦欢
+     */
+    @SaCheckPermission("system:oss:upload")
+    @Log(title = "OSS瀵硅薄瀛樺偍", businessType = BusinessType.INSERT)
+    @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
+    public R<Map<String, String>> upload(@RequestPart("file") MultipartFile file) {
+        if (ObjectUtil.isNull(file)) {
+            throw new ServiceException("涓婁紶鏂囦欢涓嶈兘涓虹┖");
+        }
+        SysOss oss = iSysOssService.upload(file);
+        Map<String, String> map = new HashMap<>(2);
+        map.put("url", oss.getUrl());
+        map.put("fileName", oss.getOriginalName());
+        map.put("ossId", oss.getOssId().toString());
+        return R.ok(map);
+    }
 
-	/**
-	 * 鍒犻櫎OSS浜戝瓨鍌�
-	 */
-	@ApiOperation("鍒犻櫎OSS浜戝瓨鍌�")
-	@PreAuthorize("@ss.hasPermi('system:oss:remove')")
-	@Log(title = "OSS浜戝瓨鍌�" , businessType = BusinessType.DELETE)
-	@DeleteMapping("/{ossIds}")
-	public AjaxResult<Void> remove(@NotEmpty(message = "涓婚敭涓嶈兘涓虹┖")
-								   @PathVariable Long[] ossIds) {
-		return toAjax(iSysOssService.deleteWithValidByIds(Arrays.asList(ossIds), true) ? 1 : 0);
-	}
+    /**
+     * 涓嬭浇OSS瀵硅薄
+     *
+     * @param ossId OSS瀵硅薄ID
+     */
+    @SaCheckPermission("system:oss:download")
+    @GetMapping("/download/{ossId}")
+    public void download(@PathVariable Long ossId, HttpServletResponse response) throws IOException {
+        SysOss sysOss = iSysOssService.getById(ossId);
+        if (ObjectUtil.isNull(sysOss)) {
+            throw new ServiceException("鏂囦欢鏁版嵁涓嶅瓨鍦�!");
+        }
+        response.reset();
+        FileUtils.setAttachmentResponseHeader(response, sysOss.getOriginalName());
+        response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE + "; charset=UTF-8");
+        long data;
+        try {
+            data = HttpUtil.download(sysOss.getUrl(), response.getOutputStream(), false);
+        } catch (HttpException e) {
+            if (e.getMessage().contains("403")) {
+                throw new ServiceException("鏃犺鍙栨潈闄�, 璇峰湪瀵瑰簲鐨凮SS寮�鍚�'鍏湁璇�'鏉冮檺!");
+            } else {
+                throw new ServiceException(e.getMessage());
+            }
+        }
+        response.setContentLength(Convert.toInt(data));
+    }
 
-	/**
-	 * 鍙樻洿鍥剧墖鍒楄〃棰勮鐘舵��
-	 */
-	@ApiOperation("鍙樻洿鍥剧墖鍒楄〃棰勮鐘舵��")
-	@PreAuthorize("@ss.hasPermi('system:oss:edit')")
-	@Log(title = "OSS浜戝瓨鍌�" , businessType = BusinessType.UPDATE)
-	@PutMapping("/changePreviewListResource")
-	public AjaxResult<Void> changePreviewListResource(@RequestBody String body) {
-		Map<String, Boolean> map = JsonUtils.parseMap(body);
-		SysConfig config = iSysConfigService.getOne(new LambdaQueryWrapper<SysConfig>()
-			.eq(SysConfig::getConfigKey, CloudConstant.PEREVIEW_LIST_RESOURCE_KEY));
-		config.setConfigValue(map.get("previewListResource").toString());
-		return toAjax(iSysConfigService.updateConfig(config));
-	}
+    /**
+     * 鍒犻櫎OSS瀵硅薄瀛樺偍
+     *
+     * @param ossIds OSS瀵硅薄ID涓�
+     */
+    @SaCheckPermission("system:oss:remove")
+    @Log(title = "OSS瀵硅薄瀛樺偍", businessType = BusinessType.DELETE)
+    @DeleteMapping("/{ossIds}")
+    public R<Void> remove(@NotEmpty(message = "涓婚敭涓嶈兘涓虹┖")
+                          @PathVariable Long[] ossIds) {
+        return toAjax(iSysOssService.deleteWithValidByIds(Arrays.asList(ossIds), true) ? 1 : 0);
+    }
 
 }

--
Gitblit v1.9.3