From 5363705f99dcbb7c270a619804beb4ac29b3faa0 Mon Sep 17 00:00:00 2001
From: 19626 <1962676589@qq.com>
Date: 星期三, 09 八月 2023 20:02:16 +0800
Subject: [PATCH] 今日修改

---
 force-app/main/default/triggers/ContentDocumentLink.trigger |  567 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 511 insertions(+), 56 deletions(-)

diff --git a/force-app/main/default/triggers/ContentDocumentLink.trigger b/force-app/main/default/triggers/ContentDocumentLink.trigger
index 0cc587b..466cff4 100644
--- a/force-app/main/default/triggers/ContentDocumentLink.trigger
+++ b/force-app/main/default/triggers/ContentDocumentLink.trigger
@@ -1,75 +1,530 @@
-trigger ContentDocumentLink on ContentDocumentLink (before delete, after insert) {
-
-    // if((!Test.isRunningTest())&&UserInfo.getUserId()==System.Label.ByPassTrigger){
-    //     return;
-    // }
-    system.debug('enter ContentDocumentLink');
-    system.debug('Trigger.new = ' + (List<ContentDocumentLink>) Trigger.new);
-    system.debug('Trigger.old = ' + (List<ContentDocumentLink>) Trigger.old);
-
-    String invoiceStart = System.Label.invoiceStart;
-    System.debug('invoiceStart = ' + invoiceStart);
+trigger ContentDocumentLink on ContentDocumentLink (before insert,after insert,before delete,after delete, before update, after update) {
     List<String> rentalIds = new List<String>();
     List<String> attIds = new List<String>();
-    // List<String> rentaldelIds = new List<String>();
-    // List<String> attdelIds = new List<String>();
+    List<String> rentaldelIds = new List<String>();
+    List<String> attdelIds = new List<String>();
+    List<String> rentalApplyIds = new List<String>();
+    List<String> accIds = new List<String>();
+    //20221014 yc 鍖婚櫌瀹℃壒浼樺寲 start
+    List<String> accAppIds = new List<String>();
+    //20221014 yc 鍖婚櫌瀹℃壒浼樺寲 end
+    // LHJ CHAN-BCLD4P 20190618 Start
+    List<String> specIds = new List<String>();
+    List<String> specDelIds = new List<String>();
+    // LHJ CHAN-BCLD4P 20190618 End
 
-    if (Trigger.isAfter && Trigger.isInsert) {
-        System.debug('Trigger.isAfter && Trigger.isInsert');
-        for (ContentDocumentLink cdl : Trigger.new) {
-            System.debug('cdl.LinkedEntityId = ' + cdl.LinkedEntityId);
-            System.debug('cdl.ContentDocumentId = ' + cdl.ContentDocumentId);
-            if (String.valueOf(cdl.LinkedEntityId).startsWith(invoiceStart)) {
-                System.debug('String.valueOf(cdl.LinkedEntityId).startsWith(invoiceStart)');
-                rentalIds.add(cdl.LinkedEntityId);
-                attIds.add(cdl.ContentDocumentId);
-                System.debug('rentalIds = ' + rentalIds);
-                System.debug('attIds = ' + attIds);
+    // MZY SWAG-BXXBKA  2021-02-19 start
+    List<String> opdIds = new List<String>();
+    Map<String,String> opdMap = new Map<String,String>();
+    // MZY SWAG-BXXBKA  2021-02-19 end
+
+    List<String> OpporFileIds = new List<String>();
+    Map<String,String> OpporFileUndeleteMap = new Map<String,String>();
+    List<String> DeleteReIds = new List<String>();
+    Map<String,String> OppordeleteReUserMap = new Map<String,String>();
+    Map<String,Datetime> OppordeleteReTimeMap = new Map<String,Datetime>();
+    //CHAN-BCNCRB ---XHL----Start-----
+    List<String> opportunity_FileIds = new List<String>();
+
+    List<String> opportunityFileOrderIds = new List<String>();
+    List<String> oFOrderIds = new List<String>();
+    Map<String,Boolean> oFOrderIdMap = new Map<String,Boolean>();
+
+    // sx 20230210start 澶囧搧鍊熷嚭鐢宠鏁呴殰鎶ュ憡闄勪欢鎻愬彇
+    List<String> rentalApplyFaultIds = new List<String>();
+    Map<String,List<Id>> trentalImages = new Map<String,List<Id>>();
+    List<String> rentaldeleteApplyFaultIds = new List<String>();
+    Map<String,List<Id>> deleteImages = new Map<String,List<Id>>();
+    // sx 20230210end 澶囧搧鍊熷嚭鐢宠鏁呴殰鎶ュ憡闄勪欢鎻愬彇
+    if (Trigger.isBefore && Trigger.isInsert) {
+        for (ContentDocumentLink link : Trigger.new) {
+            if(String.valueOf(link.LinkedEntityId).startsWith(System.Label.Oppor_sepKey)){
+                opportunity_FileIds.add(link.LinkedEntityId);
+            }
+
+            if(String.valueOf(link.LinkedEntityId).startsWith('a3Z')){
+                opportunityFileOrderIds.add(link.LinkedEntityId);
             }
         }
     }
 
-    // if (Trigger.isBefore && Trigger.isDelete) {
-    //     System.debug('Trigger.isBefore && Trigger.isDelete');
-    //     for (ContentDocumentLink cdl : Trigger.old) {
-    //         System.debug('cdl.LinkedEntityId = ' + cdl.LinkedEntityId);
-    //         System.debug('cdl.ContentDocumentId = ' + cdl.ContentDocumentId);
-    //         if (String.valueOf(cdl.LinkedEntityId).startsWith(invoiceStart)) {
-    //             System.debug('String.valueOf(cdl.LinkedEntityId).startsWith(invoiceStart)');
-    //             rentaldelIds.add(cdl.LinkedEntityId);
-    //             attdelIds.add(cdl.ContentDocumentId);
-    //             System.debug('rentaldelIds = ' + rentaldelIds);
-    //             System.debug('attdelIds = ' + attdelIds);
-    //         }
-    //     }
-    // }
+    //CHAN-BCNCRB ---XHL----End-----
+    if (Trigger.isAfter && Trigger.isInsert) {
+        for (ContentDocumentLink link : Trigger.new) {
+            ContentVersion version = [select Id,Title from ContentVersion where ContentDocumentId =: link.ContentDocumentId];
+            //if (att.Name.toUpperCase() == '鍚堝悓涔�.PDF' && String.valueOf(att.ParentId).startsWith('a0t')) {
+            // 娣讳粯銇椼仧濂戠磩鏇搞伄銉曘偂銈ゃ儷鍚嶃伅鎸囧畾銇с亶銇亜
+            if (String.valueOf(link.LinkedEntityId).startsWith('a2K')) {
+                rentalIds.add(link.LinkedEntityId);
+                attIds.add(version.Id);
+            }
+            if (String.valueOf(link.LinkedEntityId).startsWith('a0t')) {
+                rentalApplyIds.add(link.LinkedEntityId); 
+            }
+            if (String.valueOf(link.LinkedEntityId).startsWith('001')) {
+                accIds.add(link.LinkedEntityId);
+            }
+            //20221014 yc 鍖婚櫌瀹℃壒浼樺寲 start
+            if (String.valueOf(link.LinkedEntityId).startsWith('a5C') || String.valueOf(link.LinkedEntityId).startsWith('a5A')) {
+                accAppIds.add(link.LinkedEntityId);
+            }
+            //20221014 yc 鍖婚櫌瀹℃壒浼樺寲 end
+            if(String.valueOf(link.LinkedEntityId).startsWith(System.Label.Oppor_sepKey)){
+                OpporFileIds.add(link.LinkedEntityId);
+            }
+            // LHJ CHAN-BCLD4P 20190618 Start
+            if(String.valueOf(link.LinkedEntityId).startsWith(System.Label.OppSpecialApply)){
+                specIds.add(link.LinkedEntityId);
+            }
+            // LHJ CHAN-BCLD4P 20190618 End
+
+            // MZY SWAG-BXXBKA  2021-02-19 start 
+            if(String.valueOf(link.LinkedEntityId).startsWith('a3E')){
+                opdIds.add(link.LinkedEntityId);
+                opdMap.put(link.LinkedEntityId,version.Title);
+             }
+            // MZY SWAG-BXXBKA  2021-02-19 end
+
+            if(String.valueOf(link.LinkedEntityId).startsWith('a3Z')){
+                oFOrderIds.add(link.LinkedEntityId);
+                oFOrderIdMap.put(link.LinkedEntityId,true);
+            }
+
+            //2023-2-10  sx澶囧搧 澶囧搧妫�娴嬪垎鏋愭姤鍛� start
+            Id cid = link.LinkedEntityId;
+            String parentLabel = cid.getSObjectType().getDescribe().getName();
+            if(parentLabel.equals('Rental_Apply_Fault__c')){
+                rentalApplyFaultIds.add(link.LinkedEntityId);
+                if(trentalImages.containskey(link.LinkedEntityId)){
+                    trentalImages.get(link.LinkedEntityId).add(version.Id);
+                }else{
+                    List<Id> temp = new List<Id>();
+                    temp.add(version.Id);
+                    trentalImages.put(link.LinkedEntityId,temp);
+                }
+            }
+            //2023-2-10  sx澶囧搧 澶囧搧妫�娴嬪垎鏋愭姤鍛� end
+        }
+    }
+
+    if (Trigger.isAfter && Trigger.isDelete) {
+        for (ContentDocumentLink link : Trigger.old) {
+            if (String.valueOf(link.LinkedEntityId).startsWith('001')) {
+                accIds.add(link.LinkedEntityId);
+            }
+            // LHJ CHAN-BCLD4P 20190618 Start
+            if(String.valueOf(link.LinkedEntityId).startsWith(System.Label.OppSpecialApply)){
+                specIds.add(link.LinkedEntityId);
+            }
+            // LHJ CHAN-BCLD4P 20190618 End
+            //20221014 yc 鍖婚櫌瀹℃壒浼樺寲 start
+            if (String.valueOf(link.LinkedEntityId).startsWith('a5C') || String.valueOf(link.LinkedEntityId).startsWith('a5A')) {
+                accAppIds.add(link.LinkedEntityId);
+            }
+            //20221014 yc 鍖婚櫌瀹℃壒浼樺寲 end
+        }
+    }
+
+    
+    //2023-2-10  sx澶囧搧 澶囧搧妫�娴嬪垎鏋愭姤鍛� start
+    if(rentalApplyFaultIds.size() > 0){
+        List<Rental_Apply_Fault__c> renList = [SELECT Id,AttachmentId1__c,AttachmentId2__c from Rental_Apply_Fault__c where Id in :rentalApplyFaultIds];
+
+        system.debug('updrentalApplyFaultList====='+renList);
+        for(Rental_Apply_Fault__c ren : renList){
+            if(trentalImages.containskey(ren.Id)){ 
+                if (ren.AttachmentId1__c == null) {
+                    ren.AttachmentId1__c = trentalImages.get(ren.id)[0];
+                } else if(ren.AttachmentId2__c == null) {
+                    ren.AttachmentId2__c = trentalImages.get(ren.id)[0];
+                }
+            }
+        }
+        system.debug('updrentalApplyFaultList====='+renList);
+        UPDATE renList;
+    }
+
+    if(rentaldeleteApplyFaultIds.size() > 0){
+        List<Rental_Apply_Fault__c> renList = [SELECT Id,AttachmentId1__c,AttachmentId2__c from Rental_Apply_Fault__c where Id in :rentaldeleteApplyFaultIds];
+
+        system.debug('renList====='+renList);
+        for(Rental_Apply_Fault__c ren : renList){
+            if(deleteImages.containskey(ren.Id)){
+
+                if(deleteImages.get(ren.Id).contains(ren.AttachmentId1__c)){
+                    ren.AttachmentId1__c = '';
+                }
+                if(deleteImages.get(ren.Id).contains(ren.AttachmentId2__c)){
+                    ren.AttachmentId2__c = '';
+                }
+            }
+        }
+        system.debug('renList====='+renList);
+        UPDATE renList;
+    }
+    //2023-2-10  sx澶囧搧 澶囧搧妫�娴嬪垎鏋愭姤鍛� end
 
 
+    if (rentaldelIds.size() > 0) {
+        List<Consumable_accessories_invoice__c> rentaldelList = new List<Consumable_accessories_invoice__c>();
+        for (Consumable_accessories_invoice__c ra : [select Id from Consumable_accessories_invoice__c where Invoice_code__c in :rentaldelIds and Attachment_ID__c in :attdelIds]) {
+            rentaldelList.add(ra);
+        }
+        ControllerUtil.delConsumableAccessoriesInvoiceSet(rentaldelList);
+    }
+    
     if (rentalIds.size() > 0) {
         List<Consumable_order__c> rentalList = new List<Consumable_order__c>();
-        for (Consumable_order__c ra : [SELECT Id FROM Consumable_order__c WHERE Id IN :rentalIds]) {
+        for (Consumable_order__c ra : [select Id from Consumable_order__c where Id in :rentalIds]) {
             ra.Consumable_pdf_insert_day__c = Date.today();
             ra.Order_Attachment__c = attIds[0];
+            //ra.Order_status__c = '褰曞叆瀹屾垚';
+            //ra.Contract_pdf_updated__c = true;
             rentalList.add(ra);
         }
-        System.debug('rentalList = ' + rentalList);
         ControllerUtil.updRentalApplyList(rentalList);
     }
-    // if (Trigger.isInsert && Trigger.isAfter && StaticParameter.ContentDocumentLink) {
-    //     AttachmentReQisHandler handler = new AttachmentReQisHandler();
-    //     handler.run();
-    // }
+     if (rentalApplyIds.size() > 0) {
+        List<Rental_Apply__c> rentalApplyList = new List<Rental_Apply__c>();
+        for (Rental_Apply__c ra : [select Id from Rental_Apply__c where Id in :rentalApplyIds]) {
+            ra.Contract_pdf_update_day__c = Date.today();
+            ra.Contract_pdf_updated__c = true;
+            rentalApplyList.add(ra);
+        }
+        ControllerUtil.updRentalApplyList(rentalApplyList);
+    }
 
-    // if (rentaldelIds.size() > 0) {
-    //     List<Consumable_accessories_invoice__c> rentaldelList = new List<Consumable_accessories_invoice__c>();
-    //     for (Consumable_accessories_invoice__c ra : [
-    //         SELECT Id
-    //         FROM Consumable_accessories_invoice__c
-    //         WHERE Invoice_code__c IN :rentaldelIds AND Attachment_ID__c IN :attdelIds
-    //     ]) {
-    //         rentaldelList.add(ra);
-    //     }
-    //     System.debug('rentaldelList = ' + rentaldelList);
-    //     ControllerUtil.delConsumableAccessoriesInvoiceSet(rentaldelList);
-    // }
+    if (accIds.size() > 0) {
+        Map<String, String> attMap = new Map<String, String>();
+        // List<Attachment> attList = [select Id, ParentId from Attachment where ParentId = :accIds order by ParentId];
+        List<ContentDocumentLink> linkList = [select LinkedEntityId from ContentDocumentLink where LinkedEntityId =: accIds order by LinkedEntityId];
+        for (ContentDocumentLink link : linkList) {
+            attMap.put(link.LinkedEntityId, link.LinkedEntityId);
+        }
+        List<Account> updAccList = new List<Account>();
+
+        //20221207 lt 鍖婚櫌瀹℃壒浼樺寲 start
+        List<Account> accList = [select id,Name,
+                                                         Is_Active__c
+                                               from Account
+                                               where id in:accIds ];
+        //20221207 lt 鍖婚櫌瀹℃壒浼樺寲 end
+
+        for (String accid : accIds) {
+            if(accList.size() > 0){
+                // Account acc = new Account(Id = accid);
+                //20221207 lt 鍖婚櫌瀹℃壒浼樺寲 start
+                for(Account acc : accList){                    
+                    if(Trigger.isDelete && (Trigger.isAfter)){
+                        for(ContentDocumentLink link : Trigger.old){
+                            // if(attMap.containsKey(att.ParentID) && acc.Is_Active__c != '鑽夋涓�'){
+                            if(acc.Is_Active__c != '鑽夋涓�'){
+                                link.addError('闈炶崏妗堜腑锛岄檮浠朵笉鍏佽鍒犻櫎銆�');
+                
+                                return;
+                            }
+                        }
+                    }
+                    acc.Is_upload_file__c = attMap.containsKey(accid);
+                    updAccList.add(acc);
+                }
+            }
+            //20221207 lt 鍖婚櫌瀹℃壒浼樺寲 end
+        }
+
+        // for (String accid : accIds) {
+        //     Account acc = new Account(Id = accid);
+        //     acc.Is_upload_file__c = attMap.containsKey(accid);
+        //     updAccList.add(acc);
+        // }
+        if (updAccList.size() > 0) update updAccList;
+    }
+
+    //20221014 yc 鍖婚櫌瀹℃壒浼樺寲 start
+    if (accAppIds.size() > 0) {
+        Map<String, String> attMap = new Map<String, String>();
+        // List<Attachment> attList = [select Id, ParentId from Attachment where ParentId = :accAppIds order by ParentId];
+        List<ContentDocumentLink> linkList = [select LinkedEntityId from ContentDocumentLink where LinkedEntityId =: accAppIds order by LinkedEntityId];
+        for (ContentDocumentLink link : linkList) {
+            attMap.put(link.LinkedEntityId, link.LinkedEntityId);
+        }
+        List<Account_Delay_Apply__c> updAccAppList = new List<Account_Delay_Apply__c>();
+        
+        //20221207 lt 鍖婚櫌瀹℃壒浼樺寲 start
+        List<Account_Delay_Apply__c> adaList = [select id,Name,
+                                                         Is_Active__c
+                                               from Account_Delay_Apply__c 
+                                               where id in:accAppIds ];
+        //20221207 lt 鍖婚櫌瀹℃壒浼樺寲 end
+
+        for (String accappid : accAppIds) {
+            if(adaList.size() > 0){
+                // Account_Delay_Apply__c accapp = new Account_Delay_Apply__c(Id = accappid);
+                //20221207 lt 鍖婚櫌瀹℃壒浼樺寲 start
+                
+                for(Account_Delay_Apply__c accapp : adaList){                    
+                    accapp.Is_upload_file__c = attMap.containsKey(accappid);
+                    updAccAppList.add(accapp);
+                }
+                
+            }
+            
+            //20221207 lt 鍖婚櫌瀹℃壒浼樺寲 end
+            
+        }
+        if (updAccAppList.size() > 0) update updAccAppList;
+    }
+    //20221014 yc 鍖婚櫌瀹℃壒浼樺寲 end
+
+    // LHJ CHAN-BCLD4P 20190618 Start
+    if (specIds.size() > 0) {
+        
+        Map<String, String> attMap = new Map<String, String>();
+        // List<Attachment> attList = [select Id, ParentId from Attachment where ParentId = :specIds order by ParentId];
+        List<ContentDocumentLink> linkList = [select LinkedEntityId from ContentDocumentLink where LinkedEntityId =: specIds order by LinkedEntityId];
+        for (ContentDocumentLink link : linkList) {
+            attMap.put(link.LinkedEntityId, link.LinkedEntityId);
+        }
+        List<OpportunitySpecialApply__c> updSpecList = new List<OpportunitySpecialApply__c>();
+        for (String specId : specIds) {
+            OpportunitySpecialApply__c spec = new OpportunitySpecialApply__c(Id = specId);
+            spec.Is_upload_file__c = attMap.containsKey(specId);
+            updSpecList.add(spec);
+        }
+        if (updSpecList.size() > 0) update updSpecList;
+    }
+    // LHJ CHAN-BCLD4P 20190618 End
+    
+    // MZY SWAG-BXXBKA  2021-02-19 start
+    System.debug('SWAG-BXXBKA start');
+    if (opdIds.size()>0) {
+        List<OPDPlan__c> updateOPDs = new List<OPDPlan__c>();
+
+        OPDPlan__c tempOPD = new OPDPlan__c();
+        for (String i :opdIds ) {
+            tempOPD.id = i;
+            tempOPD.AttachmentCertificate__c = opdMap.get(i);
+            updateOPDs.add(tempOPD);
+        }
+        System.debug('涓存椂OPD :'+tempOPD);
+        if (updateOPDs.size()>0){
+            update updateOPDs;
+        }
+    }
+    System.debug('SWAG-BXXBKA end');
+    // MZY SWAG-BXXBKA  2021-02-19 end
+
+    if(OpporFileIds.size()>0){
+        List<Opportunity_File__c> OpporList = [select id,Last_upload_time__c,
+                                                            Is_Locked__c,
+                                                            Last_upload_user__c,
+                                                            Stock_apply_time__c
+                                                        from Opportunity_File__c 
+                                                        where id 
+                                                        in:OpporFileIds ];
+        if(OpporList.size()>0){
+            for(Opportunity_File__c ofc : OpporList){
+                if(!ofc.Is_Locked__c){
+                    ofc.Last_upload_user__c = UserInfo.getUserId();
+                    ofc.Last_upload_time__c = System.now();
+                    System.debug(ofc+'23333');
+                }else{
+                    OpporFileUndeleteMap.put(ofc.id,ofc.id);
+                    System.debug(ofc+'23333444444');
+                }
+            }
+            update OpporList;
+        }
+    }
+    System.debug(Trigger.isDelete+'Trigger.isDelete');
+    System.debug(Trigger.isBefore+'Trigger.isBefore');
+   
+    if(Trigger.isDelete && Trigger.isAfter){
+        for(ContentDocumentLink link : Trigger.old){
+            if(OpporFileUndeleteMap.containsKey(link.LinkedEntityId)){
+                link.addError('澶囪揣宸插鎵癸紝涓嶅彲鍒犻櫎闄勪欢');
+                return;
+            }else{
+                DeleteReIds.add(link.LinkedEntityId);
+            }
+        }
+    }
+    
+
+    if(Trigger.isInsert){
+        for(ContentDocumentLink link : Trigger.new){
+            if(OpporFileUndeleteMap.containsKey(link.LinkedEntityId)){
+                ContentDocument doc = [select Id from ContentDocument where Id =: link.ContentDocumentId];
+                doc.addError('澶囪揣宸插鎵癸紝涓嶅彲鍒犻櫎闄勪欢');
+                // link.addError('澶囪揣宸插鎵癸紝涓嶅彲鍒犻櫎闄勪欢');
+
+                return;
+            }else{
+                DeleteReIds.add(link.LinkedEntityId);
+            }
+        }
+    }
+
+    // List<Attachment> atcList = [select id,ParentId,createddate,createdbyid from Attachment where ParentId in:DeleteReIds];
+    List<ContentDocumentLink> linkList = [select ContentDocumentId from ContentDocumentLink where LinkedEntityId in:DeleteReIds];
+    List<Id> idList = new List<Id>();
+    for (ContentDocumentLink link : linkList) {
+        idList.add(link.ContentDocumentId);
+    }
+    List<ContentDocument> docList = [select Id,ArchivedDate,ArchivedById from ContentDocument where Id =: idList];
+    System.debug(DeleteReIds+'222222222222');
+    if(docList.size()>0){
+        for(String ids : DeleteReIds){
+            for(ContentDocument doc : docList){
+                if(OppordeleteReTimeMap.containsKey(ids)){
+                    if(doc.ArchivedDate > OppordeleteReTimeMap.get(ids)){
+                        OppordeleteReTimeMap.put(ids,doc.ArchivedDate);
+                        OppordeleteReUserMap.put(ids,doc.ArchivedById);
+                    }else{
+                        continue;
+                    }
+                }else{
+                    OppordeleteReTimeMap.put(ids,doc.ArchivedDate);
+                    OppordeleteReUserMap.put(ids,doc.ArchivedById);
+                }
+            }
+        }
+
+
+        List<Opportunity_File__c> reDateList = [select id,Last_upload_time__c,
+                                                                Is_Locked__c,
+                                                                Last_upload_user__c
+                                                            from Opportunity_File__c 
+                                                            where id 
+                                                            in:DeleteReIds ];
+        if(reDateList.size()>0){
+            for(Opportunity_File__c ofc : reDateList){
+                ofc.Last_upload_time__c = OppordeleteReTimeMap.get(ofc.id);
+                ofc.Last_upload_user__c = OppordeleteReUserMap.get(ofc.id);
+                System.debug(ofc+'233333333');
+            }
+            update reDateList;
+        }
+    }else{
+        List<Opportunity_File__c> reDateList = [select id,Last_upload_time__c,
+                                                                Is_Locked__c,
+                                                                Last_upload_user__c
+                                                            from Opportunity_File__c 
+                                                            where id 
+                                                            in:DeleteReIds ];
+        if(reDateList.size()>0){
+            for(Opportunity_File__c ofc : reDateList){
+                if (!ofc.Is_Locked__c) {
+                    ofc.Last_upload_time__c = null;
+                    ofc.Last_upload_user__c = null;
+                    update reDateList;
+                }
+                
+            }
+        }
+    }
+
+    //CHAN-BCNCRB ---XHL----Start-----
+    if (opportunity_FileIds.size() > 0) {
+        List<Opportunity_File__c> opporList = [select id,Last_upload_time__c,
+                                                            Is_Locked__c,
+                                                            Last_upload_user__c,
+                                                            Stock_apply_time__c,
+                                                            Oppor_File_Stage__c
+                                                        from Opportunity_File__c 
+                                                        where id in:opportunity_FileIds And Oppor_File_Stage__c = 'G'];
+        List<String>  ofIds = new  List<String>();                                              
+        if (opporList.size() > 0) {
+
+            for (Opportunity_File__c oppf : opporList) {
+                ofIds.add(oppf.Id);
+            }
+
+            if (ofIds.size() > 0 ) {
+                //  List<Attachment> atcList = [select id,ParentId,createddate,createdbyid from Attachment where ParentId in:ofIds];
+                List<ContentDocumentLink> linkList = [select ContentDocumentId from ContentDocumentLink where LinkedEntityId in:ofIds];
+
+                List<Id> idList = new List<Id>();
+                for (ContentDocumentLink link : linkList) {
+                    idList.add(link.ContentDocumentId);
+                }
+                List<ContentDocument> docList = [select Id from ContentDocument where Id in: idList];
+                if (docList.size() > 0) {
+                    delete docList;
+                }
+            }
+           
+            
+        }
+    }
+    //CHAN-BCNCRB ---XHL----End-----
+    
+
+    if (opportunityFileOrderIds.size() > 0) {
+        List<OpportunityFileOrder__c> ofoList = [select id,
+                                                            OpporFileStage__c
+                                                        from OpportunityFileOrder__c 
+                                                        where Id in:opportunityFileOrderIds And OpporFileStage__c = 'G'];
+        List<String>  ofoIds = new  List<String>();                                              
+        if (ofoList.size() > 0) {
+
+            for (OpportunityFileOrder__c ofo : ofoList) {
+                ofoIds.add(ofo.Id);
+            }
+
+            if (ofoIds.size() > 0 ) {
+                //  List<Attachment> atcList = [select id,ParentId,createddate,createdbyid from Attachment where ParentId in:ofoIds];
+                List<ContentDocumentLink> linkList = [select ContentDocumentId from ContentDocumentLink where LinkedEntityId in:ofoIds];
+
+                List<Id> idList = new List<Id>();
+                for (ContentDocumentLink link : linkList) {
+                    idList.add(link.ContentDocumentId);
+                }
+                List<ContentDocument> docList = [select Id from ContentDocument where Id in: idList];
+                if (docList.size() > 0) {
+                    delete docList;
+                }
+            }
+           
+            
+        }
+    }
+
+    if (oFOrderIdMap.size() > 0) {
+
+        List<OpportunityFileOrder__c> oFOrderList = [select Id,Name,LatestUploadUser__c,LatestUploadTime__c
+                                                    from OpportunityFileOrder__c 
+                                                    where Id In : oFOrderIdMap.keySet()];
+        if (oFOrderList.size() > 0 ) {
+
+            for (OpportunityFileOrder__c oFOrder :oFOrderList) {
+
+                if (oFOrderIdMap.get(oFOrder.Id)) {
+                    oFOrder.LatestUploadUser__c = UserInfo.getUserId();
+                    oFOrder.LatestUploadTime__c = System.now();
+                } else if (oFOrderIdMap.get(oFOrder.Id) == false){
+                    oFOrder.LatestUploadUser__c = null;
+                    oFOrder.LatestUploadTime__c = null;
+                }
+            }
+
+            update oFOrderList;
+
+        }                                            
+    }
+    // DB202304087063 SFDC绯荤粺闄勪欢涓婁紶鑷姩閫氱煡鍔熻兘寮�鍙戦渶姹� start
+    if (Trigger.isInsert && Trigger.isAfter && false) {
+        AttachmentReQisHandler handler = new AttachmentReQisHandler();
+        handler.run();
+    }
+    // DB202304087063 SFDC绯荤粺闄勪欢涓婁紶鑷姩閫氱煡鍔熻兘寮�鍙戦渶姹� end
+
+
+
+
+
+
+
+
+    
 }
\ No newline at end of file

--
Gitblit v1.9.1