Commit 07f9258c by 蒋勇

d

parent b3bda62f
...@@ -15,5 +15,15 @@ class CompanyCtl extends CtlBase { ...@@ -15,5 +15,15 @@ class CompanyCtl extends CtlBase {
let company=await this.cacheManager["CompanyCache"].cache(p.companykey) let company=await this.cacheManager["CompanyCache"].cache(p.companykey)
return system.getResult(company) return system.getResult(company)
} }
async setOrgs(p,q,req){
let orgs=await this.service.setOrgs(p,req.xctx.fromcompanykey)
return system.getResult({orgJson:JSON.parse(companynew.orgJson)})
}
async getOrgs(p,q,req){
let companynew=await this.cacheManager["CompanyCache"].cache(req.xctx.fromcompanykey)
return system.getResult({orgJson:JSON.parse(companynew.orgJson)})
}
} }
module.exports = CompanyCtl; module.exports = CompanyCtl;
...@@ -28,22 +28,21 @@ class DbFactory{ ...@@ -28,22 +28,21 @@ class DbFactory{
} }
async initRelations(){ async initRelations(){
this.db.models.dataauth.belongsTo(this.db.models.user,{constraints: false,}); this.db.models.dataauth.belongsTo(this.db.models.user,{constraints: false,});
/*建立用户和角色之间的关系*/ /*建立用户和角色之间的关系*/
this.db.models.user.belongsToMany(this.db.models.role, {as:"Roles",through: 'p_userrole',constraints: false,}); this.db.models.user.belongsToMany(this.db.models.role, {as:"Roles",through: 'p_userrole',constraints: false,});
this.db.models.role.belongsToMany(this.db.models.user, {as:"Users",through: 'p_userrole',constraints: false,}); this.db.models.role.belongsToMany(this.db.models.user, {as:"Users",through: 'p_userrole',constraints: false,});
/*组织机构自引用*/ /*组织机构自引用*/
this.db.models.org.belongsTo(this.db.models.org,{constraints: false,}); //this.db.models.org.belongsTo(this.db.models.org,{constraints: false,});
this.db.models.org.hasMany(this.db.models.org,{constraints: false,}); //this.db.models.org.hasMany(this.db.models.org,{constraints: false,});
//组织机构和角色是多对多关系,建立兼职岗位,给岗位赋予多个角色,从而同步修改用户的角色 //组织机构和角色是多对多关系,建立兼职岗位,给岗位赋予多个角色,从而同步修改用户的角色
//通过岗位接口去修改用户的角色 //通过岗位接口去修改用户的角色
this.db.models.role.belongsToMany(this.db.models.org,{through: this.db.models.orgrole,constraints: false,}); //this.db.models.role.belongsToMany(this.db.models.org,{through: this.db.models.orgrole,constraints: false,});
this.db.models.org.belongsToMany(this.db.models.role,{through: this.db.models.orgrole,constraints: false,}); //this.db.models.org.belongsToMany(this.db.models.role,{through: this.db.models.orgrole,constraints: false,});
//组织机构和用户是1对多, //组织机构和用户是1对多,
this.db.models.user.belongsTo(this.db.models.org,{constraints: false,}); // this.db.models.user.belongsTo(this.db.models.org,{constraints: false,});
this.db.models.org.hasMany(this.db.models.user,{constraints: false,}); // this.db.models.org.hasMany(this.db.models.user,{constraints: false,});
this.db.models.user.belongsTo(this.db.models.app,{constraints: false,}); this.db.models.user.belongsTo(this.db.models.app,{constraints: false,});
this.db.models.role.belongsTo(this.db.models.app, {constraints: false,}); this.db.models.role.belongsTo(this.db.models.app, {constraints: false,});
...@@ -58,7 +57,7 @@ class DbFactory{ ...@@ -58,7 +57,7 @@ class DbFactory{
this.db.models.user.belongsTo(this.db.models.company,{constraints: false,}); this.db.models.user.belongsTo(this.db.models.company,{constraints: false,});
this.db.models.role.belongsTo(this.db.models.company, {constraints: false,}); this.db.models.role.belongsTo(this.db.models.company, {constraints: false,});
this.db.models.org.belongsTo(this.db.models.company,{constraints: false,}); // this.db.models.org.belongsTo(this.db.models.company,{constraints: false,});
this.db.models.route.belongsTo(this.db.models.app,{constraints: false,}); this.db.models.route.belongsTo(this.db.models.app,{constraints: false,});
......
...@@ -5,5 +5,33 @@ class CompanyService extends ServiceBase { ...@@ -5,5 +5,33 @@ class CompanyService extends ServiceBase {
constructor() { constructor() {
super("common", ServiceBase.getDaoName(CompanyService)); super("common", ServiceBase.getDaoName(CompanyService));
} }
async setOrgs(p,cmk) {
var self=this
return this.db.transaction(async function (t) {
let strjson = JSON.stringify(p.orgJson)
p.id = p.company_id
p.orgJson = strjson
//更新组织机构
let u = await self.dao.update(p,t)
//更新,还得传输当前节点,查询出当前节点的角色
//按照当前节点的opath查询出所有的用户,更新这些用户的角色信息
let curNodeData=p.curdata
if(curNodeData && curNodeData.isPosition){
let opathstr=curNodeData.orgpath
let users=await self.db.models.user.findAll({where:{opath:opathstr},transaction:t})
//查询出角色
let roleids=curNodeData.roles
var roles = await self.roleDao.model.findAll({ where: { id: { [self.db.Op.in]: roleids }, app_id: p.app_id, company_id: p.company_id }, transaction: t });
users.forEach((u)=>{
await u.setRoles(roles, { transaction: t });
})
}
//用户缓存也要失效
//缓存失效
await self.cacheManager["CompanyCache"].invalidate(cmk)
let companynew = await self.cacheManager["CompanyCache"].cache(cmk)
return {orgJson:JSON.parse(companynew.orgJson)}
})
}
} }
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