19626
2023-09-09 e14d6d0619330cad423f06493e3aa2371faa2a8f
force-app/main/default/classes/eSignAgencyPageController.cls
@@ -354,41 +354,125 @@
    public static Id saveTheFile(Id parentId, String fileName, String base64Data, String contentType) {
        base64Data = EncodingUtil.urlDecode(base64Data, 'UTF-8');
 
        Attachment oAttachment = new Attachment();
        oAttachment.parentId = parentId;
        // Attachment oAttachment = new Attachment();
        // oAttachment.parentId = parentId;
 
        oAttachment.Body = EncodingUtil.base64Decode(base64Data);
        oAttachment.Name = fileName;
        oAttachment.ContentType = contentType;
        // oAttachment.Body = EncodingUtil.base64Decode(base64Data);
        // oAttachment.Name = fileName;
        // oAttachment.ContentType = contentType;
 
        insert oAttachment;
        return oAttachment.Id;
        // insert oAttachment;
        ContentVersion version = new ContentVersion();
        version.Title = fileName;
        version.VersionData = EncodingUtil.base64Decode(base64Data);
        version.ContentLocation = 's';
        version.PathOnClient = fileName + '.' +contentType;
        insert version;
        version = [select ContentDocumentId from ContentVersion where Id =: version.Id limit 1];
        ContentDocumentLink link = new ContentDocumentLink();
        link.ContentDocumentId = version.ContentDocumentId;
        link.LinkedEntityId = parentId;
        link.ShareType = 'I';
        link.Visibility = 'AllUsers';
        insert link;
        return link.ContentDocumentId;
    }
 
    private static void appendToFile(Id fileId, String base64Data) {
        base64Data = EncodingUtil.urlDecode(base64Data, 'UTF-8');
 
        Attachment a = [
            SELECT Id, Body
            FROM Attachment
            WHERE Id =: fileId
        ];
        // Attachment a = [
        //     SELECT Id, Body
        //     FROM Attachment
        //     WHERE Id =: fileId
        // ];
        ContentVersion version = [select Id,VersionData from ContentVersion where ContentDocumentId =: fileId];
 
        String existingBody = EncodingUtil.base64Encode(a.Body);
        // String existingBody = EncodingUtil.base64Encode(a.Body);
        String existingBody = EncodingUtil.base64Encode(version.VersionData);
 
        a.Body = EncodingUtil.base64Decode(existingBody + base64Data);
        // a.Body = EncodingUtil.base64Decode(existingBody + base64Data);
        version.VersionData = EncodingUtil.base64Decode(existingBody + base64Data);
 
        update a;
        update version;
    }
    //文件删除功能  精琢技术 thh 2021-09-26 start
    @AuraEnabled
    public static void deleteChunk(Id AttachmentId) {
        Attachment attachment = new Attachment();
        attachment.id = AttachmentId;
        delete attachment;
        // Attachment attachment = new Attachment();
        // attachment.id = AttachmentId;
        ContentDocument con = new ContentDocument();
        con.Id = AttachmentId;
        delete con;
        // delete attachment;
    }
    //文件删除功能  精琢技术 thh 2021-09-26 end
    //获取AWS信息 zhj 2023-01-03 start
    @AuraEnabled
    public static ControllerResponse getAWS(String objectName){
        ControllerResponse res = new ControllerResponse();
        try{
            res.Data = JSON.serialize(PIHelper.getPIIntegrationInfo(objectName));
            res.IsSuccess = true;
        }catch(Exception e){
            res.IsSuccess = false;
            res.Message = e.getMessage();
        }
        return res;
    }
    //获取AWS信息 zhj 2023-01-03 end
    //AWS改造文件上传 deloitte zhj 2023-01-03 start
    @AuraEnabled
    public static Id saveFile(String fileName,String key,String transId,String parentId){
        FileAddress__c file = new FileAddress__c();
        PIHelper.PIIntegration pI=PIHelper.getPIIntegrationInfo('Document');
        // 去除filename里得“&” bysushanhu 20220414
        fileName = fileName.remove('&');
        file.DownloadLink__c =pI.undeleteUrl+key+'&fileName='+fileName;
        file.FileName__c =fileName;
        file.ViewLink__c =pI.queryUrl+key;
        file.ParentRecordId__c =parentId;
        file.AWS_File_Key__c = key;
        insert file;
        return file.Id;
    }
    //AWS改造文件上传 deloitte zhj 2023-01-03 end
    //获取上传文件 deloitte zhj 2023-01-03 start
    public static List<FileAddress__c> getFileds(String parentId){
        // SWAG-C9S9P6 2022-05-25 ssm start
        // 文件地址里增加招标项目专用字段(信息Id、项目阶段、更新日期)
        if(String.isNotBlank(parentId)){
            return [SELECT Id,ParentRecordId__c, FileName__c,DownloadLink__c,FileAddress__c.ViewLink__c,AWS_File_Key__c  //deloitte zhj 预览/下载 加token 2022/12/01
                    // SWAG-C9S9P6 新增字段 start
                    , InfoId__c, InfoType__c, subInfoType__c, UpdateDate__c
                    // SWAG-C9S9P6 新增字段 end
                    FROM FileAddress__c where ParentRecordId__c=:parentId order by createddate desc];
        }
        return [SELECT Id, ParentRecordId__c,FileName__c,DownloadLink__c,FileAddress__c.ViewLink__c,AWS_File_Key__c  //deloitte zhj 预览/下载 加token 2022/12/01
                // SWAG-C9S9P6 新增字段 start
                , InfoId__c, InfoType__c, subInfoType__c, UpdateDate__c
                // SWAG-C9S9P6 新增字段 end
                FROM FileAddress__c order by createddate desc limit 100];
        // SWAG-C9S9P6 2022-05-25 ssm end
    }
    //获取上传文件 deloitte zhj 2023-01-03 end
    //AWS文件删除功能  deloitte zhj 2022-01-03 start
    @AuraEnabled
    public static String deleteFile(String fileId){
        System.debug('fileId = ' + fileId);
        List<FileAddress__c> fList = [select id,AWS_File_Key__c from FileAddress__c where id =:fileId];
        String awsKey = '';
        if(fList != null && fList.size() > 0){
            awsKey = fList[0].AWS_File_Key__c;
            delete fList;
        }
        return awsKey;
    }
    //AWS文件删除功能  deloitte zhj 2022-01-03 end
}