高章伟
2023-03-03 d8dc84a3d56df839895f1c417a4d9cbee763d262
force-app/main/default/classes/NewConsumApplyController.cls
@@ -28,6 +28,12 @@
    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;
@@ -47,7 +53,7 @@
        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>();
@@ -57,6 +63,20 @@
            }
            // 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');
@@ -82,10 +102,23 @@
        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{
@@ -103,6 +136,13 @@
        system.debug(fieldAPIToTypeMap);
        Map<String,Object> fieldValueMap = (Map<String,Object>)JSON.deserializeUntyped(consumApplyJson);
        Consum_Apply__c consumApplyInfo = new Consum_Apply__c();
        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);
@@ -135,14 +175,9 @@
        }
        
        //2. Save Record Process
        String status = 'success';
        Response resp = new Response();
        Savepoint sp = Database.setSavepoint();
        String rid = '';
        Boolean isClone = false;
        String awsDataId = '';
                
        try{
            System.debug('abcde');
            awsDataId = (String)consumApplyInfo.get('AWS_Data_Id__c');
            System.debug('awsDataId = ' + awsDataId);