From e53fdfdd78538a21cddd45b9d3faa1a7e9e37a0a Mon Sep 17 00:00:00 2001
From: 19626 <1962676589@qq.com>
Date: 星期五, 21 七月 2023 13:36:24 +0800
Subject: [PATCH] 修改附件
---
force-app/main/default/classes/OPDNoReportApplicationController.cls | 39 +++++++++++++++++++++++++++++++--------
1 files changed, 31 insertions(+), 8 deletions(-)
diff --git a/force-app/main/default/classes/OPDNoReportApplicationController.cls b/force-app/main/default/classes/OPDNoReportApplicationController.cls
index 94d2000..52fd00d 100644
--- a/force-app/main/default/classes/OPDNoReportApplicationController.cls
+++ b/force-app/main/default/classes/OPDNoReportApplicationController.cls
@@ -6,7 +6,7 @@
//璺宠繃涓婁紶闄勪欢鍒ゆ柇
public Boolean IsHavFile { get; set; }
//闄勪欢
- public List<Attachment> attachmentinfo { get; set; }
+ public List<ContentDocument> attachmentinfo { get; set; }
// //鎵ц瀹℃壒娴佹垚鍔熸爣璇�
public Boolean approvalFlag { get; set; }
@@ -45,7 +45,18 @@
this.ModelLendingCodeId = opdPlan.ModelLending__c;
}
- attachmentinfo = [SELECT Id, Name,OwnerId FROM Attachment WHERE parentid = :paramId];
+ //闄勪欢(lightning)
+ List<ContentDocumentLink> cdlList = [SELECT ContentDocumentId
+ FROM ContentDocumentLink
+ WHERE LinkedEntityId = :paramId];
+ List<ID> fileIDs = new List<ID>();
+ for (ContentDocumentLink docLink : cdlList) {
+ fileIDs.add(docLink.ContentDocumentId);
+ }
+ attachmentinfo=[SELECT Title,OwnerId,ContentModifiedDate from ContentDocument WHERE id IN :fileIDs];
+
+
+ // attachmentinfo = [SELECT Id, Name,OwnerId FROM Attachment WHERE parentid = :paramId];
if(attachmentinfo.size()>0){
IsHavFile =true;
} else {
@@ -60,13 +71,25 @@
@RemoteAction
public static String testAddAttachment(String attachmentName,String attachmentType, String attachmentBody,String parentId) {
String operateResult;
- Attachment tmpAttachment = new Attachment();
- tmpAttachment.Name = attachmentName;
- tmpAttachment.Body = EncodingUtil.base64Decode(attachmentBody);
- tmpAttachment.ParentId = parentId;
- tmpAttachment.ContentType = attachmentType;
+ // Attachment tmpAttachment = new Attachment();
+ // tmpAttachment.Name = attachmentName;
+ // tmpAttachment.Body = EncodingUtil.base64Decode(attachmentBody);
+ // tmpAttachment.ParentId = parentId;
+ // tmpAttachment.ContentType = attachmentType;
+ ContentVersion version = new ContentVersion();
+ version.Title = attachmentName;
+ version.VersionData = EncodingUtil.base64Decode(attachmentBody);
+ version.ContentLocation = 's';
+ version.PathOnClient = attachmentName + '.' + attachmentType;
try {
- insert tmpAttachment;
+ insert version;
+ version = [select Id,ContentDocumentId from ContentVersion where Id =: version.Id];
+ ContentDocumentLink link = new ContentDocumentLink();
+ link.ContentDocumentId = version.ContentDocumentId;
+ link.LinkedEntityId = parentId;
+ link.ShareType = 'I';
+ link.Visibility = 'AllUsers';
+ insert link;
operateResult = '鎮ㄥ凡涓婁紶鏂囦欢鎴愬姛锛�';
} catch (Exception e){
operateResult = '涓婁紶鏂囦欢澶辫触锛岃閲嶈瘯锛�';
--
Gitblit v1.9.1