Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rym-util
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhengqiuyun
rym-util
Commits
4a8e7043
Commit
4a8e7043
authored
Oct 08, 2022
by
zhengqiuyun86
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
返回封装优化
parent
4fb31ddd
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
0 deletions
+63
-0
PagePlus.go
PagePlus/PagePlus.go
+39
-0
Page.go
page/Page.go
+12
-0
Param.go
page/Param.go
+12
-0
No files found.
PagePlus/PagePlus.go
0 → 100644
View file @
4a8e7043
package
PagePlus
import
(
"git.168cad.top/zhengqiuyun/rym-util/exception"
"git.168cad.top/zhengqiuyun/rym-util/page"
"git.168cad.top/zhengqiuyun/rym-util/util"
"gorm.io/gorm"
)
func
Page
(
params
[]
page
.
Param
,
pageNum
int
,
pageSize
int
,
m
interface
{},
data
interface
{},
orderBy
string
,
db
*
gorm
.
DB
)
*
page
.
Data
{
var
page
=
page
.
Data
{}
page
.
PageSize
=
util
.
IfInt
(
pageSize
==
0
,
10
,
pageSize
)
page
.
PageNum
=
util
.
IfInt
(
pageNum
==
0
,
1
,
pageNum
)
tx
:=
db
.
Session
(
&
gorm
.
Session
{
PrepareStmt
:
true
})
countTx
:=
tx
.
Model
(
&
m
)
.
Select
(
"count(1)"
)
if
params
!=
nil
{
for
_
,
p
:=
range
params
{
countTx
.
Where
(
p
.
Column
+
" "
+
p
.
Op
+
" ?"
,
p
.
Value
)
}
}
resultCount
:=
countTx
.
Scan
(
&
page
.
Total
)
if
resultCount
.
Error
!=
nil
{
exception
.
ThrowsErr
(
resultCount
.
Error
)
}
if
page
.
Total
>
0
{
dataTx
:=
tx
.
Model
(
&
m
)
.
Offset
((
page
.
PageNum
-
1
)
*
page
.
PageSize
)
.
Limit
(
page
.
PageSize
)
.
Order
(
orderBy
)
if
params
!=
nil
{
for
_
,
p
:=
range
params
{
dataTx
.
Where
(
p
.
Column
+
" "
+
p
.
Op
+
" ?"
,
p
.
Value
)
}
}
resultList
:=
dataTx
.
Find
(
&
data
)
if
resultList
.
Error
!=
nil
{
exception
.
ThrowsErr
(
resultList
.
Error
)
}
page
.
List
=
data
}
return
&
page
}
page/Page.go
0 → 100644
View file @
4a8e7043
package
page
type
Page
struct
{
PageNum
int
`json:"pageNum"`
PageSize
int
`json:"pageSize"`
Total
int
`json:"total"`
}
type
Data
struct
{
Page
List
interface
{}
`json:"list"`
}
page/Param.go
0 → 100644
View file @
4a8e7043
package
page
type
ParamPage
struct
{
PageNum
int
`json:"pageNum"`
PageSize
int
`json:"pageSize"`
}
type
Param
struct
{
Column
string
Op
string
Value
interface
{}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment