From e53fdfdd78538a21cddd45b9d3faa1a7e9e37a0a Mon Sep 17 00:00:00 2001
From: 19626 <1962676589@qq.com>
Date: 星期五, 21 七月 2023 13:36:24 +0800
Subject: [PATCH] 修改附件

---
 force-app/main/default/classes/eSignHospitalPageController.cls |   54 ++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/force-app/main/default/classes/eSignHospitalPageController.cls b/force-app/main/default/classes/eSignHospitalPageController.cls
index a4ce651..073e9c0 100644
--- a/force-app/main/default/classes/eSignHospitalPageController.cls
+++ b/force-app/main/default/classes/eSignHospitalPageController.cls
@@ -262,41 +262,59 @@
     public static Id saveTheFile(Id parentId, String fileName, String base64Data, String contentType) {
         base64Data = EncodingUtil.urlDecode(base64Data, 'UTF-8');
  
-        Attachment oAttachment = new Attachment();
-        oAttachment.parentId = parentId;
+        // Attachment oAttachment = new Attachment();
+        // oAttachment.parentId = parentId;
  
-        oAttachment.Body = EncodingUtil.base64Decode(base64Data);
-        oAttachment.Name = fileName;
-        oAttachment.ContentType = contentType;
+        // oAttachment.Body = EncodingUtil.base64Decode(base64Data);
+        // oAttachment.Name = fileName;
+        // oAttachment.ContentType = contentType;
  
-        insert oAttachment;
+        // insert oAttachment;
+        ContentVersion version = new ContentVersion();
+        version.Title = fileName;
+        version.VersionData = EncodingUtil.base64Decode(base64Data);
+        version.ContentLocation = 's';
+        version.PathOnClient = fileName + '.' + contentType;
+        insert version;
+        version = [select ContentDocumentId from ContentVersion where Id =: version.Id limit 1];
+        ContentDocumentLink link = new ContentDocumentLink();
+        link.LinkedEntityId = parentId;
+        link.ContentDocumentId = version.ContentDocumentId;
+        link.ShareType = 'I';
+        link.Visibility = 'AllUsers';
+        insert link;
  
-        return oAttachment.Id;
+        return link.ContentDocumentId;
     }
  
     private static void appendToFile(Id fileId, String base64Data) {
         base64Data = EncodingUtil.urlDecode(base64Data, 'UTF-8');
  
-        Attachment a = [
-            SELECT Id, Body
-            FROM Attachment
-            WHERE Id =: fileId
-        ];
+        // Attachment a = [
+        //     SELECT Id, Body
+        //     FROM Attachment
+        //     WHERE Id =: fileId
+        // ];
+        ContentVersion verison = [select Id,VersionData from ContentVersion where ContentDocumentId =: fileId];
  
-        String existingBody = EncodingUtil.base64Encode(a.Body);
+        // String existingBody = EncodingUtil.base64Encode(a.Body);
+        String existingBody = EncodingUtil.base64Encode(verison.VersionData);
  
-        a.Body = EncodingUtil.base64Decode(existingBody + base64Data);
+        verison.VersionData = EncodingUtil.base64Decode(existingBody + base64Data);
  
-        update a;
+        update verison;
     }
     
     //鏂囦欢鍒犻櫎鍔熻兘  绮剧悽鎶�鏈� thh 2021-09-26 start
     @AuraEnabled
     public static void deleteChunk(Id AttachmentId) {
-        Attachment attachment = new Attachment();
-        attachment.id = AttachmentId;
+        // Attachment attachment = new Attachment();
+        // attachment.id = AttachmentId;
 
-        delete attachment;
+        // delete attachment;
+        ContentDocument con =  new ContentDocument();
+        con.Id = AttachmentId;
+        delete con;
     }
     //鏂囦欢鍒犻櫎鍔熻兘  绮剧悽鎶�鏈� thh 2021-09-26 end
 }
\ No newline at end of file

--
Gitblit v1.9.1