From e53fdfdd78538a21cddd45b9d3faa1a7e9e37a0a Mon Sep 17 00:00:00 2001
From: 19626 <1962676589@qq.com>
Date: 星期五, 21 七月 2023 13:36:24 +0800
Subject: [PATCH] 修改附件
---
force-app/main/default/classes/OFSUploadRepairImageRest.cls | 80 +++++++++++++++++++++++++++++-----------
1 files changed, 58 insertions(+), 22 deletions(-)
diff --git a/force-app/main/default/classes/OFSUploadRepairImageRest.cls b/force-app/main/default/classes/OFSUploadRepairImageRest.cls
index 1e68355..796f9e8 100644
--- a/force-app/main/default/classes/OFSUploadRepairImageRest.cls
+++ b/force-app/main/default/classes/OFSUploadRepairImageRest.cls
@@ -26,20 +26,38 @@
res.responseBody = blob.valueOf(jsonResponse);
return;
}
- List<Attachment> attList = [Select Id, Name, Body, ParentId From Attachment Where Id= :repairQ.contract_consent_id__c];
- Attachment att = null;
- if (attList.size() > 0) {
- att = attList[0];
+ // List<Attachment> attList = [Select Id, Name, Body, ParentId From Attachment Where Id= :repairQ.contract_consent_id__c];
+ // Attachment att = null;
+ List<ContentVersion> verisonList = [select Id,Title,VersionData from ContentVersion where Id =: repairQ.contract_consent_id__c];
+ ContentVersion version = null;
+ if (verisonList.size() > 0) {
+ version = verisonList[0];
} else {
- att = new Attachment();
- att.Name = 'ContractConsent.jpg';
- att.ParentId = rqId;
+ // att = new Attachment();
+ // att.Name = 'ContractConsent.jpg';
+ // att.ParentId = rqId;
+ version = new ContentVersion();
+ version.Title = 'ContractConsent.jpg';
+ version.ContentLocation = 's';
+ version.PathOnClient = 'ContractConsent.jpg';
}
- att.Body = EncodingUtil.base64Decode(ccImg);
+ // att.Body = EncodingUtil.base64Decode(ccImg);
+ version.VersionData = EncodingUtil.base64Decode(ccImg);
try {
- if (attList.size() > 0) { update att; }
- else { insert att; }
- ccId = att.Id;
+ if (verisonList.size() > 0) {
+ update version;
+ }
+ else {
+ insert version;
+ version = [select Id,ContentDocumentId from ContentVersion where Id =: version.Id];
+ ContentDocumentLink link = new ContentDocumentLink();
+ link.ContentDocumentId = version.ContentDocumentId;
+ link.LinkedEntityId = rqId;
+ link.ShareType = 'I';
+ link.Visibility = 'AllUsers';
+ insert link;
+ }
+ ccId = version.Id;
repairQ.contract_consent_id__c = ccId;
} catch ( Exception ex ) {
//TODO:
@@ -62,20 +80,38 @@
}
}
if (String.isNotBlank(acImg)) {
- List<Attachment> attList = [Select Id, Name, Body, ParentId From Attachment Where Id= :repair.acceptance_id__c];
- Attachment att = null;
- if (attList.size() > 0) {
- att = attList[0];
+ // List<Attachment> attList = [Select Id, Name, Body, ParentId From Attachment Where Id= :repair.acceptance_id__c];
+ List<ContentVersion> versionList = [select Id,Title,VersionData from ContentVersion where Id =: repair.acceptance_id__c];
+ // Attachment att = null;
+ ContentVersion version = null;
+ if (versionList.size() > 0) {
+ version = versionList[0];
} else {
- att = new Attachment();
- att.Name = 'Acceptance.jpg';
- att.ParentId = repairId;
+ // att = new Attachment();
+ // att.Name = 'Acceptance.jpg';
+ // att.ParentId = repairId;
+ version = new ContentVersion();
+ version.Title = 'Acceptance.jpg';
+ version.ContentLocation = 's';
+ version.PathOnClient = 'Acceptance.jpg';
}
- att.Body = EncodingUtil.base64Decode(acImg);
+ // att.Body = EncodingUtil.base64Decode(acImg);
+ version.VersionData = EncodingUtil.base64Decode(acImg);
try {
- if (attList.size() > 0) { update att; }
- else { insert att; }
- acId = att.Id;
+ if (versionList.size() > 0) {
+ update version;
+ }
+ else {
+ insert version;
+ version = [select Id,ContentDocumentId from ContentVersion where Id =: version.Id];
+ ContentDocumentLink link = new ContentDocumentLink();
+ link.LinkedEntityId = repairId;
+ link.ShareType = 'I';
+ link.Visibility = 'AllUsers';
+ link.ContentDocumentId = version.ContentDocumentId;
+ insert link;
+ }
+ acId = version.Id;
} catch ( Exception ex ) {
//TODO:
//error message:cannot update exception
--
Gitblit v1.9.1