Commit b7641311 by sxy

feat: 日志列表

parent 592e7434
......@@ -6,7 +6,7 @@ class CtlBase {
this.serviceName = sname;
this.service = system.getObject("service." + gname + "." + sname);
this.cacheManager = system.getObject("db.common.cacheManager");
this.logClient=system.getObject("util.logClient");
this.logClient = system.getObject("util.logClient");
}
getUUID() {
var uuid = uuidv4();
......@@ -94,10 +94,10 @@ class CtlBase {
return system.getResultFail(...xarg);
}
var rtn = await this[methodname](pobj, query, req);
this.logClient.log(pobj,req,rtn,null)
this.logClient.log(pobj, req, rtn, null)
return rtn;
} catch (e) {
this.logClient.log(pobj,req,null,e.stack)
this.logClient.log(pobj, req, null, e.stack)
console.log(e.stack, "出现异常,请联系管理员.......");
return system.getResultFail(-200, "出现异常,请联系管理员");
}
......
var system = require("../../../system");
const http = require("http");
const querystring = require('querystring');
var settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base");
class logCtl extends CtlBase {
constructor() {
super("common", CtlBase.getServiceName(logCtl));
this.logClient = system.getObject("util.logClient");
}
async findAndCountAll(pobj, qobj, req) {
try {
let rtn = await this.logClient.logList(pobj);
return system.getResult({
results: {
count: rtn.totalCount,
rows: rtn && rtn.list && rtn.list.map(item => {
let { opTitle, identifyCode, messageBody, resultInfo, errorInfo, requestId, created_at } = item;
messageBody = messageBody ? JSON.parse(messageBody) : {}
resultInfo = resultInfo ? JSON.parse(resultInfo) : {}
return {
opTitle: opTitle.split(",").length > 1 ? opTitle.split(",")[1] : opTitle,
url: `${messageBody.gname}/${messageBody.qname}/${messageBody.method}`,
user: messageBody.param && messageBody.param.username || '',
ip: messageBody.param && messageBody.param.clientIp,
created_at,
info: {
opTitle, identifyCode, messageBody, resultInfo, errorInfo, requestId, created_at
}
}
}) || []
}
});
} catch (err) {
return system.getResult(null, err.message);
}
}
}
module.exports = logCtl;
......@@ -13,11 +13,11 @@ class LogClient {
var u = uuid.replace(/\-/g, "");
return u;
}
async log(pobj, req, rtninfo,errinfo) {
async log(pobj, req, rtninfo, errinfo) {
rtninfo.requestId = this.getUUID()
req.params.param = pobj
//第三个字段应该存公司id
system.execLogs(settings.appname+"_"+req.xctx.codetitle, req.params, pobj.company_id+"_", rtninfo, errinfo).then(res => {
system.execLogs(settings.appname + "_" + req.xctx.codetitle, req.params, pobj.company_id + "_", rtninfo, errinfo).then(res => {
if (res && res.status == 1) {
console.log("log.....success")
} else {
......@@ -27,5 +27,47 @@ class LogClient {
console.log("log.....fail")
})
}
async logList(pobj) {
let { search, pageInfo, company_id } = pobj;
let query = {
indexName: settings.logindex,
pageSize: pageInfo.pageSize,
currentPage: pageInfo.pageNo
};
if (company_id && company_id != 1) {
query.identifyCode = company_id
}
if (search.opTitle) {
query.opTitle = search.opTitle
}
// {
// "opTitle": "",// N 操作的业务标题
// "indexName": "sytxpublic-msgq-request",// Y es索引值,同一个项目用一个值
// "identifyCode": "needSubmit",// Y 操作的业务标识
// "messageBody": "",//N 日志的描述信息
// "resultInfo": "",//N 返回信息
// "errorInfo": "",//N 错误信息
// "requestId": "",//请求返回的requestId
// }
console.log("请求--------日志");
console.log(settings.logUrl());
console.log(query);
let rtn = await system.postJsonTypeReq(settings.logUrl(), {
"actionType": "queryLogsData",// Y 功能名称
"actionBody": query
});
if (rtn.statusCode === 200) {
rtn = rtn.data;
if (rtn && rtn.status === 1) {
return rtn.data;
} else {
throw new Error(rtn && rtn.message || '请联系管理员');
}
} else {
throw new Error(rtn)
}
}
}
module.exports = LogClient;
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