Li Jun
2022-04-11 ea5686cada5a3e63edaa0d3e8c2db8def4f9ff31
force-app/main/default/classes/NewConsumApplyController.cls
@@ -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,12 +25,21 @@
    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 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());  
        Map<string,string> mso = ApexPages.currentPage().getParameters();
        if(mso != null && mso.containsKey('newclone')){
            isCloneMode = true;
        }
        if (!Test.isRunningTest()) { 
            controller.addFields(fieldList);
        }
@@ -51,7 +61,7 @@
            //新建
            rtTypeId = ApexPages.currentPage().getParameters().get('RecordType');
            obj.put('OwnerId',UserInfo.getUserId());
            Map<string,string> mso = ApexPages.currentPage().getParameters();
            // Map<string,string> mso = ApexPages.currentPage().getParameters();
            system.debug('mso='+mso);
            if(mso.containsKey('00N10000008rdgs')){
                controller.getRecord().put('demo_purpose2__c',mso.get('00N10000008rdgs'));
@@ -68,9 +78,14 @@
        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'));
        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);
        }
    }
    global class Response{
@@ -124,17 +139,26 @@
        Response resp = new Response();
        Savepoint sp = Database.setSavepoint();
        String rid = '';
        Boolean isClone = false;
        String awsDataId = '';
        try{
            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;