From bfca7a84bec815da594f1d12558535ed06d2490b Mon Sep 17 00:00:00 2001
From: 沙世明 <shashiming@prec-tech.com>
Date: 星期二, 13 九月 2022 09:57:32 +0800
Subject: [PATCH] 本地提交备份

---
 force-app/main/default/classes/RentalApplyTriggerHandler.cls |  118 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 115 insertions(+), 3 deletions(-)

diff --git a/force-app/main/default/classes/RentalApplyTriggerHandler.cls b/force-app/main/default/classes/RentalApplyTriggerHandler.cls
index 871a874..947c3f0 100644
--- a/force-app/main/default/classes/RentalApplyTriggerHandler.cls
+++ b/force-app/main/default/classes/RentalApplyTriggerHandler.cls
@@ -49,9 +49,11 @@
     }
     protected override void afterInsert() {
         // Check鏈儴鏄惁鍙互閫夋嫨
-        checkbenbu();
+        checkbenbu();// 20220909 ljh 鎭㈠浠g爜
         // 鍏变韩璁惧畾
         setShare();
+        
+        decryptInsert(newList);
     }
     protected override void beforeUpdate() {
         setManager();
@@ -64,7 +66,7 @@
 
     protected override void afterUpdate() {
         // Check鏈儴鏄惁鍙互閫夋嫨
-        checkbenbu();
+        checkbenbu();// 20220909 ljh 鎭㈠浠g爜
         cancelRa();
         // before 銇с伅鏁板紡闋呯洰銇宯ull銇牬鍚堛亴銇傘倞銇俱仚
         formulaToTextCheck();
@@ -458,7 +460,7 @@
             update raesList;
         }
     }
-
+    // 20220909 ljh 鎭㈠浠g爜
     private void checkbenbu() {
         for (Rental_Apply__c nObj : newList) {
             if (nObj.DataMigration_Flag__c == false) {
@@ -982,6 +984,116 @@
             RentalApplyTriggerHandler.doUnlockByFuture(raIdList);
         }
     }
+    
+    public static void decryptInsert(List<Rental_Apply__c> newList){
+        if(!system.isFuture()){
+            List<Rental_Apply__c> fendanList = new List<Rental_Apply__c>();
+            for(Rental_Apply__c ra : newList){
+                if(ra.Old_Rental_Apply__c != null){
+                    fendanList.add(ra);
+                }
+            }
+            
+            if(fendanList.size() == 0){
+                system.debug('no need split');
+                return;
+            }
+            
+           decryptInsertFuture(JSON.serialize(fendanList)); 
+        }
+    }
+    
+    @future(callout=true)
+    public static void decryptInsertFuture(string json_list){
+        decryptInsertCore(json_list);
+    }
+    
+    // List<Rental_Apply__c> temps = [select id,AWS_Data_Id__c,name, direct_shippment_address__c,  Direct_Shippment_Address_Encrypt__c, Phone_number__c,  Phone_Number_Encrypt__c,CreatedDate   from Rental_Apply__c where AWS_Data_Id__c != null order by CreatedDate desc limit 2];
+    public static void decryptInsertCore(string json_list){
+        system.debug('enter decryptInsertCore');
+        //璋冪敤婊ㄧ挏鎺ュ彛鏇存柊
+        PIHelper.PIIntegration staticResource =  PIHelper.getPIIntegrationInfo('Rental_Apply__c');
+        system.debug('staticResource.token='+staticResource.token);
+        if(String.isBlank(staticResource.token)){
+            System.debug('鑾峰彇aws token 澶辫触');
+            return;
+        }
+        List<Rental_Apply__c> newList = (List<Rental_Apply__c>)Json.deserialize(json_list, List<Rental_Apply__c>.class);
+        Map<Id,Rental_Apply__c> newMap = new Map<Id,Rental_Apply__c>(newList);
+        List<Map<string,object>> lmso = new List<Map<string,object>>();
+        for(Rental_Apply__c ra : newList){
+            Map<string,object> mso = new Map<string,object>();
+            
+            /*if(!string.isBlank(ra.AWS_Data_Id__c)){
+                continue;
+            }*/
+            for(PI_Field_Policy_Detail__c detail : staticResource.PIDetails){
+                if(ra.isSet(detail.SF_Field_API_Name__c)){
+                    mso.put(detail.AWS_Field_API__c,ra.get(detail.SF_Field_API_Name__c));
+                    mso.put(detail.AWS_Encrypted_Field_API__c,ra.get(detail.SF_Field_Encrypted_API__c));
+                }
+            }
+            mso.put('sfRecordId',ra.Id);
+            lmso.add(mso);
+        }
+        
+        if(lmso.size()==0){
+            system.debug('lmso.size()='+lmso.size());
+            return;
+        }
+        string payload = Json.serialize(lmso);
+        system.debug('payload='+payload);
+        String awsApi = staticResource.viewUnifiedContactUrl;
+        NFMUtil.response response = NFMUtil.sendToPiAWS(payload, awsApi,staticResource.token);
+        system.debug(response);
+        Map<string,object> res_obj = (Map<string,object>)Json.deserializeUntyped(response.responseBody);
+        if(res_obj == null || !res_obj.containsKey('object') ){
+            System.debug('res_obj == null || !res_obj.containsKey(\'object\')');
+            return;
+        }
+        
+        List<object> objList = (List<object>)res_obj.get('object');
+        if(objList == null){
+            System.debug('objList == null');
+            return;
+        }
+        
+        List<Rental_Apply__c> updateList = new List<Rental_Apply__c>();
+        for(object obj : objList){
+            Map<string,object> obj_map = (Map<string,object>)obj;
+            string sfRecordId = null;
+            string dataId = null;
+            if(obj_map.containsKey('sfRecordId')){
+                sfRecordId = string.valueOf(obj_map.get('sfRecordId'));
+            }else{
+                system.debug('obj_map.containsKey(\'sfRecordId\')='+obj_map.containsKey('sfRecordId'));
+                continue;
+            }
+            
+            if(obj_map.containsKey('dataId')){
+                dataId = string.valueOf(obj_map.get('dataId'));
+            }else{
+                system.debug('obj_map.containsKey(\'dataId\')='+obj_map.containsKey('dataId'));
+                continue;
+            }
+            
+            
+            if(newMap.containsKey(sfRecordId)){
+                Rental_Apply__c ra = newMap.get(sfRecordId);
+                ra.AWS_Data_Id__c = dataId;
+                updateList.add(ra);
+            }else{
+                system.debug('newMap.containsKey('+sfRecordId+')='+newMap.containsKey(sfRecordId));
+                continue;
+            }
+        }
+        
+        system.debug('updateList.size='+updateList.size());
+        if(updateList.size()>0){
+            update updateList;
+        }
+        
+    }
 
     @future
     public static void doUnlockByFuture(List<ID> idList) {

--
Gitblit v1.9.1