Prechádzať zdrojové kódy

增加 DataBlock 字段

reghao 2 rokov pred
rodič
commit
4298515d31

+ 4 - 1
dfs-store/src/main/java/cn/reghao/dfs/store/model/po/DataBlock.java

@@ -18,16 +18,19 @@ public class DataBlock extends BaseObject<Integer> {
     private String contentId;
     private int index;
     private String blockId;
+    private String host;
     private String absolutePath;
+    private long size;
     private long start;
     private long end;
     @Deprecated
     private String objectId;
 
-    public DataBlock(String contentId, int index, String blockId, String absolutePath) {
+    public DataBlock(String contentId, int index, String blockId, String absolutePath, long size) {
         this.contentId = contentId;
         this.index = index;
         this.blockId = blockId;
         this.absolutePath = absolutePath;
+        this.size = size;
     }
 }

+ 2 - 4
dfs-store/src/main/java/cn/reghao/dfs/store/service/PutObjectService.java

@@ -39,9 +39,7 @@ public class PutObjectService {
         FileMeta fileMeta = objectRepository.getBySha256sum(sha256sum);
         if (fileMeta != null) {
             FileUtils.deleteQuietly(savedFile);
-            log.error("{} 已存在", sha256sum);
-            ObjectResult objectResult = copyObject(objectProp, originalFilename, fileMeta);
-            return objectResult;
+            return copyObject(objectProp, originalFilename, fileMeta);
         } else {
             String savedPath = savedFile.getAbsolutePath();
             long size = savedFile.length();
@@ -54,7 +52,7 @@ public class PutObjectService {
             fileMeta = new FileMeta(objectName, objectId, contentId, originalFilename, size,
                     fileType, contentType, sha256sum, pid, diskFile, acl);
             String blockId = UUID.randomUUID().toString();
-            List<DataBlock> list = List.of(new DataBlock(contentId, 0, blockId, savedPath));
+            List<DataBlock> list = List.of(new DataBlock(contentId, 0, blockId, savedPath, size));
             objectRepository.saveObject(fileMeta, list);
             return new ObjectResult(objectName, objectId, fileType, savedPath);
         }

+ 4 - 4
dfs-store/src/main/resources/mapper/DataBlockMapper.xml

@@ -4,16 +4,16 @@
 <mapper namespace="cn.reghao.dfs.store.db.mapper.DataBlockMapper">
     <insert id="save" useGeneratedKeys="true" keyProperty="id">
         insert into data_block
-        (`id`,`deleted`,`create_time`,`update_time`,`content_id`,`index`,`block_id`,`absolute_path`,`start`,`end`)
+        (`id`,`deleted`,`create_time`,`update_time`,`content_id`,`index`,`block_id`,`host`,`absolute_path`,`size`,`start`,`end`)
         values
-        (#{id},#{deleted},#{createTime},#{updateTime},#{contentId},#{index},#{blockId},#{absolutePath},#{start},#{end})
+        (#{id},#{deleted},#{createTime},#{updateTime},#{contentId},#{index},#{blockId},#{host},#{absolutePath},#{size},#{start},#{end})
     </insert>
     <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
         insert into data_block
-        (`id`,`deleted`,`create_time`,`update_time`,`content_id`,`index`,`block_id`,`absolute_path`,`start`,`end`)
+        (`id`,`deleted`,`create_time`,`update_time`,`content_id`,`index`,`block_id`,`host`,`absolute_path`,`size`,`start`,`end`)
         values
         <foreach collection="list" item="item" index="index" separator=",">
-            (#{item.id},#{item.deleted},#{item.createTime},#{item.updateTime},#{item.contentId},#{item.index},#{item.blockId},#{item.absolutePath},#{item.start},#{item.end})
+            (#{item.id},#{item.deleted},#{item.createTime},#{item.updateTime},#{item.contentId},#{item.index},#{item.blockId},#{item.host},#{item.absolutePath},#{item.size},#{item.start},#{item.end})
         </foreach>
     </insert>