提交 290e6fd6 authored 作者: mooncake9527's avatar mooncake9527

new dao

上级 f1fff87e
...@@ -55,6 +55,12 @@ type XDB struct { ...@@ -55,6 +55,12 @@ type XDB struct {
Schema string Schema string
} }
func NewDB(schema string) *XDB {
return &XDB{
Schema: schema,
}
}
func (x XDB) DB() *sgorm.DB { func (x XDB) DB() *sgorm.DB {
return DB(x.Schema) return DB(x.Schema)
} }
......
...@@ -37,6 +37,13 @@ type ODao[T ocache.IID] struct { ...@@ -37,6 +37,13 @@ type ODao[T ocache.IID] struct {
Sf *singleflight.Group Sf *singleflight.Group
} }
func NewDao[T ocache.IID](schema string) *ODao[T] {
return &ODao[T]{
XDB: database.NewDB(schema),
Sf: new(singleflight.Group),
}
}
func (x *ODao[T]) deleteCache(ctx context.Context, id xsf.ID) error { func (x *ODao[T]) deleteCache(ctx context.Context, id xsf.ID) error {
if id <= 0 { if id <= 0 {
return nil return nil
......
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/go-redsync/redsync/v4" "github.com/go-redsync/redsync/v4"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/request"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response" "gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/gocron" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/gocron"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
...@@ -125,7 +126,7 @@ func (x *cronJobController) Create(c *gin.Context) { ...@@ -125,7 +126,7 @@ func (x *cronJobController) Create(c *gin.Context) {
} }
func (x *cronJobController) DeleteByID(c *gin.Context) { func (x *cronJobController) DeleteByID(c *gin.Context) {
in := &types.BaseIDReq{} in := &request.BaseIDReq{}
if err := x.Bind(c, in); err != nil { if err := x.Bind(c, in); err != nil {
response.Error(c, err) response.Error(c, err)
return return
...@@ -151,7 +152,7 @@ func (x *cronJobController) UpdateByID(c *gin.Context) { ...@@ -151,7 +152,7 @@ func (x *cronJobController) UpdateByID(c *gin.Context) {
} }
func (x *cronJobController) GetByID(c *gin.Context) { func (x *cronJobController) GetByID(c *gin.Context) {
in := &types.BaseIDReq{} in := &request.BaseIDReq{}
if err := x.Bind(c, in); err != nil { if err := x.Bind(c, in); err != nil {
response.Error(c, err) response.Error(c, err)
return return
......
// Package types define the structure of request parameters and return results in this package
package types
import (
"math"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
)
var (
InvalidParams = errcode.InvalidParams
)
const (
LastIDLimit = 1000
)
var (
LastIDMax = xsf.ParseInt64(math.MaxInt64)
)
type Result struct {
Code int `json:"code" form:"code" example:"1" validate:"required"` // 返回码 return code
Msg string `json:"message" form:"message" example:"OK" validate:"required"` // 提示信息 information description
Data interface{} `json:"data" form:"data"` // 数据 data
}
type Params struct {
PageIndex int `json:"page" form:"page" validate:"required" example:"1"` //
PageSize int `json:"pageSize" form:"pageSize" validate:"required" example:"10"` //
Sort string `json:"sort,omitempty" form:"sort,omitempty" validate:"required" example:"id"` //
Columns []Column `json:"columns,omitempty" form:"columns,omitempty"` //
}
type Column struct {
Name string `json:"name" form:"name" validate:"required" example:"id"`
Exp string `json:"exp" form:"exp" validate:"required" example:"="` // 表达式, 默认 = , 有 =, !=, >, >=, <, <=, like
Value interface{} `json:"value" form:"value" validate:"required" example:"102"` //
Logic string `json:"logic" form:"logic" example:"and"` // 逻辑, 默认 "and", 支持 &, and, ||, or
}
type Conditions struct {
Columns []Column `json:"columns" form:"columns"` // columns info
}
type BaseReply struct {
response.Result
}
type BaseIDReq struct {
ID xsf.ID `json:"id" form:"id" swaggertype:"string" validate:"required" example:"1"` // id
}
func (x *BaseIDReq) Valid() error {
if x.ID <= 0 {
return xerror.NewC(InvalidParams.Code(), "参数[id]不合法")
}
return nil
}
// BaseIDsReq request params
type BaseIDsReq struct {
IDs []xsf.ID `json:"ids" swaggertype:"array,string" form:"ids" validate:"required" example:"1" binding:"min=1"` // id list
}
func (x BaseIDsReq) Valid() error {
if len(x.IDs) == 0 {
return xerror.NewC(InvalidParams.Code(), "参数[ids]不能为空")
}
return nil
}
type BasePageReply struct {
List []any `json:"list" form:"list"` //
Total int64 `json:"total" form:"total" example:"2000"` //
}
type BaseListReply struct {
List []any `json:"list" form:"list"` //
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论