Commit 5c0850bb by 宋毅

tj

parent 5b9aadfd
const system = require("../system"); const system = require("../system");
const moment = require('moment'); const moment = require('moment');
const settings = require("../../../app/config/settings"); const settings = require("../../../app/config/settings");
const sha256 = require('sha256');
class APIBase { class APIBase {
constructor() { constructor() {
...@@ -15,6 +16,8 @@ class APIBase { ...@@ -15,6 +16,8 @@ class APIBase {
if (!pobj.actionBody) { if (!pobj.actionBody) {
pobj.actionBody = {}; pobj.actionBody = {};
} }
var shaStr = await sha256(JSON.stringify(pobj));
this.redisClient.setWithEx(shaStr, 1, 3);
var result = await this[methodname](pobj, query, req); var result = await this[methodname](pobj, query, req);
if (!result) { if (!result) {
result = system.getResult(null, "请求的方法返回值为空"); result = system.getResult(null, "请求的方法返回值为空");
......
...@@ -71,6 +71,7 @@ class ConsumerBase { ...@@ -71,6 +71,7 @@ class ConsumerBase {
return; return;
} }
if (actionBody.counter > 4) { if (actionBody.counter > 4) {
actionBody.pushAgainResultInfo = actionBody.pushAgainResultInfo || actionBody.resultInfo;
await this.pushFailureLogDao.addOpFailureLogs("推送失败", actionBody, actionBody.pushAgainResultInfo); await this.pushFailureLogDao.addOpFailureLogs("推送失败", actionBody, actionBody.pushAgainResultInfo);
return; return;
} }
......
const Sequelize = require('sequelize'); const Sequelize = require('sequelize');
const settings=require("../../../../config/settings") const settings = require("../../../../config/settings")
const fs=require("fs") const fs = require("fs")
const path=require("path"); const path = require("path");
var glob = require("glob"); var glob = require("glob");
class DbFactory{ class DbFactory {
constructor(){ constructor() {
const dbConfig=settings.database(); const dbConfig = settings.database();
this.db=new Sequelize(dbConfig.dbname, dbConfig.reconnect = {
max_retries: 10,
onRetry: function (count) {
console.log("connection lost, trying to reconnect (" + count + ")");
}
};
this.db = new Sequelize(dbConfig.dbname,
dbConfig.user, dbConfig.user,
dbConfig.password, dbConfig.password,
dbConfig.config); dbConfig.config);
this.db.Sequelize=Sequelize; this.db.Sequelize = Sequelize;
this.db.Op=Sequelize.Op; this.db.Op = Sequelize.Op;
this.initModels(); this.initModels();
this.initRelations(); this.initRelations();
} }
async initModels(){ async initModels() {
var self=this; var self = this;
var modelpath=path.normalize(path.join(__dirname, '../..'))+"/models/"; var modelpath = path.normalize(path.join(__dirname, '../..')) + "/models/";
console.log(modelpath); // console.log(modelpath);
var models=glob.sync(modelpath+"/**/*.js"); var models = glob.sync(modelpath + "/**/*.js");
console.log(models.length); // console.log(models.length);
models.forEach(function(m){ models.forEach(function (m) {
self.db.import(m); self.db.import(m);
}); });
console.log("init models...."); console.log("init models....");
} }
async initRelations(){ async initRelations() {
} }
//async getCon(){,用于使用替换table模型内字段数据使用 //async getCon(){,用于使用替换table模型内字段数据使用
getCon(){ getCon() {
var that=this; var that = this;
// await this.db.authenticate().then(()=>{ // await this.db.authenticate().then(()=>{
// console.log('Connection has been established successfully.'); // console.log('Connection has been established successfully.');
// }).catch(err => { // }).catch(err => {
...@@ -39,7 +45,7 @@ class DbFactory{ ...@@ -39,7 +45,7 @@ class DbFactory{
// throw err; // throw err;
// }); // });
//同步模型 //同步模型
if(settings.env=="dev"){ if (settings.env == "dev") {
//console.log(pa); //console.log(pa);
// pconfigObjs.forEach(p=>{ // pconfigObjs.forEach(p=>{
...@@ -56,7 +62,7 @@ class DbFactory{ ...@@ -56,7 +62,7 @@ class DbFactory{
return this.db; return this.db;
} }
} }
module.exports=DbFactory; module.exports = DbFactory;
// const dbf=new DbFactory(); // const dbf=new DbFactory();
// dbf.getCon().then((db)=>{ // dbf.getCon().then((db)=>{
// //console.log(db); // //console.log(db);
......
...@@ -40,15 +40,16 @@ class EsUtils { ...@@ -40,15 +40,16 @@ class EsUtils {
async execPostEs(queuedName, params, esIndexName) { async execPostEs(queuedName, params, esIndexName) {
try { try {
var configInfoResult = await this.configInfoDao.getList(); var configInfoResult = await this.configInfoDao.getList();
configInfoResult.status = -1;
if (configInfoResult.status != 1) { if (configInfoResult.status != 1) {
this.errorLogDao.addOpErrorLogs("publicLogsConsumer,configInfo list is empty", actionBody, null, null, 1); this.errorLogDao.addOpErrorLogs("publicLogsConsumer,configInfo list is empty", params, null, null, 1);
return system.getResultSuccess(); return system.getResultSuccess();
} }
var publicLogsEsName = configInfoResult.data.filter(f => f.c_key === "publicLogsEsName"); var publicLogsEsName = configInfoResult.data.filter(f => f.c_key === "publicLogsEsName");
var publicLogsEsPwd = configInfoResult.data.filter(f => f.c_key === "publicLogsEsPwd"); var publicLogsEsPwd = configInfoResult.data.filter(f => f.c_key === "publicLogsEsPwd");
var publicLogsEsReqUrl = configInfoResult.data.filter(f => f.c_key === "publicLogsEsReqUrl"); var publicLogsEsReqUrl = configInfoResult.data.filter(f => f.c_key === "publicLogsEsReqUrl");
if (!publicLogsEsName || !publicLogsEsPwd || !publicLogsEsReqUrl) { if (!publicLogsEsName || !publicLogsEsPwd || !publicLogsEsReqUrl) {
this.errorLogDao.addOpErrorLogs("publicLogsConsumer,es account info is empty", actionBody, null, null, 1); this.errorLogDao.addOpErrorLogs("publicLogsConsumer,es account info is empty", params, null, null, 1);
return system.getResultSuccess(); return system.getResultSuccess();
} }
var reqUrl = publicLogsEsReqUrl[0].c_value + esIndexName var reqUrl = publicLogsEsReqUrl[0].c_value + esIndexName
......
...@@ -158,6 +158,14 @@ class RedisClient { ...@@ -158,6 +158,14 @@ class RedisClient {
return this.client.getAsync(key); return this.client.getAsync(key);
} }
/** /**
* 判断key是否存在
* @param {*} key key
*/
async exists(key) {
return this.client.existsAsync(key);
}
/**
* 删除缓存 * 删除缓存
* @param {*} key key * @param {*} key key
*/ */
......
...@@ -22,10 +22,10 @@ var settings = { ...@@ -22,10 +22,10 @@ var settings = {
acquire: 90000000, acquire: 90000000,
idle: 1000000 idle: 1000000
}, },
timezone: '+08:00',
debug: false, debug: false,
dialectOptions: { dialectOptions: {
requestTimeout: 999999, requestTimeout: 999999,
// timezone: '+8:00'
// instanceName:'DEV' // instanceName:'DEV'
} //设置MSSQL超时时间 } //设置MSSQL超时时间
} }
......
var url = require("url"); const url = require("url");
var system = require("../../base/system"); const system = require("../../base/system");
const sha256 = require('sha256');
const redisClient = system.getObject("util.redisClient");
module.exports = function (app) { module.exports = function (app) {
//-----------------------新的模式---------api---------开始 //-----------------------新的模式---------api---------开始
...@@ -14,7 +17,14 @@ module.exports = function (app) { ...@@ -14,7 +17,14 @@ module.exports = function (app) {
return; return;
} }
if (!req.body.actionType) { if (!req.body.actionType) {
result.msg = "actionType can not be empty"; result.message = "actionType can not be empty";
res.end(JSON.stringify(result));
return;
}
var shaStr = await sha256(JSON.stringify(req.body));
var existsKey = await redisClient.exists(shaStr);
if (existsKey) {
result.message = "req too often";
res.end(JSON.stringify(result)); res.end(JSON.stringify(result));
return; return;
} }
...@@ -31,7 +41,6 @@ module.exports = function (app) { ...@@ -31,7 +41,6 @@ module.exports = function (app) {
req.clientIp = tClientIp; req.clientIp = tClientIp;
req.uagent = req.headers["user-agent"]; req.uagent = req.headers["user-agent"];
req.classname = classPath; req.classname = classPath;
var params = []; var params = [];
params.push(gname); params.push(gname);
params.push(methodName); params.push(methodName);
......
...@@ -10,8 +10,8 @@ var ENVINPUT = { ...@@ -10,8 +10,8 @@ var ENVINPUT = {
REDIS_DB: process.env.QUEUE_REDIS_DB, REDIS_DB: process.env.QUEUE_REDIS_DB,
DB_NAME: process.env.QUEUE_DB_NAME, DB_NAME: process.env.QUEUE_DB_NAME,
APP_ENV: process.env.APP_ENV ? process.env.APP_ENV : "dev",//运行环境 APP_ENV: process.env.APP_ENV ? process.env.APP_ENV : "dev",//运行环境
CONSUMER_NAME: process.env.CONSUMER_NAME || "publicServiceAllocation.publicConsumer",//消费者名称 CONSUMER_NAME: process.env.CONSUMER_NAME || "publicLogs.publicLogsConsumer",//消费者名称
QUEUED_NAME: process.env.QUEUED_NAME || "SYTXPUBLIC-MSGQ",//队列名称,FAIL-失败队列(队列和失败队列一对存在进行部署) QUEUED_NAME: process.env.QUEUED_NAME || "LOGS-SYTXPUBLIC-MSGQ",//队列名称,FAIL-失败队列(队列和失败队列一对存在进行部署)
}; };
var settings = { var settings = {
env: ENVINPUT.APP_ENV, env: ENVINPUT.APP_ENV,
......
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
"sequelize-cli": "^4.1.1", "sequelize-cli": "^4.1.1",
"serve-favicon": "^2.4.5", "serve-favicon": "^2.4.5",
"sha1": "^1.1.1", "sha1": "^1.1.1",
"sha256": "^0.2.0",
"socket.io": "^2.1.1", "socket.io": "^2.1.1",
"uuid": "^3.2.1" "uuid": "^3.2.1"
}, },
......
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