Browse Source

配置和文件信息大小

zhangtong 3 years ago
parent
commit
b8877f98a0

+ 20 - 0
dmp-fss/doc/table.sql

@@ -0,0 +1,20 @@
+# 文件资源
+CREATE TABLE `file_resource` (
+ `id` varchar(36) NOT NULL,
+ `file_name` varchar(100) NOT NULL,
+ `app_id` varchar(100) NOT NULL,
+ `group_code` varchar(100) NOT NULL,
+ `project_id` varchar(100) NOT NULL,
+ `extension` json NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+# 访问验证
+CREATE TABLE `file_authorization` (
+  `app_id` varchar(100) NOT NULL,
+  `access_key` varchar(100) NOT NULL,
+  `secret_key` varchar(100) NOT NULL,
+  PRIMARY KEY (`app_id`),
+  UNIQUE KEY `file_authorization_un` (`access_key`),
+  KEY `file_authorization_access_key_IDX` (`access_key`) USING BTREE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;

+ 5 - 4
dmp-fss/src/main/java/com/persagy/dmp/fss/common/service/BaseFileService.java

@@ -24,11 +24,11 @@ public abstract class BaseFileService implements FileService {
     @Override
     public String upload(String fileName, String appId, String userId, String groupCode, String projectId, MultipartFile file) throws Exception {
         ObjectNode extension = store(fileName, appId, groupCode, projectId, file);
-        String resourceId = record(fileName, appId, userId,groupCode, projectId, extension);
+        String resourceId = record(file.getSize(), fileName, appId, userId,groupCode, projectId, extension);
         return resourceId;
     }
 
-    private String record(String fileName,String appId, String userId, String groupCode, String projectId, ObjectNode extension) throws Exception {
+    private String record(Long size, String fileName,String appId, String userId, String groupCode, String projectId, ObjectNode extension) throws Exception {
         FileResource entity = new FileResource();
         entity.setId(UUID.randomUUID().toString());
         entity.setAppId(appId);
@@ -40,8 +40,9 @@ public abstract class BaseFileService implements FileService {
         }
         LocalDateTime localDateTime = LocalDateTime.now();
         String format = localDateTime.format(formatter);
-        extension.putPOJO("date", format);
-        extension.putPOJO("type", this.getType());
+        extension.put("date", format);
+        extension.put("type", this.getType());
+        extension.put("size", size);
         entity.setExtension(extension);
         fileResourceRepository.save(entity);
         return entity.getId();