Commit 4c01a502 by 宋毅

tj

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