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/NewConsumApplyController.cls | 167 ++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 132 insertions(+), 35 deletions(-)
diff --git a/force-app/main/default/classes/NewConsumApplyController.cls b/force-app/main/default/classes/NewConsumApplyController.cls
index f9fa4a2..18a1259 100644
--- a/force-app/main/default/classes/NewConsumApplyController.cls
+++ b/force-app/main/default/classes/NewConsumApplyController.cls
@@ -2,7 +2,7 @@
* @description :
* @author : ChangeMeIn@UserSettingsUnder.SFDoc
* @group :
- * @last modified on : 03-17-2022
+ * @last modified on : 03-28-2022
* @last modified by : ChangeMeIn@UserSettingsUnder.SFDoc
**/
global without sharing class NewConsumApplyController {
@@ -12,6 +12,7 @@
public static Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
public static String sobjectTypeValue = 'Consum_Apply__c';
public Boolean isNewMode{set;get;}
+ public Boolean isCloneMode{protected set;get;}
public String rtTypeId {get; set;}
public String AWSDataId{set;get;}
public List<String> encryptedAPIList{set;get;}
@@ -24,18 +25,35 @@
public String contactsInfo {set;get;}
public String contactId{set;get;}
public String PIPL_Input_Account_Error_Msg{set;get;}
+ public final string ApiPrefix{get;private set;} //Add By Li Jun 20220403
+ public Map<string,string> AWSToSobjectEncryptedMap{get;private set;}
+ public string AWSToSobjectEncryptedMapJson{get{return JSON.serialize(AWSToSobjectEncryptedMap);}}
+ public String VLookUpFieldsJson{get;private set;}
+ //zhj MEBG鏂版柟妗堟敼閫� 2022-11-29 start
+ public String staticResourceV2 {get; set;}
+ public Boolean isEdit {get; set;}
+ //zhj MEBG鏂版柟妗堟敼閫� 2022-11-29 end
+
public NewConsumApplyController(ApexPages.StandardController controller) {
+ ApiPrefix = 'PIBackApi';
isNewMode = true;
+ isCloneMode = false;
Input_Required_Field_Msg = Label.Input_Required_Field_Msg;
PIPL_Input_Account_Error_Msg = label.PIPL_Input_Account_Error_Msg;
//鑾峰彇鎵�鏈夊瓧娈�
List<String> fieldList = new List<String>(Schema.getGlobalDescribe().get('Consum_Apply__c').getDescribe().fields.getMap().keyset());
- controller.addFields(fieldList);
+ Map<string,string> mso = ApexPages.currentPage().getParameters();
+ if(mso != null && mso.containsKey('newclone')){
+ isCloneMode = true;
+ }
+ if (!Test.isRunningTest()) {
+ controller.addFields(fieldList);
+ }
SObject obj = controller.getRecord();
if(obj.Id != null){
//鏇存柊
isNewMode = false;
- Consum_Apply__c consumApplyData = [select Id,RecordTypeId,AWS_Data_Id__c,Loaner_medical_Staff__c,Loaner_medical_Staff__r.AWS_Data_Id__c from Consum_Apply__c where id =: obj.Id];
+ Consum_Apply__c consumApplyData = [select Id,RecordTypeId,AWS_Data_Id__c,Loaner_medical_Staff__c,Loaner_medical_Staff__r.AWS_Data_Id__c,Phone_number__c,direct_shippment_address__c,status__c from Consum_Apply__c where id =: obj.Id];
rtTypeId = consumApplyData.RecordTypeId;
AWSDataId = consumApplyData.AWS_Data_Id__c;
Map<String,String> sfIdToAWSIdMap = new Map<String,String>();
@@ -45,10 +63,33 @@
}
// sfIdToAWSIdMap.put(String.valueof(consumApplyData.Contact_Name__r.Id).subString(0,15),consumApplyData.Loaner_medical_Staff__r.AWS_Data_Id__c);
contactsInfo = JSON.serialize(sfIdToAWSIdMap);
+
+ //zhj MEBG鏂版柟妗堟敼閫� 2022-11-29 start
+ User loginUser = [Select Id, Name, ProfileId From User where Id = :Userinfo.getUserId()];
+ isEdit = false;
+ if(consumApplyData.status__c != '鑽夋涓�'
+ && consumApplyData.status__c != '濉啓瀹屾瘯'
+ && consumApplyData.status__c != '鐢宠涓�'
+ && loginUser.ProfileId != '00e10000000Y3o5'
+ && loginUser.ProfileId != '00e10000000xnoT'
+ && loginUser.ProfileId != '00e10000000xo1D'
+ && loginUser.ProfileId != '00e10000000dEQx'){
+ isEdit = true;
+ }
+ //zhj MEBG鏂版柟妗堟敼閫� 2022-11-29 end
}else{
//鏂板缓
rtTypeId = ApexPages.currentPage().getParameters().get('RecordType');
obj.put('OwnerId',UserInfo.getUserId());
+ // Map<string,string> mso = ApexPages.currentPage().getParameters();
+ system.debug('mso='+mso);
+ if(mso.containsKey('00N10000008rdgs')){
+ controller.getRecord().put('demo_purpose2__c',mso.get('00N10000008rdgs'));
+ }
+ if(mso.containsKey('Name')){
+ controller.getRecord().put('Name',mso.get('Name'));
+ }
+
}
LayoutDescriberHelper.LayoutWrapper LayoutWrapperValue = LayoutDescriberHelper.describeSectionWithFieldsWrapper(rtTypeId, 'Consum_Apply__c','classic');
layoutSections = LayoutWrapperValue.layoutSections;
@@ -57,9 +98,27 @@
Map<String,String> fieldAPIToLabelMap = LayoutWrapperValue.fieldAPIToLabelMap;
requiredFieldAPIListStr = JSON.serialize(requiredFieldAPIList);
fieldAPIToLabelMapStr = JSON.serialize(fieldAPIToLabelMap);
- staticResource = JSON.serialize(PIHelper.getPIIntegrationInfo('Consum_Apply__c'));
- encryptedAPIList = PIHelper.getPIIntegrationInfo('Consum_Apply__c').PIFields;
+ PIHelper.PIIntegration piIntegration = PIHelper.getPIIntegrationInfo('Consum_Apply__c');
+ staticResource = JSON.serialize(piIntegration);
+ encryptedAPIList = piIntegration.PIFields;
staticResourceContact = JSON.serialize(PIHelper.getPIIntegrationInfo('Contact'));
+ //zhj MEBG鏂版柟妗堟敼閫� 2022-11-29 start
+ staticResourceV2 = JSON.serialize(PIHelper.getPIIntegrationInfo('Consum_Apply__cV2'));
+ //zhj MEBG鏂版柟妗堟敼閫� 2022-11-29 end
+ AWSToSobjectEncryptedMap = new Map<String,String>();
+ for (PI_Field_Policy_Detail__c PIDetail : piIntegration.PIDetails) {
+ AWSToSobjectEncryptedMap.put(PIDetail.AWS_Field_API__c, PIDetail.SF_Field_API_Name__c);
+ }
+ //鑾峰彇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);
}
global class Response{
@@ -77,46 +136,64 @@
system.debug(fieldAPIToTypeMap);
Map<String,Object> fieldValueMap = (Map<String,Object>)JSON.deserializeUntyped(consumApplyJson);
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.valueOf(fielddataType)=='DATE'){
- consumApplyInfo.put(fieldAPI,(String.isBlank(fieldValue)||String.isEmpty(fieldValue))? null:Date.valueOf(fieldValue.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));
- } else if(String.valueof(fielddataType)=='BOOLEAN'){
- consumApplyInfo.put(fieldAPI, fieldValueMap.get(fieldAPI));
- }else {
- consumApplyInfo.put(fieldAPI,fieldValue);
- }
- }
-
- //2. Save Record Process
String status = 'success';
Response resp = new Response();
Savepoint sp = Database.setSavepoint();
String rid = '';
+ Boolean isClone = false;
+ String awsDataId = '';
try{
+ //鑷畾涔夋牸寮忚浆鎹�
+ for (String fieldAPI: fieldValueMap.keySet()) {
+ system.debug('field API'+fieldAPI);
+ if(!fieldAPIToTypeMap.containskey(fieldAPI)){
+ continue;
+ }
+ Schema.DisplayType fielddataType = fieldAPIToTypeMap.get(fieldAPI).getDescribe().getType();
+ String fieldValue = String.valueOf(fieldValueMap.get(fieldAPI));
+ if(String.valueOf(fielddataType)=='DATE'){
+ consumApplyInfo.put(fieldAPI,(String.isBlank(fieldValue)||String.isEmpty(fieldValue))? null:Date.valueOf(fieldValue.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 if(String.isNotBlank(fieldValue)) {
+ fieldValue = fieldValue.replace('/', '-') + ':00';
+ System.debug('fieldValue = ' + fieldValue);
+ consumApplyInfo.put(fieldAPI, Datetime.valueOf(fieldValue));
+ }else{
+ consumApplyInfo.put(fieldAPI, null);
+ }
+
+ }else if(String.valueOf(fielddataType)=='PERCENT'||String.valueOf(fielddataType)=='CURRENCY'||String.valueOf(fielddataType)=='Number'||String.valueOf(fielddataType)=='DOUBLE' ){
+ consumApplyInfo.put(fieldAPI, (String.isBlank(fieldValue)||String.isEmpty(fieldValue))?null:Decimal.valueOf(fieldValue.replace(',', '')));
+ } else if(String.valueof(fielddataType)=='BOOLEAN'){
+ consumApplyInfo.put(fieldAPI, fieldValueMap.get(fieldAPI));
+ }else {
+ consumApplyInfo.put(fieldAPI, String.valueOf(fieldValueMap.get(fieldAPI)));
+ }
+ }
+
+ //2. Save Record Process
+
+
+
System.debug('abcde');
- if(isNew){
+ awsDataId = (String)consumApplyInfo.get('AWS_Data_Id__c');
+ System.debug('awsDataId = ' + awsDataId);
+ Consum_Apply__c[] ConsumApplys = [select id from Consum_Apply__c where AWS_Data_Id__c =:awsDataId];
+ if(!isNew){
+ isClone = ConsumApplys.size() == 0;
+ }
+ if(isNew || isClone){
System.debug('consumApplyInfozhj = ' + consumApplyInfo);
insert consumApplyInfo;
System.debug('consumApplyInfo.Id' + consumApplyInfo.Id);
}else{
System.debug('into update');
- String awsDataId = (String)consumApplyInfo.get('AWS_Data_Id__c');
- System.debug('awsDataId = ' + awsDataId);
- Consum_Apply__c[] ConsumApplys = [select id from Consum_Apply__c where AWS_Data_Id__c =:awsDataId];
+ // String awsDataId = (String)consumApplyInfo.get('AWS_Data_Id__c');
+ // System.debug('awsDataId = ' + awsDataId);
+ // Consum_Apply__c[] ConsumApplys = [select id from Consum_Apply__c where AWS_Data_Id__c =:awsDataId];
System.debug('ConsumApplys[0].id = ' + ConsumApplys[0].id);
consumApplyInfo.put('Id',ConsumApplys[0].id);//For testing;
update consumApplyInfo;
@@ -128,7 +205,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