Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xpkg
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
屠思豪
xpkg
Commits
1ab6fb03
提交
1ab6fb03
authored
10月 24, 2025
作者:
mooncake
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
上级
d7fe160a
隐藏空白字符变更
内嵌
并排
正在显示
18 个修改的文件
包含
936 行增加
和
1104 行删除
+936
-1104
init_app.go
application/init_app.go
+1
-1
convert_utils.go
utils/convertutils/convert_utils.go
+0
-0
eg.go
utils/egutils/eg.go
+0
-0
go_utils.go
utils/goutils/go_utils.go
+0
-0
map_utils.go
utils/maputils/map_utils.go
+0
-0
xslice.go
utils/sliceUtils/xslice.go
+13
-3
condition.go
xcommon/base/condition.go
+96
-96
dao.go
xcommon/base/dao.go
+392
-401
query.go
xcommon/base/query.go
+352
-362
controller.go
xcommon/controller.go
+4
-3
cron_job.go
xcron/biz/cron_job.go
+0
-24
cron_job_log.go
xcron/biz/cron_job_log.go
+0
-25
cron_job_record.go
xcron/biz/cron_job_record.go
+0
-24
cron.sql
xcron/cron.sql
+1
-0
cron.go
xcron/ecode/cron.go
+4
-2
cron_job.go
xcron/service/cron_job.go
+37
-67
cron_job_log.go
xcron/service/cron_job_log.go
+18
-48
cron_job_record.go
xcron/service/cron_job_record.go
+18
-48
没有找到文件。
application/init_app.go
浏览文件 @
1ab6fb03
...
@@ -18,7 +18,7 @@ import (
...
@@ -18,7 +18,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
"gitlab.wanzhuangkj.com/tush/xpkg/rd/nacos"
"gitlab.wanzhuangkj.com/tush/xpkg/rd/nacos"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/dxsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/dxsf"
goutils
"gitlab.wanzhuangkj.com/tush/xpkg/utils/go
_
utils"
goutils
"gitlab.wanzhuangkj.com/tush/xpkg/utils/goutils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
...
...
utils/convert
_
utils/convert_utils.go
→
utils/convertutils/convert_utils.go
浏览文件 @
1ab6fb03
File moved
utils/eg
_
utils/eg.go
→
utils/egutils/eg.go
浏览文件 @
1ab6fb03
File moved
utils/go
_
utils/go_utils.go
→
utils/goutils/go_utils.go
浏览文件 @
1ab6fb03
File moved
utils/map
_
utils/map_utils.go
→
utils/maputils/map_utils.go
浏览文件 @
1ab6fb03
File moved
utils/sliceUtils/xslice.go
浏览文件 @
1ab6fb03
...
@@ -232,17 +232,27 @@ func GetIDMapSliceIDs[ID xtype.Key, T IID[ID]](m map[ID][]*T) []ID {
...
@@ -232,17 +232,27 @@ func GetIDMapSliceIDs[ID xtype.Key, T IID[ID]](m map[ID][]*T) []ID {
return
st
.
Slice
()
return
st
.
Slice
()
}
}
func
CompareSlice
[
ID
xtype
.
Key
,
T
IIDTable
[
ID
],
BizSlice
~
[]
*
T
](
ids
[]
ID
,
bizSlice
BizSlice
,
errCode
*
errcode
.
Error
)
error
{
type
ICode
interface
{
Code
()
int
}
func
CompareSlice
[
ID
xtype
.
Key
,
T
IIDTable
[
ID
],
BizSlice
~
[]
*
T
](
ids
[]
ID
,
bizSlice
BizSlice
,
errCode
error
)
error
{
if
len
(
ids
)
==
0
{
if
len
(
ids
)
==
0
{
return
nil
return
nil
}
}
if
len
(
bizSlice
)
<
len
(
ids
)
{
if
len
(
bizSlice
)
<
len
(
ids
)
{
if
len
(
bizSlice
)
==
0
{
if
len
(
bizSlice
)
==
0
{
return
xerror
.
NewC
(
errCode
.
Code
(),
errCode
.
Msg
())
if
v
,
ok
:=
errCode
.
(
*
errcode
.
Error
);
ok
{
return
xerror
.
NewC
(
v
.
Code
(),
v
.
Msg
())
}
return
xerror
.
New
(
errCode
.
Error
())
}
}
deltaIDs
:=
SetDifference
(
ids
,
GetIDs
[
ID
](
bizSlice
))
deltaIDs
:=
SetDifference
(
ids
,
GetIDs
[
ID
](
bizSlice
))
if
len
(
deltaIDs
)
>
0
{
if
len
(
deltaIDs
)
>
0
{
return
xerror
.
NewC
(
errCode
.
Code
(),
fmt
.
Sprintf
(
"%s[ids:%s]"
,
errCode
.
Msg
(),
Join
(
deltaIDs
,
","
)))
if
v
,
ok
:=
errCode
.
(
*
errcode
.
Error
);
ok
{
return
xerror
.
NewC
(
v
.
Code
(),
fmt
.
Sprintf
(
"%s[ids:%s]"
,
v
.
Msg
(),
Join
(
deltaIDs
,
","
)))
}
return
xerror
.
New
(
errCode
.
Error
())
}
}
}
}
return
nil
return
nil
...
...
xcommon/base/condition.go
浏览文件 @
1ab6fb03
package
base
package
base
import
"strings"
//
import "strings"
type
Condition
interface
{
//
type Condition interface {
SetWhere
(
k
string
,
v
[]
interface
{})
//
SetWhere(k string, v []interface{})
SetOr
(
k
string
,
v
[]
interface
{})
//
SetOr(k string, v []interface{})
SetOrder
(
k
string
)
//
SetOrder(k string)
SetJoinOn
(
t
,
on
string
)
Condition
//
SetJoinOn(t, on string) Condition
}
//
}
type
GormCondition
struct
{
//
type GormCondition struct {
GormPublic
//
GormPublic
Join
[]
*
GormJoin
//
Join []*GormJoin
}
//
}
type
GormPublic
struct
{
//
type GormPublic struct {
Where
map
[
string
][]
interface
{}
//
Where map[string][]interface{}
Order
[]
string
//
Order []string
Or
map
[
string
][]
interface
{}
//
Or map[string][]interface{}
}
//
}
type
GormJoin
struct
{
//
type GormJoin struct {
Type
string
//
Type string
JoinOn
string
//
JoinOn string
GormPublic
//
GormPublic
}
//
}
func
(
e
*
GormJoin
)
SetJoinOn
(
t
,
on
string
)
Condition
{
//
func (e *GormJoin) SetJoinOn(t, on string) Condition {
return
nil
//
return nil
}
//
}
func
(
e
*
GormPublic
)
SetWhere
(
k
string
,
v
[]
interface
{})
{
//
func (e *GormPublic) SetWhere(k string, v []interface{}) {
if
e
.
Where
==
nil
{
//
if e.Where == nil {
e
.
Where
=
make
(
map
[
string
][]
interface
{})
//
e.Where = make(map[string][]interface{})
}
//
}
e
.
Where
[
k
]
=
v
//
e.Where[k] = v
}
//
}
func
(
e
*
GormPublic
)
SetOr
(
k
string
,
v
[]
interface
{})
{
//
func (e *GormPublic) SetOr(k string, v []interface{}) {
if
e
.
Or
==
nil
{
//
if e.Or == nil {
e
.
Or
=
make
(
map
[
string
][]
interface
{})
//
e.Or = make(map[string][]interface{})
}
//
}
e
.
Or
[
k
]
=
v
//
e.Or[k] = v
}
//
}
func
(
e
*
GormPublic
)
SetOrder
(
k
string
)
{
//
func (e *GormPublic) SetOrder(k string) {
if
e
.
Order
==
nil
{
//
if e.Order == nil {
e
.
Order
=
make
([]
string
,
0
)
//
e.Order = make([]string, 0)
}
//
}
e
.
Order
=
append
(
e
.
Order
,
k
)
//
e.Order = append(e.Order, k)
}
//
}
func
(
e
*
GormCondition
)
SetJoinOn
(
t
,
on
string
)
Condition
{
//
func (e *GormCondition) SetJoinOn(t, on string) Condition {
if
e
.
Join
==
nil
{
//
if e.Join == nil {
e
.
Join
=
make
([]
*
GormJoin
,
0
)
//
e.Join = make([]*GormJoin, 0)
}
//
}
join
:=
&
GormJoin
{
//
join := &GormJoin{
Type
:
t
,
//
Type: t,
JoinOn
:
on
,
//
JoinOn: on,
GormPublic
:
GormPublic
{},
//
GormPublic: GormPublic{},
}
//
}
e
.
Join
=
append
(
e
.
Join
,
join
)
//
e.Join = append(e.Join, join)
return
join
//
return join
}
//
}
type
resolveSearchTag
struct
{
//
type resolveSearchTag struct {
Type
string
//
Type string
Column
string
//
Column string
Table
string
//
Table string
On
[]
string
//
On []string
Join
string
//
Join string
}
//
}
// makeTag 解析search的tag标签
//
//
makeTag 解析search的tag标签
func
makeTag
(
tag
string
)
*
resolveSearchTag
{
//
func makeTag(tag string) *resolveSearchTag {
r
:=
&
resolveSearchTag
{}
//
r := &resolveSearchTag{}
tags
:=
strings
.
Split
(
tag
,
";"
)
//
tags := strings.Split(tag, ";")
var
ts
[]
string
//
var ts []string
for
_
,
t
:=
range
tags
{
//
for _, t := range tags {
ts
=
strings
.
Split
(
t
,
":"
)
//
ts = strings.Split(t, ":")
if
len
(
ts
)
==
0
{
//
if len(ts) == 0 {
continue
//
continue
}
//
}
switch
ts
[
0
]
{
//
switch ts[0] {
case
"type"
:
//
case "type":
if
len
(
ts
)
>
1
{
//
if len(ts) > 1 {
r
.
Type
=
ts
[
1
]
//
r.Type = ts[1]
}
//
}
case
"column"
:
//
case "column":
if
len
(
ts
)
>
1
{
//
if len(ts) > 1 {
r
.
Column
=
ts
[
1
]
//
r.Column = ts[1]
}
//
}
case
"table"
:
//
case "table":
if
len
(
ts
)
>
1
{
//
if len(ts) > 1 {
r
.
Table
=
ts
[
1
]
//
r.Table = ts[1]
}
//
}
case
"on"
:
//
case "on":
if
len
(
ts
)
>
1
{
//
if len(ts) > 1 {
r
.
On
=
ts
[
1
:
]
//
r.On = ts[1:]
}
//
}
case
"join"
:
//
case "join":
if
len
(
ts
)
>
1
{
//
if len(ts) > 1 {
r
.
Join
=
ts
[
1
]
//
r.Join = ts[1]
}
//
}
}
//
}
}
//
}
return
r
//
return r
}
//
}
xcommon/base/dao.go
浏览文件 @
1ab6fb03
package
base
package
base
import
(
// const (
"context"
// OrderIgnoreCount = "ignore_count"
"database/sql"
// )
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/xerrors/xerror"
// type IBaseDao interface {
// DB() *gorm.DB
"gorm.io/gorm"
// Create(ctx context.Context, m any) error
)
// CreateTx(ctx context.Context, tx *gorm.DB, model any) error
// Save(ctx context.Context, model any) error
const
(
// SaveTx(ctx context.Context, tx *gorm.DB, model any) error
OrderIgnoreCount
=
"ignore_count"
)
// UpdateWhere(ctx context.Context, model any, where any, updates map[string]any) error
// UpdateWhereTx(ctx context.Context, tx *gorm.DB, model any, where any, updates map[string]any) error
type
IBaseDao
interface
{
// UpdateWhereModel(ctx context.Context, where any, updates any) error
DB
()
*
gorm
.
DB
// UpdateWhereModelTx(ctx context.Context, tx *gorm.DB, where any, updates any) error
Create
(
ctx
context
.
Context
,
m
any
)
error
// UpdateById(ctx context.Context, model any) error
CreateTx
(
ctx
context
.
Context
,
tx
*
gorm
.
DB
,
model
any
)
error
// UpdateByIdTx(ctx context.Context, tx *gorm.DB, model any) error
Save
(
ctx
context
.
Context
,
model
any
)
error
// DelModel(ctx context.Context, model any) error
SaveTx
(
ctx
context
.
Context
,
tx
*
gorm
.
DB
,
model
any
)
error
// DelWhereTx(ctx context.Context, tx *gorm.DB, model any) error
// DelWhereMap(ctx context.Context, model any, where map[string]any) error
UpdateWhere
(
ctx
context
.
Context
,
model
any
,
where
any
,
updates
map
[
string
]
any
)
error
// DelWhereMapTx(ctx context.Context, tx *gorm.DB, model any, where map[string]any) error
UpdateWhereTx
(
ctx
context
.
Context
,
tx
*
gorm
.
DB
,
model
any
,
where
any
,
updates
map
[
string
]
any
)
error
// DelIds(ctx context.Context, model any, ids any) error
UpdateWhereModel
(
ctx
context
.
Context
,
where
any
,
updates
any
)
error
// DelIdsTx(ctx context.Context, tx *gorm.DB, model any, ids any) error
UpdateWhereModelTx
(
ctx
context
.
Context
,
tx
*
gorm
.
DB
,
where
any
,
updates
any
)
error
// Get(ctx context.Context, model any, conds ...interface{}) error
UpdateById
(
ctx
context
.
Context
,
model
any
)
error
// GetByWhere(ctx context.Context, where any, models any) error
UpdateByIdTx
(
ctx
context
.
Context
,
tx
*
gorm
.
DB
,
model
any
)
error
// GetByMap(ctx context.Context, where map[string]any, models any) error
DelModel
(
ctx
context
.
Context
,
model
any
)
error
DelWhereTx
(
ctx
context
.
Context
,
tx
*
gorm
.
DB
,
model
any
)
error
// PageQuery(pageSize int, cb func(pageSize, offset int, size *int) error) error
DelWhereMap
(
ctx
context
.
Context
,
model
any
,
where
map
[
string
]
any
)
error
// Transaction(fc func(tx *gorm.DB) error, opts ...*sql.TxOptions) error
DelWhereMapTx
(
ctx
context
.
Context
,
tx
*
gorm
.
DB
,
model
any
,
where
map
[
string
]
any
)
error
// }
DelIds
(
ctx
context
.
Context
,
model
any
,
ids
any
)
error
DelIdsTx
(
ctx
context
.
Context
,
tx
*
gorm
.
DB
,
model
any
,
ids
any
)
error
// func NewDao(db *gorm.DB) *BaseDao {
Get
(
ctx
context
.
Context
,
model
any
,
conds
...
interface
{})
error
// return &BaseDao{
GetByWhere
(
ctx
context
.
Context
,
where
any
,
models
any
)
error
// db: db,
GetByMap
(
ctx
context
.
Context
,
where
map
[
string
]
any
,
models
any
)
error
// }
// }
PageQuery
(
pageSize
int
,
cb
func
(
pageSize
,
offset
int
,
size
*
int
)
error
)
error
Transaction
(
fc
func
(
tx
*
gorm
.
DB
)
error
,
opts
...*
sql
.
TxOptions
)
error
// type BaseDao struct {
}
// db *gorm.DB
// }
func
NewDao
(
db
*
gorm
.
DB
)
*
BaseDao
{
return
&
BaseDao
{
// func (x *BaseDao) DB() *gorm.DB {
db
:
db
,
// return x.db
}
// }
}
// func (x *BaseDao) Transaction(fc func(tx *gorm.DB) error, opts ...*sql.TxOptions) error {
type
BaseDao
struct
{
// err := x.DB().Transaction(fc, opts...)
db
*
gorm
.
DB
// if err != nil {
}
// return xerror.New(err.Error())
// }
func
(
x
*
BaseDao
)
DB
()
*
gorm
.
DB
{
// return nil
return
x
.
db
// }
}
// func (x *BaseDao) PageQuery(pageSize int, cb func(pageSize, offset int, size *int) error) error {
func
(
x
*
BaseDao
)
Transaction
(
fc
func
(
tx
*
gorm
.
DB
)
error
,
opts
...*
sql
.
TxOptions
)
error
{
// pageIndex := 1
err
:=
x
.
DB
()
.
Transaction
(
fc
,
opts
...
)
// size := 0
if
err
!=
nil
{
// if pageSize == 0 {
return
xerror
.
New
(
err
.
Error
())
// pageSize = 1000
}
// }
return
nil
// for {
}
// offset := (pageIndex - 1) * pageSize
// if err := cb(pageSize, offset, &size); err != nil {
func
(
x
*
BaseDao
)
PageQuery
(
pageSize
int
,
cb
func
(
pageSize
,
offset
int
,
size
*
int
)
error
)
error
{
// return err
pageIndex
:=
1
// }
size
:=
0
// if size == 0 || size < pageSize {
if
pageSize
==
0
{
// break
pageSize
=
1000
// }
}
// pageIndex++
for
{
// }
offset
:=
(
pageIndex
-
1
)
*
pageSize
// return nil
if
err
:=
cb
(
pageSize
,
offset
,
&
size
);
err
!=
nil
{
// }
return
err
}
// /*
if
size
==
0
||
size
<
pageSize
{
// * 创建 结构体 m
break
// */
}
// func (s *BaseDao) Create(ctx context.Context, m any) error {
pageIndex
++
// if err := s.DB().WithContext(ctx).Create(m).Error; err != nil {
}
// return xerror.New(err.Error())
return
nil
// }
}
// return nil
// }
/*
* 创建 结构体 m
// func (s *BaseDao) CreateTx(ctx context.Context, tx *gorm.DB, model any) error {
*/
// if err := tx.WithContext(ctx).Create(model).Error; err != nil {
func
(
s
*
BaseDao
)
Create
(
ctx
context
.
Context
,
m
any
)
error
{
// return xerror.New(err.Error())
if
err
:=
s
.
DB
()
.
WithContext
(
ctx
)
.
Create
(
m
)
.
Error
;
err
!=
nil
{
// }
return
xerror
.
New
(
err
.
Error
())
// return nil
}
// }
return
nil
}
// /*
// * 更新整个模型 结构体model 注意空值
func
(
s
*
BaseDao
)
CreateTx
(
ctx
context
.
Context
,
tx
*
gorm
.
DB
,
model
any
)
error
{
// */
if
err
:=
tx
.
WithContext
(
ctx
)
.
Create
(
model
)
.
Error
;
err
!=
nil
{
// func (s *BaseDao) Save(ctx context.Context, model any) error {
return
xerror
.
New
(
err
.
Error
())
// if err := s.DB().WithContext(ctx).Save(model).Error; err != nil {
}
// return xerror.New(err.Error())
return
nil
// }
}
// return nil
// }
/*
* 更新整个模型 结构体model 注意空值
// func (s *BaseDao) SaveTx(ctx context.Context, tx *gorm.DB, model any) error {
*/
// if err := tx.WithContext(ctx).Save(model).Error; err != nil {
func
(
s
*
BaseDao
)
Save
(
ctx
context
.
Context
,
model
any
)
error
{
// return xerror.New(err.Error())
if
err
:=
s
.
DB
()
.
WithContext
(
ctx
)
.
Save
(
model
)
.
Error
;
err
!=
nil
{
// }
return
xerror
.
New
(
err
.
Error
())
// return nil
}
// }
return
nil
}
// /*
// * 条件跟新
func
(
s
*
BaseDao
)
SaveTx
(
ctx
context
.
Context
,
tx
*
gorm
.
DB
,
model
any
)
error
{
// */
if
err
:=
tx
.
WithContext
(
ctx
)
.
Save
(
model
)
.
Error
;
err
!=
nil
{
// func (s *BaseDao) UpdateWhere(ctx context.Context, model any, where any, updates map[string]any) error {
return
xerror
.
New
(
err
.
Error
())
// if err := s.DB().WithContext(ctx).Model(model).Where(where).Updates(updates).Error; err != nil {
}
// return xerror.New(err.Error())
return
nil
// }
}
// return nil
// }
/*
* 条件跟新
// func (s *BaseDao) UpdateWhereTx(ctx context.Context, tx *gorm.DB, model any, where any, updates map[string]any) error {
*/
// if err := tx.WithContext(ctx).Model(model).Where(where).Updates(updates).Error; err != nil {
func
(
s
*
BaseDao
)
UpdateWhere
(
ctx
context
.
Context
,
model
any
,
where
any
,
updates
map
[
string
]
any
)
error
{
// return xerror.New(err.Error())
if
err
:=
s
.
DB
()
.
WithContext
(
ctx
)
.
Model
(
model
)
.
Where
(
where
)
.
Updates
(
updates
)
.
Error
;
err
!=
nil
{
// }
return
xerror
.
New
(
err
.
Error
())
// return nil
}
// }
return
nil
}
// /*
// * 模型更新
func
(
s
*
BaseDao
)
UpdateWhereTx
(
ctx
context
.
Context
,
tx
*
gorm
.
DB
,
model
any
,
where
any
,
updates
map
[
string
]
any
)
error
{
// * 注意!!!零值不会更新,建议使用 UpdateWhere、UpdateWhereTx
if
err
:=
tx
.
WithContext
(
ctx
)
.
Model
(
model
)
.
Where
(
where
)
.
Updates
(
updates
)
.
Error
;
err
!=
nil
{
// */
return
xerror
.
New
(
err
.
Error
())
// func (s *BaseDao) UpdateWhereModel(ctx context.Context, where any, updates any) error {
}
// if err := s.DB().WithContext(ctx).Where(where).Updates(updates).Error; err != nil {
return
nil
// return xerror.New(err.Error())
}
// }
// return nil
/*
// }
* 模型更新
* 注意!!!零值不会更新,建议使用 UpdateWhere、UpdateWhereTx
// /*
*/
// * 模型更新
func
(
s
*
BaseDao
)
UpdateWhereModel
(
ctx
context
.
Context
,
where
any
,
updates
any
)
error
{
// * 注意!!!零值不会更新,建议使用 UpdateWhere、UpdateWhereTx
if
err
:=
s
.
DB
()
.
WithContext
(
ctx
)
.
Where
(
where
)
.
Updates
(
updates
)
.
Error
;
err
!=
nil
{
// */
return
xerror
.
New
(
err
.
Error
())
// func (s *BaseDao) UpdateWhereModelTx(ctx context.Context, tx *gorm.DB, where any, updates any) error {
}
// if err := tx.WithContext(ctx).Where(where).Updates(updates).Error; err != nil {
return
nil
// return xerror.New(err.Error())
}
// }
// return nil
/*
// }
* 模型更新
* 注意!!!零值不会更新,建议使用 UpdateWhere、UpdateWhereTx
// /*
*/
// * 根据模型id更新
func
(
s
*
BaseDao
)
UpdateWhereModelTx
(
ctx
context
.
Context
,
tx
*
gorm
.
DB
,
where
any
,
updates
any
)
error
{
// * 注意!!!零值不会更新,建议使用 UpdateWhere、UpdateWhereTx
if
err
:=
tx
.
WithContext
(
ctx
)
.
Where
(
where
)
.
Updates
(
updates
)
.
Error
;
err
!=
nil
{
// */
return
xerror
.
New
(
err
.
Error
())
// func (s *BaseDao) UpdateById(ctx context.Context, model any) error {
}
// if err := s.DB().WithContext(ctx).Updates(model).Error; err != nil {
return
nil
// return xerror.New(err.Error())
}
// }
// return nil
/*
// }
* 根据模型id更新
* 注意!!!零值不会更新,建议使用 UpdateWhere、UpdateWhereTx
// /*
*/
// * 根据模型id更新
func
(
s
*
BaseDao
)
UpdateById
(
ctx
context
.
Context
,
model
any
)
error
{
// * 注意!!!零值不会更新,建议使用 UpdateWhere、UpdateWhereTx
if
err
:=
s
.
DB
()
.
WithContext
(
ctx
)
.
Updates
(
model
)
.
Error
;
err
!=
nil
{
// */
return
xerror
.
New
(
err
.
Error
())
// func (s *BaseDao) UpdateByIdTx(ctx context.Context, tx *gorm.DB, model any) error {
}
// if err := tx.WithContext(ctx).Updates(model).Error; err != nil {
return
nil
// return xerror.New(err.Error())
}
// }
// return nil
/*
// }
* 根据模型id更新
* 注意!!!零值不会更新,建议使用 UpdateWhere、UpdateWhereTx
// // DelModel model id 不能为空
*/
// func (s *BaseDao) DelModel(ctx context.Context, model any) error {
func
(
s
*
BaseDao
)
UpdateByIdTx
(
ctx
context
.
Context
,
tx
*
gorm
.
DB
,
model
any
)
error
{
// if err := s.DB().WithContext(ctx).Delete(model).Error; err != nil {
if
err
:=
tx
.
WithContext
(
ctx
)
.
Updates
(
model
)
.
Error
;
err
!=
nil
{
// return xerror.New(err.Error())
return
xerror
.
New
(
err
.
Error
())
// }
}
// return nil
return
nil
// }
}
// func (s *BaseDao) DelWhereTx(ctx context.Context, tx *gorm.DB, model any) error {
// DelModel model id 不能为空
// if err := tx.WithContext(ctx).Delete(model).Error; err != nil {
func
(
s
*
BaseDao
)
DelModel
(
ctx
context
.
Context
,
model
any
)
error
{
// return xerror.New(err.Error())
if
err
:=
s
.
DB
()
.
WithContext
(
ctx
)
.
Delete
(
model
)
.
Error
;
err
!=
nil
{
// }
return
xerror
.
New
(
err
.
Error
())
// return nil
}
// }
return
nil
}
// /*
// * 条件删除,模型 where 为map
func
(
s
*
BaseDao
)
DelWhereTx
(
ctx
context
.
Context
,
tx
*
gorm
.
DB
,
model
any
)
error
{
// */
if
err
:=
tx
.
WithContext
(
ctx
)
.
Delete
(
model
)
.
Error
;
err
!=
nil
{
// func (s *BaseDao) DelWhereMap(ctx context.Context, model any, where map[string]any) error {
return
xerror
.
New
(
err
.
Error
())
// if err := s.DB().WithContext(ctx).Where(where).Delete(model).Error; err != nil {
}
// return xerror.New(err.Error())
return
nil
// }
}
// return nil
// }
/*
* 条件删除,模型 where 为map
// func (s *BaseDao) DelWhereMapTx(ctx context.Context, tx *gorm.DB, model any, where map[string]any) error {
*/
// if err := tx.WithContext(ctx).Where(where).Delete(model).Error; err != nil {
func
(
s
*
BaseDao
)
DelWhereMap
(
ctx
context
.
Context
,
model
any
,
where
map
[
string
]
any
)
error
{
// return xerror.New(err.Error())
if
err
:=
s
.
DB
()
.
WithContext
(
ctx
)
.
Where
(
where
)
.
Delete
(
model
)
.
Error
;
err
!=
nil
{
// }
return
xerror
.
New
(
err
.
Error
())
// return nil
}
// }
return
nil
}
// /*
// * id 可以是xsf.ID 也可以是[]xsf.ID
func
(
s
*
BaseDao
)
DelWhereMapTx
(
ctx
context
.
Context
,
tx
*
gorm
.
DB
,
model
any
,
where
map
[
string
]
any
)
error
{
// */
if
err
:=
tx
.
WithContext
(
ctx
)
.
Where
(
where
)
.
Delete
(
model
)
.
Error
;
err
!=
nil
{
return
xerror
.
New
(
err
.
Error
())
// func (s *BaseDao) DelIds(ctx context.Context, model any, ids any) error {
}
// if err := s.DB().WithContext(ctx).Delete(model, ids).Error; err != nil {
return
nil
// return xerror.New(err.Error())
}
// }
// return nil
/*
// }
* id 可以是xsf.ID 也可以是[]xsf.ID
*/
// func (s *BaseDao) DelIdsTx(ctx context.Context, tx *gorm.DB, model any, ids any) error {
// if err := tx.WithContext(ctx).Delete(model, ids).Error; err != nil {
func
(
s
*
BaseDao
)
DelIds
(
ctx
context
.
Context
,
model
any
,
ids
any
)
error
{
// return xerror.New(err.Error())
if
err
:=
s
.
DB
()
.
WithContext
(
ctx
)
.
Delete
(
model
,
ids
)
.
Error
;
err
!=
nil
{
// }
return
xerror
.
New
(
err
.
Error
())
// return nil
}
// }
return
nil
}
// /*
// * 根据id获取模型
func
(
s
*
BaseDao
)
DelIdsTx
(
ctx
context
.
Context
,
tx
*
gorm
.
DB
,
model
any
,
ids
any
)
error
{
// */
if
err
:=
tx
.
WithContext
(
ctx
)
.
Delete
(
model
,
ids
)
.
Error
;
err
!=
nil
{
// func (s *BaseDao) Get(ctx context.Context, model any, conds ...interface{}) error {
return
xerror
.
New
(
err
.
Error
())
// if err := s.DB().WithContext(ctx).First(model, conds...).Error; err != nil {
}
// return xerror.New(err.Error())
return
nil
// }
}
// return nil
// }
/*
* 根据id获取模型
// /**
*/
// * 条件查询
func
(
s
*
BaseDao
)
Get
(
ctx
context
.
Context
,
model
any
,
conds
...
interface
{})
error
{
// * where: where 查询条件model
if
err
:=
s
.
DB
()
.
WithContext
(
ctx
)
.
First
(
model
,
conds
...
)
.
Error
;
err
!=
nil
{
// * models: 代表查询返回的model数组
return
xerror
.
New
(
err
.
Error
())
// */
}
// func (s *BaseDao) GetByWhere(ctx context.Context, where any, models any) error {
return
nil
// if err := s.DB().WithContext(ctx).Where(where).Find(models).Error; err != nil {
}
// return xerror.New(err.Error())
// }
/**
// return nil
* 条件查询
// }
* where: where 查询条件model
* models: 代表查询返回的model数组
// /**
*/
// * 列表条件查询
func
(
s
*
BaseDao
)
GetByWhere
(
ctx
context
.
Context
,
where
any
,
models
any
)
error
{
// * where: 条件查询
if
err
:=
s
.
DB
()
.
WithContext
(
ctx
)
.
Where
(
where
)
.
Find
(
models
)
.
Error
;
err
!=
nil
{
// * models: 代表查询返回的model数组
return
xerror
.
New
(
err
.
Error
())
// */
}
// func (s *BaseDao) GetByMap(ctx context.Context, where map[string]any, models any) error {
return
nil
// if err := s.DB().WithContext(ctx).Where(where).Find(models).Error; err != nil {
}
// return xerror.New(err.Error())
// }
/**
// return nil
* 列表条件查询
// }
* where: 条件查询
* models: 代表查询返回的model数组
// /**
*/
// * 条数查询
func
(
s
*
BaseDao
)
GetByMap
(
ctx
context
.
Context
,
where
map
[
string
]
any
,
models
any
)
error
{
// * model: 查询条件
if
err
:=
s
.
DB
()
.
WithContext
(
ctx
)
.
Where
(
where
)
.
Find
(
models
)
.
Error
;
err
!=
nil
{
// * count: 查询条数
return
xerror
.
New
(
err
.
Error
())
// */
}
// func (s *BaseDao) Count(ctx context.Context, model any, count *int64) error {
return
nil
// if err := s.DB().WithContext(ctx).Model(model).Where(model).Count(count).Error; err != nil {
}
// return xerror.New(err.Error())
// }
/**
// return nil
* 条数查询
// }
* model: 查询条件
* count: 查询条数
// /**
*/
// * 条数查询
func
(
s
*
BaseDao
)
Count
(
ctx
context
.
Context
,
model
any
,
count
*
int64
)
error
{
// * model: 查询条件
if
err
:=
s
.
DB
()
.
WithContext
(
ctx
)
.
Model
(
model
)
.
Where
(
model
)
.
Count
(
count
)
.
Error
;
err
!=
nil
{
// * count: 查询条数
return
xerror
.
New
(
err
.
Error
())
// */
}
// func (s *BaseDao) CountByMap(ctx context.Context, where map[string]any, model any, count *int64) error {
return
nil
// if err := s.DB().WithContext(ctx).Model(model).Where(where).Count(count).Error; err != nil {
}
// return xerror.New(err.Error())
// }
/**
// return nil
* 条数查询
// }
* model: 查询条件
* count: 查询条数
// /**
*/
// * 查询
func
(
s
*
BaseDao
)
CountByMap
(
ctx
context
.
Context
,
where
map
[
string
]
any
,
model
any
,
count
*
int64
)
error
{
// * where 实现Query接口
if
err
:=
s
.
DB
()
.
WithContext
(
ctx
)
.
Model
(
model
)
.
Where
(
where
)
.
Count
(
count
)
.
Error
;
err
!=
nil
{
// */
return
xerror
.
New
(
err
.
Error
())
// func (s *BaseDao) Query(ctx context.Context, where Query, models any) error {
}
// if err := s.DB().WithContext(ctx).Scopes(s.MakeCondition(where)).Find(models).Error; err != nil {
return
nil
// return xerror.New(err.Error())
}
// }
// return nil
/**
// }
* 查询
* where 实现Query接口
// // Page 分页查询
*/
// func (s *BaseDao) Page(ctx context.Context, where Query, models any, limit, offset int) error {
func
(
s
*
BaseDao
)
Query
(
ctx
context
.
Context
,
where
Query
,
models
any
)
error
{
// if err := s.DB().WithContext(ctx).Scopes(s.MakeCondition(where)).Limit(limit).Offset(offset).Find(models).Error; err != nil {
if
err
:=
s
.
DB
()
.
WithContext
(
ctx
)
.
Scopes
(
s
.
MakeCondition
(
where
))
.
Find
(
models
)
.
Error
;
err
!=
nil
{
// return xerror.New(err.Error())
return
xerror
.
New
(
err
.
Error
())
// }
}
// return nil
return
nil
// }
}
// /*
// Page 分页查询
// * 分页获取
func
(
s
*
BaseDao
)
Page
(
ctx
context
.
Context
,
where
Query
,
models
any
,
limit
,
offset
int
)
error
{
// */
if
err
:=
s
.
DB
()
.
WithContext
(
ctx
)
.
Scopes
(
s
.
MakeCondition
(
where
))
.
Limit
(
limit
)
.
Offset
(
offset
)
.
Find
(
models
)
.
Error
;
err
!=
nil
{
// func (s *BaseDao) QPage(ctx context.Context, where any, data any, total *int64, limit, offset int) error {
return
xerror
.
New
(
err
.
Error
())
// if err := s.DB().WithContext(ctx).Where(where).Limit(limit).Offset(offset).
}
// Find(data).Limit(-1).Offset(-1).Count(total).Error; err != nil {
return
nil
// return xerror.New(err.Error())
}
// }
// return nil
/*
// }
* 分页获取
*/
// /*
func
(
s
*
BaseDao
)
QPage
(
ctx
context
.
Context
,
where
any
,
data
any
,
total
*
int64
,
limit
,
offset
int
)
error
{
// * 分页获取
if
err
:=
s
.
DB
()
.
WithContext
(
ctx
)
.
Where
(
where
)
.
Limit
(
limit
)
.
Offset
(
offset
)
.
// */
Find
(
data
)
.
Limit
(
-
1
)
.
Offset
(
-
1
)
.
Count
(
total
)
.
Error
;
err
!=
nil
{
// func (s *BaseDao) QueryPage(ctx context.Context, where Query, models any, total *int64, limit, offset int) error {
return
xerror
.
New
(
err
.
Error
())
// if err := s.DB().WithContext(ctx).Scopes(s.MakeCondition(where)).Limit(limit).Offset(offset).
}
// Find(models).Limit(-1).Offset(-1).Count(total).Error; err != nil {
return
nil
// return xerror.New(err.Error())
}
// }
// return nil
/*
// }
* 分页获取
*/
// /*
func
(
s
*
BaseDao
)
QueryPage
(
ctx
context
.
Context
,
where
Query
,
models
any
,
total
*
int64
,
limit
,
offset
int
)
error
{
// * 分页组装
if
err
:=
s
.
DB
()
.
WithContext
(
ctx
)
.
Scopes
(
s
.
MakeCondition
(
where
))
.
Limit
(
limit
)
.
Offset
(
offset
)
.
// */
Find
(
models
)
.
Limit
(
-
1
)
.
Offset
(
-
1
)
.
Count
(
total
)
.
Error
;
err
!=
nil
{
// func (s *BaseDao) Paginate(pageSize, pageIndex int) func(db *gorm.DB) *gorm.DB {
return
xerror
.
New
(
err
.
Error
())
// return func(db *gorm.DB) *gorm.DB {
}
// offset := (pageIndex - 1) * pageSize
return
nil
// if offset < 0 {
}
// offset = 0
// }
/*
// return db.Offset(offset).Limit(pageSize)
* 分页组装
// }
*/
// }
func
(
s
*
BaseDao
)
Paginate
(
pageSize
,
pageIndex
int
)
func
(
db
*
gorm
.
DB
)
*
gorm
.
DB
{
return
func
(
db
*
gorm
.
DB
)
*
gorm
.
DB
{
// /**
offset
:=
(
pageIndex
-
1
)
*
pageSize
// * chunk 查询
if
offset
<
0
{
// */
offset
=
0
// func (s *BaseDao) Chunk(ctx context.Context, db *gorm.DB, size int, callback func(records []map[string]interface{}) error) error {
}
// var offset int
return
db
.
Offset
(
offset
)
.
Limit
(
pageSize
)
// for {
}
// var records []map[string]interface{}
}
// // 检索 size 条记录
// if err := db.WithContext(ctx).Limit(size).Offset(offset).Find(&records).Error; err != nil {
/**
// return xerror.New(err.Error())
* chunk 查询
// }
*/
// // 如果没有更多记录,则退出循环
func
(
s
*
BaseDao
)
Chunk
(
ctx
context
.
Context
,
db
*
gorm
.
DB
,
size
int
,
callback
func
(
records
[]
map
[
string
]
interface
{})
error
)
error
{
// if len(records) == 0 {
var
offset
int
// break
for
{
// }
var
records
[]
map
[
string
]
interface
{}
// // 调用回调函数处理记录
// 检索 size 条记录
// if err := callback(records); err != nil {
if
err
:=
db
.
WithContext
(
ctx
)
.
Limit
(
size
)
.
Offset
(
offset
)
.
Find
(
&
records
)
.
Error
;
err
!=
nil
{
// return err
return
xerror
.
New
(
err
.
Error
())
// }
}
// // 更新偏移量
// 如果没有更多记录,则退出循环
// offset += size
if
len
(
records
)
==
0
{
// }
break
// return nil
}
// }
// 调用回调函数处理记录
if
err
:=
callback
(
records
);
err
!=
nil
{
// /**
return
err
// * 查询条件组装
}
// */
// 更新偏移量
// func (s *BaseDao) MakeCondition(q Query) func(db *gorm.DB) *gorm.DB {
offset
+=
size
// return func(db *gorm.DB) *gorm.DB {
}
// condition := &GormCondition{
return
nil
// GormPublic: GormPublic{},
}
// Join: make([]*GormJoin, 0),
// }
/**
// driver := "mysql"
* 查询条件组装
// ResolveSearchQuery(driver, q, condition, q.TableName())
*/
// for _, join := range condition.Join {
func
(
s
*
BaseDao
)
MakeCondition
(
q
Query
)
func
(
db
*
gorm
.
DB
)
*
gorm
.
DB
{
// if join == nil {
return
func
(
db
*
gorm
.
DB
)
*
gorm
.
DB
{
// continue
condition
:=
&
GormCondition
{
// }
GormPublic
:
GormPublic
{},
// db = db.Joins(join.JoinOn)
Join
:
make
([]
*
GormJoin
,
0
),
// for k, v := range join.Where {
}
// db = db.Where(k, v...)
driver
:=
"mysql"
// }
ResolveSearchQuery
(
driver
,
q
,
condition
,
q
.
TableName
())
// for k, v := range join.Or {
for
_
,
join
:=
range
condition
.
Join
{
// db = db.Or(k, v...)
if
join
==
nil
{
// }
continue
// for _, o := range join.Order {
}
// db = db.Order(o)
db
=
db
.
Joins
(
join
.
JoinOn
)
// }
for
k
,
v
:=
range
join
.
Where
{
// }
db
=
db
.
Where
(
k
,
v
...
)
// for k, v := range condition.Where {
}
// db = db.Where(k, v...)
for
k
,
v
:=
range
join
.
Or
{
// }
db
=
db
.
Or
(
k
,
v
...
)
// for k, v := range condition.Or {
}
// db = db.Or(k, v...)
for
_
,
o
:=
range
join
.
Order
{
// }
db
=
db
.
Order
(
o
)
// for _, o := range condition.Order {
}
// db = db.Order(o)
}
// }
for
k
,
v
:=
range
condition
.
Where
{
// return db
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
}
}
xcommon/base/query.go
浏览文件 @
1ab6fb03
package
base
package
base
import
(
// /*
"fmt"
// * 条件查询结构体,结果体非零值字段将查询
"reflect"
// * @Param type
"regexp"
// * eq 等于(默认不填都可以)
"strings"
// * like 包含
"unicode"
// * gt / gte 大于 / 大于等于
// * lt / lte 小于 / 小于等于
// * left / ileft :like xxx%
// * right / iright : like %xxx
// * in
// * isnull
// * order 排序 e.g. order[key]=desc order[key]=asc
// * "-" 忽略该字段
// * @Param table
// * table 不填默认取 TableName值
// * @Param column
// * column 不填以结构体字段
// * eg:
// * type ExampleQuery struct{
// * Name string `json:"name" query:"type:like;column:name;table:exampale"`
// * Status int `json:"status" query:"type:gt"`
// * }
// * func (ExampleQuery) TableName() string {
// * return "ExampleQuery"
// * }
// */
// type Query interface {
// TableName() string
// }
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
// const (
)
// // FromQueryTag tag标记
// FromQueryTag = "query"
// // Mysql 数据库标识
// Mysql = "mysql"
// // Postgres 数据库标识
// Postgres = "pgsql"
// )
/*
// // ResolveSearchQuery 解析
* 条件查询结构体,结果体非零值字段将查询
// /**
* @Param type
// * eq 等于(默认不填都可以)
* eq 等于(默认不填都可以)
// * like 包含
* like 包含
// * gt / gte 大于 / 大于等于
* gt / gte 大于 / 大于等于
// * lt / lte 小于 / 小于等于
* lt / lte 小于 / 小于等于
// * left / ileft :like xxx%
* left / ileft :like xxx%
// * right / iright : like %xxx
* right / iright : like %xxx
// * in
* in
// * isnull
* isnull
// * order 排序 e.g. order[key]=desc order[key]=asc
* order 排序 e.g. order[key]=desc order[key]=asc
// */
* "-" 忽略该字段
// func ResolveSearchQuery(driver string, q any, condition Condition, pTName string) {
* @Param table
// qType := reflect.TypeOf(q)
* table 不填默认取 TableName值
// qValue := reflect.ValueOf(q)
* @Param column
// var tag string
* column 不填以结构体字段
// var ok bool
* eg:
// var t *resolveSearchTag
* type ExampleQuery struct{
// var tname string
* Name string `json:"name" query:"type:like;column:name;table:exampale"`
// if cur, ok := q.(Query); ok {
* Status int `json:"status" query:"type:gt"`
// if cur.TableName() == "" {
* }
// tname = pTName
* func (ExampleQuery) TableName() string {
// } else {
* return "ExampleQuery"
// tname = cur.TableName()
* }
// }
*/
// } else {
type
Query
interface
{
// tname = pTName
TableName
()
string
// }
}
// if qType.Kind() == reflect.Ptr {
// qType = qType.Elem()
// }
// if qType.Kind() != reflect.Struct {
// // fmt.Printf("SeachQuery field undefined tag of type %s, expect type is struct\n", qType.Name())
// return
// }
const
(
// for i := 0; i < qType.NumField(); i++ {
// FromQueryTag tag标记
// tag, ok = "", false
FromQueryTag
=
"query"
// tag, ok = qType.Field(i).Tag.Lookup(FromQueryTag)
// Mysql 数据库标识
// if !ok {
Mysql
=
"mysql"
// //递归调用
// Postgres 数据库标识
// ResolveSearchQuery(driver, qValue.Field(i).Interface(), condition, tname)
Postgres
=
"pgsql"
// continue
)
// }
// switch tag {
// case "-":
// continue
// }
// if qValue.Field(i).IsZero() {
// continue
// }
// t = makeTag(tag)
// if t.Column == "" {
// t.Column = snakeCase(qType.Field(i).Name, false)
// }
// if t.Table == "" {
// t.Table = tname
// }
// ResolveSearchQuery 解析
// //解析 Postgres `语法不支持,单独适配
/**
// if driver == Postgres {
* eq 等于(默认不填都可以)
// pgSql(driver, t, condition, qValue, i, tname)
* like 包含
// } else {
* gt / gte 大于 / 大于等于
// otherSql(driver, t, condition, qValue, i, tname)
* lt / lte 小于 / 小于等于
// }
* left / ileft :like xxx%
// }
* right / iright : like %xxx
// }
* in
* isnull
* order 排序 e.g. order[key]=desc order[key]=asc
*/
func
ResolveSearchQuery
(
driver
string
,
q
any
,
condition
Condition
,
pTName
string
)
{
qType
:=
reflect
.
TypeOf
(
q
)
qValue
:=
reflect
.
ValueOf
(
q
)
var
tag
string
var
ok
bool
var
t
*
resolveSearchTag
var
tname
string
if
cur
,
ok
:=
q
.
(
Query
);
ok
{
if
cur
.
TableName
()
==
""
{
tname
=
pTName
}
else
{
tname
=
cur
.
TableName
()
}
}
else
{
tname
=
pTName
}
if
qType
.
Kind
()
==
reflect
.
Ptr
{
qType
=
qType
.
Elem
()
}
if
qType
.
Kind
()
!=
reflect
.
Struct
{
// fmt.Printf("SeachQuery field undefined tag of type %s, expect type is struct\n", qType.Name())
return
}
for
i
:=
0
;
i
<
qType
.
NumField
();
i
++
{
// type QueryTag string
tag
,
ok
=
""
,
false
tag
,
ok
=
qType
.
Field
(
i
)
.
Tag
.
Lookup
(
FromQueryTag
)
if
!
ok
{
//递归调用
ResolveSearchQuery
(
driver
,
qValue
.
Field
(
i
)
.
Interface
(),
condition
,
tname
)
continue
}
switch
tag
{
case
"-"
:
continue
}
if
qValue
.
Field
(
i
)
.
IsZero
()
{
continue
}
t
=
makeTag
(
tag
)
if
t
.
Column
==
""
{
t
.
Column
=
snakeCase
(
qType
.
Field
(
i
)
.
Name
,
false
)
}
if
t
.
Table
==
""
{
t
.
Table
=
tname
}
//解析 Postgres `语法不支持,单独适配
// const (
if
driver
==
Postgres
{
// EQ QueryTag = "eq"
pgSql
(
driver
,
t
,
condition
,
qValue
,
i
,
tname
)
// LIKE QueryTag = "like"
}
else
{
// ILIKE QueryTag = "ilike"
otherSql
(
driver
,
t
,
condition
,
qValue
,
i
,
tname
)
// LEFT QueryTag = "left"
}
// ILEFT QueryTag = "ileft"
}
// RIGHT QueryTag = "right"
}
// IRIGHT QueryTag = "iright"
// GT QueryTag = "gt"
// GTE QueryTag = "gte"
// LT QueryTag = "lt"
// LTE QueryTag = "lte"
// IN QueryTag = "in"
// ISNULL QueryTag = "isnull"
// ISNOTNULL QueryTag = "isnotnull"
// ORDER QueryTag = "order"
// JOIN QueryTag = "join"
// )
type
QueryTag
string
// func pgSql(driver string, t *resolveSearchTag, condition Condition, qValue reflect.Value, i int, tname string) {
// if t.Type == "" {
// condition.SetWhere(fmt.Sprintf("%s.%s = ?", t.Table, t.Column), []interface{}{qValue.Field(i).Interface()})
// return
// }
// qtag := QueryTag(t.Type)
// switch qtag {
// case EQ:
// condition.SetWhere(fmt.Sprintf("%s.%s = ?", t.Table, t.Column), []interface{}{qValue.Field(i).Interface()})
// return
// case ILIKE:
// condition.SetWhere(fmt.Sprintf("%s.%s ilike ?", t.Table, t.Column), []interface{}{"%" + qValue.Field(i).String() + "%"})
// return
// case LIKE:
// condition.SetWhere(fmt.Sprintf("%s.%s like ?", t.Table, t.Column), []interface{}{"%" + qValue.Field(i).String() + "%"})
// return
// case GT:
// condition.SetWhere(fmt.Sprintf("%s.%s > ?", t.Table, t.Column), []interface{}{qValue.Field(i).Interface()})
// return
// case GTE:
// condition.SetWhere(fmt.Sprintf("%s.%s >= ?", t.Table, t.Column), []interface{}{qValue.Field(i).Interface()})
// return
// case LT:
// condition.SetWhere(fmt.Sprintf("%s.%s < ?", t.Table, t.Column), []interface{}{qValue.Field(i).Interface()})
// return
// case LTE:
// condition.SetWhere(fmt.Sprintf("%s.%s <= ?", t.Table, t.Column), []interface{}{qValue.Field(i).Interface()})
// return
// case ILEFT:
// condition.SetWhere(fmt.Sprintf("%s.%s ilike ?", t.Table, t.Column), []interface{}{qValue.Field(i).String() + "%"})
// return
// case LEFT:
// condition.SetWhere(fmt.Sprintf("%s.%s like ?", t.Table, t.Column), []interface{}{qValue.Field(i).String() + "%"})
// return
// case IRIGHT:
// condition.SetWhere(fmt.Sprintf("%s.%s ilike ?", t.Table, t.Column), []interface{}{"%" + qValue.Field(i).String()})
// return
// case RIGHT:
// condition.SetWhere(fmt.Sprintf("%s.%s like ?", t.Table, t.Column), []interface{}{"%" + qValue.Field(i).String()})
// return
// case IN:
// condition.SetWhere(fmt.Sprintf("%s.%s in (?)", t.Table, t.Column), []interface{}{qValue.Field(i).Interface()})
// return
// case ISNULL:
// if !(qValue.Field(i).IsZero() && qValue.Field(i).IsNil()) {
// condition.SetWhere(fmt.Sprintf("%s.%s is null", t.Table, t.Column), make([]interface{}, 0))
// }
// return
// case ISNOTNULL:
// if !(qValue.Field(i).IsZero() && qValue.Field(i).IsNil()) {
// condition.SetWhere(fmt.Sprintf("%s.%s is not null", t.Table, t.Column), make([]interface{}, 0))
// }
// return
// case ORDER:
// switch strings.ToLower(qValue.Field(i).String()) {
// case "desc", "asc":
// condition.SetOrder(fmt.Sprintf("%s.%s %s", t.Table, t.Column, qValue.Field(i).String()))
// }
// return
// case JOIN:
// //左关联
// join := condition.SetJoinOn(t.Type, fmt.Sprintf(
// "left join %s on %s.%s = %s.%s", t.Join, t.Join, t.On[0], t.Table, t.On[1],
// ))
// ResolveSearchQuery(driver, qValue.Field(i).Interface(), join, tname)
// return
// default:
// condition.SetWhere(fmt.Sprintf("%s.%s = ?", t.Table, t.Column), []interface{}{qValue.Field(i).Interface()})
// }
// }
const
(
// func otherSql(driver string, t *resolveSearchTag, condition Condition, qValue reflect.Value, i int, tname string) {
EQ
QueryTag
=
"eq"
// if t.Type == "" {
LIKE
QueryTag
=
"like"
// condition.SetWhere(fmt.Sprintf("`%s`.`%s` = ?", t.Table, t.Column), []interface{}{qValue.Field(i).Interface()})
ILIKE
QueryTag
=
"ilike"
// return
LEFT
QueryTag
=
"left"
// }
ILEFT
QueryTag
=
"ileft"
// qtag := QueryTag(t.Type)
RIGHT
QueryTag
=
"right"
// switch qtag {
IRIGHT
QueryTag
=
"iright"
// case EQ:
GT
QueryTag
=
"gt"
// condition.SetWhere(fmt.Sprintf("`%s`.`%s` = ?", t.Table, t.Column), []interface{}{qValue.Field(i).Interface()})
GTE
QueryTag
=
"gte"
// return
LT
QueryTag
=
"lt"
// case GT:
LTE
QueryTag
=
"lte"
// condition.SetWhere(fmt.Sprintf("`%s`.`%s` > ?", t.Table, t.Column), []interface{}{qValue.Field(i).Interface()})
IN
QueryTag
=
"in"
// return
ISNULL
QueryTag
=
"isnull"
// case GTE:
ISNOTNULL
QueryTag
=
"isnotnull"
// condition.SetWhere(fmt.Sprintf("`%s`.`%s` >= ?", t.Table, t.Column), []interface{}{qValue.Field(i).Interface()})
ORDER
QueryTag
=
"order"
// return
JOIN
QueryTag
=
"join"
// case LT:
)
// condition.SetWhere(fmt.Sprintf("`%s`.`%s` < ?", t.Table, t.Column), []interface{}{qValue.Field(i).Interface()})
// return
// case LTE:
// condition.SetWhere(fmt.Sprintf("`%s`.`%s` <= ?", t.Table, t.Column), []interface{}{qValue.Field(i).Interface()})
// return
// case LEFT:
// condition.SetWhere(fmt.Sprintf("`%s`.`%s` like ?", t.Table, t.Column), []interface{}{qValue.Field(i).String() + "%"})
// return
// case LIKE:
// condition.SetWhere(fmt.Sprintf("`%s`.`%s` like ?", t.Table, t.Column), []interface{}{"%" + qValue.Field(i).String() + "%"})
// return
// case RIGHT:
// condition.SetWhere(fmt.Sprintf("`%s`.`%s` like ?", t.Table, t.Column), []interface{}{"%" + qValue.Field(i).String()})
// return
// case IN:
// condition.SetWhere(fmt.Sprintf("`%s`.`%s` in (?)", t.Table, t.Column), []interface{}{qValue.Field(i).Interface()})
// return
// case ISNULL:
// if !(qValue.Field(i).IsZero() && qValue.Field(i).IsNil()) {
// condition.SetWhere(fmt.Sprintf("`%s`.`%s` is null", t.Table, t.Column), make([]interface{}, 0))
// }
// return
// case ISNOTNULL:
// if !(qValue.Field(i).IsZero() && qValue.Field(i).IsNil()) {
// condition.SetWhere(fmt.Sprintf("%s.%s is not null", t.Table, t.Column), make([]interface{}, 0))
// }
// return
// case ORDER:
// val := strings.TrimSpace(qValue.Field(i).String())
// if detectSQLInjection(val) {
// logger.Error("detect SQL injection", logger.String("sql order segment", val))
// return
// }
// if val != "" {
// orderColumns := strings.Split(val, ",")
// var orders []string
// for _, column := range orderColumns {
// if strings.HasPrefix(column, "-") {
// column = column[1:] + " desc"
// } else {
// column += " asc"
// }
// column = fmt.Sprintf("%s.%s", t.Table, column)
// orders = append(orders, column)
// }
// orderSegmet := strings.Join(orders, ",")
// condition.SetOrder(orderSegmet)
// } else {
// switch strings.ToLower(qValue.Field(i).String()) {
// case "desc", "asc":
// condition.SetOrder(fmt.Sprintf("`%s`.`%s` %s", t.Table, t.Column, qValue.Field(i).String()))
// }
// }
// return
// case JOIN:
// //左关联
// join := condition.SetJoinOn(t.Type, fmt.Sprintf(
// "left join `%s` on `%s`.`%s` = `%s`.`%s`",
// t.Join,
// t.Join,
// t.On[0],
// t.Table,
// t.On[1],
// ))
// ResolveSearchQuery(driver, qValue.Field(i).Interface(), join, tname)
// return
// default:
// condition.SetWhere(fmt.Sprintf("`%s`.`%s` = ?", t.Table, t.Column), []interface{}{qValue.Field(i).Interface()})
// }
// }
func
pgSql
(
driver
string
,
t
*
resolveSearchTag
,
condition
Condition
,
qValue
reflect
.
Value
,
i
int
,
tname
string
)
{
// var (
if
t
.
Type
==
""
{
// orderReg = regexp.MustCompile(`order\[([^\]]+)\]=([^=]+)`)
condition
.
SetWhere
(
fmt
.
Sprintf
(
"%s.%s = ?"
,
t
.
Table
,
t
.
Column
),
[]
interface
{}{
qValue
.
Field
(
i
)
.
Interface
()})
// detectSQLInjectionRe = regexp.MustCompile(`['";]+|UNION|SELECT|INSERT|UPDATE|DELETE|DROP|GRANT|EXEC|CREATE|ALTER|TRUNCATE|COUNT|\*|--|\/\*|;|\+|\/`)
return
// )
}
qtag
:=
QueryTag
(
t
.
Type
)
switch
qtag
{
case
EQ
:
condition
.
SetWhere
(
fmt
.
Sprintf
(
"%s.%s = ?"
,
t
.
Table
,
t
.
Column
),
[]
interface
{}{
qValue
.
Field
(
i
)
.
Interface
()})
return
case
ILIKE
:
condition
.
SetWhere
(
fmt
.
Sprintf
(
"%s.%s ilike ?"
,
t
.
Table
,
t
.
Column
),
[]
interface
{}{
"%"
+
qValue
.
Field
(
i
)
.
String
()
+
"%"
})
return
case
LIKE
:
condition
.
SetWhere
(
fmt
.
Sprintf
(
"%s.%s like ?"
,
t
.
Table
,
t
.
Column
),
[]
interface
{}{
"%"
+
qValue
.
Field
(
i
)
.
String
()
+
"%"
})
return
case
GT
:
condition
.
SetWhere
(
fmt
.
Sprintf
(
"%s.%s > ?"
,
t
.
Table
,
t
.
Column
),
[]
interface
{}{
qValue
.
Field
(
i
)
.
Interface
()})
return
case
GTE
:
condition
.
SetWhere
(
fmt
.
Sprintf
(
"%s.%s >= ?"
,
t
.
Table
,
t
.
Column
),
[]
interface
{}{
qValue
.
Field
(
i
)
.
Interface
()})
return
case
LT
:
condition
.
SetWhere
(
fmt
.
Sprintf
(
"%s.%s < ?"
,
t
.
Table
,
t
.
Column
),
[]
interface
{}{
qValue
.
Field
(
i
)
.
Interface
()})
return
case
LTE
:
condition
.
SetWhere
(
fmt
.
Sprintf
(
"%s.%s <= ?"
,
t
.
Table
,
t
.
Column
),
[]
interface
{}{
qValue
.
Field
(
i
)
.
Interface
()})
return
case
ILEFT
:
condition
.
SetWhere
(
fmt
.
Sprintf
(
"%s.%s ilike ?"
,
t
.
Table
,
t
.
Column
),
[]
interface
{}{
qValue
.
Field
(
i
)
.
String
()
+
"%"
})
return
case
LEFT
:
condition
.
SetWhere
(
fmt
.
Sprintf
(
"%s.%s like ?"
,
t
.
Table
,
t
.
Column
),
[]
interface
{}{
qValue
.
Field
(
i
)
.
String
()
+
"%"
})
return
case
IRIGHT
:
condition
.
SetWhere
(
fmt
.
Sprintf
(
"%s.%s ilike ?"
,
t
.
Table
,
t
.
Column
),
[]
interface
{}{
"%"
+
qValue
.
Field
(
i
)
.
String
()})
return
case
RIGHT
:
condition
.
SetWhere
(
fmt
.
Sprintf
(
"%s.%s like ?"
,
t
.
Table
,
t
.
Column
),
[]
interface
{}{
"%"
+
qValue
.
Field
(
i
)
.
String
()})
return
case
IN
:
condition
.
SetWhere
(
fmt
.
Sprintf
(
"%s.%s in (?)"
,
t
.
Table
,
t
.
Column
),
[]
interface
{}{
qValue
.
Field
(
i
)
.
Interface
()})
return
case
ISNULL
:
if
!
(
qValue
.
Field
(
i
)
.
IsZero
()
&&
qValue
.
Field
(
i
)
.
IsNil
())
{
condition
.
SetWhere
(
fmt
.
Sprintf
(
"%s.%s is null"
,
t
.
Table
,
t
.
Column
),
make
([]
interface
{},
0
))
}
return
case
ISNOTNULL
:
if
!
(
qValue
.
Field
(
i
)
.
IsZero
()
&&
qValue
.
Field
(
i
)
.
IsNil
())
{
condition
.
SetWhere
(
fmt
.
Sprintf
(
"%s.%s is not null"
,
t
.
Table
,
t
.
Column
),
make
([]
interface
{},
0
))
}
return
case
ORDER
:
switch
strings
.
ToLower
(
qValue
.
Field
(
i
)
.
String
())
{
case
"desc"
,
"asc"
:
condition
.
SetOrder
(
fmt
.
Sprintf
(
"%s.%s %s"
,
t
.
Table
,
t
.
Column
,
qValue
.
Field
(
i
)
.
String
()))
}
return
case
JOIN
:
//左关联
join
:=
condition
.
SetJoinOn
(
t
.
Type
,
fmt
.
Sprintf
(
"left join %s on %s.%s = %s.%s"
,
t
.
Join
,
t
.
Join
,
t
.
On
[
0
],
t
.
Table
,
t
.
On
[
1
],
))
ResolveSearchQuery
(
driver
,
qValue
.
Field
(
i
)
.
Interface
(),
join
,
tname
)
return
default
:
condition
.
SetWhere
(
fmt
.
Sprintf
(
"%s.%s = ?"
,
t
.
Table
,
t
.
Column
),
[]
interface
{}{
qValue
.
Field
(
i
)
.
Interface
()})
}
}
func
otherSql
(
driver
string
,
t
*
resolveSearchTag
,
condition
Condition
,
qValue
reflect
.
Value
,
i
int
,
tname
string
)
{
// func parseOrder(order string) (string, string, bool) {
if
t
.
Type
==
""
{
// matches := orderReg.FindStringSubmatch(order)
condition
.
SetWhere
(
fmt
.
Sprintf
(
"`%s`.`%s` = ?"
,
t
.
Table
,
t
.
Column
),
[]
interface
{}{
qValue
.
Field
(
i
)
.
Interface
()})
// if len(matches) == 3 {
return
// column := matches[1]
}
// value := matches[2]
qtag
:=
QueryTag
(
t
.
Type
)
// return strings.TrimSpace(column), strings.TrimSpace(value), true
switch
qtag
{
// } else {
case
EQ
:
// return "", "", false
condition
.
SetWhere
(
fmt
.
Sprintf
(
"`%s`.`%s` = ?"
,
t
.
Table
,
t
.
Column
),
[]
interface
{}{
qValue
.
Field
(
i
)
.
Interface
()})
// }
return
// }
case
GT
:
condition
.
SetWhere
(
fmt
.
Sprintf
(
"`%s`.`%s` > ?"
,
t
.
Table
,
t
.
Column
),
[]
interface
{}{
qValue
.
Field
(
i
)
.
Interface
()})
return
case
GTE
:
condition
.
SetWhere
(
fmt
.
Sprintf
(
"`%s`.`%s` >= ?"
,
t
.
Table
,
t
.
Column
),
[]
interface
{}{
qValue
.
Field
(
i
)
.
Interface
()})
return
case
LT
:
condition
.
SetWhere
(
fmt
.
Sprintf
(
"`%s`.`%s` < ?"
,
t
.
Table
,
t
.
Column
),
[]
interface
{}{
qValue
.
Field
(
i
)
.
Interface
()})
return
case
LTE
:
condition
.
SetWhere
(
fmt
.
Sprintf
(
"`%s`.`%s` <= ?"
,
t
.
Table
,
t
.
Column
),
[]
interface
{}{
qValue
.
Field
(
i
)
.
Interface
()})
return
case
LEFT
:
condition
.
SetWhere
(
fmt
.
Sprintf
(
"`%s`.`%s` like ?"
,
t
.
Table
,
t
.
Column
),
[]
interface
{}{
qValue
.
Field
(
i
)
.
String
()
+
"%"
})
return
case
LIKE
:
condition
.
SetWhere
(
fmt
.
Sprintf
(
"`%s`.`%s` like ?"
,
t
.
Table
,
t
.
Column
),
[]
interface
{}{
"%"
+
qValue
.
Field
(
i
)
.
String
()
+
"%"
})
return
case
RIGHT
:
condition
.
SetWhere
(
fmt
.
Sprintf
(
"`%s`.`%s` like ?"
,
t
.
Table
,
t
.
Column
),
[]
interface
{}{
"%"
+
qValue
.
Field
(
i
)
.
String
()})
return
case
IN
:
condition
.
SetWhere
(
fmt
.
Sprintf
(
"`%s`.`%s` in (?)"
,
t
.
Table
,
t
.
Column
),
[]
interface
{}{
qValue
.
Field
(
i
)
.
Interface
()})
return
case
ISNULL
:
if
!
(
qValue
.
Field
(
i
)
.
IsZero
()
&&
qValue
.
Field
(
i
)
.
IsNil
())
{
condition
.
SetWhere
(
fmt
.
Sprintf
(
"`%s`.`%s` is null"
,
t
.
Table
,
t
.
Column
),
make
([]
interface
{},
0
))
}
return
case
ISNOTNULL
:
if
!
(
qValue
.
Field
(
i
)
.
IsZero
()
&&
qValue
.
Field
(
i
)
.
IsNil
())
{
condition
.
SetWhere
(
fmt
.
Sprintf
(
"%s.%s is not null"
,
t
.
Table
,
t
.
Column
),
make
([]
interface
{},
0
))
}
return
case
ORDER
:
val
:=
strings
.
TrimSpace
(
qValue
.
Field
(
i
)
.
String
())
if
detectSQLInjection
(
val
)
{
logger
.
Error
(
"detect SQL injection"
,
logger
.
String
(
"sql order segment"
,
val
))
return
}
if
val
!=
""
{
orderColumns
:=
strings
.
Split
(
val
,
","
)
var
orders
[]
string
for
_
,
column
:=
range
orderColumns
{
if
strings
.
HasPrefix
(
column
,
"-"
)
{
column
=
column
[
1
:
]
+
" desc"
}
else
{
column
+=
" asc"
}
column
=
fmt
.
Sprintf
(
"%s.%s"
,
t
.
Table
,
column
)
orders
=
append
(
orders
,
column
)
}
orderSegmet
:=
strings
.
Join
(
orders
,
","
)
condition
.
SetOrder
(
orderSegmet
)
}
else
{
switch
strings
.
ToLower
(
qValue
.
Field
(
i
)
.
String
())
{
case
"desc"
,
"asc"
:
condition
.
SetOrder
(
fmt
.
Sprintf
(
"`%s`.`%s` %s"
,
t
.
Table
,
t
.
Column
,
qValue
.
Field
(
i
)
.
String
()))
}
}
return
case
JOIN
:
//左关联
join
:=
condition
.
SetJoinOn
(
t
.
Type
,
fmt
.
Sprintf
(
"left join `%s` on `%s`.`%s` = `%s`.`%s`"
,
t
.
Join
,
t
.
Join
,
t
.
On
[
0
],
t
.
Table
,
t
.
On
[
1
],
))
ResolveSearchQuery
(
driver
,
qValue
.
Field
(
i
)
.
Interface
(),
join
,
tname
)
return
default
:
condition
.
SetWhere
(
fmt
.
Sprintf
(
"`%s`.`%s` = ?"
,
t
.
Table
,
t
.
Column
),
[]
interface
{}{
qValue
.
Field
(
i
)
.
Interface
()})
}
}
var
(
// func CameCaseToUnderscore(s string) string {
orderReg
=
regexp
.
MustCompile
(
`order\[([^\]]+)\]=([^=]+)`
)
// var output []rune
detectSQLInjectionRe
=
regexp
.
MustCompile
(
`['";]+|UNION|SELECT|INSERT|UPDATE|DELETE|DROP|GRANT|EXEC|CREATE|ALTER|TRUNCATE|COUNT|\*|--|\/\*|;|\+|\/`
)
// for i, r := range s {
)
// if i == 0 {
// output = append(output, unicode.ToLower(r))
// continue
// }
// if unicode.IsUpper(r) {
// output = append(output, '_')
// }
// output = append(output, unicode.ToLower(r))
// }
// return string(output)
// }
func
parseOrder
(
order
string
)
(
string
,
string
,
bool
)
{
// func castOrder(order string) string {
matches
:=
orderReg
.
FindStringSubmatch
(
order
)
// order = strings.ToLower(order)
if
len
(
matches
)
==
3
{
// switch order {
column
:=
matches
[
1
]
// case "desc":
value
:=
matches
[
2
]
// return "desc"
return
strings
.
TrimSpace
(
column
),
strings
.
TrimSpace
(
value
),
true
// case "asc":
}
else
{
// return "asc"
return
""
,
""
,
false
// default:
}
// return ""
}
// }
// }
func
CameCaseToUnderscore
(
s
string
)
string
{
// func detectSQLInjection(input string) bool {
var
output
[]
rune
// return detectSQLInjectionRe.MatchString(input)
for
i
,
r
:=
range
s
{
// }
if
i
==
0
{
output
=
append
(
output
,
unicode
.
ToLower
(
r
))
continue
}
if
unicode
.
IsUpper
(
r
)
{
output
=
append
(
output
,
'_'
)
}
output
=
append
(
output
,
unicode
.
ToLower
(
r
))
}
return
string
(
output
)
}
func
castOrder
(
order
string
)
string
{
// /**
order
=
strings
.
ToLower
(
order
)
// * 驼峰转蛇形 snake string
switch
order
{
// **/
case
"desc"
:
// func snakeCase(s string, allMode bool) string {
return
"desc"
// num := len(s)
case
"asc"
:
// data := make([]byte, 0, num*2)
return
"asc"
// for i := 0; i < num; i++ {
default
:
// d := s[i]
return
""
// // or通过ASCII码进行大小写的转化
}
// // 65-90(A-Z),97-122(a-z)
}
// //判断如果字母为大写的A-Z就在前面拼接一个_
// if d >= 'A' && d <= 'Z' {
func
detectSQLInjection
(
input
string
)
bool
{
// if i > 0 {
return
detectSQLInjectionRe
.
MatchString
(
input
)
// if allMode {
}
// data = append(data, '_', d+32)
// } else {
/**
// if s[i-1] >= 'A' && s[i-1] <= 'Z' {
* 驼峰转蛇形 snake string
// data = append(data, d+32)
**/
// } else {
func
snakeCase
(
s
string
,
allMode
bool
)
string
{
// data = append(data, '_', d+32)
num
:=
len
(
s
)
// }
data
:=
make
([]
byte
,
0
,
num
*
2
)
// }
for
i
:=
0
;
i
<
num
;
i
++
{
// } else {
d
:=
s
[
i
]
// data = append(data, d+32)
// or通过ASCII码进行大小写的转化
// }
// 65-90(A-Z),97-122(a-z)
// } else {
//判断如果字母为大写的A-Z就在前面拼接一个_
// data = append(data, d)
if
d
>=
'A'
&&
d
<=
'Z'
{
// }
if
i
>
0
{
// }
if
allMode
{
// //ToLower把大写字母统一转小写
data
=
append
(
data
,
'_'
,
d
+
32
)
// return string(data[:])
}
else
{
// }
if
s
[
i
-
1
]
>=
'A'
&&
s
[
i
-
1
]
<=
'Z'
{
data
=
append
(
data
,
d
+
32
)
}
else
{
data
=
append
(
data
,
'_'
,
d
+
32
)
}
}
}
else
{
data
=
append
(
data
,
d
+
32
)
}
}
else
{
data
=
append
(
data
,
d
)
}
}
//ToLower把大写字母统一转小写
return
string
(
data
[
:
])
}
xcommon/controller.go
浏览文件 @
1ab6fb03
...
@@ -2,16 +2,17 @@ package xcommon
...
@@ -2,16 +2,17 @@ package xcommon
import
(
import
(
"context"
"context"
vd
"github.com/bytedance/go-tagexpr/v2/validator"
"net/http"
"net/http"
"os"
"os"
"testing"
"testing"
"time"
"time"
vd
"github.com/bytedance/go-tagexpr/v2/validator"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/response"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/httpcli"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/map_
utils"
maputils
"gitlab.wanzhuangkj.com/tush/xpkg/utils/map
utils"
)
)
type
IValid
interface
{
type
IValid
interface
{
...
@@ -104,7 +105,7 @@ func (x *ControllerTester) After(t *testing.T) {
...
@@ -104,7 +105,7 @@ func (x *ControllerTester) After(t *testing.T) {
func
(
x
*
ControllerTester
)
CommonHttp
(
method
,
URL
string
,
in
any
,
reply
*
response
.
Result
)
error
{
func
(
x
*
ControllerTester
)
CommonHttp
(
method
,
URL
string
,
in
any
,
reply
*
response
.
Result
)
error
{
if
method
==
http
.
MethodDelete
||
method
==
http
.
MethodGet
{
if
method
==
http
.
MethodDelete
||
method
==
http
.
MethodGet
{
in
=
map
_
utils
.
StructToMapWithJsonTag
(
in
)
in
=
maputils
.
StructToMapWithJsonTag
(
in
)
}
}
if
err
:=
x
.
client
.
NewRequest
()
.
if
err
:=
x
.
client
.
NewRequest
()
.
SetHeaders
(
x
.
Headers
)
.
SetHeaders
(
x
.
Headers
)
.
...
...
xcron/biz/cron_job.go
浏览文件 @
1ab6fb03
package
biz
package
biz
import
(
import
(
"context"
"encoding/json"
"encoding/json"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/models"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/models"
...
@@ -40,9 +39,6 @@ func (*CronJob) GetIDs(rs []*CronJob) []xsf.ID {
...
@@ -40,9 +39,6 @@ func (*CronJob) GetIDs(rs []*CronJob) []xsf.ID {
return
sliceUtils
.
GetIDs
(
rs
)
return
sliceUtils
.
GetIDs
(
rs
)
}
}
type
CronJobOpts
struct
{
}
func
(
CronJob
)
NewFromModel
(
m
*
models
.
CronJob
)
*
CronJob
{
func
(
CronJob
)
NewFromModel
(
m
*
models
.
CronJob
)
*
CronJob
{
if
m
==
nil
{
if
m
==
nil
{
return
nil
return
nil
...
@@ -58,23 +54,3 @@ func (x *CronJob) ToModel() *models.CronJob {
...
@@ -58,23 +54,3 @@ func (x *CronJob) ToModel() *models.CronJob {
}
}
return
&
x
.
CronJob
return
&
x
.
CronJob
}
}
func
(
x
CronJob
)
Valid
(
ctx
context
.
Context
,
cronJob
*
CronJob
,
opts
*
CronJobOpts
)
error
{
if
cronJob
==
nil
{
return
nil
}
if
opts
==
nil
{
opts
=
&
CronJobOpts
{}
}
return
nil
}
func
(
x
CronJob
)
ValidSlice
(
ctx
context
.
Context
,
cronJobBizSlice
[]
*
CronJob
,
opts
*
CronJobOpts
)
error
{
if
len
(
cronJobBizSlice
)
==
0
{
return
nil
}
if
opts
==
nil
{
opts
=
&
CronJobOpts
{}
}
return
nil
}
xcron/biz/cron_job_log.go
浏览文件 @
1ab6fb03
package
biz
package
biz
import
(
import
(
"context"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/sliceUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/xsf"
...
@@ -28,9 +26,6 @@ func (x *CronJobLog) GetJobIDs(rs []*CronJobLog) []xsf.ID {
...
@@ -28,9 +26,6 @@ func (x *CronJobLog) GetJobIDs(rs []*CronJobLog) []xsf.ID {
return
set
.
Slice
()
return
set
.
Slice
()
}
}
type
CronJobLogOpts
struct
{
}
func
(
CronJobLog
)
NewFromModel
(
m
*
models
.
CronJobLog
)
*
CronJobLog
{
func
(
CronJobLog
)
NewFromModel
(
m
*
models
.
CronJobLog
)
*
CronJobLog
{
if
m
==
nil
{
if
m
==
nil
{
return
nil
return
nil
...
@@ -46,23 +41,3 @@ func (x *CronJobLog) ToModel() *models.CronJobLog {
...
@@ -46,23 +41,3 @@ func (x *CronJobLog) ToModel() *models.CronJobLog {
}
}
return
&
x
.
CronJobLog
return
&
x
.
CronJobLog
}
}
func
(
x
CronJobLog
)
Valid
(
ctx
context
.
Context
,
cronJobLog
*
CronJobLog
,
opts
*
CronJobLogOpts
)
error
{
if
cronJobLog
==
nil
{
return
nil
}
if
opts
==
nil
{
opts
=
&
CronJobLogOpts
{}
}
return
nil
}
func
(
x
CronJobLog
)
ValidSlice
(
ctx
context
.
Context
,
cronJobLogBizSlice
[]
*
CronJobLog
,
opts
*
CronJobLogOpts
)
error
{
if
len
(
cronJobLogBizSlice
)
==
0
{
return
nil
}
if
opts
==
nil
{
opts
=
&
CronJobLogOpts
{}
}
return
nil
}
xcron/biz/cron_job_record.go
浏览文件 @
1ab6fb03
package
biz
package
biz
import
(
import
(
"context"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/models"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/models"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
"gitlab.wanzhuangkj.com/tush/xpkg/utils/setUtils"
...
@@ -28,9 +27,6 @@ func (x *CronJobRecord) GetJobIDs(rs []*CronJobRecord) []xsf.ID {
...
@@ -28,9 +27,6 @@ func (x *CronJobRecord) GetJobIDs(rs []*CronJobRecord) []xsf.ID {
return
set
.
Slice
()
return
set
.
Slice
()
}
}
type
CronJobRecordOpts
struct
{
}
func
(
CronJobRecord
)
NewFromModel
(
m
*
models
.
CronJobRecord
)
*
CronJobRecord
{
func
(
CronJobRecord
)
NewFromModel
(
m
*
models
.
CronJobRecord
)
*
CronJobRecord
{
if
m
==
nil
{
if
m
==
nil
{
return
nil
return
nil
...
@@ -46,23 +42,3 @@ func (x *CronJobRecord) ToModel() *models.CronJobRecord {
...
@@ -46,23 +42,3 @@ func (x *CronJobRecord) ToModel() *models.CronJobRecord {
}
}
return
&
x
.
CronJobRecord
return
&
x
.
CronJobRecord
}
}
func
(
x
CronJobRecord
)
Valid
(
ctx
context
.
Context
,
cronJobRecord
*
CronJobRecord
,
opts
*
CronJobRecordOpts
)
error
{
if
cronJobRecord
==
nil
{
return
nil
}
if
opts
==
nil
{
opts
=
&
CronJobRecordOpts
{}
}
return
nil
}
func
(
x
CronJobRecord
)
ValidSlice
(
ctx
context
.
Context
,
cronJobRecordBizSlice
[]
*
CronJobRecord
,
opts
*
CronJobRecordOpts
)
error
{
if
len
(
cronJobRecordBizSlice
)
==
0
{
return
nil
}
if
opts
==
nil
{
opts
=
&
CronJobRecordOpts
{}
}
return
nil
}
xcron/cron.sql
浏览文件 @
1ab6fb03
...
@@ -17,6 +17,7 @@ CREATE TABLE `cron_job_log` (
...
@@ -17,6 +17,7 @@ CREATE TABLE `cron_job_log` (
`job_id`
bigint
(
20
)
unsigned
NOT
NULL
COMMENT
'job ID eg[101]'
,
`job_id`
bigint
(
20
)
unsigned
NOT
NULL
COMMENT
'job ID eg[101]'
,
`info`
text
COLLATE
utf8mb4_unicode_ci
COMMENT
'日志 eg[job occur error...]'
,
`info`
text
COLLATE
utf8mb4_unicode_ci
COMMENT
'日志 eg[job occur error...]'
,
`created_at`
datetime
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
COMMENT
'创建时间 eg[2025-01-07 12:20:43]'
,
`created_at`
datetime
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
COMMENT
'创建时间 eg[2025-01-07 12:20:43]'
,
`updated_at`
datetime
DEFAULT
NULL
COMMENT
'修改时间 eg[2025-01-07 12:20:43]'
,
PRIMARY
KEY
(
`id`
),
PRIMARY
KEY
(
`id`
),
KEY
`idx_jobid_time`
(
`job_id`
,
`created_at`
)
KEY
`idx_jobid_time`
(
`job_id`
,
`created_at`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb4
COLLATE
=
utf8mb4_unicode_ci
ROW_FORMAT
=
DYNAMIC
COMMENT
=
'定时任务日志'
;
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb4
COLLATE
=
utf8mb4_unicode_ci
ROW_FORMAT
=
DYNAMIC
COMMENT
=
'定时任务日志'
;
...
...
xcron/ecode/cron.go
浏览文件 @
1ab6fb03
package
ecode
package
ecode
import
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/errcode"
import
(
"errors"
)
var
(
var
(
ErrCronJobNotFound
=
err
code
.
NewError
(
12001
,
"未查询到任务"
)
ErrCronJobNotFound
=
err
ors
.
New
(
"未查询到任务"
)
)
)
xcron/service/cron_job.go
浏览文件 @
1ab6fb03
...
@@ -29,7 +29,7 @@ func newCronJobService() *cronJobService {
...
@@ -29,7 +29,7 @@ func newCronJobService() *cronJobService {
Service
:
xcommon
.
NewService
(),
Service
:
xcommon
.
NewService
(),
}
}
}
}
func
(
x
*
cronJobService
)
GetByJobCode
(
ctx
context
.
Context
,
jobCode
string
,
opts
*
biz
.
CronJobOpts
)
(
*
biz
.
CronJob
,
error
)
{
func
(
x
*
cronJobService
)
GetByJobCode
(
ctx
context
.
Context
,
jobCode
string
)
(
*
biz
.
CronJob
,
error
)
{
if
jobCode
==
""
{
if
jobCode
==
""
{
return
nil
,
nil
return
nil
,
nil
}
}
...
@@ -37,14 +37,14 @@ func (x *cronJobService) GetByJobCode(ctx context.Context, jobCode string, opts
...
@@ -37,14 +37,14 @@ func (x *cronJobService) GetByJobCode(ctx context.Context, jobCode string, opts
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
x
.
ToBiz
(
ctx
,
cronJob
,
opts
)
return
x
.
ToBiz
(
ctx
,
cronJob
)
}
}
func
(
x
*
cronJobService
)
GetNotRunning
(
ctx
context
.
Context
,
id
xsf
.
ID
)
(
*
models
.
CronJob
,
error
)
{
func
(
x
*
cronJobService
)
GetNotRunning
(
ctx
context
.
Context
,
id
xsf
.
ID
)
(
*
models
.
CronJob
,
error
)
{
return
dao
.
CronJobDao
.
GetNotRunning
(
ctx
,
id
)
return
dao
.
CronJobDao
.
GetNotRunning
(
ctx
,
id
)
}
}
func
(
x
*
cronJobService
)
Create
(
ctx
context
.
Context
,
req
*
types
.
CronJobCreateReq
,
opts
*
biz
.
CronJobOpts
)
(
id
xsf
.
ID
,
err
error
)
{
func
(
x
*
cronJobService
)
Create
(
ctx
context
.
Context
,
req
*
types
.
CronJobCreateReq
)
(
id
xsf
.
ID
,
err
error
)
{
cronJob
:=
&
models
.
CronJob
{}
cronJob
:=
&
models
.
CronJob
{}
_
=
copier
.
Copy
(
cronJob
,
req
)
_
=
copier
.
Copy
(
cronJob
,
req
)
if
err
=
dao
.
CronJobDao
.
Create
(
ctx
,
cronJob
);
err
!=
nil
{
if
err
=
dao
.
CronJobDao
.
Create
(
ctx
,
cronJob
);
err
!=
nil
{
...
@@ -53,25 +53,25 @@ func (x *cronJobService) Create(ctx context.Context, req *types.CronJobCreateReq
...
@@ -53,25 +53,25 @@ func (x *cronJobService) Create(ctx context.Context, req *types.CronJobCreateReq
return
cronJob
.
ID
,
nil
return
cronJob
.
ID
,
nil
}
}
func
(
x
*
cronJobService
)
DeleteByID
(
ctx
context
.
Context
,
id
xsf
.
ID
,
opts
*
biz
.
CronJobOpts
)
error
{
func
(
x
*
cronJobService
)
DeleteByID
(
ctx
context
.
Context
,
id
xsf
.
ID
)
error
{
if
id
<=
0
{
if
id
<=
0
{
return
nil
return
nil
}
}
cronJob
,
err
:=
x
.
GetByID
(
ctx
,
id
,
opts
)
cronJob
,
err
:=
x
.
GetByID
(
ctx
,
id
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
cronJob
==
nil
{
if
cronJob
==
nil
{
return
xerror
.
New
C
(
ecode
.
ErrCronJobNotFound
.
Code
(),
fmt
.
Sprintf
(
"未查询到%s[id:%d]"
,
models
.
CronJobTool
.
TableName
(),
id
))
return
xerror
.
New
(
fmt
.
Sprintf
(
"未查询到%s[id:%d]"
,
models
.
CronJobTool
.
TableName
(),
id
))
}
}
return
dao
.
CronJobDao
.
DeleteByID
(
ctx
,
id
)
return
dao
.
CronJobDao
.
DeleteByID
(
ctx
,
id
)
}
}
func
(
x
*
cronJobService
)
DeleteByIDs
(
ctx
context
.
Context
,
ids
[]
xsf
.
ID
,
opts
*
biz
.
CronJobOpts
)
error
{
func
(
x
*
cronJobService
)
DeleteByIDs
(
ctx
context
.
Context
,
ids
[]
xsf
.
ID
)
error
{
if
len
(
ids
)
==
0
{
if
len
(
ids
)
==
0
{
return
nil
return
nil
}
}
cronJobs
,
err
:=
x
.
GetSliceByIDs
(
ctx
,
ids
,
opts
)
cronJobs
,
err
:=
x
.
GetSliceByIDs
(
ctx
,
ids
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -82,43 +82,43 @@ func (x *cronJobService) DeleteByIDs(ctx context.Context, ids []xsf.ID, opts *bi
...
@@ -82,43 +82,43 @@ func (x *cronJobService) DeleteByIDs(ctx context.Context, ids []xsf.ID, opts *bi
return
dao
.
CronJobDao
.
DeleteByIDs
(
ctx
,
ids
)
return
dao
.
CronJobDao
.
DeleteByIDs
(
ctx
,
ids
)
}
}
func
(
x
*
cronJobService
)
StartByID
(
ctx
context
.
Context
,
id
xsf
.
ID
,
opts
*
biz
.
CronJobOpts
)
error
{
func
(
x
*
cronJobService
)
StartByID
(
ctx
context
.
Context
,
id
xsf
.
ID
)
error
{
req
:=
&
types
.
CronJobUpdateByIDReq
{
req
:=
&
types
.
CronJobUpdateByIDReq
{
ID
:
id
,
ID
:
id
,
Enable
:
enums
.
CronJob_Enable_OPEN
,
Enable
:
enums
.
CronJob_Enable_OPEN
,
}
}
return
x
.
UpdateByID
(
ctx
,
req
,
opts
)
return
x
.
UpdateByID
(
ctx
,
req
)
}
}
func
(
x
*
cronJobService
)
StopByID
(
ctx
context
.
Context
,
id
xsf
.
ID
,
opts
*
biz
.
CronJobOpts
)
error
{
func
(
x
*
cronJobService
)
StopByID
(
ctx
context
.
Context
,
id
xsf
.
ID
)
error
{
req
:=
&
types
.
CronJobUpdateByIDReq
{
req
:=
&
types
.
CronJobUpdateByIDReq
{
ID
:
id
,
ID
:
id
,
Enable
:
enums
.
CronJob_Enable_CLOSE
,
Enable
:
enums
.
CronJob_Enable_CLOSE
,
}
}
return
x
.
UpdateByID
(
ctx
,
req
,
opts
)
return
x
.
UpdateByID
(
ctx
,
req
)
}
}
func
(
x
*
cronJobService
)
UpdateByID
(
ctx
context
.
Context
,
req
*
types
.
CronJobUpdateByIDReq
,
opts
*
biz
.
CronJobOpts
)
error
{
func
(
x
*
cronJobService
)
UpdateByID
(
ctx
context
.
Context
,
req
*
types
.
CronJobUpdateByIDReq
)
error
{
if
req
.
ID
<=
0
{
if
req
.
ID
<=
0
{
return
nil
return
nil
}
}
cronJob
,
err
:=
x
.
GetByID
(
ctx
,
req
.
ID
,
opts
)
cronJob
,
err
:=
x
.
GetByID
(
ctx
,
req
.
ID
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
cronJob
==
nil
{
if
cronJob
==
nil
{
return
xerror
.
New
C
(
ecode
.
ErrCronJobNotFound
.
Code
(),
fmt
.
Sprintf
(
"未查询到%s[id:%d]"
,
models
.
CronJobTool
.
TableName
(),
req
.
ID
))
return
xerror
.
New
(
fmt
.
Sprintf
(
"未查询到%s[id:%d]"
,
models
.
CronJobTool
.
TableName
(),
req
.
ID
))
}
}
cronJobUpd
:=
&
models
.
CronJob
{}
cronJobUpd
:=
&
models
.
CronJob
{}
_
=
copier
.
Copy
(
cronJobUpd
,
req
)
_
=
copier
.
Copy
(
cronJobUpd
,
req
)
return
dao
.
CronJobDao
.
UpdateByID
(
ctx
,
cronJobUpd
.
ID
,
cronJobUpd
)
return
dao
.
CronJobDao
.
UpdateByID
(
ctx
,
cronJobUpd
.
ID
,
cronJobUpd
)
}
}
func
(
x
*
cronJobService
)
UpdateByIDs
(
ctx
context
.
Context
,
req
*
types
.
CronJobUpdateByIDsReq
,
opts
*
biz
.
CronJobOpts
)
error
{
func
(
x
*
cronJobService
)
UpdateByIDs
(
ctx
context
.
Context
,
req
*
types
.
CronJobUpdateByIDsReq
)
error
{
if
len
(
req
.
IDs
)
==
0
{
if
len
(
req
.
IDs
)
==
0
{
return
nil
return
nil
}
}
cronJobs
,
err
:=
x
.
GetSliceByIDs
(
ctx
,
req
.
IDs
,
opts
)
cronJobs
,
err
:=
x
.
GetSliceByIDs
(
ctx
,
req
.
IDs
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -131,7 +131,7 @@ func (x *cronJobService) UpdateByIDs(ctx context.Context, req *types.CronJobUpda
...
@@ -131,7 +131,7 @@ func (x *cronJobService) UpdateByIDs(ctx context.Context, req *types.CronJobUpda
return
dao
.
CronJobDao
.
UpdateByIDs
(
ctx
,
req
.
IDs
,
cronJobUpd
)
return
dao
.
CronJobDao
.
UpdateByIDs
(
ctx
,
req
.
IDs
,
cronJobUpd
)
}
}
func
(
x
*
cronJobService
)
GetByID
(
ctx
context
.
Context
,
id
xsf
.
ID
,
opts
*
biz
.
CronJobOpts
)
(
cronJobBiz
*
biz
.
CronJob
,
err
error
)
{
func
(
x
*
cronJobService
)
GetByID
(
ctx
context
.
Context
,
id
xsf
.
ID
)
(
cronJobBiz
*
biz
.
CronJob
,
err
error
)
{
if
id
<=
0
{
if
id
<=
0
{
return
nil
,
nil
return
nil
,
nil
}
}
...
@@ -142,10 +142,10 @@ func (x *cronJobService) GetByID(ctx context.Context, id xsf.ID, opts *biz.CronJ
...
@@ -142,10 +142,10 @@ func (x *cronJobService) GetByID(ctx context.Context, id xsf.ID, opts *biz.CronJ
if
cronJob
==
nil
{
if
cronJob
==
nil
{
return
nil
,
nil
return
nil
,
nil
}
}
return
x
.
ToBiz
(
ctx
,
cronJob
,
opts
)
return
x
.
ToBiz
(
ctx
,
cronJob
)
}
}
func
(
x
*
cronJobService
)
GetSliceByIDs
(
ctx
context
.
Context
,
ids
[]
xsf
.
ID
,
opts
*
biz
.
CronJobOpts
)
([]
*
biz
.
CronJob
,
error
)
{
func
(
x
*
cronJobService
)
GetSliceByIDs
(
ctx
context
.
Context
,
ids
[]
xsf
.
ID
)
([]
*
biz
.
CronJob
,
error
)
{
if
len
(
ids
)
==
0
{
if
len
(
ids
)
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
...
@@ -156,14 +156,14 @@ func (x *cronJobService) GetSliceByIDs(ctx context.Context, ids []xsf.ID, opts *
...
@@ -156,14 +156,14 @@ func (x *cronJobService) GetSliceByIDs(ctx context.Context, ids []xsf.ID, opts *
if
len
(
cronJobs
)
==
0
{
if
len
(
cronJobs
)
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
return
x
.
ToSliceBiz
(
ctx
,
cronJobs
,
opts
)
return
x
.
ToSliceBiz
(
ctx
,
cronJobs
)
}
}
func
(
x
*
cronJobService
)
GetMapByIDs
(
ctx
context
.
Context
,
ids
[]
xsf
.
ID
,
opts
*
biz
.
CronJobOpts
)
(
map
[
xsf
.
ID
]
*
biz
.
CronJob
,
error
)
{
func
(
x
*
cronJobService
)
GetMapByIDs
(
ctx
context
.
Context
,
ids
[]
xsf
.
ID
)
(
map
[
xsf
.
ID
]
*
biz
.
CronJob
,
error
)
{
if
len
(
ids
)
==
0
{
if
len
(
ids
)
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
cronJobBizSlice
,
err
:=
x
.
GetSliceByIDs
(
ctx
,
ids
,
opts
)
cronJobBizSlice
,
err
:=
x
.
GetSliceByIDs
(
ctx
,
ids
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -174,7 +174,7 @@ func (x *cronJobService) GetMapByIDs(ctx context.Context, ids []xsf.ID, opts *bi
...
@@ -174,7 +174,7 @@ func (x *cronJobService) GetMapByIDs(ctx context.Context, ids []xsf.ID, opts *bi
return
cronJobBizIDMap
,
nil
return
cronJobBizIDMap
,
nil
}
}
func
(
x
*
cronJobService
)
Page
(
ctx
context
.
Context
,
req
*
types
.
CronJobPageReq
,
opts
*
biz
.
CronJobOpts
)
([]
*
biz
.
CronJob
,
int64
,
error
)
{
func
(
x
*
cronJobService
)
Page
(
ctx
context
.
Context
,
req
*
types
.
CronJobPageReq
)
([]
*
biz
.
CronJob
,
int64
,
error
)
{
cronJobs
,
total
,
err
:=
dao
.
CronJobDao
.
Page
(
ctx
,
req
)
cronJobs
,
total
,
err
:=
dao
.
CronJobDao
.
Page
(
ctx
,
req
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
0
,
err
return
nil
,
0
,
err
...
@@ -182,13 +182,13 @@ func (x *cronJobService) Page(ctx context.Context, req *types.CronJobPageReq, op
...
@@ -182,13 +182,13 @@ func (x *cronJobService) Page(ctx context.Context, req *types.CronJobPageReq, op
if
len
(
cronJobs
)
==
0
{
if
len
(
cronJobs
)
==
0
{
return
nil
,
total
,
nil
return
nil
,
total
,
nil
}
}
cronJobBizSlice
,
err
:=
x
.
ToSliceBiz
(
ctx
,
cronJobs
,
opts
)
cronJobBizSlice
,
err
:=
x
.
ToSliceBiz
(
ctx
,
cronJobs
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
0
,
err
return
nil
,
0
,
err
}
}
return
cronJobBizSlice
,
total
,
nil
return
cronJobBizSlice
,
total
,
nil
}
}
func
(
x
*
cronJobService
)
GetSliceByState
(
ctx
context
.
Context
,
state
enums
.
CronJob_State_Enum
,
opts
*
biz
.
CronJobOpts
)
([]
*
biz
.
CronJob
,
error
)
{
func
(
x
*
cronJobService
)
GetSliceByState
(
ctx
context
.
Context
,
state
enums
.
CronJob_State_Enum
)
([]
*
biz
.
CronJob
,
error
)
{
cronJobs
,
err
:=
dao
.
CronJobDao
.
GetSliceByState
(
ctx
,
models
.
CronJobTool
.
GetOrder
(),
state
)
cronJobs
,
err
:=
dao
.
CronJobDao
.
GetSliceByState
(
ctx
,
models
.
CronJobTool
.
GetOrder
(),
state
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -196,10 +196,10 @@ func (x *cronJobService) GetSliceByState(ctx context.Context, state enums.CronJo
...
@@ -196,10 +196,10 @@ func (x *cronJobService) GetSliceByState(ctx context.Context, state enums.CronJo
if
len
(
cronJobs
)
==
0
{
if
len
(
cronJobs
)
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
return
x
.
ToSliceBiz
(
ctx
,
cronJobs
,
opts
)
return
x
.
ToSliceBiz
(
ctx
,
cronJobs
)
}
}
func
(
x
*
cronJobService
)
GetSliceByStates
(
ctx
context
.
Context
,
states
[]
enums
.
CronJob_State_Enum
,
opts
*
biz
.
CronJobOpts
)
([]
*
biz
.
CronJob
,
error
)
{
func
(
x
*
cronJobService
)
GetSliceByStates
(
ctx
context
.
Context
,
states
[]
enums
.
CronJob_State_Enum
)
([]
*
biz
.
CronJob
,
error
)
{
if
len
(
states
)
==
0
{
if
len
(
states
)
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
...
@@ -214,14 +214,14 @@ func (x *cronJobService) GetSliceByStates(ctx context.Context, states []enums.Cr
...
@@ -214,14 +214,14 @@ func (x *cronJobService) GetSliceByStates(ctx context.Context, states []enums.Cr
for
_
,
v
:=
range
cronJobMapSlice
{
for
_
,
v
:=
range
cronJobMapSlice
{
cronJobs
=
append
(
cronJobs
,
v
...
)
cronJobs
=
append
(
cronJobs
,
v
...
)
}
}
return
x
.
ToSliceBiz
(
ctx
,
cronJobs
,
opts
)
return
x
.
ToSliceBiz
(
ctx
,
cronJobs
)
}
}
func
(
x
*
cronJobService
)
GetMapSliceByStates
(
ctx
context
.
Context
,
states
[]
enums
.
CronJob_State_Enum
,
opts
*
biz
.
CronJobOpts
)
(
map
[
enums
.
CronJob_State_Enum
][]
*
biz
.
CronJob
,
int
,
error
)
{
func
(
x
*
cronJobService
)
GetMapSliceByStates
(
ctx
context
.
Context
,
states
[]
enums
.
CronJob_State_Enum
)
(
map
[
enums
.
CronJob_State_Enum
][]
*
biz
.
CronJob
,
int
,
error
)
{
if
len
(
states
)
==
0
{
if
len
(
states
)
==
0
{
return
nil
,
0
,
nil
return
nil
,
0
,
nil
}
}
cronJobBizSlice
,
err
:=
x
.
GetSliceByStates
(
ctx
,
states
,
opts
)
cronJobBizSlice
,
err
:=
x
.
GetSliceByStates
(
ctx
,
states
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
0
,
err
return
nil
,
0
,
err
}
}
...
@@ -235,7 +235,7 @@ func (x *cronJobService) GetMapSliceByStates(ctx context.Context, states []enums
...
@@ -235,7 +235,7 @@ func (x *cronJobService) GetMapSliceByStates(ctx context.Context, states []enums
return
ret
,
len
(
cronJobBizSlice
),
nil
return
ret
,
len
(
cronJobBizSlice
),
nil
}
}
func
(
x
*
cronJobService
)
GetSliceByEnable
(
ctx
context
.
Context
,
enable
enums
.
CronJob_Enable_Enum
,
opts
*
biz
.
CronJobOpts
)
([]
*
biz
.
CronJob
,
error
)
{
func
(
x
*
cronJobService
)
GetSliceByEnable
(
ctx
context
.
Context
,
enable
enums
.
CronJob_Enable_Enum
)
([]
*
biz
.
CronJob
,
error
)
{
cronJobs
,
err
:=
dao
.
CronJobDao
.
GetSliceByEnable
(
ctx
,
models
.
CronJobTool
.
GetOrder
(),
enable
)
cronJobs
,
err
:=
dao
.
CronJobDao
.
GetSliceByEnable
(
ctx
,
models
.
CronJobTool
.
GetOrder
(),
enable
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -243,56 +243,26 @@ func (x *cronJobService) GetSliceByEnable(ctx context.Context, enable enums.Cron
...
@@ -243,56 +243,26 @@ func (x *cronJobService) GetSliceByEnable(ctx context.Context, enable enums.Cron
if
len
(
cronJobs
)
==
0
{
if
len
(
cronJobs
)
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
return
x
.
ToSliceBiz
(
ctx
,
cronJobs
,
opts
)
return
x
.
ToSliceBiz
(
ctx
,
cronJobs
)
}
}
func
(
x
*
cronJobService
)
ToBiz
(
ctx
context
.
Context
,
cronJob
*
models
.
CronJob
,
opts
*
biz
.
CronJobOpts
)
(
cronJobBiz
*
biz
.
CronJob
,
err
error
)
{
func
(
x
*
cronJobService
)
ToBiz
(
ctx
context
.
Context
,
cronJob
*
models
.
CronJob
)
(
cronJobBiz
*
biz
.
CronJob
,
err
error
)
{
if
cronJob
==
nil
{
if
cronJob
==
nil
{
return
nil
,
nil
return
nil
,
nil
}
}
cronJobBiz
=
biz
.
CronJobTool
.
NewFromModel
(
cronJob
)
cronJobBiz
=
biz
.
CronJobTool
.
NewFromModel
(
cronJob
)
if
err
=
x
.
Fill
(
ctx
,
cronJobBiz
,
opts
);
err
!=
nil
{
return
nil
,
err
}
if
err
=
biz
.
CronJobTool
.
Valid
(
ctx
,
cronJobBiz
,
opts
);
err
!=
nil
{
return
nil
,
err
}
return
cronJobBiz
,
nil
return
cronJobBiz
,
nil
}
}
func
(
x
*
cronJobService
)
ToSliceBiz
(
ctx
context
.
Context
,
cronJobs
[]
*
models
.
CronJob
,
opts
*
biz
.
CronJobOpts
)
(
cronJobBizSlice
[]
*
biz
.
CronJob
,
err
error
)
{
func
(
x
*
cronJobService
)
ToSliceBiz
(
ctx
context
.
Context
,
cronJobs
[]
*
models
.
CronJob
)
(
cronJobBizSlice
[]
*
biz
.
CronJob
,
err
error
)
{
if
len
(
cronJobs
)
==
0
{
if
len
(
cronJobs
)
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
cronJobBizSlice
=
biz
.
CronJobTool
.
NewSliceFromModelsBiz
(
cronJobs
)
cronJobBizSlice
=
biz
.
CronJobTool
.
NewSliceFromModelsBiz
(
cronJobs
)
if
err
=
x
.
SliceFill
(
ctx
,
cronJobBizSlice
,
opts
);
err
!=
nil
{
return
nil
,
err
}
if
err
=
biz
.
CronJobTool
.
ValidSlice
(
ctx
,
cronJobBizSlice
,
opts
);
err
!=
nil
{
return
nil
,
err
}
return
cronJobBizSlice
,
nil
return
cronJobBizSlice
,
nil
}
}
func
(
x
*
cronJobService
)
Fill
(
ctx
context
.
Context
,
cronJobBiz
*
biz
.
CronJob
,
opts
*
biz
.
CronJobOpts
)
error
{
func
(
x
*
cronJobService
)
GetAll
(
ctx
context
.
Context
)
([]
*
biz
.
CronJob
,
error
)
{
if
cronJobBiz
==
nil
{
return
nil
}
if
opts
!=
nil
{
}
return
nil
}
func
(
x
*
cronJobService
)
SliceFill
(
ctx
context
.
Context
,
cronJobBizSlice
[]
*
biz
.
CronJob
,
opts
*
biz
.
CronJobOpts
)
error
{
if
len
(
cronJobBizSlice
)
==
0
{
return
nil
}
if
opts
!=
nil
{
}
return
nil
}
func
(
x
*
cronJobService
)
GetAll
(
ctx
context
.
Context
,
opts
*
biz
.
CronJobOpts
)
([]
*
biz
.
CronJob
,
error
)
{
cronJobs
,
err
:=
dao
.
CronJobDao
.
GetAll
(
ctx
)
cronJobs
,
err
:=
dao
.
CronJobDao
.
GetAll
(
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -300,5 +270,5 @@ func (x *cronJobService) GetAll(ctx context.Context, opts *biz.CronJobOpts) ([]*
...
@@ -300,5 +270,5 @@ func (x *cronJobService) GetAll(ctx context.Context, opts *biz.CronJobOpts) ([]*
if
len
(
cronJobs
)
==
0
{
if
len
(
cronJobs
)
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
return
x
.
ToSliceBiz
(
ctx
,
cronJobs
,
opts
)
return
x
.
ToSliceBiz
(
ctx
,
cronJobs
)
}
}
xcron/service/cron_job_log.go
浏览文件 @
1ab6fb03
...
@@ -23,7 +23,7 @@ func newCronJobLogService() *cronJobLogService {
...
@@ -23,7 +23,7 @@ func newCronJobLogService() *cronJobLogService {
}
}
}
}
func
(
x
*
cronJobLogService
)
GetByID
(
ctx
context
.
Context
,
id
xsf
.
ID
,
opts
*
biz
.
CronJobLogOpts
)
(
cronJobLogBiz
*
biz
.
CronJobLog
,
err
error
)
{
func
(
x
*
cronJobLogService
)
GetByID
(
ctx
context
.
Context
,
id
xsf
.
ID
)
(
cronJobLogBiz
*
biz
.
CronJobLog
,
err
error
)
{
if
id
<=
0
{
if
id
<=
0
{
return
nil
,
nil
return
nil
,
nil
}
}
...
@@ -34,10 +34,10 @@ func (x *cronJobLogService) GetByID(ctx context.Context, id xsf.ID, opts *biz.Cr
...
@@ -34,10 +34,10 @@ func (x *cronJobLogService) GetByID(ctx context.Context, id xsf.ID, opts *biz.Cr
if
cronJobLog
==
nil
{
if
cronJobLog
==
nil
{
return
nil
,
nil
return
nil
,
nil
}
}
return
x
.
ToBiz
(
ctx
,
cronJobLog
,
opts
)
return
x
.
ToBiz
(
ctx
,
cronJobLog
)
}
}
func
(
x
*
cronJobLogService
)
GetSliceByIDs
(
ctx
context
.
Context
,
ids
[]
xsf
.
ID
,
opts
*
biz
.
CronJobLogOpts
)
([]
*
biz
.
CronJobLog
,
error
)
{
func
(
x
*
cronJobLogService
)
GetSliceByIDs
(
ctx
context
.
Context
,
ids
[]
xsf
.
ID
)
([]
*
biz
.
CronJobLog
,
error
)
{
if
len
(
ids
)
==
0
{
if
len
(
ids
)
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
...
@@ -48,14 +48,14 @@ func (x *cronJobLogService) GetSliceByIDs(ctx context.Context, ids []xsf.ID, opt
...
@@ -48,14 +48,14 @@ func (x *cronJobLogService) GetSliceByIDs(ctx context.Context, ids []xsf.ID, opt
if
len
(
cronJobLogs
)
==
0
{
if
len
(
cronJobLogs
)
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
return
x
.
ToSliceBiz
(
ctx
,
cronJobLogs
,
opts
)
return
x
.
ToSliceBiz
(
ctx
,
cronJobLogs
)
}
}
func
(
x
*
cronJobLogService
)
GetMapByIDs
(
ctx
context
.
Context
,
ids
[]
xsf
.
ID
,
opts
*
biz
.
CronJobLogOpts
)
(
map
[
xsf
.
ID
]
*
biz
.
CronJobLog
,
error
)
{
func
(
x
*
cronJobLogService
)
GetMapByIDs
(
ctx
context
.
Context
,
ids
[]
xsf
.
ID
)
(
map
[
xsf
.
ID
]
*
biz
.
CronJobLog
,
error
)
{
if
len
(
ids
)
==
0
{
if
len
(
ids
)
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
cronJobLogBizSlice
,
err
:=
x
.
GetSliceByIDs
(
ctx
,
ids
,
opts
)
cronJobLogBizSlice
,
err
:=
x
.
GetSliceByIDs
(
ctx
,
ids
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -66,7 +66,7 @@ func (x *cronJobLogService) GetMapByIDs(ctx context.Context, ids []xsf.ID, opts
...
@@ -66,7 +66,7 @@ func (x *cronJobLogService) GetMapByIDs(ctx context.Context, ids []xsf.ID, opts
return
cronJobLogBizIDMap
,
nil
return
cronJobLogBizIDMap
,
nil
}
}
func
(
x
*
cronJobLogService
)
Page
(
ctx
context
.
Context
,
req
*
types
.
CronJobLogPageReq
,
opts
*
biz
.
CronJobLogOpts
)
([]
*
biz
.
CronJobLog
,
int64
,
error
)
{
func
(
x
*
cronJobLogService
)
Page
(
ctx
context
.
Context
,
req
*
types
.
CronJobLogPageReq
)
([]
*
biz
.
CronJobLog
,
int64
,
error
)
{
cronJobLogs
,
total
,
err
:=
dao
.
CronJobLogDao
.
Page
(
ctx
,
req
)
cronJobLogs
,
total
,
err
:=
dao
.
CronJobLogDao
.
Page
(
ctx
,
req
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
0
,
err
return
nil
,
0
,
err
...
@@ -74,13 +74,13 @@ func (x *cronJobLogService) Page(ctx context.Context, req *types.CronJobLogPageR
...
@@ -74,13 +74,13 @@ func (x *cronJobLogService) Page(ctx context.Context, req *types.CronJobLogPageR
if
len
(
cronJobLogs
)
==
0
{
if
len
(
cronJobLogs
)
==
0
{
return
nil
,
total
,
nil
return
nil
,
total
,
nil
}
}
cronJobLogBizSlice
,
err
:=
x
.
ToSliceBiz
(
ctx
,
cronJobLogs
,
opts
)
cronJobLogBizSlice
,
err
:=
x
.
ToSliceBiz
(
ctx
,
cronJobLogs
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
0
,
err
return
nil
,
0
,
err
}
}
return
cronJobLogBizSlice
,
total
,
nil
return
cronJobLogBizSlice
,
total
,
nil
}
}
func
(
x
*
cronJobLogService
)
GetSliceByJobID
(
ctx
context
.
Context
,
jobID
xsf
.
ID
,
opts
*
biz
.
CronJobLogOpts
)
([]
*
biz
.
CronJobLog
,
error
)
{
func
(
x
*
cronJobLogService
)
GetSliceByJobID
(
ctx
context
.
Context
,
jobID
xsf
.
ID
)
([]
*
biz
.
CronJobLog
,
error
)
{
if
jobID
==
0
{
if
jobID
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
...
@@ -91,10 +91,10 @@ func (x *cronJobLogService) GetSliceByJobID(ctx context.Context, jobID xsf.ID, o
...
@@ -91,10 +91,10 @@ func (x *cronJobLogService) GetSliceByJobID(ctx context.Context, jobID xsf.ID, o
if
len
(
cronJobLogs
)
==
0
{
if
len
(
cronJobLogs
)
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
return
x
.
ToSliceBiz
(
ctx
,
cronJobLogs
,
opts
)
return
x
.
ToSliceBiz
(
ctx
,
cronJobLogs
)
}
}
func
(
x
*
cronJobLogService
)
GetSliceByJobIDs
(
ctx
context
.
Context
,
jobIDs
[]
xsf
.
ID
,
opts
*
biz
.
CronJobLogOpts
)
([]
*
biz
.
CronJobLog
,
error
)
{
func
(
x
*
cronJobLogService
)
GetSliceByJobIDs
(
ctx
context
.
Context
,
jobIDs
[]
xsf
.
ID
)
([]
*
biz
.
CronJobLog
,
error
)
{
if
len
(
jobIDs
)
==
0
{
if
len
(
jobIDs
)
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
...
@@ -105,14 +105,14 @@ func (x *cronJobLogService) GetSliceByJobIDs(ctx context.Context, jobIDs []xsf.I
...
@@ -105,14 +105,14 @@ func (x *cronJobLogService) GetSliceByJobIDs(ctx context.Context, jobIDs []xsf.I
if
len
(
cronJobLogs
)
==
0
{
if
len
(
cronJobLogs
)
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
return
x
.
ToSliceBiz
(
ctx
,
cronJobLogs
,
opts
)
return
x
.
ToSliceBiz
(
ctx
,
cronJobLogs
)
}
}
func
(
x
*
cronJobLogService
)
GetMapSliceByJobIDs
(
ctx
context
.
Context
,
jobIDs
[]
xsf
.
ID
,
opts
*
biz
.
CronJobLogOpts
)
(
map
[
xsf
.
ID
][]
*
biz
.
CronJobLog
,
int
,
error
)
{
func
(
x
*
cronJobLogService
)
GetMapSliceByJobIDs
(
ctx
context
.
Context
,
jobIDs
[]
xsf
.
ID
)
(
map
[
xsf
.
ID
][]
*
biz
.
CronJobLog
,
int
,
error
)
{
if
len
(
jobIDs
)
==
0
{
if
len
(
jobIDs
)
==
0
{
return
nil
,
0
,
nil
return
nil
,
0
,
nil
}
}
cronJobLogBizSlice
,
err
:=
x
.
GetSliceByJobIDs
(
ctx
,
jobIDs
,
opts
)
cronJobLogBizSlice
,
err
:=
x
.
GetSliceByJobIDs
(
ctx
,
jobIDs
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
0
,
err
return
nil
,
0
,
err
}
}
...
@@ -126,53 +126,23 @@ func (x *cronJobLogService) GetMapSliceByJobIDs(ctx context.Context, jobIDs []xs
...
@@ -126,53 +126,23 @@ func (x *cronJobLogService) GetMapSliceByJobIDs(ctx context.Context, jobIDs []xs
return
ret
,
len
(
cronJobLogBizSlice
),
nil
return
ret
,
len
(
cronJobLogBizSlice
),
nil
}
}
func
(
x
*
cronJobLogService
)
ToBiz
(
ctx
context
.
Context
,
cronJobLog
*
models
.
CronJobLog
,
opts
*
biz
.
CronJobLogOpts
)
(
cronJobLogBiz
*
biz
.
CronJobLog
,
err
error
)
{
func
(
x
*
cronJobLogService
)
ToBiz
(
ctx
context
.
Context
,
cronJobLog
*
models
.
CronJobLog
)
(
cronJobLogBiz
*
biz
.
CronJobLog
,
err
error
)
{
if
cronJobLog
==
nil
{
if
cronJobLog
==
nil
{
return
nil
,
nil
return
nil
,
nil
}
}
cronJobLogBiz
=
biz
.
CronJobLogTool
.
NewFromModel
(
cronJobLog
)
cronJobLogBiz
=
biz
.
CronJobLogTool
.
NewFromModel
(
cronJobLog
)
if
err
=
x
.
Fill
(
ctx
,
cronJobLogBiz
,
opts
);
err
!=
nil
{
return
nil
,
err
}
if
err
=
biz
.
CronJobLogTool
.
Valid
(
ctx
,
cronJobLogBiz
,
opts
);
err
!=
nil
{
return
nil
,
err
}
return
cronJobLogBiz
,
nil
return
cronJobLogBiz
,
nil
}
}
func
(
x
*
cronJobLogService
)
ToSliceBiz
(
ctx
context
.
Context
,
cronJobLogs
[]
*
models
.
CronJobLog
,
opts
*
biz
.
CronJobLogOpts
)
(
cronJobLogBizSlice
[]
*
biz
.
CronJobLog
,
err
error
)
{
func
(
x
*
cronJobLogService
)
ToSliceBiz
(
ctx
context
.
Context
,
cronJobLogs
[]
*
models
.
CronJobLog
)
(
cronJobLogBizSlice
[]
*
biz
.
CronJobLog
,
err
error
)
{
if
len
(
cronJobLogs
)
==
0
{
if
len
(
cronJobLogs
)
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
cronJobLogBizSlice
=
biz
.
CronJobLogTool
.
NewSliceFromModelsBiz
(
cronJobLogs
)
cronJobLogBizSlice
=
biz
.
CronJobLogTool
.
NewSliceFromModelsBiz
(
cronJobLogs
)
if
err
=
x
.
SliceFill
(
ctx
,
cronJobLogBizSlice
,
opts
);
err
!=
nil
{
return
nil
,
err
}
if
err
=
biz
.
CronJobLogTool
.
ValidSlice
(
ctx
,
cronJobLogBizSlice
,
opts
);
err
!=
nil
{
return
nil
,
err
}
return
cronJobLogBizSlice
,
nil
return
cronJobLogBizSlice
,
nil
}
}
func
(
x
*
cronJobLogService
)
Fill
(
ctx
context
.
Context
,
cronJobLogBiz
*
biz
.
CronJobLog
,
opts
*
biz
.
CronJobLogOpts
)
error
{
func
(
x
*
cronJobLogService
)
GetAll
(
ctx
context
.
Context
)
([]
*
biz
.
CronJobLog
,
error
)
{
if
cronJobLogBiz
==
nil
{
return
nil
}
if
opts
!=
nil
{
}
return
nil
}
func
(
x
*
cronJobLogService
)
SliceFill
(
ctx
context
.
Context
,
cronJobLogBizSlice
[]
*
biz
.
CronJobLog
,
opts
*
biz
.
CronJobLogOpts
)
error
{
if
len
(
cronJobLogBizSlice
)
==
0
{
return
nil
}
if
opts
!=
nil
{
}
return
nil
}
func
(
x
*
cronJobLogService
)
GetAll
(
ctx
context
.
Context
,
opts
*
biz
.
CronJobLogOpts
)
([]
*
biz
.
CronJobLog
,
error
)
{
cronJobLogs
,
err
:=
dao
.
CronJobLogDao
.
GetAll
(
ctx
)
cronJobLogs
,
err
:=
dao
.
CronJobLogDao
.
GetAll
(
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -180,5 +150,5 @@ func (x *cronJobLogService) GetAll(ctx context.Context, opts *biz.CronJobLogOpts
...
@@ -180,5 +150,5 @@ func (x *cronJobLogService) GetAll(ctx context.Context, opts *biz.CronJobLogOpts
if
len
(
cronJobLogs
)
==
0
{
if
len
(
cronJobLogs
)
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
return
x
.
ToSliceBiz
(
ctx
,
cronJobLogs
,
opts
)
return
x
.
ToSliceBiz
(
ctx
,
cronJobLogs
)
}
}
xcron/service/cron_job_record.go
浏览文件 @
1ab6fb03
...
@@ -23,7 +23,7 @@ func newCronJobRecordService() *cronJobRecordService {
...
@@ -23,7 +23,7 @@ func newCronJobRecordService() *cronJobRecordService {
}
}
}
}
func
(
x
*
cronJobRecordService
)
GetByID
(
ctx
context
.
Context
,
id
xsf
.
ID
,
opts
*
biz
.
CronJobRecordOpts
)
(
cronJobRecordBiz
*
biz
.
CronJobRecord
,
err
error
)
{
func
(
x
*
cronJobRecordService
)
GetByID
(
ctx
context
.
Context
,
id
xsf
.
ID
)
(
cronJobRecordBiz
*
biz
.
CronJobRecord
,
err
error
)
{
if
id
<=
0
{
if
id
<=
0
{
return
nil
,
nil
return
nil
,
nil
}
}
...
@@ -31,10 +31,10 @@ func (x *cronJobRecordService) GetByID(ctx context.Context, id xsf.ID, opts *biz
...
@@ -31,10 +31,10 @@ func (x *cronJobRecordService) GetByID(ctx context.Context, id xsf.ID, opts *biz
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
x
.
ToBiz
(
ctx
,
cronJobRecord
,
opts
)
return
x
.
ToBiz
(
ctx
,
cronJobRecord
)
}
}
func
(
x
*
cronJobRecordService
)
GetSliceByIDs
(
ctx
context
.
Context
,
ids
[]
xsf
.
ID
,
opts
*
biz
.
CronJobRecordOpts
)
([]
*
biz
.
CronJobRecord
,
error
)
{
func
(
x
*
cronJobRecordService
)
GetSliceByIDs
(
ctx
context
.
Context
,
ids
[]
xsf
.
ID
)
([]
*
biz
.
CronJobRecord
,
error
)
{
if
len
(
ids
)
==
0
{
if
len
(
ids
)
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
...
@@ -45,14 +45,14 @@ func (x *cronJobRecordService) GetSliceByIDs(ctx context.Context, ids []xsf.ID,
...
@@ -45,14 +45,14 @@ func (x *cronJobRecordService) GetSliceByIDs(ctx context.Context, ids []xsf.ID,
if
len
(
cronJobRecords
)
==
0
{
if
len
(
cronJobRecords
)
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
return
x
.
ToSliceBiz
(
ctx
,
cronJobRecords
,
opts
)
return
x
.
ToSliceBiz
(
ctx
,
cronJobRecords
)
}
}
func
(
x
*
cronJobRecordService
)
GetMapByIDs
(
ctx
context
.
Context
,
ids
[]
xsf
.
ID
,
opts
*
biz
.
CronJobRecordOpts
)
(
map
[
xsf
.
ID
]
*
biz
.
CronJobRecord
,
error
)
{
func
(
x
*
cronJobRecordService
)
GetMapByIDs
(
ctx
context
.
Context
,
ids
[]
xsf
.
ID
)
(
map
[
xsf
.
ID
]
*
biz
.
CronJobRecord
,
error
)
{
if
len
(
ids
)
==
0
{
if
len
(
ids
)
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
cronJobRecordBizSlice
,
err
:=
x
.
GetSliceByIDs
(
ctx
,
ids
,
opts
)
cronJobRecordBizSlice
,
err
:=
x
.
GetSliceByIDs
(
ctx
,
ids
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -63,7 +63,7 @@ func (x *cronJobRecordService) GetMapByIDs(ctx context.Context, ids []xsf.ID, op
...
@@ -63,7 +63,7 @@ func (x *cronJobRecordService) GetMapByIDs(ctx context.Context, ids []xsf.ID, op
return
cronJobRecordBizIDMap
,
nil
return
cronJobRecordBizIDMap
,
nil
}
}
func
(
x
*
cronJobRecordService
)
Page
(
ctx
context
.
Context
,
req
*
types
.
CronJobRecordPageReq
,
opts
*
biz
.
CronJobRecordOpts
)
([]
*
biz
.
CronJobRecord
,
int64
,
error
)
{
func
(
x
*
cronJobRecordService
)
Page
(
ctx
context
.
Context
,
req
*
types
.
CronJobRecordPageReq
)
([]
*
biz
.
CronJobRecord
,
int64
,
error
)
{
cronJobRecords
,
total
,
err
:=
dao
.
CronJobRecordDao
.
Page
(
ctx
,
req
)
cronJobRecords
,
total
,
err
:=
dao
.
CronJobRecordDao
.
Page
(
ctx
,
req
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
0
,
err
return
nil
,
0
,
err
...
@@ -71,13 +71,13 @@ func (x *cronJobRecordService) Page(ctx context.Context, req *types.CronJobRecor
...
@@ -71,13 +71,13 @@ func (x *cronJobRecordService) Page(ctx context.Context, req *types.CronJobRecor
if
len
(
cronJobRecords
)
==
0
{
if
len
(
cronJobRecords
)
==
0
{
return
nil
,
total
,
nil
return
nil
,
total
,
nil
}
}
cronJobRecordBizSlice
,
err
:=
x
.
ToSliceBiz
(
ctx
,
cronJobRecords
,
opts
)
cronJobRecordBizSlice
,
err
:=
x
.
ToSliceBiz
(
ctx
,
cronJobRecords
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
0
,
err
return
nil
,
0
,
err
}
}
return
cronJobRecordBizSlice
,
total
,
nil
return
cronJobRecordBizSlice
,
total
,
nil
}
}
func
(
x
*
cronJobRecordService
)
GetSliceByJobID
(
ctx
context
.
Context
,
jobID
xsf
.
ID
,
opts
*
biz
.
CronJobRecordOpts
)
([]
*
biz
.
CronJobRecord
,
error
)
{
func
(
x
*
cronJobRecordService
)
GetSliceByJobID
(
ctx
context
.
Context
,
jobID
xsf
.
ID
)
([]
*
biz
.
CronJobRecord
,
error
)
{
if
jobID
==
0
{
if
jobID
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
...
@@ -88,10 +88,10 @@ func (x *cronJobRecordService) GetSliceByJobID(ctx context.Context, jobID xsf.ID
...
@@ -88,10 +88,10 @@ func (x *cronJobRecordService) GetSliceByJobID(ctx context.Context, jobID xsf.ID
if
len
(
cronJobRecords
)
==
0
{
if
len
(
cronJobRecords
)
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
return
x
.
ToSliceBiz
(
ctx
,
cronJobRecords
,
opts
)
return
x
.
ToSliceBiz
(
ctx
,
cronJobRecords
)
}
}
func
(
x
*
cronJobRecordService
)
GetSliceByJobIDs
(
ctx
context
.
Context
,
jobIDs
[]
xsf
.
ID
,
opts
*
biz
.
CronJobRecordOpts
)
([]
*
biz
.
CronJobRecord
,
error
)
{
func
(
x
*
cronJobRecordService
)
GetSliceByJobIDs
(
ctx
context
.
Context
,
jobIDs
[]
xsf
.
ID
)
([]
*
biz
.
CronJobRecord
,
error
)
{
if
len
(
jobIDs
)
==
0
{
if
len
(
jobIDs
)
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
...
@@ -102,14 +102,14 @@ func (x *cronJobRecordService) GetSliceByJobIDs(ctx context.Context, jobIDs []xs
...
@@ -102,14 +102,14 @@ func (x *cronJobRecordService) GetSliceByJobIDs(ctx context.Context, jobIDs []xs
if
len
(
cronJobRecords
)
==
0
{
if
len
(
cronJobRecords
)
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
return
x
.
ToSliceBiz
(
ctx
,
cronJobRecords
,
opts
)
return
x
.
ToSliceBiz
(
ctx
,
cronJobRecords
)
}
}
func
(
x
*
cronJobRecordService
)
GetMapSliceByJobIDs
(
ctx
context
.
Context
,
jobIDs
[]
xsf
.
ID
,
opts
*
biz
.
CronJobRecordOpts
)
(
map
[
xsf
.
ID
][]
*
biz
.
CronJobRecord
,
int
,
error
)
{
func
(
x
*
cronJobRecordService
)
GetMapSliceByJobIDs
(
ctx
context
.
Context
,
jobIDs
[]
xsf
.
ID
)
(
map
[
xsf
.
ID
][]
*
biz
.
CronJobRecord
,
int
,
error
)
{
if
len
(
jobIDs
)
==
0
{
if
len
(
jobIDs
)
==
0
{
return
nil
,
0
,
nil
return
nil
,
0
,
nil
}
}
cronJobRecordBizSlice
,
err
:=
x
.
GetSliceByJobIDs
(
ctx
,
jobIDs
,
opts
)
cronJobRecordBizSlice
,
err
:=
x
.
GetSliceByJobIDs
(
ctx
,
jobIDs
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
0
,
err
return
nil
,
0
,
err
}
}
...
@@ -123,53 +123,23 @@ func (x *cronJobRecordService) GetMapSliceByJobIDs(ctx context.Context, jobIDs [
...
@@ -123,53 +123,23 @@ func (x *cronJobRecordService) GetMapSliceByJobIDs(ctx context.Context, jobIDs [
return
ret
,
len
(
cronJobRecordBizSlice
),
nil
return
ret
,
len
(
cronJobRecordBizSlice
),
nil
}
}
func
(
x
*
cronJobRecordService
)
ToBiz
(
ctx
context
.
Context
,
cronJobRecord
*
models
.
CronJobRecord
,
opts
*
biz
.
CronJobRecordOpts
)
(
cronJobRecordBiz
*
biz
.
CronJobRecord
,
err
error
)
{
func
(
x
*
cronJobRecordService
)
ToBiz
(
ctx
context
.
Context
,
cronJobRecord
*
models
.
CronJobRecord
)
(
cronJobRecordBiz
*
biz
.
CronJobRecord
,
err
error
)
{
if
cronJobRecord
==
nil
{
if
cronJobRecord
==
nil
{
return
nil
,
nil
return
nil
,
nil
}
}
cronJobRecordBiz
=
biz
.
CronJobRecordTool
.
NewFromModel
(
cronJobRecord
)
cronJobRecordBiz
=
biz
.
CronJobRecordTool
.
NewFromModel
(
cronJobRecord
)
if
err
=
x
.
Fill
(
ctx
,
cronJobRecordBiz
,
opts
);
err
!=
nil
{
return
nil
,
err
}
if
err
=
biz
.
CronJobRecordTool
.
Valid
(
ctx
,
cronJobRecordBiz
,
opts
);
err
!=
nil
{
return
nil
,
err
}
return
cronJobRecordBiz
,
nil
return
cronJobRecordBiz
,
nil
}
}
func
(
x
*
cronJobRecordService
)
ToSliceBiz
(
ctx
context
.
Context
,
cronJobRecords
[]
*
models
.
CronJobRecord
,
opts
*
biz
.
CronJobRecordOpts
)
(
cronJobRecordBizSlice
[]
*
biz
.
CronJobRecord
,
err
error
)
{
func
(
x
*
cronJobRecordService
)
ToSliceBiz
(
ctx
context
.
Context
,
cronJobRecords
[]
*
models
.
CronJobRecord
)
(
cronJobRecordBizSlice
[]
*
biz
.
CronJobRecord
,
err
error
)
{
if
len
(
cronJobRecords
)
==
0
{
if
len
(
cronJobRecords
)
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
cronJobRecordBizSlice
=
biz
.
CronJobRecordTool
.
NewSliceFromModelsBiz
(
cronJobRecords
)
cronJobRecordBizSlice
=
biz
.
CronJobRecordTool
.
NewSliceFromModelsBiz
(
cronJobRecords
)
if
err
=
x
.
SliceFill
(
ctx
,
cronJobRecordBizSlice
,
opts
);
err
!=
nil
{
return
nil
,
err
}
if
err
=
biz
.
CronJobRecordTool
.
ValidSlice
(
ctx
,
cronJobRecordBizSlice
,
opts
);
err
!=
nil
{
return
nil
,
err
}
return
cronJobRecordBizSlice
,
nil
return
cronJobRecordBizSlice
,
nil
}
}
func
(
x
*
cronJobRecordService
)
Fill
(
ctx
context
.
Context
,
cronJobRecordBiz
*
biz
.
CronJobRecord
,
opts
*
biz
.
CronJobRecordOpts
)
error
{
func
(
x
*
cronJobRecordService
)
GetAll
(
ctx
context
.
Context
)
([]
*
biz
.
CronJobRecord
,
error
)
{
if
cronJobRecordBiz
==
nil
{
return
nil
}
if
opts
!=
nil
{
}
return
nil
}
func
(
x
*
cronJobRecordService
)
SliceFill
(
ctx
context
.
Context
,
cronJobRecordBizSlice
[]
*
biz
.
CronJobRecord
,
opts
*
biz
.
CronJobRecordOpts
)
error
{
if
len
(
cronJobRecordBizSlice
)
==
0
{
return
nil
}
if
opts
!=
nil
{
}
return
nil
}
func
(
x
*
cronJobRecordService
)
GetAll
(
ctx
context
.
Context
,
opts
*
biz
.
CronJobRecordOpts
)
([]
*
biz
.
CronJobRecord
,
error
)
{
cronJobRecords
,
err
:=
dao
.
CronJobRecordDao
.
GetAll
(
ctx
)
cronJobRecords
,
err
:=
dao
.
CronJobRecordDao
.
GetAll
(
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -177,5 +147,5 @@ func (x *cronJobRecordService) GetAll(ctx context.Context, opts *biz.CronJobReco
...
@@ -177,5 +147,5 @@ func (x *cronJobRecordService) GetAll(ctx context.Context, opts *biz.CronJobReco
if
len
(
cronJobRecords
)
==
0
{
if
len
(
cronJobRecords
)
==
0
{
return
nil
,
nil
return
nil
,
nil
}
}
return
x
.
ToSliceBiz
(
ctx
,
cronJobRecords
,
opts
)
return
x
.
ToSliceBiz
(
ctx
,
cronJobRecords
)
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论