Commit 3cd7eb53 by 蒋勇

d

parent b36c5fd2
......@@ -7,7 +7,7 @@ class CtlBase {
this.service = system.getObject("service." + gname + "." + sname);
this.cacheManager = system.getObject("db.common.cacheManager");
}
getUUID() {
getUUID() {
var uuid = uuidv4();
var u = uuid.replace(/\-/g, "");
return u;
......@@ -36,35 +36,35 @@ class CtlBase {
}
async refQuery(pobj, qobj, req) {
//pobj.refwhere.app_id=pobj.app_id;//角色过滤按照公司过滤
pobj.refwhere.company_id=pobj.company_id;
let rtn=await this.service.refQuery(pobj);
pobj.refwhere.company_id = pobj.company_id;
let rtn = await this.service.refQuery(pobj);
return rtn
}
async setContextParams(pobj, qobj, req) {
let custtags = req.headers["x-consumetag"]?req.headers["x-consumetag"].split("|"):null;
let lastindex=custtags?custtags.length-1:0;
let custtags = req.headers["x-consumetag"] ? req.headers["x-consumetag"].split("|") : null;
let lastindex = custtags ? custtags.length - 1 : 0;
//当自由用户注册时,需要根据前端传来的companykey,查询出公司,给companyid赋值
req.xctx = {
appkey: req.headers["xappkey"],//用于系统管理区分应用,比如角色
fromappkey:req.headers["xfromappkey"],//来源APP,如果没有来源与appkey相同
companyid: custtags?custtags[0].split("_")[1]:null,
fromcompanykey:req.headers["xfromcompanykey"],//专用于自由用户注册,自由用户用于一定属于某个存在的公司
password: custtags?custtags[lastindex].split("_")[1]:null,
fromappkey: req.headers["xfromappkey"],//来源APP,如果没有来源与appkey相同
companyid: custtags ? custtags[0].split("_")[1] : null,
fromcompanykey: req.headers["xfromcompanykey"],//专用于自由用户注册,自由用户用于一定属于某个存在的公司
password: custtags ? custtags[lastindex].split("_")[1] : null,
username: req.headers["x-consumer-username"],
userid:req.headers["x-consumer-custom-id"],
userid: req.headers["x-consumer-custom-id"],
credid: req.headers["x-credential-identifier"],
regrole:req.headers["xregrole"],
bizpath:req.headers["xbizpath"],
codename:req.headers["xcodename"],
codetitle:req.headers["xcodetitle"]?decodeURI(req.headers["xcodetitle"]):'',
regrole: req.headers["xregrole"],
bizpath: req.headers["xbizpath"],
codename: req.headers["xcodename"],
codetitle: req.headers["xcodetitle"] ? decodeURI(req.headers["xcodetitle"]) : '',
}
if(!req.xctx.appkey){
return [-200,"请求头缺少应用x-app-key"]
}else{
let app=await this.cacheManager["AppCache"].cache(req.xctx.fromappkey);
req.xctx.appid=app.id;
if(!pobj.app_id){
pobj.app_id=app.id;//传递参数对象里注入app_id
if (!req.xctx.appkey) {
return [-200, "请求头缺少应用x-app-key"]
} else {
let app = await this.cacheManager["AppCache"].cache(req.xctx.fromappkey);
req.xctx.appid = app.id;
if (!pobj.app_id) {
pobj.app_id = app.id;//传递参数对象里注入app_id
}
}
//平台注册时,companyid,companykey都为空
......@@ -72,63 +72,44 @@ class CtlBase {
// if(!req.xctx.companyid && !req.xctx.companykey){
// return [-200,"请求头缺少应用x-app-key"]
// }
if(!req.xctx.companyid && req.xctx.fromcompanykey && req.xctx.fromcompanykey!="null" && req.xctx.fromcompanykey!="undefined"){
let comptmp=await this.cacheManager["CompanyCache"].cache(req.xctx.fromcompanykey);
req.xctx.companyid=comptmp.id;
if (!req.xctx.companyid && req.xctx.fromcompanykey && req.xctx.fromcompanykey != "null" && req.xctx.fromcompanykey != "undefined") {
let comptmp = await this.cacheManager["CompanyCache"].cache(req.xctx.fromcompanykey);
req.xctx.companyid = comptmp.id;
}
if(req.xctx.companyid){//在请求传递数据对象注入公司id
pobj.company_id=req.xctx.companyid;
if (req.xctx.companyid) {//在请求传递数据对象注入公司id
pobj.company_id = req.xctx.companyid;
}
if(req.xctx.userid){//在请求传递数据对象注入公司id
pobj.userid=req.xctx.userid;
pobj.username=req.xctx.username;
if (req.xctx.userid) {//在请求传递数据对象注入公司id
pobj.userid = req.xctx.userid;
pobj.username = req.xctx.username;
}
pobj.bizpath=req.xctx.bizpath;
pobj.bizpath = req.xctx.bizpath;
}
async log(pobj, req, rtn) {
rtn.requestId = this.getUUID()
req.params.param = pobj
//第三个字段应该存公司id
system.execLogs(req.xctx.codetitle, req.params, pobj.company_id, rtn, null).then(res => {
if (res && res.status == 1) {
console.log("log.....success")
} else {
console.log("log.....fail")
}
}).catch(e => {
console.log("log.....fail")
})
}
async doexec(methodname, pobj, query, req) {
try {
let xarg=await this.setContextParams(pobj, query, req);
if(xarg && xarg[0]<0){
return system.getResultFail(...xarg);
let xarg = await this.setContextParams(pobj, query, req);
if (xarg && xarg[0] < 0) {
return system.getResultFail(...xarg);
}
//从请求头里面取appkey_consumename
// var consumeName=req.headers[""]
// var appkey=
// if( this.session["appkey_consumename"]) {
// }else{
// //从头里取,从redis中取出缓存对象赋值到控制基类的session属性
// //appkey_consumename
// this.session={};
// }
//req.session=redis缓存的上下文对象
var rtn = await this[methodname](pobj, query, req);
rtn.requestId=this.getUUID()
req.params.param=pobj
//第三个字段应该存公司id
system.execLogs(req.xctx.codetitle,req.params, pobj.company_id,rtn,null).then(res=>{
if(res && res.status==1){
console.log("log.....success")
}else{
console.log("log.....fail")
}
}).catch(e=>{
console.log("log.....fail")
})
//this.log(pobj,req,rtn)
return rtn;
} catch (e) {
let rtn={}
rtn.requestId=this.getUUID()
req.params.param=pobj
system.execLogs(req.xctx.codetitle,req.params,pobj.company_id,rtn,e).then(res=>{
if(res && res.status==1){
console.log("log.....success")
}else{
console.log("log.....fail")
}
}).catch(e=>{
console.log("log.....fail")
})
//this.log(pobj,req,rtn)
console.log(e.stack, "出现异常,请联系管理员.......");
return system.getResultFail(-200, "出现异常,请联系管理员");
}
......@@ -136,7 +117,7 @@ class CtlBase {
}
module.exports = CtlBase;
/*
地址:http://192.168.1.128:401/api/queueAction/producer/springBoard
地址:http://192.168.1.128:401/api/queueAction/producer/springBoard
请求方式:post
参数:
{
......
[
{"id":41,"price_code":"sv_business_registration_category_indi7","product_name":"/ic/cpreg/","price_name":"个体工商","created_at":null,"updated_at":null,"deleted_at":null,"version":null},
{"id":42,"price_code":"sv_business_registration_category_lp7","product_name":"/ic/cpreg/","price_name":"有限公司","created_at":null,"updated_at":null,"deleted_at":null,"version":null},
{"id":43,"price_code":"sv_business_registration_category_sole7","product_name":"/ic/cpreg/","price_name":"个人独资","created_at":null,"updated_at":null,"deleted_at":null,"version":null}
]
\ No newline at end of file
[{"id":41,"price_code":"sv_business_registration_category_indi7","product_name":"/ic/cpreg/","price_name":"个体工商","created_at":null,"updated_at":null,"deleted_at":null,"version":null},{"id":42,"price_code":"sv_business_registration_category_lp7","product_name":"/ic/cpreg/","price_name":"有限公司","created_at":null,"updated_at":null,"deleted_at":null,"version":null},{"id":43,"price_code":"sv_business_registration_category_sole7","product_name":"/ic/cpreg/","price_name":"个人独资","created_at":null,"updated_at":null,"deleted_at":null,"version":null}]
\ No newline at end of file
......@@ -74,6 +74,7 @@ class System {
},
body: data
}, function (error, response, body) {
console.log(response)
console.log(error)
if (!error) {
rtn.statusCode = response.statusCode
......
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