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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
global without sharing class BatchFileUploadController {
    public String newUrl {get; set;}
    public String staticResource {get; set;}
 
    public BatchFileUploadController(){
        //deloitte-zhj 20231208 PIPL还原
        // 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没配置');
        // }else {
        //     newUrl = awsConfiguration.Host_URL__c + '/api/file/batchupload';
        //     staticResource = JSON.serialize(PIHelper.getPIIntegrationInfo('Document'));
        // }
    }
 
    global class Response{
        public String recordId{set;get;}
        public String message{set;get;}
        public String status{set;get;}
    }
 
    global class ResponseDeleteFile{
        public List<String> keyList{set;get;}
        public String message{set;get;}
        public String status{set;get;}
    }
 
    //deloitte-zhj  202312085 PIPL还原 start
    @RemoteAction
    global static Response saveFile(String fileName,String base64Data, String contentType,String parentId,String bool){
        Response response =new Response();
        Savepoint sp = Database.setSavepoint();
        try {
            FileAddress__c file = new FileAddress__c();
            // 去除filename里得“&” zhj 2022-11-17
            fileName = fileName.remove('&');
            file.FileName__c =fileName;
            file.ParentRecordId__c =parentId;
            
            
            ContentVersion version = new ContentVersion();
            version.Title = fileName;
            version.VersionData = EncodingUtil.base64Decode(base64Data);
            version.ContentLocation = 's';
            version.PathOnClient = fileName;
            version.Origin = 'C';
            insert version;
            version = [select ContentDocumentId from ContentVersion where Id =: version.Id limit 1];
 
            file.DownloadLink__c = '/sfc/servlet.shepherd/version/download/' + version.Id;
            file.ViewLink__c = '/lightning/page/filePreview?selectedRecordId=' + version.ContentDocumentId;
            file.View_Link__c = '/sfc/servlet.shepherd/version/renditionDownload?rendition=SVGZ&versionId=' + version.Id + '&operationContext=CHATTER';
            insert file;
 
            ContentDocumentLink link = new ContentDocumentLink();
            link.ContentDocumentId = version.ContentDocumentId;
            link.LinkedEntityId = file.Id;
            link.ShareType = 'I';
            link.Visibility = 'AllUsers';
            insert link;
 
            ContentDocumentLink link1 = new ContentDocumentLink();
            link1.LinkedEntityId = System.Label.GuestFile;
            link1.ContentDocumentId = version.ContentDocumentId;
            link1.Visibility = 'AllUsers';
            link1.ShareType = 'I';
            insert link1;
 
            response.recordId = file.Id;
            response.status='success';
 
            if(bool == 'true'){
                System.debug('成功调用batch');
                Database.executeBatch(new SetFrameNumManageBatch(), 100);     //上传成功后需要手动跑batch做数据和附件的关联 2022-12-27
            }
        } catch (Exception e) {
            System.debug('into catch'+e.getMessage());
            Database.rollback(sp);
            response.message=e.getMessage() + '________' + e.getLineNumber();
            response.status='fail';
        }
        return response;
    }
 
 
    @RemoteAction
    global static ResponseDeleteFile deleteFile(String fileIds){
        String[] ids = fileIds.split(',');
        System.debug('ids = ' + ids);
        List<String> idList = new List<String>();
        for(String str : ids){
            idList.add(str);
        }
        System.debug('idList = ' + idList);
        //List<FileAddress__c> fList = [select id,AWS_File_Key__c from FileAddress__c where id in:idList];
        List<ContentDocument> fList = [select id from ContentDocument where id in:idList];
        ResponseDeleteFile response =new ResponseDeleteFile();
        Savepoint sp = Database.setSavepoint();
        try {
            delete fList;
            response.keyList = null;
            response.message = '';
            response.status = 'success';
            return response;
        } catch (Exception e) {
            Database.rollback(sp);
            response.keyList = null;
            response.message = e.getMessage();
            response.status = 'error';
            return response;
        }
    }
 
    // @RemoteAction
    // global static Response saveFile(String fileName,String key,String transId,String parentId,String bool){
    //     FileAddress__c file = new FileAddress__c();
    //     PIHelper.PIIntegration pI=PIHelper.getPIIntegrationInfo('Document');
    //     // 去除filename里得“&” zhj 2022-11-17
    //     fileName = fileName.remove('&');
    //     file.DownloadLink__c =pI.undeleteUrl+key+'&fileName='+fileName;
    //     file.FileName__c =fileName;
    //     file.ViewLink__c =pI.queryUrl+key;
    //     file.ParentRecordId__c =parentId;
    //     file.AWS_File_Key__c = key;
    //     Response response =new Response();
    //     Savepoint sp = Database.setSavepoint();
    //     try {
    //         insert file;
    //         //插入日志 
    //         //update 2022-11-17 加入新的日志方式
    //         PIHelper.saveTransLog('Document',key,transId,file.Id,JSON.serialize(file),'success','');
    //         response.recordId=file.Id;
    //         response.status='success';
    //         if(bool == 'true'){
    //             System.debug('成功调用batch');
    //             Database.executeBatch(new SetFrameNumManageBatch(), 100);     //上传成功后需要手动跑batch做数据和附件的关联 2022-12-27
    //         }
    //         return response;
    //     } catch (Exception e) {
    //         System.debug('into catch'+e.getMessage());
    //         PIHelper.saveTransLog('Document',key,transId,file.Id,JSON.serialize(file),'fail',e.getMessage());
    //         Database.rollback(sp);
    //         response.message=e.getMessage();
    //         response.status='fail';
    //         return response;
    //     }
    // }
 
    // @RemoteAction
    // global static ResponseDeleteFile deleteFile(String fileIds){
    //     String[] ids = fileIds.split(',');
    //     System.debug('ids = ' + ids);
    //     List<String> idList = new List<String>();
    //     for(String str : ids){
    //         idList.add(str);
    //     }
    //     System.debug('idList = ' + idList);
    //     List<FileAddress__c> fList = [select id,AWS_File_Key__c from FileAddress__c where id in:idList];
 
    //     List<String> keyList = new List<String>();
    //     for(FileAddress__c fa : fList){
    //         keyList.add(fa.AWS_File_Key__c);
    //     }
    //     System.debug('keyList = ' + keyList);
    //     ResponseDeleteFile response =new ResponseDeleteFile();
    //     Savepoint sp = Database.setSavepoint();
    //     try {
    //         delete fList;
    //         response.keyList = keyList;
    //         response.message = '';
    //         response.status = 'success';
    //         return response;
    //     } catch (Exception e) {
    //         Database.rollback(sp);
    //         response.keyList = null;
    //         response.message = e.getMessage();
    //         response.status = 'success';
    //         return response;
    //     }
    // }
    //deloitte-zhj  202312085 PIPL还原 end
}