高章伟
2023-03-03 d8dc84a3d56df839895f1c417a4d9cbee763d262
force-app/main/default/classes/SearchVisitorController.cls
@@ -34,7 +34,6 @@
    public String awsDataIdArray {set;get;}
    public String sfContactId{set;get;}
    //Add By Li Jun 20220217 End
    public SearchVisitorController(){
        this.id1 = Apexpages.currentPage().getParameters().get('id1');
        this.hId1 = Apexpages.currentPage().getParameters().get('hId1');
@@ -175,11 +174,16 @@
        //Add By Li Jun for PIPL 20220217 Start
        //1. Query Contact by accountId
        List<Contact> conList = new List<Contact>();
        List<Account> departmentClass = new List<Account>();
        system.debug('Account Id from Front-end:'+a.Id);
        String accountId = a.Id;
        PIHelper.PIIntegration contactPIIntegration = PIHelper.getPIIntegrationInfo('Contact');
        if(String.isNotBlank(accountId) && String.isNotEmpty(accountId)){
            conList = new List<Contact>([select Id,AWS_Data_Id__c from Contact where AccountId=:accountId and AWS_Data_Id__c!='' limit :contactPIIntegration.maxQueryNumber]);
            departmentClass = [select Department_Class__c from Account where id =:accountId];
            if(departmentClass.size() > 0){
                conList = new List<Contact>([select Id,AWS_Data_Id__c from Contact where Account.ParentId =:departmentClass[0].Department_Class__c and AWS_Data_Id__c!='' limit :contactPIIntegration.maxQueryNumber]);
            }
            //conList = new List<Contact>([select Id,AWS_Data_Id__c from Contact where AccountId=:accountId and AWS_Data_Id__c!='' limit :contactPIIntegration.maxQueryNumber]);
        }        
        //2. Prepare the Contact Info
        List<String> conAWSIds = new List<String>();
@@ -399,9 +403,9 @@
        rc.AccountId = rc.Account_Visitor_Search__c;
        rc.Isactive__c = '有效';
        system.debug('--------------rc.LastName ='+rc.LastName);
        Savepoint sp = Database.setSavepoint();
        try{
            system.debug('rc = ' + rc);
            upsert rc;
            sfContactId = rc.Id;
            }catch(Exception io){
@@ -493,4 +497,28 @@
            this.index = index;
        }
    }
    //zhj MEBG新方案改造 2022-11-24 start
    @RemoteAction
    public static NewAndEditContactController.ResponseV2 searchContactByAccountId(String accountId) {
        NewAndEditContactController.ResponseV2 res = new NewAndEditContactController.ResponseV2();
        try{
            Account account = [select Id,Name from Account where Id =:accountId];
            List<Contact> contactList = [select id,AWS_Data_Id__c, CManageCode__c,Name from Contact where AccountId = :account.Id];
            Map<String,String> dataIdManageCodeMap = new Map<String,String>();
            for(Contact contact : contactList){
                dataIdManageCodeMap.put(contact.AWS_Data_Id__c,contact.CManageCode__c);
            }
            res.dataIdManageCodeMap = dataIdManageCodeMap;
            res.accountName = account.Name;
            res.contactList = contactList;
            res.status = 'success';
            return res;
        }catch(Exception e){
            res.message = e.getMessage() + '';
            res.status = 'fail';
            return res;
        }
    }
    //zhj MEBG新方案改造 2022-11-24 end
}