Commit 3b101b11 by 王悦

add推送管理、组织结构监控

parent ae750f27
...@@ -5,71 +5,81 @@ var settings = require("../../../../config/settings"); ...@@ -5,71 +5,81 @@ var settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base"); const CtlBase = require("../../ctl.base");
class CompanyCtl extends CtlBase { class CompanyCtl extends CtlBase {
constructor() { constructor() {
super("common", CtlBase.getServiceName(CompanyCtl)); super("common", CtlBase.getServiceName(CompanyCtl));
this.userSve = system.getObject("service.auth.userSve"); this.userSve = system.getObject("service.auth.userSve");
}
async update(p, q, req) {
let u = await super.update(p, q, req)
//缓存失效
await this.cacheManager["CompanyCache"].invalidate(p.companykey)
let company = await this.cacheManager["CompanyCache"].cache(p.companykey)
return system.getResult(company)
}
async getMyApps(p, q, req) {
let userfind = await this.cacheManager["UserCache"].cache(p.username)
let isSuper = userfind.isSuper
if (userfind.company.appids && userfind.company.appids != "") {
let appsarray = userfind.company.appids.split(",")
let appidsquery = appsarray.map(astr => {
return astr.split("|")[0]
})
let apps = await this.service.getMyApps(appidsquery, isSuper)
return system.getResult(apps)
} else {
return []
} }
}
async bindApps(p, q, req) { async update(p, q, req) {
let appids = p.appids let u = await super.update(p, q, req)
let cmpid = p.postcmpid //缓存失效
let appids2 = appids.map(item => { await this.cacheManager["CompanyCache"].invalidate(p.companykey)
return item.appid + "|" + item.title let company = await this.cacheManager["CompanyCache"].cache(p.companykey)
}) return system.getResult(company)
let appidstrs = appids2.join(",") }
await this.service.bindApps(appidstrs, cmpid)
return system.getResult(appids) async getMyApps(p, q, req) {
} let userfind = await this.cacheManager["UserCache"].cache(p.username)
async setOrgs(p, q, req) { let isSuper = userfind.isSuper
//let companynew=await this.service.findById(p.company_id) if (userfind.company.appids && userfind.company.appids != "") {
let orgs = await this.service.setOrgs(p) let appsarray = userfind.company.appids.split(",")
return system.getResult(orgs) let appidsquery = appsarray.map(astr => {
} return astr.split("|")[0]
async getOrgs(p, q, req) { })
//let companynew=await this.cacheManager["CompanyCache"].cache(req.xctx.fromcompanykey) let apps = await this.service.getMyApps(appidsquery, isSuper)
let companynew = await this.service.findById(p.company_id); return system.getResult(apps)
const userData = await this.userSve.findById(p.userid); } else {
let orgjsonstr = companynew.orgJson; return []
let rtnjson = null; }
if (orgjsonstr && orgjsonstr != "") { }
rtnjson = JSON.parse(companynew.orgJson);
} else { async bindApps(p, q, req) {
rtnjson = []; let appids = p.appids
let cmpid = p.postcmpid
let appids2 = appids.map(item => {
return item.appid + "|" + item.title
})
let appidstrs = appids2.join(",")
await this.service.bindApps(appidstrs, cmpid)
return system.getResult(appids)
}
async setOrgs(p, q, req) {
//let companynew=await this.service.findById(p.company_id)
let orgs = await this.service.setOrgs(p)
return system.getResult(orgs)
}
async getOrgs(p, q, req) {
//let companynew=await this.cacheManager["CompanyCache"].cache(req.xctx.fromcompanykey)
let companynew = await this.service.findById(p.company_id);
const userData = await this.userSve.findById(p.userid);
let orgjsonstr = companynew.orgJson;
let rtnjson = null;
if (orgjsonstr && orgjsonstr != "") {
rtnjson = JSON.parse(companynew.orgJson);
} else {
rtnjson = [];
}
if (userData) {
if (userData.isAdmin || userData.isSuper) {
return system.getResult({orgJson: rtnjson});
} else {
return system.getResult({orgJson: this.service.buildOrgs(rtnjson, userData.ptags)});
}
} else {
return system.getResult({orgJson: []});
}
} }
if (userData) {
if (userData.isAdmin || userData.isSuper) { async getWatchOrgNodes(p, q, req) {
return system.getResult({ orgJson: rtnjson }); return await this.service.getWatchOrgNodes(p.company_id);
} else {
return system.getResult({ orgJson: this.service.buildOrgs(rtnjson, userData.ptags) });
}
} else {
return system.getResult({ orgJson: [] });
} }
}
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
} }
} }
module.exports = CompanyCtl; module.exports = CompanyCtl;
var system = require("../../../system")
const http = require("http")
const querystring = require('querystring');
var settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base");
class PushCtl extends CtlBase {
constructor() {
super("common", CtlBase.getServiceName(PushCtl));
}
async findAndCountAll(pobj, qobj, req) {
let query = {
pageSize: pobj.pageInfo.pageSize,
pageIndex: pobj.pageInfo.pageNo
};
if (pobj.messageBody)
query.messageBody = pobj.messageBody;
if (pobj.identify_code)
query.identifyCode = pobj.identify_code;
if (pobj.request_id)
query.requestIdInfo = pobj.request_id;
let actionType;
switch (pobj.bizpath) {
case "/sysmag/pushfail":
actionType = "getPushFailureList";
break;
case "/sysmag/pusherror":
actionType = "getPushErrorList";
break
}
let rtn = await system.postJsonTypeReq(settings.pushUrl(), {
"actionType": actionType,
"actionBody": query
});
if (rtn.statusCode === 200) {
rtn = rtn.data;
if (rtn && rtn.status === 1) {
return system.getResult({
results: {
count: rtn.totalCount,
rows: rtn && rtn.data || []
}
});
} else {
return system.getResultFail(rtn && rtn.message || '请联系管理员');
}
} else {
return system.getResultFail(rtn)
}
}
async repush(pobj, qobj, req) {
let rtn = await system.postJsonTypeReq(settings.pushUrl(), {
"actionType": "pushAgainFailureLog",
"actionBody": {
id: pobj.id
}
});
if (rtn.statusCode === 200) {
return rtn.data;
} else {
return system.getResultFail(rtn)
}
}
}
module.exports = PushCtl;
const system = require("../../../system"); const system = require("../../../system");
const ServiceBase = require("../../sve.base"); const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings"); const settings = require("../../../../config/settings");
class CompanyService extends ServiceBase { class CompanyService extends ServiceBase {
constructor() { constructor() {
super("common", ServiceBase.getDaoName(CompanyService)); super("common", ServiceBase.getDaoName(CompanyService));
}
async getMyApps(appids, isSuper) {
let appsrtn = null
if (isSuper) {
appsrtn = this.db.models.app.findAll({
where:
{
id: { [this.db.Op.ne]: settings.pmappid }
}
})
} else {
appsrtn = this.db.models.app.findAll({
where:
{
id: { [this.db.Op.in]: appids }
}
})
} }
return appsrtn
}
async bindApps(appids, companyid) {
var self = this
return this.db.transaction(async function (t) {
let u = await self.dao.update({ appids: appids, id: companyid }, t)
return appids
})
}
async setOrgs(p, cmk) {
var self = this
let curNodeData = p.curdata
let opathstr = curNodeData.orgpath
let oldNodeData = p.olddata//老的节点数据
let strjson = JSON.stringify(p.orgJson)
p.id = p.company_id
p.orgJson = strjson
let oldopath = ''
if (!oldNodeData) {//如果不传老对象,表示当前操作是删除节点操作,检查是否存在用户,如果已经存在
//那么就提示不能删除
let us = await self.db.models.user.findOne({ where: { opath: { [self.db.Op.like]: `%${opathstr}%` } } })
if (us) {
let companytmp = await this.dao.model.findOne({ where: { id: p.company_id } });
return { orgJson: JSON.parse(companytmp.orgJson) }
} else {
let u = await this.dao.update(p)
let companytmp = await this.dao.model.findOne({ where: { id: p.company_id } });
return { orgJson: JSON.parse(companytmp.orgJson) }
}
} else {
oldopath = oldNodeData.orgpath == '' ? '123456' : oldNodeData.orgpath
}
return this.db.transaction(async function (t) {
//更新组织机构 async getMyApps(appids, isSuper) {
let u = await self.dao.update(p, t) let appsrtn = null
//更新,还得传输当前节点,查询出当前节点的角色 if (isSuper) {
//按照当前节点的opath查询出所有的用户,更新这些用户的角色信息 appsrtn = this.db.models.app.findAll({
where:
{
id: {[this.db.Op.ne]: settings.pmappid}
}
})
} else {
appsrtn = this.db.models.app.findAll({
where:
{
id: {[this.db.Op.in]: appids}
}
})
}
return appsrtn
}
if (curNodeData) { async bindApps(appids, companyid) {
if (curNodeData.isPosition) { var self = this
let us = await self.db.models.user.findAll({ where: { opath: { [self.db.Op.like]: `%${oldopath}%` } }, transaction: t }) return this.db.transaction(async function (t) {
//查询出角色 let u = await self.dao.update({appids: appids, id: companyid}, t)
let roleids = curNodeData.roles return appids
// let rs=await self.db.models.role.findAll({where:{id:{[self.db.Op.in]:roleids},app_id:p.app_id,company_id:p.company_id},transaction:t}) })
//需要添加访客角色 }
if (roleids && roleids.length > 0) { buildNoPositionNode(treejson, rtnArray) {
if (roleids.indexOf(settings.pmroleid["pr"]) < 0) { treejson.forEach((n) => {
roleids.push(settings.pmroleid["pr"]) if (n.children) {
this.buildNoPositionNode(n.children, rtnArray)
} }
} if (n.hasOwnProperty("isPosition") && !n.isPosition) {
let rs = await self.db.models.role.findAll({ where: { id: { [self.db.Op.in]: roleids } }, transaction: t }) rtnArray.push(n)
for (let u of us) {
await u.setRoles(rs, { transaction: t })
//if (opathstr != oldopath) {
u.opath = opathstr + "/" + u.userName
u.ptags = curNodeData.ptags
u.save({ transaction: t })
// }
//令用户缓存失效
await self.cacheManager["UserCache"].invalidate(u.userName)
}
} else {//不是岗位节点,检查修改后的路径是否和原始一致,如果不一致,那么需要查出原始的用户数据
//把原来的路径替换当前新的code
if (opathstr != oldopath) {
let us2 = await self.db.models.user.findAll({ where: { opath: { [self.db.Op.like]: `%${oldopath}%` } }, transaction: t })
for (let u of us2) {
let curpath = u.opath
let newpath = curpath.replace(oldNodeData.code, curNodeData.code)
u.opath = newpath
u.save({ transaction: t })
//令用户缓存失效
await self.cacheManager["UserCache"].invalidate(u.userName)
} }
} })
}
async getWatchOrgNodes(cmid) {
let rtn = []
let companynew = await this.findById(cmid)
let orgjsonstr = companynew.orgJson
if (orgjsonstr && orgjsonstr != "") {
let treejson = JSON.parse(companynew.orgJson)
this.buildNoPositionNode(treejson, rtn)
} }
return rtn
}
} async setOrgs(p, cmk) {
let companytmp = await self.dao.model.findOne({ where: { id: p.company_id }, transaction: t }); var self = this
return { orgJson: JSON.parse(companytmp.orgJson) } let curNodeData = p.curdata
}) let opathstr = curNodeData.orgpath
} let oldNodeData = p.olddata//老的节点数据
buildOrgs(rtnjson, code) { let strjson = JSON.stringify(p.orgJson)
if (rtnjson.length > 0) { p.id = p.company_id
for (let val of rtnjson) { p.orgJson = strjson
if (val.code === code) { let oldopath = ''
return [val] if (!oldNodeData) {//如果不传老对象,表示当前操作是删除节点操作,检查是否存在用户,如果已经存在
//那么就提示不能删除
let us = await self.db.models.user.findOne({where: {opath: {[self.db.Op.like]: `%${opathstr}%`}}})
if (us) {
let companytmp = await this.dao.model.findOne({where: {id: p.company_id}});
return {orgJson: JSON.parse(companytmp.orgJson)}
} else {
let u = await this.dao.update(p)
let companytmp = await this.dao.model.findOne({where: {id: p.company_id}});
return {orgJson: JSON.parse(companytmp.orgJson)}
}
} else { } else {
return this.buildOrgs(val.children || [], code) oldopath = oldNodeData.orgpath == '' ? '123456' : oldNodeData.orgpath
}
return this.db.transaction(async function (t) {
//更新组织机构
let u = await self.dao.update(p, t)
//更新,还得传输当前节点,查询出当前节点的角色
//按照当前节点的opath查询出所有的用户,更新这些用户的角色信息
if (curNodeData) {
if (curNodeData.isPosition) {
let us = await self.db.models.user.findAll({
where: {opath: {[self.db.Op.like]: `%${oldopath}%`}},
transaction: t
})
//查询出角色
let roleids = curNodeData.roles
// let rs=await self.db.models.role.findAll({where:{id:{[self.db.Op.in]:roleids},app_id:p.app_id,company_id:p.company_id},transaction:t})
//需要添加访客角色
if (roleids && roleids.length > 0) {
if (roleids.indexOf(settings.pmroleid["pr"]) < 0) {
roleids.push(settings.pmroleid["pr"])
}
}
let rs = await self.db.models.role.findAll({
where: {id: {[self.db.Op.in]: roleids}},
transaction: t
})
for (let u of us) {
await u.setRoles(rs, {transaction: t})
//if (opathstr != oldopath) {
u.opath = opathstr + "/" + u.userName
u.ptags = curNodeData.ptags
u.save({transaction: t})
// }
//令用户缓存失效
await self.cacheManager["UserCache"].invalidate(u.userName)
}
} else {//不是岗位节点,检查修改后的路径是否和原始一致,如果不一致,那么需要查出原始的用户数据
//把原来的路径替换当前新的code
if (opathstr != oldopath) {
let us2 = await self.db.models.user.findAll({
where: {opath: {[self.db.Op.like]: `%${oldopath}%`}},
transaction: t
})
for (let u of us2) {
let curpath = u.opath
let newpath = curpath.replace(oldNodeData.code, curNodeData.code)
u.opath = newpath
u.save({transaction: t})
//令用户缓存失效
await self.cacheManager["UserCache"].invalidate(u.userName)
}
}
}
}
let companytmp = await self.dao.model.findOne({where: {id: p.company_id}, transaction: t});
return {orgJson: JSON.parse(companytmp.orgJson)}
})
}
buildOrgs(rtnjson, code) {
if (rtnjson.length > 0) {
for (let val of rtnjson) {
if (val.code === code) {
return [val]
} else {
return this.buildOrgs(val.children || [], code)
}
}
} else {
return rtnjson
} }
}
} else {
return rtnjson
} }
}
} }
module.exports = CompanyService; module.exports = CompanyService;
...@@ -53,6 +53,13 @@ var settings = { ...@@ -53,6 +53,13 @@ var settings = {
return "http://logs-sytxpublic-msgq-service/api/queueAction/producer/springBoard"; return "http://logs-sytxpublic-msgq-service/api/queueAction/producer/springBoard";
} }
}, },
pushUrl: function () {
if (this.env == "localhost") {
return "http://192.168.1.128:4018/api/queueAction/producer/springBoard";
} else {
return "http://logs-sytxpublic-msgq-service/api/queueAction/producer/springBoard";
}
},
pmappname: "center-app", pmappname: "center-app",
pmappid: 1, pmappid: 1,
pmcompanyid: 1, pmcompanyid: 1,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment