mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 12:39:05 +08:00
feat(file): 新增内部文件上传接口
- 在RemoteFileService中新增innerUpload方法并添加NoToken注解 - 在SysFileController中新增innerUpload接口方法并标记为Inner - 支持通过微服务内部调用上传文件功能
This commit is contained in:
1 parent
64cdd035e1
commit
00fb8ce48b
2 files changed
+154
-117
No files matched your search
+12
@@ -2,6 +2,7 @@ package com.pig4cloud.pigx.admin.api.feign;
|
||||
|
||||
import com.pig4cloud.pigx.common.core.constant.ServiceNameConstants;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.feign.annotation.NoToken;
|
||||
import feign.Response;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -37,4 +38,15 @@ public interface RemoteFileService {
|
||||
*/
|
||||
@PostMapping(value = "/sys-file/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
R upload(@RequestPart("file") MultipartFile file);
|
||||
|
||||
|
||||
/**
|
||||
* 内部上传文件接口
|
||||
*
|
||||
* @param file 要上传的文件
|
||||
* @return 上传结果
|
||||
*/
|
||||
@NoToken
|
||||
@PostMapping(value = "/sys-file/inner/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
R innerUpload(@RequestPart("file") MultipartFile file);
|
||||
}
|
||||
+142
-117
@@ -58,133 +58,158 @@ import java.util.Objects;
|
||||
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
|
||||
public class SysFileController {
|
||||
|
||||
private final SysFileService sysFileService;
|
||||
private final SysFileService sysFileService;
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param page 分页对象
|
||||
* @param sysFile 文件管理
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "分页查询", description = "分页查询")
|
||||
@GetMapping("/page")
|
||||
public R getSysFilePage(@ParameterObject Page page, @ParameterObject SysFile sysFile) {
|
||||
LambdaQueryWrapper<SysFile> wrapper = Wrappers.<SysFile>lambdaQuery()
|
||||
.eq(StrUtil.isNotBlank(sysFile.getType()), SysFile::getType, sysFile.getType())
|
||||
.eq(Objects.nonNull(sysFile.getGroupId()), SysFile::getGroupId, sysFile.getGroupId())
|
||||
.like(StrUtil.isNotBlank(sysFile.getOriginal()), SysFile::getOriginal, sysFile.getOriginal());
|
||||
return R.ok(sysFileService.page(page, wrapper));
|
||||
}
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param sysFile 文件管理
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "分页查询", description = "分页查询")
|
||||
@GetMapping("/page")
|
||||
public R getSysFilePage(@ParameterObject Page page, @ParameterObject SysFile sysFile) {
|
||||
LambdaQueryWrapper<SysFile> wrapper = Wrappers.<SysFile>lambdaQuery()
|
||||
.eq(StrUtil.isNotBlank(sysFile.getType()), SysFile::getType, sysFile.getType())
|
||||
.eq(Objects.nonNull(sysFile.getGroupId()), SysFile::getGroupId, sysFile.getGroupId())
|
||||
.like(StrUtil.isNotBlank(sysFile.getOriginal()), SysFile::getOriginal, sysFile.getOriginal());
|
||||
return R.ok(sysFileService.page(page, wrapper));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除文件管理
|
||||
* @param ids id 列表
|
||||
* @return R
|
||||
*/
|
||||
@Operation(summary = "通过id删除文件管理", description = "通过id删除文件管理")
|
||||
@SysLog("删除文件管理")
|
||||
@DeleteMapping
|
||||
@HasPermission("sys_file_del")
|
||||
public R removeById(@RequestBody Long[] ids) {
|
||||
for (Long id : ids) {
|
||||
sysFileService.deleteFile(id);
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
/**
|
||||
* 通过id删除文件管理
|
||||
*
|
||||
* @param ids id 列表
|
||||
* @return R
|
||||
*/
|
||||
@Operation(summary = "通过id删除文件管理", description = "通过id删除文件管理")
|
||||
@SysLog("删除文件管理")
|
||||
@DeleteMapping
|
||||
@HasPermission("sys_file_del")
|
||||
public R removeById(@RequestBody Long[] ids) {
|
||||
for (Long id : ids) {
|
||||
sysFileService.deleteFile(id);
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@PutMapping("/rename")
|
||||
public R rename(@RequestBody SysFile sysFile) {
|
||||
return R.ok(sysFileService.updateById(sysFile));
|
||||
}
|
||||
@PutMapping("/rename")
|
||||
public R rename(@RequestBody SysFile sysFile) {
|
||||
return R.ok(sysFileService.updateById(sysFile));
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件 文件名采用uuid,避免原始文件名中带"-"符号导致下载的时候解析出现异常
|
||||
* @param file 资源
|
||||
* @param dir 文件夹
|
||||
* @return R(/ admin / bucketName / filename)
|
||||
*/
|
||||
@PostMapping(value = "/upload")
|
||||
public R upload(@RequestPart("file") MultipartFile file, @RequestParam(value = "dir", required = false) String dir,
|
||||
@RequestParam(value = "groupId", required = false) Long groupId,
|
||||
@RequestParam(value = "type", required = false) String type) {
|
||||
return sysFileService.uploadFile(file, dir, groupId, type);
|
||||
}
|
||||
/**
|
||||
* 上传文件 文件名采用uuid,避免原始文件名中带"-"符号导致下载的时候解析出现异常
|
||||
*
|
||||
* @param file 资源
|
||||
* @param dir 文件夹
|
||||
* @return R(/ admin / bucketName / filename)
|
||||
*/
|
||||
@PostMapping(value = "/upload")
|
||||
public R upload(@RequestPart("file") MultipartFile file, @RequestParam(value = "dir", required = false) String dir,
|
||||
@RequestParam(value = "groupId", required = false) Long groupId,
|
||||
@RequestParam(value = "type", required = false) String type) {
|
||||
return sysFileService.uploadFile(file, dir, groupId, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件
|
||||
* @param fileName 文件空间/名称
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@Inner(false)
|
||||
@NoEncrypt
|
||||
@GetMapping("/oss/file")
|
||||
public void file(String fileName, HttpServletResponse response) {
|
||||
sysFileService.getFile(fileName, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本地(resources)文件
|
||||
* @param fileName 文件名称
|
||||
* @param response 本地文件
|
||||
*/
|
||||
@SneakyThrows
|
||||
@NoEncrypt
|
||||
@GetMapping("/local/file/{fileName}")
|
||||
public void localFile(@PathVariable String fileName, HttpServletResponse response) {
|
||||
ClassPathResource resource = new ClassPathResource("file/" + fileName);
|
||||
response.setContentType("application/octet-stream; charset=UTF-8");
|
||||
IoUtil.copy(resource.getInputStream(), response.getOutputStream());
|
||||
}
|
||||
/**
|
||||
* 内部文件上传接口
|
||||
*
|
||||
* @return 文件上传结果
|
||||
*/
|
||||
@Inner
|
||||
@PostMapping(value = "/inner/upload")
|
||||
public R innerUpload(@RequestPart("file") MultipartFile file, @RequestParam(value = "dir", required = false) String dir,
|
||||
@RequestParam(value = "groupId", required = false) Long groupId,
|
||||
@RequestParam(value = "type", required = false) String type) {
|
||||
return sysFileService.uploadFile(file, dir, groupId, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询文件组列表
|
||||
* @param fileGroup SysFileGroup对象,用于筛选条件
|
||||
* @return 包含文件组列表的R对象
|
||||
*/
|
||||
@GetMapping("/group/list")
|
||||
public R listGroup(SysFileGroup fileGroup) {
|
||||
return R.ok(sysFileService.listFileGroup(fileGroup));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加文件组
|
||||
* @param fileGroup SysFileGroup对象,要添加的文件组信息
|
||||
* @return 包含添加结果的R对象
|
||||
*/
|
||||
@PostMapping("/group/add")
|
||||
public R addGroup(@RequestBody SysFileGroup fileGroup) {
|
||||
return R.ok(sysFileService.saveOrUpdateGroup(fileGroup));
|
||||
}
|
||||
/**
|
||||
* 获取文件
|
||||
*
|
||||
* @param fileName 文件空间/名称
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@Inner(false)
|
||||
@NoEncrypt
|
||||
@GetMapping("/oss/file")
|
||||
public void file(String fileName, HttpServletResponse response) {
|
||||
sysFileService.getFile(fileName, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新文件组
|
||||
* @param fileGroup SysFileGroup对象,要更新的文件组信息
|
||||
* @return 包含更新结果的R对象
|
||||
*/
|
||||
@PutMapping("/group/update")
|
||||
public R updateGroup(@RequestBody SysFileGroup fileGroup) {
|
||||
return R.ok(sysFileService.saveOrUpdateGroup(fileGroup));
|
||||
}
|
||||
/**
|
||||
* 获取本地(resources)文件
|
||||
*
|
||||
* @param fileName 文件名称
|
||||
* @param response 本地文件
|
||||
*/
|
||||
@SneakyThrows
|
||||
@NoEncrypt
|
||||
@GetMapping("/local/file/{fileName}")
|
||||
public void localFile(@PathVariable String fileName, HttpServletResponse response) {
|
||||
ClassPathResource resource = new ClassPathResource("file/" + fileName);
|
||||
response.setContentType("application/octet-stream; charset=UTF-8");
|
||||
IoUtil.copy(resource.getInputStream(), response.getOutputStream());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件组
|
||||
* @param id 待删除文件组的ID
|
||||
* @return 包含删除结果的R对象
|
||||
*/
|
||||
@DeleteMapping("/group/delete/{id}")
|
||||
public R updateGroup(@PathVariable Long id) {
|
||||
return R.ok(sysFileService.deleteGroup(id));
|
||||
}
|
||||
/**
|
||||
* 查询文件组列表
|
||||
*
|
||||
* @param fileGroup SysFileGroup对象,用于筛选条件
|
||||
* @return 包含文件组列表的R对象
|
||||
*/
|
||||
@GetMapping("/group/list")
|
||||
public R listGroup(SysFileGroup fileGroup) {
|
||||
return R.ok(sysFileService.listFileGroup(fileGroup));
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动文件组
|
||||
* @param fileGroupDTO SysFileGroupDTO对象,要移动的文件组信息
|
||||
* @return 包含移动结果的R对象
|
||||
*/
|
||||
@PutMapping("/group/move")
|
||||
public R moveFileGroup(@RequestBody SysFileGroupDTO fileGroupDTO) {
|
||||
return R.ok(sysFileService.moveFileGroup(fileGroupDTO));
|
||||
}
|
||||
/**
|
||||
* 添加文件组
|
||||
*
|
||||
* @param fileGroup SysFileGroup对象,要添加的文件组信息
|
||||
* @return 包含添加结果的R对象
|
||||
*/
|
||||
@PostMapping("/group/add")
|
||||
public R addGroup(@RequestBody SysFileGroup fileGroup) {
|
||||
return R.ok(sysFileService.saveOrUpdateGroup(fileGroup));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新文件组
|
||||
*
|
||||
* @param fileGroup SysFileGroup对象,要更新的文件组信息
|
||||
* @return 包含更新结果的R对象
|
||||
*/
|
||||
@PutMapping("/group/update")
|
||||
public R updateGroup(@RequestBody SysFileGroup fileGroup) {
|
||||
return R.ok(sysFileService.saveOrUpdateGroup(fileGroup));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文件组
|
||||
*
|
||||
* @param id 待删除文件组的ID
|
||||
* @return 包含删除结果的R对象
|
||||
*/
|
||||
@DeleteMapping("/group/delete/{id}")
|
||||
public R updateGroup(@PathVariable Long id) {
|
||||
return R.ok(sysFileService.deleteGroup(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动文件组
|
||||
*
|
||||
* @param fileGroupDTO SysFileGroupDTO对象,要移动的文件组信息
|
||||
* @return 包含移动结果的R对象
|
||||
*/
|
||||
@PutMapping("/group/move")
|
||||
public R moveFileGroup(@RequestBody SysFileGroupDTO fileGroupDTO) {
|
||||
return R.ok(sysFileService.moveFileGroup(fileGroupDTO));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user