diff --git a/dsBaseRpc/RpcService/BaseRole/BaseRoleDao/BaseRoleDao.go b/dsBaseRpc/RpcService/BaseRole/BaseRoleDao/BaseRoleDao.go index 5d283c37..1a08bf6e 100644 --- a/dsBaseRpc/RpcService/BaseRole/BaseRoleDao/BaseRoleDao.go +++ b/dsBaseRpc/RpcService/BaseRole/BaseRoleDao/BaseRoleDao.go @@ -77,3 +77,19 @@ func DeleteRoleAppRepleation(roleId string) { sql := `update t_base_role_app set b_use=-2 where rold_id=? and b_use=1` db.SQL(sql, roleId).Execute() } + +//获取角色与系统的关联关系 +func GetRoleAppRepleation(roleId string) ([]map[string]interface{}, error) { + var myBuilder = builder.Dialect(builder.MYSQL).Select("t1.*,t2.app_name").From("t_base_role_app as t1") + myBuilder.InnerJoin("t_app_base as t2","t1.app_id=t2.app_id") + myBuilder.And(builder.Eq{"t1.app_id": roleId}) + myBuilder.And(builder.Eq{"t1.b_use": 1}) + //获取拼接完成的SQL语句 + sql, err := myBuilder.ToBoundSQL() + if err != nil { + return nil, err + } + //调用多查询字段通用方法 + list, _, err := SqlKit.Query(sql) + return list, err +} diff --git a/dsBaseRpc/RpcService/BaseRole/BaseRoleService/BaseRoleService.go b/dsBaseRpc/RpcService/BaseRole/BaseRoleService/BaseRoleService.go index 318d2d56..0145d9d1 100644 --- a/dsBaseRpc/RpcService/BaseRole/BaseRoleService/BaseRoleService.go +++ b/dsBaseRpc/RpcService/BaseRole/BaseRoleService/BaseRoleService.go @@ -27,6 +27,9 @@ func (s *Rpc) GetBaseRole(ctx context.Context, in *BaseRoleProto.ModelArg) (*Bas var reply BaseRoleProto.Reply //通用获取单条 list := SqlKit.QueryByIds([]string{in.RoleId}, "t_base_role") + //扩展它的与对应系统AppIds的关系 + releation, _ := BaseRoleDao.GetRoleAppRepleation(list[0]["role_id"].(string)) + list[0]["app_info"] = releation //将结果序列化 reply.Success = true reply.Count = 1 @@ -79,7 +82,7 @@ func (s *Rpc) AddBaseRole(ctx context.Context, in *BaseRoleProto.ModelArg) (*Bas // 增加角色与系统的关联关系 for i := 0; i < len(in.AppIds); i++ { model2 := new(models.TBaseRoleApp) - model2.Id=CommonUtil.GetUUID() + model2.Id = CommonUtil.GetUUID() model2.AppId = in.AppIds[i] model2.RoleId = model.RoleId model2.BUse = 1 @@ -139,7 +142,6 @@ func (s *Rpc) UpdateBaseRole(ctx context.Context, in *BaseRoleProto.ModelArg) (* model := new(models.TBaseRole) model.RoleId = in.RoleId model.IdentityId = in.IdentityId - model.BUse = in.BUse _, err := BaseRoleDao.UpdateBaseRole(*model, in.ForceUpdateFields) //错误处理 @@ -149,6 +151,24 @@ func (s *Rpc) UpdateBaseRole(ctx context.Context, in *BaseRoleProto.ModelArg) (* LogUtil.Error(ErrorConst.SqlUpdateError, "执行UpdateBaseRole时发生严重错误:"+err.Error()) return &reply, err } + //对应表需要先删除再插入 + BaseRoleDao.DeleteRoleAppRepleation(model.RoleId) + // 增加角色与系统的关联关系 + for i := 0; i < len(in.AppIds); i++ { + model2 := new(models.TBaseRoleApp) + model2.Id = CommonUtil.GetUUID() + model2.AppId = in.AppIds[i] + model2.RoleId = model.RoleId + model2.BUse = 1 + _, err = BaseRoleDao.AddRoleAppReleation(*model2) + if err != nil { + reply.Success = false + reply.Message = Const.DataBaseActionError + LogUtil.Error(ErrorConst.SqlUpdateError, "执行AddRoleAppReleation时发生严重错误:"+err.Error()) + return &reply, err + } + } + reply.Success = true reply.Message = Const.SuccessDataBaseAction return &reply, nil