| | |
| | | /** |
| | | * 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 这里用到的人员ID 和获取到的简档ID都是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); |
| | | //新的获取简档ID calendarUtil.getMemberProfileID 这里用到的人员ID 和获取到的简档ID都是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、NDT、ANI无需审批,跳过审批状态变草案 |
| | | 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>(); |
| | | |
| | | //新的获取简档ID calendarUtil.getMemberProfileID 这里用到的人员ID 和获取到的简档ID都是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') { |
| | | // 批准过程肯定是一条一条批准的,所以这里再循环中写了select文 |
| | | |
| | | 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); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |