mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-23 18:58:09 +00:00
Every import of the module changes, not only the seven packages that
moved out of sdk/pkg: Go requires the major version in the path from v2
on. Both happen in one pass —
go run github.com/go-admin-team/go-admin-core/tools/coreupgrade@v2.0.0 -w -v2 .
go mod tidy
— which is the command the release notes give, run here as a consumer
would run it. 210 imports across 95 files.
The compatibility shims this used are gone in v2, so the paths that
moved had to move: sdk/pkg/captcha, sdk/pkg/jwtauth and its user
package, sdk/pkg/response and sdk/pkg/casbin.
The count of unformatted files is unchanged at 34, none of them touched
by this: the tool reformats a file only if it was already gofmt clean,
so a migration cannot disappear into whitespace.
81 lines
1.7 KiB
Go
81 lines
1.7 KiB
Go
package dto
|
|
|
|
import (
|
|
"github.com/go-admin-team/go-admin-core/v2/tools/search"
|
|
"go-admin/common/global"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type GeneralDelDto struct {
|
|
Id int `uri:"id" json:"id" validate:"required"`
|
|
Ids []int `json:"ids"`
|
|
}
|
|
|
|
func (g GeneralDelDto) GetIds() []int {
|
|
ids := make([]int, 0)
|
|
// Id 此前在 else 分支里被重复追加:仅传 Id 时会得到 [5 5],
|
|
// 同一条记录被执行两次删除
|
|
if g.Id > 0 {
|
|
ids = append(ids, g.Id)
|
|
}
|
|
for _, id := range g.Ids {
|
|
if id > 0 {
|
|
ids = append(ids, id)
|
|
}
|
|
}
|
|
if len(ids) == 0 {
|
|
//方式全部删除
|
|
ids = append(ids, 0)
|
|
}
|
|
return ids
|
|
}
|
|
|
|
type GeneralGetDto struct {
|
|
Id int `uri:"id" json:"id" validate:"required"`
|
|
}
|
|
|
|
func MakeCondition(q interface{}) func(db *gorm.DB) *gorm.DB {
|
|
return func(db *gorm.DB) *gorm.DB {
|
|
condition := &search.GormCondition{
|
|
GormPublic: search.GormPublic{},
|
|
Join: make([]*search.GormJoin, 0),
|
|
}
|
|
search.ResolveSearchQuery(global.Driver, q, condition)
|
|
for _, join := range condition.Join {
|
|
if join == nil {
|
|
continue
|
|
}
|
|
db = db.Joins(join.JoinOn)
|
|
for k, v := range join.Where {
|
|
db = db.Where(k, v...)
|
|
}
|
|
for k, v := range join.Or {
|
|
db = db.Or(k, v...)
|
|
}
|
|
for _, o := range join.Order {
|
|
db = db.Order(o)
|
|
}
|
|
}
|
|
for k, v := range condition.Where {
|
|
db = db.Where(k, v...)
|
|
}
|
|
for k, v := range condition.Or {
|
|
db = db.Or(k, v...)
|
|
}
|
|
for _, o := range condition.Order {
|
|
db = db.Order(o)
|
|
}
|
|
return db
|
|
}
|
|
}
|
|
|
|
func Paginate(pageSize, pageIndex int) func(db *gorm.DB) *gorm.DB {
|
|
return func(db *gorm.DB) *gorm.DB {
|
|
offset := (pageIndex - 1) * pageSize
|
|
if offset < 0 {
|
|
offset = 0
|
|
}
|
|
return db.Offset(offset).Limit(pageSize)
|
|
}
|
|
}
|