Commit 4a85a274 by 宋毅

tj

parent f001b4c8
......@@ -3,6 +3,7 @@ var system = require("../../../system");
class TmTransactionAPI extends WEBBase {
constructor() {
super();
this.pushlogSve = system.getObject("service.common.pushlogSve");
}
/**
* 接口跳转-POST请求
......@@ -14,20 +15,22 @@ class TmTransactionAPI extends WEBBase {
if (!pobj.actionProcess) {
return system.getResult(null, "actionProcess参数不能为空");
}
if (!pobj.action_type) {
if (!pobj.actionType) {
return system.getResult(null, "actionType参数不能为空");
}
var result = await this.opActionProcess(pobj.actionProcess, pobj.actionType, pobj.actionBody, req);
var result = await this.opActionProcess(pobj, pobj.actionType, req);
return result;
}
async opActionProcess(action_process, action_type, action_body, req) {
async opActionProcess(pobj, action_type, req) {
var opResult = null;
switch (action_type) {
// sy
case "test"://测试
opResult = system.getResultSuccess(null, "测试成功");
break;
case "addPushContent"://添加推送信息
opResult = await this.pushlogSve.addPublicServiceLog(pobj, req);
break;
default:
opResult = system.getResult(null, "action_type参数错误");
break;
......
......@@ -39,6 +39,7 @@ class AccessAuthAPI extends APIBase {
if (result.status != 0 || !result.data || result.data.length == 0) {
return system.getResult(null, "push data is empty");
}
var self = this;
for (let index = 0; index < result.data.length; index++) {
const element = result.data[index];
if (element) {
......@@ -46,12 +47,12 @@ class AccessAuthAPI extends APIBase {
contentData.id = element.id;
contentData.pushNumber = element.pushNumber + 1;
if (element.failType == 1) {
this.taskAgainPushOneOldBusInfo(contentData);
self.taskAgainPushOneOldBusInfo(contentData);
}
else if (element.failType == 2) {
this.taskAgainPushOneNewBusInfo(contentData);
self.taskAgainPushOneNewBusInfo(contentData);
} else if (element.failType == 4) {
this.taskAgainFqPushInfo(contentData);
self.taskAgainFqPushInfo(contentData);
}//FQ
}
}
......@@ -59,26 +60,41 @@ class AccessAuthAPI extends APIBase {
}
async taskPushPublicService(pobj, qobj, req) {
// var result = await this.pushlogSve.getFailLogList();
// if (result.status != 0 || !result.data || result.data.length == 0) {
// return system.getResult(null, "push data is empty");
// }
// for (let index = 0; index < result.data.length; index++) {
// const element = result.data[index];
// if (element) {
// var contentData = JSON.parse(element.content);
// contentData.id = element.id;
// contentData.pushNumber = element.pushNumber + 1;
// if (element.failType == 1) {
// this.taskAgainPushOneOldBusInfo(contentData);
// }
// else if (element.failType == 2) {
// this.taskAgainPushOneNewBusInfo(contentData);
// } else if (element.failType == 4) {
// this.taskAgainFqPushInfo(contentData);
// }//FQ
// }
// }
var result = await this.pushlogSve.getPublicServiceLogList();
if (result.status != 0 || !result.data || result.data.length == 0) {
return system.getResult(null, "PushPublicService data is empty");
}
var self = this;
for (let index = 0; index < result.data.length; index++) {
const element = result.data[index];
if (element && element.pushUrl) {
var contentData = JSON.parse(element.pushContent);
var opResult = await self.restPostUrl(contentData, element.pushUrl);
if ((!opResult && opResult.status != 0) || opResult.code != 1) {
var tmpPobj = {
actionBody: {
uapp_key: element.appkey,
pushUrl: element.pushUrl,
pushContent: contentData,
pushNumber: element.pushNumber + 1
}
}
self.pushlogSve.addPublicServiceLog(tmpPobj, { clientIp: element.clientIp });
} else {
self.logCtl.info({
appid: "",
appkey: element.appkey,
requestId: req.requestId || "",
op: req.classname,
content: contentData,
clientIp: element.clientIp,
agent: req.uagent,
optitle: "推送公共服务:PushPublicService Success",
});
}
self.pushlogSve.delPublicServiceLog(element.id);
}
}
return system.getResultSuccess();
}
......
......@@ -184,7 +184,38 @@ class Dao {
var result = this.db.query(sql, tmpParas);
return result;
}
async customInsert(sql, paras, t) {
var tmpParas = null;
if (t && t != 'undefined') {
if (paras == null || paras == 'undefined') {
tmpParas = { type: this.db.QueryTypes.INSERT };
tmpParas.transaction = t;
} else {
tmpParas = { replacements: paras, type: this.db.QueryTypes.INSERT };
tmpParas.transaction = t;
}
} else {
tmpParas = paras == null || paras == 'undefined' || paras.keys == 0 ? { type: this.db.QueryTypes.INSERT } : { replacements: paras, type: this.db.QueryTypes.INSERT };
}
var result = this.db.query(sql, tmpParas);
return result;
}
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' || paras.keys == 0 ? { type: this.db.QueryTypes.DELETE } : { replacements: paras, type: this.db.QueryTypes.DELETE };
}
var result = this.db.query(sql, tmpParas);
return result;
}
async customUpdate(sql, paras, t) {
var tmpParas = null;
if (t && t != 'undefined') {
......
......@@ -50,5 +50,34 @@ class PushlogService extends ServiceBase {
var result = system.getResultSuccess(list);
return result;
}
async addPublicServiceLog(pobj, req) {
var sql = "INSERT INTO `igirl_api`.`center_channel_public_servicelog` (`appkey`,`pushUrl`,`pushContent`,`pushNumber`,`clientIp`,created_at)" +
"VALUES(:appkey,:pushUrl,:pushContent,:pushNumber,:clientIp,:created_at)";
var params = {
appkey: pobj.appInfo ? pobj.appInfo.uapp_key || "" : "",
pushUrl: pobj.actionBody.pushUrl,
pushContent: JSON.stringify(pobj.actionBody.pushContent),
pushNumber: pobj.actionBody.pushNumber || 0,
clientIp: req.clientIp || "",
created_at: new Date()
}
await this.pushfaillogDao.customInsert(sql, params);
return system.getResultSuccess();
}
async delPublicServiceLog(id) {
var sql = "DELETE FROM `center_channel_public_servicelog` WHERE id=:id";
var params = {
id: id
}
await this.pushfaillogDao.customDelete(sql, params);
return system.getResultSuccess();
}
async getPublicServiceLogList() {
var sql = "SELECT id,appkey,`pushUrl`,pushContent,pushNumber,clientIp FROM `center_channel_public_servicelog` WHERE pushNumber<10 LIMIT 200";
var list = await this.pushfaillogDao.customQuery(sql);
var result = system.getResultSuccess(list);
return result;
}
}
module.exports = PushlogService;
......@@ -23,6 +23,7 @@ var settings = {
debug: false,
dialectOptions: {
requestTimeout: 999999,
// timezone: '+8:00'
// instanceName:'DEV'
} //设置MSSQL超时时间
}
......
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