From ea5686cada5a3e63edaa0d3e8c2db8def4f9ff31 Mon Sep 17 00:00:00 2001 From: Li Jun <buli@deloitte.com.cn> Date: 星期一, 11 四月 2022 11:52:41 +0800 Subject: [PATCH] PIPLCloneButton --- force-app/main/default/classes/NewRepairController.cls | 246 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 235 insertions(+), 11 deletions(-) diff --git a/force-app/main/default/classes/NewRepairController.cls b/force-app/main/default/classes/NewRepairController.cls index e0391de..b246859 100644 --- a/force-app/main/default/classes/NewRepairController.cls +++ b/force-app/main/default/classes/NewRepairController.cls @@ -4,6 +4,7 @@ *@Date: 2022-03-10 10:26:47 */ global without sharing class NewRepairController { + public String layoutSectionsStr {get; set;}//for dynamic add readonly attribute public List <LayoutDescriberHelper.LayoutSection > layoutSections{set;get;} public String awsToken{set;get;} public static Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe(); @@ -25,6 +26,9 @@ public String sobjectPrefix{set;get;} public String sobjecttypeForFrontEnd{set;get;} public String sobjectId{set;get;} + public String workLocationSelect{set;get;} + public String RepairSubOrderAWSDataId{set;get;} + public String staticResourceRepairSubOrder{set;get;} public NewRepairController(ApexPages.StandardController controller) { sobjectId = [SELECT CustomObjectId,CustomObjectName FROM CustomObjectUserLicenseMetrics where CustomObjectName ='Repair' limit 1].CustomObjectId; isNewMode = true; @@ -35,7 +39,9 @@ //鑾峰彇鎵�鏈夊瓧娈� List<String> fieldList = new List<String>(Schema.getGlobalDescribe().get('Repair__c').getDescribe().fields.getMap().keyset()); // Add fields to controller. This is to avoid the SOQL error in visualforce page - controller.addFields(fieldList); + if(!Test.isRunningTest()){ + controller.addFields(fieldList); + } SObject obj = controller.getRecord(); if(obj.Id != null){ //鏇存柊 @@ -47,6 +53,184 @@ ContactAWSDataId = String.valueOf(repairData.Contact_AWS_Data_Id__c); }else{ //鏂板缓 + Map<string,string> mso = ApexPages.currentPage().getParameters(); + system.debug('mso='+mso); + //淇悊鍝佽繑閫佸湴 + if(mso.containsKey('00N10000006P6SM')){ + controller.getRecord().put('SalesOfficeCode_selection__c',mso.get('00N10000006P6SM')); + } + if(mso.containsKey('00N10000002FH86')){ + //controller.getRecord().put('On_site_repair__c',mso.get('00N10000002FH86')); + //Repair_Source__c + controller.getRecord().put('Repair_Source__c',mso.get('00N10000002FH86')); + } + if(mso.containsKey('00N10000006P6Rn')){ + controller.getRecord().put('work_location_select__c',mso.get('00N10000006P6Rn')); + workLocationSelect = mso.get('00N10000006P6Rn'); + System.debug('workLocationSelect = ' + workLocationSelect); + } + //闂鍐呭鎻忚堪00N10000002Dx6I + if(mso.containsKey('00N10000002Dx6I')){ + controller.getRecord().put('Repair_Detail__c',mso.get('00N10000002Dx6I')); + } + //闂鑱旂粶鏀跺埌鏃�00N10000008rsVQ + if(mso.containsKey('00N10000008rsVQ')){ + String o = mso.get('00N10000008rsVQ'); + controller.getRecord().put('DateReceiptQuestions__c',(String.isBlank(o)||String.isEmpty(o))? null:Date.valueOf(o.replace('/', '-'))); + } + + //鏄惁鏈夋浜°�佷激瀹炽�佹劅鏌�00N10000008rsW7 + if(mso.containsKey('00N10000008rsW7')){ + controller.getRecord().put('ifDeadHurt__c',mso.get('00N10000008rsW7')); + } + //鏄惁鍜岃繖娆$殑浜у搧鏁呴殰鏈夊叧00N10000008rsVw + if(mso.containsKey('00N10000008rsVw')){ + controller.getRecord().put('ProductFailureRelated__c',mso.get('00N10000008rsVw')); + } + //鍖婚櫌鏈夋病鏈夊悜鏀垮簻鏈哄叧鎶ュ憡涓嶈壇浜嬩欢鎴栫枒浼间笉鑹簨浠�00N10000008rsW2 + if(mso.containsKey('00N10000008rsW2')){ + controller.getRecord().put('ReportAdverseEvents__c',mso.get('00N10000008rsW2')); + } + //鍋氱殑鏄摢涓」鐩�00N10000008rsW6 + if(mso.containsKey('00N10000008rsW6')){ + controller.getRecord().put('WhatProject__c',mso.get('00N10000008rsW6')); + } + //鎵嬫湳/妫�鏌ュ悕绉�00N10000008rsVk + if(mso.containsKey('00N10000008rsVk')){ + controller.getRecord().put('OperationOrExaminationName__c',mso.get('00N10000008rsVk')); + } + //鏄惁鏈夊彂鐢熸柇瑁傛垨鑴辫惤00N10000008rsVN + if(mso.containsKey('00N10000008rsVN')){ + controller.getRecord().put('BreakORFallOff__c',mso.get('00N10000008rsVN')); + } + //閰嶅浣跨敤浜у搧00N10000008rsW4 + if(mso.containsKey('00N10000008rsW4')){ + controller.getRecord().put('SupportingProducts__c',mso.get('00N10000008rsW4')); + } + //鍙戠幇鏁呴殰鍚庯紝鍖婚櫌瀵规偅鑰呯殑澶勭悊鎯呭喌00N10000008rsVL + if(mso.containsKey('00N10000008rsVL')){ + controller.getRecord().put('AfterFailureInformation__c',mso.get('00N10000008rsVL')); + } + //鍙戠幇鏁呴殰鐜拌薄鍚庯紝鏈夊欢璇�15鍒嗛挓浠ヤ笂鐨勬墜鏈疄鏂界殑鎯呭喌鍙戠敓鍚�00N10000008rsVR + if(mso.containsKey('00N10000008rsVR')){ + controller.getRecord().put('Delay15Min__c',mso.get('00N10000008rsVR')); + } + //淇℃伅鏄粠鍖婚櫌鐨勮皝閭i噷寰楀埌鐨�00N10000008rsVZ + if(mso.containsKey('00N10000008rsVZ')){ + controller.getRecord().put('InformationFrom__c',mso.get('00N10000008rsVZ')); + } + //鍦ㄥ尰闄紝鏁呴殰鍙戠敓鐨勯鐜囨槸澶氬皯00N10000008rsVT + if(mso.containsKey('00N10000008rsVT')){ + controller.getRecord().put('FailureQInHospital__c',mso.get('00N10000008rsVT')); + } + //闂鍙戠敓鏃堕棿鎯呭喌00N10000008rsVv + if(mso.containsKey('00N10000008rsVv')){ + controller.getRecord().put('ProblemOccurred__c',mso.get('00N10000008rsVv')); + } + //鏄惁鐢ㄨ浜у搧瀹屾垚浜嗘墜鏈�/妫�鏌�00N10000008rsW5 + if(mso.containsKey('00N10000008rsW5')){ + if(mso.get('00N10000008rsW5') != 'undefined'){ + controller.getRecord().put('UseFailProductFinish__c',mso.get('00N10000008rsW5')); + } + } + //鏁呴殰鍙戠敓鏃�00N10000002Dx5y + if(mso.containsKey('00N10000002Dx5y')){ + String o = mso.get('00N10000002Dx5y'); + controller.getRecord().put('Failure_Occurrence_Date__c',(String.isBlank(o)||String.isEmpty(o))? null:Date.valueOf(o.replace('/', '-'))); + } + //淇悊濮旀墭鑰�(FSE)CF00N10000002EMHw_lkid + if(mso.containsKey('CF00N10000002EMHw_lkid')){ + controller.getRecord().put('Incharge_Staff__c',mso.get('CF00N10000002EMHw_lkid')); + } + //鍘熶慨鐞嗗彈浠樼暘鍙�00N1m000005gt1l + if(mso.containsKey('00N1m000005gt1l')){ + controller.getRecord().put('Old_Name__c',mso.get('00N1m000005gt1l')); + } + //璁惧鍨嬪彿CF00N10000002Dx1X_lkid + if(mso.containsKey('CF00N10000002Dx1X_lkid')){ + controller.getRecord().put('Delivered_Product__c',mso.get('CF00N10000002Dx1X_lkid')); + } + //缁翠慨濮旀墭涔﹀彿鐮�00N10000006P1dw + if(mso.containsKey('00N10000006P1dw')){ + controller.getRecord().put('PaperRepairRequestNo__c',mso.get('00N10000006P1dw')); + } + + //閫氳繃id鏌� + Repair__c rc = null; + if (mso.containsKey('RepairId')) { + String RepairId = mso.get('RepairId'); + rc = [select Hospital__c,Department_Class__c,Account__c,Dealer__c,Incharge_Staff_Contact__c,Incharge_Staff__c from Repair__c where id =:RepairId ]; + //鍖婚櫌 + controller.getRecord().put('Hospital__c',rc.Hospital__c); + //鎴樼暐绉戝鍒嗙被 + controller.getRecord().put('Department_Class__c',rc.Department_Class__c); + //绉戝 + controller.getRecord().put('Account__c',rc.Account__c); + //缁忛攢鍟嗗悕 + controller.getRecord().put('Dealer__c',rc.Dealer__c); + //淇悊濮旀墭鑰咃紙鍛樺伐锛� + controller.getRecord().put('Incharge_Staff_Contact__c',rc.Incharge_Staff_Contact__c); + //淇悊濮旀墭鑰�(FSE) + controller.getRecord().put('Incharge_Staff__c',rc.Incharge_Staff__c); + } + + //甯傚満澶氬勾淇濅慨 鏈夊伩/鏃犲伩淇悊00N10000008rG4p + if(mso.containsKey('00N10000008rG4p')){ + controller.getRecord().put('RepairCostType__c',mso.get('00N10000008rG4p')); + } + //鏈嶅姟鏂瑰紡00N10000002F6dW + if(mso.containsKey('00N10000002F6dW')){ + controller.getRecord().put('On_site_repair__c',mso.get('00N10000002F6dW')); + } + //杩斿搧鏂瑰紡00N1m000004QmcJ + if(mso.containsKey('00N1m000004QmcJ')){ + controller.getRecord().put('Returns_Product_way__c',mso.get('00N1m000004QmcJ')); + } + //闂鍐呭鎻忚堪锛堝浘鐗囷級00N10000008rsVuEAI + if(mso.containsKey('00N10000008rsVuEAI')){ + controller.getRecord().put('ProblemDescription__c',mso.get('00N10000008rsVuEAI')); + } + //鎶ヤ慨浜�00N1m0000054ufW + if(mso.containsKey('00N1m0000054ufW')){ + controller.getRecord().put('RepairApplicant__c',mso.get('00N1m0000054ufW')); + } + //鎶ヤ慨浜哄尰闄�00N1m0000054ufU + if(mso.containsKey('00N1m0000054ufU')){ + controller.getRecord().put('RepairApplicantHospital__c',mso.get('00N1m0000054ufU')); + } + //鎶ヤ慨浜虹瀹�00N1m0000054ufT + if(mso.containsKey('00N1m0000054ufT')){ + controller.getRecord().put('RepairApplicantDepartment__c',mso.get('00N1m0000054ufT')); + } + //閫佷慨鐗╂祦鏂瑰紡00N1m0000054ufE + if(mso.containsKey('00N1m0000054ufE')){ + controller.getRecord().put('DeliveryLogisticsMode__c',mso.get('00N1m0000054ufE')); + } + //閫佷慨鐗╂祦鏈�鏂扮姸鎬�00N1m0000054ufk + if(mso.containsKey('00N1m0000054ufk')){ + controller.getRecord().put('LogisticsLatestStatus__c',mso.get('00N1m0000054ufk')); + } + //閫佷慨鐗╂祦鍗曞彿00N1m0000054ufF + if(mso.containsKey('00N1m0000054ufF')){ + controller.getRecord().put('DeliveryLogisticsNo__c',mso.get('00N1m0000054ufF')); + } + //閫佷慨鐗╂祦淇℃伅澶囨敞00N1m0000054ufD + if(mso.containsKey('00N1m0000054ufD')){ + controller.getRecord().put('DeliveryLogisticsAnnotation__c',mso.get('00N1m0000054ufD')); + } + //瓒呮椂鎶ュ憡鐨勭悊鐢�00N10000008rsVS + if(mso.containsKey('00N10000008rsVS')){ + controller.getRecord().put('DelayReportReason__c',mso.get('00N10000008rsVS')); + } + //鎶ヤ慨瀛愬崟CF00N1m0000054ufZ_lkid + if(mso.containsKey('CF00N1m0000054ufZ_lkid')){ + controller.getRecord().put('RepairSubOrder__c',mso.get('CF00N1m0000054ufZ_lkid')); + //鏌ヨAWSDataId + List<RepairSubOrder__c> rso = [select AWS_Data_Id__c from RepairSubOrder__c where Id=:mso.get('CF00N1m0000054ufZ_lkid')]; + if(rso.size() > 0){ + RepairSubOrderAWSDataId = rso[0].AWS_Data_Id__c; + } + } rtTypeId = ApexPages.currentPage().getParameters().get('RecordType'); if(String.isBlank(rtTypeId)||String.isEmpty(rtTypeId)){ List<RecordType> rtList = new List<RecordType>([select Id,DeveloperName from RecordType where SobjectType ='Repair__c' and DeveloperName ='Repair']); @@ -55,6 +239,7 @@ } LayoutDescriberHelper.LayoutWrapper LayoutWrapperValue = LayoutDescriberHelper.describeSectionWithFieldsWrapper(rtTypeId, 'Repair__c','classic'); layoutSections = LayoutWrapperValue.layoutSections; + layoutSectionsStr = JSON.serialize(layoutSections); //for dynamic add readonly attribute List<String> requiredFieldAPIList = LayoutWrapperValue.requiredFieldAPIList; Map<String,String> fieldAPIToLabelMap = LayoutWrapperValue.fieldAPIToLabelMap; requiredFieldAPIListStr = JSON.serialize(requiredFieldAPIList); @@ -62,9 +247,11 @@ PIHelper.PIIntegration piIntegration = PIHelper.getPIIntegrationInfo('Repair__c'); PIHelper.PIIntegration piIntegrationAddress = PIHelper.getPIIntegrationInfo('Address__c'); PIHelper.PIIntegration piIntegrationContact = PIHelper.getPIIntegrationInfo('Contact'); + PIHelper.PIIntegration piIntegrationRepairSubOrder = PIHelper.getPIIntegrationInfo('RepairSubOrder__c'); staticResource = JSON.serialize(piIntegration); staticResourceAddress = JSON.serialize(piIntegrationAddress); staticResourceContact = JSON.serialize(piIntegrationContact); + staticResourceRepairSubOrder = JSON.serialize(piIntegrationRepairSubOrder); encryptedAPIList = piIntegration.PIFields; sobjectPrefix = piIntegration.sobjectPrefix; } @@ -73,6 +260,17 @@ public String recordId{set;get;} public String message{set;get;} public String status{set;get;} + } + + @RemoteAction + global static Response EncryptUpdate(string rid){ + + boolean b = AWSServiceTool2.EncryptPushData(new string[]{rid}); + Response r = new Response(); + r.status = b ? 'success' : 'failed'; + r.message = b ? '' : '鍔犲瘑鎺ㄩ�佸け璐�'; + r.recordId = rid; + return r; } @RemoteAction @@ -86,21 +284,27 @@ //鑷畾涔夋牸寮忚浆鎹� 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)); - if(String.isBlank(fieldValue)){ + 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'){ - repairInfo.put(fieldAPI, Date.valueOf(String.valueOf(fieldValueMap.get(fieldAPI)).replace('/', '-'))); + repairInfo.put(fieldAPI,(String.isBlank(fieldValue)||String.isEmpty(fieldValue))? null:Date.valueOf(fieldValue.replace('/', '-'))); }else if(String.valueOf(fielddataType)=='DATETIME'){ - String dt = String.valueOf(fieldValueMap.get(fieldAPI)); - if(String.isNotBlank(dt)&&dt.contains('T')){ - dt = dt.replace('T',' '); - repairInfo.put(fieldAPI, Datetime.valueOfGmt(dt)); - } + if(String.isNotBlank(fieldValue)&&fieldValue.contains('T')){ + fieldValue = fieldValue.replace('T',' '); + repairInfo.put(fieldAPI, Datetime.valueOfGmt(fieldValue)); + }else if(String.isNotBlank(fieldValue)) { + fieldValue = fieldValue.replace('/', '-') + ':00'; + System.debug('fieldValue = ' + fieldValue); + repairInfo.put(fieldAPI, Datetime.valueOf(fieldValue)); + }else{ + repairInfo.put(fieldAPI, null); + } + }else if(String.valueOf(fielddataType)=='PERCENT'||String.valueOf(fielddataType)=='CURRENCY'||String.valueOf(fielddataType)=='Number'||String.valueOf(fielddataType)=='DOUBLE' ){ - repairInfo.put(fieldAPI, Decimal.valueOf(String.valueOf(fieldValueMap.get(fieldAPI)))); + repairInfo.put(fieldAPI, (String.isBlank(fieldValue)||String.isEmpty(fieldValue))?null:Decimal.valueOf(fieldValue.replace(',', ''))); } else if(String.valueof(fielddataType)=='BOOLEAN'){ repairInfo.put(fieldAPI, fieldValueMap.get(fieldAPI)); }else { @@ -135,6 +339,26 @@ System.debug('resp from sfdx back-end' + resp); return resp; + } catch(DmlException e) { + rid=repairInfo.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)repairInfo.get('AWS_Data_Id__c'),repairJson ,status,''); + return resp; + } catch(Exception e) { System.debug('into catch'+e.getMessage()); Database.rollback(sp); -- Gitblit v1.9.1