[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
+25 -24
View File
@@ -5,34 +5,36 @@ import (
"reflect"
"strings"
"git.fsdpf.net/go/condition"
"git.fsdpf.net/go/contracts"
"git.fsdpf.net/go/db"
"git.fsdpf.net/go/utils"
"github.com/samber/do"
"github.com/samber/lo"
"github.com/spf13/cast"
)
type Operation struct {
Uuid string `json:"uuid"`
Name string `json:"name"`
Code string `json:"code"`
Icon string `json:"icon"`
Size string `json:"size"`
Block bool `json:"block"`
Ghost bool `json:"ghost"`
Shape string `json:"shape"`
Type string `json:"type"`
PopConfirm any `json:"popConfirm,omitempty"`
Widget string `json:"widget"`
WidgetType string `json:"widgetType"`
WidgetProps any `json:"widgetProps"`
WidgetSetting any `json:"widgetSetting"`
WidgetContainerSetting any `json:"widgetContainerSetting"`
IsRefresh int `json:"isRefresh"`
NoAuthType string `json:"noAuthType"`
Roles []string `json:"-"`
Children []Operation `json:"children,omitempty"`
AccessCondition contracts.Condition `json:"-"`
Uuid string `json:"uuid"`
Name string `json:"name"`
Code string `json:"code"`
Icon string `json:"icon"`
Size string `json:"size"`
Block bool `json:"block"`
Ghost bool `json:"ghost"`
Shape string `json:"shape"`
Type string `json:"type"`
PopConfirm any `json:"popConfirm,omitempty"`
Widget string `json:"widget"`
WidgetType string `json:"widgetType"`
WidgetProps any `json:"widgetProps"`
WidgetSetting any `json:"widgetSetting"`
WidgetContainerSetting any `json:"widgetContainerSetting"`
IsRefresh int `json:"isRefresh"`
NoAuthType string `json:"noAuthType"`
Roles []string `json:"-"`
Children []Operation `json:"children,omitempty"`
AccessCondition *condition.Condition `json:"-"`
}
type OperationAccess struct {
@@ -42,14 +44,13 @@ type OperationAccess struct {
func (o Operation) ToDBColumn(model contracts.Model, container *do.Injector) (column db.Expression, field reflect.StructField) {
GetOrmConditionByRes := do.MustInvoke[contracts.GetOrmConditionByRes](container)
NewOrmCondition := do.MustInvoke[contracts.NewOrmCondition](container)
uuid := strings.ReplaceAll(o.Uuid, "-", "_")
// 主键
pk := model.GetCode() + "." + model.GetPrimaryKey()
cond := lo.Ternary(o.AccessCondition != nil, o.AccessCondition, NewOrmCondition(contracts.ConditionType_AND, "operation access condition "+uuid))
cond := lo.Ternary(o.AccessCondition != nil, o.AccessCondition, condition.New(condition.Describe("operation access condition "+uuid)))
if c := GetOrmConditionByRes(o.Uuid, "operation access condition "+uuid); c.IsNotEmpty() {
cond.SetCondition(c)
@@ -63,7 +64,7 @@ func (o Operation) ToDBColumn(model contracts.Model, container *do.Injector) (co
// 主键类型
tPkType := reflect.TypeOf("")
if tPk, ok := GetStructField(model.GetQueryFieldsStruct(), model.GetPrimaryKey()); ok {
if tPk, ok := utils.GetStructField(model.GetQueryFieldsStruct(), model.GetPrimaryKey()); ok {
tPkType = tPk.Type
}
field = reflect.StructField{
@@ -149,7 +150,7 @@ func NewOperationAccess(m contracts.Model) OperationAccess {
// 主键类型
tPkType := reflect.String
if tPk, ok := GetStructField(m.GetQueryFieldsStruct(), m.GetPrimaryKey()); ok {
if tPk, ok := utils.GetStructField(m.GetQueryFieldsStruct(), m.GetPrimaryKey()); ok {
switch tPk.Type.Kind() {
case reflect.Int, reflect.Int32, reflect.Int64,
reflect.Uint, reflect.Uint32, reflect.Uint64: