Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
bwallet
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Go
bwallet
Commits
db6cbe19
Commit
db6cbe19
authored
Jul 24, 2020
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化快讯
parent
19739590
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
6 deletions
+39
-6
news.go
models/news.go
+25
-5
news.go
routers/api/app/news.go
+8
-1
news.go
service/news_service/news.go
+6
-0
No files found.
models/news.go
View file @
db6cbe19
...
@@ -37,8 +37,21 @@ func ExistNewsById(id int) (bool, error) {
...
@@ -37,8 +37,21 @@ func ExistNewsById(id int) (bool, error) {
func
GetNewsTotal
(
maps
interface
{})
(
int
,
error
)
{
func
GetNewsTotal
(
maps
interface
{})
(
int
,
error
)
{
var
count
int
var
count
int
if
err
:=
db
.
Model
(
&
News
{})
.
Where
(
maps
)
.
Count
(
&
count
)
.
Error
;
err
!=
nil
{
return
0
,
err
//if tmpmap, ok := maps.(map[string]interface{}); ok {
// _, ok = tmpmap["search_type"]
// if ok {
//
// }
//}
if
_
,
ok
:=
maps
.
(
map
[
string
]
interface
{})[
"search_type"
];
ok
{
if
err
:=
db
.
Model
(
&
News
{})
.
Where
(
"platform_id in (?)"
,
maps
.
(
map
[
string
]
interface
{})[
"search_type"
])
.
Count
(
&
count
)
.
Error
;
err
!=
nil
{
return
0
,
err
}
}
else
{
if
err
:=
db
.
Model
(
&
News
{})
.
Where
(
maps
)
.
Count
(
&
count
)
.
Error
;
err
!=
nil
{
return
0
,
err
}
}
}
return
count
,
nil
return
count
,
nil
...
@@ -46,9 +59,16 @@ func GetNewsTotal(maps interface{}) (int, error) {
...
@@ -46,9 +59,16 @@ func GetNewsTotal(maps interface{}) (int, error) {
func
GetNews
(
pageNum
,
pageSize
int
,
maps
interface
{})
([]
*
News
,
error
)
{
func
GetNews
(
pageNum
,
pageSize
int
,
maps
interface
{})
([]
*
News
,
error
)
{
var
news
[]
*
News
var
news
[]
*
News
err
:=
db
.
Where
(
maps
)
.
Offset
(
pageNum
)
.
Limit
(
pageSize
)
.
Find
(
&
news
)
.
Error
if
_
,
ok
:=
maps
.
(
map
[
string
]
interface
{})[
"search_type"
];
ok
{
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
err
:=
db
.
Where
(
"platform_id in (?)"
,
maps
.
(
map
[
string
]
interface
{})[
"search_type"
])
.
Order
(
"create_time desc"
)
.
Offset
(
pageNum
)
.
Limit
(
pageSize
)
.
Find
(
&
news
)
.
Error
return
nil
,
err
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
nil
,
err
}
}
else
{
err
:=
db
.
Where
(
maps
)
.
Order
(
"create_time desc"
)
.
Offset
(
pageNum
)
.
Limit
(
pageSize
)
.
Find
(
&
news
)
.
Error
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
nil
,
err
}
}
}
return
news
,
nil
return
news
,
nil
...
...
routers/api/app/news.go
View file @
db6cbe19
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
"bwallet/pkg/util"
"bwallet/pkg/util"
"bwallet/service/news_service"
"bwallet/service/news_service"
"fmt"
"fmt"
"github.com/astaxie/beego/validation"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"strconv"
"strconv"
)
)
...
@@ -22,9 +23,15 @@ func GetOneNews(c *gin.Context) {
...
@@ -22,9 +23,15 @@ func GetOneNews(c *gin.Context) {
func
GetNews
(
c
*
gin
.
Context
)
{
func
GetNews
(
c
*
gin
.
Context
)
{
platform_id
,
_
:=
strconv
.
Atoi
(
c
.
Request
.
Header
.
Get
(
"FZM-PLATFORM-ID"
))
platform_id
,
_
:=
strconv
.
Atoi
(
c
.
Request
.
Header
.
Get
(
"FZM-PLATFORM-ID"
))
valid
:=
validation
.
Validation
{}
valid
.
Min
(
platform_id
,
1
,
"platform_id"
)
.
Message
(
"平台Id不能为空"
)
if
valid
.
HasErrors
()
{
handler
.
SendResponse
(
c
,
valid
.
Errors
[
0
],
nil
)
return
}
newsService
:=
news_service
.
News
{
newsService
:=
news_service
.
News
{
PlatformId
:
platform_id
,
PlatformId
:
platform_id
,
SearchType
:
-
1
,
PageNum
:
util
.
GetPage
(
c
),
PageNum
:
util
.
GetPage
(
c
),
PageSize
:
util
.
GetLimit
(
c
),
PageSize
:
util
.
GetLimit
(
c
),
}
}
...
...
service/news_service/news.go
View file @
db6cbe19
...
@@ -13,6 +13,7 @@ type News struct {
...
@@ -13,6 +13,7 @@ type News struct {
Highlight
uint8
Highlight
uint8
Status
uint8
Status
uint8
PlatformId
int
PlatformId
int
SearchType
int
PageNum
int
PageNum
int
PageSize
int
PageSize
int
...
@@ -95,5 +96,10 @@ func (n *News) getMaps() (map[string]interface{}) {
...
@@ -95,5 +96,10 @@ func (n *News) getMaps() (map[string]interface{}) {
maps
[
"platform_id"
]
=
n
.
PlatformId
maps
[
"platform_id"
]
=
n
.
PlatformId
}
}
if
n
.
SearchType
!=
0
{
platform_id
:=
[]
int
{
n
.
PlatformId
,
n
.
SearchType
}
maps
[
"search_type"
]
=
platform_id
}
return
maps
return
maps
}
}
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