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/pages/AssetModifyBelongs.page                    |    2 
 force-app/main/default/classes/AttachmentReQisHandler.cls               |  109 +++++
 force-app/main/default/pages/AssetQR.page                               |   12 
 force-app/main/default/classes/NFM401Controller.cls                     |  127 ++++-
 force-app/main/default/classes/OFSRepairConsignPDFOuterController.cls   |    4 
 force-app/main/default/classes/NFMUtil.cls                              |  364 ------------------
 force-app/main/default/classes/OFSUploadImageRest.cls-meta.xml          |    2 
 force-app/main/default/classes/AttachmentReQisHandler.cls-meta.xml      |    5 
 force-app/main/default/classes/OPDNoReportApplicationController.cls     |   24 
 force-app/main/default/classes/InsReportPDFOuterController.cls          |  113 ++++-
 force-app/main/default/classes/eSignAgencyConfirmPageController.cls     |   58 +
 force-app/main/default/classes/InsReportPDFOuterController.cls-meta.xml |    2 
 force-app/main/default/pages/ConsumApplyQR.page                         |   16 
 force-app/main/default/classes/NFM609FiledDownloadBatch.cls             |   67 ++-
 force-app/main/default/classes/QRAndBRController.cls                    |    8 
 force-app/main/default/classes/BidAnnounceIframeController.cls          |    6 
 force-app/main/default/classes/OFSUploadRepairImageRest.cls             |   80 ++-
 force-app/main/default/classes/OFSUploadRepairImageRest.cls-meta.xml    |    2 
 force-app/main/default/classes/OFSUploadImageRest.cls                   |   72 ++
 force-app/main/default/classes/MaintenanceUpdateProductHandler.cls      |    7 
 force-app/main/default/classes/eSignHospitalPageController.cls          |   54 +
 force-app/main/default/pages/ConsumApplyBR.page                         |    2 
 force-app/main/default/classes/QRAndBRController.cls-meta.xml           |    5 
 23 files changed, 590 insertions(+), 551 deletions(-)

diff --git a/force-app/main/default/classes/AttachmentReQisHandler.cls b/force-app/main/default/classes/AttachmentReQisHandler.cls
new file mode 100644
index 0000000..86d17c1
--- /dev/null
+++ b/force-app/main/default/classes/AttachmentReQisHandler.cls
@@ -0,0 +1,109 @@
+/**
+ * SFDC绯荤粺妗堜欢锛堜慨鐞�/QIS锛変腑鏂板缓闄勪欢鎴栧娉ㄦ椂锛�
+ * 绯荤粺鑷姩閫氱煡鍒扮浉鍏充笟鍔′汉鍛�
+ * 鍏朵腑澶囨敞浼氳嚜鍔ㄧ敓鎴怭DF闄勪欢
+ */
+public without sharing class AttachmentReQisHandler extends Oly_TriggerHandler{
+    @TestVisible
+    private Map<Id, Attachment> newMap;
+    @TestVisible
+    private Map<Id, Attachment> oldMap;
+    @TestVisible
+    private List<Attachment> newList;
+    @TestVisible
+    private List<Attachment> oldList;
+    public AttachmentReQisHandler() {
+        this.newMap = (Map<Id, Attachment>) Trigger.newMap;
+        this.oldMap = (Map<Id, Attachment>) Trigger.oldMap;
+        this.newList = (List<Attachment>) Trigger.new;
+        this.oldList = (List<Attachment>) Trigger.old;
+    }
+    @TestVisible
+    protected override void afterInsert() {
+        // 淇悊ID
+        NoteMail();
+    }
+    private void NoteMail() {
+        String baseUrl = URL.getSalesforceBaseUrl().toExternalForm();
+        List<Messaging.SingleEmailMessage> sendMails = new List<Messaging.SingleEmailMessage>();
+        List<String> Rlist = new List<String>();
+        List<String> ParentIdList = new List<String>();
+        // QisID
+        for (Attachment att : newList) {
+            if(String.valueOf(att.ParentId).startsWith('a0J') 
+                || String.valueOf(att.ParentId).startsWith('a0f')){
+                Rlist.add(att.Id);
+                ParentIdList.add(att.ParentId);
+            }
+        }
+        List<Attachment> NtList = [Select id,ParentId,Name,Body FROM Attachment where Id in : Rlist];
+        Map<Id,Repair__c> updateRprMap = new Map<Id,Repair__c>();
+        Map<Id,QIS_Report__c> updateQisMap = new Map<Id,QIS_Report__c>();
+        for (Repair__c re :[select id,Name,SerialNumber__c,Delivered_Product__r.Name,HP_Name__c
+                                        from Repair__c where id in : ParentIdList] ) {
+            updateRprMap.put(re.id, re);
+        }
+        for (QIS_Report__c qi :[select id,Name,lot_or_serial__c,nonyushohin__r.Name,Hospital__r.Name 
+                                        from QIS_Report__c where id in : ParentIdList] ) {
+            updateQisMap.put(qi.id, qi);
+        }
+        // Map<Id,Repair__c> updateRprMap = [select id,Name,SerialNumber__c,Delivered_Product__r.Name
+        //                              from Repair__c where id in : ParentIdList];
+        // Map<Id,QIS_Report__c>updateQisMap = [select id,Name,lot_or_serial__c,nonyushohin__r.Name 
+        //                              from QIS_Report__c where id in : ParentIdList];
+        List<group> gList = [SELECT (select userOrGroupId from groupMembers) FROM group WHERE name = '闄勪欢涓婁紶閫氱煡灏忕粍'];
+        List<String> IdList = new List<String>();
+        if (gList != null && gList.size() > 0) {
+            for (Group g : gList) {
+                for (GroupMember gm : g.groupMembers) {
+                    IdList.add(gm.userOrGroupId);
+                }
+            }
+        }
+        List<User> userList = [select Id, Name, Email, Manager.Email from User where id IN :IdList];
+        for (Attachment nt : NtList) {
+            String titName = updateRprMap.containsKey(nt.ParentId)? updateRprMap.get(nt.ParentId).Name : updateQisMap.get(nt.ParentId).Name;
+            String prname = updateRprMap.containsKey(nt.ParentId)? updateRprMap.get(nt.ParentId).Delivered_Product__r.Name : updateQisMap.get(nt.ParentId).nonyushohin__r.Name;
+            String Serial = updateRprMap.containsKey(nt.ParentId)? updateRprMap.get(nt.ParentId).SerialNumber__c : updateQisMap.get(nt.ParentId).lot_or_serial__c;
+            String accountname = updateRprMap.containsKey(nt.ParentId)? updateRprMap.get(nt.ParentId).HP_Name__c : updateQisMap.get(nt.ParentId).Hospital__r.Name;
+            String title = '';
+            String body = '';
+            title = '銆愪慨鐞�/QIS銆戯細' + titName + '宸叉柊澧為檮浠讹紝璇锋煡鐪�';
+            body += '鐢ㄦ埛鍚嶏細' + accountname;
+            body += '<br/>';
+            body += '浜у搧鍚嶇О/鍨嬪彿 锛�' + prname;
+            body += '<br/>';
+            body += '鏈鸿韩鍙�/鎵瑰彿 锛�' + Serial;
+            body += '<br/>';
+            body += '闄勪欢鍚嶇О/澶囨敞鍚嶇О锛�' + nt.Name;
+            body += '<br/>';
+            body += '鎿嶄綔鎷呭綋锛�' + UserInfo.getName();
+            body += '<br/>';
+            body += '<br/>';
+            body += '閾炬帴锛�' + baseUrl + '/' + nt.ParentId +' ';
+            //鏀朵欢閭
+            List<String> toMailList = new List<String>();
+            String uId = UserInfo.getUserId();
+            for (User u : userList) {
+                if (u.Id != uId) {
+                    toMailList.add(u.Email);
+                }
+            }
+            //鎶勯�佺殑閭
+            List<String> ccMailList = new List<String>();
+            ccMailList.add('gaozhangwei@prec-tech.com');
+            ccMailList.add('wei_liang@olympus.com.cn');
+            Messaging.SingleEmailMessage messageNEW = new Messaging.SingleEmailMessage();
+            messageNEW.subject = title;
+            messageNEW.htmlBody = body;
+            messageNEW.setCharset('UTF-8');
+            messageNEW.toAddresses = toMailList;
+            if(ccMailList.size() > 0){
+                messageNEW.ccAddresses = ccMailList;
+            }
+            sendMails.add(messageNEW);
+        }
+        //鍦ㄥ崟涓簨鍔′腑锛屽彧鑳借皟鐢╯end鏂规硶 10 娆°��
+        Messaging.SendEmailResult[] results = messaging.sendEmail(sendMails);
+    }
+}
\ No newline at end of file
diff --git a/force-app/main/default/classes/AttachmentReQisHandler.cls-meta.xml b/force-app/main/default/classes/AttachmentReQisHandler.cls-meta.xml
new file mode 100644
index 0000000..f3bac1f
--- /dev/null
+++ b/force-app/main/default/classes/AttachmentReQisHandler.cls-meta.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
+    <apiVersion>41.0</apiVersion>
+    <status>Active</status>
+</ApexClass>
diff --git a/force-app/main/default/classes/BidAnnounceIframeController.cls b/force-app/main/default/classes/BidAnnounceIframeController.cls
index 68b19cb..6f2b673 100644
--- a/force-app/main/default/classes/BidAnnounceIframeController.cls
+++ b/force-app/main/default/classes/BidAnnounceIframeController.cls
@@ -20,12 +20,12 @@
         if (docList.size() > 0) {
             doc = docList[0];
         }
-        
+        ContentVersion version = [select Id from ContentVersion where ContentDocumentId =: doc.Id];
         if (bid.Web_URL__c != null) {
             // 涓爣閫氱煡涔RL鏇存柊鏃堕棿銆�銇ㄣ��鏈�鏂癆ttachment銇檪闁撱仺姣旇純銆佹柊銇椼亜銈傘伄銈掗仼鐢�
             if (doc != null) {
                 if (bid.Web_URL_ModifiedDate__c < doc.ContentModifiedDate) {
-                    iframe = '/lightning/r/ContentDocument/' + doc.Id + '/view';
+                    iframe = '/sfc/servlet.shepherd/version/renditionDownload?rendition=THUMB720BY480&versionId='+ version.Id;
                 } else {
                     iframe = bid.Web_URL__c;
                 }
@@ -37,7 +37,7 @@
         } else {
             // Attachment銈掗仼鐢�
             if (doc != null) {
-                iframe = '/lightning/r/ContentDocument/' + doc.Id + '/view';
+                iframe = '/sfc/servlet.shepherd/version/renditionDownload?rendition=THUMB720BY480&versionId='+ version.Id;
             }
         }
     }
diff --git a/force-app/main/default/classes/InsReportPDFOuterController.cls b/force-app/main/default/classes/InsReportPDFOuterController.cls
index cdde55d..6cd918f 100644
--- a/force-app/main/default/classes/InsReportPDFOuterController.cls
+++ b/force-app/main/default/classes/InsReportPDFOuterController.cls
@@ -15,46 +15,107 @@
     }
     
     public void saveSign() {
-        // Sign鐢诲儚銇竴銇ゃ仹銇勩亜銇樸們銇亜锛烡elete鈬扞nsert銇仚銈�
-        List<Attachment> atts = [select Id from Attachment where ParentId = :ir.Id and Name = :(ir.Name + '_Sign')];
-        if (atts.size() > 0) delete atts;
+        // // Sign鐢诲儚銇竴銇ゃ仹銇勩亜銇樸們銇亜锛烡elete鈬扞nsert銇仚銈�
+        // List<Attachment> atts = [select Id from Attachment where ParentId = :ir.Id and Name = :(ir.Name + '_Sign')];
+        // if (atts.size() > 0) delete atts;
         
-        Attachment ac = new Attachment();
-        ac.Body = EncodingUtil.base64Decode(this.signStr.removeStart('data:image/png;base64,'));
-        ac.Name = ir.Name + '_Sign';
-        ac.ParentId = ir.Id;
-        ac.ContentType = 'jpg';
+        // Attachment ac = new Attachment();
+        // ac.Body = EncodingUtil.base64Decode(this.signStr.removeStart('data:image/png;base64,'));
+        // ac.Name = ir.Name + '_Sign';
+        // ac.ParentId = ir.Id;
+        // ac.ContentType = 'jpg';
+        // try {
+        //     insert ac;
+        //     //TODO status銆屻偟銈ゃ兂娓堛伩銆嶃伀銇欍倠
+        //     ir.ResponsiblePerson_Sign__c = '<img src="/servlet/servlet.FileDownload?file=' + ac.Id + '"/>';
+        //     ir.SignUrl__c = '/servlet/servlet.FileDownload?file=' + ac.Id;
+        //     ir.Status__c = '宸茬瀛�';
+        //     update ir;
+        // } catch (Exception ex) {
+        //     ApexPages.addMessages(ex);
+        //     //return;
+        // }
+
+        List<ContentDocumentLink> links = [select ContentDocumentId from ContentDocumentLink where LinkedEntityId =: ir.Id];
+        if (links.size() > 0) {
+            List<Id> idList = new List<Id>();
+            for (ContentDocumentLink link : links) {
+                idList.add(link.ContentDocumentId);
+            }
+            List<ContentDocument> cons = [select Id from ContentDocument where Id in: idList and Title =: (ir.Name + '_Sign')];
+            if (cons.size() > 0) {
+                delete cons;
+            }
+        }
+        ContentVersion version = new ContentVersion();
+        version.Title = ir.Name + '_Sign';
+        version.VersionData = EncodingUtil.base64Decode(this.signStr.removeStart('data:image/png;base64,'));
+        version.PathOnClient = ir.Name + '_Sign.jpg';
+        version.ContentLocation = 's';
         try {
-            insert ac;
-            //TODO status銆屻偟銈ゃ兂娓堛伩銆嶃伀銇欍倠
-            ir.ResponsiblePerson_Sign__c = '<img src="/servlet/servlet.FileDownload?file=' + ac.Id + '"/>';
-            ir.SignUrl__c = '/servlet/servlet.FileDownload?file=' + ac.Id;
+            insert version;
+            version = [select Id,ContentDocumentId from ContentVersion where Id =: version.Id];
+            ContentDocumentLink link = new ContentDocumentLink();
+            link.LinkedEntityId = ir.Id;
+            link.ShareType = 'I';
+            link.ContentDocumentId = version.ContentDocumentId;
+            link.Visibility = 'AllUsers';
+            insert link;
+            //     //TODO status銆屻偟銈ゃ兂娓堛伩銆嶃伀銇欍倠
+            // ir.ResponsiblePerson_Sign__c = '<img src="/lightning/r/ContentDocument/'+ link.ContentDocumentId + '/view"/>';
+            // ir.SignUrl__c = '/lightning/r/ContentDocument/'+ link.ContentDocumentId + '/view';
+            ir.ResponsiblePerson_Sign__c = '<img src="/sfc/servlet.shepherd/version/download/'+ version.Id + '"/>';
+            ir.SignUrl__c = '/sfc/servlet.shepherd/version/download/'+ version.Id;
             ir.Status__c = '宸茬瀛�';
             update ir;
-        } catch (Exception ex) {
-            ApexPages.addMessages(ex);
-            //return;
+        } catch (Exception e) {
+            ApexPages.addMessages(e);
         }
     }
     
     public void savePDF() {
+        // String pdfPageURL = '/apex/InsReportPDF?id=' + ir.Id;
+        // PageReference pageRef = new PageReference(pdfPageURL);
+
+        // Attachment att = new Attachment();
+        // // TODO TestMethod銇痝etContent銈掋偟銉濄兗銉堛仐銇亜
+        // if (!Test.isRunningTest()) {
+        //     att.body = pageRef.getContent();
+        // } else {
+        //     att.body = EncodingUtil.base64Decode('test');
+        // }
+        // att.Name = ir.Name + '_鐐规鎶ュ憡涔' + String.valueOf(Datetime.now()) + '.pdf';
+        // att.ParentId = ir.Id;
+        // try {
+        //     insert att;
+        // } catch (Exception ex) {
+        //     ApexPages.addMessages(ex);
+        //     //return;
+        // }
         String pdfPageURL = '/apex/InsReportPDF?id=' + ir.Id;
         PageReference pageRef = new PageReference(pdfPageURL);
-
-        Attachment att = new Attachment();
-        // TODO TestMethod銇痝etContent銈掋偟銉濄兗銉堛仐銇亜
+        ContentVersion version = new ContentVersion();
         if (!Test.isRunningTest()) {
-            att.body = pageRef.getContent();
+            version.VersionData = pageRef.getContent();
         } else {
-            att.body = EncodingUtil.base64Decode('test');
+            version.VersionData = EncodingUtil.base64Decode('test');
         }
-        att.Name = ir.Name + '_鐐规鎶ュ憡涔' + String.valueOf(Datetime.now()) + '.pdf';
-        att.ParentId = ir.Id;
+        // version.Title = ir.Name + '_鐐规鎶ュ憡涔' + String.valueOf(Datetime.now()) + '.pdf';
+        version.Title = ir.Name + '_鐐规鎶ュ憡涔' + String.valueOf(Datetime.now());
+        version.ContentLocation = 's';
+        version.PathOnClient = ir.Name + '_鐐规鎶ュ憡涔' + String.valueOf(Datetime.now()) + '.pdf';
         try {
-            insert att;
-        } catch (Exception ex) {
-            ApexPages.addMessages(ex);
-            //return;
+            insert version;
+            version = [select ContentDocumentId from ContentVersion where Id =: version.Id];
+            ContentDocumentLink link = new ContentDocumentLink();
+            link.LinkedEntityId = ir.Id;
+            link.ShareType = 'I';
+            link.Visibility = 'AllUsers';
+            link.ContentDocumentId = version.ContentDocumentId;
+            insert link;
+        } catch (Exception e) {
+            ApexPages.addMessages(e);
+            // ApexPages.addMessage(e);
         }
     }
     
diff --git a/force-app/main/default/classes/InsReportPDFOuterController.cls-meta.xml b/force-app/main/default/classes/InsReportPDFOuterController.cls-meta.xml
index f165265..800e53c 100644
--- a/force-app/main/default/classes/InsReportPDFOuterController.cls-meta.xml
+++ b/force-app/main/default/classes/InsReportPDFOuterController.cls-meta.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
-    <apiVersion>29.0</apiVersion>
+    <apiVersion>43.0</apiVersion>
     <status>Active</status>
 </ApexClass>
diff --git a/force-app/main/default/classes/MaintenanceUpdateProductHandler.cls b/force-app/main/default/classes/MaintenanceUpdateProductHandler.cls
index 3f2fd09..a8b61bd 100644
--- a/force-app/main/default/classes/MaintenanceUpdateProductHandler.cls
+++ b/force-app/main/default/classes/MaintenanceUpdateProductHandler.cls
@@ -73,8 +73,9 @@
                 }   
             }
             for(String id:mpdIds){
-                List<Attachment> attachmentinfo = [SELECT Id, Name,OwnerId FROM Attachment WHERE  parentid  =:mpdIds ];
-                if(attachmentinfo.size() ==0){
+                List<ContentDocumentLink> linksinfo = [select Id from ContentDocumentLink where LinkedEntityId =: id];
+                // List<Attachment> attachmentinfo = [SELECT Id, Name,OwnerId FROM Attachment WHERE  parentid  =:mpdIds ];
+                if(linksinfo.size() ==0){
                     attachmentSize = true;
                 }
             }
@@ -90,7 +91,7 @@
                 }
                 
                 if(newMpd.Status__c=='瀹℃壒涓�-鏈嶅姟'&& newMpd.Status__c != old.Status__c && attachmentSize&&attachmentChange){
-                    newMpd.addError('杩樻病鏈変笂浼犻檮浠讹紝璇蜂笂浼犻檮浠讹紒');
+                    newMpd.addError('杩樻病鏈変笂浼犳枃浠讹紝璇蜂笂浼犳枃浠讹紒');
                 }
             }
         }
diff --git a/force-app/main/default/classes/NFM401Controller.cls b/force-app/main/default/classes/NFM401Controller.cls
index 4d90ab0..e4e7d33 100644
--- a/force-app/main/default/classes/NFM401Controller.cls
+++ b/force-app/main/default/classes/NFM401Controller.cls
@@ -117,6 +117,13 @@
         public String GLOBAL_ATTRIBUTE1;
         public String RECORD_INSERTED_DATE;
     }
+    public class ContentDocmentCtl{
+        public String title;
+        public Blob versionData;
+        public Integer contentSize;
+        public String parentId;
+        public String Id;
+    }
 
     webservice static void sendToETQ(String iflog_Id,BatchIF_Log__c rowDataSFDC, List<String> repairIds,String statu){
         if(statu == '' || statu == null){
@@ -244,21 +251,34 @@
 
             
             // 鏍规嵁淇悊鍜孮IS ID鍙栧緱淇悊闄勪欢鐩稿叧淇℃伅
-            List<Attachment> attachmentList = [select Id,
-                                                Name,
-                                                Body,
-                                                ParentId,
-                                                BodyLength 
-                                            from Attachment
-                                            where ParentId in : repairIds];
-            Map<String,List<Attachment>> rAMap = new Map<String,List<Attachment>>();
-            for (Attachment ra: attachmentList ) {
-                if (!rAMap.containsKey(ra.ParentId)) {
-                    rAMap.put(ra.ParentId, new List<Attachment>());
+            // List<Attachment> attachmentList = [select Id,
+            //                                     Name,
+            //                                     Body,
+            //                                     ParentId,
+            //                                     BodyLength 
+            //                                 from Attachment
+            //                                 where ParentId in : repairIds];
+            // Map<String,List<Attachment>> rAMap = new Map<String,List<Attachment>>();
+            // for (Attachment ra: attachmentList ) {
+            //     if (!rAMap.containsKey(ra.ParentId)) {
+            //         rAMap.put(ra.ParentId, new List<Attachment>());
+            //     }
+            //     rAMap.get(ra.ParentId).add(ra);
+            // }
+            // 鏍规嵁淇悊鍜孮IS ID鍙栧緱淇悊鏂囦欢鐩稿叧淇℃伅
+            List<ContentDocumentLink> links = [
+                select
+                ContentDocumentId,
+                LinkedEntityId
+                from ContentDocumentLink where LinkedEntityId in: repairIds
+            ];
+            Map<String,List<ContentDocumentLink>> rAMap = new Map<String,List<ContentDocumentLink>>();
+            for (ContentDocumentLink ra: links ) {
+                if (!rAMap.containsKey(ra.LinkedEntityId)) {
+                    rAMap.put(ra.LinkedEntityId, new List<ContentDocumentLink>());
                 }
-                rAMap.get(ra.ParentId).add(ra);
+                rAMap.get(ra.LinkedEntityId).add(ra);
             }
-
 
             // 鏍规嵁淇悊ID鍙栧緱QIS鐩稿叧淇℃伅
             List<QIS_Report__c> qISList = [select id,Name,
@@ -544,19 +564,43 @@
 
                  //ATTACHMENT
                 RepairRequest.ATTACHMENT = new List<Attachment_element>();
-                List<Attachment> attList = rAMap.get(rr.id);
-                if (attList != null && attList.size() > 0) {
-                    for(Attachment rpd : attList){
+                // List<Attachment> attList = rAMap.get(rr.id);
+                // if (attList != null && attList.size() > 0) {
+                //     for(Attachment rpd : attList){
 
+                //         //2020-11-05  濡傛灉闄勪欢澶у皬瓒呰繃1.5mb 鍙戦�侀偖浠舵彁绀�
+                //         if (rpd.BodyLength > 1048576) {
+                //             sendemail(rpd,'淇悊'+rr.Name);
+                //         }else{
+                //             Attachment_element Attachmentdet = new Attachment_element();
+                //             RepairRequest.ATTACHMENT.add(Attachmentdet);
+                //             Attachmentdet.FILE_DATA = EncodingUtil.base64Encode(rpd.body);
+                //             Attachmentdet.ATTACHMENT_FIELD_NAME = 'COMPLAINTS_DOCUMENT_ATTACHMENT';
+                //             Attachmentdet.FILE_NAME = rpd.Name;
+                //             Attachmentdet.GLOBAL_ATTRIBUTE1 = 'COMPLAINT';
+                //             Attachmentdet.RECORD_INSERTED_DATE = NFMUtil.formatDate2Str(Date.today());
+                //         }
+                //     }
+                // }
+                List<ContentDocumentLink> attList = rAMap.get(rr.id);
+                if (attList != null && attList.size() > 0) {
+                    for(ContentDocumentLink rpd : attList){
+                        ContentVersion version = [
+                            select
+                            Title,
+                            VersionData,
+                            ContentSize
+                            from ContentVersion where ContentDocumentId =: rpd.ContentDocumentId
+                        ];
                         //2020-11-05  濡傛灉闄勪欢澶у皬瓒呰繃1.5mb 鍙戦�侀偖浠舵彁绀�
-                        if (rpd.BodyLength > 1048576) {
-                            sendemail(rpd,'淇悊'+rr.Name);
+                        if (version.ContentSize > 1048576) {
+                            sendemail(version,'淇悊'+rr.Name);
                         }else{
                             Attachment_element Attachmentdet = new Attachment_element();
                             RepairRequest.ATTACHMENT.add(Attachmentdet);
-                            Attachmentdet.FILE_DATA = EncodingUtil.base64Encode(rpd.body);
+                            Attachmentdet.FILE_DATA = EncodingUtil.base64Encode(version.VersionData);
                             Attachmentdet.ATTACHMENT_FIELD_NAME = 'COMPLAINTS_DOCUMENT_ATTACHMENT';
-                            Attachmentdet.FILE_NAME = rpd.Name;
+                            Attachmentdet.FILE_NAME = version.Title;
                             Attachmentdet.GLOBAL_ATTRIBUTE1 = 'COMPLAINT';
                             Attachmentdet.RECORD_INSERTED_DATE = NFMUtil.formatDate2Str(Date.today());
                         }
@@ -702,24 +746,47 @@
 
                 // ATTACHMENT
                 RepairRequest.ATTACHMENT = new List<Attachment_element>();
-                List<Attachment> attList = rAMap.get(qr.id);
+                // List<Attachment> attList = rAMap.get(qr.id);
+                // if (attList != null && attList.size() > 0) {
+                //     for(Attachment rpd :attList){
+                //          //2020-11-05  濡傛灉闄勪欢澶у皬瓒呰繃1.5mb 鍙戦�侀偖浠舵彁绀�
+                //         if (rpd.BodyLength > 1048576) {
+                //             sendemail(rpd,'QIS '+qr.Name);
+                //         }else{
+                //             Attachment_element Attachmentdet = new Attachment_element();
+                //             RepairRequest.ATTACHMENT.add(Attachmentdet);
+                //             Attachmentdet.FILE_DATA = EncodingUtil.base64Encode(rpd.body);
+                //             Attachmentdet.ATTACHMENT_FIELD_NAME = 'COMPLAINTS_DOCUMENT_ATTACHMENT';
+                //             Attachmentdet.FILE_NAME = rpd.Name;
+                //             Attachmentdet.GLOBAL_ATTRIBUTE1 = 'COMPLAINT';
+                //             Attachmentdet.RECORD_INSERTED_DATE = NFMUtil.formatDate2Str(Date.today());
+                //         }
+                //     }
+                // }
+                List<ContentDocumentLink> attList = rAMap.get(qr.id);
                 if (attList != null && attList.size() > 0) {
-                    for(Attachment rpd :attList){
+                    for(ContentDocumentLink rpd :attList){
                          //2020-11-05  濡傛灉闄勪欢澶у皬瓒呰繃1.5mb 鍙戦�侀偖浠舵彁绀�
-                        if (rpd.BodyLength > 1048576) {
-                            sendemail(rpd,'QIS '+qr.Name);
+                        ContentVersion version = [
+                            select
+                            VersionData,
+                            Title,
+                            ContentSize
+                            from ContentVersion where ContentDocumentId =: rpd.ContentDocumentId
+                        ];
+                        if (version.ContentSize > 1048576) {
+                            sendemail(version,'QIS '+qr.Name);
                         }else{
                             Attachment_element Attachmentdet = new Attachment_element();
                             RepairRequest.ATTACHMENT.add(Attachmentdet);
-                            Attachmentdet.FILE_DATA = EncodingUtil.base64Encode(rpd.body);
+                            Attachmentdet.FILE_DATA = EncodingUtil.base64Encode(version.VersionData);
                             Attachmentdet.ATTACHMENT_FIELD_NAME = 'COMPLAINTS_DOCUMENT_ATTACHMENT';
-                            Attachmentdet.FILE_NAME = rpd.Name;
+                            Attachmentdet.FILE_NAME = version.Title;
                             Attachmentdet.GLOBAL_ATTRIBUTE1 = 'COMPLAINT';
                             Attachmentdet.RECORD_INSERTED_DATE = NFMUtil.formatDate2Str(Date.today());
                         }
                     }
                 }
-
 
                 if (statu == 'Q1') {
                     RepairRequest.AWARE_DATE = NFMUtil.formatDate2Str(qr.Trable_occur_daY_collect__c);
@@ -816,16 +883,16 @@
 
     //add by rentx 2020-11-05 start
     //鍙戦�佹彁绀洪檮浠惰繃澶х數瀛愰偖浠�
-    public static void SendEmail(Attachment rpd,String str){
+    public static void SendEmail(ContentVersion rpd,String str){
         
         // sendMails = new List<Messaging.SingleEmailMessage>();
         //鍙戦�侀偖浠�
         String title = '';
         String body = '';
-        title = str+' 涓殑闄勪欢 '+rpd.Name+' 鍙戦�乪tq澶辫触鎻愰啋';
+        title = str+' 涓殑鏂囦欢 '+rpd.Title+' 鍙戦�乪tq澶辫触鎻愰啋';
         body =  '鎮ㄥソ,';
         body += '<br/>';
-        body += str+'涓殑闄勪欢'+rpd.Name+'杩囧ぇ,瀵艰嚧鍙戦�丒TQ澶辫触!';
+        body += str+'涓殑鏂囦欢'+rpd.Title+'杩囧ぇ,瀵艰嚧鍙戦�丒TQ澶辫触!';
         body += '<br/>';
         body += '璇锋墜鍔ㄤ笂浼犲埌ETQ';
         List<String> toMailList = new List<String>();
diff --git a/force-app/main/default/classes/NFM609FiledDownloadBatch.cls b/force-app/main/default/classes/NFM609FiledDownloadBatch.cls
index 313a8d5..0a9062b 100644
--- a/force-app/main/default/classes/NFM609FiledDownloadBatch.cls
+++ b/force-app/main/default/classes/NFM609FiledDownloadBatch.cls
@@ -43,15 +43,15 @@
         }
 
         try{
-            List < Attachment > newAttList = AttachmentFiledDownload(endpoint, parentId, attachmentName);
+            List < ContentVersion > newAttList = AttachmentFiledDownload(endpoint, parentId, attachmentName);
 
-            if (newAttList.size() > 0) {
-                List < Attachment > delAttaList = [select id from Attachment where ParentId =: parentId];
-                if (delAttaList.size() > 0) {
-                    delete delAttaList;
-                }
-                insert newAttList;
-            } 
+            // if (newAttList.size() > 0) {
+            //     List < Attachment > delAttaList = [select id from Attachment where ParentId =: parentId];
+            //     if (delAttaList.size() > 0) {
+            //         delete delAttaList;
+            //     }
+            //     insert newAttList;
+            // } 
             if (updateCaseList.size() > 0) {
                 update updateCaseList;
             }
@@ -66,9 +66,22 @@
         // }
     }
 
-    global static List < Attachment > AttachmentFiledDownload(String endpoint, String parentId, String attachmentName) {
-
-        List < Attachment > result = new List < Attachment > ();
+    global static List < ContentVersion > AttachmentFiledDownload(String endpoint, String parentId, String attachmentName) {
+        List<ContentDocumentLink> linkList = [
+            select
+            ContentDocumentId
+            from ContentDocumentLink where LinkedEntityId =: parentId
+        ];
+        if (linkList.size() > 0) {
+            List<Id> idList = new List<Id>();
+            for (ContentDocumentLink link : linkList) {
+                idList.add(link.ContentDocumentId);
+            }
+            List<ContentDocument> conList = [select Id from ContentDocument where Id in: idList];
+            delete conList;
+        }
+        // List < Attachment > result = new List < Attachment > ();
+        List<ContentVersion> result = new List<ContentVersion>();
         Http http = new Http();
         HttpRequest req = new HttpRequest();
         req.setTimeout(120000);
@@ -82,9 +95,13 @@
 
         String statusCode = String.valueOf(response.getStatusCode());
         system.debug('statusCode---->' + statusCode);
-        Attachment atta = new Attachment();
-        atta.ParentId = parentId;
-        atta.Name = attachmentName;
+
+        // Attachment atta = new Attachment();
+        // atta.ParentId = parentId;
+        // atta.Name = attachmentName;
+        ContentVersion version = new ContentVersion();
+        version.Title = attachmentName;
+        version.ContentLocation = 's';
         if ('200'.equals(statusCode)) {
             // 闄勪欢澶у皬
             // 12,582,912
@@ -92,14 +109,24 @@
             System.debug('ContentLength----->' + ContentLength);
             if (ContentLength < 12582912) {
                 Blob bodyAsBlob = response.getBodyAsBlob();
-                atta.Body = bodyAsBlob;
-                result.add(atta);
+                version.VersionData = bodyAsBlob;
+                // atta.Body = bodyAsBlob;
+                result.add(version);
             } else {
-                atta.Name = '鏂囦欢澶у皬瓒呰繃12M,璇峰湪鏂版湇鍔$郴缁熸煡鐪�';
-                atta.Body = Blob.valueOf('鏂囦欢澶у皬瓒呰繃12M');
-                result.add(atta);
+                // atta.Name = '鏂囦欢澶у皬瓒呰繃12M,璇峰湪鏂版湇鍔$郴缁熸煡鐪�';
+                // atta.Body = Blob.valueOf('鏂囦欢澶у皬瓒呰繃12M');
+                version.Title = '鏂囦欢澶у皬瓒呰繃12M,璇峰湪鏂版湇鍔$郴缁熸煡鐪�';
+                version.VersionData = Blob.valueOf('鏂囦欢澶у皬瓒呰繃12M');
+                result.add(version);
             }
-
+            insert result;
+            version =  [select ContentDocumentId from ContentVersion where Id =: version.Id];
+            ContentDocumentLink link = new ContentDocumentLink();
+            link.LinkedEntityId = parentId;
+            link.ShareType = 'I';
+            link.ContentDocumentId = version.ContentDocumentId;
+            link.Visibility = 'AllUsers';
+            insert link;
         }
 
 
diff --git a/force-app/main/default/classes/NFMUtil.cls b/force-app/main/default/classes/NFMUtil.cls
index d058c29..b4ea4a7 100644
--- a/force-app/main/default/classes/NFMUtil.cls
+++ b/force-app/main/default/classes/NFMUtil.cls
@@ -1375,369 +1375,7 @@
 
     public static Integer ControllerUtil() {
         Integer i = 0;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
-        i++;
+        
         return i;
     }
 }
\ No newline at end of file
diff --git a/force-app/main/default/classes/OFSRepairConsignPDFOuterController.cls b/force-app/main/default/classes/OFSRepairConsignPDFOuterController.cls
index a089c99..039464c 100644
--- a/force-app/main/default/classes/OFSRepairConsignPDFOuterController.cls
+++ b/force-app/main/default/classes/OFSRepairConsignPDFOuterController.cls
@@ -55,8 +55,8 @@
         insert cDe;
         try {
             
-            rp.Sign__c = '<img src="/lightning/r/ContentDocument/' + contVerFile.ContentDocumentId + '/view"/>';
-            rp.SignUrl__c = '/lightning/r/ContentDocument/' + contVerFile.ContentDocumentId + '/view';
+            rp.Sign__c = '<img src="/sfc/servlet.shepherd/version/download/'+ contVerFile.Id + '"/>';
+            rp.SignUrl__c = '/sfc/servlet.shepherd/version/download/'+ contVerFile.Id;
             rp.SignDate__c = Date.today();
             update rp;
         } catch (Exception ex) {
diff --git a/force-app/main/default/classes/OFSUploadImageRest.cls b/force-app/main/default/classes/OFSUploadImageRest.cls
index 289550d..f6a624e 100644
--- a/force-app/main/default/classes/OFSUploadImageRest.cls
+++ b/force-app/main/default/classes/OFSUploadImageRest.cls
@@ -25,19 +25,37 @@
                     res.responseBody = blob.valueOf(jsonResponse);
                     return;
                 }
-                Attachment att;
+                // Attachment att;
+                ContentVersion version;
                 if (String.isNotBlank(repairQ.contract_consent_id__c)) {
-                    att = [Select Id, Name, Body, ParentId From Attachment Where Id= :repairQ.contract_consent_id__c];
+                    // att = [Select Id, Name, Body, ParentId From Attachment Where Id= :repairQ.contract_consent_id__c];
+                    version = [select Id,VersionData,Title from ContentVersion where Id =: repairQ.contract_consent_id__c];
                 } else {
-                    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 = new Attachment();
+                    // att.Name = 'ContractConsent.jpg';
+                    // att.ParentId = rqId;
                 }
-                att.Body = EncodingUtil.base64Decode(ccImg);
+                // att.Body = EncodingUtil.base64Decode(ccImg);
+                version.VersionData = EncodingUtil.base64Decode(ccImg);
                 try {
-                    if (String.isNotBlank(repairQ.contract_consent_id__c)) { update att; }
-                    else { insert att; }
-                    ccId = att.Id;
+                    if (String.isNotBlank(repairQ.contract_consent_id__c)) {
+                        update version; 
+                    }
+                    else { 
+                        insert version; 
+                        version = [select Id,ContentDocumentId from ContentVersion where Id =: version.Id];
+                        ContentDocumentLink link = new ContentDocumentLink();
+                        link.LinkedEntityId = rqId;
+                        link.ContentDocumentId = version.ContentDocumentId;
+                        link.ShareType = 'I';
+                        link.Visibility = 'AllUsers';
+                        insert link;
+                    }
+                    ccId = version.Id;
                     repairQ.contract_consent_id__c = ccId;
                 } catch ( Exception ex ) {
                     //TODO:
@@ -60,19 +78,37 @@
                 }
             }
             if (String.isNotBlank(acImg)) {
-                Attachment att;
+                // Attachment att;
+                ContentVersion version;
                 if (String.isNotBlank(repair.acceptance_id__c)) {
-                    att = [Select Id, Name, Body, ParentId From Attachment Where Id= :repair.acceptance_id__c];
+                    // att = [Select Id, Name, Body, ParentId From Attachment Where Id= :repair.acceptance_id__c];
+                    version = [select Id,Title,VersionData from ContentVersion where Id =: repair.acceptance_id__c];
                 } else {
-                    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 = new Attachment();
+                    // att.Name = 'Acceptance.jpg';
+                    // att.ParentId = repairId;
                 }
-                att.Body = EncodingUtil.base64Decode(acImg);
+                // att.Body = EncodingUtil.base64Decode(acImg);
+                version.VersionData = EncodingUtil.base64Decode(acImg);
                 try {
-                    if (String.isNotBlank(repair.acceptance_id__c)) { update att; }
-                    else { insert att; }
-                    acId = att.Id;
+                    if (String.isNotBlank(repair.acceptance_id__c)) {
+                        update version; 
+                    }
+                    else {
+                        insert version; 
+                        version = [select Id,ContentDocumentId from ContentVersion where Id =: version.Id];
+                        ContentDocumentLink link = new ContentDocumentLink();
+                        link.ShareType = 'I';
+                        link.Visibility = 'AllUsers';
+                        link.ContentDocumentId = version.ContentDocumentId;
+                        link.LinkedEntityId = repairId;
+                        insert link;
+                    }
+                    acId = version.Id;
                 } catch ( Exception ex ) {
                     //TODO:
                     //error message:cannot update exception
diff --git a/force-app/main/default/classes/OFSUploadImageRest.cls-meta.xml b/force-app/main/default/classes/OFSUploadImageRest.cls-meta.xml
index f165265..800e53c 100644
--- a/force-app/main/default/classes/OFSUploadImageRest.cls-meta.xml
+++ b/force-app/main/default/classes/OFSUploadImageRest.cls-meta.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
-    <apiVersion>29.0</apiVersion>
+    <apiVersion>43.0</apiVersion>
     <status>Active</status>
 </ApexClass>
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
diff --git a/force-app/main/default/classes/OFSUploadRepairImageRest.cls-meta.xml b/force-app/main/default/classes/OFSUploadRepairImageRest.cls-meta.xml
index f165265..800e53c 100644
--- a/force-app/main/default/classes/OFSUploadRepairImageRest.cls-meta.xml
+++ b/force-app/main/default/classes/OFSUploadRepairImageRest.cls-meta.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
-    <apiVersion>29.0</apiVersion>
+    <apiVersion>43.0</apiVersion>
     <status>Active</status>
 </ApexClass>
diff --git a/force-app/main/default/classes/OPDNoReportApplicationController.cls b/force-app/main/default/classes/OPDNoReportApplicationController.cls
index 55ef72f..52fd00d 100644
--- a/force-app/main/default/classes/OPDNoReportApplicationController.cls
+++ b/force-app/main/default/classes/OPDNoReportApplicationController.cls
@@ -71,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 = '涓婁紶鏂囦欢澶辫触锛岃閲嶈瘯锛�';
diff --git a/force-app/main/default/classes/QRAndBRController.cls b/force-app/main/default/classes/QRAndBRController.cls
new file mode 100644
index 0000000..73366b2
--- /dev/null
+++ b/force-app/main/default/classes/QRAndBRController.cls
@@ -0,0 +1,8 @@
+public with sharing class QRAndBRController {
+    public QRAndBRController(ApexPages.StandardController controller){
+        
+    }
+    public String getParentUrl(){
+        return ApexPages.currentPage().getHeaders().get('referer');
+    }
+}
\ No newline at end of file
diff --git a/force-app/main/default/classes/QRAndBRController.cls-meta.xml b/force-app/main/default/classes/QRAndBRController.cls-meta.xml
new file mode 100644
index 0000000..45cccbd
--- /dev/null
+++ b/force-app/main/default/classes/QRAndBRController.cls-meta.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
+    <apiVersion>57.0</apiVersion>
+    <status>Active</status>
+</ApexClass>
\ No newline at end of file
diff --git a/force-app/main/default/classes/eSignAgencyConfirmPageController.cls b/force-app/main/default/classes/eSignAgencyConfirmPageController.cls
index da7e851..4d43060 100644
--- a/force-app/main/default/classes/eSignAgencyConfirmPageController.cls
+++ b/force-app/main/default/classes/eSignAgencyConfirmPageController.cls
@@ -255,42 +255,62 @@
  
     public static Id saveTheFile(Id parentId, String fileName, String base64Data, String contentType) {
         base64Data = EncodingUtil.urlDecode(base64Data, 'UTF-8');
+        ContentVersion version = new ContentVersion();
+        version.VersionData = EncodingUtil.base64Decode(base64Data);
+        version.Title = fileName;
+        version.PathOnClient = fileName + contentType;
+        version.ContentLocation = 's';
+        insert version;
+        version = [select Id,ContentDocumentId from ContentVersion where Id =: version.Id];
+        ContentDocumentLink link = new ContentDocumentLink();
+        link.LinkedEntityId = parentId;
+        link.ContentDocumentId = version.ContentDocumentId;
+        link.Visibility = 'AllUsers';
+        link.ShareType = 'I';
+        insert link;
+
+        // 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;
  
-        insert oAttachment;
- 
-        return oAttachment.Id;
+        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(version.VersionData);
  
-        String existingBody = EncodingUtil.base64Encode(a.Body);
+        version.VersionData = EncodingUtil.base64Decode(existingBody + base64Data);
  
-        a.Body = 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;
+        // Attachment attachment = new Attachment();
+        // attachment.id = AttachmentId;
+        ContentDocument con = new ContentDocument();
+        con.Id = AttachmentId;
 
-        delete attachment;
+        delete con;
     }
     //鏂囦欢鍒犻櫎鍔熻兘  绮剧悽鎶�鏈� thh 2021-09-26 end
 }
\ No newline at end of file
diff --git a/force-app/main/default/classes/eSignHospitalPageController.cls b/force-app/main/default/classes/eSignHospitalPageController.cls
index a4ce651..073e9c0 100644
--- a/force-app/main/default/classes/eSignHospitalPageController.cls
+++ b/force-app/main/default/classes/eSignHospitalPageController.cls
@@ -262,41 +262,59 @@
     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;
+        // 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.LinkedEntityId = parentId;
+        link.ContentDocumentId = version.ContentDocumentId;
+        link.ShareType = 'I';
+        link.Visibility = 'AllUsers';
+        insert link;
  
-        return oAttachment.Id;
+        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 verison = [select Id,VersionData from ContentVersion where ContentDocumentId =: fileId];
  
-        String existingBody = EncodingUtil.base64Encode(a.Body);
+        // String existingBody = EncodingUtil.base64Encode(a.Body);
+        String existingBody = EncodingUtil.base64Encode(verison.VersionData);
  
-        a.Body = EncodingUtil.base64Decode(existingBody + base64Data);
+        verison.VersionData = EncodingUtil.base64Decode(existingBody + base64Data);
  
-        update a;
+        update verison;
     }
     
     //鏂囦欢鍒犻櫎鍔熻兘  绮剧悽鎶�鏈� thh 2021-09-26 start
     @AuraEnabled
     public static void deleteChunk(Id AttachmentId) {
-        Attachment attachment = new Attachment();
-        attachment.id = AttachmentId;
+        // Attachment attachment = new Attachment();
+        // attachment.id = AttachmentId;
 
-        delete attachment;
+        // delete attachment;
+        ContentDocument con =  new ContentDocument();
+        con.Id = AttachmentId;
+        delete con;
     }
     //鏂囦欢鍒犻櫎鍔熻兘  绮剧悽鎶�鏈� thh 2021-09-26 end
 }
\ No newline at end of file
diff --git a/force-app/main/default/pages/AssetModifyBelongs.page b/force-app/main/default/pages/AssetModifyBelongs.page
index 647d4c1..3361cbc 100644
--- a/force-app/main/default/pages/AssetModifyBelongs.page
+++ b/force-app/main/default/pages/AssetModifyBelongs.page
@@ -347,7 +347,7 @@
                 <apex:pageBlock title="鏂囦欢" id="accessory" rendered="{!isShow}">
                 
                     <apex:pageBlockButtons location="top">
-                        <apex:commandButton value="闄勪欢涓婁紶"  onclick="uploadingAttachmentJs();" disabled="{!IF(ambc.Change_status__c='宸叉彁浜�'||ambc.Change_status__c='鎵瑰噯',true,false)}"/>
+                        <apex:commandButton value="鏂囦欢涓婁紶"  onclick="uploadingAttachmentJs();" disabled="{!IF(ambc.Change_status__c='宸叉彁浜�'||ambc.Change_status__c='鎵瑰噯',true,false)}"/>
                     </apex:pageBlockButtons>
                     
                     <apex:pageBlockTable value="{!contents}" var="attachment" >
diff --git a/force-app/main/default/pages/AssetQR.page b/force-app/main/default/pages/AssetQR.page
index b5d3a21..ca6c362 100644
--- a/force-app/main/default/pages/AssetQR.page
+++ b/force-app/main/default/pages/AssetQR.page
@@ -10,9 +10,7 @@
             var img = div.getElementsByTagName("img");
             var src = img[0].src;
             src = src.substring(22, src.length);
-
             sforce.connection.sessionId = '{!GETSESSIONID()}';
-
             // var record = sforce.connection.query("select id from Attachment where ParentId = \'{!Asset.Id}\' and name = \'QRCode\'");
             var record = sforce.connection.query("SELECT ContentDocumentId from ContentDocumentLink where LinkedEntityId =\'{!Asset.Id}\'");
             var records;
@@ -46,7 +44,7 @@
 
                 var es = new sforce.SObject("Asset");
                 es.Id = "{!Asset.Id}";
-                es.QRId__c = result[0].ContentDocumentId;
+                es.QRId__c = versionResult[0].id;
                 es.Fixture_QRCode_Text__c = "{!Asset.Fixture_QRCode__c}";
                 result = sforce.connection.update([es]);
             } else if ("{!Asset.QRId__c}" == null || "{!Asset.QRId__c}" == '' || "{!Asset.Fixture_QRCode__c}" != "{!Asset.Fixture_QRCode_Text__c}"){
@@ -59,9 +57,9 @@
                 // var result = sforce.connection.update([atta]);
 
 
-                var result = sforce.connection.query("SELECT Id from ContentDocumentLink where ContentDocumentId =" + record[0].Id);
-                var version = sforce.connection.query("SELECT Id from ContentVersion where ContentDocumentId =" + record[0].Id);
-                var versions = version.getArray("versions");
+                var result = sforce.connection.query("SELECT Id from ContentDocumentLink where ContentDocumentId = \'" + records[0].ContentDocumentId + "\'");
+                var version = sforce.connection.query("SELECT Id from ContentVersion where ContentDocumentId = \'" + records[0].ContentDocumentId  + "\'");
+                var versions = version.getArray("records");
                 var atta = new sforce.SObject("ContentVersion");
                 atta.VersionData = src;
                 atta.Id = versions[0].Id;
@@ -69,7 +67,7 @@
                 records = result.getArray("records");
                 var es = new sforce.SObject("Asset");
                 es.Id = "{!Asset.Id}";
-                es.QRId__c = records[0].Id;
+                es.QRId__c = atta.Id;
                 es.Fixture_QRCode_Text__c = "{!Asset.Fixture_QRCode__c}";
                 result = sforce.connection.update([es]);
                 // TODO Name澶夈倧銈嬪彲鑳芥�с亗銈娿�乽psert銇仐銇俱仚
diff --git a/force-app/main/default/pages/ConsumApplyBR.page b/force-app/main/default/pages/ConsumApplyBR.page
index 5d1d40c..db69438 100644
--- a/force-app/main/default/pages/ConsumApplyBR.page
+++ b/force-app/main/default/pages/ConsumApplyBR.page
@@ -52,7 +52,7 @@
             var srcNew = getImgBase64(src);
             src = srcNew.substring(22, srcNew.length);
             sforce.connection.sessionId = '{!GETSESSIONID()}';
-
+            console.log(src);
             // var record = sforce.connection.query("select id from Attachment where ParentId = \'{!Consum_Apply__c.Id}\' and name = \'BRCode-{!Consum_Apply__c.Name_No__c}\'");
 
             var record = sforce.connection.query("select Id,ContentDocumentId from ContentDocumentLink where LinkedEntityId = \'{!Consum_Apply__c.Id}\'");
diff --git a/force-app/main/default/pages/ConsumApplyQR.page b/force-app/main/default/pages/ConsumApplyQR.page
index bd76782..7b33ac3 100644
--- a/force-app/main/default/pages/ConsumApplyQR.page
+++ b/force-app/main/default/pages/ConsumApplyQR.page
@@ -16,14 +16,12 @@
             // var record = sforce.connection.query("select id from Attachment where ParentId = \'{!Consum_Apply__c.Id}\' and name = \'QRCode-{!Consum_Apply__c.Name}\'");
             var record = sforce.connection.query("select ContentDocumentId from ContentDocumentLink where LinkedEntityId = \'{!Consum_Apply__c.Id}\'");
             // 涓嶅瓨鍦╭r鏂囦欢鏃讹紝鏂扮敓鎴愪竴涓紝骞惰繛鍒扮敵璇峰崟涓�
-            console.log(record.size);
             if(record.size > 0){
                 var records = record.getArray("records");
                 var idList = records.map(obj => "'" + obj.ContentDocumentId + "'").join(",");
                 record = sforce.connection.query("select Id from ContentDocument where Id in (" + idList + ") and Title = \'QRCode-{!Consum_Apply__c.Name}\'");
                 console.log("select Id from ContentDocument where Id in (" + idList + ") and Title = \'QRCode-{!Consum_Apply__c.Name}\'");
             }
-            console.log(record.size);
             if (record.size == 0) {
                 // var atta = new sforce.SObject("Attachment");
                 // atta.Name = "QRCode-{!Consum_Apply__c.Name}";
@@ -37,11 +35,8 @@
                 version.ContentLocation = "s";
                 version.PathOnClient = "QRCode-{!Consum_Apply__c.Name}.jpg";
                 var result = sforce.connection.create([version]);
-                console.log(result[0].id);
-                version = sforce.connection.query("select ContentDocumentId from ContentVersion where Id = \'" + result[0].id + "\'");
-                console.log(version);
+                version = sforce.connection.query("select Id,ContentDocumentId from ContentVersion where Id = \'" + result[0].id + "\'");
                 version = version.getArray("records"); 
-                console.log(version);
                 var link = new sforce.SObject("ContentDocumentLink");
                 link.LinkedEntityId = "{!Consum_Apply__c.Id}";
                 link.ContentDocumentId = version[0].ContentDocumentId;
@@ -51,16 +46,19 @@
 
                 var es = new sforce.SObject("Consum_Apply__c");
                 es.Id = "{!Consum_Apply__c.Id}";
-                es.QRId__c = version[0].ContentDocumentId;
+                es.QRId__c = version[0].Id;
                 result = sforce.connection.update([es]);
             }
             else {
                 var records = record.getArray("records");
+                var version = new sforce.SObject("ContentVersion");
+                version = sforce.connection.query("select Id,ContentDocumentId from ContentVersion where ContentDocumentId = \'" + records[0].Id + "\'");
+                version = version.getArray("records"); 
                 // 瀛樺湪qr鏃讹紝缁戝埌鐢宠鍗曚笂
-                if(records[0].Id != "{!Consum_Apply__c.QRId__c}"){
+                if(version[0].Id != "{!Consum_Apply__c.QRId__c}"){
                     var es = new sforce.SObject("Consum_Apply__c");
                     es.Id = "{!Consum_Apply__c.Id}";
-                    es.QRId__c = records[0].Id;
+                    es.QRId__c = version[0].Id;
                     result = sforce.connection.update([es]);
                 }
             }

--
Gitblit v1.9.1