From 254ea442ff0e0a7a97e9f481e9f127a782cba840 Mon Sep 17 00:00:00 2001
From: 19626 <1962676589@qq.com>
Date: 星期一, 17 七月 2023 11:37:35 +0800
Subject: [PATCH] 修改附件7.17

---
 force-app/main/default/classes/OPDPlanHandler.cls |   84 +++++++++++++++++++++++++++++++++--------
 1 files changed, 67 insertions(+), 17 deletions(-)

diff --git a/force-app/main/default/classes/OPDPlanHandler.cls b/force-app/main/default/classes/OPDPlanHandler.cls
index 7540370..bd9837c 100644
--- a/force-app/main/default/classes/OPDPlanHandler.cls
+++ b/force-app/main/default/classes/OPDPlanHandler.cls
@@ -666,25 +666,75 @@
                     insert insertCloneList;
                 }
             }
-            List<Attachment> getAttachmentList = [SELECT Id, Body, Name, ParentId
-                                        FROM Attachment
-                                        WHERE ParentId In:reapplyopdMap.keySet()];
-            List<Attachment> insertAttachmentCloneList = new List<Attachment>();
-            if (getAttachmentList.size() > 0 ) {
-                for(Attachment att :getAttachmentList){
-                    Attachment attClone = new Attachment();
-                    attClone = att.clone();
-                    attClone.Id = null;
-                    attClone.Body = att.Body;
-                    attClone.Name = att.Name;
-                    attClone.ParentId = reapplyopdMap.get(att.ParentId);
-                    insertAttachmentCloneList.add(attClone);
-                }
 
-                if (insertAttachmentCloneList.size() > 0) {
-                    insert insertAttachmentCloneList;
-                }
+
+            List<ContentDocumentLink> cdlList = [SELECT ContentDocumentId,LinkedEntityId
+                                                   FROM ContentDocumentLink
+                                                   WHERE LinkedEntityId In:reapplyopdMap.keySet()];
+            List<ID> fileIDs = new List<ID>();
+            for (ContentDocumentLink docLink : cdlList) {
+                fileIDs.add(docLink.ContentDocumentId);
             }
+            List<ContentDocument> attachmentinfo=[SELECT Id,Title,OwnerId from ContentDocument WHERE id IN :fileIDs];
+            List<Id> idList = new List<Id>();
+            for (ContentDocument attachment : attachmentinfo) {
+                idList.add(attachment.Id);
+            }
+            List<ContentVersion> versionList = [select Id,VersionData,Title,ContentLocation,PathOnClient from ContentVersion where ContentDocumentId in: idList];
+            List<ContentVersion> newVersionList = new List<ContentVersion>();
+            for (ContentVersion version : versionList) {
+                ContentVersion newVersion = new ContentVersion();
+                newVersion = version.clone();
+                newVersion.Id = null;
+                newVersion.VersionData = version.VersionData;
+                newVersion.Title = version.Title;
+                newVersion.ContentLocation = version.ContentLocation;
+                newVersion.PathOnClient = version.PathOnClient;
+                newVersionList.add(newVersion);
+            }
+
+            if (newVersionList.size() > 0) {
+                insert newVersionList;
+            }
+            idList = new List<Id>();
+            for (ContentVersion newVersion : newVersionList) {
+                idList.add(newVersion.Id);
+            }
+            newVersionList = [SELECT ContentDocumentId FROM ContentVersion WHERE Id IN:idList];
+            List<ContentDocumentLink> linkList = new List<ContentDocumentLink>();
+            Integer i = 0;
+            for (ContentVersion newVersion : newVersionList) {
+                ContentDocumentLink link = new ContentDocumentLink();
+                link.ContentDocumentId = newVersion.ContentDocumentId;
+                link.LinkedEntityId = reapplyopdMap.get(cdlList[i].LinkedEntityId);
+                link.ShareType = 'I';
+                link.Visibility = 'AllUsers';
+                linkList.add(link);
+                i++;
+            }
+            if (linkList.size() > 0) {
+                insert linkList;
+            }
+            
+            // List<Attachment> getAttachmentList = [SELECT Id, Body, Name, ParentId
+            //                             FROM Attachment
+            //                             WHERE ParentId In:reapplyopdMap.keySet()];
+            // List<Attachment> insertAttachmentCloneList = new List<Attachment>();
+            // if (getAttachmentList.size() > 0 ) {
+            //     for(Attachment att :getAttachmentList){
+            //         Attachment attClone = new Attachment();
+            //         attClone = att.clone();
+            //         attClone.Id = null;
+            //         attClone.Body = att.Body;
+            //         attClone.Name = att.Name;
+            //         attClone.ParentId = reapplyopdMap.get(att.ParentId);
+            //         insertAttachmentCloneList.add(attClone);
+            //     }
+
+            //     if (insertAttachmentCloneList.size() > 0) {
+            //         insert insertAttachmentCloneList;
+            //     }
+            // }
     }
 
     private void updateOppPlan() {

--
Gitblit v1.9.1