Commit 417cbfe5 by 宋毅

tj

parent 7abd3bce
......@@ -64,6 +64,43 @@ class APIBase {
}
//-----------------------新的模式------------------开始
async doexecOverviewMethod(gname, methodname, pobj, query, req) {
try {
var shaStr = await sha256(JSON.stringify(pobj));
//查询缓存
var cacheRes = await this.redisClient.getCache(shaStr);
if (cacheRes) {
return JSON.parse(cacheRes);
}
var result = await this[methodname](pobj, query, req);
if (!result) {
result = system.getResult(null, "请求的方法返回值为空");
}
this.execClient.execLogs("reqPath:" + req.path + "执行结果", pobj, "brg-user-center-doexecOverviewMethod", result, null);
//保存缓存
await this.redisClient.setWithEx(shaStr, JSON.stringify(result), 5);
return result;
} catch (error) {
var stackStr = error.stack ? error.stack : JSON.stringify(error);
console.log(stackStr, "api调用出现异常,请联系管理员..........")
var rtnerror = system.getResultFail(-200, "系统出现异常");
this.execClient.execLogs("reqPath:" + req.path + "执行异常", pobj, "brg-user-center-doexecOverviewMethod", rtnerror, stackStr);
if (pobj.Action && action) {
return {
"Response": {
"Status": -200,
"Error": {
"Code": "FailedOperation",//操作失败
"Message": req.path + "执行异常"
},
"RequestId": rtnerror.requestId
}
};
}
return rtnerror;
}
}
async doexecMethod(gname, methodname, pobj, query, req) {
var action = this.userCenterAction[req.body.Action];
......@@ -95,7 +132,7 @@ class APIBase {
}
result.requestId = pobj.RequestId || uuid.v1();
var tmpResult = reqParams.actionType && reqParams.actionType.indexOf("List") < 0 ? result : { status: result.status, message: result.message, requestId: result.requestId };
this.execClient.execLogs("reqPath:" + req.path + "执行结果", reqParams, "brg-user-center-apibase", tmpResult, null);
this.execClient.execLogs("reqPath:" + req.path + "执行结果", reqParams, "brg-user-center-doexecMethod", tmpResult, null);
if (pobj.Action && action) {
result = await this.handleTxResult(result);
delete req.body["Action"];
......@@ -109,7 +146,7 @@ class APIBase {
console.log(stackStr, "api调用出现异常,请联系管理员..........")
var rtnerror = system.getResultFail(-200, "系统出现异常");
rtnerror.requestId = pobj.RequestId || uuid.v1();
this.execClient.execLogs("reqPath:" + req.path + "执行异常", reqParams, "brg-user-center-apibase", rtnerror, stackStr);
this.execClient.execLogs("reqPath:" + req.path + "执行异常", reqParams, "brg-user-center-doexecMethod", rtnerror, stackStr);
if (pobj.Action && action) {
return {
"Response": {
......@@ -245,14 +282,14 @@ class APIBase {
result = system.getResult(null, "请求的方法返回值为空");
}
result.requestId = pobj.RequestId || uuid.v1();
this.execClient.execLogs("reqPath:" + req.path + "brg请求结果", param, "brg-user-center-brg-apibase", result, null);
this.execClient.execLogs("reqPath:" + req.path + "brg请求结果", param, "brg-user-center-brgDoexecMethod", result, null);
return result;
} catch (error) {
var stackStr = error.stack ? error.stack : JSON.stringify(error);
console.log(stackStr, "api-brg请求调用出现异常,请联系管理员..........")
console.log(stackStr, "api-brg请求调用出现异常,请联系管理员..........");
var rtnerror = system.getResultTX(-1, "", "brg请求出现异常,error:" + stackStr, null);
rtnerror.requestId = pobj.RequestId || uuid.v1();
this.execClient.execLogs("reqPath:" + req.path + "brg请求出现异常", param, "brg-user-center-brg-apibase", null, stackStr);
this.execClient.execLogs("reqPath:" + req.path + "brg请求出现异常", param, "brg-user-center-brgDoexecMethod", null, stackStr);
return rtnerror;
}
}
......
var APIBase = require("../../api.base");
var system = require("../../../system");
var settings = require("../../../../config/settings");
class icName extends APIBase {
constructor() {
super();
this.utilsIcNameSve = system.getObject("service.utilsSve.utilsIcNameSve");
}
async getVat(pobj, qobj, req) {
return system.getResultSuccess();
}
async getBusinessRegistration(pobj, qobj, req) {
return system.getResultSuccess();
}
}
module.exports = icName;
var url = require("url");
var system = require("../../base/system");
var bodyParser = require('body-parser');
const { JSON } = require("sequelize");
const utilsAuthSve = system.getObject("service.utilsSve.utilsAuthSve");
module.exports = function (app) {
//-----------------------新的模式---------api---------开始
app.all("/overview/*", async function (req, res, next) {
var result = system.getResult(null, "req method must is post");
if (req.method != "POST") {
res.end(JSON.stringify(result));
return;
app.post('/overview/:gname/:qname/:method', function (req, res) {
var classPath = req.params["qname"];
var methodName = req.params["method"];
var gname = req.params["gname"];
var params = [];
classPath = gname + "." + classPath;
var tClientIp = system.get_client_ip(req);
req.clientIp = tClientIp;
req.uagent = req.headers["user-agent"];
req.classname = classPath;
var keys = Object.keys(req.body);
if (keys.length > 0) {
req.body = JSON.parse(keys[0]);
}
console.log(req.body, "....body......");
// var param = bodyParser.urlencoded({ extended: false })
// if (["getAppTokenByHosts", "getAppTokenByAppKey"].indexOf(req.body.actionType) >= 0) {
// req.body.actionBody.appHosts = req.host;
// next();
// return;
// }
// if (req.path.indexOf("/taskapi/") >= 0) {
// next();
// return;
// }
next();
params.push(gname);
params.push(methodName);
params.push(req.body);
params.push(req.query);
params.push(req);
var p = null;
var invokeObj = system.getObject("api." + classPath);
if (invokeObj["doexecOverviewMethod"]) {
p = invokeObj["doexecOverviewMethod"].apply(invokeObj, params);
}
p.then(r => {
res.end(JSON.stringify(r));
});
});
app.all("/api/*", async function (req, res, next) {
......@@ -31,15 +43,6 @@ module.exports = function (app) {
res.end(JSON.stringify(result));
return;
}
// if (["getAppTokenByHosts", "getAppTokenByAppKey"].indexOf(req.body.actionType) >= 0) {
// req.body.actionBody.appHosts = req.host;
// next();
// return;
// }
// if (req.path.indexOf("/taskapi/") >= 0) {
// next();
// return;
// }
next();
});
......
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