From 2f4492ee18f90274582fcc2bb06f5e9bf64136e8 Mon Sep 17 00:00:00 2001
From: buli <137736985@qq.com>
Date: 星期五, 13 五月 2022 17:32:14 +0800
Subject: [PATCH] ProdBackup0513

---
 force-app/main/default/classes/ContactTriggerHandler.cls |  586 ++++++++++++++++++----------------------------------------
 1 files changed, 186 insertions(+), 400 deletions(-)

diff --git a/force-app/main/default/classes/ContactTriggerHandler.cls b/force-app/main/default/classes/ContactTriggerHandler.cls
index ad4e5ce..e17979a 100644
--- a/force-app/main/default/classes/ContactTriggerHandler.cls
+++ b/force-app/main/default/classes/ContactTriggerHandler.cls
@@ -1,419 +1,205 @@
-/**
- * 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;
-    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() {
-        mobileNumberVerification();
-    }
-
-    protected override void afterInsert() {
-        syncToAgencyContact();
-        updateDealerNum();
-        sendToComPlat();
-        //NFM702
-        // NFM702_Handler(this.newList , this.newMap , this.oldList , this.oldMap);
-    }
-
-    protected override void afterUpdate() {
-        syncToAgencyContact();
-        updateDealerNum();
-        sendToComPlat();
-        //NFM702
-        // NFM702_Handler(this.newList , this.newMap , this.oldList , this.oldMap);
-
-    }
-    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;
-
-
-            }
-        }
-
-    }
-    // 鏈嶅姟鎶�甯� 2018/12/24  end
-    private void syncToAgencyContact() {
-        Map < Id, Agency_Contact__c > targetContactMap = new Map < Id, Agency_Contact__c > ();
-        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);
-                    targetContactMap.put(nObj.Id, acObj);
-                }
-            }
-        }
-        if (targetContactMap.size() > 0) {
-            upsert targetContactMap.values() ContactId18__c;
-        }
-    }
-
-    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);
-                }
-            }
-        }
-
-        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
+public without sharing class ContactTriggerHandler {
     
-    // 鎵嬫満鍙峰幓閲嶅強瑙勫垯楠岃瘉 鍙婃柊澧炲鎴蜂汉鍛橀噸鍚嶉獙璇�
-    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>();
-        for (Contact contactnew: newList) {
-            // 鎵嬫満鍙� 鏈夊�� 骞朵笖 鑱旂郴浜烘湁鏁� 杩涜鎵嬫満鍙风爜楠岃瘉
-            if (String.isNotBlank(contactnew.MobilePhone) && '鏈夋晥'.equals(contactnew.Isactive__c)) {
-                Matcher isMobilePhone = pattern.matcher(contactnew.MobilePhone);
-                if (isMobilePhone.matches()) {
-                    // 灏嗘墜鏈哄彿 璧嬪�肩粰 鎵嬫満鍙峰敮涓�瀛楁
-                    contactnew.UniqueNumber__c = contactnew.MobilePhone;
-                } else {
-                    // 鎵嬫満鍙峰敮涓�瀛楁娓呯┖
-                    contactnew.UniqueNumber__c = null;
-                }    
+    public static void setIsNew(List<Contact> newList, Map<Id, Contact> newMap, List<Contact> oldList, Map<Id, Contact> oldMap) {
+        for (Contact newCon : newList) {
+            // String new_profileId = UserInfo.getProfileId().subString(0,15);
+            //calendarUtil.getMemberProfileID  杩欓噷鐢ㄥ埌鐨勪汉鍛業D 鍜岃幏鍙栧埌鐨勭畝妗D閮芥槸15浣嶇殑
+            String new_profileId = calendarUtil.getMemberProfileID(UserInfo.getUserId().subString(0,15));
+            
+            if (new_profileId.subString(0,15) == System.label.Market_Department || new_profileId.subString(0,15) == System.label.Market_Department1 || new_profileId.subString(0,15) == System.label.Service_Owner ||
+                UserInfo.getUserType() == 'PowerPartner') {
+                newCon.IsNew__c = true;
             } else {
-                // 鎵嬫満鍙� 鏃犲�� 鎴栬�� 鑱旂郴浜轰笉鏄湁鏁� 鎵嬫満鍙峰敮涓�瀛楁娓呯┖
-                contactnew.UniqueNumber__c = null;
+                newCon.MobilePhoneD__c = newCon.MobilePhone;
+                newCon.OtherPhoneD__c = newCon.OtherPhone;
+                newCon.FaxD__c = newCon.Fax;
+                newCon.EmailD__c = newCon.Email;
+                newCon.PhoneD__c = newCon.Phone;
+                newCon.TitleD__c = newCon.Title;
+                newCon.Address1D__c = newCon.Address1__c;
+                newCon.Address2D__c = newCon.Address2__c;
+                newCon.Address3D__c = newCon.Address3__c;
+                newCon.PostcodeD__c = newCon.Postcode__c;
+                newCon.ContactStatusD__c = newCon.ContactStatus__c;
+                newCon.CancelReasonD__c = newCon.CancelReason__c;
+                if(new_profileId.subString(0,15) == '00e28000000YKLo'){
+                    newCon.IsNew__c = true;
+                }
+            }
+        }
+    }
+    
+    public static void updateForDealer(List<Contact> newList, Map<Id, Contact> newMap, List<Contact> oldList, Map<Id, Contact> oldMap) {
+        //鐜嬮箯浼� 娣诲姞userId 鏈嶅姟閮ㄤ慨鏀硅仈绯讳汉閲嶆柊瀹℃壒 鍒ゆ柇褰撳墠淇敼鐨勭櫥闄嗕汉鏄惁鏄瓩瀛︽磱  鍚存檽涓�
+        String userId = UserInfo.getUserId(); 
+        for (Contact newCon : newList) {
+            Contact oldCon = oldMap.get(newCon.Id);
+            
+            if(newCon.AccountStaut__c != 'Pass' && newCon.StatusD__c != oldCon.StatusD__c && newCon.StatusD__c == 'Pass' ){
+                newCon.addError('璇峰厛瀹℃壒瀵瑰簲鐨勫鎴�');
+            }
+
+            if (newCon.MobilePhoneD__c != oldCon.MobilePhoneD__c ||
+                newCon.OtherPhoneD__c != oldCon.OtherPhoneD__c ||
+                newCon.FaxD__c != oldCon.FaxD__c ||
+                newCon.EmailD__c != oldCon.EmailD__c ||
+                newCon.PhoneD__c != oldCon.PhoneD__c ||
+                newCon.TitleD__c != oldCon.TitleD__c ||
+                newCon.Address1D__c != oldCon.Address1D__c ||
+                newCon.Address2D__c != oldCon.Address2D__c ||
+                newCon.Address3D__c != oldCon.Address3D__c ||
+                newCon.PostcodeD__c != oldCon.PostcodeD__c ||
+                newCon.ContactStatusD__c != oldCon.ContactStatusD__c ||
+                newCon.CancelReasonD__c != oldCon.CancelReasonD__c) {
+                // String new_profileId = UserInfo.getProfileId().subString(0,15);
+                //鏂扮殑鑾峰彇绠�妗D  calendarUtil.getMemberProfileID  杩欓噷鐢ㄥ埌鐨勪汉鍛業D 鍜岃幏鍙栧埌鐨勭畝妗D閮芥槸15浣嶇殑
+                String new_profileId = calendarUtil.getMemberProfileID(UserInfo.getUserId().subString(0,15));
+                //鐜嬮箯浼� 娣诲姞 && !((oldCon.ProductSegment__c == 'BS' || oldCon.ProductSegment__c == 'NDT' || oldCon.ProductSegment__c = 'ANI') && oldCon.isServiceCreate__c == true)
+                //鏈嶅姟閮ㄤ慨鏀硅仈绯讳汉淇℃伅 LS銆丯DT銆丄NI鏃犻渶瀹℃壒,璺宠繃瀹℃壒鐘舵�佸彉鑽夋
+                if (( new_profileId.subString(0,15) == System.label.Service_Owner
+                    || UserInfo.getUserType() == 'PowerPartner' || userId =='00528000000YWC6' || userId =='00528000000YWE7')
+                    && !((oldCon.ProductSegment__c == 'BS' || oldCon.ProductSegment__c == 'NDT' || oldCon.ProductSegment__c == 'ANI') && oldCon.isServiceCreate__c == true)) {
+                    newCon.StatusD__c = 'Draft';
+                }
             }
             
-
-
-            if (Trigger.isInsert) {
-                accountIdSet.add(contactnew.AccountId);
+            if (newCon.MobilePhone != oldCon.MobilePhone) {
+                newCon.MobilePhoneD__c = newCon.MobilePhone;
+            }
+            if (newCon.OtherPhone != oldCon.OtherPhone) {
+                newCon.OtherPhoneD__c = newCon.OtherPhone;
+            }
+            if (newCon.Fax != oldCon.Fax) {
+                newCon.FaxD__c = newCon.Fax;
+            }
+            if (newCon.Email != oldCon.Email) {
+                newCon.EmailD__c = newCon.Email;
+            }
+            if (newCon.Phone != oldCon.Phone) {
+                newCon.PhoneD__c = newCon.Phone;
+            }
+            if (newCon.Title != oldCon.Title) {
+                newCon.TitleD__c = newCon.Title;
+            }
+            if (newCon.Address1__c != oldCon.Address1__c) {
+                newCon.Address1D__c = newCon.Address1__c;
+            }
+            if (newCon.Address2__c != oldCon.Address2__c) {
+                newCon.Address2D__c = newCon.Address2__c;
+            }
+            if (newCon.Address3__c != oldCon.Address3__c) {
+                newCon.Address3D__c = newCon.Address3__c;
+            }
+            if (newCon.Postcode__c != oldCon.Postcode__c) {
+                newCon.PostcodeD__c = newCon.Postcode__c;
+            }
                 
-            }   
-        }
-        // 鏂板鑱旂郴浜烘椂锛�
-        if (accountIdSet.size() > 0) {
-            List<Contact> contactList = [SELECT Id,AccountId,FullName__c,LastName,FirstName,Account.Name,CManageCode__c,IsFromSPO__c 
-                                        FROM Contact 
-                                        WHERE IsFromSPO__c = false AND AccountId IN:accountIdSet];
-            if ( contactList.size() > 0) {
-                for(Contact contact :contactList){
-
-                    String lastNameStr = String.isNotBlank(contact.LastName) ? contact.LastName:'';
-                    String firstNameStr = String.isNotBlank(contact.FirstName) ? contact.FirstName:'';
-                    String contactFullName = lastNameStr + firstNameStr;
-                    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);
-                }
+            if (newCon.ContactStatus__c != oldCon.ContactStatus__c) {
+                newCon.ContactStatusD__c = newCon.ContactStatus__c;
+            }
+            if (newCon.CancelReason__c != oldCon.CancelReason__c) {
+                newCon.CancelReasonD__c = newCon.CancelReason__c;
             }
         }
-
-        for (Contact contactnew: newList) {
-            
-            if (Trigger.isInsert) {
-                
-                String accountId = String.valueOf(contactnew.AccountId).substring(0, 15);
-
-                if (accountContactMap.containsKey(accountId)) {
-                    Map<String,Contact> contactFullNameMap =  accountContactMap.get(accountId);
-                    String lastNameStr = String.isNotBlank(contactnew.LastName) ? contactnew.LastName:'';
-                    String firstNameStr = String.isNotBlank(contactnew.FirstName) ? contactnew.FirstName:'';
-                    String contactFullName = lastNameStr + firstNameStr;
-
-                    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)) {
-                            contactnew.LastName.addError('瀹㈡埛 [ '+accountName+ ' ],宸插瓨鍦ㄧ浉鍚屽悕瀛楃殑鑱旂郴浜� 浜哄憳绠$悊缂栫爜 ['+cManageCode+' ] 锛屼笉鑳介噸澶嶅垱寤猴紝璇蜂簡瑙�');     
-                        }
-                           
-                    }
-                }
-                
-            }   
-        }
-
-        
     }
+    
+    public static void dealerContactApproval(List<Contact> newList, Map<Id, Contact> newMap, List<Contact> oldList, Map<Id, Contact> oldMap) {
+        List<String> accIdList = new List<String>();
+        for (Contact newCon : newList) {
+            accIdList.add(newCon.AccountId);
+        }
+        // 鐜版湁瀹㈡埛灏忕粍
+        Map<String, String> accsMap = new Map<String, String>();
+        //List<AccountTeamMember> atmList = [select Id, AccountId, UserId from AccountTeamMember where AccountId in :accIdList];
+        List<AccountShare> accsList = [select id, accountId, UserOrGroupId, AccountAccessLevel, RowCause from AccountShare where AccountId in :accIdList and RowCause = 'Team'];
+        for (AccountShare accs : accsList) {
+            accsMap.put(accs.AccountId + '' + accs.UserOrGroupId, accs.Id);
+        }
+        // 闇�瑕佹洿鏂板鎴峰皬缁�
+//      List<AccountShare> updList = new List<AccountShare>();
 
+        //鏂扮殑鑾峰彇绠�妗D calendarUtil.getMemberProfileID  杩欓噷鐢ㄥ埌鐨勪汉鍛業D 鍜岃幏鍙栧埌鐨勭畝妗D閮芥槸15浣嶇殑  
+        // String new_profileId = UserInfo.getProfileId().subString(0,15);
+        String new_profileId = calendarUtil.getMemberProfileID(UserInfo.getUserId().subString(0,15));
 
-    public static Map<Id,Id> NFM606_IdMap = new Map<Id,Id>();
-    private void sendToComPlat() {
-        List<Id> contactIdList = new List<Id>();
-        List<String>    interfaceUserUpsertContact = new List<String>();
-        for (Contact local: newList) {
+        for (Contact newCon : newList) {
+            Contact oldCon = oldMap.get(newCon.Id);
 
-            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//浜哄憳绫诲瀷
-                        
-                        ) {
-                if (!local.IsFromSPO__c && !'01210000000QtkyAAC'.equals(local.RecordTypeId)) {
-
-                    // 鍖婚櫌 瀹㈡埛浜哄憳 缁熶竴骞冲彴缂栫爜鏈夊�� 鍙戦�� PO
-                    if ('01210000000QfWdAAK'.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);
+            if (new_profileId.subString(0,15) == System.label.Market_Department || new_profileId.subString(0,15) == System.label.Market_Department1){
+                newCon.MobilePhone = newCon.MobilePhoneD__c;
+                newCon.OtherPhone = newCon.OtherPhoneD__c;
+                newCon.Fax = newCon.FaxD__c;
+                newCon.Email = newCon.EmailD__c;
+                newCon.Phone = newCon.PhoneD__c;
+                newCon.Title = newCon.TitleD__c;
+                newCon.Address1__c = newCon.Address1D__c;
+                newCon.Address2__c = newCon.Address2D__c;
+                newCon.Address3__c = newCon.Address3D__c;
+                newCon.Postcode__c = newCon.PostcodeD__c;
+                
+                newCon.ContactStatus__c = newCon.ContactStatusD__c;
+                newCon.CancelReason__c = newCon.CancelReasonD__c;
+            } else if (newCon.StatusD__c != oldCon.StatusD__c) {
+                if (newCon.StatusD__c == 'Submit') {
+                    //newCon.DealerSelectOwner__c = newCon.Account.DealerSelectOwner__c;
+                }
+                if (newCon.StatusD__c == 'Pass') {
+                    // 鎵瑰噯杩囩▼鑲畾鏄竴鏉′竴鏉℃壒鍑嗙殑锛屾墍浠ヨ繖閲屽啀寰幆涓啓浜唖elect鏂�
+                    
+                    List<Account> accList = [select Id, IsNew__c, AccountStatus__c from Account where Id = :newCon.AccountId];
+                    if (accList.size() > 0 ) {
+                        Account acc = accList[0];
+                        if (acc.IsNew__c == true || (acc.AccountStatus__c == 'Cancel' && newCon.ContactStatusD__c != 'Cancel')) {
+                            newCon.addError('瀹㈡埛鏃犳晥鎴栨湭閫氳繃瀹℃壒锛屼笉鑳芥壒鍑嗗綋鍓嶈仈绯讳汉銆�');
                         }
                     }
-                    // 缁忛攢鍟� 瀹㈡埛浜哄憳 鎵嬫満鍙风爜鏈夊�� 鍙戦�� PO
-                    if ('01210000000QfWiAAK'.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);
-                        }
+                    
+                    newCon.MobilePhone = newCon.MobilePhoneD__c;
+                    newCon.OtherPhone = newCon.OtherPhoneD__c;
+                    newCon.Fax = newCon.FaxD__c;
+                    newCon.Email = newCon.EmailD__c;
+                    newCon.Phone = newCon.PhoneD__c;
+                    newCon.Title = newCon.TitleD__c;
+                    newCon.Address1__c = newCon.Address1D__c;
+                    newCon.Address2__c = newCon.Address2D__c;
+                    newCon.Address3__c = newCon.Address3D__c;
+                    newCon.Postcode__c = newCon.PostcodeD__c;
+                    
+                    newCon.ContactStatus__c = newCon.ContactStatusD__c;
+                    newCon.CancelReason__c = newCon.CancelReasonD__c;
+                    
+//                  if (accsMap.containsKey(newCon.AccountId + '' + newCon.OwnerId) == true && newCon.IsNew__c == true) {
+//                      AccountShare upd = new AccountShare(
+//                          Id = accsMap.get(newCon.AccountId + '' + newCon.OwnerId),
+//                          AccountAccessLevel = 'Edit'
+//                      );
+//                      updList.add(upd);
+//                  }
+                    
+                    if (newCon.IsNew__c = true) {
+                        newCon.IsNew__c = false;
                     }
                 }
-                
+                if (newCon.StatusD__c == 'Reject' && newCon.IsNew__c == false) {
+                    newCon.MobilePhoneD__c = newCon.MobilePhone;
+                    newCon.OtherPhoneD__c = newCon.OtherPhone;
+                    newCon.FaxD__c = newCon.Fax;
+                    newCon.EmailD__c = newCon.Email;
+                    newCon.PhoneD__c = newCon.Phone;
+                    newCon.TitleD__c = newCon.Title;
+                    newCon.Address1D__c = newCon.Address1__c;
+                    newCon.Address2D__c = newCon.Address2__c;
+                    newCon.Address3D__c = newCon.Address3__c;
+                    newCon.PostcodeD__c = newCon.Postcode__c;
+                    
+                    newCon.ContactStatusD__c = newCon.ContactStatus__c;
+                    newCon.CancelReasonD__c = newCon.CancelReason__c;
+                }
             }
         }
-        
-        if(!System.Test.isRunningTest()){
-            // NFM606Controller.executeNotFuture('', contactIdList);
-            if (contactIdList.size() > 0) {
-                NFM606Controller.callout('', contactIdList);
-            }
-            if (interfaceUserUpsertContact.size() > 0) {
-                NFM606Controller.executeNotFuture('', interfaceUserUpsertContact);
-            }
-        } 
-        
+        // 鏇存柊瀹㈡埛灏忕粍
+//      if (updList!= null && updList.size() > 0) {
+//          update updList;
+//      }
     }
-
-
-    public void NFM702_Handler(List<Contact> newList, Map<Id, Contact> newMap, List<Contact> oldList, Map<Id, Contact> oldMap){
-        List<Contact> conIdList = new List<Contact>();
-        List<String> idList = new List<String>();
-        String LOG_TYPE = 'NFM702';
-        // iflog.Log__c = '---------';
-        String ConTypeId = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('Doctor').getRecordTypeId();
-        if (Trigger.isUpdate && Trigger.isAfter) {
-            if (newList.size() > 0) {
-                for (Contact con : newList) {
-                    Contact oldCon = oldMap.get(con.Id);
-                    if ((con.RecordTypeId.equals(ConTypeId)) && (con.FullName__c != oldCon.FullName__c || con.Phone != oldCon.Phone || con.Department__c != oldCon.Department__c || con.Isactive__c != oldCon.Isactive__c)) {
-                        idList.add(con.Id);
-                    }
-                }
-            }
-        }
-        if(Trigger.isInsert && Trigger.isAfter){
-            if (newList.size() > 0) {
-                for (Contact con : newList) {
-                    if(con.RecordTypeId.equals(ConTypeId)){
-                        idList.add(con.Id);
-                    }
-                }
-            }
-        }
-        if (idList.size() > 0) {
-            BatchIF_Log__c iflog = new BatchIF_Log__c();
-            iflog.Log__c = '瑙﹀彂鎴愬姛';
-            iflog.Type__c = LOG_TYPE;
-            insert iflog;
-            NFM702Controller.callout(iflog.Id, idList);
-        }
-
-    }
-
 }
\ No newline at end of file

--
Gitblit v1.9.1