yumenghui
2023-08-11 d533f39b6fa798e238810d17e928dee75d5b1af7
备注添加改造
4个文件已添加
178 ■■■■■ 已修改文件
force-app/main/default/classes/ReAndQISNotePDFController.cls 136 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/ReAndQISNotePDFController.cls-meta.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/pages/ReAndQISNotePDF.page 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/pages/ReAndQISNotePDF.page-meta.xml 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/ReAndQISNotePDFController.cls
New file
@@ -0,0 +1,136 @@
public with sharing class ReAndQISNotePDFController {
    // DB202304087063 课题对应
    // public Note Noteinfo {get; set;}
    public ContentVersion Versioninfo {get; set;}
    // public String Title{get; set;}
    // public String Body{get; set;}
    // id
    public String objId {get; set;}
    public ReAndQISNotePDFController(){
        objId = ApexPages.currentPage().getParameters().get('id');
        // Noteinfo = [select Id,Parentid,Title,Body  from Note where id = :objId];
        Versioninfo = [SELECT Id,Title,VersionData,TextPreview FROM ContentVersion WHERE ContentDocumentId =: objId];
    }
    // 生成pdf添加到对应的修理中
    @Future(callout=true)
    public static void generateAttachment(List<String> reAndQisMap){
        PageReference pdfPage ;
        system.debug('reAndQisMap数据:' + reAndQisMap);
        List<ContentDocumentLink> linkList = new List<ContentDocumentLink>();
        List<ContentVersion> versionList = new List<ContentVersion>();
        // Map<Id,Repair__c> updateRpr = [select id,SerialNumber__c,Delivered_Product__r.Name
        //                              from Repair__c where id in : reAndQisMap.keySet()];
        // Map<Id,QIS_Report__c>updateQis = [select id,lot_or_serial__c,nonyushohin__r.Name
        //                              from QIS_Report__c where id in : reAndQisMap.keySet()];
        List<ContentDocumentLink> selectLinkList = [SELECT ContentDocumentId FROM ContentDocumentLink WHERE Id in: reAndQisMap];
        List<Id> linkIdList = new List<Id>();
        for (ContentDocumentLink link : selectLinkList) {
            linkIdList.add(link.ContentDocumentId);
        }
        List<ContentDocument> ntList = [Select id,Title FROM ContentDocument where Id in : linkIdList];
        List<Id> docIdList =new List<Id>();
        List<Id> verIdList = new List<Id>();
        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<ContentVersion> versionDocId = new List<ContentVersion>();
        if (verIdList.size()>0) {
            versionDocId = [select ContentDocumentId from ContentVersion where Id IN: verIdList];
        }
        if (versionDocId.size()>0 && docIdList.size()>0) {
            List<ContentDocumentLink> 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<Note> NtList = [Select id,ParentId,Title,Body FROM Note where Id in : reAndQisMap];
        // List<Attachment> attachments = new List<Attachment>();
        // 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;
    }
}
force-app/main/default/classes/ReAndQISNotePDFController.cls-meta.xml
New file
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>56.0</apiVersion>
    <status>Active</status>
</ApexClass>
force-app/main/default/pages/ReAndQISNotePDF.page
New file
@@ -0,0 +1,30 @@
<apex:page controller="ReAndQISNotePDFController" renderAs="pdf" applyHtmlTag="false" applyBodyTag="false"  showheader="false"  contentType="text/html; charset=UTF-8" lightningStylesheets="true">
    <html>
        <head>
            <style>
                /*table{margin: auto;}*/
                body {
                    /*text-align: center;*/
                    font-family: Arial Unicode MS;
                    font-size:14px;
                    font-weight:200;
                }
            </style>
        </head>
        <body>
            <table width="300" border="1" cellspacing="0">
                <tr>
                    <td style="height:300px; text-align: center;width: 80%">
                    <!-- <td style="text-align: center;"> -->
                            <!-- <apex:outputText value="{!Noteinfo.Title}" escape="false"  />
                            <br/>
                            <apex:outputField value="{!Noteinfo.Body}"/> -->
                            <apex:outputText value="{!Versioninfo.Title}" escape="false"  />
                            <br/>
                            <apex:outputField value="{!Versioninfo.TextPreview}"/>
                    </td>
                </tr>
            </table>
        </body>
    </html>
</apex:page>
force-app/main/default/pages/ReAndQISNotePDF.page-meta.xml
New file
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexPage xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>56.0</apiVersion>
    <availableInTouch>false</availableInTouch>
    <confirmationTokenRequired>false</confirmationTokenRequired>
    <label>ReAndQISNotePDF</label>
</ApexPage>