public without sharing class eSignHospitalConfirmController { //Get Account Records @AuraEnabled public static eSignWrapper geteSigns(String DNName){ // 最多只显示200条明细数据 List eSignFormLineItems = [SELECT Id, OTCode__c, Name, Asset_Model_No__c , productName__c, Count_Text__c, GoodStatus__c, agencyGoodStatus__c, agencyConfirmResult__c, HPConfirmResult__c, HPGoodStatus__c , CaseNumber__c FROM eSignFormLineItem__c where eSignForm__r.DNNameNo0__c =: DNName order by CaseNumber__c asc ]; system.debug('eSignFormLineItems:'+eSignFormLineItems); eSignForm__c eSignForm = [SELECT Id, Name, supplier__c, supplierNo__c, ContractNO__c, shippingUnit__c, shippingAddress__c, DNNameNo0__c, contactName__c, contactNumber__c, DeliveryDate__c, endUserName__c, totalNumber__c, transportMode__c, totalWeight__c, Hospital_Name__c,handleOpinionHP__c,handleOpinionAgency__c, //GoodDetails__c, weight__c, account_Name__c FROM eSignForm__c where DNNameNo0__c =: DNName ]; eSignWrapper eSignWrapper = new eSignWrapper(); eSignWrapper.eSignFormLineItems = loadeSignFormEntry(eSignFormLineItems, '医院收货', eSignForm.ID ); eSignWrapper.eSignForm = eSignForm; return eSignWrapper; } @AuraEnabled public static saveeSignFormEntryResult saveeSignFormEntry( list eSignFormLineItems, eSignForm__c eSignForm , string entryType, boolean IsSubmit){ saveeSignFormEntryResult tempResult = new saveeSignFormEntryResult(); try{ eSignFormEntry__c tempeSignFormEntry = new eSignFormEntry__c(); List lastESignFormEntryList = [select id,agencyScanDayBack__c,agencySignUpDateBack__c,agencyConfirmDateBack__c, HPScanDayBack__c,HPSignUpDateBack__c,IsSubmit__c,IsHPSubmit__c,AgencyWorkflowEmailBack__c,HPWorkflowEmailBack__c,AgencyWorkflowEmail__c,HPWorkflowEmail__c,agencyAutoSignUpStatus__c,agencyReject__c,HPReject__c,IsAgencyScan__c,IsHPScan__c,IsHandled__c from eSignFormEntry__c where eSignForm__c = :eSignForm.ID order by createddate desc limit 1]; if(lastESignFormEntryList.size()>0){ //经销商扫描日 tempeSignFormEntry.agencyScanDayBack__c = lastESignFormEntryList[0].agencyScanDayBack__c; //经销商签收日 tempeSignFormEntry.agencySignUpDateBack__c = lastESignFormEntryList[0].agencySignUpDateBack__c; //经销商确认日 tempeSignFormEntry.agencyConfirmDateBack__c = lastESignFormEntryList[0].agencyConfirmDateBack__c; //医院扫描日 tempeSignFormEntry.HPScanDayBack__c = lastESignFormEntryList[0].HPScanDayBack__c; //医院签收日 tempeSignFormEntry.HPSignUpDateBack__c = lastESignFormEntryList[0].HPSignUpDateBack__c; //经销商是否提交 tempeSignFormEntry.IsSubmit__c = lastESignFormEntryList[0].IsSubmit__c; //医院是否提交 tempeSignFormEntry.IsHPSubmit__c = lastESignFormEntryList[0].IsHPSubmit__c; //医院是否扫描 tempeSignFormEntry.IsHPScan__c = lastESignFormEntryList[0].IsHPScan__c; //经销商邮箱 tempeSignFormEntry.AgencyWorkflowEmailBack__c = lastESignFormEntryList[0].AgencyWorkflowEmail__c; //医院邮箱 tempeSignFormEntry.HPWorkflowEmailBack__c = lastESignFormEntryList[0].HPWorkflowEmailBack__c; //如果上一条经销商已处理,但是签收单被驳回了,那么医院签收的中间表就不应该有这两个经销商的勾 //其它情况都应该带着 if(lastESignFormEntryList[0].IsHandled__c && lastESignFormEntryList[0].agencyAutoSignUpStatus__c == '不批准'){ tempeSignFormEntry.IsSubmit__c = false; tempeSignFormEntry.IsAgencyScan__c = false; }else{ tempeSignFormEntry.IsSubmit__c = lastESignFormEntryList[0].IsHPSubmit__c; tempeSignFormEntry.IsAgencyScan__c = lastESignFormEntryList[0].IsAgencyScan__c; } } //医院确认日 tempeSignFormEntry.HPConfirmDateBack__c = Date.today(); tempeSignFormEntry.Name = eSignForm.Name + '-' + entryType; tempeSignFormEntry.entryType__c = entryType; tempeSignFormEntry.eSignForm__c = eSignForm.ID; insert tempeSignFormEntry; list eSignFormLineItemEntryList = new list(); for(eSignFormLineItem__c tempeSignFormLineItem : eSignFormLineItems){ eSignFormLineItemEntry__c tempeSignFormLineItemEntry = new eSignFormLineItemEntry__c(); tempeSignFormLineItemEntry.eSignFormEntry__c = tempeSignFormEntry.id; tempeSignFormLineItemEntry.Name = tempeSignFormLineItem.Name; tempeSignFormLineItemEntry.eSignFormLineItem__c = tempeSignFormLineItem.id; //更新之前的经销商、医院的操作流程信息 货物情况(经销商)、确认结果(经销商)、货物情况(医院) tempeSignFormLineItemEntry.agencyConfirmResult__c = tempeSignFormLineItem.agencyConfirmResult__c; tempeSignFormLineItemEntry.agencyGoodStatus__c = tempeSignFormLineItem.agencyGoodStatus__c; tempeSignFormLineItemEntry.HPGoodStatus__c = tempeSignFormLineItem.HPGoodStatus__c; tempeSignFormLineItemEntry.HPConfirmResult__c = tempeSignFormLineItem.HPConfirmResult__c; //如果医院货物情况为完好,默认赋值为同意 if(tempeSignFormLineItem.HPGoodStatus__c == '完好'){ tempeSignFormLineItemEntry.HPConfirmResult__c = '同意'; } eSignFormLineItemEntryList.add(tempeSignFormLineItemEntry); } if(eSignFormLineItemEntryList.size() > 0 ){ insert eSignFormLineItemEntryList; } tempResult.isSuccess = true; tempResult.result = tempeSignFormEntry.id; }catch(Exception e){ tempResult.result = e.getMessage(); } return tempResult; } public static List loadeSignFormEntry( List eSignFormLineItems, string entryType, string eSignFormID ){ list tempeSignFormEntryList = [select id from eSignFormEntry__c where eSignForm__c = :eSignFormID and entryType__c =: entryType order by createddate desc limit 1 ]; if( tempeSignFormEntryList.size() == 0){ return eSignFormLineItems; } list eSignFormLineItemEntryList = [select id ,HPGoodStatus__c,eSignFormLineItem__c,HPConfirmResult__c,CaseNumber__c from eSignFormLineItemEntry__c where eSignFormEntry__c =: tempeSignFormEntryList[0].id ]; map eSignFormLineItemEntryMap = new map(); for( eSignFormLineItemEntry__c tempESignEntryItem : eSignFormLineItemEntryList){ eSignFormLineItemEntryMap.put(tempESignEntryItem.eSignFormLineItem__c, tempESignEntryItem); } for( eSignFormLineItem__c tempEsignItem: eSignFormLineItems){ eSignFormLineItemEntry__c tempESignEntryItem = eSignFormLineItemEntryMap.get(tempEsignItem.id); if(tempESignEntryItem.HPGoodStatus__c != null){ tempEsignItem.HPGoodStatus__c = tempESignEntryItem.HPGoodStatus__c; } // tempEsignItem.CaseNumber__c = tempESignEntryItem.CaseNumber__c; if(String.isBlank(tempEsignItem.HPConfirmResult__c)){ tempEsignItem.HPConfirmResult__c= '同意'; } } return eSignFormLineItems; } public class saveeSignFormEntryResult{ @AuraEnabled public Boolean isSuccess; @AuraEnabled public string result; public saveeSignFormEntryResult(){ isSuccess = false; result = ''; } } public class eSignWrapper{ @AuraEnabled public List eSignFormLineItems; @AuraEnabled public eSignForm__c eSignForm; public eSignWrapper(){ eSignFormLineItems = new List(); eSignForm = new eSignForm__c(); } } //文件上传 @AuraEnabled public static Id saveChunk(Id parentId, String fileName, String base64Data, String contentType, String fileId) { // check if fileId id ''(Always blank in first chunk), then call the saveTheFile method, // which is save the check data and return the attachemnt Id after insert, // next time (in else) we are call the appentTOFile() method // for update the attachment with reamins chunks System.debug('base64Data = ' + base64Data); if (fileId == '') { fileId = saveTheFile(parentId, fileName, base64Data, contentType); } else { fileId = appendToFile(parentId, fileId, base64Data); } return Id.valueOf(fileId); } public static Id saveTheFile(Id parentId, String fileName, String base64Data, String contentType) { base64Data = EncodingUtil.urlDecode(base64Data, 'UTF-8'); // 20231103 Lightning文件修改 Start ContentVersion version = new ContentVersion(); version.Title = fileName; version.VersionData = EncodingUtil.base64Decode(base64Data); version.ContentLocation = 's'; version.PathOnClient = fileName + '.' + contentType; version.FirstPublishLocationId = parentId; version.Description = parentId; insert version; version = [select ContentDocumentId from ContentVersion where Id =: version.Id]; System.debug('version.ContentDocumentId = ' + version.ContentDocumentId); // ContentDocumentLink link = new ContentDocumentLink(); // link.ContentDocumentId = version.ContentDocumentId; // link.LinkedEntityId = parentId; // link.ShareType = 'I'; // link.Visibility = 'AllUsers'; // insert link; // Attachment oAttachment = new Attachment(); // oAttachment.parentId = parentId; // oAttachment.Body = EncodingUtil.base64Decode(base64Data); // oAttachment.Name = fileName; // oAttachment.ContentType = contentType; // insert oAttachment; BatchIF_Log__c iflog = new BatchIF_Log__c(); iflog.Type__c = 'ContentDocumentLink'; iflog.Log__c = 'first id: ' + parentId + '; version.ContentDocumentId: ' + version.ContentDocumentId + '; eSignHospitalConfirmController'; insert iflog; return version.ContentDocumentId; // return link.ContentDocumentId; // 20231103 Lightning文件修改 End } private static Id appendToFile(Id parentId, Id fileId, String base64Data) { base64Data = EncodingUtil.urlDecode(base64Data, 'UTF-8'); // 20231103 Lightning文件修改 Start // Attachment a = [ // SELECT Id, Body // FROM Attachment // WHERE Id =: fileId // ]; ContentVersion oldVersion = [select Id,VersionData,ContentDocumentId, Title from ContentVersion where ContentDocumentId =: fileId]; // List oldContentDocumentLink = [select Id,LinkedEntityId from ContentDocumentLink where ContentDocumentId =: fileId]; // String linkId = ''; // String key = Schema.getGlobalDescribe().get('eSignFormEntry__c').getDescribe().getKeyPrefix(); // for (ContentDocumentLink conDocuLink : oldContentDocumentLink) { // String lId = conDocuLink.LinkedEntityId; // if (lId.startsWith(key)) { // linkId = conDocuLink.LinkedEntityId; // } // } // String existingBody = EncodingUtil.base64Encode(a.Body); String existingBody = EncodingUtil.base64Encode(oldVersion.VersionData); // a.Body = EncodingUtil.base64Decode(existingBody + base64Data); // version.VersionData = EncodingUtil.base64Decode(existingBody + base64Data); ContentVersion version = new ContentVersion(); version.Title = oldVersion.Title; version.VersionData = EncodingUtil.base64Decode(existingBody + base64Data); version.ContentLocation = 's'; version.PathOnClient = oldVersion.Title; version.Description = parentId; insert version; System.debug('version.Id = ' + version.Id); version = [select ContentDocumentId from ContentVersion where Id =: version.Id limit 1]; System.debug('version.ContentDocumentId = ' + version.ContentDocumentId); // // if (String.isNotBlank(linkId)) { // ContentDocumentLink link = new ContentDocumentLink(); // link.ContentDocumentId = version.ContentDocumentId; // link.LinkedEntityId = parentId; // link.ShareType = 'I'; // link.Visibility = 'AllUsers'; // insert link; // } BatchIF_Log__c iflog = new BatchIF_Log__c(); iflog.Type__c = 'COntentDocumentLink'; iflog.Log__c = 'id: ' + parentId + '; version.ContentDocumentId: ' + version.ContentDocumentId + '; eSignHospitalConfirmController'; insert iflog; ContentDocument con = new ContentDocument(); con.Id = oldVersion.ContentDocumentId; if (!Test.isRunningTest()) { delete con; } return version.ContentDocumentId; // update version; // 20231103 Lightning文件修改 End } //文件删除功能 精琢技术 thh 2021-09-26 start @AuraEnabled public static void deleteChunk(Id AttachmentId) { // 20231103 Lightning文件修改 Start // Attachment attachment = new Attachment(); // attachment.id = AttachmentId; // delete attachment; ContentDocument con = new ContentDocument(); con.Id = AttachmentId; delete con; // 20231103 Lightning文件修改 End } //文件删除功能 精琢技术 thh 2021-09-26 end }