| | |
| | | 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() { |
| | |
| | | } |
| | | // 服务技师 2018/12/24 end |
| | | private void syncToAgencyContact() { |
| | | System.debug('enter syncToAgencyContact'); |
| | | 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 |
| | | && |
| | |
| | | ) |
| | | ) { |
| | | //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( |
| | | Agency_ID__c = '000000000000000', |
| | | Contact__c = nObj.Id, |
| | | ContactId18__c = nObj.Id, |
| | | Agency_Hospital__c = null, |
| | | Name = nObj.LastName, |
| | | Name_Encrypted__c = nObj.LastName_Encrypted__c, |
| | | //Name_Encrypted__c = nObj.LastName_Encrypted__c, |
| | | Department_Class__c = nObj.Strategic_dept_Class__c, |
| | | Type__c = nObj.Type__c, |
| | | Type_Encrypted__c = nObj.Type_Encrypted__c, |
| | | Doctor_Division1__c = nObj.Doctor_Division1__c, |
| | | Doctor_Division1_Encrypted__c = nObj.Doctor_Division1_Encrypted__c |
| | | //Type_Encrypted__c = nObj.Type_Encrypted__c, |
| | | Doctor_Division1__c = nObj.Doctor_Division1__c |
| | | //Doctor_Division1_Encrypted__c = nObj.Doctor_Division1_Encrypted__c |
| | | ); |
| | | //zhj MEBG新方案改造 2022-11-27 去掉Encrypted end |
| | | targetContactMap.put(nObj.Id, acObj); |
| | | ContactMap.put(nObj.Id, nObj); |
| | | } |
| | | } |
| | | } |
| | |
| | | List<Agency_Contact__c> temp = targetContactMap.values(); |
| | | upsert temp ContactId18__c; |
| | | system.debug('temp='+temp); |
| | | EncryptInsert(temp); |
| | | EncryptInsert(temp,ContactMap); |
| | | } |
| | | } |
| | | |
| | | static void EncryptInsert(List<Agency_Contact__c> aclist){ |
| | | static void EncryptInsert(List<Agency_Contact__c> aclist,Map < Id, Contact > ContactMap){ |
| | | if(!(system.isFuture() || system.isBatch())){ |
| | | AwsServiceTool2.EncryptPushFuture(Json.serialize(aclist), 'Agency_Contact__c'); |
| | | //zhj MEBG新方案改造 2022-11-27 start |
| | | //AwsServiceTool2.EncryptPushFuture(Json.serialize(aclist), 'Agency_Contact__c'); |
| | | |
| | | Map<String,PIHelper.PIIntegration> staticResource = new Map<String,PIHelper.PIIntegration>(); |
| | | staticResource.put('Contact',PIHelper.getPIIntegrationInfo('Contact')); |
| | | staticResource.put('Agency_Contact__c',PIHelper.getPIIntegrationInfo('Agency_Contact__c')); |
| | | Map<String, Map<String, PI_Field_Policy_Detail__c>> mmsp = new Map<String, Map<String,PI_Field_Policy_Detail__c>>(); |
| | | for (String key : staticResource.keySet()) { |
| | | mmsp.put(key, new Map<String,PI_Field_Policy_Detail__c>()); |
| | | for (PI_Field_Policy_Detail__c detail : staticResource.get(key).PIDetails) { |
| | | mmsp.get(key).put(detail.SF_Field_API_Name__c, detail); |
| | | } |
| | | } |
| | | |
| | | System.debug('mmsp = ' + mmsp); |
| | | List<AWSServiceTool2V2.EncryptPushRequestBody> EncryptPushList = new List<AWSServiceTool2V2.EncryptPushRequestBody>(); |
| | | for(Agency_Contact__c ac : aclist){ |
| | | AWSServiceTool2V2.EncryptPushRequestBody EncryptPush = new AWSServiceTool2V2.EncryptPushRequestBody(); |
| | | EncryptPush.dataId = ac.AWS_Data_Id__c != null ?ac.AWS_Data_Id__c:''; |
| | | EncryptPush.sfRecordId = ac.Id; |
| | | EncryptPush.fieldsMapping = new Map<String, List<AWSServiceTool2V2.EncryptPushRes>>(); |
| | | List<AWSServiceTool2V2.EncryptPushRes> resList = new List<AWSServiceTool2V2.EncryptPushRes>(); |
| | | AWSServiceTool2V2.EncryptPushRes res= new AWSServiceTool2V2.EncryptPushRes(); |
| | | res.isQueryDb = true; |
| | | res.value = ''; |
| | | res.table = staticResource.get('Contact').awsTableName; |
| | | res.dataId = ContactMap.get(ac.Contact__c).AWS_Data_Id__c; |
| | | res.field = mmsp.get('Contact').get('LastName').AWS_Field_API__c; |
| | | resList.add(res); |
| | | |
| | | List<AWSServiceTool2V2.EncryptPushRes> resList2 = new List<AWSServiceTool2V2.EncryptPushRes>(); |
| | | AWSServiceTool2V2.EncryptPushRes res2= new AWSServiceTool2V2.EncryptPushRes(); |
| | | res2.isQueryDb = true; |
| | | res2.value = ''; |
| | | res2.table = staticResource.get('Contact').awsTableName; |
| | | res2.dataId = ContactMap.get(ac.Contact__c).AWS_Data_Id__c; |
| | | res2.field = mmsp.get('Contact').get('Type__c').AWS_Field_API__c; |
| | | resList2.add(res2); |
| | | |
| | | List<AWSServiceTool2V2.EncryptPushRes> resList3 = new List<AWSServiceTool2V2.EncryptPushRes>(); |
| | | AWSServiceTool2V2.EncryptPushRes res3= new AWSServiceTool2V2.EncryptPushRes(); |
| | | res3.isQueryDb = true; |
| | | res3.value = ''; |
| | | res3.table = staticResource.get('Contact').awsTableName; |
| | | res3.dataId = ContactMap.get(ac.Contact__c).AWS_Data_Id__c; |
| | | res3.field = mmsp.get('Contact').get('Doctor_Division1__c').AWS_Field_API__c; |
| | | resList3.add(res3); |
| | | |
| | | System.debug('Agency_Contact__c Name = ' +mmsp.get('Agency_Contact__c').get('Name').AWS_Field_API__c); |
| | | System.debug('resList = ' + resList); |
| | | EncryptPush.fieldsMapping.put(mmsp.get('Agency_Contact__c').get('Name').AWS_Field_API__c, resList); |
| | | EncryptPush.fieldsMapping.put(mmsp.get('Agency_Contact__c').get('Type__c').AWS_Field_API__c, resList2); |
| | | EncryptPush.fieldsMapping.put(mmsp.get('Agency_Contact__c').get('Doctor_Division1__c').AWS_Field_API__c, resList3); |
| | | EncryptPushList.add(EncryptPush); |
| | | } |
| | | System.debug('EncryptPushListdataId = ' + JSON.serialize(EncryptPushList[0].dataId)); |
| | | System.debug('EncryptPushListsfRecordId = ' + JSON.serialize(EncryptPushList[0].sfRecordId)); |
| | | System.debug('EncryptPushListfieldsMapping = ' + JSON.serialize(EncryptPushList[0].fieldsMapping)); |
| | | System.debug('EncryptPushList = ' + JSON.serialize(EncryptPushList)); |
| | | if(!Test.isRunningTest()) |
| | | AwsServiceTool2V2.EncryptPushFutureV2(Json.serialize(EncryptPushList),Json.serialize(aclist), 'Agency_Contact__c'); |
| | | //zhj MEBG新方案改造 2022-11-27 end |
| | | }else{ |
| | | //Add By Li Jun for sync agency contact to aws 20220424 start |
| | | if(!Test.isRunningTest()){ |
| | | SyncAccountContactToAWS.assignOnceOneMinuteLater(aclist); |
| | | System.debug('ContactMap = ' + ContactMap); |
| | | SyncAccountContactToAWS.assignOnceOneMinuteLater(aclist,ContactMap); |
| | | } |
| | | //Add By Li Jun for sync agency contact to aws 20220424 end |
| | | } |
| | |
| | | } |
| | | //更新经销商用户人数字段 精琢技术 pk 2021-08-26 end |
| | | |
| | | //zhj 新方案改造 将手机号去重及其验证规则移动到AWS和前端 start |
| | | // 手机号去重及规则验证 及新增客户人员重名验证 |
| | | public void mobileNumberVerification(){ |
| | | |
| | |
| | | contactnew.UniqueNumber__c = null; |
| | | } |
| | | // 经销商客户人员不进行手机号校验 thh 20220517 end |
| | | } else if(DoctorRecordTypeId.equals(contactnew.RecordTypeId)){ |
| | | if(String.isNotBlank(contactnew.MobilePhone_Encrypted__c)){ |
| | | contactnew.UniqueNumber__c = contactnew.MobilePhone_Encrypted__c; |
| | | } else { |
| | | contactnew.UniqueNumber__c = null; |
| | | } |
| | | } |
| | | } |
| | | // else if(DoctorRecordTypeId.equals(contactnew.RecordTypeId)){ |
| | | // 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); |
| | | // 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) { |
| | | 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 = contact.LastName_Encrypted__c + contact.MobilePhone_Encrypted__c;// 20220314 PI改造 by Bright |
| | | // 通过姓名+手机号判断人员是否重复 thh 20220518 end |
| | | if(string.isBlank(contactFullName)){ |
| | | continue; |
| | | } |
| | | 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 (accountIdSet.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 = contact.LastName_Encrypted__c + contact.MobilePhone_Encrypted__c;// 20220314 PI改造 by Bright |
| | | // // 通过姓名+手机号判断人员是否重复 thh 20220518 end |
| | | // if(string.isBlank(contactFullName)){ |
| | | // continue; |
| | | // } |
| | | // 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); |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | for (Contact contactnew: newList) { |
| | | 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.isBlank(contactnew.MobilePhone_Encrypted__c)){ |
| | | contactnew.LastName.addError('相同名字的联系人 人员管理编码 ['+cManageCode+' ] 手机号为空已经存在,不能重复创建,请了解'); |
| | | } else{ |
| | | contactnew.LastName.addError('客户 [ '+accountName+ ' ],已存在相同名字的联系人 人员管理编码 ['+cManageCode+' ] ,不能重复创建,请了解'); |
| | | } |
| | | } |
| | | // 客户人员删除手机号时,进行判断是否存在同名且手机号为空的客户人员 thh 20220523 end |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // 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 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 |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | } |
| | | //zhj 新方案改造 将手机号去重及其验证规则移动到AWS和前端 end |
| | | |
| | | public static Map<Id,Id> NFM606_IdMap = new Map<Id,Id>(); |
| | | // 606接口调用问题修复 thh 20220330 start |
| | | private void sendToComPlat() { |
| | |
| | | || 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 |
| | | |
| | | |
| | | } |