强化文件api,添加FilePond

This commit is contained in:
AlanScipio
2024-02-22 11:19:57 +08:00
parent da8d9f2fed
commit 7b71fd28e4
57 changed files with 1798 additions and 1542 deletions

View File

@@ -1,14 +1,16 @@
package com.ruoyi.system.api;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.core.constant.ServiceNameConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.domain.SysFileInfo;
import com.ruoyi.system.api.factory.RemoteFileFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;
/**
* 文件服务
@@ -25,4 +27,13 @@ public interface RemoteFileService {
*/
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
R<SysFileInfo> upload(@RequestPart(value = "file") MultipartFile file);
/**
* 删除文件
*
* @param fileIds 文件id
* @return 结果
*/
@DeleteMapping("/deleteFiles/{fileIds}")
R<SysFileInfo> deleteFiles(@PathVariable String[] fileIds);
}

View File

@@ -1,35 +1,36 @@
package com.ruoyi.system.api.factory;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.RemoteFileService;
import com.ruoyi.system.api.domain.SysFileInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.RemoteFileService;
import com.ruoyi.system.api.domain.SysFileInfo;
/**
* 文件服务降级处理
*
*
* @author ruoyi
*/
@Component
public class RemoteFileFallbackFactory implements FallbackFactory<RemoteFileService>
{
public class RemoteFileFallbackFactory implements FallbackFactory<RemoteFileService> {
private static final Logger log = LoggerFactory.getLogger(RemoteFileFallbackFactory.class);
@Override
public RemoteFileService create(Throwable throwable)
{
public RemoteFileService create(Throwable throwable) {
log.error("文件服务调用失败:{}", throwable.getMessage());
return new RemoteFileService()
{
return new RemoteFileService() {
@Override
public R<SysFileInfo> upload(MultipartFile file)
{
public R<SysFileInfo> upload(MultipartFile file) {
return R.fail("上传文件失败:" + throwable.getMessage());
}
@Override
public R<SysFileInfo> deleteFiles(String[] fileIds) {
return R.fail("删除文件失败:" + throwable.getMessage());
}
};
}
}