Browse Source

修改回调格式

yjp 1 month ago
parent
commit
3bf9cd1c94
1 changed files with 10 additions and 7 deletions
  1. 10 7
      convenient/domain/query_rule/query_rule.go

+ 10 - 7
convenient/domain/query_rule/query_rule.go

@@ -69,7 +69,7 @@ type FormAdditionalSelectClausesFunc func(queryParams AdvanceQueryParams) ([]str
 type FormAdditionalFromFunc func(queryParams AdvanceQueryParams) ([]clause.Clause, error)
 type FormAdditionalConditionsFunc func(queryParams AdvanceQueryParams) (clause.Clause, error)
 type FormOtherClausesFunc func(queryParams AdvanceQueryParams) ([]clause.Clause, error)
-type PostQueryFunc[O any] func(queryParams AdvanceQueryParams, infos []O, i *infrastructure.Infrastructure) ([]O, error)
+type PostQueryFunc[O any] func(queryParams AdvanceQueryParams, results []sql.Result, i *infrastructure.Infrastructure) ([]O, int64, error)
 
 type AddUseQueryRuleQueryRouteParams[O any] struct {
 	DBSchema                        string
@@ -233,23 +233,26 @@ func AddUseQueryRuleQueryRoute[O any](binder *binding.Binder, addParams *AddUseQ
 			}
 
 			infos := make([]O, 0)
-			err = sql.ParseSqlResult(results, &infos)
-			if err != nil {
-				return errResponse, err
-			}
+			totalCount := countResults[0].ColumnValueInt64("total")
 
 			if addParams.PostQueryFunc != nil {
-				innerInfos, err := addParams.PostQueryFunc(queryParams, infos, i)
+				innerInfos, innerTotalCount, err := addParams.PostQueryFunc(queryParams, results, i)
 				if err != nil {
 					return errResponse, err
 				}
 
 				infos = innerInfos
+				totalCount = innerTotalCount
+			}
+
+			err = sql.ParseSqlResult(results, &infos)
+			if err != nil {
+				return errResponse, err
 			}
 
 			return response.InfosData[O]{
 				Infos:      infos,
-				TotalCount: countResults[0].ColumnValueInt64("total"),
+				TotalCount: totalCount,
 				PageNo:     advanceQueryParams.GetPageNo(),
 			}, nil
 		},