public with sharing class ReAndQISNotePDFController { // DB202304087063 课题对应 // public Note Noteinfo {get; set;} public static ContentVersion Versioninfo {get; set;} // 20231027 ymh添加注释 add // public String Title{get; set;} // public String Body{get; set;} // id public static String objId {get; set;} public ReAndQISNotePDFController(){ objId = ApexPages.currentPage().getParameters().get('id'); // Noteinfo = [select Id,Parentid,Title,Body from Note where id = :objId]; // 20231027 ymh添加注释 update Versioninfo = [SELECT Id,Title,VersionData,TextPreview FROM ContentVersion WHERE ContentDocumentId =: objId]; } // 生成pdf添加到对应的修理中 @Future(callout=true) public static void generateAttachment(List reAndQisMap){ PageReference pdfPage ; system.debug('reAndQisMap数据:' + reAndQisMap); // //20231027 ymh添加注释 lighting修改附件上传 start List linkList = new List(); List versionList = new List(); // Map updateRpr = [select id,SerialNumber__c,Delivered_Product__r.Name // from Repair__c where id in : reAndQisMap.keySet()]; // MapupdateQis = [select id,lot_or_serial__c,nonyushohin__r.Name // from QIS_Report__c where id in : reAndQisMap.keySet()]; List selectLinkList = [SELECT ContentDocumentId FROM ContentDocumentLink WHERE Id in: reAndQisMap]; List linkIdList = new List(); for (ContentDocumentLink link : selectLinkList) { linkIdList.add(link.ContentDocumentId); } List ntList = [Select id,Title FROM ContentDocument where Id in : linkIdList]; List docIdList =new List(); List verIdList = new List(); for (ContentDocument doc : ntList) { pdfPage = new PageReference('/apex/ReAndQISNotePDF?id='+doc.Id); Blob pdfBody; if(Test.isRunningTest()) { pdfBody = blob.valueOf('Unit.Test'); } else { pdfBody = pdfPage.getContentAsPDF(); } ContentVersion version = new ContentVersion(); version.VersionData = pdfBody; version.Title = doc.Title + '.pdf'; version.PathOnClient = '/'+doc.Title + '.pdf'; versionList.add(version); docIdList.add(doc.Id); } insert versionList; for (ContentVersion ver : versionList) { verIdList.add(ver.Id); } List versionDocId = new List(); if (verIdList.size()>0) { versionDocId = [select ContentDocumentId from ContentVersion where Id IN: verIdList]; } if (versionDocId.size()>0 && docIdList.size()>0) { List linkId = [SELECT LinkedEntityId FROM ContentDocumentLink WHERE Id IN: reAndQisMap]; system.debug('linkId长度:' + linkId.size()); for (ContentVersion cv : versionDocId) { for (ContentDocumentLink link : linkId) { ContentDocumentLink cdl = new ContentDocumentLink(); cdl.ContentDocumentId = cv.ContentDocumentId; cdl.LinkedEntityId = link.LinkedEntityId; cdl.ShareType = 'I'; cdl.Visibility = 'AllUsers'; linkList.add(cdl); } } // insert linkList; Database.SaveResult[] lsr = Database.Insert(linkList, false); for (Integer tIdx = 0; tIdx < lsr.size(); tIdx++) { Database.SaveResult sr = lsr[tIdx]; if (!sr.isSuccess()) { Database.Error emsg =sr.getErrors()[0]; system.debug('\nERROR ADDING ACCOUNT TEAM MEMBER:' + emsg); } } } // List NtList = [Select id,ParentId,Title,Body FROM Note where Id in : reAndQisMap]; // List attachments = new List(); // for (Note nt : NtList) { // pdfPage = new PageReference('/apex/ReAndQISNotePDF?id='+nt.Id); // Blob pdfBody; // if(Test.isRunningTest()) { // pdfBody = blob.valueOf('Unit.Test'); // } else { // pdfBody = pdfPage.getContentAsPDF(); // } // Attachment attach = new Attachment(); // attach.Body = pdfBody; // attach.Name = nt.Title + '.pdf'; // attach.ParentId = nt.ParentId; // attachments.add(attach); // } // insert attachments; // for(Repair__c re : repList){ // String generatedFields = re.GeneratedPDFField__c; // if (checkFieldisGeneratedPDF('ProblemDescription__c',re)) { // continue; // } // if (re.get('ProblemDescription__c') == null) { // continue; // } // setImgSrcs(re, 'ProblemDescription__c'); // pdfPage = new PageReference('/apex/repairandqistopdf?api=repair&id='+re.Id); // Blob pdfBody; // if(Test.isRunningTest()) { // pdfBody = blob.valueOf('Unit.Test'); // } else { // pdfBody = pdfPage.getContentAsPDF(); // } // Attachment attach = new Attachment(); // attach.Body = pdfBody; // attach.Name = re.name + '_' + 'Problem_Discription.pdf'; // attach.ParentId = re.id; // attachments.add(attach); // re.GeneratedPDFField__c = 'ProblemDescription__c'; // updateRpr.add(re); // } // insert attachments; // update updateRpr; // return null; // //20231027 ymh添加注释 lighting修改附件上传 end } }