涂煌豪
2022-03-28 ae181f917b1b6ee90b2d6c273e0e9f61f29b4e33
606接口报错修改,客户人员手机号校验
2个文件已修改
156 ■■■■■ 已修改文件
force-app/main/default/classes/ContactTriggerHandler.cls 102 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/NFM606Batch.cls 54 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/ContactTriggerHandler.cls
@@ -14,25 +14,25 @@
    }
    protected override void beforeInsert() {
        mobileNumberVerification();
        sendToComPlat();
    }
    protected override void afterInsert() {
        syncToAgencyContact();
        updateDealerNum();
        sendToComPlat();
    }
    protected override void afterUpdate() {
        syncToAgencyContact();
        updateDealerNum();
        sendToComPlat();
    }
    protected override void beforeUpdate() {
        // 服务技师 2018/12/24  Start
        UpdateProcessingWork();
        // 服务技师 2018/12/24  end
        mobileNumberVerification();
        sendToComPlat();
    }
@@ -235,7 +235,7 @@
        //     for(User us1: userList){
        //         userMap.put(us1.ContactId, us1);
        //     }
        // }
        // }
        //查找联系人对象上对应的有效客户;医院直接使用有效/无效字段、经销商使用有效/无效公式字段
        List<String> accIdList = new List<String>();
        Map<String,String> accMap= new Map<String,String>();
@@ -256,30 +256,37 @@
                }
            }
        }
        for (Contact contactnew: newList) {
            // 手机号 有值 并且 联系人有效 联系人的客户有效 进行手机号码验证
            if (String.isNotBlank(contactnew.MobilePhone) && ('有效'.equals(contactnew.Isactive__c) ||'有効'.equals(contactnew.Isactive__c))
                && '有効'.equals(accMap.get(contactnew.AccountId))) {
                Matcher isMobilePhone = pattern.matcher(contactnew.MobilePhone);
                if (isMobilePhone.matches()) {
                    // 将手机号 赋值给 手机号唯一字段
                    contactnew.UniqueNumber__c = contactnew.MobilePhone;
                } else {
                    // 手机号唯一字段清空
                    contactnew.UniqueNumber__c = null;
                }
            } else {
                // 手机号 无值 或者 联系人不是有效 手机号唯一字段清空
                contactnew.UniqueNumber__c = null;
        //手机号唯一校验-医院下新建客户人员校验使用加密手机号,经销商使用普通手机号 thh 20220328 start
        ID recordTypeId = 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(contactnew.RecordTypeId.equals(recordTypeId)){
                    if(String.isNotBlank(contactnew.MobilePhone)){
                        Matcher isMobilePhone = pattern.matcher(contactnew.MobilePhone);
                        if (isMobilePhone.matches()) {
                            contactnew.UniqueNumber__c = contactnew.MobilePhone;
                        } else {
                            // 手机号唯一字段清空
                            contactnew.UniqueNumber__c = null;
                        }
                    } else {
                        contactnew.UniqueNumber__c = null;
                    }
                } else{
                    if(String.isNotBlank(contactnew.MobilePhone_Encrypted__c)){
                        contactnew.UniqueNumber__c = contactnew.MobilePhone_Encrypted__c;
                    } else {
                        contactnew.UniqueNumber__c = null;
                    }
                }
            }
            if (Trigger.isInsert) {
                accountIdSet.add(contactnew.AccountId);
                accountIdSet.add(contactnew.AccountId);
            }   
        }
        //手机号唯一校验-医院下新建客户人员校验使用加密手机号,经销商使用普通手机号 thh 20220328 end
        // 新增联系人时,
        if (accountIdSet.size() > 0) {
            List<Contact> contactList = [SELECT Id,AccountId,FullName__c,LastName,FirstName,Account.Name,CManageCode__c,IsFromSPO__c,
@@ -340,9 +347,8 @@
    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>();
        List<String> interfaceUserUpsertContact = new List<String>();
        for (Contact local: newList) {
            Contact old = null;
            if (Trigger.isUpdate) {
                old = oldMap.get(local.Id);
@@ -369,52 +375,50 @@
                        || old.ContactType__c != local.ContactType__c//人员类型
                        
                        ) {
                //624调用606问题修复 thh 20220328 start
                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)) {
                            //624调用606问题修复 thh 20220325 start
                            // if(UserInfo.getProfileId().equals(System.Label.ProfileId_SystemAdmin)){
                            //     interfaceUserUpsertContact.add(local.Id);
                            // } else {
                                contactIdList.add(local.Id);
                            // contactIdList.add(local.Id);
                            // }
                            //624调用606问题修复 thh 20220325 end
                            local.trigger606Flag__c = true;
                            NFM606_IdMap.put(local.Id, local.Id);
                        }
                    }
                    // 经销商 客户人员 手机号码有值 发送 PO
                    if ('01210000000QfWiAAK'.equals(local.RecordTypeId) && String.isNotBlank(local.MobilePhone)) {
                        if (!NFM606_IdMap.containsKey(local.Id)) {
                            //624调用606问题修复 thh 20220325 start
                            // if(UserInfo.getProfileId().equals(System.Label.ProfileId_SystemAdmin)){
                            //     interfaceUserUpsertContact.add(local.Id);
                            // } else {
                                contactIdList.add(local.Id);
                            //     contactIdList.add(local.Id);
                            // }
                            //624调用606问题修复 thh 20220325 end
                            local.trigger606Flag__c = true;
                            NFM606_IdMap.put(local.Id, local.Id);
                        }
                    }
                }
                //624调用606问题修复 thh 20220328 end
            }
        }
        if(!System.Test.isRunningTest()){
            // NFM606Controller.executeNotFuture('', contactIdList);
            //624调用606问题修复 thh 20220325 start
            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
            }
        //606标记
        // if(!System.Test.isRunningTest()){
        //     // NFM606Controller.executeNotFuture('', contactIdList);
        //     //624调用606问题修复 thh 20220325 start
        //     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
@@ -425,7 +429,7 @@
               
            // }
            //624调用606问题修复 thh 20220325 end 
        }
        // }
        
    }
force-app/main/default/classes/NFM606Batch.cls
@@ -1,11 +1,19 @@
global class NFM606Batch implements Database.Batchable < sObject > , Database.AllowsCallouts {
    public String query;
    // public String query;
    // public List < String > IdList;
    // public String executeType;
    // public String idStr;
    // global NFM606Batch() {
    // }
    // Boolean IsNeedExecute = false; // 2021-03-03  mzy  WLIG-BYHD79  SFDC环境batch合并调查  是否符合执行条件
    // public SubAuthorizedBatch(Boolean NeedExecute) {
    //     this.IsNeedExecute = NeedExecute;
    // }
    public ID recordTypeId;
    global NFM606Batch() {
        ID recordTypeId = Schema.SObjectType.Contact.getRecordTypeInfosByName().get('社内员工').getRecordTypeId();
    }
    // global NFM606Batch(String executeType) {
    //     this.executeType = executeType;
    // }
@@ -26,9 +34,11 @@
        //     ]);
        // } else if ('Contact'.equals(executeType)) {
        //     // 联系人接口
        //     return Database.getQueryLocator([
        //         select Id, Isactive__c from Contact where Isactive__c = '有效' AND RecordTypeId != '01210000000QtkyAAC' AND MobilePhone != ''
        //     ]);
        return Database.getQueryLocator([
            select Id, trigger606Flag__c from Contact where Isactive__c = '有效' AND RecordTypeId != :recordTypeId
                AND MobilePhone != '' AND trigger606Flag__c = true
        ]);
        // } else if ('Inspection_Report'.equals(executeType)) {
        //     // 点检报告接口
        //     return Database.getQueryLocator([
@@ -60,11 +70,32 @@
        //     ]);
        // }
        // // NewMaintenanceReport_Task__c
        return Database.getQueryLocator(query);
        // return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext BC, list < Sobject > scope) {
    global void execute(Database.BatchableContext BC, List<Contact> contactList) {
        List<String> IdList = new List<String>();
        List<Contact> trigger606List = new List<Contact>();
        List<Contact> updateContactList = new List<Contact>();
        if (contactList != null && contactList.size() > 0) {
            for (Contact con : contactList) {
                if(con.trigger606Flag__c){
                    IdList.add(con.Id);
                    trigger606List.add(con);
                }
            }
        }
        if(IdList.size() > 0){
            NFM606Controller.executeNotFuture(null, IdList);
            for(Contact con : trigger606List){
                con.trigger606Flag__c = false;
                updateContactList.add(con);
            }
        }
        if(updateContactList.size() > 0){
            update updateContactList;
        }
        // List < String > sobjectList = new List < String > ();
        // for (Sobject sobj: scope) {
        //     sobjectList.add(sobj.Id);
@@ -81,11 +112,8 @@
        //         //     NFM621Controller.executefuture('', employeeNoList);
        //         // }
        //         NFM621Controller.executefuture('', sobjectList);
        //     } else if ('Contact'.equals(executeType)) {
        //         NFM606Controller.executeNotFuture(null, sobjectList);
        //     } else if ('Inspection_Report'.equals(executeType)) {
        //         NFM602Controller.executeNotFuture(null, sobjectList);
        //     } else if ('NewMaintenanceReport_Task'.equals(executeType)) {
@@ -93,11 +121,7 @@
        //     } else if ('Repair'.equals(executeType)) {
        //         NFM603Controller.executefuture(null, sobjectList);
        //     }
        // }
    }
    global void finish(Database.BatchableContext BC) {