Commit e332fee1 by v_vjyjiang

d

parent b08fee79
...@@ -5,7 +5,7 @@ class CompanyService extends ServiceBase { ...@@ -5,7 +5,7 @@ class CompanyService extends ServiceBase {
constructor() { constructor() {
super("common", ServiceBase.getDaoName(CompanyService)); super("common", ServiceBase.getDaoName(CompanyService));
} }
async getMyApps(appids, isSuper) { async getMyApps (appids, isSuper) {
let appsrtn = null let appsrtn = null
if (isSuper) { if (isSuper) {
appsrtn = this.db.models.app.findAll({ appsrtn = this.db.models.app.findAll({
...@@ -24,14 +24,14 @@ class CompanyService extends ServiceBase { ...@@ -24,14 +24,14 @@ class CompanyService extends ServiceBase {
} }
return appsrtn return appsrtn
} }
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
}) })
} }
async setOrgs(p, cmk) { async setOrgs (p, cmk) {
var self = this var self = this
let curNodeData = p.curdata let curNodeData = p.curdata
let opathstr = curNodeData.orgpath let opathstr = curNodeData.orgpath
...@@ -39,20 +39,20 @@ class CompanyService extends ServiceBase { ...@@ -39,20 +39,20 @@ class CompanyService extends ServiceBase {
let strjson = JSON.stringify(p.orgJson) let strjson = JSON.stringify(p.orgJson)
p.id = p.company_id p.id = p.company_id
p.orgJson = strjson p.orgJson = strjson
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 oldopath = oldNodeData.orgpath == '' ? '123456' : oldNodeData.orgpath
} }
return this.db.transaction(async function (t) { return this.db.transaction(async function (t) {
...@@ -60,7 +60,7 @@ class CompanyService extends ServiceBase { ...@@ -60,7 +60,7 @@ class CompanyService extends ServiceBase {
let u = await self.dao.update(p, t) let u = await self.dao.update(p, t)
//更新,还得传输当前节点,查询出当前节点的角色 //更新,还得传输当前节点,查询出当前节点的角色
//按照当前节点的opath查询出所有的用户,更新这些用户的角色信息 //按照当前节点的opath查询出所有的用户,更新这些用户的角色信息
if (curNodeData) { if (curNodeData) {
if (curNodeData.isPosition) { if (curNodeData.isPosition) {
let us = await self.db.models.user.findAll({ where: { opath: { [self.db.Op.like]: `%${oldopath}%` } }, transaction: t }) let us = await self.db.models.user.findAll({ where: { opath: { [self.db.Op.like]: `%${oldopath}%` } }, transaction: t })
...@@ -85,14 +85,14 @@ class CompanyService extends ServiceBase { ...@@ -85,14 +85,14 @@ class CompanyService extends ServiceBase {
//令用户缓存失效 //令用户缓存失效
await self.cacheManager["UserCache"].invalidate(u.userName) await self.cacheManager["UserCache"].invalidate(u.userName)
} }
}else{//不是岗位节点,检查修改后的路径是否和原始一致,如果不一致,那么需要查出原始的用户数据 } else {//不是岗位节点,检查修改后的路径是否和原始一致,如果不一致,那么需要查出原始的用户数据
//把原来的路径替换当前新的code //把原来的路径替换当前新的code
if(opathstr!=oldopath){ if (opathstr != oldopath) {
let us2 = await self.db.models.user.findAll({ where: { opath: { [self.db.Op.like]: `%${oldopath}%` } }, transaction: t }) let us2 = await self.db.models.user.findAll({ where: { opath: { [self.db.Op.like]: `%${oldopath}%` } }, 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)
......
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