|  |  |  | 
|---|
|  |  |  | var  AWSService = {}; | 
|---|
|  |  |  | let  AWSService = {}; | 
|---|
|  |  |  | AWSService = { | 
|---|
|  |  |  | sfSessionId : '', | 
|---|
|  |  |  | insertModule : 'Insert AWS ', | 
|---|
|  |  |  | 
|---|
|  |  |  | successStatus : 'success', | 
|---|
|  |  |  | failStatus : 'fail', | 
|---|
|  |  |  | insertCalloutLog:function(module,url,request,response,status){ | 
|---|
|  |  |  | if(AWSService.sfSessionId){ | 
|---|
|  |  |  | if(AWSService.sfSessionId&&false){ | 
|---|
|  |  |  | sforce.connection.sessionId = AWSService.sfSessionId; | 
|---|
|  |  |  | let transLog = new sforce.SObject('Transaction_Log__c'); | 
|---|
|  |  |  | transLog.AWS_Data_Id__c = ''; | 
|---|
|  |  |  | transLog.Module__c = module; | 
|---|
|  |  |  | transLog.Interface_URL__c = url; | 
|---|
|  |  |  | transLog.Request__c = request; | 
|---|
|  |  |  | transLog.Response__c = response; | 
|---|
|  |  |  | transLog.Request__c = ''; | 
|---|
|  |  |  | transLog.Response__c = ''; | 
|---|
|  |  |  | transLog.Status__c = status; | 
|---|
|  |  |  | let insertLogResult = sforce.connection.create([transLog]); | 
|---|
|  |  |  | if(insertLogResult[0].getBoolean(AWSService.successStatus)) { | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }, | 
|---|
|  |  |  |  | 
|---|
|  |  |  | get:function(queryURL, queryback, token) { | 
|---|
|  |  |  | let para = { | 
|---|
|  |  |  | url:queryURL, | 
|---|
|  |  |  | headers: { | 
|---|
|  |  |  | 'Content-Type': 'application/json', | 
|---|
|  |  |  | 'pi-token': token | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | type: "get", | 
|---|
|  |  |  | success: function (data) { | 
|---|
|  |  |  | AWSService.insertCalloutLog(AWSService.queryModule,queryURL,'',JSON.stringify(data),AWSService.successStatus); | 
|---|
|  |  |  | queryback(data); | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | error: function (error){ | 
|---|
|  |  |  | //错误相关处理 404属于该处理(经测试) | 
|---|
|  |  |  | //还可能是"timeout", "error", "notmodified" 和 "parsererror"。 | 
|---|
|  |  |  | AWSService.insertCalloutLog(AWSService.queryModule,queryURL,'',JSON.stringify(error),AWSService.failStatus); | 
|---|
|  |  |  | console.log(error); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | jQuery.ajax(para); | 
|---|
|  |  |  | }, | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //update | 
|---|
|  |  |  | post:function(postURL, payloadForNewPI, callback, token) { | 
|---|
|  |  |  | post:function(postURL, payloadForNewPI, callback, token,callbackError) { | 
|---|
|  |  |  | console.log('Process New PI Data'); | 
|---|
|  |  |  | console.log(JSON.stringify(payloadForNewPI)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | error: function (error){ | 
|---|
|  |  |  | AWSService.insertCalloutLog(AWSService.insertModule,postURL,JSON.stringify(payloadForNewPI),JSON.stringify(error),AWSService.failStatus); | 
|---|
|  |  |  | console.log(error); | 
|---|
|  |  |  | if(callbackError) callbackError(error); | 
|---|
|  |  |  | console.log(JSON.stringify(error)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | if (payloadstr) { | 
|---|
|  |  |  | 
|---|
|  |  |  | jQuery.ajax(para); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }, | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //update | 
|---|
|  |  |  | postConsumTrial:function(postURL, indexNumber , payloadForNewPI, callback, token) { | 
|---|
|  |  |  | console.log('Process New PI Data'); | 
|---|
|  |  |  | console.log(JSON.stringify(payloadForNewPI)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | let payloadstr= null; | 
|---|
|  |  |  | if (payloadForNewPI) { | 
|---|
|  |  |  | if (typeof payloadForNewPI == 'string') { | 
|---|
|  |  |  | payloadstr = payloadForNewPI; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | payloadstr = JSON.stringify(payloadForNewPI); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | let para = { | 
|---|
|  |  |  | url:postURL, | 
|---|
|  |  |  | headers: { | 
|---|
|  |  |  | 'Content-Type': 'application/json', | 
|---|
|  |  |  | 'pi-token': token | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | type: "post", | 
|---|
|  |  |  | success: function (result) { | 
|---|
|  |  |  | AWSService.insertCalloutLog(AWSService.insertModule,postURL,JSON.stringify(payloadForNewPI),JSON.stringify(result),AWSService.successStatus); | 
|---|
|  |  |  | if(callback) callback(result,indexNumber); | 
|---|
|  |  |  | }, | 
|---|
|  |  |  | error: function (error){ | 
|---|
|  |  |  | AWSService.insertCalloutLog(AWSService.insertModule,postURL,JSON.stringify(payloadForNewPI),JSON.stringify(error),AWSService.failStatus); | 
|---|
|  |  |  | console.log(error); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | if (payloadstr) { | 
|---|
|  |  |  | para.data = payloadstr; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | jQuery.ajax(para); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }, | 
|---|
|  |  |  |  | 
|---|
|  |  |  | confirmTrans:function(transactionURL,transParameters,callback,token){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | { escape: true } | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | window.AWSService = AWSService; | 
|---|