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
10d0724c
Commit
10d0724c
authored
Jan 04, 2023
by
zhengqiuyun86
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
网络通过
parent
3eb2feea
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
0 deletions
+25
-0
PagePlus.go
PagePlus/PagePlus.go
+25
-0
No files found.
PagePlus/PagePlus.go
View file @
10d0724c
package
PagePlus
package
PagePlus
import
(
import
(
"fmt"
"git.168cad.top/zhengqiuyun/rym-util/exception"
"git.168cad.top/zhengqiuyun/rym-util/exception"
"git.168cad.top/zhengqiuyun/rym-util/page"
"git.168cad.top/zhengqiuyun/rym-util/page"
"git.168cad.top/zhengqiuyun/rym-util/util"
"git.168cad.top/zhengqiuyun/rym-util/util"
...
@@ -37,3 +38,27 @@ func Page(params []page.Param, pageNum int, pageSize int, m interface{}, data in
...
@@ -37,3 +38,27 @@ func Page(params []page.Param, pageNum int, pageSize int, m interface{}, data in
}
}
return
&
page
return
&
page
}
}
func
PageSql
(
db
*
gorm
.
DB
,
data
interface
{},
pageNum
int
,
pageSize
int
,
sql
string
,
sqlParams
[]
interface
{})
*
page
.
Data
{
var
page
=
page
.
Data
{}
page
.
PageSize
=
util
.
If
(
pageSize
==
0
,
10
,
pageSize
)
page
.
PageNum
=
util
.
If
(
pageNum
==
0
,
1
,
pageNum
)
tx
:=
db
.
Session
(
&
gorm
.
Session
{
PrepareStmt
:
false
})
countTx
:=
tx
.
Raw
(
fmt
.
Sprintf
(
"select count(1) from (%s) _tmp_"
,
sql
),
sqlParams
...
)
resultCount
:=
countTx
.
Scan
(
&
page
.
Total
)
if
resultCount
.
Error
!=
nil
{
exception
.
ThrowsErr
(
resultCount
.
Error
)
}
if
page
.
Total
>
0
{
sql
=
fmt
.
Sprintf
(
"%s limit ?,? "
,
sql
)
sqlParams
=
append
(
sqlParams
,
(
page
.
PageNum
-
1
)
*
page
.
PageSize
)
sqlParams
=
append
(
sqlParams
,
page
.
PageSize
)
dataTx
:=
tx
.
Raw
(
sql
,
sqlParams
...
)
resultList
:=
dataTx
.
Scan
(
&
data
)
if
resultList
.
Error
!=
nil
{
exception
.
ThrowsErr
(
resultList
.
Error
)
}
}
page
.
List
=
data
return
&
page
}
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