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
59
60
61
62
63
64
65
66
67
68
69
public without sharing class LexSearchContractController {
    private static Boolean OSHFLG;//lt 20230517 安徽两票制 add
 
    @AuraEnabled
    public static Results init(String ctype){
        Results results = new Results();
        try {
            //lt 20230517 安徽两票制 add ,OSHFLG__c
            User useracc = [SELECT accountid,OSHFLG__c FROM user WHERE id = :UserInfo.getUserId() ];
            OSHFLG = Useracc.OSHFLG__c; //lt 20230517 安徽两票制 add;
            String accountId = Useracc.accountid;
            List<Account> attList = [SELECT id,Name,State_Master__c,State_Master__r.Name,Sales_Section__c,
                        Contract_Decide_Start_Date__c,Contract_Decide_End_Date__c
                    FROM Account
                    WHERE ParentId = :accountId
                    AND Contact_Type__c like :ctype
                    AND Contract_Decide_Start_Date__c <= :Date.Today()
                    AND Contract_Decide_End_Date__c >= :Date.Today()
                    AND Secondary_contract__c = false
                    AND OSH_Dealer__c =: OSHFLG  //lt 20230517 安徽两票制 add
                    ];
            results.attList = attList;
            results.result = 'Success'; 
        } catch (Exception e) {
            results.result = 'Fail';
            results.errorMsg = e.getLineNumber() + '---' + e.getMessage();
        }
        return results;
    }
 
    @AuraEnabled
    public static Results searchContract(String searchName, String accountId, String ctype, Boolean OSHFLGStr){
        Results results = new Results();
        OSHFLG = OSHFLGStr;
        try {
            results.attList = Database.query(makeSoql(searchName,Date.today(),accountId,ctype));
            results.result = 'Success'; 
        } catch (Exception e) {
            results.result = 'Fail';
            results.errorMsg = e.getLineNumber() + '---' + e.getMessage();
        }
        return results;
    }
 
    private static String makeSoql(String CateName,Date timetest,String accountId, String ctype){
        
        String soql = 'SELECT id,Name,State_Master__c,State_Master__r.Name,Sales_Section__c,';
        soql += ' Contract_Decide_Start_Date__c,Contract_Decide_End_Date__c,OSH_Dealer__c FROM Account';
        soql += ' where ParentId = \'' + accountId + '\'' ;
        soql += ' AND OSH_Dealer__c = ' + OSHFLG + '' ; //lt 20230517 安徽两票制 add
        soql += ' AND Secondary_contract__c = false' ;
        soql += ' AND Contact_Type__c like \'%' + String.escapeSingleQuotes(ctype.replaceAll('%', '\\%')) + '%\'';
        soql += ' AND Contract_Decide_Start_Date__c <=' + String.valueOf(timetest).substring(0, 10);
        soql += ' AND Contract_Decide_End_Date__c >= ' + String.valueOf(timetest).substring(0, 10);
        if(!String.isBlank(CateName)){
            soql += ' AND Name like \'%' + String.escapeSingleQuotes(CateName.replaceAll('%', '\\%')) + '%\'';
        }
        return soql;
    }
 
    public class Results {
        @AuraEnabled
        public String result;
        @AuraEnabled
        public String errorMsg;
        @AuraEnabled
        public List<Account> attList;
    }
}