| | |
| | | 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; |
| | |
| | | syncToAgencyContact(); |
| | | updateDealerNum(); |
| | | sendToComPlat(); |
| | | updateChargeState();// 20220830 ljh LLIU-CHR8FF |
| | | } |
| | | |
| | | protected override void afterUpdate() { |
| | |
| | | } |
| | | } |
| | | } |
| | | if (Trigger.isInsert) { |
| | | // if (Trigger.isInsert) { |
| | | if(DoctorRecordTypeId.equals(contactnew.RecordTypeId)){ |
| | | 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, |
| | | LastName_Encrypted__c// 20220314 PI改造 by Bright |
| | | , MobilePhone_Encrypted__c // 通过姓名+手机号判断人员是否重复 thh 20220518 |
| | | FROM Contact |
| | | WHERE IsFromSPO__c = false AND AccountId IN:accountIdSet]; |
| | | if ( contactList.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 = lastNameStr + firstNameStr + MobilePhoneStr; |
| | | String contactFullName = contact.LastName_Encrypted__c + contact.MobilePhone_Encrypted__c;// 20220314 PI改造 by Bright |
| | | // 通过姓名+手机号判断人员是否重复 thh 20220518 end |
| | | if(string.isBlank(contactFullName)){ |
| | |
| | | } |
| | | |
| | | 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); |
| | | // 通过姓名+手机号判断人员是否重复 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(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 |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | public static Map<Id,Id> NFM606_IdMap = new Map<Id,Id>(); |
| | |
| | | || 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 thh 20220330 end |
| | | System.debug('local.UnifiedI_Contact_ID__c1:' + local.UnifiedI_Contact_ID__c); |
| | | System.debug('local.MobilePhone1:' + local.MobilePhone); |
| | | if (!local.IsFromSPO__c && !InternalStaffRecordTypeId.equals(local.RecordTypeId)) { |
| | | // 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)) { |
| | |
| | | } |
| | | } |
| | | // 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; |
| | | } |
| | | } |
| | | // 20220830 ljh LLIU-CHR8FF add end |
| | | |
| | | } |