高章伟
2023-03-03 d8dc84a3d56df839895f1c417a4d9cbee763d262
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
public class SearchAgencyContactController {    
    public String searchKeyWord{set;get;}
    public String staticResource {get; set;}
    public String contactAWSIds {set;get;}
    public String contactsInfo {set;get;}
    public String PIPL_Search_Contact_Label{set;get;}
    public String aId{set;get;}
 
    public static Boolean checkNullString(String inputString){
        if(String.isEmpty(inputString)||String.isBlank(inputString)){
            return true;
        }
        return false;
    }
 
    public SearchAgencyContactController() {
        String acId = ApexPages.currentPage().getParameters().get('acId');
        searchKeyWord = ApexPages.currentPage().getParameters().get('searchContactKeyWord');
        aId = acId;
        PIPL_Search_Contact_Label = Label.PIPL_Search_Contact_Label;
        //1. Query Agency_Contact__c by acId
        List<Agency_Contact__c> acList = new List<Agency_Contact__c>();
        system.debug('Account Id from Front-end:'+acId);
        if(checkNullString(acId)&&checkNullString(searchKeyWord)){
            acList = new List<Agency_Contact__c>();
        }else{
            if(checkNullString(acId)){
                acList = new List<Agency_Contact__c>(); 
            }else {
                //2022-5-12 yjk 将科室匹配改为医院匹配查询联系人 statt
                Agency_Hospital_Link__c ahl = [select id from Agency_Hospital_Link__c where id = :acId];
                acList = new List<Agency_Contact__c>([select Id,AWS_Data_Id__c,Agency_Hospital__c, Agency_Hospital__r.Name from Agency_Contact__c  where Agency_Hospital__c =: ahl.Id and AWS_Data_Id__c!='']); 
                //2022-5-12 yjk 将科室匹配改为医院匹配查询联系人 end
            }
        }    
        //2. Prepare the Agency_Contact__c Info
        Map<String,Agency_Contact__c> awsIdToContactMap = new Map<String,Agency_Contact__c>();
        List<String> acAWSIds = new List<String>();
        for(Agency_Contact__c ac:acList){
            acAWSIds.add(ac.AWS_Data_Id__c);
            awsIdToContactMap.put(ac.AWS_Data_Id__c,ac);
        }
        contactsInfo = JSON.serialize(awsIdToContactMap);
        contactAWSIds = JSON.serialize(acAWSIds);
        staticResource = JSON.serialize(PIHelper.getPIIntegrationInfo('Agency_Contact__c'));        
    }
 
    @RemoteAction
    public static Response searchAgencyContacts(String awsAgencyContactIds,String searchAgencyContactName,String accountId) {
        system.debug('awsAgencyContactIds = ' + awsAgencyContactIds);
        Response resp = new Response();
        resp.status = 'fail';
        Map<String,Agency_Contact__c> awsIdToContactMapTemp = new Map<String,Agency_Contact__c>();
        if(!checkNullString(awsAgencyContactIds)){
            List<String> awsDataIds = (List<String>) JSON.deserialize(awsAgencyContactIds, List<String>.class);
            List<Agency_Contact__c> conListTemp = new List<Agency_Contact__c>();
            if(!checkNullString(accountId)){
                //2022-5-12 yjk 将科室匹配改为医院匹配查询联系人 statt
                Agency_Hospital_Link__c act = [select id from Agency_Hospital_Link__c where id = :accountId];
                conListTemp = new List<Agency_Contact__c>([select Id,AWS_Data_Id__c, Agency_Hospital__r.Name,Department_Class__r.Name from Agency_Contact__c  where Agency_Hospital__c =: act.Id and AWS_Data_Id__c in:awsDataIds]);
                //2022-5-12 yjk 将科室匹配改为医院匹配查询联系人 end
            }else {
                conListTemp = new List<Agency_Contact__c>([select Id,AWS_Data_Id__c,Agency_Hospital__r.Name,Department_Class__r.Name from Agency_Contact__c where AWS_Data_Id__c in:awsDataIds]);
            }
            for(Agency_Contact__c con:conListTemp){
                awsIdToContactMapTemp.put(con.AWS_Data_Id__c,con);
            }
        }
        System.debug('awsIdToContactMapTemp = ' + awsIdToContactMapTemp);
        //Map<String,Agency_Contact__c> noPIContactMapTemp = new Map<String,Agency_Contact__c>();
        //List<Agency_Contact__c> partnerContactList = AWSServiceTool.getNoPIAgencyContact(searchAgencyContactName,accountId);
        //System.debug('partnerContactList = ' + partnerContactList);            
        // if(partnerContactList.size()>0){
        //     for(Agency_Contact__c con:partnerContactList){
        //         noPIContactMapTemp.put(con.Id,con);
        //     }               
        // }
        if(awsIdToContactMapTemp.keySet().size()>0){
            resp.status = 'success';
            resp.message = JSON.serialize(awsIdToContactMapTemp);// PI contact info
            //resp.noPIContactList = JSON.serialize(noPIContactMapTemp);//NoPI contact info
        }
        return resp;
    }
 
    public class Response{
        public String message{set;get;}
        public String status{set;get;}
        public String noPIContactList{set;get;}
    }
}