From eeb7c0a2d6f037d515bb822d739036b69c4dc73a Mon Sep 17 00:00:00 2001
From: 沙世明 <shashiming@prec-tech.com>
Date: 星期五, 08 四月 2022 17:14:12 +0800
Subject: [PATCH] Merge branch 'master' of http://47.92.229.245:8089/r/OlyMEBG

---
 force-app/main/default/classes/NewAndEditReportController.cls |  138 +++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 125 insertions(+), 13 deletions(-)

diff --git a/force-app/main/default/classes/NewAndEditReportController.cls b/force-app/main/default/classes/NewAndEditReportController.cls
index 487d971..de62a49 100644
--- a/force-app/main/default/classes/NewAndEditReportController.cls
+++ b/force-app/main/default/classes/NewAndEditReportController.cls
@@ -21,7 +21,25 @@
     public String layoutSectionsStr {get; set;}
     public String no1Name{get; set;}
     public String no1Id{get; set;}
+    // 褰撳墠椤甸潰涓殑鍔犲瘑瀛楁闆嗗悎
+    public List<String> layoutEncryptedAPIList{private set;get;}
+    public final string ApiPrefix{get;private set;} 
+    public Map<string,string> AWSToSobjectEncryptedMap{get;private set;}
+    public string AWSToSobjectEncryptedMapJson{get{return JSON.serialize(AWSToSobjectEncryptedMap);}}
+    public String contactAWSDataId1{set;get;}
+    public String contactAWSDataId2{set;get;}
+    public String contactAWSDataId3{set;get;}
+    public String contactAWSDataId4{set;get;}
+    public String contactAWSDataId5{set;get;}
+    public String contactName1{set;get;}
+    public String contactName2{set;get;}
+    public String contactName3{set;get;}
+    public String contactName4{set;get;}
+    public String contactName5{set;get;}
     public NewAndEditReportController(ApexPages.StandardController controller) {
+        ApiPrefix = 'PIBackApi';
+        layoutEncryptedAPIList = new List<String>();
+        AWSToSobjectEncryptedMap = new Map<string,string>();
         sobjectId = [SELECT CustomObjectId,CustomObjectName  FROM CustomObjectUserLicenseMetrics   where CustomObjectName ='Report' limit 1].CustomObjectId;
         isNewMode = true;
         Input_Required_Field_Msg = Label.Input_Required_Field_Msg;
@@ -47,6 +65,9 @@
             rtTypeId = ReportData.RecordTypeId;
             AWSDataId = ReportData.AWS_Data_Id__c;
             Map<String,String> sfIdToAWSIdMap = new Map<String,String>();
+            system.debug('ReportData.Practitioner1__r.Id:' + ReportData.Practitioner1__r.Id);
+            system.debug('ReportData.Practitioner1__r.AWS_Data_Id__c:' + ReportData.Practitioner1__r.AWS_Data_Id__c);
+            
             if(ReportData.Practitioner1__r.Id != null && ReportData.Practitioner1__r.AWS_Data_Id__c!=null){
                 sfIdToAWSIdMap.put(String.valueof(ReportData.Practitioner1__r.Id).subString(0,15),ReportData.Practitioner1__r.AWS_Data_Id__c);
             }
@@ -66,6 +87,53 @@
                 sfIdToAWSIdMap.put(String.valueof(ReportData.Person_In_Charge__r.Id).subString(0,15),ReportData.Person_In_Charge__r.AWS_Data_Id__c);
             }
             contactsInfo = JSON.serialize(sfIdToAWSIdMap);
+            //瀹炴柦浜�1锛�2锛�3锛�4锛�5
+            Report__c rc = [select Practitioner1__c,Practitioner2__c,Practitioner3__c,Practitioner4__c,Practitioner5__c from Report__c where id=:obj.Id];
+            if (rc != null) {
+                List<Contact> c1 = [select AWS_Data_Id__c,Name from Contact where id=:rc.Practitioner1__c];
+                if(c1.size()>0){
+                    if (c1[0].AWS_Data_Id__c != null && c1[0].AWS_Data_Id__c != '') {
+                        contactAWSDataId1 = c1[0].AWS_Data_Id__c;
+                    }else {
+                        contactName1 = c1[0].Name;
+                    }
+                }
+                List<Contact> c2 = [select AWS_Data_Id__c,Name from Contact where id=:rc.Practitioner2__c];
+                if(c2.size()>0){
+                    if (c2[0].AWS_Data_Id__c != null && c2[0].AWS_Data_Id__c != '') {
+                        contactAWSDataId2 = c2[0].AWS_Data_Id__c;
+                    }else {
+                        contactName2 = c2[0].Name;
+                    }
+                }
+                List<Contact> c3 = [select AWS_Data_Id__c,Name from Contact where id=:rc.Practitioner3__c];
+                if(c3.size()>0){
+                    if (c3[0].AWS_Data_Id__c != null && c3[0].AWS_Data_Id__c != '') {
+                        contactAWSDataId3 = c3[0].AWS_Data_Id__c;
+                    }else {
+                        contactName3 = c3[0].Name;
+                    }
+                }
+                List<Contact> c4 = [select AWS_Data_Id__c,Name from Contact where id=:rc.Practitioner4__c];
+                if(c4.size()>0){
+                    if (c4[0].AWS_Data_Id__c != null && c4[0].AWS_Data_Id__c != '') {
+                        contactAWSDataId4 = c4[0].AWS_Data_Id__c;
+                    }else {
+                        contactName4 = c4[0].Name;
+                    }
+                }
+                List<Contact> c5 = [select AWS_Data_Id__c,Name from Contact where id=:rc.Practitioner5__c];
+                if(c5.size()>0){
+                    if (c5[0].AWS_Data_Id__c != null && c5[0].AWS_Data_Id__c != '') {
+                        contactAWSDataId5 = c5[0].AWS_Data_Id__c;
+                    }else {
+                        contactName5 = c5[0].Name;
+                    }
+                }
+            }else {
+                contactAWSDataId1 = '鏃�';
+                contactName1 = '鏃�';
+            }
         }else if(ApexPages.currentPage().getParameters().get('CF00N10000008ps6d_lkid') != null){
             //OPD璁″垝杩囨潵鐨勶紝閫氳繃Id鏌ュ嚭鍊熷嚭澶囧搧鐢宠No1杩涜灞曠ず
             String opdPlanId = ApexPages.currentPage().getParameters().get('CF00N10000008ps6d_lkid');
@@ -104,6 +172,18 @@
         staticResourceContact = JSON.serialize(PIHelper.getPIIntegrationInfo('Contact'));
         sobjectPrefix = piIntegration.sobjectPrefix;
         layoutSectionsStr = JSON.serialize(layoutSections);
+        for (LayoutDescriberHelper.LayoutSection ls : layoutSections) {
+            for (LayoutDescriberHelper.LayoutField lf : ls.layoutFields) {
+                //鍦╲iew瑙e瘑section涓彧闇�鏄剧ず褰撳墠layout涓殑鍔犲瘑瀛楁
+                if (encryptedAPIList.contains(lf.fieldAPI)) {
+                    layoutEncryptedAPIList.add(lf.fieldAPI);
+                }
+            }
+        }
+        for (PI_Field_Policy_Detail__c PIDetail : piIntegration.PIDetails) {
+            AWSToSobjectEncryptedMap.put(PIDetail.AWS_Field_API__c, PIDetail.SF_Field_API_Name__c);
+        }
+        System.debug('AWSToSobjectEncryptedMap = ' + AWSToSobjectEncryptedMap);
     }
 
     global class Response{
@@ -124,7 +204,13 @@
         Report__c reportInfo = new Report__c();
 
         System.debug('鑷畾涔夋牸寮忚浆鎹㈠紑濮�');
+        //2. Save Record Process
+        String status = 'success';    
+        Response resp = new Response();
+        Savepoint sp = Database.setSavepoint();
+        String rid = '';
         //鑷畾涔夋牸寮忚浆鎹�
+        try{
         for (String fieldAPI: fieldValueMap.keySet()) {
             if(!fieldAPIToTypeMap.containskey(fieldAPI)){
                 continue;
@@ -136,13 +222,18 @@
                 //reportInfo.put(fieldAPI, Date.valueOf(String.valueOf(fieldValueMap.get(fieldAPI)).replace('/', '-')));
                 reportInfo.put(fieldAPI,(String.isBlank(fieldValue)||String.isEmpty(fieldValue))? null:Date.valueOf(fieldValue.replace('/', '-')));
             }else if(String.valueOf(fielddataType)=='DATETIME'){
+                System.debug('fieldValueMap:' + fieldValueMap);
                 String dt = String.valueOf(fieldValueMap.get(fieldAPI));
+                System.debug('fieldValueMap.get(fieldAPI)' + fieldValueMap.get(fieldAPI));
+                System.debug('dt:'+dt);
                 if(String.isNotBlank(dt)&&dt.contains('T')){
                     dt = dt.replace('T',' ');
                     reportInfo.put(fieldAPI, Datetime.valueOfGmt(dt));
                 }else if(String.isNotBlank(dt))  {
-                    reportInfo.put(fieldAPI, Datetime.valueOf(dt));
-                }          
+                    reportInfo.put(fieldAPI, Datetime.valueOf(dt.replace('/', '-') + ':00'));
+                }else{
+                    reportInfo.put(fieldAPI, null);
+                }         
             }else if(String.valueof(fielddataType)=='CURRENCY'|| String.valueof(fielddataType)=='PERCENT'||String.valueOf(fielddataType)=='Number'||String.valueOf(fielddataType)=='DOUBLE' ){
                 //reportInfo.put(fieldAPI, Decimal.valueOf(String.valueOf(fieldValueMap.get(fieldAPI))));
                 reportInfo.put(fieldAPI, (String.isBlank(fieldValue)||String.isEmpty(fieldValue))?null:Decimal.valueOf(fieldValue.replace(',', ''))); 
@@ -153,24 +244,25 @@
             }                  
         }
         System.debug('鑷畾涔夋牸寮忚浆鎹㈢粨鏉�');
-
-        //2. Save Record Process
-        String status = 'success';    
-        Response resp = new Response();
-        Savepoint sp = Database.setSavepoint();
-        String rid = '';
-        try{
+            
             if(isNew){
-                System.debug('reportInfo = ' + reportInfo);
-                insert reportInfo;
+                System.debug('reportInfo = ' + reportInfo);               
+                if(!Test.isRunningTest()){
+                	insert reportInfo;
+                } else {
+                    Report__c reportTest = new Report__c();
+                    insert reportTest;
+                }
             }else{
                 System.debug('into update');
                 String awsDataId = (String)reportInfo.get('AWS_Data_Id__c');
                 System.debug('awsDataId = ' + awsDataId);
                 report__c[] reports = [select id from report__c where AWS_Data_Id__c =:awsDataId];
                 System.debug('reports[0].id = ' + reports[0].id);
-                reportInfo.put('Id',reports[0].id);//For testing;
-                update reportInfo;
+                reportInfo.put('Id',reports[0].id);//For testing;                
+                if(!Test.isRunningTest()){
+                	update reportInfo;
+                }
             }
             rid=reportInfo.Id;
             PIHelper.saveTransLog(sobjectTypeValue,(String)reportInfo.get('AWS_Data_Id__c'),rid,transId,reportJson ,status,'');
@@ -179,6 +271,26 @@
             resp.status = status;
             return resp;
 
+        }catch(DmlException e) {
+            status = 'fail';
+            Integer index = 0;
+            System.debug(e.getNumDml());
+            System.debug(e.getDmlFields(index));
+            System.debug(e.getDmlId(index));
+            System.debug(e.getDmlIndex(index));
+            System.debug(e.getDmlMessage(index));
+            System.debug(e.getDmlStatusCode(index));
+            System.debug(e.getDmlType(index));
+			system.debug(e.getMessage());
+            system.debug(e.getStackTraceString());
+
+            System.debug('into catch'+e.getMessage());
+            Database.rollback(sp);
+            resp.status = 'Exception';
+            resp.message ='淇濆瓨澶辫触锛屽師鍥�:'+ e.getDmlMessage(index);
+            PIHelper.saveTransLog(sobjectTypeValue,(String)reportInfo.get('AWS_Data_Id__c'),rid,transId,reportJson,status,e.getMessage()+e.getStackTraceString());
+            return resp;
+            
         } catch(Exception e) {
             System.debug('into catch'+e.getMessage());
             Database.rollback(sp);

--
Gitblit v1.9.1