From dec96e2f8b84ea04d773c0c520c39b0822912ee3 Mon Sep 17 00:00:00 2001 From: D C <chenbangcai@prec-tech.com> Date: 星期五, 26 五月 2023 10:32:20 +0800 Subject: [PATCH] Merge branch 'master' of http://47.92.229.245:8089/r/OlyMEBG --- force-app/main/default/triggers/AttachmentTrigger.trigger | 88 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 88 insertions(+), 0 deletions(-) diff --git a/force-app/main/default/triggers/AttachmentTrigger.trigger b/force-app/main/default/triggers/AttachmentTrigger.trigger index caec12f..06312aa 100644 --- a/force-app/main/default/triggers/AttachmentTrigger.trigger +++ b/force-app/main/default/triggers/AttachmentTrigger.trigger @@ -10,6 +10,13 @@ List<String> specDelIds = new List<String>(); // LHJ CHAN-BCLD4P 20190618 End + // 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 澶囧搧鍊熷嚭鐢宠鏁呴殰鎶ュ憡闄勪欢鎻愬彇 + // MZY SWAG-BXXBKA 2021-02-19 start List<String> opdIds = new List<String>(); Map<String,String> opdMap = new Map<String,String>(); @@ -72,9 +79,26 @@ oFOrderIds.add(att.ParentId); oFOrderIdMap.put(att.ParentId,true); } + + //2023-2-10 sx澶囧搧 澶囧搧妫�娴嬪垎鏋愭姤鍛� start + Id cid = att.ParentId; + String parentLabel = cid.getSObjectType().getDescribe().getName(); + if(parentLabel.equals('Rental_Apply_Fault__c')){ + rentalApplyFaultIds.add(att.ParentId); + if(trentalImages.containskey(att.ParentId)){ + trentalImages.get(att.ParentId).add(att.Id); + }else{ + List<Id> temp = new List<Id>(); + temp.add(att.Id); + trentalImages.put(att.ParentId,temp); + } + } + //2023-2-10 sx澶囧搧 澶囧搧妫�娴嬪垎鏋愭姤鍛� end } } + if (Trigger.isBefore && Trigger.isDelete) { + List<Attachment> attDeleteList = new List<Attachment>(); for (Attachment att : Trigger.old) { //if (att.Name.toUpperCase() == '鍚堝悓涔�.PDF' && String.valueOf(att.ParentId).startsWith('a0t')) { // 娣讳粯銇椼仧濂戠磩鏇搞伄銉曘偂銈ゃ儷鍚嶃伅鎸囧畾銇с亶銇亜 @@ -94,7 +118,34 @@ oFOrderIds.add(att.ParentId); oFOrderIdMap.put(att.ParentId,false); } + + //2023-2-10 sx澶囧搧 澶囧搧妫�娴嬪垎鏋愭姤鍛� start + Id cid = att.ParentId; + String parentLabel = cid.getSObjectType().getDescribe().getName(); + if(parentLabel.equals('Rental_Apply_Fault__c')){ + rentaldeleteApplyFaultIds.add(att.ParentId); + attDeleteList.add(att); + if(deleteImages.containskey(att.ParentId)){ + deleteImages.get(att.ParentId).add(att.Id); + }else{ + List<Id> temp = new List<Id>(); + temp.add(att.Id); + deleteImages.put(att.ParentId,temp); + } + } + //2023-2-10 sx澶囧搧 澶囧搧妫�娴嬪垎鏋愭姤鍛� end } + + //2023-2-10 sx澶囧搧 澶囧搧妫�娴嬪垎鏋愭姤鍛� start + List<Rental_Apply_Fault__c> rafList = [SELECT Id, Name FROM Rental_Apply_Fault__c WHERE Id IN: rentaldeleteApplyFaultIds AND (status__c = '宸插彂閫�' OR status__c = '宸插弽棣�')]; + for (Rental_Apply_Fault__c raf : rafList) { + for (Attachment att : attDeleteList) { + if (att.ParentId == raf.Id) { + att.addError('闈炶崏妗堜腑鐨勬娴嬪垎鏋愭姤鍛婁笉鍏佽鍒犻櫎宸蹭笂浼犵殑鏁呴殰鍥剧墖'); + } + } + } + //2023-2-10 sx澶囧搧 澶囧搧妫�娴嬪垎鏋愭姤鍛� end } if (Trigger.isAfter && Trigger.isDelete) { for (Attachment att : Trigger.old) { @@ -139,6 +190,43 @@ ControllerUtil.updRentalApplyList(rentalApplyList); } + + 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; + } + 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]; -- Gitblit v1.9.1