| | |
| | | } |
| | | } |
| | | // if (Trigger.isInsert) { |
| | | accountIdSet.add(contactnew.AccountId); |
| | | 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) { |
| | | for (Contact contactnew: newList) { |
| | | 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 cManageCode = contactFullNameMap.get(contactFullName).CManageCode__c; |
| | | // 跳过测试程序 和 SPO通过203接口创建的联系人 |
| | | if (!(Test.isRunningTest() || contactnew.IsFromSPO__c)) { |
| | | if(Trigger.isInsert) { |
| | | // if(Trigger.isInsert) { |
| | | contactnew.LastName.addError('客户 [ '+accountName+ ' ],已存在相同名字的联系人 人员管理编码 ['+cManageCode+' ] ,不能重复创建,请了解'); |
| | | } |
| | | // } |
| | | // 客户人员删除手机号时,进行判断是否存在同名且手机号为空的客户人员 thh 20220523 start |
| | | if(Trigger.isUpdate && !UserInfo.getUserId().equals(System.Label.interfaceUserID)) { |
| | | if (String.isBlank(contactnew.MobilePhone_Encrypted__c)){ |
| | | contactnew.LastName.addError('相同名字的联系人 人员管理编码 ['+cManageCode+' ] 手机号为空已经存在,不能重复创建,请了解'); |
| | | } else{ |
| | | contactnew.LastName.addError('客户 [ '+accountName+ ' ],已存在相同名字的联系人 人员管理编码 ['+cManageCode+' ] ,不能重复创建,请了解'); |
| | | } |
| | | } |
| | | // 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 |
| | | } |
| | | } |