Commit 26490768 by Sxy

fix: 组织结构 格式化

parent 93023e5c
...@@ -62,13 +62,14 @@ class CompanyCtl extends CtlBase { ...@@ -62,13 +62,14 @@ class CompanyCtl extends CtlBase {
rtnjson = []; rtnjson = [];
} }
if (userData) { if (userData) {
this.service.formatOrgs(rtnjson);
if (userData.isAdmin || userData.isSuper) { if (userData.isAdmin || userData.isSuper) {
return system.getResult({orgJson: rtnjson}); return system.getResult({ orgJson: rtnjson });
} else { } else {
return system.getResult({orgJson: this.service.buildOrgs(rtnjson, userData.ptags)}); return system.getResult({ orgJson: this.service.buildOrgs(rtnjson, userData.ptags) });
} }
} else { } else {
return system.getResult({orgJson: []}); return system.getResult({ orgJson: [] });
} }
} }
......
...@@ -13,14 +13,14 @@ class CompanyService extends ServiceBase { ...@@ -13,14 +13,14 @@ class CompanyService extends ServiceBase {
appsrtn = this.db.models.app.findAll({ appsrtn = this.db.models.app.findAll({
where: where:
{ {
id: {[this.db.Op.ne]: settings.pmappid} id: { [this.db.Op.ne]: settings.pmappid }
} }
}) })
} else { } else {
appsrtn = this.db.models.app.findAll({ appsrtn = this.db.models.app.findAll({
where: where:
{ {
id: {[this.db.Op.in]: appids} id: { [this.db.Op.in]: appids }
} }
}) })
} }
...@@ -30,7 +30,7 @@ class CompanyService extends ServiceBase { ...@@ -30,7 +30,7 @@ class CompanyService extends ServiceBase {
async bindApps(appids, companyid) { async bindApps(appids, companyid) {
var self = this var self = this
return this.db.transaction(async function (t) { return this.db.transaction(async function (t) {
let u = await self.dao.update({appids: appids, id: companyid}, t) let u = await self.dao.update({ appids: appids, id: companyid }, t)
return appids return appids
}) })
} }
...@@ -68,14 +68,14 @@ class CompanyService extends ServiceBase { ...@@ -68,14 +68,14 @@ class CompanyService extends ServiceBase {
let oldopath = '' let oldopath = ''
if (!oldNodeData) {//如果不传老对象,表示当前操作是删除节点操作,检查是否存在用户,如果已经存在 if (!oldNodeData) {//如果不传老对象,表示当前操作是删除节点操作,检查是否存在用户,如果已经存在
//那么就提示不能删除 //那么就提示不能删除
let us = await self.db.models.user.findOne({where: {opath: {[self.db.Op.like]: `%${opathstr}%`}}}) let us = await self.db.models.user.findOne({ where: { opath: { [self.db.Op.like]: `%${opathstr}%` } } })
if (us) { if (us) {
let companytmp = await this.dao.model.findOne({where: {id: p.company_id}}); let companytmp = await this.dao.model.findOne({ where: { id: p.company_id } });
return {orgJson: JSON.parse(companytmp.orgJson)} return { orgJson: JSON.parse(companytmp.orgJson) }
} else { } else {
let u = await this.dao.update(p) let u = await this.dao.update(p)
let companytmp = await this.dao.model.findOne({where: {id: p.company_id}}); let companytmp = await this.dao.model.findOne({ where: { id: p.company_id } });
return {orgJson: JSON.parse(companytmp.orgJson)} return { orgJson: JSON.parse(companytmp.orgJson) }
} }
} else { } else {
oldopath = oldNodeData.orgpath == '' ? '123456' : oldNodeData.orgpath oldopath = oldNodeData.orgpath == '' ? '123456' : oldNodeData.orgpath
...@@ -90,7 +90,7 @@ class CompanyService extends ServiceBase { ...@@ -90,7 +90,7 @@ class CompanyService extends ServiceBase {
if (curNodeData) { if (curNodeData) {
if (curNodeData.isPosition) { if (curNodeData.isPosition) {
let us = await self.db.models.user.findAll({ let us = await self.db.models.user.findAll({
where: {opath: {[self.db.Op.like]: `%${oldopath}%`}}, where: { opath: { [self.db.Op.like]: `%${oldopath}%` } },
transaction: t transaction: t
}) })
//查询出角色 //查询出角色
...@@ -104,15 +104,15 @@ class CompanyService extends ServiceBase { ...@@ -104,15 +104,15 @@ class CompanyService extends ServiceBase {
} }
} }
let rs = await self.db.models.role.findAll({ let rs = await self.db.models.role.findAll({
where: {id: {[self.db.Op.in]: roleids}}, where: { id: { [self.db.Op.in]: roleids } },
transaction: t transaction: t
}) })
for (let u of us) { for (let u of us) {
await u.setRoles(rs, {transaction: t}) await u.setRoles(rs, { transaction: t })
//if (opathstr != oldopath) { //if (opathstr != oldopath) {
u.opath = opathstr + "/" + u.userName u.opath = opathstr + "/" + u.userName
u.ptags = curNodeData.ptags u.ptags = curNodeData.ptags
u.save({transaction: t}) u.save({ transaction: t })
// } // }
//令用户缓存失效 //令用户缓存失效
await self.cacheManager["UserCache"].invalidate(u.userName) await self.cacheManager["UserCache"].invalidate(u.userName)
...@@ -121,14 +121,14 @@ class CompanyService extends ServiceBase { ...@@ -121,14 +121,14 @@ class CompanyService extends ServiceBase {
//把原来的路径替换当前新的code //把原来的路径替换当前新的code
if (opathstr != oldopath) { if (opathstr != oldopath) {
let us2 = await self.db.models.user.findAll({ let us2 = await self.db.models.user.findAll({
where: {opath: {[self.db.Op.like]: `%${oldopath}%`}}, where: { opath: { [self.db.Op.like]: `%${oldopath}%` } },
transaction: t transaction: t
}) })
for (let u of us2) { for (let u of us2) {
let curpath = u.opath let curpath = u.opath
let newpath = curpath.replace(oldNodeData.code, curNodeData.code) let newpath = curpath.replace(oldNodeData.code, curNodeData.code)
u.opath = newpath u.opath = newpath
u.save({transaction: t}) u.save({ transaction: t })
//令用户缓存失效 //令用户缓存失效
await self.cacheManager["UserCache"].invalidate(u.userName) await self.cacheManager["UserCache"].invalidate(u.userName)
} }
...@@ -137,8 +137,8 @@ class CompanyService extends ServiceBase { ...@@ -137,8 +137,8 @@ class CompanyService extends ServiceBase {
} }
} }
let companytmp = await self.dao.model.findOne({where: {id: p.company_id}, transaction: t}); let companytmp = await self.dao.model.findOne({ where: { id: p.company_id }, transaction: t });
return {orgJson: JSON.parse(companytmp.orgJson)} return { orgJson: JSON.parse(companytmp.orgJson) }
}) })
} }
...@@ -155,6 +155,17 @@ class CompanyService extends ServiceBase { ...@@ -155,6 +155,17 @@ class CompanyService extends ServiceBase {
return rtnjson return rtnjson
} }
} }
formatOrgs(rtnjson) {
if (rtnjson.length > 0) {
for (let val of rtnjson) {
if (!val.children) {
val.children = []
}
this.formatOrgs(val.children || [])
}
}
}
} }
module.exports = CompanyService; module.exports = CompanyService;
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