高章伟
2023-03-03 d8dc84a3d56df839895f1c417a4d9cbee763d262
force-app/main/default/classes/NewAndEditReportController.cls
@@ -37,6 +37,12 @@
    public String contactName3{set;get;}
    public String contactName4{set;get;}
    public String contactName5{set;get;}
    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 NewAndEditReportController(ApexPages.StandardController controller) {
        ApiPrefix = 'PIBackApi';
        layoutEncryptedAPIList = new List<String>();
@@ -70,6 +76,7 @@
            rtTypeId = ReportData.RecordTypeId;
            AWSDataId = ReportData.AWS_Data_Id__c;
            sfRecordIdForEdit = obj.Id;
            Map<String,String> sfIdToAWSIdMap = new Map<String,String>();
            system.debug('ReportData.Practitioner1__r.Id:' + ReportData.Practitioner1__r.Id);
            system.debug('ReportData.Practitioner1__r.AWS_Data_Id__c:' + ReportData.Practitioner1__r.AWS_Data_Id__c);
@@ -140,7 +147,17 @@
                contactAWSDataId1 = '无';
                contactName1 = '无';
            }
        }else if(ApexPages.currentPage().getParameters().get('CF00N10000008ps6d_lkid') != null){
        }else{
            //新建
            // Map<string,string> mso = ApexPages.currentPage().getParameters();
            //医院/科室/经销商(手写)
            if(mso.containsKey('00N10000002GE3Z')){
                controller.getRecord().put('Manual_Name__c',mso.get('00N10000002GE3Z'));
            }
            rtTypeId = ApexPages.currentPage().getParameters().get('RecordType');
            obj.put('OwnerId',UserInfo.getUserId());
        }
        if(ApexPages.currentPage().getParameters().get('CF00N10000008ps6d_lkid') != null){
            //OPD计划过来的,通过Id查出借出备品申请No1进行展示
            String opdPlanId = ApexPages.currentPage().getParameters().get('CF00N10000008ps6d_lkid');
            if(String.isNotEmpty(opdPlanId)&&String.isNotBlank(opdPlanId)){
@@ -153,17 +170,10 @@
                    }                   
                }
            }                                  
            rtTypeId = ApexPages.currentPage().getParameters().get('RecordType');
            obj.put('OwnerId',UserInfo.getUserId());
        }else{
            //新建
            // Map<string,string> mso = ApexPages.currentPage().getParameters();
            //医院/科室/经销商(手写)
            if(mso.containsKey('00N10000002GE3Z')){
                controller.getRecord().put('Manual_Name__c',mso.get('00N10000002GE3Z'));
            }
            rtTypeId = ApexPages.currentPage().getParameters().get('RecordType');
            obj.put('OwnerId',UserInfo.getUserId());
        }
        //OPD计划
        if(mso.containsKey('CF00N10000008ps6d_lkid')){
            controller.getRecord().put('Report_OPDPlan__c',mso.get('CF00N10000008ps6d_lkid'));
        }
        LayoutDescriberHelper.LayoutWrapper LayoutWrapperValue = LayoutDescriberHelper.describeSectionWithFieldsWrapper(rtTypeId, 'Report__c','classic');
        layoutSections = LayoutWrapperValue.layoutSections;
@@ -186,10 +196,23 @@
                }
            }
        }
        //获取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);
        }
        System.debug('AWSToSobjectEncryptedMap = ' + AWSToSobjectEncryptedMap);
        //zhj MEBG新方案改造 2022-11-29 start
        staticResourceV2 = JSON.serialize(PIHelper.getPIIntegrationInfo('Report__cV2'));
        //zhj MEBG新方案改造 2022-11-29 end
    }
    global class Response{
@@ -253,16 +276,29 @@
            System.debug('自定义格式转换结束');
            String awsDataId = (String)reportInfo.get('AWS_Data_Id__c');
            String sfRecordId =  (String)reportInfo.get('Id');
            System.debug('awsDataId = ' + awsDataId);
            report__c[] reports = [select id from report__c where AWS_Data_Id__c =:awsDataId];
            System.debug('sfRecordId = ' + sfRecordId);
            report__c[] reports = [select id from report__c where AWS_Data_Id__c =:awsDataId or id=:sfRecordId];
            //report__c[] reportsFromDaily = [select id from report__c where AWS_Data_Id__c =:awsDataId or id=:sfRecordId];
            
            if(!isNew){
                isClone = reports.size() == 0;
            }
            if(isNew){
            system.debug('isClone'+isClone + ' isNew'+isNew);
            if(isNew || isClone){
                System.debug('reportInfo = ' + reportInfo);               
                if(!Test.isRunningTest()){
                   insert reportInfo;
                    // if(isClone){
                    //     Report__c[] r = [select Practitioner4__c,Practitioner5__c from Report__c where id=:sfRecordId];
                    //     if(r.size()>0){
                    //         reportInfo.Practitioner4__c = r[0].Practitioner4__c;
                    //         reportInfo.Practitioner5__c = r[0].Practitioner5__c;
                    //     }
                    //     reportInfo.Id = null;
                    // }
                    reportInfo.Status__c = '草案中';
                    insert reportInfo;
                } else {
                    Report__c reportTest = new Report__c();
                    insert reportTest;
@@ -275,7 +311,7 @@
                System.debug('reports[0].id = ' + reports[0].id);
                reportInfo.put('Id',reports[0].id);//For testing;                
                if(!Test.isRunningTest()){
                   update reportInfo;
                    update reportInfo;
                }
            }
            rid=reportInfo.Id;
@@ -295,7 +331,7 @@
            System.debug(e.getDmlMessage(index));
            System.debug(e.getDmlStatusCode(index));
            System.debug(e.getDmlType(index));
         system.debug(e.getMessage());
            system.debug(e.getMessage());
            system.debug(e.getStackTraceString());
            System.debug('into catch'+e.getMessage());