mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-23 15:35:06 +08:00
优化文件配置,去掉 region 的配置,通过自动识别
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
package cn.iocoder.yudao.module.infra.api.file;
|
||||
|
||||
import cn.iocoder.yudao.module.infra.api.file.FileApi;
|
||||
import cn.iocoder.yudao.module.infra.service.file.FileService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@ -20,7 +19,7 @@ public class FileApiImpl implements FileApi {
|
||||
private FileService fileService;
|
||||
|
||||
@Override
|
||||
public String createFile(String path, byte[] content) {
|
||||
public String createFile(String path, byte[] content) throws Exception {
|
||||
return fileService.createFile(path, content);
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ public class FileConfigController {
|
||||
@GetMapping("/test")
|
||||
@ApiOperation("测试文件配置是否正确")
|
||||
@PreAuthorize("@ss.hasPermission('infra:file-config:query')")
|
||||
public CommonResult<String> testFileConfig(@RequestParam("id") Long id) {
|
||||
public CommonResult<String> testFileConfig(@RequestParam("id") Long id) throws Exception {
|
||||
String url = fileConfigService.testFileConfig(id);
|
||||
return success(url);
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@ -44,7 +43,7 @@ public class FileController {
|
||||
@ApiImplicitParam(name = "path", value = "文件路径", example = "yudaoyuanma.png", dataTypeClass = String.class)
|
||||
})
|
||||
public CommonResult<String> uploadFile(@RequestParam("file") MultipartFile file,
|
||||
@RequestParam("path") String path) throws IOException {
|
||||
@RequestParam("path") String path) throws Exception {
|
||||
return success(fileService.createFile(path, IoUtil.readBytes(file.getInputStream())));
|
||||
}
|
||||
|
||||
@ -52,7 +51,7 @@ public class FileController {
|
||||
@ApiOperation("删除文件")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
|
||||
@PreAuthorize("@ss.hasPermission('infra:file:delete')")
|
||||
public CommonResult<Boolean> deleteFile(@RequestParam("id") Long id) {
|
||||
public CommonResult<Boolean> deleteFile(@RequestParam("id") Long id) throws Exception {
|
||||
fileService.deleteFile(id);
|
||||
return success(true);
|
||||
}
|
||||
@ -65,7 +64,7 @@ public class FileController {
|
||||
})
|
||||
public void getFileContent(HttpServletResponse response,
|
||||
@PathVariable("configId") Long configId,
|
||||
@PathVariable("path") String path) throws IOException {
|
||||
@PathVariable("path") String path) throws Exception {
|
||||
byte[] content = fileService.getFileContent(configId, path);
|
||||
if (content == null) {
|
||||
log.warn("[getFileContent][configId({}) path({}) 文件不存在]", configId, path);
|
||||
|
@ -82,7 +82,7 @@ public interface FileConfigService {
|
||||
* @param id 编号
|
||||
* @return 文件 URL
|
||||
*/
|
||||
String testFileConfig(Long id);
|
||||
String testFileConfig(Long id) throws Exception;
|
||||
|
||||
/**
|
||||
* 获得指定编号的文件客户端
|
||||
|
@ -225,7 +225,7 @@ public class FileConfigServiceImpl implements FileConfigService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String testFileConfig(Long id) {
|
||||
public String testFileConfig(Long id) throws Exception {
|
||||
// 校验存在
|
||||
this.validateFileConfigExists(id);
|
||||
// 上传文件
|
||||
|
@ -26,14 +26,14 @@ public interface FileService {
|
||||
* @param content 文件内容
|
||||
* @return 文件路径
|
||||
*/
|
||||
String createFile(String path, byte[] content);
|
||||
String createFile(String path, byte[] content) throws Exception;
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteFile(Long id);
|
||||
void deleteFile(Long id) throws Exception;
|
||||
|
||||
/**
|
||||
* 获得文件内容
|
||||
@ -42,6 +42,6 @@ public interface FileService {
|
||||
* @param path 文件路径
|
||||
* @return 文件内容
|
||||
*/
|
||||
byte[] getFileContent(Long configId, String path);
|
||||
byte[] getFileContent(Long configId, String path) throws Exception;
|
||||
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public class FileServiceImpl implements FileService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createFile(String path, byte[] content) {
|
||||
public String createFile(String path, byte[] content) throws Exception {
|
||||
// 上传到文件存储器
|
||||
FileClient client = fileConfigService.getMasterFileClient();
|
||||
Assert.notNull(client, "客户端(master) 不能为空");
|
||||
@ -53,7 +53,7 @@ public class FileServiceImpl implements FileService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFile(Long id) {
|
||||
public void deleteFile(Long id) throws Exception {
|
||||
// 校验存在
|
||||
FileDO file = this.validateFileExists(id);
|
||||
|
||||
@ -75,7 +75,7 @@ public class FileServiceImpl implements FileService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getFileContent(Long configId, String path) {
|
||||
public byte[] getFileContent(Long configId, String path) throws Exception {
|
||||
FileClient client = fileConfigService.getFileClient(configId);
|
||||
Assert.notNull(client, "客户端({}) 不能为空", configId);
|
||||
return client.getContent(path);
|
||||
|
@ -228,7 +228,7 @@ public class FileConfigServiceImplTest extends BaseDbUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileConfig() {
|
||||
public void testFileConfig() throws Exception {
|
||||
// mock 数据
|
||||
FileConfigDO dbFileConfig = randomFileConfigDO().setMaster(false);
|
||||
fileConfigMapper.insert(dbFileConfig);// @Sql: 先插入出一条存在的数据
|
||||
|
@ -70,7 +70,7 @@ public class FileServiceTest extends BaseDbUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateFile_success() {
|
||||
public void testCreateFile_success() throws Exception {
|
||||
// 准备参数
|
||||
String path = randomString();
|
||||
byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
|
||||
@ -95,7 +95,7 @@ public class FileServiceTest extends BaseDbUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteFile_success() {
|
||||
public void testDeleteFile_success() throws Exception {
|
||||
// mock 数据
|
||||
FileDO dbFile = randomPojo(FileDO.class, o -> o.setConfigId(10L).setPath("tudou.jpg"));
|
||||
fileMapper.insert(dbFile);// @Sql: 先插入出一条存在的数据
|
||||
@ -123,7 +123,7 @@ public class FileServiceTest extends BaseDbUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFileContent() {
|
||||
public void testGetFileContent() throws Exception {
|
||||
// 准备参数
|
||||
Long configId = 10L;
|
||||
String path = "tudou.jpg";
|
||||
|
Reference in New Issue
Block a user