Commit 31136731 by 蒋勇

d

parents b3e8aed8 d29af882
...@@ -8,8 +8,16 @@ class ChannelCtl extends CtlBase { ...@@ -8,8 +8,16 @@ class ChannelCtl extends CtlBase {
super("common", CtlBase.getServiceName(ChannelCtl)); super("common", CtlBase.getServiceName(ChannelCtl));
} }
async refQuery(pobj, qobj, req) { async refQuery(pobj, qobj, req) {
let rtn=await this.service.refQuery(pobj); let rtn = await this.service.refQuery(pobj);
return rtn return rtn
} }
async authorizeUser(pobj, qobj, req) {
if (!pobj.channelId) {
return system.getResult(null, "channelId can not be empty,100290");
}
await this.service.authorizeUser(pobj);
return system.getResult("SUCCESS");
}
} }
module.exports = ChannelCtl; module.exports = ChannelCtl;
...@@ -20,12 +20,23 @@ class logCtl extends CtlBase { ...@@ -20,12 +20,23 @@ class logCtl extends CtlBase {
let { opTitle, identifyCode, messageBody, resultInfo, errorInfo, requestId, created_at } = item; let { opTitle, identifyCode, messageBody, resultInfo, errorInfo, requestId, created_at } = item;
messageBody = messageBody ? JSON.parse(messageBody) : {} messageBody = messageBody ? JSON.parse(messageBody) : {}
resultInfo = resultInfo ? JSON.parse(resultInfo) : {} resultInfo = resultInfo ? JSON.parse(resultInfo) : {}
let status;
if (resultInfo && resultInfo.status === 0) {
status = "SUCCESS"
} else {
status = "FAIL"
}
if (errorInfo && errorInfo !== "null") {
status = "FAIL"
}
return { return {
opTitle: opTitle.split(",").length > 1 ? opTitle.split(",")[1] : opTitle, opTitle: opTitle,
url: `${messageBody.gname}/${messageBody.qname}/${messageBody.method}`, url: `${messageBody.gname}/${messageBody.qname}/${messageBody.method}`,
user: messageBody.param && messageBody.param.username || '', user: messageBody.param && messageBody.param.username || '',
ip: messageBody.param && messageBody.param.clientIp, ip: messageBody.param && messageBody.param.clientIp,
created_at, created_at,
requestId,
status,
info: { info: {
opTitle, identifyCode, messageBody, resultInfo, errorInfo, requestId, created_at opTitle, identifyCode, messageBody, resultInfo, errorInfo, requestId, created_at
} }
......
...@@ -5,6 +5,7 @@ class UserCache extends CacheBase { ...@@ -5,6 +5,7 @@ class UserCache extends CacheBase {
constructor() { constructor() {
super(); super();
this.userDao = system.getObject("db.auth.userDao"); this.userDao = system.getObject("db.auth.userDao");
this.channelDao = system.getObject("db.common.channelDao");
} }
isdebug() { isdebug() {
return settings.env == "dev"; return settings.env == "dev";
...@@ -26,7 +27,20 @@ class UserCache extends CacheBase { ...@@ -26,7 +27,20 @@ class UserCache extends CacheBase {
}); });
if (configValue && configValue[0]) { if (configValue && configValue[0]) {
return JSON.stringify(configValue[0]); let data = JSON.parse(JSON.stringify(configValue[0]));
let channelDatas = await this.channelDao.findAll({});
channelDatas = JSON.parse(JSON.stringify(channelDatas));
channelDatas.forEach(item => {
if (item.userids && item.userids.split(",").includes(data.id.toString())) {
data.channel = {
id: item.id,
code: item.code,
name: item.name
}
}
});
// 获取渠道信息
return JSON.stringify(data);
} }
return null; return null;
} }
......
const system = require("../../../system"); const system = require("../../../system");
const settings = require("../../../../config/settings"); const settings = require("../../../../config/settings");
const appconfig=system.getSysConfig(); const appconfig = system.getSysConfig();
module.exports = (db, DataTypes) => { module.exports = (db, DataTypes) => {
return db.define("channel", { return db.define("channel", {
code:{ code: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: false,
}, },
...@@ -14,7 +14,11 @@ module.exports = (db, DataTypes) => { ...@@ -14,7 +14,11 @@ module.exports = (db, DataTypes) => {
routehost: { routehost: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: false,
}//和user的from相同,在注册user时,去创建 },//和user的from相同,在注册user时,去创建
userids: {
type: DataTypes.STRING,
allowNull: true,
},
}, { }, {
paranoid: true,//假的删除 paranoid: true,//假的删除
underscored: true, underscored: true,
......
...@@ -5,71 +5,79 @@ const appconfig = system.getSysConfig(); ...@@ -5,71 +5,79 @@ const appconfig = system.getSysConfig();
class ChannelService extends ServiceBase { class ChannelService extends ServiceBase {
constructor() { constructor() {
super("common", ServiceBase.getDaoName(ChannelService)); super("common", ServiceBase.getDaoName(ChannelService));
this.handlers={} this.handlers = {}
} }
async channelHandle(channelobj,path,datajson){ async channelHandle(channelobj, path, datajson) {
let p=channelobj.pts.filter(item=>{ let p = channelobj.pts.filter(item => {
return item.path==path return item.path == path
}) })
if(p.length==0){ if (p.length == 0) {
throw Error("请配置渠道流量的路径方法映射") throw Error("请配置渠道流量的路径方法映射")
} }
let fileName=channelobj.code let fileName = channelobj.code
let method=p[0].method let method = p[0].method
if(!this.handlers[fileName]) { if (!this.handlers[fileName]) {
this.handlers[fileName]=require("./channelhandlers/"+fileName+".js") this.handlers[fileName] = require("./channelhandlers/" + fileName + ".js")
} }
if( !this.handlers[fileName][method]){ if (!this.handlers[fileName][method]) {
throw Error(`请在${fileName}文件中定义渠道流量的处理方法${method}`) throw Error(`请在${fileName}文件中定义渠道流量的处理方法${method}`)
} }
let rtn=await this.handlers[fileName][method](datajson); let rtn = await this.handlers[fileName][method](datajson);
return rtn; return rtn;
} }
async create(p,q,req){ async create(p, q, req) {
let self =this let self = this
return this.db.transaction(async function (t) { return this.db.transaction(async function (t) {
let u = await self.dao.create(p,t) let u = await self.dao.create(p, t)
//创建路由--针对于特定来源渠道域名的路由,给中台服务添加路由 //创建路由--针对于特定来源渠道域名的路由,给中台服务添加路由
try{ try {
let ps = ["/"] let ps = ["/"]
let routeobj = await self.cjsonregister(ChannelService.newRouteUrl(settings.pmappname), let routeobj = await self.cjsonregister(ChannelService.newRouteUrl(settings.pmappname),
{ name: p.code, paths: ps, hosts: [p.routehost], strip_path: false }) { name: p.code, paths: ps, hosts: [p.routehost], strip_path: false })
}catch(e){ } catch (e) {
await self.cdel(ChannelService.routeUrl(p.code)) await self.cdel(ChannelService.routeUrl(p.code))
throw new Error("创建渠道报错") throw new Error("创建渠道报错")
} }
return u return u
}) })
} }
async update(p,q,req){ async update(p, q, req) {
let self =this let self = this
return this.db.transaction(async function (t) { return this.db.transaction(async function (t) {
let old=await self.dao.findOne({id:p.id}) let old = await self.dao.findOne({ id: p.id })
let u = await self.dao.update(p,t) let u = await self.dao.update(p, t)
//创建路由--针对于特定来源渠道域名的路由,给中台服务添加路由 //创建路由--针对于特定来源渠道域名的路由,给中台服务添加路由
try{ try {
await self.cdel(ChannelService.routeUrl(old.code)) await self.cdel(ChannelService.routeUrl(old.code))
let ps = ["/"] let ps = ["/"]
let routeobj = await self.cjsonregister(ChannelService.newRouteUrl(settings.pmappname), let routeobj = await self.cjsonregister(ChannelService.newRouteUrl(settings.pmappname),
{ name: p.code, paths: ps, hosts: [p.routehost], strip_path: false }) { name: p.code, paths: ps, hosts: [p.routehost], strip_path: false })
}catch(e){ } catch (e) {
throw new Error("创建渠道报错") throw new Error("创建渠道报错")
} }
return u return u
}) })
} }
async delete(p,q,req){ async delete(p, q, req) {
let self =this let self = this
return this.db.transaction(async function (t) { return this.db.transaction(async function (t) {
let u = await self.dao.delete(p,t) let u = await self.dao.delete(p, t)
//创建路由--针对于特定来源渠道域名的路由,给中台服务添加路由 //创建路由--针对于特定来源渠道域名的路由,给中台服务添加路由
try{ try {
await self.cdel(ChannelService.routeUrl(u.code)) await self.cdel(ChannelService.routeUrl(u.code))
}catch(e){ } catch (e) {
throw new Error("创建渠道报错") throw new Error("创建渠道报错")
} }
return u return u
}) })
} }
async authorizeUser(p, q, req) {
await this.dao.updateByWhere({
userids: p.userids
}, {
id: p.channelId
})
}
} }
module.exports = ChannelService; module.exports = ChannelService;
\ No newline at end of file
...@@ -32,16 +32,32 @@ class LogClient { ...@@ -32,16 +32,32 @@ class LogClient {
async logList(pobj) { async logList(pobj) {
let { search, pageInfo, company_id } = pobj; let { search, pageInfo, company_id } = pobj;
let { userName, errorInfo, messageBody, resultInfo, created_at, opTitle, requestId } = search;
let query = { let query = {
indexName: `logs-sytxpublic-msgq-${settings.logindex}`, indexName: `logs-sytxpublic-msgq-${settings.logindex}`,
pageSize: pageInfo.pageSize, pageSize: pageInfo.pageSize,
currentPage: pageInfo.pageNo currentPage: pageInfo.pageNo
}; };
if (company_id && company_id != 1) { if (company_id && company_id != 1) {
query.identifyCode = `_${company_id}_` query.identifyCode = `_${company_id}_`;
} }
if (search.opTitle) { if (opTitle) {
query.opTitle = search.opTitle query.opTitle = opTitle;
}
if (requestId) {
query.requestId = requestId;
}
if (userName) {
query.messageBody = userName;
}
if (errorInfo) {
query.errorInfo = errorInfo;
}
if (messageBody) {
query.messageBody = messageBody;
}
if (resultInfo) {
query.resultInfo = resultInfo;
} }
// { // {
// "opTitle": "",// N 操作的业务标题 // "opTitle": "",// N 操作的业务标题
...@@ -55,6 +71,29 @@ class LogClient { ...@@ -55,6 +71,29 @@ class LogClient {
console.log("请求--------日志"); console.log("请求--------日志");
console.log(settings.logUrl()); console.log(settings.logUrl());
console.log(query); console.log(query);
// return {
// "totalCount": 1,
// "pageSize": 20,
// "currentPage": 0,
// "list": [
// {
// "opTitle": "center_manage_首页",
// "identifyCode": "10_",
// "messageBody": "{\"gname\":\"msg\",\"qname\":\"msgCtl\",\"method\":\"findUnreadCount\",\"param\":{\"clientIp\":\"9.223.9.138\",\"agent\":\"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36\",\"classname\":\"msg.msgCtl\",\"app_id\":1,\"company_id\":\"10\",\"userid\":\"15\",\"username\":\"j2\",\"bizpath\":\"/home\",\"is_read\":false},\"actionType\":\"\",\"pushUrl\":\"\"}",
// "resultInfo": "{\"status\":0}",
// "errorInfo": "null",
// "requestId": "19a258474e384a0db939270580f01407",
// "created_at": "2020-07-16T05:18:48.454Z"
// }, {
// "opTitle": "center_manage_消息中心",
// "identifyCode": "10_",
// "messageBody": "{\"gname\":\"msg\",\"qname\":\"msgCtl\",\"method\":\"findUnreadCount\",\"param\":{\"clientIp\":\"9.223.9.138\",\"agent\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36\",\"classname\":\"msg.msgCtl\",\"app_id\":1,\"company_id\":\"10\",\"userid\":\"15\",\"username\":\"j2\",\"bizpath\":\"/message/message_page\",\"is_read\":false},\"actionType\":\"\",\"pushUrl\":\"\"}",
// "resultInfo": "{\"status\":-1}",
// "errorInfo": "null",
// "requestId": "06d94fbcd05b44a1ae292a21f5931f41",
// "created_at": "2020-07-16T05:51:54.888Z"
// }]
// }
let rtn = await system.postJsonTypeReq(settings.logUrl(), { let rtn = await system.postJsonTypeReq(settings.logUrl(), {
"actionType": "queryLogsData",// Y 功能名称 "actionType": "queryLogsData",// Y 功能名称
"actionBody": query "actionBody": query
......
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