Commit 4c01a502 by 宋毅

tj

parent 7c6241eb
......@@ -24,17 +24,17 @@ class APIBase {
pobj.actionBody.resultInfo = result;
pobj.actionBody.requestId = result.requestId;
pobj.actionBody.opTitle = "reqPath:" + req.path;
this.esUtils.addEsLogs(settings.queuedName + "api-req", pobj.actionBody);
this.esUtils.addEsLogs(settings.queuedName + "api-req", pobj);
}
return result;
} catch (e) {
var stackStr = e.stack ? e.stack : JSON.stringify(e);
console.log(stackStr, "api.base调用出现异常,请联系管理员..........");
} catch (error) {
var stackStr = error.stack ? error.stack : JSON.stringify(error);
// console.log(stackStr, "api.base调用出现异常,请联系管理员..........");
var rtnerror = system.getResultFail(-200, "出现异常,error:" + stackStr);
pobj.actionBody.requestId = await this.getBusUid("err");
pobj.actionBody.errorInfo = stackStr;
pobj.actionBody.opTitle = ",reqPath:" + req.path;
this.esUtils.addEsLogs(settings.queuedName + "apidoexec-error", pobj.actionBody);
this.esUtils.addEsLogs(settings.queuedName + "apidoexec-error", pobj);
return rtnerror;
}
}
......
const ConsumerBase = require("../../consumer.base");
const system = require("../../../system");
const moment = require('moment');
class PublicFailConsumer extends ConsumerBase {
constructor() {
super(ConsumerBase.getServiceName(PublicFailConsumer));
}
async subBeforeConsumer(queuedName, actionBody) {
console.log("前置操作......", this.serviceName);
}
async subDoConsumer(queuedName, actionBody) {
actionBody.counter = actionBody.counter + 1;
var exTime = actionBody.counter * 20;
var mathStr = await this.getUidInfo(3, 10);
var scoreValue = Number(moment().format("YYYYMMDDHHmmssSSS") + mathStr);
await this.redisClient.init(scoreValue);
await this.redisClient.setDelayEventData(queuedName, scoreValue, exTime);
await this.redisClient.zaddSortedSet(queuedName, scoreValue, actionBody);
return system.getResultSuccess();
}
}
const ConsumerBase = require("../../consumer.base");
const system = require("../../../system");
const moment = require('moment');
class PublicFailConsumer extends ConsumerBase {
constructor() {
super(ConsumerBase.getServiceName(PublicFailConsumer));
}
async subBeforeConsumer(queuedName, actionBody) {
console.log("前置操作......", this.serviceName);
}
async subDoConsumer(queuedName, actionBody) {
actionBody.counter = actionBody.counter + 1;
var exTime = actionBody.counter * 20;
var mathStr = await this.getUidInfo(3, 10);
var scoreValue = Number(moment().format("YYYYMMDDHHmmssSSS") + mathStr);
await this.redisClient.init(scoreValue);
await this.redisClient.setDelayEventData(queuedName, scoreValue, exTime);
await this.redisClient.zaddSortedSet(queuedName, scoreValue, actionBody);
return system.getResultSuccess();
}
}
module.exports = PublicFailConsumer;
\ No newline at end of file
const ConsumerBase = require("../../consumer.base");
const system = require("../../../system");
class PublicLogsConsumer extends ConsumerBase {
constructor() {
super(ConsumerBase.getServiceName(PublicLogsConsumer));
this.configInfoDao = system.getObject("db.opLogs.configInfoDao");
this.errorLogDao = system.getObject("db.opLogs.errorLogDao");
this.esUtils = system.getObject("util.esUtils");
}
async subBeforeConsumer(queuedName, actionBody) {
console.log("前置操作......", this.serviceName);
}
async subDoConsumer(queuedName, actionBody) {
var params = {
opTitle: actionBody.opTitle,
identifyCode: actionBody.identifyCode,
messageBody: actionBody.messageBody,
requestId: actionBody.requestId
}
var execResult = await this.esUtils.addEsLogs(queuedName, actionBody);;
return execResult;
}
}
const ConsumerBase = require("../../consumer.base");
const system = require("../../../system");
class PublicLogsConsumer extends ConsumerBase {
constructor() {
super(ConsumerBase.getServiceName(PublicLogsConsumer));
this.configInfoDao = system.getObject("db.opLogs.configInfoDao");
this.errorLogDao = system.getObject("db.opLogs.errorLogDao");
this.esUtils = system.getObject("util.esUtils");
}
async subBeforeConsumer(queuedName, actionBody) {
console.log("前置操作......", this.serviceName);
}
async subDoConsumer(queuedName, actionBody) {
var params = {
opTitle: actionBody.opTitle,
identifyCode: actionBody.identifyCode,
messageBody: actionBody.messageBody,
requestId: actionBody.requestId
}
var execResult = await this.esUtils.addEsLogs(queuedName, actionBody);;
return execResult;
}
}
module.exports = PublicLogsConsumer;
\ No newline at end of file
const ConsumerBase = require("../../consumer.base");
class PublicNotifyConsumer extends ConsumerBase {
constructor() {
super(ConsumerBase.getServiceName(PublicNotifyConsumer));
}
async subBeforeConsumer(queuedName, actionBody) {
console.log("前置操作......", this.serviceName);
}
async subDoConsumer(queuedName, actionBody) {
var params = {
actionType: actionBody.actionType,
identifyCode: actionBody.identifyCode,
actionBody: {
messageBody: actionBody.messageBody,
resultInfo: actionBody.resultInfo
},
requestId: actionBody.requestId
}
var execResult = await this.execPostByTimeOut(params, actionBody.notifyUrl);
return execResult;
}
}
const ConsumerBase = require("../../consumer.base");
class PublicNotifyConsumer extends ConsumerBase {
constructor() {
super(ConsumerBase.getServiceName(PublicNotifyConsumer));
}
async subBeforeConsumer(queuedName, actionBody) {
console.log("前置操作......", this.serviceName);
}
async subDoConsumer(queuedName, actionBody) {
var params = {
actionType: actionBody.actionType,
identifyCode: actionBody.identifyCode,
actionBody: {
messageBody: actionBody.messageBody,
resultInfo: actionBody.resultInfo
},
requestId: actionBody.requestId
}
var execResult = await this.execPostByTimeOut(params, actionBody.notifyUrl);
return execResult;
}
}
module.exports = PublicNotifyConsumer;
\ No newline at end of file
const ConsumerBase = require("../../consumer.base");
class PublicConsumer extends ConsumerBase {
constructor() {
super(ConsumerBase.getServiceName(PublicConsumer));
}
async subBeforeConsumer(queuedName, actionBody) {
console.log("前置操作......", this.serviceName);
}
async subDoConsumer(queuedName, actionBody) {
var params = {
actionType: actionBody.actionType,
identifyCode: actionBody.identifyCode,
actionBody: actionBody.messageBody,
requestId: actionBody.requestId
}
var execResult = await this.execPostByTimeOut(params, actionBody.pushUrl);
return execResult;
}
}
const ConsumerBase = require("../../consumer.base");
class PublicConsumer extends ConsumerBase {
constructor() {
super(ConsumerBase.getServiceName(PublicConsumer));
}
async subBeforeConsumer(queuedName, actionBody) {
console.log("前置操作......", this.serviceName);
}
async subDoConsumer(queuedName, actionBody) {
var params = {
actionType: actionBody.actionType,
identifyCode: actionBody.identifyCode,
actionBody: actionBody.messageBody,
requestId: actionBody.requestId
}
var execResult = await this.execPostByTimeOut(params, actionBody.pushUrl);
return execResult;
}
}
module.exports = PublicConsumer;
\ No newline at end of file
const system = require("../system");
class Dao {
constructor(modelName) {
this.modelName = modelName;
var db = system.getObject("db.common.connection").getCon();
this.db = db;
this.model = db.models[this.modelName];
}
static getModelName(ClassObj) {
var nameStr = ClassObj["name"].substring(0, ClassObj["name"].lastIndexOf("Dao"));
var initialStr = nameStr.substring(0, 1);
var resultStr = initialStr.toLowerCase() + nameStr.substring(1, nameStr.length);
return resultStr;
}
preCreate(u) {
return u;
}
/**
*
* @param {*} u 对象
* @param {*} t 事务对象t
*/
async create(u, t) {
var u2 = this.preCreate(u);
if (t) {
return this.model.create(u2, { transaction: t }).then(u => {
return u;
});
} else {
return this.model.create(u2, { transaction: t }).then(u => {
return u;
});
}
}
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') {
if (paras == null || paras == 'undefined') {
tmpParas = { type: this.db.QueryTypes.SELECT };
tmpParas.transaction = t;
} else {
tmpParas = { replacements: paras, type: this.db.QueryTypes.SELECT };
tmpParas.transaction = t;
}
} else {
tmpParas = paras == null || paras == 'undefined' || paras.keys == 0 ? { type: this.db.QueryTypes.SELECT } : { replacements: paras, type: this.db.QueryTypes.SELECT };
}
var result = this.db.query(sql, tmpParas);
return result;
}
}
module.exports = Dao;
const system = require("../system");
class Dao {
constructor(modelName) {
this.modelName = modelName;
var db = system.getObject("db.common.connection").getCon();
this.db = db;
this.model = db.models[this.modelName];
}
static getModelName(ClassObj) {
var nameStr = ClassObj["name"].substring(0, ClassObj["name"].lastIndexOf("Dao"));
var initialStr = nameStr.substring(0, 1);
var resultStr = initialStr.toLowerCase() + nameStr.substring(1, nameStr.length);
return resultStr;
}
preCreate(u) {
return u;
}
/**
*
* @param {*} u 对象
* @param {*} t 事务对象t
*/
async create(u, t) {
var u2 = this.preCreate(u);
if (t) {
return this.model.create(u2, { transaction: t }).then(u => {
return u;
});
} else {
return this.model.create(u2, { transaction: t }).then(u => {
return u;
});
}
}
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') {
if (paras == null || paras == 'undefined') {
tmpParas = { type: this.db.QueryTypes.SELECT };
tmpParas.transaction = t;
} else {
tmpParas = { replacements: paras, type: this.db.QueryTypes.SELECT };
tmpParas.transaction = t;
}
} else {
tmpParas = paras == null || paras == 'undefined' || paras.keys == 0 ? { type: this.db.QueryTypes.SELECT } : { replacements: paras, type: this.db.QueryTypes.SELECT };
}
var result = this.db.query(sql, tmpParas);
return result;
}
}
module.exports = Dao;
const Sequelize = require('sequelize');
const settings=require("../../../../config/settings")
const fs=require("fs")
const path=require("path");
var glob = require("glob");
class DbFactory{
constructor(){
const dbConfig=settings.database();
this.db=new Sequelize(dbConfig.dbname,
dbConfig.user,
dbConfig.password,
dbConfig.config);
this.db.Sequelize=Sequelize;
this.db.Op=Sequelize.Op;
this.initModels();
this.initRelations();
}
async initModels(){
var self=this;
var modelpath=path.normalize(path.join(__dirname, '../..'))+"/models/";
console.log(modelpath);
var models=glob.sync(modelpath+"/**/*.js");
console.log(models.length);
models.forEach(function(m){
self.db.import(m);
});
console.log("init models....");
}
async initRelations(){
}
//async getCon(){,用于使用替换table模型内字段数据使用
getCon(){
var that=this;
// await this.db.authenticate().then(()=>{
// console.log('Connection has been established successfully.');
// }).catch(err => {
// console.error('Unable to connect to the database:', err);
// throw err;
// });
//同步模型
if(settings.env=="dev"){
//console.log(pa);
// pconfigObjs.forEach(p=>{
// console.log(p.get({plain:true}));
// });
// await this.db.models.user.create({nickName:"dev","description":"test user",openId:"testopenid",unionId:"testunionid"})
// .then(function(user){
// var acc=that.db.models.account.build({unionId:"testunionid",nickName:"dev"});
// acc.save().then(a=>{
// user.setAccount(a);
// });
// });
}
return this.db;
}
}
module.exports=DbFactory;
// const dbf=new DbFactory();
// dbf.getCon().then((db)=>{
// //console.log(db);
// // db.models.user.create({nickName:"jy","description":"cccc",openId:"xxyy",unionId:"zz"})
// // .then(function(user){
// // var acc=db.models.account.build({unionId:"zz",nickName:"jy"});
// // acc.save().then(a=>{
// // user.setAccount(a);
// // });
// // console.log(user);
// // });
// // db.models.user.findAll().then(function(rs){
// // console.log("xxxxyyyyyyyyyyyyyyyyy");
// // console.log(rs);
// // })
// });
// const User = db.define('user', {
// firstName: {
// type: Sequelize.STRING
// },
// lastName: {
// type: Sequelize.STRING
// }
// });
// db
// .authenticate()
// .then(() => {
// console.log('Co+nnection has been established successfully.');
//
// User.sync(/*{force: true}*/).then(() => {
// // Table created
// return User.create({
// firstName: 'John',
// lastName: 'Hancock'
// });
// });
//
// })
// .catch(err => {
// console.error('Unable to connect to the database:', err);
// });
//
// User.findAll().then((rows)=>{
// console.log(rows[0].firstName);
// });
const Sequelize = require('sequelize');
const settings=require("../../../../config/settings")
const fs=require("fs")
const path=require("path");
var glob = require("glob");
class DbFactory{
constructor(){
const dbConfig=settings.database();
this.db=new Sequelize(dbConfig.dbname,
dbConfig.user,
dbConfig.password,
dbConfig.config);
this.db.Sequelize=Sequelize;
this.db.Op=Sequelize.Op;
this.initModels();
this.initRelations();
}
async initModels(){
var self=this;
var modelpath=path.normalize(path.join(__dirname, '../..'))+"/models/";
console.log(modelpath);
var models=glob.sync(modelpath+"/**/*.js");
console.log(models.length);
models.forEach(function(m){
self.db.import(m);
});
console.log("init models....");
}
async initRelations(){
}
//async getCon(){,用于使用替换table模型内字段数据使用
getCon(){
var that=this;
// await this.db.authenticate().then(()=>{
// console.log('Connection has been established successfully.');
// }).catch(err => {
// console.error('Unable to connect to the database:', err);
// throw err;
// });
//同步模型
if(settings.env=="dev"){
//console.log(pa);
// pconfigObjs.forEach(p=>{
// console.log(p.get({plain:true}));
// });
// await this.db.models.user.create({nickName:"dev","description":"test user",openId:"testopenid",unionId:"testunionid"})
// .then(function(user){
// var acc=that.db.models.account.build({unionId:"testunionid",nickName:"dev"});
// acc.save().then(a=>{
// user.setAccount(a);
// });
// });
}
return this.db;
}
}
module.exports=DbFactory;
// const dbf=new DbFactory();
// dbf.getCon().then((db)=>{
// //console.log(db);
// // db.models.user.create({nickName:"jy","description":"cccc",openId:"xxyy",unionId:"zz"})
// // .then(function(user){
// // var acc=db.models.account.build({unionId:"zz",nickName:"jy"});
// // acc.save().then(a=>{
// // user.setAccount(a);
// // });
// // console.log(user);
// // });
// // db.models.user.findAll().then(function(rs){
// // console.log("xxxxyyyyyyyyyyyyyyyyy");
// // console.log(rs);
// // })
// });
// const User = db.define('user', {
// firstName: {
// type: Sequelize.STRING
// },
// lastName: {
// type: Sequelize.STRING
// }
// });
// db
// .authenticate()
// .then(() => {
// console.log('Co+nnection has been established successfully.');
//
// User.sync(/*{force: true}*/).then(() => {
// // Table created
// return User.create({
// firstName: 'John',
// lastName: 'Hancock'
// });
// });
//
// })
// .catch(err => {
// console.error('Unable to connect to the database:', err);
// });
//
// User.findAll().then((rows)=>{
// console.log(rows[0].firstName);
// });
const system = require("../../../system");
const settings = require("../../../../config/settings");
const AppServiceBase = require("../../app.base");
//用户权限操作
class UtilsProduceService extends AppServiceBase {
constructor() {
super();
}
/**
* 接口跳转-POST请求
* action_type 执行的类型
* action_body 执行的参数
*/
async produceData(pobj, req) {
if (!pobj.actionBody) {
return system.getResult(null, "actionBody不能为空");
}
var keyCount = Object.keys(pobj.actionBody).length;
if (keyCount === 0) {
return system.getResult(null, "actionBody参数不能为空");
}
if (!pobj.actionBody.pushUrl) {
return system.getResult(null, "actionBody.pushUrl参数不能为空");
}
if (!pobj.actionBody.identifyCode) {
return system.getResult(null, "actionBody.identifyCode参数不能为空");
}
if (!pobj.actionBody.messageBody) {
return system.getResult(null, "actionBody.messageBody不能为空");
}
var msgKeyCount = Object.keys(pobj.actionBody.messageBody).length;
if (msgKeyCount === 0) {
return system.getResult(null, "actionBody.messageBody参数不能为空");
}
await this.redisClient.lpushData(settings.queuedName, pobj.actionBody);
return system.getResultSuccess();
}
/**
* 接口跳转-POST请求
* action_type 执行的类型
* action_body 执行的参数
*/
async produceLogsData(pobj, req) {
if (!pobj.actionBody) {
return system.getResult(null, "actionBody不能为空");
}
var keyCount = Object.keys(pobj.actionBody).length;
if (keyCount === 0) {
return system.getResult(null, "actionBody参数不能为空");
}
if (!pobj.actionBody.identifyCode) {
return system.getResult(null, "actionBody.identifyCode参数不能为空");
}
if (!pobj.actionBody.messageBody) {
return system.getResult(null, "actionBody.messageBody不能为空");
}
var msgKeyCount = Object.keys(pobj.actionBody.messageBody).length;
if (msgKeyCount === 0) {
return system.getResult(null, "actionBody.messageBody参数不能为空");
}
await this.redisClient.lpushData(settings.queuedName, pobj.actionBody);
return system.getResultSuccess();
}
}
module.exports = UtilsProduceService;
const system = require("../../../system");
const settings = require("../../../../config/settings");
const AppServiceBase = require("../../app.base");
//用户权限操作
class UtilsProduceService extends AppServiceBase {
constructor() {
super();
}
/**
* 接口跳转-POST请求
* action_type 执行的类型
* action_body 执行的参数
*/
async produceData(pobj, req) {
if (!pobj.actionBody) {
return system.getResult(null, "actionBody不能为空");
}
var keyCount = Object.keys(pobj.actionBody).length;
if (keyCount === 0) {
return system.getResult(null, "actionBody参数不能为空");
}
if (!pobj.actionBody.pushUrl) {
return system.getResult(null, "actionBody.pushUrl参数不能为空");
}
if (!pobj.actionBody.identifyCode) {
return system.getResult(null, "actionBody.identifyCode参数不能为空");
}
if (!pobj.actionBody.messageBody) {
return system.getResult(null, "actionBody.messageBody不能为空");
}
var msgKeyCount = Object.keys(pobj.actionBody.messageBody).length;
if (msgKeyCount === 0) {
return system.getResult(null, "actionBody.messageBody参数不能为空");
}
await this.redisClient.lpushData(settings.queuedName, pobj.actionBody);
return system.getResultSuccess();
}
/**
* 接口跳转-POST请求
* action_type 执行的类型
* action_body 执行的参数
*/
async produceLogsData(pobj, req) {
if (!pobj.actionBody) {
return system.getResult(null, "actionBody不能为空");
}
var keyCount = Object.keys(pobj.actionBody).length;
if (keyCount === 0) {
return system.getResult(null, "actionBody参数不能为空");
}
if (!pobj.actionBody.identifyCode) {
return system.getResult(null, "actionBody.identifyCode参数不能为空");
}
if (!pobj.actionBody.messageBody) {
return system.getResult(null, "actionBody.messageBody不能为空");
}
var msgKeyCount = Object.keys(pobj.actionBody.messageBody).length;
if (msgKeyCount === 0) {
return system.getResult(null, "actionBody.messageBody参数不能为空");
}
await this.redisClient.lpushData(settings.queuedName, pobj.actionBody);
return system.getResultSuccess();
}
}
module.exports = UtilsProduceService;
const system = require("../../../system");
const AppServiceBase = require("../../app.base");
const { TXCOSCONFIG } = require("../../../../config/platform");
const COSSTS = require('qcloud-cos-sts');
//用户权限操作
class UtilsTxCosService extends AppServiceBase {
constructor() {
super();
this.configInfoDao = system.getObject("db.opLogs.configInfoDao");
}
/**
* 接口跳转-POST请求
* action_type 执行的类型
* action_body 执行的参数
*/
async getCosInfo() {
var result = null;
if (TXCOSCONFIG.allowPrefix === '_ALLOW_DIR_/*') {
result = system.getResult(null, "请修改 allowPrefix 配置项,指定允许上传的路径前缀");
return result;
}
var configInfoResult = await this.configInfoDao.getList();
if (configInfoResult.status != 1) {
result = system.getResult(null, "db-configInfo list is empty");
return result;
}
var cosSecretId = configInfoResult.data.filter(f => f.c_key === "cosSecretId");
var cosSecretKey = configInfoResult.data.filter(f => f.c_key === "cosSecretKey");
var cosBucket = configInfoResult.data.filter(f => f.c_key === "cosBucket");
var cosRegion = configInfoResult.data.filter(f => f.c_key === "cosRegion");
var cosProxy = configInfoResult.data.filter(f => f.c_key === "cosProxy");
if (!cosSecretId || !cosSecretKey || !cosBucket || !cosRegion) {
result = system.getResult(null, "db-configInfo,cos info is empty");
return result;
}
// 获取临时密钥
var LongBucketName = cosBucket[0].c_value;
var ShortBucketName = LongBucketName.substr(0, LongBucketName.lastIndexOf('-'));
var AppId = LongBucketName.substr(LongBucketName.lastIndexOf('-') + 1);
var policy = {
'version': '2.0',
'statement': [{
'action': TXCOSCONFIG.allowActions,
'effect': 'allow',
'resource': [
'qcs::cos:' + cosRegion[0].c_value + ':uid/' + AppId + ':prefix//' + AppId + '/' + ShortBucketName + '/' + TXCOSCONFIG.allowPrefix,
],
}],
};
var options = {
secretId: cosSecretId[0].c_value,
secretKey: cosSecretKey[0].c_value,
proxy: cosProxy ? cosProxy[0].c_value || "" : "",
region: cosRegion[0].c_value,
durationSeconds: TXCOSCONFIG.durationSeconds,
policy: policy,
};
console.log(options, "...getCosInfo.....options");
var getParam = await new Promise(function (resv, rej) {
COSSTS.getCredential(options, function (err, tempKeys) {
if (err) {
rej(err);
} else {
if (tempKeys.credentials) {
tempKeys.credentials.tmpBucket = cosBucket[0].c_value;
tempKeys.credentials.tmpRegion = cosRegion[0].c_value;
}
resv(tempKeys);
}
});
});
result = getParam ? system.getResultSuccess(getParam) : system.getResult(null, "获取cos信息失败");
return result;
}
}
module.exports = UtilsTxCosService;
const system = require("../../../system");
const AppServiceBase = require("../../app.base");
const { TXCOSCONFIG } = require("../../../../config/platform");
const COSSTS = require('qcloud-cos-sts');
//用户权限操作
class UtilsTxCosService extends AppServiceBase {
constructor() {
super();
this.configInfoDao = system.getObject("db.opLogs.configInfoDao");
}
/**
* 接口跳转-POST请求
* action_type 执行的类型
* action_body 执行的参数
*/
async getCosInfo() {
var result = null;
if (TXCOSCONFIG.allowPrefix === '_ALLOW_DIR_/*') {
result = system.getResult(null, "请修改 allowPrefix 配置项,指定允许上传的路径前缀");
return result;
}
var configInfoResult = await this.configInfoDao.getList();
if (configInfoResult.status != 1) {
result = system.getResult(null, "db-configInfo list is empty");
return result;
}
var cosSecretId = configInfoResult.data.filter(f => f.c_key === "cosSecretId");
var cosSecretKey = configInfoResult.data.filter(f => f.c_key === "cosSecretKey");
var cosBucket = configInfoResult.data.filter(f => f.c_key === "cosBucket");
var cosRegion = configInfoResult.data.filter(f => f.c_key === "cosRegion");
var cosProxy = configInfoResult.data.filter(f => f.c_key === "cosProxy");
if (!cosSecretId || !cosSecretKey || !cosBucket || !cosRegion) {
result = system.getResult(null, "db-configInfo,cos info is empty");
return result;
}
// 获取临时密钥
var LongBucketName = cosBucket[0].c_value;
var ShortBucketName = LongBucketName.substr(0, LongBucketName.lastIndexOf('-'));
var AppId = LongBucketName.substr(LongBucketName.lastIndexOf('-') + 1);
var policy = {
'version': '2.0',
'statement': [{
'action': TXCOSCONFIG.allowActions,
'effect': 'allow',
'resource': [
'qcs::cos:' + cosRegion[0].c_value + ':uid/' + AppId + ':prefix//' + AppId + '/' + ShortBucketName + '/' + TXCOSCONFIG.allowPrefix,
],
}],
};
var options = {
secretId: cosSecretId[0].c_value,
secretKey: cosSecretKey[0].c_value,
proxy: cosProxy ? cosProxy[0].c_value || "" : "",
region: cosRegion[0].c_value,
durationSeconds: TXCOSCONFIG.durationSeconds,
policy: policy,
};
console.log(options, "...getCosInfo.....options");
var getParam = await new Promise(function (resv, rej) {
COSSTS.getCredential(options, function (err, tempKeys) {
if (err) {
rej(err);
} else {
if (tempKeys.credentials) {
tempKeys.credentials.tmpBucket = cosBucket[0].c_value;
tempKeys.credentials.tmpRegion = cosRegion[0].c_value;
}
resv(tempKeys);
}
});
});
result = getParam ? system.getResultSuccess(getParam) : system.getResult(null, "获取cos信息失败");
return result;
}
}
module.exports = UtilsTxCosService;
......@@ -85,8 +85,9 @@ class EsUtils {
}
return system.getResultSuccess(stdoutInfo);
} catch (error) {
console.log(error.stack, "......execPostEs....error.....");
this.errorLogDao.addOpErrorLogs(queuedName + "执行execPostEs存在异常", params, null, error.stack, 3);
var stackStr = error.stack ? error.stack : JSON.stringify(error);
console.log(stackStr, "......execPostEs....error.....");
this.errorLogDao.addOpErrorLogs(queuedName + "执行execPostEs存在异常", params, null, stackStr, 3);
}
}
}
......
......@@ -61,7 +61,8 @@ class ExecClient {
var result = JSON.parse(rtn.stdout);
return result;
} catch (error) {
this.errorLogDao.addOpErrorLogs(execFile + "执行execPostByTimeOut存在异常", params, rtn.stdout, error.stack, 3);
var stackStr = error.stack ? error.stack : JSON.stringify(error);
this.errorLogDao.addOpErrorLogs(execFile + "执行execPostByTimeOut存在异常", params, rtn ? rtn.stdout : null, stackStr, 3);
return system.getResultFail(-200, execFile + "执行execPostByTimeOut存在异常");
}
}
......
......@@ -42,8 +42,9 @@ class RedisClient {
await self.zremRangebyscoreData(opResult[0], opResult[1], opResult[1]);
}
} catch (error) {
var stackStr = error.stack ? error.stack : JSON.stringify(error);
//TODO:日志处理
console.log(error.stack, ".....message......................error...........");
console.log(stackStr, ".....message......................error...........");
}
});
......
var express = require('express');
var path = require('path');
var methodOverride = require('method-override');
// var cookierParser = require('cookie-parser');
// var session = require('express-session');
// var RedisStore = require('connect-redis')(session);
var bodyParser = require('body-parser');
// var multer = require('multer');
var errorHandler = require('errorhandler');
var settings = require('./settings');
var system = require('../base/system');
var routes = require('./routes');
// const logCtl = system.getObject("service.common.oplogSve");
// const clientRedis = system.getObject("util.redisClient").client;
//const tm=system.getObject("db.taskManager");
module.exports = function (app) {
app.set('port', settings.port);
app.use(methodOverride());
// app.use(cookierParser());
app.use(bodyParser.json({ limit: '50mb' }));
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
routes(app);//初始化路由
app.use(express.static(path.join(settings.basepath, '/app/front/entry/public')));
app.all('*', function (req, res, next) {
req.objs = system;
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
//跨域允许的请求方式
res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
res.header('Access-Control-Allow-Credentials', 'true');
if (req.method.toLowerCase() == 'options') {
res.send(200); //让options请求快速返回/
}
else {
next();
}
});
// if (settings.env == "dev") {
// app.use(session(
// {
// name: 'devdemosid',
// cookie: { maxAge: 3600000 },
// rolling: true,
// resave: false,
// saveUninitialized: false,
// secret: 'uwotm8',
// store: new RedisStore({
// client: clientRedis,
// }),
// }));
// } else {
// app.use(session(
// {
// name: 'demosid',
// cookie: { maxAge: 3600000 },
// rolling: true,
// resave: false,
// saveUninitialized: false,
// secret: 'uwotm8',
// store: new RedisStore({
// client: clientRedis,
// }),
// }));
// }
// development only
if ('development' == app.get('env')) {
app.use(errorHandler());
} else {
app.use(function (err, req, res) {
console.log("prod error handler...........................................");
console.log(err);
logCtl.error({
optitle: "environment 调用异常error:",
op: req.url,
content: e.toString(),
clientIp: system.get_client_ip(req),
agent: req.headers["user-agent"],
});
//logerApp.error("prod error handler",err);
res.send("link index");
});
}
};
var express = require('express');
var path = require('path');
var methodOverride = require('method-override');
// var cookierParser = require('cookie-parser');
// var session = require('express-session');
// var RedisStore = require('connect-redis')(session);
var bodyParser = require('body-parser');
// var multer = require('multer');
var errorHandler = require('errorhandler');
var settings = require('./settings');
var system = require('../base/system');
var routes = require('./routes');
// const logCtl = system.getObject("service.common.oplogSve");
// const clientRedis = system.getObject("util.redisClient").client;
//const tm=system.getObject("db.taskManager");
module.exports = function (app) {
app.set('port', settings.port);
app.use(methodOverride());
// app.use(cookierParser());
app.use(bodyParser.json({ limit: '50mb' }));
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
routes(app);//初始化路由
app.use(express.static(path.join(settings.basepath, '/app/front/entry/public')));
app.all('*', function (req, res, next) {
req.objs = system;
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
//跨域允许的请求方式
res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
res.header('Access-Control-Allow-Credentials', 'true');
if (req.method.toLowerCase() == 'options') {
res.send(200); //让options请求快速返回/
}
else {
next();
}
});
// if (settings.env == "dev") {
// app.use(session(
// {
// name: 'devdemosid',
// cookie: { maxAge: 3600000 },
// rolling: true,
// resave: false,
// saveUninitialized: false,
// secret: 'uwotm8',
// store: new RedisStore({
// client: clientRedis,
// }),
// }));
// } else {
// app.use(session(
// {
// name: 'demosid',
// cookie: { maxAge: 3600000 },
// rolling: true,
// resave: false,
// saveUninitialized: false,
// secret: 'uwotm8',
// store: new RedisStore({
// client: clientRedis,
// }),
// }));
// }
// development only
if ('development' == app.get('env')) {
app.use(errorHandler());
} else {
app.use(function (err, req, res) {
console.log("prod error handler...........................................");
console.log(err);
logCtl.error({
optitle: "environment 调用异常error:",
op: req.url,
content: e.toString(),
clientIp: system.get_client_ip(req),
agent: req.headers["user-agent"],
});
//logerApp.error("prod error handler",err);
res.send("link index");
});
}
};
var settings = {
redis: {
// host: "121.36.3.35",
// port: 6379,
host: "43.247.184.32",
port: 8967,
password: "Gongsibao2018",
db: 2,
},
database: {
dbname: "tx-queue-log",
user: "write",
password: "write",
config: {
host: '43.247.184.35',
port: 8899,
dialect: 'mysql',
operatorsAliases: false,
pool: {
max: 5,
min: 0,
acquire: 90000000,
idle: 1000000
},
debug: false,
dialectOptions: {
requestTimeout: 999999,
// timezone: '+8:00'
// instanceName:'DEV'
} //设置MSSQL超时时间
}
},
reqEsDevUrl: "http://192.168.4.249:9200/",
reqHomePageDevUrl: "http://zcchannel.apps.com:4003/",
reqAuthUrl: "http://sj.app.com:4002/auth"
};
module.exports = settings;
var settings = {
redis: {
// host: "121.36.3.35",
// port: 6379,
host: "43.247.184.32",
port: 8967,
password: "Gongsibao2018",
db: 1,
},
database: {
dbname: "tx-queue-log",
user: "write",
password: "write",
config: {
host: '43.247.184.35',
port: 8899,
dialect: 'mysql',
operatorsAliases: false,
pool: {
max: 5,
min: 0,
acquire: 90000000,
idle: 1000000
},
debug: false,
dialectOptions: {
requestTimeout: 999999,
// timezone: '+8:00'
// instanceName:'DEV'
} //设置MSSQL超时时间
}
},
reqEsDevUrl: "http://192.168.4.249:9200/",
reqHomePageDevUrl: "http://zcchannel.apps.com:4003/",
reqAuthUrl: "http://sj.app.com:4002/auth"
};
module.exports = settings;
var path= require('path');
var basepath=path.normalize(path.join(__dirname, '../..'));
var settings = {
api:path.join(basepath,"app/base/api/impl"),
util:path.join(basepath,"app/base/utils"),
service:path.join(basepath,"app/base/service/impl"),
db:path.join(basepath,"app/base/db/impl"),
service2:path.join(basepath,"app/base/service"),
consumer:path.join(basepath,"app/base/db/consumer"),
}
module.exports = settings;
var path= require('path');
var basepath=path.normalize(path.join(__dirname, '../..'));
var settings = {
api:path.join(basepath,"app/base/api/impl"),
util:path.join(basepath,"app/base/utils"),
service:path.join(basepath,"app/base/service/impl"),
db:path.join(basepath,"app/base/db/impl"),
service2:path.join(basepath,"app/base/service"),
consumer:path.join(basepath,"app/base/db/consumer"),
}
module.exports = settings;
File mode changed from 100644 to 100755
var fs=require("fs");
var path=require("path");
var system = require('../base/system');
module.exports = function (app) {
var routePath=__dirname+"/routes";
fs.readdir(routePath,function(err,rs){
if(rs){
rs.forEach(function(r){
var func=require(routePath+"/"+r);
func.call(null,app);
});
}
});
};
var fs=require("fs");
var path=require("path");
var system = require('../base/system');
module.exports = function (app) {
var routePath=__dirname+"/routes";
fs.readdir(routePath,function(err,rs){
if(rs){
rs.forEach(function(r){
var func=require(routePath+"/"+r);
func.call(null,app);
});
}
});
};
var path = require('path');
var ENVINPUT = {
DB_HOST: process.env.DB_HOST,
DB_PORT: process.env.DB_PORT,
DB_USER: process.env.DB_USER,
DB_PWD: process.env.DB_PWD,
REDIS_HOST: process.env.REDIS_HOST,
REDIS_PORT: process.env.REDIS_PORT,
REDIS_PWD: process.env.REDIS_PWD,
REDIS_DB: process.env.QUEUE_REDIS_DB,
DB_NAME: process.env.QUEUE_DB_NAME,
APP_ENV: process.env.APP_ENV ? process.env.APP_ENV : "test",//运行环境
CONSUMER_NAME: process.env.CONSUMER_NAME || "publicServiceAllocation.publicConsumer",//消费者名称
QUEUED_NAME: process.env.QUEUED_NAME || "SYTXPUBLIC-MSGQ",//队列名称,FAIL-失败队列(队列和失败队列一对存在进行部署)
};
var settings = {
env: ENVINPUT.APP_ENV,
consumerName: ENVINPUT.CONSUMER_NAME,
queuedName: ENVINPUT.QUEUED_NAME,
basepath: path.normalize(path.join(__dirname, '../..')),
port: process.env.NODE_PORT || 4018,
redis: function () {
if (this.env == "dev" || this.env == "test") {
var localsettings = require("./localsettings");
return localsettings.redis;
} else {
return {
host: ENVINPUT.REDIS_HOST,
port: ENVINPUT.REDIS_PORT,
password: ENVINPUT.REDIS_PWD,
db: ENVINPUT.REDIS_DB,
};
}
},
database: function () {
if (this.env == "dev" || this.env == "test") {
var localsettings = require("./localsettings");
return localsettings.database;
} else {
return {
dbname: ENVINPUT.DB_NAME,
user: ENVINPUT.DB_USER,
password: ENVINPUT.DB_PWD,
config: {
host: ENVINPUT.DB_HOST,
dialect: 'mysql',
operatorsAliases: false,
pool: {
max: 5,
min: 0,
acquire: 90000000,
idle: 1000000
},
debug: false,
dialectOptions: {
requestTimeout: 999999,
// instanceName:'DEV'
} //设置MSSQL超时时间
},
};
}
}
};
settings.ENVINPUT = ENVINPUT;
module.exports = settings;
var path = require('path');
var ENVINPUT = {
DB_HOST: process.env.DB_HOST,
DB_PORT: process.env.DB_PORT,
DB_USER: process.env.DB_USER,
DB_PWD: process.env.DB_PWD,
REDIS_HOST: process.env.REDIS_HOST,
REDIS_PORT: process.env.REDIS_PORT,
REDIS_PWD: process.env.REDIS_PWD,
REDIS_DB: process.env.QUEUE_REDIS_DB,
DB_NAME: process.env.QUEUE_DB_NAME,
APP_ENV: process.env.APP_ENV ? process.env.APP_ENV : "dev",//运行环境
CONSUMER_NAME: process.env.CONSUMER_NAME || "publicServiceAllocation.publicConsumer",//消费者名称
QUEUED_NAME: process.env.QUEUED_NAME || "SYTXPUBLIC-MSGQ",//队列名称,FAIL-失败队列(队列和失败队列一对存在进行部署)
};
var settings = {
env: ENVINPUT.APP_ENV,
consumerName: ENVINPUT.CONSUMER_NAME,
queuedName: ENVINPUT.QUEUED_NAME,
basepath: path.normalize(path.join(__dirname, '../..')),
port: process.env.NODE_PORT || 4018,
redis: function () {
if (this.env == "dev" || this.env == "test") {
var localsettings = require("./localsettings");
return localsettings.redis;
} else {
return {
host: ENVINPUT.REDIS_HOST,
port: ENVINPUT.REDIS_PORT,
password: ENVINPUT.REDIS_PWD,
db: ENVINPUT.REDIS_DB,
};
}
},
database: function () {
if (this.env == "dev" || this.env == "test") {
var localsettings = require("./localsettings");
return localsettings.database;
} else {
return {
dbname: ENVINPUT.DB_NAME,
user: ENVINPUT.DB_USER,
password: ENVINPUT.DB_PWD,
config: {
host: ENVINPUT.DB_HOST,
dialect: 'mysql',
operatorsAliases: false,
pool: {
max: 5,
min: 0,
acquire: 90000000,
idle: 1000000
},
debug: false,
dialectOptions: {
requestTimeout: 999999,
// instanceName:'DEV'
} //设置MSSQL超时时间
},
};
}
}
};
settings.ENVINPUT = ENVINPUT;
module.exports = settings;
const system = require("./app/base/system");
var settings = require("./app/config/settings");
var http = require('http');
var express = require('express');
var environment = require('./app/config/environment');
const app = express();
// //数据库支持暂缓支持
// var dbf = system.getObject("db.common.connection");
// con = dbf.getCon();
console.log(settings.consumerName, "--consumerName-----start-----");
if (settings.consumerName) {
var consumer = system.getObject("consumer." + settings.consumerName);
(async () => {
await consumer.doConsumer(settings.queuedName);
})();
} else {
console.log("not find consumer,please check ............................");
}
environment(app);//初始化环境
var server = http.createServer(app);
server.listen(settings.port, function () {
console.log('Express server listening on port ' + settings.port);
});
const system = require("./app/base/system");
var settings = require("./app/config/settings");
var http = require('http');
var express = require('express');
var environment = require('./app/config/environment');
const app = express();
// //数据库支持暂缓支持
// var dbf = system.getObject("db.common.connection");
// con = dbf.getCon();
console.log(settings.consumerName, "--consumerName-----start-----");
if (settings.consumerName) {
var consumer = system.getObject("consumer." + settings.consumerName);
(async () => {
await consumer.doConsumer(settings.queuedName);
})();
} else {
console.log("not find consumer,please check ............................");
}
environment(app);//初始化环境
var server = http.createServer(app);
server.listen(settings.port, function () {
console.log('Express server listening on port ' + settings.port);
});
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "bigdata",
"version": "1.0.0",
"description": "h5framework",
"main": "main.js",
"scripts": {
"dev": "nodemon main.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"license": "ISC",
"dependencies": {
"@alicloud/pop-core": "^1.7.7",
"MD5": "^1.3.0",
"after": "^0.8.2",
"ali-oss": "^4.12.2",
"aliyun-api-gateway": "^1.1.6",
"axios": "^0.19.2",
"babel-polyfill": "^6.26.0",
"base64id": "^1.0.0",
"bluebird": "^3.5.1",
"body-parser": "^1.18.2",
"co": "^4.6.0",
"connect-redis": "^3.3.3",
"continuation-local-storage": "^3.2.1",
"cookie-parser": "^1.4.3",
"crypto": "^1.0.1",
"crypto-js": "^3.1.9-1",
"ejs": "^2.5.8",
"element-ui": "^2.4.0",
"engine.io-parser": "^2.1.2",
"errorhandler": "^1.5.0",
"exif-js": "^2.3.0",
"express": "^4.16.2",
"express-session": "^1.15.6",
"gm": "^1.23.1",
"marked": "^0.7.0",
"method-override": "^2.3.10",
"morgan": "^1.9.0",
"multer": "^1.3.0",
"mysql2": "^1.5.3",
"node-cron": "^2.0.1",
"node-uuid": "^1.4.8",
"node-xlsx": "^0.15.0",
"nodemailer": "^6.3.0",
"pinyin": "^2.9.0",
"puppeteer": "^1.20.0",
"qcloud-cos-sts": "^3.0.2",
"qr-image": "^3.2.0",
"sequelize": "^4.37.8",
"sequelize-cli": "^4.1.1",
"serve-favicon": "^2.4.5",
"sha1": "^1.1.1",
"socket.io": "^2.1.1",
"uuid": "^3.2.1"
},
"devDependencies": {
"element-theme": "^2.0.1",
"element-theme-chalk": "^2.4.0"
}
}
{
"name": "bigdata",
"version": "1.0.0",
"description": "h5framework",
"main": "main.js",
"scripts": {
"dev": "nodemon main.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"license": "ISC",
"dependencies": {
"@alicloud/pop-core": "^1.7.7",
"MD5": "^1.3.0",
"after": "^0.8.2",
"ali-oss": "^4.12.2",
"aliyun-api-gateway": "^1.1.6",
"axios": "^0.19.2",
"babel-polyfill": "^6.26.0",
"base64id": "^1.0.0",
"bluebird": "^3.5.1",
"body-parser": "^1.18.2",
"co": "^4.6.0",
"connect-redis": "^3.3.3",
"continuation-local-storage": "^3.2.1",
"cookie-parser": "^1.4.3",
"crypto": "^1.0.1",
"crypto-js": "^3.1.9-1",
"ejs": "^2.5.8",
"element-ui": "^2.4.0",
"engine.io-parser": "^2.1.2",
"errorhandler": "^1.5.0",
"exif-js": "^2.3.0",
"express": "^4.16.2",
"express-session": "^1.15.6",
"gm": "^1.23.1",
"marked": "^0.7.0",
"method-override": "^2.3.10",
"morgan": "^1.9.0",
"multer": "^1.3.0",
"mysql2": "^1.5.3",
"node-cron": "^2.0.1",
"node-uuid": "^1.4.8",
"node-xlsx": "^0.15.0",
"nodemailer": "^6.3.0",
"pinyin": "^2.9.0",
"puppeteer": "^1.20.0",
"qcloud-cos-sts": "^3.0.2",
"qr-image": "^3.2.0",
"sequelize": "^4.37.8",
"sequelize-cli": "^4.1.1",
"serve-favicon": "^2.4.5",
"sha1": "^1.1.1",
"socket.io": "^2.1.1",
"uuid": "^3.2.1"
},
"devDependencies": {
"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