Commit 42392cf4 by 蒋勇

d

parent c2b3c2f0
...@@ -5,6 +5,11 @@ class APIBase{ ...@@ -5,6 +5,11 @@ class APIBase{
constructor() { constructor() {
this.cacheManager = system.getObject("db.common.cacheManager"); this.cacheManager = system.getObject("db.common.cacheManager");
} }
getUUID() {
var uuid = uuidv4();
var u = uuid.replace(/\-/g, "");
return u;
}
async setContextParams(pobj, qobj, req) { async setContextParams(pobj, qobj, req) {
let custtags = req.headers["x-consumetag"]?req.headers["x-consumetag"].split("|"):null; let custtags = req.headers["x-consumetag"]?req.headers["x-consumetag"].split("|"):null;
//当自由用户注册时,需要根据前端传来的companykey,查询出公司,给companyid赋值 //当自由用户注册时,需要根据前端传来的companykey,查询出公司,给companyid赋值
...@@ -15,6 +20,8 @@ class APIBase{ ...@@ -15,6 +20,8 @@ class APIBase{
username: req.headers["x-consumer-username"], username: req.headers["x-consumer-username"],
credid: req.headers["x-credential-identifier"], credid: req.headers["x-credential-identifier"],
companykey:req.headers["x-company-key"],//专用于自由用户注册,自由用户用于一定属于某个存在的公司 companykey:req.headers["x-company-key"],//专用于自由用户注册,自由用户用于一定属于某个存在的公司
codename:req.headers["xcodename"],
codetitle:req.headers["xcodetitle"]?decodeURI(req.headers["xcodetitle"]):'',
} }
if(!req.xctx.appkey){ if(!req.xctx.appkey){
return [-200,"请求头缺少应用x-app-key"] return [-200,"请求头缺少应用x-app-key"]
...@@ -44,8 +51,43 @@ class APIBase{ ...@@ -44,8 +51,43 @@ class APIBase{
} }
var rtn = await this[methodname](pobj, query, req); var rtn = await this[methodname](pobj, query, req);
rtn.requestId=this.getUUID()
req.params.param=pobj
let t=req.xctx.codetitle
let codename=req.xctx.codename
if(t==''){
t="外部调用"
codename=req.xctx.appkey
}
system.execLogs(t,req.params,codename,rtn,null).then(res=>{
if(res && res.status==1){
console.log("log.....success")
}else{
console.log("log.....fail")
}
}).catch(e=>{
console.log("log.....fail")
})
return rtn; return rtn;
} catch (e) { } catch (e) {
let rtn={}
rtn.requestId=this.getUUID()
req.params.param=pobj
let t=req.xctx.codetitle
let codename=req.xctx.codename
if(t==''){
t="外部调用"
codename=req.xctx.appkey
}
system.execLogs(t,req.params,codename,rtn,e.stack).then(res=>{
if(res && res.status==1){
console.log("log.....success")
}else{
console.log("log.....fail")
}
}).catch(e=>{
console.log("log.....fail")
})
console.log(e.stack, "api调用异常--error..................."); console.log(e.stack, "api调用异常--error...................");
var rtnerror = system.getResultFail(-200, "出现异常,请联系管理员"); var rtnerror = system.getResultFail(-200, "出现异常,请联系管理员");
return rtnerror; return rtnerror;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment