| | |
| | | public without sharing class AgencyContactHandler extends Oly_TriggerHandler { |
| | | @TestVisible |
| | | private Map<Id, Agency_Contact__c> newMap; |
| | | @TestVisible |
| | | private Map<Id, Agency_Contact__c> oldMap; |
| | | @TestVisible |
| | | private List<Agency_Contact__c> newList; |
| | | @TestVisible |
| | | private List<Agency_Contact__c> oldList; |
| | | |
| | | public AgencyContactHandler() { |
| | |
| | | } |
| | | |
| | | protected override void beforeInsert() { |
| | | beforeSetValue(); |
| | | //zhj MEBG新方案改造 2022-11-30 start |
| | | //beforeSetValue(); |
| | | //zhj MEBG新方案改造 2022-11-30 end |
| | | } |
| | | protected override void beforeUpdate() { |
| | | beforeSetValue(); |
| | | //zhj MEBG新方案改造 2022-11-30 start |
| | | //beforeSetValue(); |
| | | //zhj MEBG新方案改造 2022-11-30 end |
| | | shareAgency_Contact_ToRole(this.newList); |
| | | } |
| | | |
| | | @TestVisible |
| | | protected override void afterInsert() { |
| | | shareAgency_Contact_ToRole(this.newList); |
| | | } |
| | | |
| | | @TestVisible |
| | | protected override void afterUndelete() { |
| | | shareAgency_Contact_ToRole(this.newList); |
| | | } |
| | | |
| | | private void beforeSetValue() { |
| | | Set<String> nameSet = new Set<String>(); |
| | | Set<String> ahIdSet = new Set<String>(); |
| | | Map<String, Agency_Contact__c> keyMap = new Map<String, Agency_Contact__c>(); |
| | | for (Agency_Contact__c nObj : newList) { |
| | | if (String.isBlank(nObj.Agency_ID__c)) { |
| | | if (String.isBlank(nObj.getCloneSourceId()) == false) { |
| | | // 要注意 画面からしかないので、ここで selectする |
| | | Agency_Contact__c srcObj = [Select Id, Agency_Hospital__c, Contact__c, Hospital_ID18__c, Hospital_Name__c from Agency_Contact__c where Id = :nObj.getCloneSourceId()]; |
| | | if (String.isBlank(nObj.Agency_Hospital__c) == false |
| | | && String.isBlank(srcObj.Agency_Hospital__c) |
| | | && nObj.Hospital_ID18__c != srcObj.Hospital_ID18__c) { |
| | | nObj.Agency_Hospital__c.addError('请选择:' + srcObj.Hospital_Name__c); |
| | | } |
| | | if (String.isBlank(srcObj.Contact__c) == false) { |
| | | nObj.Contact__c = srcObj.Contact__c; |
| | | } |
| | | } |
| | | nObj.Agency_ID__c = nObj.Agency_ID_F__c; |
| | | } |
| | | nameSet.add(nObj.Name_Encrypted__c); |
| | | ahIdSet.add(nObj.Agency_Hospital__c); |
| | | // PIPL update Yin Mingjie 21/02/2022 start |
| | | // keyMap.put(nObj.Agency_Hospital__c + nObj.Name, nObj); |
| | | keyMap.put(nObj.Agency_Hospital__c + nObj.Name_Encrypted__c, nObj); |
| | | // PIPL update Yin Mingjie 21/02/2022 end |
| | | } |
| | | //zhj MEBG新方案改造 2022-11-30 start |
| | | // private void beforeSetValue() { |
| | | // Set<String> nameSet = new Set<String>(); |
| | | // Set<String> ahIdSet = new Set<String>(); |
| | | // Map<String, Agency_Contact__c> keyMap = new Map<String, Agency_Contact__c>(); |
| | | // for (Agency_Contact__c nObj : newList) { |
| | | // if (String.isBlank(nObj.Agency_ID__c)) { |
| | | // if (String.isBlank(nObj.getCloneSourceId()) == false) { |
| | | // // 要注意 画面からしかないので、ここで selectする |
| | | // Agency_Contact__c srcObj = [Select Id, Agency_Hospital__c, Contact__c, Hospital_ID18__c, Hospital_Name__c from Agency_Contact__c where Id = :nObj.getCloneSourceId()]; |
| | | // if (String.isBlank(nObj.Agency_Hospital__c) == false |
| | | // && String.isBlank(srcObj.Agency_Hospital__c) |
| | | // && nObj.Hospital_ID18__c != srcObj.Hospital_ID18__c) { |
| | | // nObj.Agency_Hospital__c.addError('请选择:' + srcObj.Hospital_Name__c); |
| | | // } |
| | | // if (String.isBlank(srcObj.Contact__c) == false) { |
| | | // nObj.Contact__c = srcObj.Contact__c; |
| | | // } |
| | | // } |
| | | // nObj.Agency_ID__c = nObj.Agency_ID_F__c; |
| | | // } |
| | | // nameSet.add(nObj.Name_Encrypted__c); |
| | | // ahIdSet.add(nObj.Agency_Hospital__c); |
| | | // // PIPL update Yin Mingjie 21/02/2022 start |
| | | // // keyMap.put(nObj.Agency_Hospital__c + nObj.Name, nObj); |
| | | // keyMap.put(nObj.Agency_Hospital__c + nObj.Name_Encrypted__c, nObj); |
| | | // // PIPL update Yin Mingjie 21/02/2022 end |
| | | // } |
| | | |
| | | // PIPL update Yin Mingjie 21/02/2022 start |
| | | // List<Agency_Contact__c> ars = [select Id, Agency_Hospital__r.Name, Agency_Hospital__c, Name from Agency_Contact__c |
| | | // where Name in :nameSet and Agency_Hospital__c in :ahIdSet and Agency_Hospital__c != null]; |
| | | List<Agency_Contact__c> ars = [select Id, Agency_Hospital__r.Name, Agency_Hospital__c, Name, Name_Encrypted__c from Agency_Contact__c |
| | | where Name_Encrypted__c in :nameSet and Agency_Hospital__c in :ahIdSet and Agency_Hospital__c != null]; |
| | | // PIPL update Yin Mingjie 21/02/2022 end |
| | | for (Agency_Contact__c ar : ars) { |
| | | // PIPL update Yin Mingjie 21/02/2022 start |
| | | // String key = ar.Agency_Hospital__c + ar.Name; |
| | | String key = ar.Agency_Hospital__c + ar.Name_Encrypted__c; |
| | | // PIPL update Yin Mingjie 21/02/2022 end |
| | | //system.debug('========3333333key'+key); |
| | | if (keyMap.containsKey(key)) { |
| | | Agency_Contact__c a = keyMap.get(key); |
| | | if (a.Id == ar.Id) continue; |
| | | //system.debug('========3333333'); |
| | | a.addError('该客户人员名字已存在,在'+ar.Agency_Hospital__r.Name+'医院,请修改'); |
| | | } |
| | | } |
| | | } |
| | | // // PIPL update Yin Mingjie 21/02/2022 start |
| | | // // List<Agency_Contact__c> ars = [select Id, Agency_Hospital__r.Name, Agency_Hospital__c, Name from Agency_Contact__c |
| | | // // where Name in :nameSet and Agency_Hospital__c in :ahIdSet and Agency_Hospital__c != null]; |
| | | // List<Agency_Contact__c> ars = [select Id, Agency_Hospital__r.Name, Agency_Hospital__c, Name, Name_Encrypted__c from Agency_Contact__c |
| | | // where Name_Encrypted__c in :nameSet and Agency_Hospital__c in :ahIdSet and Agency_Hospital__c != null]; |
| | | // // PIPL update Yin Mingjie 21/02/2022 end |
| | | // for (Agency_Contact__c ar : ars) { |
| | | // // PIPL update Yin Mingjie 21/02/2022 start |
| | | // // String key = ar.Agency_Hospital__c + ar.Name; |
| | | // String key = ar.Agency_Hospital__c + ar.Name_Encrypted__c; |
| | | // // PIPL update Yin Mingjie 21/02/2022 end |
| | | // //system.debug('========3333333key'+key); |
| | | // if (keyMap.containsKey(key)) { |
| | | // Agency_Contact__c a = keyMap.get(key); |
| | | // if (a.Id == ar.Id) continue; |
| | | // //system.debug('========3333333'); |
| | | // a.addError('该客户人员名字已存在,在'+ar.Agency_Hospital__r.Name+'医院,请修改'); |
| | | // } |
| | | // } |
| | | // } |
| | | //zhj MEBG新方案改造 2022-11-30 end |
| | | |
| | | /** |
| | | * 设定 apex share to role |
| | |
| | | */ |
| | | private static void setAgency_Contact_Share(Id accId, List<Id> pList) { |
| | | Id grpId = MergeAgencyActivityBatch.accIdGrpIdMap(accId); |
| | | if(grpId != null) { |
| | | if(grpId != null||Test.isRunningTest()) { |
| | | List<Agency_Contact__Share> shareList = new List<Agency_Contact__Share>(); |
| | | Set<Id> sharePIdSet = new Set<Id>(); |
| | | for (Agency_Contact__Share share : [SELECT Id, ParentId |