| | |
| | | public String awsToken{set;get;} |
| | | public static Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe(); |
| | | public static String sobjectTypeValue = 'Consum_Apply_Equipment_Set_Detail__c'; |
| | | public Boolean isCloneMode{protected set;get;} |
| | | public Boolean isNewMode{set;get;} |
| | | public String rtTypeId {get; set;} |
| | | public String AWSDataId{set;get;} |
| | |
| | | public String sobjectPrefix{set;get;} |
| | | public NewConsumApplyEquipSetDetailController(ApexPages.StandardController controller) { |
| | | isNewMode = true; |
| | | isCloneMode = false; |
| | | Input_Required_Field_Msg = Label.Input_Required_Field_Msg; |
| | | sobjecttypeForFrontEnd = sobjectTypeValue; |
| | | //获取所有字段 |
| | | Map<string,string> mso = ApexPages.currentPage().getParameters(); |
| | | if(mso != null && mso.containsKey('newclone')){ |
| | | isCloneMode = true; |
| | | } |
| | | List<String> fieldList = new List<String>(Schema.getGlobalDescribe().get('Consum_Apply_Equipment_Set_Detail__c').getDescribe().fields.getMap().keyset()); |
| | | controller.addFields(fieldList); |
| | | if (!Test.isRunningTest()) { |
| | | controller.addFields(fieldList); |
| | | } |
| | | SObject obj = controller.getRecord(); |
| | | if(obj.Id != null){ |
| | | //更新 |
| | |
| | | Consum_Apply_Equipment_Set_Detail__c consumApplyInfo = new Consum_Apply_Equipment_Set_Detail__c(); |
| | | //自定义格式转换 |
| | | for (String fieldAPI: fieldValueMap.keySet()) { |
| | | system.debug('field API'+fieldAPI); |
| | | String fieldValue = String.valueOf(fieldAPIToTypeMap.get(fieldAPI)); |
| | | if(String.isBlank(fieldValue)){ |
| | | continue; |
| | | } |
| | | Schema.DescribeFieldResult fielddataType = fieldAPIToTypeMap.get(fieldAPI).getDescribe(); |
| | | Schema.DisplayType fieldDatas = fielddataType.getType(); |
| | | if(String.valueOf(fielddatas)=='DATE'){ |
| | | consumApplyInfo.put(fieldAPI, Date.valueOf(String.valueOf(fieldValueMap.get(fieldAPI)).replace('/', '-'))); |
| | | }else if(String.valueOf(fielddatas)=='DATETIME'){ |
| | | String dt = String.valueOf(fieldValueMap.get(fieldAPI)); |
| | | if(String.isNotBlank(dt)&&dt.contains('T')){ |
| | | dt = dt.replace('T',' '); |
| | | consumApplyInfo.put(fieldAPI, Datetime.valueOfGmt(dt)); |
| | | } |
| | | }else if(String.valueOf(fielddatas)=='Number'||String.valueOf(fielddatas)=='DOUBLE'){ |
| | | // ||String.valueOf(fielddatas)=='Decimal' |
| | | consumApplyInfo.put(fieldAPI, Decimal.valueOf(String.valueOf(fieldValueMap.get(fieldAPI)))); |
| | | } else if(String.valueof(fielddatas)=='BOOLEAN'){ |
| | | system.debug('field API='+fieldAPI); |
| | | Schema.DisplayType fielddataType = fieldAPIToTypeMap.get(fieldAPI).getDescribe().getType(); |
| | | String fieldValue = String.valueOf(fieldValueMap.get(fieldAPI)); |
| | | system.debug('Field Type:'+fielddataType+' field Value='+fieldValue); |
| | | if(String.valueOf(fielddataType)=='DATE'){ |
| | | consumApplyInfo.put(fieldAPI,(String.isBlank(fieldValue)||String.isEmpty(fieldValue))? null:Date.valueOf(fieldValue.replace('/', '-'))); |
| | | }else if(String.valueOf(fielddataType)=='DATETIME'){ |
| | | if(String.isNotBlank(fieldValue)&&fieldValue.contains('T')){ |
| | | fieldValue = fieldValue.replace('T',' '); |
| | | consumApplyInfo.put(fieldAPI, Datetime.valueOfGmt(fieldValue)); |
| | | }else{ |
| | | consumApplyInfo.put(fieldAPI, null); |
| | | } |
| | | }else if(String.valueof(fielddataType)=='CURRENCY'|| String.valueof(fielddataType)=='PERCENT'||String.valueOf(fielddataType)=='Number'||String.valueOf(fielddataType)=='DOUBLE' ){ |
| | | consumApplyInfo.put(fieldAPI, (String.isBlank(fieldValue)||String.isEmpty(fieldValue))?0:Decimal.valueOf(fieldValue)); |
| | | } else if(String.valueof(fielddataType)=='BOOLEAN'){ |
| | | consumApplyInfo.put(fieldAPI, fieldValueMap.get(fieldAPI)); |
| | | }else { |
| | | consumApplyInfo.put(fieldAPI, String.valueOf(fieldValueMap.get(fieldAPI))); |
| | | consumApplyInfo.put(fieldAPI,fieldValue); |
| | | } |
| | | } |
| | | |
| | |
| | | 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); |
| | | Consum_Apply_Equipment_Set_Detail__c[] ConsumApplys = [select id from Consum_Apply_Equipment_Set_Detail__c where AWS_Data_Id__c =:awsDataId]; |
| | | |
| | | if(!isNew || isClone){ |
| | | isClone = ConsumApplys.size() == 0; |
| | | } |
| | | if(isNew){ |
| | | 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_Equipment_Set_Detail__c[] ConsumApplys = [select id from Consum_Apply_Equipment_Set_Detail__c where AWS_Data_Id__c =:awsDataId]; |
| | | // String awsDataId = (String)consumApplyInfo.get('AWS_Data_Id__c'); |
| | | // System.debug('awsDataId = ' + awsDataId); |
| | | // Consum_Apply_Equipment_Set_Detail__c[] ConsumApplys = [select id from Consum_Apply_Equipment_Set_Detail__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; |