buli
2022-05-09 248433c920f935ffcaee52b240f0c162decc1564
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
 * Author: Bubba Li
 * Created Date: 01/25/2022
 * Purpose: Utility class for AWS Servicw
 * Test Class: AWSServiceTool
 * History: 
 *      01/25/2022 - Bubba Li - Initial Code.
 * 
 * */
public without sharing class AWSServiceTool {
    public static Boolean getAWSServiceStatus(){
        AWS_Integration_Info__mdt awsConfiguration = [SELECT Enable_AWS_Service__c FROM AWS_Integration_Info__mdt  WHERE DeveloperName = 'AWS_Default_Configuration'];
        if (awsConfiguration == null) {
            System.debug('AWS_Integration_Info__mdt没配置');
            return false;
        }
        return awsConfiguration.Enable_AWS_Service__c;
    }
    public static List<Contact>  getNoPIContact(String searchContactName,String accountId){
        if(searchContactName!='' || accountId!=''){
            String noPISQL = 'select Id,Name,Email,Phone,Account.Name,MobilePhone from Contact where Account_Record_Type_DeveloperName__c in('+'\'Agency\''+','+'\'Dealer\''+')';
            if(String.isNotEmpty(accountId)){
                String[] accountIds = accountId.split(',');
                String accounts = '';
                for(String s : accountIds){
                    accounts += ',\''+s+'\'';
                }
                accounts = accounts.substring(1);
                System.debug('accounts = ' + accounts);
                noPISQL += ' and AccountId in ('+accounts+')';
            }
            if(String.isNotEmpty(searchContactName)){
                noPISQL += ' and Name like \'%'+searchContactName+'%\'';
            }
            system.debug('noPISQL = ' + noPISQL);
            List<Contact> partnerContactList = Database.query(noPISQL);
            return partnerContactList;
        }
        return new List<Contact>();
    }
    public static String getAWSToken(){
        AWS_Integration_Info__mdt awsConfiguration = [SELECT App_Id__c,Token_URL__c,App_Secret__c,Host_URL__c FROM AWS_Integration_Info__mdt  WHERE DeveloperName = 'AWS_Default_Configuration'];
        if (awsConfiguration == null) {
            System.debug('AWS_Integration_Info__mdt没配置');
            return null;
        }
        String awsAppId = awsConfiguration.App_Id__c;
        String awsAppSecret = awsConfiguration.App_Secret__c;
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        String url = awsConfiguration.Token_URL__c;
        request.setEndpoint(url);
        request.setMethod('GET');
        if(Test.isRunningTest()){
            return 'UTToken';
        }
        HttpResponse response = http.send(request);
        Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
        String token = (String)results.get('object');
        return token;
    }
    @future(callout=true)
    public static void deleteFileAddress(Set<String> fileAddressIds){
        //1. Get file address id
        system.debug('fileAddressId = '+ JSON.serialize(fileAddressIds));
        PIHelper.PIIntegration documentPI=PIHelper.getPIIntegrationInfo('Document');
        //2. Delete aws file doucment and post aws service
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        String url = documentPI.deleteUrl;
        request.setEndpoint(url);
        request.setMethod('POST');
        request.setHeader('pi-token',documentPI.token);
        request.setHeader('Content-Type', 'application/json');
        request.setBody(JSON.serialize(fileAddressIds));
        HttpResponse response = http.send(request);
        system.debug('response = ' + response);
        if(response.getStatusCode() == 200){
            Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
            if(results.get('status')=='0'){
                System.debug('成功删除');
            }
        }
    }
 //add for pipl sushanhu 20220311 start
 public static response sendToPiAWS(String rowDataStr, String endpoint,String awsToken) {
 
    Http http = new Http();
    HttpRequest req = new HttpRequest();
    HTTPResponse res;
    String resb;
    req.setHeader('Content-Type', 'application/json');
    req.setTimeout(120000);
    req.setEndpoint(endpoint);
    req.setMethod('POST');
    req.setHeader('pi-token', awsToken);
    req.setBody(rowDataStr);
    res = http.send(req);
    string ress = String.valueOf(res.getStatusCode()) ;
    resb = res.getBody();
    system.debug('ress:' + ress);
    return new response(ress, resb);
}
 
    public class response {
        public string status;
        public string responseBody;
        public response(string status, string responseBody ) {
            this.status         = status;
            this.responseBody   = responseBody;
        }
    }
//add for pipl sushanhu 20220311 end
//add for pipl sushanhu 20220311 start
    public class NFMResponse{
        public Boolean SFStatus;
        public String SFMessage;
        public StaticResponse staticResponse;
    }
    public class StaticResponse{
        public string status;
        public String Message;
        public StaticResponse(){
            status='0';
            Message='';
        }
    }
    public static NFMResponse getNFMResponse(){
        NFMResponse  result=new NFMResponse();
        result.staticResponse =new StaticResponse();
        return result;
        
    }
//add for pipl sushanhu 20220311 en
   
 
}