From d8dc84a3d56df839895f1c417a4d9cbee763d262 Mon Sep 17 00:00:00 2001
From: 高章伟 <gaozhangwei@prec-tech.com>
Date: 星期五, 03 三月 2023 14:50:59 +0800
Subject: [PATCH] gzw 测试环境代码更新

---
 force-app/main/default/classes/NewAndEditCaseController.cls |  137 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 137 insertions(+), 0 deletions(-)

diff --git a/force-app/main/default/classes/NewAndEditCaseController.cls b/force-app/main/default/classes/NewAndEditCaseController.cls
index 205d7de..7083bc3 100644
--- a/force-app/main/default/classes/NewAndEditCaseController.cls
+++ b/force-app/main/default/classes/NewAndEditCaseController.cls
@@ -33,6 +33,10 @@
     public Map<string,string> AWSToSobjectEncryptedMap{get;private set;}
     public string AWSToSobjectEncryptedMapJson{get{return JSON.serialize(AWSToSobjectEncryptedMap);}}
     public String sfRecordIdForEdit{set;get;}//Add By LiJun for Edit Record from NFM609, 20220510
+    public String VLookUpFieldsJson{get;private set;}
+    //zhj MEBG鏂版柟妗堟敼閫� 2022-11-29 start
+    public String staticResourceV2 {get; set;}
+    //zhj MEBG鏂版柟妗堟敼閫� 2022-11-29 end
     public NewAndEditCaseController(ApexPages.StandardController controller) {
         isNewMode = true;
         isCloneMode = false;
@@ -69,6 +73,7 @@
         }else{
             //鏂板缓
             // rtTypeId = ApexPages.currentPage().getParameters().get('RecordType');
+            AssignValueFromUrl(mso,controller.getRecord());
             rtTypeId = mso.get('RecordType');
             obj.put('OwnerId',UserInfo.getUserId());
         }
@@ -85,9 +90,23 @@
         sobjectPrefix = piIntegration.sobjectPrefix;
         layoutSectionsStr = JSON.serialize(layoutSections);
         AWSToSobjectEncryptedMap = new Map<String,String>();
+        
+        //鑾峰彇lookup瀛楁
+        List<String> VLookUpFields = new List<String>();
+        for (LayoutDescriberHelper.LayoutSection ls : layoutSections) {
+            for (LayoutDescriberHelper.LayoutField lf : ls.layoutFields) {
+                if (lf.fieldAPI != '' && lf.fieldType == 'reference') {
+                    VLookUpFields.add(lf.fieldAPI);
+                }
+            }
+        }
+        VLookUpFieldsJson = Json.serialize(VLookUpFields);
         for (PI_Field_Policy_Detail__c PIDetail : piIntegration.PIDetails) {
             AWSToSobjectEncryptedMap.put(PIDetail.AWS_Field_API__c, PIDetail.SF_Field_API_Name__c);
         }
+        //zhj MEBG鏂版柟妗堟敼閫� 2022-11-29 start
+        staticResourceV2 = JSON.serialize(PIHelper.getPIIntegrationInfo('CaseV2'));
+        //zhj MEBG鏂版柟妗堟敼閫� 2022-11-29 end
     }
     global class Response{
         public String recordId{set;get;}
@@ -217,4 +236,122 @@
             return resp;
         }
     }
+
+    public static void AssignValueFromUrl(Map<string,string> mso, sobject sobj){
+        
+        String sobject_name = sobj.getSObjectType().getDescribe().getName();
+        Map<string,object> temp = new Map<string,object>();
+        Map<string,FieldDefinition> fdm = new Map<string,FieldDefinition>();
+        List<FieldDefinition> fds = [SELECT Id, DurableId, QualifiedApiName,ValueTypeId , EntityDefinitionId, NamespacePrefix,EntityDefinition.NamespacePrefix, DeveloperName, MasterLabel, Label FROM FieldDefinition where EntityDefinition.QualifiedApiName = :sobject_name];
+        for(FieldDefinition fd : fds){
+            //system.debug(fd.DurableId);
+            fdm.put(fd.DurableId.split('\\.')[1],fd);
+        }
+        
+        for(string key : mso.keySet()){
+            if (key.toLowerCase() == 'id') {
+                System.debug('skip id assign');
+                continue;
+            }
+            string new_key = key;
+            system.debug('new_key='+new_key);
+            if(new_key.contains('_lkid')){
+                new_key = new_key.replace('_lkid', '');
+                new_key = new_key.substring(2);
+            }else{
+                if(temp.containsKey(new_key)){
+                    continue;
+                }
+            }
+            
+            system.debug('now new_key='+new_key);
+            if(fdm.containsKey(new_key)){
+                system.debug('fdm.get(new_key)='+fdm.get(new_key));
+                string val_str = mso.get(key);
+                system.debug('val_str='+val_str);
+                /*鏃犻渶鍋歞ecode锛宻f鍐呴儴宸茬粡鍋氬ソ
+                try{
+                    val_str = EncodingUtil.urlDecode(mso.get(key),'UTF-8');
+                }catch(Exception e){
+                    continue;
+                    system.debug('Exception from get Key:'+e.getMessage());
+                    system.debug(e.getStackTraceString());
+                } */             
+                object val = null;
+                string type_id = fdm.get(new_key).ValueTypeId;
+                // address, boolean, date, datetime, double, id, location, string, time
+                if(string.isBlank(val_str)){
+                    val = null;
+                }else if(type_id == 'boolean'){
+                    if(val_str == '1'){
+                        val = true;
+                    }else{
+                        val = boolean.valueOf(val_str);
+                    }
+                }else if(type_id == 'date'){
+                    //
+                   	try{
+                        val = date.parse(val_str);
+                    }catch(Exception e){
+                        system.debug('val_str='+val_str);
+                        system.debug(e.getMessage());
+                        system.debug(e.getStackTraceString());
+                        try{
+                            val = date.valueOf(val_str);
+                        }catch(Exception ee){
+                            system.debug('val_str='+val_str);
+                            system.debug(ee.getMessage());
+                            system.debug(ee.getStackTraceString());
+                            continue;
+                        }
+                    }
+                }else if(type_id == 'datetime'){
+                    //
+                   	try{
+                        val = datetime.parse(val_str);
+                    }catch(Exception e){
+                        system.debug('val_str='+val_str);
+                        system.debug(e.getMessage());
+                        system.debug(e.getStackTraceString());
+                        try{
+                            val = datetime.valueOf(val_str);
+                        }catch(Exception ee){
+                            system.debug('val_str='+val_str);
+                            system.debug(ee.getMessage());
+                            system.debug(ee.getStackTraceString());
+                            continue;
+                        }
+                    }
+                }else if(type_id == 'double' || type_id == 'number'){
+                    try{
+                        val = decimal.valueOf(val_str.replace(',', ''));
+                    }catch(Exception ee){
+                        system.debug('val_str='+val_str);
+                        system.debug(ee.getMessage());
+                        system.debug(ee.getStackTraceString());
+                        continue;
+                    }
+                    
+                }else if(type_id == 'id' || type_id == 'string'){
+                    val = val_str;
+                }else{
+                    system.debug('type_id='+type_id+' is not support to convert');
+                    continue;
+                }
+                temp.put(fdm.get(new_key).QualifiedApiName,val);
+            }else{
+                system.debug(key+' is not in fdm');
+            }
+        }
+        
+        for(string key : temp.keySet()){
+            system.debug('assign '+key+'='+temp.get(key));
+            try{
+                sobj.put(key, temp.get(key));
+            }catch(Exception e){
+                system.debug(e.getMessage());
+                system.debug(e.getStackTraceString());
+            }
+        }
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.1