mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-09-17 08:46:39 +08:00
perf: 数据库表名硬编码替换
This commit is contained in:
parent
f33e36803a
commit
9feb4c2022
@ -9,15 +9,18 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"hotgo/internal/dao"
|
||||||
|
"math"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/casbin/casbin/v2/model"
|
"github.com/casbin/casbin/v2/model"
|
||||||
"github.com/casbin/casbin/v2/persist"
|
"github.com/casbin/casbin/v2/persist"
|
||||||
"github.com/gogf/gf/v2/database/gdb"
|
"github.com/gogf/gf/v2/database/gdb"
|
||||||
"math"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var defaultTableName = dao.AdminRoleCasbin.Table()
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultTableName = "hg_admin_role_casbin"
|
|
||||||
dropPolicyTableSql = `DROP TABLE IF EXISTS %s`
|
dropPolicyTableSql = `DROP TABLE IF EXISTS %s`
|
||||||
createPolicyTableSql = `
|
createPolicyTableSql = `
|
||||||
CREATE TABLE IF NOT EXISTS %s (
|
CREATE TABLE IF NOT EXISTS %s (
|
||||||
|
@ -7,15 +7,18 @@ package casbin
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"hotgo/internal/consts"
|
||||||
|
"hotgo/internal/dao"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/casbin/casbin/v2"
|
"github.com/casbin/casbin/v2"
|
||||||
"github.com/casbin/casbin/v2/model"
|
"github.com/casbin/casbin/v2/model"
|
||||||
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
|
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
"github.com/gogf/gf/v2/os/gfile"
|
"github.com/gogf/gf/v2/os/gfile"
|
||||||
"github.com/gogf/gf/v2/os/gres"
|
"github.com/gogf/gf/v2/os/gres"
|
||||||
"hotgo/internal/consts"
|
"github.com/gogf/gf/v2/text/gstr"
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -76,10 +79,9 @@ func loadPermissions(ctx context.Context) {
|
|||||||
polices []*Policy
|
polices []*Policy
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
err = g.Model(gstr.Join([]string{dao.AdminRole.Table(), "r"}, " ")).
|
||||||
err = g.Model("hg_admin_role r").
|
LeftJoin(gstr.Join([]string{dao.AdminRoleMenu.Table(), "rm"}, " "), "r.id=rm.role_id").
|
||||||
LeftJoin("hg_admin_role_menu rm", "r.id=rm.role_id").
|
LeftJoin(gstr.Join([]string{dao.AdminMenu.Table(), "m"}, " "), "rm.menu_id=m.id").
|
||||||
LeftJoin("hg_admin_menu m", "rm.menu_id=m.id").
|
|
||||||
Fields("r.key,m.permissions").
|
Fields("r.key,m.permissions").
|
||||||
Where("r.status", consts.StatusEnabled).
|
Where("r.status", consts.StatusEnabled).
|
||||||
Where("m.status", consts.StatusEnabled).
|
Where("m.status", consts.StatusEnabled).
|
||||||
|
@ -8,10 +8,12 @@ package hgorm
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"hotgo/internal/consts"
|
"hotgo/internal/consts"
|
||||||
|
"hotgo/internal/dao"
|
||||||
"hotgo/utility/tree"
|
"hotgo/utility/tree"
|
||||||
|
|
||||||
"github.com/gogf/gf/v2/errors/gerror"
|
"github.com/gogf/gf/v2/errors/gerror"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/gogf/gf/v2/text/gstr"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TenantRelation 租户关系
|
// TenantRelation 租户关系
|
||||||
@ -24,8 +26,9 @@ type TenantRelation struct {
|
|||||||
|
|
||||||
// GetTenantRelation 获取租户关系
|
// GetTenantRelation 获取租户关系
|
||||||
func GetTenantRelation(ctx context.Context, memberId int64) (tr *TenantRelation, err error) {
|
func GetTenantRelation(ctx context.Context, memberId int64) (tr *TenantRelation, err error) {
|
||||||
data, err := g.Model("hg_admin_member u").Ctx(ctx).
|
|
||||||
LeftJoin("hg_admin_dept d", "u.dept_id=d.id").
|
data, err := g.Model(gstr.Join([]string{dao.AdminMember.Table(), "u"}, " ")).Ctx(ctx).
|
||||||
|
LeftJoin(gstr.Join([]string{dao.AdminDept.Table(), "d"}, " "), "u.dept_id=d.id").
|
||||||
Fields("u.tree,d.type").
|
Fields("u.tree,d.type").
|
||||||
Where("u.id", memberId).One()
|
Where("u.id", memberId).One()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -40,8 +43,8 @@ func GetTenantRelation(ctx context.Context, memberId int64) (tr *TenantRelation,
|
|||||||
ids := tree.GetIds(data["tree"].String())
|
ids := tree.GetIds(data["tree"].String())
|
||||||
|
|
||||||
getRelationId := func(deptType string) (int64, error) {
|
getRelationId := func(deptType string) (int64, error) {
|
||||||
id, err := g.Model("hg_admin_member u").Ctx(ctx).
|
id, err := g.Model(gstr.Join([]string{dao.AdminMember.Table(), "u"}, " ")).Ctx(ctx).
|
||||||
LeftJoin("hg_admin_dept d", "u.dept_id=d.id").
|
LeftJoin(gstr.Join([]string{dao.AdminDept.Table(), "d"}, " "), "u.dept_id=d.id").
|
||||||
Fields("u.id").
|
Fields("u.id").
|
||||||
WhereIn("u.id", ids).Where("d.type", deptType).
|
WhereIn("u.id", ids).Where("d.type", deptType).
|
||||||
OrderAsc("u.level"). // 确保是第一关系
|
OrderAsc("u.level"). // 确保是第一关系
|
||||||
|
Loading…
Reference in New Issue
Block a user