[feat] 重新梳理依赖

This commit is contained in:
2024-05-09 13:15:24 +08:00
parent 9172fb2f34
commit bddd754869
28 changed files with 341 additions and 1075 deletions
+14 -14
View File
@@ -11,8 +11,8 @@ import (
"github.com/samber/lo"
"git.fsdpf.net/go/contracts"
"git.fsdpf.net/go/contracts/support"
"git.fsdpf.net/go/db"
"git.fsdpf.net/go/req"
)
// 资源变更事件
@@ -29,7 +29,7 @@ type ResChangeEventTopicPayload struct {
type ResChangeRecordTopicPayload struct {
Type string // insert | delete | update
User contracts.User // 操作用户
User req.User // 操作用户
Res Resource // 变更资源
Result sql.Result // 执行结果
Old []map[string]any // 旧数据
@@ -92,7 +92,7 @@ func (this Resource) IsSystem() bool {
}
// 资源字段
func (this Resource) GetFields() (result []contracts.ResField) {
func (this Resource) GetFields() (result []req.ResField) {
for _, item := range this.Fields {
result = append(result, item)
}
@@ -100,15 +100,15 @@ func (this Resource) GetFields() (result []contracts.ResField) {
}
// 资源字段
func (this Resource) GetField(code string) (contracts.ResField, bool) {
return lo.Find(this.GetFields(), func(v contracts.ResField) bool {
func (this Resource) GetField(code string) (req.ResField, bool) {
return lo.Find(this.GetFields(), func(v req.ResField) bool {
return v.GetCode() == code
})
}
// 判断资源字段
func (this Resource) HasField(code string) bool {
return lo.SomeBy(this.GetFields(), func(v contracts.ResField) bool {
return lo.SomeBy(this.GetFields(), func(v req.ResField) bool {
return v.GetCode() == code
})
}
@@ -147,7 +147,7 @@ func (this Resource) GetDBDriver() string {
return this.GetDBConn().GetConfig().Driver
}
func (this Resource) GetAuthDBTable(u contracts.User, params ...any) *db.Builder {
func (this Resource) GetAuthDBTable(u req.User, params ...any) *db.Builder {
builder := this.GetDBTable(append(params, u)...)
// 数据权限过滤
@@ -164,7 +164,7 @@ func (this Resource) GetAuthDBTable(u contracts.User, params ...any) *db.Builder
func (this Resource) GetDBTable(params ...any) *db.Builder {
builder := this.GetDBBuilder()
var user contracts.User
var user req.User
alias := this.Code
for _, param := range params {
@@ -173,7 +173,7 @@ func (this Resource) GetDBTable(params ...any) *db.Builder {
builder.Tx = v
case string:
alias = v
case contracts.User:
case req.User:
user = v
}
}
@@ -213,7 +213,7 @@ func (this Resource) GetDBTable(params ...any) *db.Builder {
return builder.Table(string(this.GetTable()), alias)
}
func (this Resource) WithRolesCondition(b *db.Builder, t string, u contracts.User) error {
func (this Resource) WithRolesCondition(b *db.Builder, t string, u req.User) error {
isFullRight := false
isFullNot := false
@@ -268,7 +268,7 @@ func (this Resource) WithRolesCondition(b *db.Builder, t string, u contracts.Use
return db.ToSql()
} else if conditions.IsNotEmpty() {
oOrm := NewOrm(this, nil)
oOrm.SetGlobalParams(support.NewGlobalParam("{}", u))
oOrm.SetGlobalParams(req.NewGlobalParam("{}", u))
db.Where(conditions.ToSql(oOrm.GetModel()))
@@ -322,7 +322,7 @@ func (this Resource) formatSaveValue(data map[string]any) {
}
// 填充保存数据
func (this Resource) fillSaveValue(data map[string]any, u contracts.User, t string) {
func (this Resource) fillSaveValue(data map[string]any, u req.User, t string) {
for _, field := range this.GetFields() {
fCode := field.GetCode()
@@ -401,7 +401,7 @@ func (this Resource) onResEvent(builder *db.Builder) {
}
// 用户事件
func (this Resource) onUserEvent(builder *db.Builder, user contracts.User) {
func (this Resource) onUserEvent(builder *db.Builder, user req.User) {
old := []map[string]any{}
builder.Before(func(b *db.Builder, t string, data ...map[string]any) {
@@ -439,7 +439,7 @@ func (this Resource) onUserEvent(builder *db.Builder, user contracts.User) {
})
}
func NewVirtualResource(pRes Resource, code, name, sql string, fields []ResField) contracts.Resource {
func NewVirtualResource(pRes Resource, code, name, sql string, fields []ResField) req.Resource {
return &Resource{
Uuid: code,
PUuid: pRes.Uuid,