buli
2023-06-05 3962c2bb0435484b60a3e408e4738d792e249a53
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
public without sharing class lexSearchAgencyHospitalController {
    //经销商用户产品分类(ET、ENG)
    public static String agencyProType {get;set;}
    public static String searchName {get;set;} 
    private static String accountid = null;
    @AuraEnabled
    public static List<Account> at {get;set;}
 
 
    @AuraEnabled
    public static ResponseBodyLWC init(String ctype){
        ResponseBodyLWC res = new ResponseBodyLWC();
        Map<String, object> data = new Map<String, object>();
        res.entity = data;
        User useracc = [SELECT accountid,UserPro_Type__c FROM user WHERE id = :UserInfo.getUserId() ];
        accountid = Useracc.accountid;
        agencyProType = Useracc.UserPro_Type__c;
        if(String.isBlank(Useracc.UserPro_Type__c)){
            agencyProType = 'ET';
        }
        String soql = 'SELECT id,Name,State_Master__c,State_Master__r.Name FROM Account';
        soql += ' where id in (SELECT Hospital__c FROM Agency_Hospital_Link__c WHERE Agency__c = \'' + accountid + '\' AND Hosptial_Type__c like \'%' + String.escapeSingleQuotes(ctype.replaceAll('%', '\\%')) + '%\')' ;
        soql += ' order by Name desc limit 100';
        at = Database.query(soql);
        data.put('at',at);
        res.status = 'Success';
        res.code = 200;
        System.debug('res = ' + res);
        return res;
    }
 
    @AuraEnabled
    public static ResponseBodyLWC serContact(String searchName,String ctype){
        ResponseBodyLWC res = new ResponseBodyLWC();
        Map<String, object> data = new Map<String, object>();
        res.entity = data;
        User useracc = [SELECT accountid,UserPro_Type__c FROM user WHERE id = :UserInfo.getUserId() ];
        accountid = Useracc.accountid;
        at = Database.query(makeSoql(searchName,accountid,ctype));
        data.put('at',at);
        res.status = 'Success';
        res.code = 200;
        System.debug('res = ' + res);
        return res;
    }
 
    private static String makeSoql(String searchName,String accountid,String ctype){
 
        String soql = 'SELECT id,Name,State_Master__c,State_Master__r.Name FROM Account';
        soql += ' where id in (SELECT Hospital__c FROM Agency_Hospital_Link__c WHERE Agency__c = \'' + accountid + '\' AND Hosptial_Type__c like \'%' + String.escapeSingleQuotes(ctype.replaceAll('%', '\\%')) + '%\')' ;
        if(String.isNotBlank(searchName)){
            soql += ' AND Name like \'%' + String.escapeSingleQuotes(searchName.replaceAll('%', '\\%')) + '%\'';
        }
        soql += ' order by Name desc limit 100';
        //ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'soql' + soql));
        return soql;
    }
}