| | |
| | | public String layoutSectionsStr {get; set;} |
| | | public String no1Name{get; set;} |
| | | public String no1Id{get; set;} |
| | | // 当前页面中的加密字段集合 |
| | | public List<String> layoutEncryptedAPIList{private set;get;} |
| | | public final string ApiPrefix{get;private set;} |
| | | public Map<string,string> AWSToSobjectEncryptedMap{get;private set;} |
| | | public string AWSToSobjectEncryptedMapJson{get{return JSON.serialize(AWSToSobjectEncryptedMap);}} |
| | | public NewAndEditReportController(ApexPages.StandardController controller) { |
| | | ApiPrefix = 'PIBackApi'; |
| | | layoutEncryptedAPIList = new List<String>(); |
| | | AWSToSobjectEncryptedMap = new Map<string,string>(); |
| | | sobjectId = [SELECT CustomObjectId,CustomObjectName FROM CustomObjectUserLicenseMetrics where CustomObjectName ='Report' limit 1].CustomObjectId; |
| | | isNewMode = true; |
| | | Input_Required_Field_Msg = Label.Input_Required_Field_Msg; |
| | |
| | | rtTypeId = ReportData.RecordTypeId; |
| | | AWSDataId = ReportData.AWS_Data_Id__c; |
| | | 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); |
| | | |
| | | if(ReportData.Practitioner1__r.Id != null && ReportData.Practitioner1__r.AWS_Data_Id__c!=null){ |
| | | sfIdToAWSIdMap.put(String.valueof(ReportData.Practitioner1__r.Id).subString(0,15),ReportData.Practitioner1__r.AWS_Data_Id__c); |
| | | } |
| | |
| | | staticResourceContact = JSON.serialize(PIHelper.getPIIntegrationInfo('Contact')); |
| | | sobjectPrefix = piIntegration.sobjectPrefix; |
| | | layoutSectionsStr = JSON.serialize(layoutSections); |
| | | for (LayoutDescriberHelper.LayoutSection ls : layoutSections) { |
| | | for (LayoutDescriberHelper.LayoutField lf : ls.layoutFields) { |
| | | //在view解密section中只需显示当前layout中的加密字段 |
| | | if (encryptedAPIList.contains(lf.fieldAPI)) { |
| | | layoutEncryptedAPIList.add(lf.fieldAPI); |
| | | } |
| | | } |
| | | } |
| | | 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); |
| | | } |
| | | |
| | | global class Response{ |
| | |
| | | Report__c reportInfo = new Report__c(); |
| | | |
| | | System.debug('自定义格式转换开始'); |
| | | //2. Save Record Process |
| | | String status = 'success'; |
| | | Response resp = new Response(); |
| | | Savepoint sp = Database.setSavepoint(); |
| | | String rid = ''; |
| | | //自定义格式转换 |
| | | try{ |
| | | for (String fieldAPI: fieldValueMap.keySet()) { |
| | | if(!fieldAPIToTypeMap.containskey(fieldAPI)){ |
| | | continue; |
| | |
| | | //reportInfo.put(fieldAPI, Date.valueOf(String.valueOf(fieldValueMap.get(fieldAPI)).replace('/', '-'))); |
| | | reportInfo.put(fieldAPI,(String.isBlank(fieldValue)||String.isEmpty(fieldValue))? null:Date.valueOf(fieldValue.replace('/', '-'))); |
| | | }else if(String.valueOf(fielddataType)=='DATETIME'){ |
| | | System.debug('fieldValueMap:' + fieldValueMap); |
| | | String dt = String.valueOf(fieldValueMap.get(fieldAPI)); |
| | | System.debug('fieldValueMap.get(fieldAPI)' + fieldValueMap.get(fieldAPI)); |
| | | System.debug('dt:'+dt); |
| | | if(String.isNotBlank(dt)&&dt.contains('T')){ |
| | | dt = dt.replace('T',' '); |
| | | reportInfo.put(fieldAPI, Datetime.valueOfGmt(dt)); |
| | | }else if(String.isNotBlank(dt)) { |
| | | reportInfo.put(fieldAPI, Datetime.valueOf(dt)); |
| | | } |
| | | reportInfo.put(fieldAPI, Datetime.valueOf(dt.replace('/', '-') + ':00')); |
| | | }else{ |
| | | reportInfo.put(fieldAPI, null); |
| | | } |
| | | }else if(String.valueof(fielddataType)=='CURRENCY'|| String.valueof(fielddataType)=='PERCENT'||String.valueOf(fielddataType)=='Number'||String.valueOf(fielddataType)=='DOUBLE' ){ |
| | | //reportInfo.put(fieldAPI, Decimal.valueOf(String.valueOf(fieldValueMap.get(fieldAPI)))); |
| | | reportInfo.put(fieldAPI, (String.isBlank(fieldValue)||String.isEmpty(fieldValue))?null:Decimal.valueOf(fieldValue.replace(',', ''))); |
| | |
| | | } |
| | | } |
| | | System.debug('自定义格式转换结束'); |
| | | |
| | | //2. Save Record Process |
| | | String status = 'success'; |
| | | Response resp = new Response(); |
| | | Savepoint sp = Database.setSavepoint(); |
| | | String rid = ''; |
| | | try{ |
| | | |
| | | if(isNew){ |
| | | System.debug('reportInfo = ' + reportInfo); |
| | | insert reportInfo; |
| | | System.debug('reportInfo = ' + reportInfo); |
| | | if(!Test.isRunningTest()){ |
| | | insert reportInfo; |
| | | } else { |
| | | Report__c reportTest = new Report__c(); |
| | | insert reportTest; |
| | | } |
| | | }else{ |
| | | System.debug('into update'); |
| | | String awsDataId = (String)reportInfo.get('AWS_Data_Id__c'); |
| | | System.debug('awsDataId = ' + awsDataId); |
| | | report__c[] reports = [select id from report__c where AWS_Data_Id__c =:awsDataId]; |
| | | System.debug('reports[0].id = ' + reports[0].id); |
| | | reportInfo.put('Id',reports[0].id);//For testing; |
| | | update reportInfo; |
| | | reportInfo.put('Id',reports[0].id);//For testing; |
| | | if(!Test.isRunningTest()){ |
| | | update reportInfo; |
| | | } |
| | | } |
| | | rid=reportInfo.Id; |
| | | PIHelper.saveTransLog(sobjectTypeValue,(String)reportInfo.get('AWS_Data_Id__c'),rid,transId,reportJson ,status,''); |
| | |
| | | resp.status = status; |
| | | return resp; |
| | | |
| | | }catch(DmlException e) { |
| | | status = 'fail'; |
| | | 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,(String)reportInfo.get('AWS_Data_Id__c'),rid,transId,reportJson,status,e.getMessage()+e.getStackTraceString()); |
| | | return resp; |
| | | |
| | | } catch(Exception e) { |
| | | System.debug('into catch'+e.getMessage()); |
| | | Database.rollback(sp); |