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 = {
dbConfig.user, max_retries: 10,
dbConfig.password, onRetry: function (count) {
dbConfig.config); console.log("connection lost, trying to reconnect (" + count + ")");
this.db.Sequelize=Sequelize; }
this.db.Op=Sequelize.Op; };
this.db = new Sequelize(dbConfig.dbname,
dbConfig.user,
dbConfig.password,
dbConfig.config);
this.db.Sequelize = Sequelize;
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,
......
{ {
"name": "bigdata", "name": "bigdata",
"version": "1.0.0", "version": "1.0.0",
"description": "h5framework", "description": "h5framework",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {
"dev": "nodemon main.js", "dev": "nodemon main.js",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@alicloud/pop-core": "^1.7.7", "@alicloud/pop-core": "^1.7.7",
"MD5": "^1.3.0", "MD5": "^1.3.0",
"after": "^0.8.2", "after": "^0.8.2",
"ali-oss": "^4.12.2", "ali-oss": "^4.12.2",
"aliyun-api-gateway": "^1.1.6", "aliyun-api-gateway": "^1.1.6",
"axios": "^0.19.2", "axios": "^0.19.2",
"babel-polyfill": "^6.26.0", "babel-polyfill": "^6.26.0",
"base64id": "^1.0.0", "base64id": "^1.0.0",
"bluebird": "^3.5.1", "bluebird": "^3.5.1",
"body-parser": "^1.18.2", "body-parser": "^1.18.2",
"co": "^4.6.0", "co": "^4.6.0",
"connect-redis": "^3.3.3", "connect-redis": "^3.3.3",
"continuation-local-storage": "^3.2.1", "continuation-local-storage": "^3.2.1",
"cookie-parser": "^1.4.3", "cookie-parser": "^1.4.3",
"crypto": "^1.0.1", "crypto": "^1.0.1",
"crypto-js": "^3.1.9-1", "crypto-js": "^3.1.9-1",
"ejs": "^2.5.8", "ejs": "^2.5.8",
"element-ui": "^2.4.0", "element-ui": "^2.4.0",
"engine.io-parser": "^2.1.2", "engine.io-parser": "^2.1.2",
"errorhandler": "^1.5.0", "errorhandler": "^1.5.0",
"exif-js": "^2.3.0", "exif-js": "^2.3.0",
"express": "^4.16.2", "express": "^4.16.2",
"express-session": "^1.15.6", "express-session": "^1.15.6",
"gm": "^1.23.1", "gm": "^1.23.1",
"marked": "^0.7.0", "marked": "^0.7.0",
"method-override": "^2.3.10", "method-override": "^2.3.10",
"morgan": "^1.9.0", "morgan": "^1.9.0",
"multer": "^1.3.0", "multer": "^1.3.0",
"mysql2": "^1.5.3", "mysql2": "^1.5.3",
"node-cron": "^2.0.1", "node-cron": "^2.0.1",
"node-uuid": "^1.4.8", "node-uuid": "^1.4.8",
"node-xlsx": "^0.15.0", "node-xlsx": "^0.15.0",
"nodemailer": "^6.3.0", "nodemailer": "^6.3.0",
"pinyin": "^2.9.0", "pinyin": "^2.9.0",
"puppeteer": "^1.20.0", "puppeteer": "^1.20.0",
"qcloud-cos-sts": "^3.0.2", "qcloud-cos-sts": "^3.0.2",
"qr-image": "^3.2.0", "qr-image": "^3.2.0",
"sequelize": "^4.37.8", "sequelize": "^4.37.8",
"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",
"socket.io": "^2.1.1", "sha256": "^0.2.0",
"uuid": "^3.2.1" "socket.io": "^2.1.1",
}, "uuid": "^3.2.1"
"devDependencies": { },
"element-theme": "^2.0.1", "devDependencies": {
"element-theme-chalk": "^2.4.0" "element-theme": "^2.0.1",
} "element-theme-chalk": "^2.4.0"
} }
}
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