From f127c76b19f5316032d4bed127a1dde710c48d74 Mon Sep 17 00:00:00 2001
From: Li Jun <buli@deloitte.com.cn>
Date: 星期四, 24 三月 2022 10:10:36 +0800
Subject: [PATCH] PIPLFunctionFixBug0324

---
 force-app/main/default/classes/NewConsumApplyController.cls |   55 ++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 40 insertions(+), 15 deletions(-)

diff --git a/force-app/main/default/classes/NewConsumApplyController.cls b/force-app/main/default/classes/NewConsumApplyController.cls
index c8efb33..b1bc107 100644
--- a/force-app/main/default/classes/NewConsumApplyController.cls
+++ b/force-app/main/default/classes/NewConsumApplyController.cls
@@ -2,10 +2,11 @@
  * @description       : 
  * @author            : ChangeMeIn@UserSettingsUnder.SFDoc
  * @group             : 
- * @last modified on  : 03-10-2022
+ * @last modified on  : 03-23-2022
  * @last modified by  : ChangeMeIn@UserSettingsUnder.SFDoc
 **/
 global without sharing class NewConsumApplyController {
+    public String layoutSectionsStr {get; set;}//for dynamic add readonly attribute
     public List <LayoutDescriberHelper.LayoutSection > layoutSections{set;get;}
     public String awsToken{set;get;}
     public static Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
@@ -51,6 +52,7 @@
         }
         LayoutDescriberHelper.LayoutWrapper LayoutWrapperValue = LayoutDescriberHelper.describeSectionWithFieldsWrapper(rtTypeId, 'Consum_Apply__c','classic');
         layoutSections = LayoutWrapperValue.layoutSections;
+        layoutSectionsStr = JSON.serialize(layoutSections); //for dynamic add readonly attribute
         List<String> requiredFieldAPIList = LayoutWrapperValue.requiredFieldAPIList;
         Map<String,String> fieldAPIToLabelMap = LayoutWrapperValue.fieldAPIToLabelMap;
         requiredFieldAPIListStr = JSON.serialize(requiredFieldAPIList);
@@ -77,26 +79,29 @@
         Consum_Apply__c consumApplyInfo = new Consum_Apply__c();
         //鑷畾涔夋牸寮忚浆鎹�
         for (String fieldAPI: fieldValueMap.keySet()) {
-            system.debug('field API='+fieldAPI);
             Schema.DisplayType fielddataType = fieldAPIToTypeMap.get(fieldAPI).getDescribe().getType();  
             String fieldValue = String.valueOf(fieldValueMap.get(fieldAPI)); 
-            system.debug('Field Type:'+fielddataType+' field Value='+fieldValue);
+            if(String.isBlank(fieldValue)){
+                continue;
+            }
             if(String.valueOf(fielddataType)=='DATE'){
-                consumApplyInfo.put(fieldAPI,(String.isBlank(fieldValue)||String.isEmpty(fieldValue))? null:Date.valueOf(fieldValue.replace('/', '-')));              
+                System.debug('DATE fieldAPI = '+fieldAPI+' filedData = '+String.valueOf(fieldValueMap.get(fieldAPI)));
+                consumApplyInfo.put(fieldAPI, Date.valueOf(String.valueOf(fieldValueMap.get(fieldAPI)).replace('/', '-')));
             }else if(String.valueOf(fielddataType)=='DATETIME'){
-                if(String.isNotBlank(fieldValue)&&fieldValue.contains('T')){
-                    fieldValue = fieldValue.replace('T',' ');
-                    consumApplyInfo.put(fieldAPI, Datetime.valueOfGmt(fieldValue));
-                }else{
-                    consumApplyInfo.put(fieldAPI, null);
-                }                    
-            }else if(String.valueof(fielddataType)=='CURRENCY'|| String.valueof(fielddataType)=='PERCENT'||String.valueOf(fielddataType)=='Number'||String.valueOf(fielddataType)=='DOUBLE' ){
-                consumApplyInfo.put(fieldAPI, (String.isBlank(fieldValue)||String.isEmpty(fieldValue))?0:Decimal.valueOf(fieldValue)); 
+                String dt = String.valueOf(fieldValueMap.get(fieldAPI));
+                if(String.isNotBlank(dt)&&dt.contains('T')){
+                    dt = dt.replace('T',' ');
+                    consumApplyInfo.put(fieldAPI, Datetime.valueOfGmt(dt));
+                }else if(String.isNotBlank(dt))  {
+                    consumApplyInfo.put(fieldAPI, Datetime.valueOf(dt));
+                }          
+            }else if(String.valueOf(fielddataType)=='Number'||String.valueOf(fielddataType)=='DOUBLE' ){
+                consumApplyInfo.put(fieldAPI, Decimal.valueOf(String.valueOf(fieldValueMap.get(fieldAPI))));
             } else if(String.valueof(fielddataType)=='BOOLEAN'){
                 consumApplyInfo.put(fieldAPI, fieldValueMap.get(fieldAPI));
             }else {
-                consumApplyInfo.put(fieldAPI,fieldValue);
-            }                 
+                consumApplyInfo.put(fieldAPI, String.valueOf(fieldValueMap.get(fieldAPI)));
+            }                  
         }
         
         //2. Save Record Process
@@ -126,7 +131,27 @@
             resp.status = status;
             System.debug('resp from sfdx back-end' + resp);
             return resp;
-        } catch(Exception e) {
+        } catch(DmlException e) {
+            rid=consumApplyInfo.Id;
+            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,rid,transId, (String)consumApplyInfo.get('AWS_Data_Id__c'),consumApplyJson ,status,'');
+            return resp;
+            
+        }catch(Exception e) {
             System.debug('into catch'+e.getMessage());
             Database.rollback(sp);
             status = 'fail';

--
Gitblit v1.9.1