|
@@ -1,11 +1,16 @@
|
|
|
package com.backendsys.modules.upload.controller;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.backendsys.exception.CustException;
|
|
|
import com.backendsys.modules.common.aspect.SysLog;
|
|
|
+import com.backendsys.modules.common.config.security.enums.SecurityEnum;
|
|
|
import com.backendsys.modules.common.config.security.utils.HttpRequestUtil;
|
|
|
import com.backendsys.modules.common.config.security.utils.SecurityUtil;
|
|
|
import com.backendsys.modules.common.utils.Result;
|
|
|
import com.backendsys.modules.upload.entity.SysFile;
|
|
|
import com.backendsys.modules.upload.service.SysFileService;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -14,11 +19,17 @@ import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
@Validated
|
|
|
@RestController
|
|
|
@Tag(name = "文件管理")
|
|
|
public class SysFileController {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SecurityUtil securityUtil;
|
|
|
+
|
|
|
@Autowired
|
|
|
private SysFileService sysFileService;
|
|
|
|
|
@@ -27,12 +38,14 @@ public class SysFileController {
|
|
|
* - 缩略图 (?imageView2/1/w/100/h/100/q/60)
|
|
|
*/
|
|
|
@Operation(summary = "获取文件列表 (全部)")
|
|
|
+ @PreAuthorize("@sr.hasPermission('1.1.1')")
|
|
|
@GetMapping("/api/upload/getUploadFileAllList")
|
|
|
public Result getUploadFileAllList(@Validated SysFile sysFile) {
|
|
|
return Result.success().put("data", sysFileService.selectUploadFileList(sysFile));
|
|
|
}
|
|
|
|
|
|
@Operation(summary = "获取文件列表 (我的)")
|
|
|
+ @PreAuthorize("@sr.hasPermission('1.1.2')")
|
|
|
@GetMapping("/api/upload/getUploadFileList")
|
|
|
public Result getUploadFileList(@Validated SysFile sysFile) {
|
|
|
sysFile.setUser_id(SecurityUtil.getUserId());
|
|
@@ -41,34 +54,66 @@ public class SysFileController {
|
|
|
|
|
|
@SysLog("上传文件 (普通上传)")
|
|
|
@Operation(summary = "上传文件 (普通上传,单文件上传不超过 100MB)")
|
|
|
- @PreAuthorize("@sr.hasPermission(1.1)")
|
|
|
+ @PreAuthorize("@sr.hasPermission('1.1.3')")
|
|
|
@PostMapping("/api/upload/uploadSmall")
|
|
|
public Result uploadSmall(@RequestParam("file") MultipartFile multipartFile, Long category_id) {
|
|
|
return Result.success().put("data", sysFileService.uploadSmall(multipartFile, category_id));
|
|
|
}
|
|
|
|
|
|
+ @SysLog("编辑文件 (名称)")
|
|
|
+ @Operation(summary = "编辑文件 (名称)")
|
|
|
+ @PreAuthorize("@sr.hasPermission('1.1.4')")
|
|
|
+ @PutMapping("/api/upload/updateUploadFile")
|
|
|
+ public Result updateUploadFile(@Validated(SysFile.Update.class) @RequestBody SysFile sysFile) {
|
|
|
+ return Result.success().put("data", sysFileService.updateUploadFile(sysFile));
|
|
|
+ }
|
|
|
+
|
|
|
@SysLog("删除文件")
|
|
|
@Operation(summary = "删除文件")
|
|
|
- @PreAuthorize("@sr.hasPermission(1.1)")
|
|
|
+ @PreAuthorize("@sr.hasPermission('1.1.6')")
|
|
|
@DeleteMapping("/api/upload/removeUploadFile")
|
|
|
public Result removeUploadFile(@Validated(SysFile.Delete.class) @RequestBody SysFile sysFile) {
|
|
|
- return Result.success().put("data", sysFileService.removeUploadFile(sysFile));
|
|
|
+
|
|
|
+ // 判断是否存在
|
|
|
+ String object_key = sysFile.getObject_key();
|
|
|
+ SysFile querySysFile = sysFileService.getOne(new LambdaQueryWrapper<SysFile>().eq(SysFile::getObject_key, object_key));
|
|
|
+ if (querySysFile == null) throw new CustException("文件不存在");
|
|
|
+
|
|
|
+ // 权限:
|
|
|
+ // - 删除自己 (需权限) (1.1.6)
|
|
|
+ // - 删除全部 (需要子权限或超级管理员) (1.1.5)
|
|
|
+ Long user_id = querySysFile.getUser_id();
|
|
|
+ if (user_id.equals(SecurityUtil.getUserId()) && !securityUtil.hasPermission("1.1.5")) {
|
|
|
+ throw new CustException(SecurityEnum.NOAUTH);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Result.success().put("data", sysFileService.removeUploadFile(sysFile, querySysFile));
|
|
|
}
|
|
|
|
|
|
@SysLog("删除文件 (批量)")
|
|
|
@Operation(summary = "删除文件 (批量)")
|
|
|
- @PreAuthorize("@sr.hasPermission(1.1)")
|
|
|
+ @PreAuthorize("@sr.hasPermission('1.1.6')")
|
|
|
@DeleteMapping("/api/upload/removeUploadFileBatch")
|
|
|
public Result removeUploadFileBatch(@Validated(SysFile.DeleteBatch.class) @RequestBody SysFile sysFile) {
|
|
|
- return Result.success().put("data", sysFileService.removeUploadFileBatch(sysFile));
|
|
|
- }
|
|
|
|
|
|
- @SysLog("编辑文件 (名称)")
|
|
|
- @Operation(summary = "编辑文件 (名称)")
|
|
|
- @PreAuthorize("@sr.hasPermission(1.1)")
|
|
|
- @PutMapping("/api/upload/updateUploadFile")
|
|
|
- public Result updateUploadFile(@Validated(SysFile.Update.class) @RequestBody SysFile sysFile) {
|
|
|
- return Result.success().put("data", sysFileService.updateUploadFile(sysFile));
|
|
|
+ // 判断是否存在
|
|
|
+ List<String> object_keys = StrUtil.split(sysFile.getObject_keys(), ',', true, true);
|
|
|
+ List<SysFile> querySysFileList = sysFileService.list(new LambdaQueryWrapper<SysFile>().in(SysFile::getObject_key, object_keys));
|
|
|
+ if (querySysFileList != null && querySysFileList.size() != object_keys.size()) {
|
|
|
+ throw new CustException("object_key 一个或多个不存在 (提交:" + object_keys.size() + ", 存在:" + querySysFileList.size() + ")");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 权限:
|
|
|
+ // - 删除自己 (需权限) (1.1.6)
|
|
|
+ // - 删除全部 (需要子权限或超级管理员) (1.1.5)
|
|
|
+ List<Long> userIdList = querySysFileList.stream().map(SysFile::getUser_id).collect(Collectors.toList());
|
|
|
+ if (userIdList.contains(SecurityUtil.getUserId()) && !securityUtil.hasPermission("1.1.5")) {
|
|
|
+ throw new CustException(SecurityEnum.NOAUTH);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Result.success().put("data", sysFileService.removeUploadFileBatch(sysFile, querySysFileList));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
}
|