From 254ea442ff0e0a7a97e9f481e9f127a782cba840 Mon Sep 17 00:00:00 2001
From: 19626 <1962676589@qq.com>
Date: 星期一, 17 七月 2023 11:37:35 +0800
Subject: [PATCH] 修改附件7.17
---
force-app/main/default/classes/BatchSelectRepairPDFDelete.cls | 105 +++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 87 insertions(+), 18 deletions(-)
diff --git a/force-app/main/default/classes/BatchSelectRepairPDFDelete.cls b/force-app/main/default/classes/BatchSelectRepairPDFDelete.cls
index 9083f5f..40a7703 100644
--- a/force-app/main/default/classes/BatchSelectRepairPDFDelete.cls
+++ b/force-app/main/default/classes/BatchSelectRepairPDFDelete.cls
@@ -1,35 +1,104 @@
public without sharing class BatchSelectRepairPDFDelete {
public void deletePDF(List<Repair__c> repList){
- List<String> attachmentNameList = new List<String>();
- List<Attachment> isGeneratedPDFList = new List<Attachment>();
- for(Repair__c re : repList){
- attachmentNameList.add(re.name + '_' + 'MaintenanceCommission.pdf');
+ //淇敼鍒犻櫎闄勪欢锛屾敼涓哄垹闄ゆ枃浠讹紙lightning鏀归�狅級
+ List<String> attachmentNameList = new List<String>();
+ List<Id> parentIdList = new List<Id>();
+ List<ContentDocumentLink> isGeneratedPDFLinkList = new List<ContentDocumentLink>();
+ List<ContentDocument> isGeneratedPDFList = new List<ContentDocument>();
+ for(Repair__c re : repList){
+ attachmentNameList.add(re.name + '_' + 'MaintenanceCommission.pdf');
+ parentIdList.add(re.Id);
}
- isGeneratedPDFList = [select id from Attachment where name IN:attachmentNameList];
- System.debug(LoggingLevel.INFO, '*** isGeneratedPDFList: ' + isGeneratedPDFList);
+ isGeneratedPDFLinkList = [select ContentDocumentId from ContentDocumentLink where LinkedEntityId in: parentIdList];
+ List<Id> attachmentIdList = new List<Id>();
+ for (ContentDocumentLink PDFLink : isGeneratedPDFLinkList) {
+ attachmentIdList.add(PDFLink.ContentDocumentId);
+ }
+ isGeneratedPDFList = [select Id from ContentDocument where Id in: attachmentIdList and Title in: attachmentNameList];
if(isGeneratedPDFList.size() > 0){
delete isGeneratedPDFList;
}
+
+
+
+
+
+
+
+
+
+ // List<String> attachmentNameList = new List<String>();
+ // List<Attachment> isGeneratedPDFList = new List<Attachment>();
+ // for(Repair__c re : repList){
+ // attachmentNameList.add(re.name + '_' + 'MaintenanceCommission.pdf');
+ // }
+ // isGeneratedPDFList = [select id from Attachment where name IN:attachmentNameList];
+ // System.debug(LoggingLevel.INFO, '*** isGeneratedPDFList: ' + isGeneratedPDFList);
+ // if(isGeneratedPDFList.size() > 0){
+ // delete isGeneratedPDFList;
+ // }
}
public void createPDF(List<Repair__c> repList){
- PageReference pdfPage;
- List<Attachment> attachments = new List<Attachment>();
- for(Repair__c re : repList){
- pdfPage = new PageReference('/apex/MaintenanceCommissionPDF?id=' + re.Id);
+ // PageReference pdfPage;
+ // List<Attachment> attachments = new List<Attachment>();
+ // for(Repair__c re : repList){
+ // pdfPage = new PageReference('/apex/MaintenanceCommissionPDF?id=' + re.Id);
+ // Blob pdfBody;
+ // if(System.Test.isRunningTest()) {
+ // pdfBody = blob.valueOf('Unit.Test');
+ // } else {
+ // pdfBody = pdfPage.getContentAsPDF();
+ // }
+ // Attachment attach = new Attachment();
+ // attach.Body = pdfBody;
+ // attach.Name = re.name + '_' + 'MaintenanceCommission.pdf';
+ // attach.ParentId = re.id;
+ // attachments.add(attach);
+ // }
+ // System.debug(LoggingLevel.INFO, '*** attachments: ' + attachments);
+ // insert attachments;
+
+ PageReference pdfPage;
+ List<ContentVersion> versions = new List<ContentVersion>();
+ for(Repair__c re : repList){
+ pdfPage = new PageReference('/apex/MaintenanceCommissionPDF?id=' + re.Id);
Blob pdfBody;
if(System.Test.isRunningTest()) {
pdfBody = blob.valueOf('Unit.Test');
} else {
pdfBody = pdfPage.getContentAsPDF();
}
- Attachment attach = new Attachment();
- attach.Body = pdfBody;
- attach.Name = re.name + '_' + 'MaintenanceCommission.pdf';
- attach.ParentId = re.id;
- attachments.add(attach);
+ ContentVersion version = new ContentVersion();
+ version.VersionData = pdfBody;
+ version.Title = re.name + '_' + 'MaintenanceCommission.pdf';
+ version.ContentLocation = 's';
+ version.PathOnClient = re.name + '_' + 'MaintenanceCommission.pdf';
+ versions.add(version);
}
- System.debug(LoggingLevel.INFO, '*** attachments: ' + attachments);
- insert attachments;
- }
+ if (versions.size() > 0) {
+ insert versions;
+ }
+ List<Id> idList = new List<Id>();
+ for (ContentVersion newVersion : versions) {
+ idList.add(newVersion.Id);
+ }
+ versions = [select ContentDocumentId from ContentVersion where Id in: idList];
+ List<ContentDocumentLink> links = new List<ContentDocumentLink>();
+ Integer i = 0;
+ for (ContentVersion newVersion : versions) {
+ ContentDocumentLink link = new ContentDocumentLink();
+ link.ContentDocumentId = newVersion.ContentDocumentId;
+ link.LinkedEntityId = repList[i].Id;
+ link.ShareType = 'I';
+ link.Visibility = 'AllUsers';
+ links.add(link);
+ i++;
+ }
+ if (links.size() > 0) {
+ insert links;
+ }
+
+ }
+
}
\ No newline at end of file
--
Gitblit v1.9.1