buli
2023-07-11 0c4796706fc9473d069b620321a54b20a119906c
force-app/main/default/classes/ContactTriggerHandler.cls
@@ -15,7 +15,8 @@
        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
        if (Test.isRunningTest() || UserInfo.getUserId() != System.Label.ByPassTrigger) {
            //Add by Li Jun for PIPL 20220331
            mobileNumberVerification();
        }
    }
@@ -40,7 +41,6 @@
        mobileNumberVerification();
    }
    protected override void afterDelete() {
        syncToAgencyContactDelete();
        updateDealerNum();
@@ -55,13 +55,11 @@
    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)) {
@@ -70,7 +68,6 @@
                    } else {
                        ProcessingWork += ',点检' + temContact.InspectTime__c + '次';
                        ProcessingWorkWithoutNumber += ',点检';
                    }
                }
                if (temContact.InspectEquipmentTime__c != 0) {
@@ -81,7 +78,6 @@
                        ProcessingWork += ',点检设备' + temContact.InspectEquipmentTime__c + '个';
                        ProcessingWorkWithoutNumber += ',点检设备';
                    }
                }
                if (temContact.VisitTime__c != 0) {
                    if (String.isBlank(ProcessingWork)) {
@@ -91,7 +87,6 @@
                        ProcessingWork += ',上门' + temContact.VisitTime__c + '次';
                        ProcessingWorkWithoutNumber += ',上门';
                    }
                }
                if (temContact.pollingTime__c != 0) {
                    if (String.isBlank(ProcessingWork)) {
@@ -101,7 +96,6 @@
                        ProcessingWork += ',巡检' + temContact.pollingTime__c + '次';
                        ProcessingWorkWithoutNumber += ',巡检';
                    }
                }
                if (temContact.TeachingTime__c != 0) {
                    if (String.isBlank(ProcessingWork)) {
@@ -118,11 +112,8 @@
                //}
                temContact.ProcessingWork__c = ProcessingWork;
                temContact.ProcessingWorkWithoutNumber__c = ProcessingWorkWithoutNumber;
            }
        }
    }
    // 服务技师 2018/12/24  end
    private void syncToAgencyContact() {
@@ -130,12 +121,12 @@
        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
                &&
            if (
                nObj.RecordTypeId ==
                '01210000000QfWdAAK' && // Doctor
                String.isBlank(nObj.Strategic_dept_Class__c) == false
            ) {
                if (Trigger.isInsert ||
                    (Trigger.isUpdate
                if (Trigger.isInsert || (Trigger.isUpdate)) {
                        //                        && (
                        //                            oldMap.get(nObj.Id).LastName                != nObj.LastName
                        //                         || oldMap.get(nObj.Id).FirstName               != nObj.FirstName
@@ -143,8 +134,6 @@
                        //                         || 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(
@@ -254,8 +243,10 @@
            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'
            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;
@@ -269,7 +260,11 @@
        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')) {
                if (
                    contactnew.Agency_User__c != oldMap.get(contactnew.Id).Agency_User__c ||
                    (System.Label.onlyUpdate == '1' &&
                    UserInfo.getUserId() == '00510000005sEEMAA2')
                ) {
                    accountSet.add(contactnew.AccountId);
                }
            }
@@ -283,7 +278,6 @@
            }
        }
        if (Trigger.isDelete) {
            for (Contact contactold: oldList) {
                if (contactold.Agency_User__c) {
@@ -293,8 +287,11 @@
        }
        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
            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');
@@ -317,15 +314,12 @@
                update acMap.values();
            }
        }
    }
    //更新经销商用户人数字段 精琢技术 pk 2021-08-26 end
    
    //zhj 新方案改造 将手机号去重及其验证规则移动到AWS和前端 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>();
@@ -344,7 +338,11 @@
            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];
            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)){
@@ -362,8 +360,10 @@
        ID AgencyRecordTypeId = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId();
        for (Contact contactnew : newList) {
            // 手机号有值并且联系人有效,联系人的客户有效,进行手机号码验证
            if (('有效'.equals(contactnew.Isactive__c) || '有効'.equals(contactnew.Isactive__c))
                && ('有効'.equals(accMap.get(contactnew.AccountId)) || '有效'.equals(accMap.get(contactnew.AccountId)))) {
            if (
                ('有效'.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)){
@@ -484,30 +484,34 @@
            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
            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
                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
                        ) {
                //获取客户人员的记录类型ID thh 20220330 start
                ID InternalStaffRecordTypeId = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('Internal_staff').getRecordTypeId();
                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();
                //获取客户人员的记录类型ID thh 20220330 end
@@ -540,7 +544,6 @@
                        }
                    }
                }
            }
        }
        //606标记
@@ -551,6 +554,7 @@
                 //添加future 判断 add for pipl  sushanhu 20220317 start
                // if (!(System.isFuture()||System.isBatch())) {
                NFM606Controller.callout('', contactIdList);
                // } else{
                    // NFM606Controller.executeNotFuture('', contactIdList);
                // }
@@ -583,6 +587,4 @@
        }
    }
    // 20220830 ljh LLIU-CHR8FF add end
}