From dcd1d3017647f5f821b12be2328416d7c34617a3 Mon Sep 17 00:00:00 2001
From: buli <137736985@qq.com>
Date: 星期五, 09 六月 2023 11:34:47 +0800
Subject: [PATCH] backup0609

---
 force-app/main/default/classes/ContactTriggerHandler.cls | 1190 +++++++++++++++++++++++++++++++---------------------------
 1 files changed, 634 insertions(+), 556 deletions(-)

diff --git a/force-app/main/default/classes/ContactTriggerHandler.cls b/force-app/main/default/classes/ContactTriggerHandler.cls
index cb33adc..8d1fca3 100644
--- a/force-app/main/default/classes/ContactTriggerHandler.cls
+++ b/force-app/main/default/classes/ContactTriggerHandler.cls
@@ -2,587 +2,665 @@
  * Select Id From Contact Where RecordTypeId = '01210000000QfWdAAK' and Strategic_dept_Class__c != null
  */
 public without sharing class ContactTriggerHandler extends Oly_TriggerHandler {
-    private Map < Id, Contact > newMap;
-    private Map < Id, Contact > oldMap;
-    private List < Contact > newList;
-    private List < Contact > oldList;
-    private Id AgencyId = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId(); // 20220830 ljh LLIU-CHR8FF add
-        
-    public ContactTriggerHandler() {
-        this.newMap = (Map < Id, Contact > ) Trigger.newMap;
-        this.oldMap = (Map < Id, Contact > ) Trigger.oldMap;
-        this.newList = (List < Contact > ) Trigger.new;
-        this.oldList = (List < Contact > ) Trigger.old;
+  private Map<Id, Contact> newMap;
+  private Map<Id, Contact> oldMap;
+  private List<Contact> newList;
+  private List<Contact> oldList;
+  private Id AgencyId = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName()
+    .get('Agency')
+    .getRecordTypeId(); // 20220830 ljh LLIU-CHR8FF add
+
+  public ContactTriggerHandler() {
+    this.newMap = (Map<Id, Contact>) Trigger.newMap;
+    this.oldMap = (Map<Id, Contact>) Trigger.oldMap;
+    this.newList = (List<Contact>) Trigger.new;
+    this.oldList = (List<Contact>) Trigger.old;
+  }
+  protected override void beforeInsert() {
+    if (
+      Test.isRunningTest() || UserInfo.getUserId() != System.Label.ByPassTrigger
+    ) {
+      //Add by Li Jun for PIPL 20220331
+      mobileNumberVerification();
     }
-    protected override void beforeInsert() {
-        if(Test.isRunningTest()||UserInfo.getUserId()!=System.Label.ByPassTrigger){ //Add by Li Jun for PIPL 20220331
-            mobileNumberVerification();
-        }
-    }
+  }
 
-    protected override void afterInsert() {
-        syncToAgencyContact();
-        updateDealerNum();
-        sendToComPlat();
-        updateChargeState();// 20220830 ljh LLIU-CHR8FF
-    }
+  protected override void afterInsert() {
+    syncToAgencyContact();
+    updateDealerNum();
+    sendToComPlat();
+    updateChargeState(); // 20220830 ljh LLIU-CHR8FF
+  }
 
-    protected override void afterUpdate() {
-        syncToAgencyContact();
-        updateDealerNum();
-        sendToComPlat();
-    }
+  protected override void afterUpdate() {
+    syncToAgencyContact();
+    updateDealerNum();
+    sendToComPlat();
+  }
 
-    protected override void beforeUpdate() {
-        // 鏈嶅姟鎶�甯� 2018/12/24  Start
-        UpdateProcessingWork();
-        // 鏈嶅姟鎶�甯� 2018/12/24  end
-        mobileNumberVerification();
-    }
-
-
-    protected override void afterDelete() {
-        syncToAgencyContactDelete();
-        updateDealerNum();
-    }
-
-    //
-    /**
-     * @author 寮犵帀灞�
-     * @DateTime 2019-03-11T13:49:10+0800
-     * 鏍规嵁鏈嶅姟鎶�甯堝~鍐欐儏鍐垫洿鏂板鎴蜂汉鍛樹笂鐨勫紑灞曞伐浣滃瓧娈�
-     */
-    private void UpdateProcessingWork() {
-        for (Contact temContact: newList) {
-            if (System.label.UpdateServiceHistory.equals('true')) {
-
-                string ProcessingWork = '';
-                string ProcessingWorkWithoutNumber = '';
-                if (temContact.ServiceBookInput__c != 0) {
-                    ProcessingWork += '缁翠慨濮旀墭涔﹀~鍐�' + temContact.ServiceBookInput__c + '娆�';
-                    ProcessingWorkWithoutNumber += '缁翠慨濮旀墭涔﹀~鍐�';
-
-                }
-                if (temContact.InspectTime__c != 0) {
-                    if (String.isBlank(ProcessingWork)) {
-                        ProcessingWork += '鐐规' + temContact.InspectTime__c + '娆�';
-                        ProcessingWorkWithoutNumber += '鐐规';
-                    } else {
-                        ProcessingWork += '锛岀偣妫�' + temContact.InspectTime__c + '娆�';
-                        ProcessingWorkWithoutNumber += '锛岀偣妫�';
-
-                    }
-                }
-                if (temContact.InspectEquipmentTime__c != 0) {
-                    if (String.isBlank(ProcessingWork)) {
-                        ProcessingWork += '鐐规璁惧' + temContact.InspectEquipmentTime__c + '涓�';
-                        ProcessingWorkWithoutNumber += '鐐规璁惧';
-                    } else {
-                        ProcessingWork += '锛岀偣妫�璁惧' + temContact.InspectEquipmentTime__c + '涓�';
-                        ProcessingWorkWithoutNumber += '锛岀偣妫�璁惧';
-                    }
-
-                }
-                if (temContact.VisitTime__c != 0) {
-                    if (String.isBlank(ProcessingWork)) {
-                        ProcessingWork += '涓婇棬' + temContact.VisitTime__c + '娆�';
-                        ProcessingWorkWithoutNumber += '涓婇棬';
-                    } else {
-                        ProcessingWork += '锛屼笂闂�' + temContact.VisitTime__c + '娆�';
-                        ProcessingWorkWithoutNumber += '锛屼笂闂�';
-                    }
-
-                }
-                if (temContact.pollingTime__c != 0) {
-                    if (String.isBlank(ProcessingWork)) {
-                        ProcessingWork += '宸℃' + temContact.pollingTime__c + '娆�';
-                        ProcessingWorkWithoutNumber += '宸℃';
-                    } else {
-                        ProcessingWork += '锛屽贰妫�' + temContact.pollingTime__c + '娆�';
-                        ProcessingWorkWithoutNumber += '锛屽贰妫�';
-                    }
-
-                }
-                if (temContact.TeachingTime__c != 0) {
-                    if (String.isBlank(ProcessingWork)) {
-                        ProcessingWork += '鍩硅娆℃暟' + temContact.TeachingTime__c + '娆�';
-                        ProcessingWorkWithoutNumber += '鍩硅娆℃暟';
-                    } else {
-                        ProcessingWork += '锛屽煿璁鏁�' + temContact.TeachingTime__c + '娆�';
-                        ProcessingWorkWithoutNumber += '锛屽煿璁鏁�';
-                    }
-                }
-                //if (!String.isBlank(ProcessingWork)) {
-                //    ProcessingWork += '銆�';
-                //    ProcessingWorkWithoutNumber += '銆�';
-                //}
-                temContact.ProcessingWork__c = ProcessingWork;
-                temContact.ProcessingWorkWithoutNumber__c = ProcessingWorkWithoutNumber;
-
-
-            }
-        }
-
-    }
+  protected override void beforeUpdate() {
+    // 鏈嶅姟鎶�甯� 2018/12/24  Start
+    UpdateProcessingWork();
     // 鏈嶅姟鎶�甯� 2018/12/24  end
-    private void syncToAgencyContact() {
-        System.debug('enter syncToAgencyContact');
-        Map < Id, Agency_Contact__c > targetContactMap = new Map < Id, Agency_Contact__c > ();
-        Map < Id, Contact > ContactMap = new Map < Id, Contact > ();
-        for (Contact nObj: newList) {
-            if (nObj.RecordTypeId == '01210000000QfWdAAK' // Doctor
-                &&
-                String.isBlank(nObj.Strategic_dept_Class__c) == false
-            ) {
-                if (Trigger.isInsert ||
-                    (Trigger.isUpdate
-                        //                        && (
-                        //                            oldMap.get(nObj.Id).LastName                != nObj.LastName
-                        //                         || oldMap.get(nObj.Id).FirstName               != nObj.FirstName
-                        //                         || oldMap.get(nObj.Id).Strategic_dept_Class__c != nObj.Strategic_dept_Class__c
-                        //                         || oldMap.get(nObj.Id).Type__c                 != nObj.Type__c
-                        //                         || oldMap.get(nObj.Id).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);
-                    //zhj MEBG鏂版柟妗堟敼閫� 2022-11-27 鍘绘帀Encrypted start
-                    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
-                    );
-                    //zhj MEBG鏂版柟妗堟敼閫� 2022-11-27 鍘绘帀Encrypted end
-                    targetContactMap.put(nObj.Id, acObj);
-                    ContactMap.put(nObj.Id, nObj);
-                }
-            }
+    mobileNumberVerification();
+  }
+
+  protected override void afterDelete() {
+    syncToAgencyContactDelete();
+    updateDealerNum();
+  }
+
+  //
+  /**
+   * @author 寮犵帀灞�
+   * @DateTime 2019-03-11T13:49:10+0800
+   * 鏍规嵁鏈嶅姟鎶�甯堝~鍐欐儏鍐垫洿鏂板鎴蜂汉鍛樹笂鐨勫紑灞曞伐浣滃瓧娈�
+   */
+  private void UpdateProcessingWork() {
+    for (Contact temContact : newList) {
+      if (System.label.UpdateServiceHistory.equals('true')) {
+        string ProcessingWork = '';
+        string ProcessingWorkWithoutNumber = '';
+        if (temContact.ServiceBookInput__c != 0) {
+          ProcessingWork +=
+            '缁翠慨濮旀墭涔﹀~鍐�' +
+            temContact.ServiceBookInput__c +
+            '娆�';
+          ProcessingWorkWithoutNumber += '缁翠慨濮旀墭涔﹀~鍐�';
         }
-        if (targetContactMap.size() > 0) {
-            List<Agency_Contact__c> temp = targetContactMap.values();
-            upsert temp ContactId18__c;
-            system.debug('temp='+temp);
-            EncryptInsert(temp,ContactMap);
+        if (temContact.InspectTime__c != 0) {
+          if (String.isBlank(ProcessingWork)) {
+            ProcessingWork += '鐐规' + temContact.InspectTime__c + '娆�';
+            ProcessingWorkWithoutNumber += '鐐规';
+          } else {
+            ProcessingWork += '锛岀偣妫�' + temContact.InspectTime__c + '娆�';
+            ProcessingWorkWithoutNumber += '锛岀偣妫�';
+          }
         }
+        if (temContact.InspectEquipmentTime__c != 0) {
+          if (String.isBlank(ProcessingWork)) {
+            ProcessingWork +=
+              '鐐规璁惧' +
+              temContact.InspectEquipmentTime__c +
+              '涓�';
+            ProcessingWorkWithoutNumber += '鐐规璁惧';
+          } else {
+            ProcessingWork +=
+              '锛岀偣妫�璁惧' +
+              temContact.InspectEquipmentTime__c +
+              '涓�';
+            ProcessingWorkWithoutNumber += '锛岀偣妫�璁惧';
+          }
+        }
+        if (temContact.VisitTime__c != 0) {
+          if (String.isBlank(ProcessingWork)) {
+            ProcessingWork += '涓婇棬' + temContact.VisitTime__c + '娆�';
+            ProcessingWorkWithoutNumber += '涓婇棬';
+          } else {
+            ProcessingWork += '锛屼笂闂�' + temContact.VisitTime__c + '娆�';
+            ProcessingWorkWithoutNumber += '锛屼笂闂�';
+          }
+        }
+        if (temContact.pollingTime__c != 0) {
+          if (String.isBlank(ProcessingWork)) {
+            ProcessingWork += '宸℃' + temContact.pollingTime__c + '娆�';
+            ProcessingWorkWithoutNumber += '宸℃';
+          } else {
+            ProcessingWork += '锛屽贰妫�' + temContact.pollingTime__c + '娆�';
+            ProcessingWorkWithoutNumber += '锛屽贰妫�';
+          }
+        }
+        if (temContact.TeachingTime__c != 0) {
+          if (String.isBlank(ProcessingWork)) {
+            ProcessingWork += '鍩硅娆℃暟' + temContact.TeachingTime__c + '娆�';
+            ProcessingWorkWithoutNumber += '鍩硅娆℃暟';
+          } else {
+            ProcessingWork += '锛屽煿璁鏁�' + temContact.TeachingTime__c + '娆�';
+            ProcessingWorkWithoutNumber += '锛屽煿璁鏁�';
+          }
+        }
+        //if (!String.isBlank(ProcessingWork)) {
+        //    ProcessingWork += '銆�';
+        //    ProcessingWorkWithoutNumber += '銆�';
+        //}
+        temContact.ProcessingWork__c = ProcessingWork;
+        temContact.ProcessingWorkWithoutNumber__c = ProcessingWorkWithoutNumber;
+      }
     }
-    
-    static void EncryptInsert(List<Agency_Contact__c> aclist,Map < Id, Contact > ContactMap){
-        if(!(system.isFuture() || system.isBatch())){
-            //zhj MEBG鏂版柟妗堟敼閫� 2022-11-27 start
-            //AwsServiceTool2.EncryptPushFuture(Json.serialize(aclist), 'Agency_Contact__c');
-
-            Map<String,PIHelper.PIIntegration> staticResource = new Map<String,PIHelper.PIIntegration>();
-            staticResource.put('Contact',PIHelper.getPIIntegrationInfo('Contact'));
-            staticResource.put('Agency_Contact__c',PIHelper.getPIIntegrationInfo('Agency_Contact__c'));
-            Map<String, Map<String, PI_Field_Policy_Detail__c>> mmsp = new Map<String, Map<String,PI_Field_Policy_Detail__c>>();
-            for (String key : staticResource.keySet()) {
-                mmsp.put(key, new Map<String,PI_Field_Policy_Detail__c>());
-                for (PI_Field_Policy_Detail__c detail : staticResource.get(key).PIDetails) {
-                    mmsp.get(key).put(detail.SF_Field_API_Name__c, detail);
-                }
-            }
-
-            System.debug('mmsp = ' + mmsp);
-            List<AWSServiceTool2V2.EncryptPushRequestBody> EncryptPushList = new List<AWSServiceTool2V2.EncryptPushRequestBody>();
-            for(Agency_Contact__c ac : aclist){
-                AWSServiceTool2V2.EncryptPushRequestBody EncryptPush = new AWSServiceTool2V2.EncryptPushRequestBody();
-                EncryptPush.dataId = ac.AWS_Data_Id__c != null ?ac.AWS_Data_Id__c:'';
-                EncryptPush.sfRecordId = ac.Id;
-                EncryptPush.fieldsMapping = new Map<String, List<AWSServiceTool2V2.EncryptPushRes>>();
-                List<AWSServiceTool2V2.EncryptPushRes> resList = new List<AWSServiceTool2V2.EncryptPushRes>();
-                AWSServiceTool2V2.EncryptPushRes res= new AWSServiceTool2V2.EncryptPushRes();
-                res.isQueryDb = true;
-                res.value = '';
-                res.table = staticResource.get('Contact').awsTableName;
-                res.dataId = ContactMap.get(ac.Contact__c).AWS_Data_Id__c;
-                res.field = mmsp.get('Contact').get('LastName').AWS_Field_API__c;
-                resList.add(res);
-
-                List<AWSServiceTool2V2.EncryptPushRes> resList2 = new List<AWSServiceTool2V2.EncryptPushRes>();
-                AWSServiceTool2V2.EncryptPushRes res2= new AWSServiceTool2V2.EncryptPushRes();
-                res2.isQueryDb = true;
-                res2.value = '';
-                res2.table = staticResource.get('Contact').awsTableName;
-                res2.dataId = ContactMap.get(ac.Contact__c).AWS_Data_Id__c;
-                res2.field = mmsp.get('Contact').get('Type__c').AWS_Field_API__c;
-                resList2.add(res2);
-
-                List<AWSServiceTool2V2.EncryptPushRes> resList3 = new List<AWSServiceTool2V2.EncryptPushRes>();
-                AWSServiceTool2V2.EncryptPushRes res3= new AWSServiceTool2V2.EncryptPushRes();
-                res3.isQueryDb = true;
-                res3.value = '';
-                res3.table = staticResource.get('Contact').awsTableName;
-                res3.dataId = ContactMap.get(ac.Contact__c).AWS_Data_Id__c;
-                res3.field = mmsp.get('Contact').get('Doctor_Division1__c').AWS_Field_API__c;
-                resList3.add(res3);
-
-                System.debug('Agency_Contact__c Name = ' +mmsp.get('Agency_Contact__c').get('Name').AWS_Field_API__c);
-                System.debug('resList = ' + resList);
-                EncryptPush.fieldsMapping.put(mmsp.get('Agency_Contact__c').get('Name').AWS_Field_API__c, resList);
-                EncryptPush.fieldsMapping.put(mmsp.get('Agency_Contact__c').get('Type__c').AWS_Field_API__c, resList2);
-                EncryptPush.fieldsMapping.put(mmsp.get('Agency_Contact__c').get('Doctor_Division1__c').AWS_Field_API__c, resList3);
-                EncryptPushList.add(EncryptPush);
-            }
-            System.debug('EncryptPushListdataId = ' + JSON.serialize(EncryptPushList[0].dataId));
-            System.debug('EncryptPushListsfRecordId = ' + JSON.serialize(EncryptPushList[0].sfRecordId));
-            System.debug('EncryptPushListfieldsMapping = ' + JSON.serialize(EncryptPushList[0].fieldsMapping));
-            System.debug('EncryptPushList = ' + JSON.serialize(EncryptPushList));
-            if(!Test.isRunningTest())
-                AwsServiceTool2V2.EncryptPushFutureV2(Json.serialize(EncryptPushList),Json.serialize(aclist), 'Agency_Contact__c');
-            //zhj MEBG鏂版柟妗堟敼閫� 2022-11-27 end
-        }else{
-            //Add By Li Jun for sync agency contact to aws 20220424 start
-            if(!Test.isRunningTest()){
-                System.debug('ContactMap = ' + ContactMap);
-                SyncAccountContactToAWS.assignOnceOneMinuteLater(aclist,ContactMap);
-            }
-            //Add By Li Jun for sync agency contact to aws 20220424 end
+  }
+  // 鏈嶅姟鎶�甯� 2018/12/24  end
+  private void syncToAgencyContact() {
+    System.debug('enter syncToAgencyContact');
+    Map<Id, Agency_Contact__c> targetContactMap = new Map<Id, Agency_Contact__c>();
+    Map<Id, Contact> ContactMap = new Map<Id, Contact>();
+    for (Contact nObj : newList) {
+      if (
+        nObj.RecordTypeId ==
+        '01210000000QfWdAAK' && // Doctor
+        String.isBlank(nObj.Strategic_dept_Class__c) == false
+      ) {
+        if (
+          Trigger.isInsert ||
+          (Trigger.isUpdate)
+          //                        && (
+          //                            oldMap.get(nObj.Id).LastName                != nObj.LastName
+          //                         || oldMap.get(nObj.Id).FirstName               != nObj.FirstName
+          //                         || oldMap.get(nObj.Id).Strategic_dept_Class__c != nObj.Strategic_dept_Class__c
+          //                         || oldMap.get(nObj.Id).Type__c                 != nObj.Type__c
+          //                         || oldMap.get(nObj.Id).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);
+          //zhj MEBG鏂版柟妗堟敼閫� 2022-11-27 鍘绘帀Encrypted start
+          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
+          );
+          //zhj MEBG鏂版柟妗堟敼閫� 2022-11-27 鍘绘帀Encrypted end
+          targetContactMap.put(nObj.Id, acObj);
+          ContactMap.put(nObj.Id, nObj);
         }
+      }
+    }
+    if (targetContactMap.size() > 0) {
+      List<Agency_Contact__c> temp = targetContactMap.values();
+      upsert temp ContactId18__c;
+      system.debug('temp=' + temp);
+      EncryptInsert(temp, ContactMap);
+    }
+  }
+
+  static void EncryptInsert(
+    List<Agency_Contact__c> aclist,
+    Map<Id, Contact> ContactMap
+  ) {
+    if (!(system.isFuture() || system.isBatch())) {
+      //zhj MEBG鏂版柟妗堟敼閫� 2022-11-27 start
+      //AwsServiceTool2.EncryptPushFuture(Json.serialize(aclist), 'Agency_Contact__c');
+
+      Map<String, PIHelper.PIIntegration> staticResource = new Map<String, PIHelper.PIIntegration>();
+      staticResource.put('Contact', PIHelper.getPIIntegrationInfo('Contact'));
+      staticResource.put(
+        'Agency_Contact__c',
+        PIHelper.getPIIntegrationInfo('Agency_Contact__c')
+      );
+      Map<String, Map<String, PI_Field_Policy_Detail__c>> mmsp = new Map<String, Map<String, PI_Field_Policy_Detail__c>>();
+      for (String key : staticResource.keySet()) {
+        mmsp.put(key, new Map<String, PI_Field_Policy_Detail__c>());
+        for (
+          PI_Field_Policy_Detail__c detail : staticResource.get(key).PIDetails
+        ) {
+          mmsp.get(key).put(detail.SF_Field_API_Name__c, detail);
+        }
+      }
+
+      System.debug('mmsp = ' + mmsp);
+      List<AWSServiceTool2V2.EncryptPushRequestBody> EncryptPushList = new List<AWSServiceTool2V2.EncryptPushRequestBody>();
+      for (Agency_Contact__c ac : aclist) {
+        AWSServiceTool2V2.EncryptPushRequestBody EncryptPush = new AWSServiceTool2V2.EncryptPushRequestBody();
+        EncryptPush.dataId = ac.AWS_Data_Id__c != null ? ac.AWS_Data_Id__c : '';
+        EncryptPush.sfRecordId = ac.Id;
+        EncryptPush.fieldsMapping = new Map<String, List<AWSServiceTool2V2.EncryptPushRes>>();
+        List<AWSServiceTool2V2.EncryptPushRes> resList = new List<AWSServiceTool2V2.EncryptPushRes>();
+        AWSServiceTool2V2.EncryptPushRes res = new AWSServiceTool2V2.EncryptPushRes();
+        res.isQueryDb = true;
+        res.value = '';
+        res.table = staticResource.get('Contact').awsTableName;
+        res.dataId = ContactMap.get(ac.Contact__c).AWS_Data_Id__c;
+        res.field = mmsp.get('Contact').get('LastName').AWS_Field_API__c;
+        resList.add(res);
+
+        List<AWSServiceTool2V2.EncryptPushRes> resList2 = new List<AWSServiceTool2V2.EncryptPushRes>();
+        AWSServiceTool2V2.EncryptPushRes res2 = new AWSServiceTool2V2.EncryptPushRes();
+        res2.isQueryDb = true;
+        res2.value = '';
+        res2.table = staticResource.get('Contact').awsTableName;
+        res2.dataId = ContactMap.get(ac.Contact__c).AWS_Data_Id__c;
+        res2.field = mmsp.get('Contact').get('Type__c').AWS_Field_API__c;
+        resList2.add(res2);
+
+        List<AWSServiceTool2V2.EncryptPushRes> resList3 = new List<AWSServiceTool2V2.EncryptPushRes>();
+        AWSServiceTool2V2.EncryptPushRes res3 = new AWSServiceTool2V2.EncryptPushRes();
+        res3.isQueryDb = true;
+        res3.value = '';
+        res3.table = staticResource.get('Contact').awsTableName;
+        res3.dataId = ContactMap.get(ac.Contact__c).AWS_Data_Id__c;
+        res3.field = mmsp.get('Contact')
+          .get('Doctor_Division1__c')
+          .AWS_Field_API__c;
+        resList3.add(res3);
+
+        System.debug(
+          'Agency_Contact__c Name = ' +
+          mmsp.get('Agency_Contact__c').get('Name').AWS_Field_API__c
+        );
+        System.debug('resList = ' + resList);
+        EncryptPush.fieldsMapping.put(
+          mmsp.get('Agency_Contact__c').get('Name').AWS_Field_API__c,
+          resList
+        );
+        EncryptPush.fieldsMapping.put(
+          mmsp.get('Agency_Contact__c').get('Type__c').AWS_Field_API__c,
+          resList2
+        );
+        EncryptPush.fieldsMapping.put(
+          mmsp.get('Agency_Contact__c')
+            .get('Doctor_Division1__c')
+            .AWS_Field_API__c,
+          resList3
+        );
+        EncryptPushList.add(EncryptPush);
+      }
+      System.debug(
+        'EncryptPushListdataId = ' + JSON.serialize(EncryptPushList[0].dataId)
+      );
+      System.debug(
+        'EncryptPushListsfRecordId = ' +
+        JSON.serialize(EncryptPushList[0].sfRecordId)
+      );
+      System.debug(
+        'EncryptPushListfieldsMapping = ' +
+        JSON.serialize(EncryptPushList[0].fieldsMapping)
+      );
+      System.debug('EncryptPushList = ' + JSON.serialize(EncryptPushList));
+      if (!Test.isRunningTest())
+        AwsServiceTool2V2.EncryptPushFutureV2(
+          Json.serialize(EncryptPushList),
+          Json.serialize(aclist),
+          'Agency_Contact__c'
+        );
+      //zhj MEBG鏂版柟妗堟敼閫� 2022-11-27 end
+    } else {
+      //Add By Li Jun for sync agency contact to aws 20220424 start
+      if (!Test.isRunningTest()) {
+        System.debug('ContactMap = ' + ContactMap);
+        SyncAccountContactToAWS.assignOnceOneMinuteLater(aclist, ContactMap);
+      }
+      //Add By Li Jun for sync agency contact to aws 20220424 end
+    }
+  }
+
+  private void syncToAgencyContactDelete() {
+    List<Id> cIdList = new List<Id>();
+    for (Contact oObj : oldList) {
+      cIdList.add(oObj.Id);
+    }
+    if (cIdList.size() > 0) {
+      List<Agency_Contact__c> acList = [
+        SELECT Id
+        FROM Agency_Contact__c
+        WHERE Contact__c = :null AND Agency_ID__c = '000000000000000'
+      ];
+      if (acList.size() > 0) {
+        delete acList;
+      }
+    }
+  }
+
+  //鏇存柊缁忛攢鍟嗙敤鎴蜂汉鏁板瓧娈� 绮剧悽鎶�鏈� pk 2021-08-26 start
+  private void updateDealerNum() {
+    Set<Id> accountSet = new Set<Id>();
+    Map<Id, Account> acMap = new Map<Id, Account>();
+    if (Trigger.isUpdate) {
+      for (Contact contactnew : newList) {
+        if (
+          contactnew.Agency_User__c !=
+          oldMap.get(contactnew.Id).Agency_User__c ||
+          (System.Label.onlyUpdate == '1' &&
+          UserInfo.getUserId() == '00510000005sEEMAA2')
+        ) {
+          accountSet.add(contactnew.AccountId);
+        }
+      }
     }
 
-    private void syncToAgencyContactDelete() {
-        List < Id > cIdList = new List < Id > ();
-        for (Contact oObj: oldList) {
-            cIdList.add(oObj.Id);
+    if (Trigger.isInsert) {
+      for (Contact contactnew : newList) {
+        if (contactnew.Agency_User__c) {
+          accountSet.add(contactnew.AccountId);
         }
-        if (cIdList.size() > 0) {
-            List < Agency_Contact__c > acList = [Select Id From Agency_Contact__c
-                Where Contact__c =: null and Agency_ID__c = '000000000000000'
-            ];
-            if (acList.size() > 0) {
-                delete acList;
-            }
-        }
+      }
     }
 
-    //鏇存柊缁忛攢鍟嗙敤鎴蜂汉鏁板瓧娈� 绮剧悽鎶�鏈� pk 2021-08-26 start
-    private void updateDealerNum() {
-        Set < Id > accountSet = new Set < Id > ();
-        Map < Id, Account > acMap = new Map < Id, Account > ();
-        if (Trigger.isUpdate) {
-            for (Contact contactnew: newList) {
-                if (contactnew.Agency_User__c != oldMap.get(contactnew.Id).Agency_User__c || (System.Label.onlyUpdate == '1' && UserInfo.getUserId() == '00510000005sEEMAA2')) {
-                    accountSet.add(contactnew.AccountId);
-                }
-            }
+    if (Trigger.isDelete) {
+      for (Contact contactold : oldList) {
+        if (contactold.Agency_User__c) {
+          accountSet.add(contactold.AccountId);
         }
-
-        if (Trigger.isInsert) {
-            for (Contact contactnew: newList) {
-                if (contactnew.Agency_User__c) {
-                    accountSet.add(contactnew.AccountId);
-                }
-            }
-        }
-
-
-        if (Trigger.isDelete) {
-            for (Contact contactold: oldList) {
-                if (contactold.Agency_User__c) {
-                    accountSet.add(contactold.AccountId);
-                }
-            }
-        }
-
-        if (accountSet.size() > 0) {
-            List < AggregateResult > contactList = [select count(id) ctn, AccountId accid from Contact where Agency_User__c = true and AccountId =: accountSet and RecordTypeId = '01210000000QfWi'
-                group by AccountId
-            ];
-            for (AggregateResult ar: contactList) {
-                String accid = (String) ar.get('accid');
-                Account account = new Account();
-                account.id = accid;
-                account.Dealer_Num__c = (Integer) ar.get('ctn');
-                acMap.put(accid, account);
-            }
-
-            for (Id accountId: accountSet) {
-                if (!acMap.containsKey(accountId)) {
-                    Account account = new Account();
-                    account.id = accountId;
-                    account.Dealer_Num__c = 0;
-                    acMap.put(accountId, account);
-                }
-            }
-
-            if (acMap.size() > 0) {
-                update acMap.values();
-            }
-        }
-
-
+      }
     }
-    //鏇存柊缁忛攢鍟嗙敤鎴蜂汉鏁板瓧娈� 绮剧悽鎶�鏈� pk 2021-08-26 end
-    
-    //zhj 鏂版柟妗堟敼閫� 灏嗘墜鏈哄彿鍘婚噸鍙婂叾楠岃瘉瑙勫垯绉诲姩鍒癆WS鍜屽墠绔� start
-    // 鎵嬫満鍙峰幓閲嶅強瑙勫垯楠岃瘉 鍙婃柊澧炲鎴蜂汉鍛橀噸鍚嶉獙璇�
-    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<String> accIdList = new List<String>();
-        Map<String,String> accMap= new Map<String,String>();
-        for (Contact contact1: newList) {
-            accIdList.add(contact1.AccountId);
+    if (accountSet.size() > 0) {
+      List<AggregateResult> contactList = [
+        SELECT count(id) ctn, AccountId accid
+        FROM Contact
+        WHERE
+          Agency_User__c = TRUE
+          AND AccountId = :accountSet
+          AND RecordTypeId = '01210000000QfWi'
+        GROUP BY AccountId
+      ];
+      for (AggregateResult ar : contactList) {
+        String accid = (String) ar.get('accid');
+        Account account = new Account();
+        account.id = accid;
+        account.Dealer_Num__c = (Integer) ar.get('ctn');
+        acMap.put(accid, account);
+      }
+
+      for (Id accountId : accountSet) {
+        if (!acMap.containsKey(accountId)) {
+          Account account = new Account();
+          account.id = accountId;
+          account.Dealer_Num__c = 0;
+          acMap.put(accountId, account);
         }
-        if (accIdList.size()>0){
-            List<Account> accList=[select ID,Is_Active__c,Is_Active_Formula__c from Account where ID in:accIdList];
-            if(accList.size()>0){
-                for(Account acc:accList){
-                    if (String.isNotBlank(acc.Is_Active__c)){
-                        accMap.put(acc.Id, acc.Is_Active__c);
-                        continue;
-                    }
-                    if (String.isNotBlank(acc.Is_Active_Formula__c)){
-                        accMap.put(acc.Id, acc.Is_Active_Formula__c);
-                    }
-                }
-            }
+      }
+
+      if (acMap.size() > 0) {
+        update acMap.values();
+      }
+    }
+  }
+  //鏇存柊缁忛攢鍟嗙敤鎴蜂汉鏁板瓧娈� 绮剧悽鎶�鏈� pk 2021-08-26 end
+
+  //zhj 鏂版柟妗堟敼閫� 灏嗘墜鏈哄彿鍘婚噸鍙婂叾楠岃瘉瑙勫垯绉诲姩鍒癆WS鍜屽墠绔� start
+  // 鎵嬫満鍙峰幓閲嶅強瑙勫垯楠岃瘉 鍙婃柊澧炲鎴蜂汉鍛橀噸鍚嶉獙璇�
+  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<String> accIdList = new List<String>();
+    Map<String, String> accMap = new Map<String, String>();
+    for (Contact contact1 : newList) {
+      accIdList.add(contact1.AccountId);
+    }
+    if (accIdList.size() > 0) {
+      List<Account> accList = [
+        SELECT ID, Is_Active__c, Is_Active_Formula__c
+        FROM Account
+        WHERE ID IN :accIdList
+      ];
+      if (accList.size() > 0) {
+        for (Account acc : accList) {
+          if (String.isNotBlank(acc.Is_Active__c)) {
+            accMap.put(acc.Id, acc.Is_Active__c);
+            continue;
+          }
+          if (String.isNotBlank(acc.Is_Active_Formula__c)) {
+            accMap.put(acc.Id, acc.Is_Active_Formula__c);
+          }
         }
-        //鎵嬫満鍙峰敮涓�鏍¢獙-鍖婚櫌涓嬫柊寤哄鎴蜂汉鍛樻牎楠屼娇鐢ㄥ姞瀵嗘墜鏈哄彿,缁忛攢鍟嗕娇鐢ㄦ櫘閫氭墜鏈哄彿 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)))) {
-                // 缁忛攢鍟嗗鎴蜂汉鍛樹笉杩涜鎵嬫満鍙锋牎楠� thh 20220517 start
-                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;
-                    }
-                // 缁忛攢鍟嗗鎴蜂汉鍛樹笉杩涜鎵嬫満鍙锋牎楠� thh 20220517 end
-                } 
-                // 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) {
-            // if(DoctorRecordTypeId.equals(contactnew.RecordTypeId)){
-            //     accountIdSet.add(contactnew.AccountId);  
+      }
+    }
+    //鎵嬫満鍙峰敮涓�鏍¢獙-鍖婚櫌涓嬫柊寤哄鎴蜂汉鍛樻牎楠屼娇鐢ㄥ姞瀵嗘墜鏈哄彿,缁忛攢鍟嗕娇鐢ㄦ櫘閫氭墜鏈哄彿 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)))
+      ) {
+        // 缁忛攢鍟嗗鎴蜂汉鍛樹笉杩涜鎵嬫満鍙锋牎楠� thh 20220517 start
+        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;
+          }
+          // 缁忛攢鍟嗗鎴蜂汉鍛樹笉杩涜鎵嬫満鍙锋牎楠� thh 20220517 end
         }
-        //鎵嬫満鍙峰敮涓�鏍¢獙-鍖婚櫌涓嬫柊寤哄鎴蜂汉鍛樻牎楠屼娇鐢ㄥ姞瀵嗘墜鏈哄彿,缁忛攢鍟嗕娇鐢ㄦ櫘閫氭墜鏈哄彿 thh 20220328 end
-        // 鏂板鍖婚櫌鑱旂郴浜烘椂
-        // if (accountIdSet.size() > 0) {
-        //     List<Contact> contactList = new List<Contact>();
-        //     if(Trigger.isInsert){
-        //         contactList = [SELECT Id,AccountId,FullName__c,LastName,FirstName,Account.Name,CManageCode__c,IsFromSPO__c,
-        //                                         LastName_Encrypted__c// 20220314 PI鏀归�� by Bright
-        //                                         , MobilePhone_Encrypted__c // 閫氳繃濮撳悕+鎵嬫満鍙峰垽鏂汉鍛樻槸鍚﹂噸澶� thh 20220518
-        //                                         FROM Contact 
-        //                                         WHERE IsFromSPO__c = false AND AccountId IN:accountIdSet];
-        //     }
-        //     if(Trigger.isUpdate){
-        //         contactList = [SELECT Id,AccountId,FullName__c,LastName,FirstName,Account.Name,CManageCode__c,IsFromSPO__c,
-        //                                      LastName_Encrypted__c// 20220314 PI鏀归�� by Bright
-        //                                      , MobilePhone_Encrypted__c // 閫氳繃濮撳悕+鎵嬫満鍙峰垽鏂汉鍛樻槸鍚﹂噸澶� thh 20220518
-        //                                     FROM Contact 
-        //                                     WHERE IsFromSPO__c = false AND AccountId IN:accountIdSet AND Id Not IN: oldMap.keyset()];
-        //     }
-        //     System.debug('contactList:' + contactList);
-        //     if (contactList.size() > 0) {
-        //         for(Contact contact :contactList){
-        //             // 閫氳繃濮撳悕+鎵嬫満鍙峰垽鏂汉鍛樻槸鍚﹂噸澶� thh 20220518 start
-        //             // String lastNameStr = String.isNotBlank(contact.LastName) ? contact.LastName:'';
-        //             // String firstNameStr = String.isNotBlank(contact.FirstName) ? contact.FirstName:'';
-        //             // String contactFullName = lastNameStr + firstNameStr + MobilePhoneStr; 
-        //             String contactFullName = contact.LastName_Encrypted__c + contact.MobilePhone_Encrypted__c;// 20220314 PI鏀归�� by Bright
-        //             // 閫氳繃濮撳悕+鎵嬫満鍙峰垽鏂汉鍛樻槸鍚﹂噸澶� thh 20220518 end
-        //             if(string.isBlank(contactFullName)){
-        //                 continue;
-        //             }      
-        //             String accountId = String.valueOf(contact.AccountId).SubString(0,15);
-        //             Map<String,Contact> contactFullNameMap = new  Map<String,Contact>();
-        //             if (accountContactMap.containsKey(accountId)) {
-        //                 contactFullNameMap = accountContactMap.get(accountId);
-        //             }
-        //             contactFullNameMap.put(contactFullName, contact);
-        //             accountContactMap.put(accountId, contactFullNameMap);
-        //         }
+        // 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) {
+      // if(DoctorRecordTypeId.equals(contactnew.RecordTypeId)){
+      //     accountIdSet.add(contactnew.AccountId);
+      // }
+      // }
+    }
+    //鎵嬫満鍙峰敮涓�鏍¢獙-鍖婚櫌涓嬫柊寤哄鎴蜂汉鍛樻牎楠屼娇鐢ㄥ姞瀵嗘墜鏈哄彿,缁忛攢鍟嗕娇鐢ㄦ櫘閫氭墜鏈哄彿 thh 20220328 end
+    // 鏂板鍖婚櫌鑱旂郴浜烘椂
+    // if (accountIdSet.size() > 0) {
+    //     List<Contact> contactList = new List<Contact>();
+    //     if(Trigger.isInsert){
+    //         contactList = [SELECT Id,AccountId,FullName__c,LastName,FirstName,Account.Name,CManageCode__c,IsFromSPO__c,
+    //                                         LastName_Encrypted__c// 20220314 PI鏀归�� by Bright
+    //                                         , MobilePhone_Encrypted__c // 閫氳繃濮撳悕+鎵嬫満鍙峰垽鏂汉鍛樻槸鍚﹂噸澶� thh 20220518
+    //                                         FROM Contact
+    //                                         WHERE IsFromSPO__c = false AND AccountId IN:accountIdSet];
+    //     }
+    //     if(Trigger.isUpdate){
+    //         contactList = [SELECT Id,AccountId,FullName__c,LastName,FirstName,Account.Name,CManageCode__c,IsFromSPO__c,
+    //                                      LastName_Encrypted__c// 20220314 PI鏀归�� by Bright
+    //                                      , MobilePhone_Encrypted__c // 閫氳繃濮撳悕+鎵嬫満鍙峰垽鏂汉鍛樻槸鍚﹂噸澶� thh 20220518
+    //                                     FROM Contact
+    //                                     WHERE IsFromSPO__c = false AND AccountId IN:accountIdSet AND Id Not IN: oldMap.keyset()];
+    //     }
+    //     System.debug('contactList:' + contactList);
+    //     if (contactList.size() > 0) {
+    //         for(Contact contact :contactList){
+    //             // 閫氳繃濮撳悕+鎵嬫満鍙峰垽鏂汉鍛樻槸鍚﹂噸澶� thh 20220518 start
+    //             // String lastNameStr = String.isNotBlank(contact.LastName) ? contact.LastName:'';
+    //             // String firstNameStr = String.isNotBlank(contact.FirstName) ? contact.FirstName:'';
+    //             // String contactFullName = lastNameStr + firstNameStr + MobilePhoneStr;
+    //             String contactFullName = contact.LastName_Encrypted__c + contact.MobilePhone_Encrypted__c;// 20220314 PI鏀归�� by Bright
+    //             // 閫氳繃濮撳悕+鎵嬫満鍙峰垽鏂汉鍛樻槸鍚﹂噸澶� thh 20220518 end
+    //             if(string.isBlank(contactFullName)){
+    //                 continue;
+    //             }
+    //             String accountId = String.valueOf(contact.AccountId).SubString(0,15);
+    //             Map<String,Contact> contactFullNameMap = new  Map<String,Contact>();
+    //             if (accountContactMap.containsKey(accountId)) {
+    //                 contactFullNameMap = accountContactMap.get(accountId);
+    //             }
+    //             contactFullNameMap.put(contactFullName, contact);
+    //             accountContactMap.put(accountId, contactFullNameMap);
+    //         }
+    //     }
+    // }
 
-        // for (Contact contactnew: newList) {
-        //     if(AgencyRecordTypeId.equals(contactnew.RecordTypeId) || (Trigger.isUpdate && !oldMap.isEmpty() && oldMap.get(contactnew.Id) != null 
-        //         && String.isBlank(oldMap.get(contactnew.Id).MobilePhone_Encrypted__c) 
-        //         && String.isBlank(contactnew.MobilePhone_Encrypted__c))){
-        //         continue;
-        //     }
-        //     String accountId = String.valueOf(contactnew.AccountId).substring(0, 15);
-        //     if (accountContactMap.containsKey(accountId)) {
-        //         Map<String,Contact> contactFullNameMap =  accountContactMap.get(accountId);
-        //         // 閫氳繃濮撳悕+鎵嬫満鍙峰垽鏂汉鍛樻槸鍚﹂噸澶� thh 20220518 start
-        //         // String lastNameStr = String.isNotBlank(contactnew.LastName) ? contactnew.LastName:'';
-        //         // String firstNameStr = String.isNotBlank(contactnew.FirstName) ? contactnew.FirstName:'';
-        //         // String contactFullName = lastNameStr + firstNameStr + MobilePhoneStr;
-        //         String contactFullName = contactnew.LastName_Encrypted__c + contactnew.MobilePhone_Encrypted__c;// 20220314 PI鏀归�� by Bright
-        //         // 閫氳繃濮撳悕+鎵嬫満鍙峰垽鏂汉鍛樻槸鍚﹂噸澶� thh 20220518 end
-        //         if (contactFullNameMap.containsKey(contactFullName)) {
-        //             String accountName = contactFullNameMap.get(contactFullName).Account.Name;
-        //             String cManageCode = contactFullNameMap.get(contactFullName).CManageCode__c;
-        //             // 璺宠繃娴嬭瘯绋嬪簭 鍜� SPO閫氳繃203鎺ュ彛鍒涘缓鐨勮仈绯讳汉
-        //             if (!(Test.isRunningTest() || contactnew.IsFromSPO__c)) {
-        //                 // if(Trigger.isInsert) {
-        //                     contactnew.LastName.addError('瀹㈡埛 [ '+accountName+ ' ],宸插瓨鍦ㄧ浉鍚屽悕瀛楃殑鑱旂郴浜� 浜哄憳绠$悊缂栫爜 ['+cManageCode+' ] 锛屼笉鑳介噸澶嶅垱寤猴紝璇蜂簡瑙�');     
-        //                 // } 
-        //                 // 瀹㈡埛浜哄憳鍒犻櫎鎵嬫満鍙锋椂,杩涜鍒ゆ柇鏄惁瀛樺湪鍚屽悕涓旀墜鏈哄彿涓虹┖鐨勫鎴蜂汉鍛� thh 20220523 start
-        //                 // if(Trigger.isUpdate && !UserInfo.getUserId().equals(System.Label.interfaceUserID)) {
-        //                 //     if (String.isNotBlank(oldMap.get(contactnew.Id).MobilePhone_Encrypted__c) && String.isBlank(contactnew.MobilePhone_Encrypted__c)){
-        //                 //         contactnew.LastName.addError('鐩稿悓鍚嶅瓧鐨勮仈绯讳汉 浜哄憳绠$悊缂栫爜 ['+cManageCode+' ] 鎵嬫満鍙蜂负绌哄凡缁忓瓨鍦紝涓嶈兘閲嶅鍒涘缓锛岃浜嗚В');
-        //                 //     } 
-        //                 //     if (oldMap.get(contactnew.Id).CManageCode__c != contactnew.CManageCode__c){
-        //                 //         contactnew.LastName.addError('瀹㈡埛 [ '+accountName+ ' ],宸插瓨鍦ㄧ浉鍚屽悕瀛楃殑鑱旂郴浜� 浜哄憳绠$悊缂栫爜 ['+cManageCode+' ] 锛屼笉鑳介噸澶嶅垱寤猴紝璇蜂簡瑙�'); 
-        //                 //     }
-        //                 // }
-        //                 // 瀹㈡埛浜哄憳鍒犻櫎鎵嬫満鍙锋椂,杩涜鍒ゆ柇鏄惁瀛樺湪鍚屽悕涓旀墜鏈哄彿涓虹┖鐨勫鎴蜂汉鍛� thh 20220523 end
-        //             } 
-        //         }
-        //     }
+    // for (Contact contactnew: newList) {
+    //     if(AgencyRecordTypeId.equals(contactnew.RecordTypeId) || (Trigger.isUpdate && !oldMap.isEmpty() && oldMap.get(contactnew.Id) != null
+    //         && String.isBlank(oldMap.get(contactnew.Id).MobilePhone_Encrypted__c)
+    //         && String.isBlank(contactnew.MobilePhone_Encrypted__c))){
+    //         continue;
+    //     }
+    //     String accountId = String.valueOf(contactnew.AccountId).substring(0, 15);
+    //     if (accountContactMap.containsKey(accountId)) {
+    //         Map<String,Contact> contactFullNameMap =  accountContactMap.get(accountId);
+    //         // 閫氳繃濮撳悕+鎵嬫満鍙峰垽鏂汉鍛樻槸鍚﹂噸澶� thh 20220518 start
+    //         // String lastNameStr = String.isNotBlank(contactnew.LastName) ? contactnew.LastName:'';
+    //         // String firstNameStr = String.isNotBlank(contactnew.FirstName) ? contactnew.FirstName:'';
+    //         // String contactFullName = lastNameStr + firstNameStr + MobilePhoneStr;
+    //         String contactFullName = contactnew.LastName_Encrypted__c + contactnew.MobilePhone_Encrypted__c;// 20220314 PI鏀归�� by Bright
+    //         // 閫氳繃濮撳悕+鎵嬫満鍙峰垽鏂汉鍛樻槸鍚﹂噸澶� thh 20220518 end
+    //         if (contactFullNameMap.containsKey(contactFullName)) {
+    //             String accountName = contactFullNameMap.get(contactFullName).Account.Name;
+    //             String cManageCode = contactFullNameMap.get(contactFullName).CManageCode__c;
+    //             // 璺宠繃娴嬭瘯绋嬪簭 鍜� SPO閫氳繃203鎺ュ彛鍒涘缓鐨勮仈绯讳汉
+    //             if (!(Test.isRunningTest() || contactnew.IsFromSPO__c)) {
+    //                 // if(Trigger.isInsert) {
+    //                     contactnew.LastName.addError('瀹㈡埛 [ '+accountName+ ' ],宸插瓨鍦ㄧ浉鍚屽悕瀛楃殑鑱旂郴浜� 浜哄憳绠$悊缂栫爜 ['+cManageCode+' ] 锛屼笉鑳介噸澶嶅垱寤猴紝璇蜂簡瑙�');
+    //                 // }
+    //                 // 瀹㈡埛浜哄憳鍒犻櫎鎵嬫満鍙锋椂,杩涜鍒ゆ柇鏄惁瀛樺湪鍚屽悕涓旀墜鏈哄彿涓虹┖鐨勫鎴蜂汉鍛� thh 20220523 start
+    //                 // if(Trigger.isUpdate && !UserInfo.getUserId().equals(System.Label.interfaceUserID)) {
+    //                 //     if (String.isNotBlank(oldMap.get(contactnew.Id).MobilePhone_Encrypted__c) && String.isBlank(contactnew.MobilePhone_Encrypted__c)){
+    //                 //         contactnew.LastName.addError('鐩稿悓鍚嶅瓧鐨勮仈绯讳汉 浜哄憳绠$悊缂栫爜 ['+cManageCode+' ] 鎵嬫満鍙蜂负绌哄凡缁忓瓨鍦紝涓嶈兘閲嶅鍒涘缓锛岃浜嗚В');
+    //                 //     }
+    //                 //     if (oldMap.get(contactnew.Id).CManageCode__c != contactnew.CManageCode__c){
+    //                 //         contactnew.LastName.addError('瀹㈡埛 [ '+accountName+ ' ],宸插瓨鍦ㄧ浉鍚屽悕瀛楃殑鑱旂郴浜� 浜哄憳绠$悊缂栫爜 ['+cManageCode+' ] 锛屼笉鑳介噸澶嶅垱寤猴紝璇蜂簡瑙�');
+    //                 //     }
+    //                 // }
+    //                 // 瀹㈡埛浜哄憳鍒犻櫎鎵嬫満鍙锋椂,杩涜鍒ゆ柇鏄惁瀛樺湪鍚屽悕涓旀墜鏈哄彿涓虹┖鐨勫鎴蜂汉鍛� thh 20220523 end
+    //             }
+    //         }
+    //     }
+    // }
+  }
+  //zhj 鏂版柟妗堟敼閫� 灏嗘墜鏈哄彿鍘婚噸鍙婂叾楠岃瘉瑙勫垯绉诲姩鍒癆WS鍜屽墠绔� end
+
+  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>();
+    for (Contact local : newList) {
+      Contact old = null;
+      if (Trigger.isUpdate) {
+        old = oldMap.get(local.Id);
+      }
+      if (
+        Trigger.isInsert ||
+        old.LastName != local.LastName ||
+        old.FirstName != local.FirstName ||
+        old.Email != local.Email || //銉°兗銉� Email
+        old.MobilePhone != local.MobilePhone || //鎵嬫満鍙风爜 Mobile_Phone__c
+        old.Employee_No_manual__c != local.Employee_No_manual__c || //鍛樺伐鍙风爜 Employee_No__c
+        old.Work_Location_manual__c != local.Work_Location_manual__c || //宸ヤ綔鍦� Work_Location__c
+        old.Post_picklist__c != local.Post_picklist__c || //鑱屼綅 post__c
+        old.Job_Category_picklist__c != local.Job_Category_picklist__c || //鑱岀 Job_Category__c
+        old.Hire_date_text__c != local.Hire_date_text__c || //鍏ヨ亴鏃� Hire_date__c
+        old.Gender_text__c != local.Gender_text__c || //鎬у埆 Gender__c
+        old.dept__c != local.dept__c || //鏈儴 dept__c
+        old.Pregnant_Rest__c != local.Pregnant_Rest__c || // 鏄惁浜у亣 Pregnant_Rest__c
+        old.Stay_or_not__c != local.Stay_or_not__c || // 鍦ㄨ亴/绂昏亴 Stay_or_not__c
+        //|| old.Salesdepartment_Text__c != local.Salesdepartment_Text__c // 閿�鍞湰閮� Salesdepartment__c
+        old.AccountId != local.AccountId || //瀹㈡埛浜哄憳鎹㈠鎴�
+        old.Isactive__c != local.Isactive__c || //鐘舵�佸彉鏇�
+        old.ServicePlatformCode__c != local.ServicePlatformCode__c || //鏈嶅姟骞冲彴缂栫爜
+        old.UnifiedI_Contact_ID__c != local.UnifiedI_Contact_ID__c || //鏅烘収鍖荤枟缂栫爜
+        old.ContactType__c != local.ContactType__c || //浜哄憳绫诲瀷
+        (old.ChargeState__c != local.ChargeState__c &&
+        local.RecordTypeId == AgencyId) //璐熻矗鐪� // 20220830 ljh LLIU-CHR8FF add
+      ) {
+        //鑾峰彇瀹㈡埛浜哄憳鐨勮褰曠被鍨婭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);
+        // gzw 20220824 bugfix start
+        // if (!local.IsFromSPO__c && !InternalStaffRecordTypeId.equals(local.RecordTypeId)) {
+        if (!InternalStaffRecordTypeId.equals(local.RecordTypeId)) {
+          // gzw 20220824 bugfix end
+          // 鍖婚櫌 瀹㈡埛浜哄憳 缁熶竴骞冲彴缂栫爜鏈夊�� 鍙戦�� PO
+          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);
+              } else {
+                contactIdList.add(local.Id);
+              }
+              NFM606_IdMap.put(local.Id, local.Id);
+            }
+          }
+          // 缁忛攢鍟� 瀹㈡埛浜哄憳 鎵嬫満鍙风爜鏈夊�� 鍙戦�� PO
+          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);
+              } else {
+                contactIdList.add(local.Id);
+              }
+              NFM606_IdMap.put(local.Id, local.Id);
+            }
+          }
+        }
+      }
+    }
+    //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);
+
+        // } else{
+        // NFM606Controller.executeNotFuture('', contactIdList);
         // }
+        //娣诲姞future 鍒ゆ柇 add for pipl  sushanhu 20220317 end
+      }
+      if (interfaceUserUpsertContact.size() > 0) {
+        NFM606Controller.executeNotFuture('', interfaceUserUpsertContact);
+        //娣诲姞future 鍒ゆ柇 add for pipl  sushanhu 20220316 start
+        // if (!(System.isFuture()||System.isBatch())) {
+        // NFM606Controller.executeNotFuture('', interfaceUserUpsertContact);
+        // }
+        //娣诲姞future 鍒ゆ柇 add for pipl  sushanhu 20220316 end
+      }
     }
-    //zhj 鏂版柟妗堟敼閫� 灏嗘墜鏈哄彿鍘婚噸鍙婂叾楠岃瘉瑙勫垯绉诲姩鍒癆WS鍜屽墠绔� end
-
-    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>();
-        for (Contact local: newList) {
-            Contact old = null;
-            if (Trigger.isUpdate) {
-                old = oldMap.get(local.Id);
-            }
-            if (Trigger.isInsert
-                        || old.LastName != local.LastName
-                        || old.FirstName != local.FirstName
-                        || old.Email != local.Email  //銉°兗銉� Email
-                        || old.MobilePhone != local.MobilePhone  //鎵嬫満鍙风爜 Mobile_Phone__c
-                        || old.Employee_No_manual__c != local.Employee_No_manual__c  //鍛樺伐鍙风爜 Employee_No__c
-                        || old.Work_Location_manual__c != local.Work_Location_manual__c  //宸ヤ綔鍦� Work_Location__c
-                        || old.Post_picklist__c != local.Post_picklist__c  //鑱屼綅 post__c
-                        || old.Job_Category_picklist__c != local.Job_Category_picklist__c  //鑱岀 Job_Category__c
-                        || old.Hire_date_text__c != local.Hire_date_text__c  //鍏ヨ亴鏃� Hire_date__c
-                        || old.Gender_text__c != local.Gender_text__c  //鎬у埆 Gender__c
-                        || old.dept__c != local.dept__c  //鏈儴 dept__c
-                        || old.Pregnant_Rest__c != local.Pregnant_Rest__c // 鏄惁浜у亣 Pregnant_Rest__c
-                        || old.Stay_or_not__c != local.Stay_or_not__c // 鍦ㄨ亴/绂昏亴 Stay_or_not__c
-                        //|| old.Salesdepartment_Text__c != local.Salesdepartment_Text__c // 閿�鍞湰閮� Salesdepartment__c
-                        || old.AccountId != local.AccountId//瀹㈡埛浜哄憳鎹㈠鎴�
-                        || old.Isactive__c != local.Isactive__c//鐘舵�佸彉鏇�
-                        || old.ServicePlatformCode__c != local.ServicePlatformCode__c//鏈嶅姟骞冲彴缂栫爜
-                        || old.UnifiedI_Contact_ID__c != local.UnifiedI_Contact_ID__c//鏅烘収鍖荤枟缂栫爜
-                        || old.ContactType__c != local.ContactType__c//浜哄憳绫诲瀷
-                        || (old.ChargeState__c != local.ChargeState__c && local.RecordTypeId == AgencyId)//璐熻矗鐪� // 20220830 ljh LLIU-CHR8FF add
-                        ) {
-                //鑾峰彇瀹㈡埛浜哄憳鐨勮褰曠被鍨婭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);
-                // gzw 20220824 bugfix start
-                // if (!local.IsFromSPO__c && !InternalStaffRecordTypeId.equals(local.RecordTypeId)) {
-                if (!InternalStaffRecordTypeId.equals(local.RecordTypeId)) {
-                // gzw 20220824 bugfix end
-                    // 鍖婚櫌 瀹㈡埛浜哄憳 缁熶竴骞冲彴缂栫爜鏈夊�� 鍙戦�� PO
-                    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);
-                            } else {
-                                contactIdList.add(local.Id);
-                            }
-                            NFM606_IdMap.put(local.Id, local.Id);
-                        }
-                    }
-                    // 缁忛攢鍟� 瀹㈡埛浜哄憳 鎵嬫満鍙风爜鏈夊�� 鍙戦�� PO
-                    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);
-                            } else {
-                                contactIdList.add(local.Id);
-                            }
-                            NFM606_IdMap.put(local.Id, local.Id);
-                        }
-                    }
-                }
-                
-            }
-        }
-        //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);
-                // } else{
-                    // NFM606Controller.executeNotFuture('', contactIdList);
-                // }
-               //娣诲姞future 鍒ゆ柇 add for pipl  sushanhu 20220317 end 
-            }
-            if (interfaceUserUpsertContact.size() > 0) {
-                NFM606Controller.executeNotFuture('', interfaceUserUpsertContact);
-                //娣诲姞future 鍒ゆ柇 add for pipl  sushanhu 20220316 start
-                // if (!(System.isFuture()||System.isBatch())) {
-                    // NFM606Controller.executeNotFuture('', interfaceUserUpsertContact);
-                // }
-               //娣诲姞future 鍒ゆ柇 add for pipl  sushanhu 20220316 end 
-            }
-        } 
+  }
+  // 606鎺ュ彛璋冪敤闂淇 thh 20220330 end
+  // 20220830 ljh LLIU-CHR8FF add start
+  private void updateChargeState() {
+    List<Contact> contactL = new List<Contact>();
+    for (Contact nObj : newList) {
+      if (
+        nObj.RecordTypeId == AgencyId && String.isBlank(nObj.ChargeState__c)
+      ) {
+        Contact cnew = new Contact();
+        cnew.Id = nObj.Id;
+        cnew.ChargeState__c = nObj.ChargeState_F__c;
+        contactL.add(cnew);
+      }
     }
-    // 606鎺ュ彛璋冪敤闂淇 thh 20220330 end
-    // 20220830 ljh LLIU-CHR8FF add start
-    private void updateChargeState(){
-        List<Contact> contactL = new List<Contact>();
-        for (Contact nObj : newList) {
-            if(nObj.RecordTypeId == AgencyId && String.isBlank(nObj.ChargeState__c)){
-                Contact cnew = new Contact();
-                cnew.Id = nObj.Id;
-                cnew.ChargeState__c =  nObj.ChargeState_F__c;
-                contactL.add(cnew);
-            }
-        }
-        if (!contactL.isEmpty()) {
-            update contactL;
-        }
+    if (!contactL.isEmpty()) {
+      update contactL;
     }
-    // 20220830 ljh LLIU-CHR8FF add end
-
-    
-}
\ No newline at end of file
+  }
+  // 20220830 ljh LLIU-CHR8FF add end
+}

--
Gitblit v1.9.1