From fc8a8cea62e5d248834482a1ade9db6ab0758bf2 Mon Sep 17 00:00:00 2001
From: Li Jun <buli@deloitte.com.cn>
Date: 星期日, 24 四月 2022 18:55:04 +0800
Subject: [PATCH] 20220424FixIssue

---
 force-app/main/default/classes/ContactTriggerHandler.cls |  147 +++++++++++++++++++++++++++++++------------------
 1 files changed, 93 insertions(+), 54 deletions(-)

diff --git a/force-app/main/default/classes/ContactTriggerHandler.cls b/force-app/main/default/classes/ContactTriggerHandler.cls
index c7cf9af..3c3c299 100644
--- a/force-app/main/default/classes/ContactTriggerHandler.cls
+++ b/force-app/main/default/classes/ContactTriggerHandler.cls
@@ -13,7 +13,9 @@
         this.oldList = (List < Contact > ) Trigger.old;
     }
     protected override void beforeInsert() {
-        mobileNumberVerification();
+        if(Test.isRunningTest()||UserInfo.getUserId()!=System.Label.ByPassTrigger){ //Add by Li Jun for PIPL 20220331
+            mobileNumberVerification();
+        }
     }
 
     protected override void afterInsert() {
@@ -26,8 +28,8 @@
         syncToAgencyContact();
         updateDealerNum();
         sendToComPlat();
-
     }
+
     protected override void beforeUpdate() {
         // 鏈嶅姟鎶�甯� 2018/12/24  Start
         UpdateProcessingWork();
@@ -138,13 +140,41 @@
                         //                        )
                     )
                 ) {
-                    Agency_Contact__c acObj = new Agency_Contact__c(Agency_ID__c = '000000000000000', Contact__c = nObj.Id, ContactId18__c = nObj.Id, Agency_Hospital__c = null, Name = nObj.LastName + ((String.isBlank(nObj.FirstName) == false) ? ' ' + nObj.FirstName : ''), Department_Class__c = nObj.Strategic_dept_Class__c, Type__c = nObj.Type__c, Doctor_Division1__c = nObj.Doctor_Division1__c);
+                    //Agency_Contact__c acObj = new Agency_Contact__c(Agency_ID__c = '000000000000000', Contact__c = nObj.Id, ContactId18__c = nObj.Id, Agency_Hospital__c = null, Name = nObj.LastName + ((String.isBlank(nObj.FirstName) == false) ? ' ' + nObj.FirstName : ''), Department_Class__c = nObj.Strategic_dept_Class__c, Type__c = nObj.Type__c, Doctor_Division1__c = nObj.Doctor_Division1__c);
+                    Agency_Contact__c acObj = new Agency_Contact__c(
+                        Agency_ID__c = '000000000000000', 
+                        Contact__c = nObj.Id, 
+                        ContactId18__c = nObj.Id, 
+                        Agency_Hospital__c = null, 
+                        Name = nObj.LastName,
+                        Name_Encrypted__c = nObj.LastName_Encrypted__c,
+                        Department_Class__c = nObj.Strategic_dept_Class__c, 
+                        Type__c = nObj.Type__c,
+                        Type_Encrypted__c = nObj.Type_Encrypted__c,
+                        Doctor_Division1__c = nObj.Doctor_Division1__c,
+                        Doctor_Division1_Encrypted__c = nObj.Doctor_Division1_Encrypted__c
+                    );
                     targetContactMap.put(nObj.Id, acObj);
                 }
             }
         }
         if (targetContactMap.size() > 0) {
-            upsert targetContactMap.values() ContactId18__c;
+            List<Agency_Contact__c> temp = targetContactMap.values();
+            upsert temp ContactId18__c;
+            system.debug('temp='+temp);
+            EncryptInsert(temp);
+        }
+    }
+    
+    static void EncryptInsert(List<Agency_Contact__c> aclist){
+        if(!(system.isFuture() || system.isBatch())){
+            AwsServiceTool2.EncryptPushFuture(Json.serialize(aclist), 'Agency_Contact__c');
+        }else{
+            //Add By Li Jun for sync agency contact to aws 20220424 start
+            if(!Test.isRunningTest()){
+                SyncAccountContactToAWS.assignOnceOneMinuteLater();
+            }
+            //Add By Li Jun for sync agency contact to aws 20220424 end
         }
     }
 
@@ -223,19 +253,19 @@
     //鏇存柊缁忛攢鍟嗙敤鎴蜂汉鏁板瓧娈� 绮剧悽鎶�鏈� pk 2021-08-26 end
     
     // 鎵嬫満鍙峰幓閲嶅強瑙勫垯楠岃瘉 鍙婃柊澧炲鎴蜂汉鍛橀噸鍚嶉獙璇�
-    public  void mobileNumberVerification(){
+    public void mobileNumberVerification(){
 
         Pattern pattern = Pattern.compile('^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$');
         Map<String, Map<String,Contact>> accountContactMap = new Map<String, Map<String,Contact>>();
         Set<Id> accountIdSet = new Set<Id>();
         //鐢ㄦ埛瀵硅薄涓婃壘瀵瑰簲鐨勮仈绯讳汉
-        List<User> userList=[select ID,ContactID from User where ContactID != null];
-        Map<String,User> userMap= new Map<String,User>();
-        if (userList.size()>0){
-            for(User us1: userList){
-                userMap.put(us1.ContactId, us1);
-            }
-        } 
+        // List<User> userList=[select ID,ContactID from User where ContactID != null];
+        // Map<String,User> userMap= new Map<String,User>();
+        // if (userList.size()>0){
+        //     for(User us1: userList){
+        //         userMap.put(us1.ContactId, us1);
+        //     }
+        // }
         //鏌ユ壘鑱旂郴浜哄璞′笂瀵瑰簲鐨勬湁鏁堝鎴凤紱鍖婚櫌鐩存帴浣跨敤鏈夋晥/鏃犳晥瀛楁銆佺粡閿�鍟嗕娇鐢ㄦ湁鏁�/鏃犳晥鍏紡瀛楁
         List<String> accIdList = new List<String>();
         Map<String,String> accMap= new Map<String,String>();
@@ -256,32 +286,38 @@
                 }
             }
         }
-        for (Contact contactnew: newList) {
-            // 鎵嬫満鍙� 鏈夊�� 骞朵笖 鑱旂郴浜烘湁鏁� 鑱旂郴浜虹殑瀹㈡埛鏈夋晥 鏃犲閮ㄥ叧鑱旂敤鎴� 杩涜鎵嬫満鍙风爜楠岃瘉
-            if (String.isNotBlank(contactnew.MobilePhone) && ('鏈夋晥'.equals(contactnew.Isactive__c) ||'鏈夊姽'.equals(contactnew.Isactive__c))
-                && '鏈夊姽'.equals(accMap.get(contactnew.AccountId))
-                && !userMap.containsKey(contactnew.Id)
-                ) {
-                Matcher isMobilePhone = pattern.matcher(contactnew.MobilePhone);
-                if (isMobilePhone.matches()) {
-                    // 灏嗘墜鏈哄彿 璧嬪�肩粰 鎵嬫満鍙峰敮涓�瀛楁
-                    contactnew.UniqueNumber__c = contactnew.MobilePhone;
-                } else {
-                    // 鎵嬫満鍙峰敮涓�瀛楁娓呯┖
-                    contactnew.UniqueNumber__c = null;
-                }    
-            } else {
-                // 鎵嬫満鍙� 鏃犲�� 鎴栬�� 鑱旂郴浜轰笉鏄湁鏁� 鎵嬫満鍙峰敮涓�瀛楁娓呯┖
-                contactnew.UniqueNumber__c = null;
+        //鎵嬫満鍙峰敮涓�鏍¢獙-鍖婚櫌涓嬫柊寤哄鎴蜂汉鍛樻牎楠屼娇鐢ㄥ姞瀵嗘墜鏈哄彿,缁忛攢鍟嗕娇鐢ㄦ櫘閫氭墜鏈哄彿 thh 20220328 start
+        ID DoctorRecordTypeId = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('Doctor').getRecordTypeId();
+        ID AgencyRecordTypeId = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId();
+        for (Contact contactnew : newList) {
+            // 鎵嬫満鍙锋湁鍊煎苟涓旇仈绯讳汉鏈夋晥锛岃仈绯讳汉鐨勫鎴锋湁鏁堬紝杩涜鎵嬫満鍙风爜楠岃瘉
+            if (('鏈夋晥'.equals(contactnew.Isactive__c) || '鏈夊姽'.equals(contactnew.Isactive__c))
+                && ('鏈夊姽'.equals(accMap.get(contactnew.AccountId)) || '鏈夋晥'.equals(accMap.get(contactnew.AccountId)))) {
+                if(AgencyRecordTypeId.equals(contactnew.RecordTypeId)){
+                    if(String.isNotBlank(contactnew.MobilePhone)){
+                        Matcher isMobilePhone = pattern.matcher(contactnew.MobilePhone);
+                        if (isMobilePhone.matches()) {
+                            contactnew.UniqueNumber__c = contactnew.MobilePhone;
+                        } else {
+                            // 鎵嬫満鍙峰敮涓�瀛楁娓呯┖
+                            contactnew.UniqueNumber__c = null;
+                        }
+                    } else {
+                        contactnew.UniqueNumber__c = null;
+                    }
+                } else if(DoctorRecordTypeId.equals(contactnew.RecordTypeId)){
+                    if(String.isNotBlank(contactnew.MobilePhone_Encrypted__c)){
+                        contactnew.UniqueNumber__c = contactnew.MobilePhone_Encrypted__c;
+                    } else {
+                        contactnew.UniqueNumber__c = null;
+                    }
+                }
             }
-            
-
-
             if (Trigger.isInsert) {
-                accountIdSet.add(contactnew.AccountId);
-                
+                accountIdSet.add(contactnew.AccountId);  
             }   
         }
+        //鎵嬫満鍙峰敮涓�鏍¢獙-鍖婚櫌涓嬫柊寤哄鎴蜂汉鍛樻牎楠屼娇鐢ㄥ姞瀵嗘墜鏈哄彿,缁忛攢鍟嗕娇鐢ㄦ櫘閫氭墜鏈哄彿 thh 20220328 end
         // 鏂板鑱旂郴浜烘椂锛�
         if (accountIdSet.size() > 0) {
             List<Contact> contactList = [SELECT Id,AccountId,FullName__c,LastName,FirstName,Account.Name,CManageCode__c,IsFromSPO__c,
@@ -334,17 +370,13 @@
                 
             }   
         }
-
-        
     }
-
-
     public static Map<Id,Id> NFM606_IdMap = new Map<Id,Id>();
+    // 606鎺ュ彛璋冪敤闂淇 thh 20220330 start
     private void sendToComPlat() {
         List<Id> contactIdList = new List<Id>();
-        List<String>    interfaceUserUpsertContact = new List<String>();
+        List<String> interfaceUserUpsertContact = new List<String>();
         for (Contact local: newList) {
-
             Contact old = null;
             if (Trigger.isUpdate) {
                 old = oldMap.get(local.Id);
@@ -371,10 +403,16 @@
                         || old.ContactType__c != local.ContactType__c//浜哄憳绫诲瀷
                         
                         ) {
-                if (!local.IsFromSPO__c && !'01210000000QtkyAAC'.equals(local.RecordTypeId)) {
-
+                //鑾峰彇瀹㈡埛浜哄憳鐨勮褰曠被鍨婭D thh 20220330 start
+                ID InternalStaffRecordTypeId = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('Internal_staff').getRecordTypeId();
+                ID DoctorRecordTypeId = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('Doctor').getRecordTypeId();
+                ID AgencyRecordTypeId = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId();
+                //鑾峰彇瀹㈡埛浜哄憳鐨勮褰曠被鍨婭D thh 20220330 end
+                System.debug('local.UnifiedI_Contact_ID__c1:' + local.UnifiedI_Contact_ID__c);
+                System.debug('local.MobilePhone1:' + local.MobilePhone);
+                if (!local.IsFromSPO__c && !InternalStaffRecordTypeId.equals(local.RecordTypeId)) {
                     // 鍖婚櫌 瀹㈡埛浜哄憳 缁熶竴骞冲彴缂栫爜鏈夊�� 鍙戦�� PO
-                    if ('01210000000QfWdAAK'.equals(local.RecordTypeId) && String.isNotBlank(local.UnifiedI_Contact_ID__c)) {
+                    if (DoctorRecordTypeId.equals(local.RecordTypeId) && String.isNotBlank(local.UnifiedI_Contact_ID__c)) {
                         if (!NFM606_IdMap.containsKey(local.Id)) {
                             if(UserInfo.getUserId().equals(System.Label.interfaceUserID)){
                                 interfaceUserUpsertContact.add(local.Id);
@@ -385,7 +423,7 @@
                         }
                     }
                     // 缁忛攢鍟� 瀹㈡埛浜哄憳 鎵嬫満鍙风爜鏈夊�� 鍙戦�� PO
-                    if ('01210000000QfWiAAK'.equals(local.RecordTypeId) && String.isNotBlank(local.MobilePhone)) {
+                    if (AgencyRecordTypeId.equals(local.RecordTypeId) && String.isNotBlank(local.MobilePhone)) {
                         if (!NFM606_IdMap.containsKey(local.Id)) {
                             if(UserInfo.getUserId().equals(System.Label.interfaceUserID)){
                                 interfaceUserUpsertContact.add(local.Id);
@@ -399,28 +437,29 @@
                 
             }
         }
-        
+        //606鏍囪
         if(!System.Test.isRunningTest()){
             // NFM606Controller.executeNotFuture('', contactIdList);
             if (contactIdList.size() > 0) {
                 // NFM606Controller.callout('', contactIdList);
                  //娣诲姞future 鍒ゆ柇 add for pipl  sushanhu 20220317 start
-                 if (!(System.isFuture()||System.isBatch())) {
-                    NFM606Controller.callout('', contactIdList);
-                }
+                // if (!(System.isFuture()||System.isBatch())) {
+                NFM606Controller.callout('', contactIdList);
+                // } else{
+                    // NFM606Controller.executeNotFuture('', contactIdList);
+                // }
                //娣诲姞future 鍒ゆ柇 add for pipl  sushanhu 20220317 end 
             }
             if (interfaceUserUpsertContact.size() > 0) {
-                // NFM606Controller.executeNotFuture('', interfaceUserUpsertContact);
+                NFM606Controller.executeNotFuture('', interfaceUserUpsertContact);
                 //娣诲姞future 鍒ゆ柇 add for pipl  sushanhu 20220316 start
-                if (!(System.isFuture()||System.isBatch())) {
-                    NFM606Controller.executeNotFuture('', interfaceUserUpsertContact);
-                }
+                // if (!(System.isFuture()||System.isBatch())) {
+                    // NFM606Controller.executeNotFuture('', interfaceUserUpsertContact);
+                // }
                //娣诲姞future 鍒ゆ柇 add for pipl  sushanhu 20220316 end 
-               
             }
         } 
-        
     }
+    // 606鎺ュ彛璋冪敤闂淇 thh 20220330 end
 
 }
\ No newline at end of file

--
Gitblit v1.9.1