buli
2023-05-22 71b93327e8f3fb3bffffc7c033c1f782e7b6ab32
force-app/main/default/classes/QLMAttachmentPreviewController.cls
@@ -4,7 +4,7 @@
//    //附件的Id
    public String attachId { get; private set; }
    //所有附件
    public list<Attachment> attachMentList { get; private set; }
    public list<ContentVersion> attachMentList { get; private set; }
    //所有超过12Murl
    public list<Over12MInfo> Over12MInfoList { get; set; }
@@ -20,8 +20,12 @@
        try {
            // return [SELECT Id, Body, ParentId FROM Attachment
            //        where Id = :parentId ].body.tostring();
            String Att = [SELECT Id, Body, ParentId FROM Attachment
                          where Id = :attachId ].body.tostring();
            // String Att = [SELECT Id, Body, ParentId FROM Attachment
            //               where Id = :attachId ].body.tostring();
            // lwc改造
            String Att = [SELECT Id,Title,VersionData, ContentDocumentId
                                         FROM ContentVersion
                                         WHERE id = :attachId].VersionData.toString();
            System.debug('------123456----' + Att);
            return Att;
        } catch (exception e) {
@@ -37,9 +41,21 @@
        try {
            //判断url是否有id
            if (String.isNotBlank(this.parentId)) {
                this.attachMentList = [SELECT id, parentId, Name, Body, ContentType
                                       from Attachment where parentId = :parentId];
                // this.attachMentList = [SELECT id, parentId, Name, Body, ContentType
                //                        from Attachment where parentId = :parentId];
                // lwc 修改
                // 查询 ContentDocumentLink 对象
                List<ContentDocumentLink> cdlList = [SELECT ContentDocumentId
                                                     FROM ContentDocumentLink
                                                     WHERE LinkedEntityId = :parentId];
                // 遍历 ContentDocumentLink 对象列表
                for (ContentDocumentLink cdl : cdlList) {
                    // 查询 ContentVersion 对象
                    this.attachMentList = [SELECT Id,Title,VersionData, ContentDocumentId
                                         FROM ContentVersion
                                         WHERE ContentDocumentId = :cdl.ContentDocumentId];
                }
                attachmentInfo = new AttachmentInfo(attachMentList);
                List<Tender_information__c> QLMattachMentList = [SELECT id, ProjectId__c, InfoType__c,
                                            Overstep_12M_infofile__c,
@@ -66,12 +82,12 @@
    }
    public class AttachmentInfo {
        public list<Attachment> attachMentList { get; set; }
        public list<ContentVersion> attachMentList { get; set; }
        public AttachmentInfo(list<Attachment> attachMentList) {
        public AttachmentInfo(list<ContentVersion> attachMentList) {
            this.attachMentList = attachMentList;
            for (Attachment tempatt : attachMentList) {
               tempatt.Name =  String.escapeSingleQuotes(tempatt.Name);
            for (ContentVersion tempatt : attachMentList) {
               tempatt.Title =  String.escapeSingleQuotes(tempatt.Title);
            }
        }
    }