1. 代码生成器在生成的时候可以手动选择是否是业务数据类代码(会自动继承基础业务类,合并字段,实现业务接口标记,这个标记会将右上角选择公司作为当前业务数据数据权限进行过滤,办理业务时,如果操作人归属同一个公司的多个部门,会前置校验后弹窗选择归属部门后才能正常办理业务)
2. 文件上传的地方做了一个改动,如果上传文件的 hash 和已存在的附件相同,不会重复上传,会复用相同hash 的附件(要加一个字段,加字段脚本提供两个版本的 patch 脚本 mysql:根目录/sql/mysql/patch.sql dm:根目录/sql/dm/patch.sql )
This commit is contained in:
@@ -306,4 +306,44 @@ public class FileServiceImplTest extends BaseDbUnitTest {
|
||||
assertTrue(path.matches("\\d{8}/test_\\d+\\.jpg"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果上传文件 hash 一致 SHA256 值,则复用已存在的文件
|
||||
* 不做重复上传
|
||||
*/
|
||||
@Test
|
||||
public void testCreateFile_withSameHash() throws Exception {
|
||||
// 准备参数
|
||||
byte[] content = ResourceUtil.readBytes("file/erweima.jpg");
|
||||
String name = "单测文件名";
|
||||
String directory = randomString();
|
||||
String type = "image/jpeg";
|
||||
// mock Master 文件客户端
|
||||
FileClient client = mock(FileClient.class);
|
||||
when(fileConfigService.getMasterFileClient()).thenReturn(client);
|
||||
String url = randomString();
|
||||
AtomicReference<String> pathRef = new AtomicReference<>();
|
||||
when(client.upload(same(content), argThat(path -> {
|
||||
assertTrue(path.matches(directory + "/\\d{8}/" + name + "_\\d+.jpg"));
|
||||
pathRef.set(path);
|
||||
return true;
|
||||
}), eq(type))).thenReturn(url);
|
||||
when(client.getId()).thenReturn(10L);
|
||||
|
||||
// 首次上传
|
||||
String result1 = fileService.createFile(content, name, directory, type);
|
||||
assertEquals(result1, url);
|
||||
|
||||
// 再次上传同样的内容,应该复用已存在的文件
|
||||
String result2 = fileService.createFile(content, name, directory, type);
|
||||
assertEquals(result2, url);
|
||||
|
||||
// 校验数据
|
||||
FileDO file = fileMapper.selectOne(FileDO::getUrl, url);
|
||||
assertEquals(10L, file.getConfigId());
|
||||
assertEquals(pathRef.get(), file.getPath());
|
||||
assertEquals(url, file.getUrl());
|
||||
assertEquals(type, file.getType());
|
||||
assertEquals(content.length, file.getSize());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ CREATE TABLE IF NOT EXISTS "infra_file" (
|
||||
"update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deleted" bit NOT NULL DEFAULT FALSE,
|
||||
"tenant_id" bigint not null default '0',
|
||||
"hash" varchar(64) DEFAULT NULL COMMENT '文件哈希值(SHA-256)',
|
||||
PRIMARY KEY ("id")
|
||||
) COMMENT '文件表';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user