Browse Source

修改查询规则

yjp 1 year ago
parent
commit
6830c52bdd

+ 2 - 0
convenient/domain/query_rule/api.go

@@ -149,6 +149,7 @@ func (simple *Simple) bind(binder *binding.Binder) {
 		Path:             "/queryRule/enable",
 		SendResponseFunc: response.SendMsgResponse,
 		RequestParams:    &EnableQueryRuleJsonBody{},
+		Objects:          []domain.Object{&Entity{}},
 		ServiceFunc: func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (any, error) {
 			dbExecutor := i.DBExecutor()
 
@@ -207,6 +208,7 @@ func (simple *Simple) bind(binder *binding.Binder) {
 		Path:             "/queryRule/disable",
 		SendResponseFunc: response.SendMsgResponse,
 		RequestParams:    &EnableQueryRuleJsonBody{},
+		Objects:          []domain.Object{&Entity{}},
 		ServiceFunc: func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (any, error) {
 			dbExecutor := i.DBExecutor()
 

+ 1 - 1
convenient/domain/query_rule/entity.go

@@ -28,7 +28,7 @@ var fieldMap = map[string]string{
 
 type Entity struct {
 	entity.Base
-	Scope      string `sqlmapping:"column:scope;key;notUpdate;" sqlresult:"column:scope;" check:"required,lte=256"`
+	Scope      string `sqlmapping:"column:scope;notUpdate;" sqlresult:"column:scope;" check:"required,lte=256"`
 	DomainName string `sqlmapping:"column:domain_name;notUpdate;" sqlresult:"column:domain_name;" check:"required,lte=256"`
 	Rule       string `sqlmapping:"column:rule;notUpdate;" sqlresult:"column:rule;" check:"required"`
 	Enabled    bool   `sqlresult:"column:enabled;" sqlresult:"column:enabled;"`

+ 10 - 4
convenient/domain/query_rule/query_rule_parser.go

@@ -117,8 +117,11 @@ func HasRule(dbSchema string, scope string, domainName string, i *infrastructure
 	dbExecutor := i.DBExecutor()
 
 	return database.CheckExist(dbExecutor, &sql.CheckExistExecuteParams{
-		TableName:  domain.TableName(dbSchema, &Entity{}),
-		Conditions: sql.NewConditions().Equal(ColumnScope, scope).Equal(ColumnDomainName, domainName),
+		TableName: domain.TableName(dbSchema, &Entity{}),
+		Conditions: sql.NewConditions().
+			Equal(ColumnScope, scope).
+			Equal(ColumnDomainName, domainName).
+			Equal(ColumnEnabled, true),
 	})
 }
 
@@ -150,8 +153,11 @@ func getRule(dbSchema string, scope string, domainName string, i *infrastructure
 	dbExecutor := i.DBExecutor()
 
 	result, err := database.QueryOne(dbExecutor, &sql.QueryOneExecuteParams{
-		TableName:  domain.TableName(dbSchema, &Entity{}),
-		Conditions: sql.NewConditions().Equal(ColumnScope, scope).Equal(ColumnDomainName, domainName),
+		TableName: domain.TableName(dbSchema, &Entity{}),
+		Conditions: sql.NewConditions().
+			Equal(ColumnScope, scope).
+			Equal(ColumnDomainName, domainName).
+			Equal(ColumnEnabled, true),
 	})
 	if err != nil {
 		return Rule{}, err

+ 5 - 1
framework/core/infrastructure/database/clause/common.go

@@ -19,9 +19,13 @@ func (clause CommonClause) Clause() (string, error) {
 		return "", nil
 	}
 
-	return string(clause.clause + "\n"), nil
+	return clause.clause + "\n", nil
 }
 
 func (clause CommonClause) Args() []any {
+	if strutils.IsStringEmpty(clause.clause) {
+		return make([]any, 0)
+	}
+
 	return clause.args
 }

+ 1 - 0
framework/core/infrastructure/database/clause/condition.go

@@ -138,6 +138,7 @@ func (conditions *Conditions) formClause(conditionOperator string) (string, erro
 
 func (conditions *Conditions) formArgs() []any {
 	args := make([]any, 0)
+
 	for _, conditionArgs := range conditions.args {
 		if conditionArgs == nil {
 			continue

+ 4 - 0
framework/core/infrastructure/database/clause/where.go

@@ -31,5 +31,9 @@ func (clause *Where) Clause() (string, error) {
 }
 
 func (clause *Where) Args() []any {
+	if clause.condition == nil {
+		return make([]any, 0)
+	}
+
 	return clause.condition.Args()
 }