|
|
@@ -8,6 +8,7 @@ import (
|
|
|
"git.sxidc.com/go-framework/baize/framwork/domain"
|
|
|
"git.sxidc.com/go-framework/baize/framwork/domain/entity"
|
|
|
"github.com/iancoleman/strcase"
|
|
|
+ "reflect"
|
|
|
)
|
|
|
|
|
|
// Simple 关联的Bind参数
|
|
|
@@ -19,12 +20,6 @@ type Simple[LI any, RI any] struct {
|
|
|
// 右领域实体,注意是Entity类型
|
|
|
Right entity.Entity
|
|
|
|
|
|
- // 左领域实体不是本地的
|
|
|
- LeftRemote bool
|
|
|
-
|
|
|
- // 右领域实体不是本地的
|
|
|
- RightRemote bool
|
|
|
-
|
|
|
// 数据库Schema
|
|
|
Schema string
|
|
|
|
|
|
@@ -59,6 +54,16 @@ func (simple *Simple[LI, RI]) bind(binder *binding.Binder) {
|
|
|
rightTableName := domain.TableName(simple.Schema, simple.Right)
|
|
|
rightRelationColumnName := fmt.Sprintf("%s_id", strcase.ToSnake(simple.Left.DomainCamelName()))
|
|
|
|
|
|
+ leftRemote := false
|
|
|
+ if reflect.TypeOf(new(LI)).Elem().Kind() == reflect.String {
|
|
|
+ leftRemote = true
|
|
|
+ }
|
|
|
+
|
|
|
+ rightRemote := false
|
|
|
+ if reflect.TypeOf(new(RI)).Elem().Kind() == reflect.String {
|
|
|
+ rightRemote = true
|
|
|
+ }
|
|
|
+
|
|
|
if !options.disableLeft {
|
|
|
if !options.disableLeftUpdate {
|
|
|
// 左到右更新
|
|
|
@@ -68,20 +73,20 @@ func (simple *Simple[LI, RI]) bind(binder *binding.Binder) {
|
|
|
RequestParams: simple.LeftUpdateJsonBody,
|
|
|
Objects: []domain.Object{simple.Left},
|
|
|
ServiceFunc: Update(middleTableName,
|
|
|
- simple.LeftRemote, leftTableName, simple.Left.DomainCNName(), leftRelationFieldName, leftRelationColumnName,
|
|
|
- simple.RightRemote, rightTableName, rightRelationColumnName),
|
|
|
+ leftRemote, leftTableName, simple.Left.DomainCNName(), leftRelationFieldName, leftRelationColumnName,
|
|
|
+ rightRemote, rightTableName, rightRelationColumnName),
|
|
|
})
|
|
|
}
|
|
|
|
|
|
if !options.disableLeftQuery {
|
|
|
// 左到右查询
|
|
|
- if simple.RightRemote {
|
|
|
+ if rightRemote {
|
|
|
binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[string]]{
|
|
|
Path: leftDomainPath + rightDomainPath + "/query",
|
|
|
ResponseFunc: response.SendInfosResponse[string],
|
|
|
RequestParams: simple.LeftQueryQueryParams,
|
|
|
Objects: []domain.Object{simple.Left},
|
|
|
- ServiceFunc: QueryToRemote(middleTableName, simple.LeftRemote, leftTableName, leftRelationColumnName, rightRelationColumnName),
|
|
|
+ ServiceFunc: QueryToRemote(middleTableName, leftRemote, leftTableName, leftRelationColumnName, rightRelationColumnName),
|
|
|
})
|
|
|
} else {
|
|
|
binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[RI]]{
|
|
|
@@ -90,7 +95,7 @@ func (simple *Simple[LI, RI]) bind(binder *binding.Binder) {
|
|
|
RequestParams: simple.LeftQueryQueryParams,
|
|
|
Objects: []domain.Object{simple.Left},
|
|
|
ServiceFunc: QueryToExist[RI](middleTableName,
|
|
|
- simple.LeftRemote, leftTableName, leftRelationColumnName,
|
|
|
+ leftRemote, leftTableName, leftRelationColumnName,
|
|
|
rightTableName, rightRelationColumnName),
|
|
|
})
|
|
|
}
|
|
|
@@ -106,20 +111,20 @@ func (simple *Simple[LI, RI]) bind(binder *binding.Binder) {
|
|
|
RequestParams: simple.RightUpdateJsonBody,
|
|
|
Objects: []domain.Object{simple.Right},
|
|
|
ServiceFunc: Update(middleTableName,
|
|
|
- simple.RightRemote, rightTableName, simple.Right.DomainCNName(), rightRelationFieldName, rightRelationColumnName,
|
|
|
- simple.LeftRemote, leftTableName, leftRelationColumnName),
|
|
|
+ rightRemote, rightTableName, simple.Right.DomainCNName(), rightRelationFieldName, rightRelationColumnName,
|
|
|
+ leftRemote, leftTableName, leftRelationColumnName),
|
|
|
})
|
|
|
}
|
|
|
|
|
|
if !options.disableRightQuery {
|
|
|
// 右到左查询
|
|
|
- if simple.LeftRemote {
|
|
|
+ if leftRemote {
|
|
|
binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[string]]{
|
|
|
Path: rightDomainPath + leftDomainPath + "/query",
|
|
|
ResponseFunc: response.SendInfosResponse[string],
|
|
|
RequestParams: simple.RightQueryQueryParams,
|
|
|
Objects: []domain.Object{simple.Right},
|
|
|
- ServiceFunc: QueryToRemote(middleTableName, simple.RightRemote, rightTableName, rightRelationColumnName, leftRelationColumnName),
|
|
|
+ ServiceFunc: QueryToRemote(middleTableName, rightRemote, rightTableName, rightRelationColumnName, leftRelationColumnName),
|
|
|
})
|
|
|
} else {
|
|
|
binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[LI]]{
|
|
|
@@ -128,7 +133,7 @@ func (simple *Simple[LI, RI]) bind(binder *binding.Binder) {
|
|
|
RequestParams: simple.RightQueryQueryParams,
|
|
|
Objects: []domain.Object{simple.Right},
|
|
|
ServiceFunc: QueryToExist[LI](middleTableName,
|
|
|
- simple.RightRemote, rightTableName, rightRelationColumnName,
|
|
|
+ rightRemote, rightTableName, rightRelationColumnName,
|
|
|
leftTableName, leftRelationColumnName),
|
|
|
})
|
|
|
}
|