liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
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
global class FileBatchDeleteController {
 
    //先删除salesforce的附件
    WebService static String fileSFDelete(List<String> idList){
        Savepoint sp = Database.setSavepoint();
        try{
            //sf删除
            Database.delete(idList); 
            return 'success';
        }catch(Exception e){
            Database.rollback(sp);
            System.debug('失败原因是 : ' + e.getMessage());
            return '失败原因是 : ' + e.getMessage();
        }
    }
 
    //再删除AWS那边的附件
    WebService static String fileAWSDelete(List<String> keyList){
        try {
            // System.debug('keyList = ' + keyList);
            // Map<String,List<String>> keyMap = new Map<String,List<String>>();
            // keyMap.put('keys' , keyList);
            String keyJson = JSON.serialize(keyList);
            System.debug('keyJson = ' + keyJson);
 
            String deleteUrl = '';
            PIHelper.PIIntegration staticResource = null;
            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 'AWS_Integration_Info__mdt没配置';
            }else {
                deleteUrl = awsConfiguration.Host_URL__c + '/api/file/delete';
                staticResource = PIHelper.getPIIntegrationInfo('Document');
            }
            Http http = new Http();
            HttpRequest request = new HttpRequest();
            // 设置网络服务接口的地址
            request.setEndpoint(deleteUrl);
            // 设置REST方法
            request.setMethod('POST');
            // 设置请求的Header,类型为JSON
            request.setHeader('Content-Type', 'application/json');
            // 设置请求的token
            request.setHeader('pi-token', staticResource.token);
            // 将一个JSON对象传入请求的Body,设置编程语言的名字
            request.setBody(keyJson);
            // 发送HTTP请求
            HttpResponse response = http.send(request);
            System.debug(response);
            // 检查HTTP通信结果状态代码
            if (response.getStatusCode() == 200) {
                //在控制台输出通信结果   
                System.debug(response.getBody());
            }
            return 'success';
        } catch (Exception e) {
            System.debug('失败原因是 : ' + e.getMessage());
            return '失败原因是 : ' + e.getMessage();
        }
    }
}