public with sharing class QLMAttachmentPreviewController { // //附件的parentId public String parentId { get; private set; } // //附件的Id public String attachId { get; private set; } //所有附件 public list attachMentList { get; private set; } public List contentVerResList { get; private set; } // 阿里云迁移 by DTT-亚楠 20240107 public String baseUrl { get; private set; } // 阿里云迁移 by DTT-亚楠 20240107 //所有超过12Murl public list Over12MInfoList { get; set; } //构造bean类 public AttachmentInfo attachmentInfo {get; set;} public String gethtmlvalue() { this.parentId = ApexPages.currentPage().getParameters().get('parentId'); this.attachId = ApexPages.currentPage().getParameters().get('Id'); System.debug('123456--=--=--=-=--=' + attachId); 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(); // lwc改造 String Att = [SELECT Id,Title,VersionData, ContentDocumentId FROM ContentVersion WHERE id = :attachId].VersionData.toString(); System.debug('------123456----' + Att); return Att; } catch (exception e) { return ''; } } public void init() { //获取页面参数 this.baseUrl = URL.getOrgDomainURL().toExternalForm(); this.parentId = ApexPages.currentPage().getParameters().get('parentId'); this.attachId = ApexPages.currentPage().getParameters().get('Id'); System.debug('this.parentId' + this.parentId); System.debug('this.attachId' + this.attachId); Over12MInfoList = new List(); this.contentVerResList = new List(); // 阿里云迁移 by DTT-亚楠 20240107 try { //判断url是否有id if (String.isNotBlank(this.parentId)) { // this.attachMentList = [SELECT id, parentId, Name, Body, ContentType // from Attachment where parentId = :parentId]; // lwc 修改 // 查询 ContentDocumentLink 对象 List cdlList = [SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = :parentId]; // 阿里云迁移 by DTT-亚楠 20240107 start // 遍历 ContentDocumentLink 对象列表 // for (ContentDocumentLink cdl : cdlList) { // // 查询 ContentVersion 对象 // this.attachMentList = [SELECT Id,Title,VersionData, ContentDocumentId // FROM ContentVersion // WHERE ContentDocumentId = :cdl.ContentDocumentId]; // } List cdIdList = new List(); for (ContentDocumentLink cdl : cdlList) { cdIdList.add(cdl.ContentDocumentId); } this.attachMentList = [SELECT Id,Title,VersionData, ContentDocumentId, Description FROM ContentVersion WHERE ContentDocumentId IN :cdIdList]; // attachmentInfo = new AttachmentInfo(this.attachMentList); for (ContentVersion contentVersion : this.attachMentList) { ContentVersionResponse contentVerRes = new ContentVersionResponse(); contentVerRes.Id = contentVersion.Id; contentVerRes.contDocumentId = contentVersion.ContentDocumentId; contentVerRes.Title = String.escapeSingleQuotes(contentVersion.Title); List descriptionList = new List(); if (String.isNotBlank(contentVersion.Description)) { descriptionList = contentVersion.Description.split(';'); } if (descriptionList.size() > 0 && contentVersion.Description.contains(';')) { contentVerRes.infoId = descriptionList[0]; contentVerRes.infoType = descriptionList[1]; contentVerRes.subInfoType = descriptionList[2]; contentVerRes.updateDate = String.isNotBlank(descriptionList[3]) ? Date.valueOf(descriptionList[3]) : null; } this.contentVerResList.add(contentVerRes); } attachmentInfo = new AttachmentInfo(this.attachMentList, this.contentVerResList); attachmentInfo.sort(); // 阿里云迁移 by DTT-亚楠 20240107 end List QLMattachMentList = [SELECT id, ProjectId__c, InfoType__c, Overstep_12M_infofile__c, File_Surpass_12M__c from Tender_information__c where Id = :parentId]; if (QLMattachMentList.size() > 0) { System.debug('QLMattachMentList:' + QLMattachMentList); Integer i = 1; // for (Tender_information__c Over12M : QLMattachMentList) { for (String urlStr : QLMattachMentList[0].Overstep_12M_infofile__c.split(',')) { // this.url = Over12M.Overstep_12M_infofile__c; System.debug('urlStr:' + urlStr); urlStr = urlStr.replaceAll('http://', 'https://'); over12MInfo over12MFile = new Over12MInfo('文件' + i, urlStr); Over12MInfoList.add(over12MFile); System.debug('12345678Over12MInfoList:' + Over12MInfoList); i++; } } } } catch (Exception ex) { ApexPages.addMessages(ex); } } public class ContentVersionResponse { // 阿里云迁移 by DTT-亚楠 20240107 star public String Id {get; set;} public String contDocumentId {get; set;} public String Title {get; set;} public String infoId {get; set;} public String infoType {get; set;} public String subInfoType {get; set;} public Date updateDate {get; set;} public ContentVersionResponse(String Id, String contDocumentId, String Title, String infoId, String infoType, String subInfoType, Date updateDate) { this.Id = Id; this.contDocumentId = contDocumentId; this.title = Title; this.infoId = infoId; this.infoType = infoType; this.subInfoType = subInfoType; this.updateDate = updateDate; } public ContentVersionResponse(){} // 阿里云迁移 by DTT-亚楠 20240107 end } public class AttachmentInfo implements Comparable{ // lighting 附件改造 start public list attachMentList { get; set; } public ContentVersionResponse contentVerRes { get; set; } public List contentVerResList { get; set; } // 阿里云迁移 by DTT-亚楠 20240107 public AttachmentInfo(list attachMentList) { this.attachMentList = attachMentList; for (ContentVersion tempatt : attachMentList) { tempatt.Title = String.escapeSingleQuotes(tempatt.Title); } } public AttachmentInfo(ContentVersionResponse contentVerRes) { this.contentVerRes = contentVerRes; } // lighting 附件改造 end // 阿里云迁移 by DTT-亚楠 20240107 start public AttachmentInfo(list attachMentList, List contentVerResList) { this.attachMentList = attachMentList; this.contentVerResList = contentVerResList; } public Integer compareTo(Object compareToPB) { AttachmentInfo compareToEmp = (AttachmentInfo)compareToPB; if (this.contentVerRes.updateDate != null && compareToEmp.contentVerRes.updateDate == null) { return -1; } else if (this.contentVerRes.updateDate == null && compareToEmp.contentVerRes.updateDate != null) { return 1; } else if (this.contentVerRes.updateDate != null && compareToEmp.contentVerRes.updateDate != null) { return this.contentVerRes.updateDate < compareToEmp.contentVerRes.updateDate ? 1 : 0; } else { return 0; } } public void sort() { List dataInfoSorts = new List(); for (ContentVersionResponse contentVerRes : contentVerResList) { dataInfoSorts.add(new AttachmentInfo(contentVerRes)); } dataInfoSorts.sort(); for (Integer i = 0; i < contentVerResList.size(); i++) { contentVerResList[i] = dataInfoSorts[i].contentVerRes; } } // 阿里云迁移 by DTT-亚楠 20240107 end } public class Over12MInfo { public string name { get; set; } public string url { get; set; } public Over12MInfo(string name, string url) { this.name = name; this.url = url; } } }