19626
2023-09-09 e14d6d0619330cad423f06493e3aa2371faa2a8f
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 Id,Title,OwnerId 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 = '上传文件失败,请重试!';
@@ -104,7 +127,7 @@
            opdPlan.noReportStatus__c = '已保存';
            System.debug('opdPlan2:'+opdPlan);
            update opdPlan;
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM, '保存完毕!'));
            // ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM, '保存完毕!'));
            saveFlag = true;
        }catch(exception e){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, e.getMessage()));