提交 c03f5474 authored 作者: mooncake's avatar mooncake

jlist

上级 e3189e71
......@@ -291,13 +291,18 @@ func (x *ODao[T]) GetSliceByIDs(ctx context.Context, ids []xsf.ID) (rs []*T, err
return rs, nil
}
type IParams interface {
type IPageParams interface {
query.IPagination
TableName() string
Unscoped() bool
}
func (x *ODao[T]) Page(ctx context.Context, where IParams) (rs []*T, total int64, err error) {
type IListParams interface {
TableName() string
Unscoped() bool
}
func (x *ODao[T]) Page(ctx context.Context, where IPageParams) (rs []*T, total int64, err error) {
if ginCtx, err := ctxUtils.GetGinCtx(ctx); err == nil && ginCtx != nil {
ginCtx.Set(ctxUtils.KeyApiType, "page")
pagination := query.Pagination{
......@@ -322,7 +327,7 @@ func (x *ODao[T]) Page(ctx context.Context, where IParams) (rs []*T, total int64
return rs, total, nil
}
func (x *ODao[T]) JPage(ctx context.Context, where IParams, result any, resultType any) (total int64, err error) {
func (x *ODao[T]) JPage(ctx context.Context, where IPageParams, result any, resultType any) (total int64, err error) {
condition := x.DB().WithContext(ctx).Model(new(T)).Scopes(x.MakeCondition(where))
if where.Unscoped() {
condition = condition.Unscoped()
......@@ -340,6 +345,24 @@ func (x *ODao[T]) JPage(ctx context.Context, where IParams, result any, resultTy
return total, nil
}
func (x *ODao[T]) JList(ctx context.Context, where IListParams, result any, resultType any) (total int64, err error) {
condition := x.DB().WithContext(ctx).Model(new(T)).Scopes(x.MakeCondition(where))
if where.Unscoped() {
condition = condition.Unscoped()
}
if err = condition.Limit(-1).Offset(-1).Count(&total).Error; err != nil {
return total, xerror.New(err.Error())
}
if total == 0 {
return total, nil
}
fields := GetGormTags(resultType)
if err = condition.Select(strings.Join(fields, ",")).Scan(result).Error; err != nil {
return total, xerror.New(err.Error())
}
return total, nil
}
func (x *ODao[T]) GetPageByColumns(ctx context.Context, params *query.Params) (rs []*T, total int64, err error) {
queryStr, args, err := params.ConvertToGormConditions()
if err != nil {
......@@ -536,7 +559,7 @@ func (x *ODao[T]) GetMapByIDs(ctx context.Context, ids []xsf.ID) (itemMap map[xs
return itemMap, nil
}
func (x *ODao[T]) CalcCondition(ctx context.Context, where IParams, columns string, ret any) (err error) {
func (x *ODao[T]) CalcCondition(ctx context.Context, where IPageParams, columns string, ret any) (err error) {
var t T
condition := x.DB().WithContext(ctx).Model(&t).Select(columns).Order("").Scopes(x.MakeCondition(where))
if where.Unscoped() {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论