Commit 3a1ab12c by 宋毅

tj

parent f653cfc4
......@@ -33,7 +33,7 @@ class APIBase {
pobj.actionBody.resultInfo = result;
pobj.actionBody.requestId = result.requestId;
pobj.actionBody.opTitle = "reqPath:" + req.path;
if (pobj.actionType && pobj.actionType != "queryLogsData") {
if (pobj.actionType && pobj.actionType != "queryLogsData" && pobj.actionType != "getPushErrorList" && pobj.actionType != "getPushFailureList") {
this.esUtils.addEsLogs(settings.queuedName + "-apireq", pobj.actionBody);
}
}
......
......@@ -7,6 +7,7 @@ class ProducerAPI extends APIBase {
super();
this.utilsProduceSve = system.getObject("service.utilsSve.utilsProduceSve");
this.utilsLogsSve = system.getObject("service.utilsSve.utilsLogsSve");
this.pushFailureLogSve = system.getObject("service.opLogs.pushFailureLogSve");
}
/**
* 接口跳转-POST请求
......@@ -27,7 +28,7 @@ class ProducerAPI extends APIBase {
if (settings.queuedName != "SYTXPUBLIC-MSGQ") {
return system.getResult(null, "请求地址有误!");
}
opResult = await this.utilsProduceSve.produceData(pobj, req);
opResult = await this.utilsProduceSve.produceData(pobj, settings.queuedName, req);
break;
case "produceLogsData":
if (settings.queuedName != "LOGS-SYTXPUBLIC-MSGQ") {
......@@ -38,6 +39,21 @@ class ProducerAPI extends APIBase {
case "queryLogsData":
opResult = await this.utilsLogsSve.getListByIndexName(pobj.actionBody, req);
break;
case "getPushErrorList":
opResult = await this.pushFailureLogSve.getPushErrorList(pobj.actionBody, req);
break;
case "getPushFailureList":
opResult = await this.pushFailureLogSve.getPushFailureList(pobj.actionBody, req);
break;
case "pushAgainFailureLog":
opResult = await this.pushFailureLogSve.getPushAgainFailureLog(pobj.actionBody, req);
if (opResult.status == 1) {
opResult = await this.utilsProduceSve.produceData(opResult.data, "SYTXPUBLIC-MSGQ", req);
if (opResult.status == 1) {
opResult = await this.pushFailureLogSve.delFailureLog(pobj.actionBody, req);
}
}
break;
default:
opResult = system.getResult(null, "actionType参数错误");
break;
......
......@@ -32,6 +32,22 @@ class Dao {
});
}
}
async customDelete(sql, paras, t) {
var tmpParas = null;
if (t && t != 'undefined') {
if (paras == null || paras == 'undefined') {
tmpParas = { type: this.db.QueryTypes.DELETE };
tmpParas.transaction = t;
} else {
tmpParas = { replacements: paras, type: this.db.QueryTypes.DELETE };
tmpParas.transaction = t;
}
} else {
tmpParas = paras == null || paras == 'undefined' ? { type: this.db.QueryTypes.DELETE } : { replacements: paras, type: this.db.QueryTypes.DELETE };
}
return this.db.query(sql, tmpParas);
}
async customQuery(sql, paras, t) {
var tmpParas = null;//||paras=='undefined'?{type: this.db.QueryTypes.SELECT }:{ replacements: paras, type: this.db.QueryTypes.SELECT };
if (t && t != 'undefined') {
......@@ -48,5 +64,26 @@ class Dao {
var result = this.db.query(sql, tmpParas);
return result;
}
async getPageList(pageIndex, pageSize, whereObj = null, orderObj = null, attributesObj = null, includeObj = null) {
var tmpWhere = {};
tmpWhere.limit = pageSize;
tmpWhere.offset = (pageIndex - 1) * pageSize;
if (whereObj != null) {
tmpWhere.where = whereObj;
}
if (orderObj != null && orderObj.length > 0) {
tmpWhere.order = orderObj;
}
if (attributesObj != null && attributesObj.length > 0) {
tmpWhere.attributes = attributesObj;
}
if (includeObj != null && includeObj.length > 0) {
tmpWhere.include = includeObj;
tmpWhere.distinct = true;
}
tmpWhere.raw = true;
return await this.model.findAndCountAll(tmpWhere);
}
}
module.exports = Dao;
......@@ -5,5 +5,127 @@ class PushFailureLogService extends ServiceBase {
constructor() {
super("opLogs", ServiceBase.getDaoName(PushFailureLogService));
}
async getPushErrorList(actionBody, req) {
var pageIndex = actionBody.pageIndex || 1;
var pageSize = actionBody.pageSize || 20;
if (pageSize > 100) {
pageSize = 100;
}
var offset = (pageIndex - 1) * pageSize;
var sqlCount = "select count(1) as dataCount from op_error_log";
var sql = "select id,`queued_name`,`identify_code`,`op_title`,`push_content`, `result_info`,`request_id`,`created_at` from op_error_log";
var params = null;
if (actionBody.messageBody) {
sql = sql + " WHERE push_content like :push_content";
params = { push_content: "%" + actionBody.messageBody + "%" };
}
if (actionBody.identifyCode) {
sql = sql + (params ? " and identify_code like :identify_code" : " WHERE identify_code like :identify_code");
if (params) {
params.identify_code = "%" + actionBody.identifyCode + "%";
} else {
params = { identify_code: "%" + actionBody.identifyCode + "%" };
}
}
if (actionBody.requestIdInfo) {
sql = sql + (params ? " and request_id =:request_id" : " WHERE request_id =:request_id");
if (params) {
params.request_id = actionBody.requestIdInfo;
} else {
params = { request_id: actionBody.requestIdInfo };
}
}
sql = sql + " order by id desc LIMIT " + offset + ", " + pageSize + "; ";
var tmpCountList = await this.customQuery(sqlCount, null);
var tmpList = await this.customQuery(sql, params);
var tmpCount = 0;
if (tmpCountList && tmpCountList.length > 0) {
tmpCount = tmpCountList[0].dataCount;
}
var reslut = system.getResultSuccess(tmpList);
reslut.totalCount = tmpCount;
return reslut;
}
async getPushFailureList(actionBody, req) {
var pageIndex = actionBody.pageIndex || 1;
var pageSize = actionBody.pageSize || 20;
if (pageSize > 100) {
pageSize = 100;
}
var offset = (pageIndex - 1) * pageSize;
var sqlCount = "select count(1) as dataCount from x_push_failure_log";
var sql = "select id,`queued_name`,`identify_code`,`op_title`,`push_content`, `result_info`,`request_id`,`created_at` from x_push_failure_log";
var params = null;
if (actionBody.messageBody) {
sql = sql + " WHERE push_content like :push_content";
params = { push_content: "%" + actionBody.messageBody + "%" };
}
if (actionBody.identifyCode) {
sql = sql + (params ? " and identify_code like :identify_code" : " WHERE identify_code like :identify_code");
if (params) {
params.identify_code = "%" + actionBody.identifyCode + "%";
} else {
params = { identify_code: "%" + actionBody.identifyCode + "%" };
}
}
if (actionBody.requestIdInfo) {
sql = sql + (params ? " and request_id =:request_id" : " WHERE request_id =:request_id");
if (params) {
params.request_id = actionBody.requestIdInfo;
} else {
params = { request_id: actionBody.requestIdInfo };
}
}
sql = sql + " order by id desc LIMIT " + offset + ", " + pageSize + "; ";
var tmpCountList = await this.customQuery(sqlCount, null);
var tmpList = await this.customQuery(sql, params);
var tmpCount = 0;
if (tmpCountList && tmpCountList.length > 0) {
tmpCount = tmpCountList[0].dataCount;
}
var reslut = system.getResultSuccess(tmpList);
reslut.totalCount = tmpCount;
return reslut;
}
async getPushAgainFailureLog(actionBody, req) {
if (!actionBody.id) {
return system.getResult(null, "id can not be empty");
}
var sql = "select id,`queued_name`,`identify_code`,`op_title`,`push_content`, `result_info`,`request_id`,`created_at` from x_push_failure_log where id=:id limit 1";
var params = { id: actionBody.id };
var tmpList = await this.customQuery(sql, params);
var item = null;
if (tmpList && tmpList.length > 0) {
item = tmpList[0];
}
if (!item) {
return system.getResult(null, "data is empty");
}
if (!item.push_content.pushUrl) {
return system.getResult(null, "push_content pushUrl is empty");
}
var resultParam = {
actionBody: {
pushUrl: item.push_content.pushUrl,// Y 推送地址
actionType: item.push_content.actionType,// Y 推送地址接收时的功能名称
notifyUrl: item.push_content.notifyUrl,// N 推送成功后通知的Url
identifyCode: item.push_content.identifyCode,// Y 操作的业务标识
messageBody: item.push_content.messageBody,
headData: null //N 请求头信息,Json格式,如:{token:"XXXXXXX"}
}
}
return system.getResultSuccess(resultParam);
}
async delFailureLog(actionBody, req) {
if (!actionBody.id) {
return system.getResult(null, "id can not be empty");
}
var sql = "DELETE from x_push_failure_log where id=:id";
var params = { id: actionBody.id };
await this.customDelete(sql, params);
return system.getResultSuccess();
}
}
module.exports = PushFailureLogService;
......@@ -9,7 +9,7 @@ class UtilsLogsService extends AppServiceBase {
this.esUtils = system.getObject("util.esUtils");
}
/**
* 公司模糊查询
* 日志模糊查询
* actionBody
* {
* indexName:索引名称,
......
......@@ -7,11 +7,12 @@ class UtilsProduceService extends AppServiceBase {
super();
}
/**
* 接口跳转-POST请求
* action_type 执行的类型
* action_body 执行的参数
*/
async produceData(pobj, req) {
* 接口跳转-POST请求
* @param {*} pobj
* @param {*} queuedName 队列名称
* @param {*} req
*/
async produceData(pobj, queuedName, req) {
if (!pobj.actionBody) {
return system.getResult(null, "actionBody不能为空");
}
......@@ -32,7 +33,8 @@ class UtilsProduceService extends AppServiceBase {
if (msgKeyCount === 0) {
return system.getResult(null, "actionBody.messageBody参数不能为空");
}
await this.redisClient.lpushData(settings.queuedName, pobj.actionBody);
queuedName = queuedName || settings.queuedName;
await this.redisClient.lpushData(queuedName, pobj.actionBody);
return system.getResultSuccess();
}
/**
......
......@@ -27,9 +27,15 @@ class ServiceBase {
async create(qobj) {
return this.dao.create(qobj);
}
async customDelete(sql, paras, t) {
return this.dao.customDelete(sql, paras, t);
}
async customQuery(sql, paras, t) {
return this.dao.customQuery(sql, paras, t);
}
async getPageList(pageIndex, pageSize, whereObj = null, orderObj = null, attributesObj = null, includeObj = null) {
return this.dao.getPageList(pageIndex, pageSize, whereObj, orderObj, attributesObj, includeObj);
}
/*
返回20位业务订单号
prefix:业务前缀
......
......@@ -6,7 +6,7 @@ var settings = {
db: 5,
},
database: {
dbname: "tx-queue-log",
dbname: "brg-tx-queue-log",
user: "write",
password: "write",
config: {
......
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