Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
U
unify_api2
Project
Project
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
chaonan
unify_api2
Commits
10a425d8
Commit
10a425d8
authored
Mar 07, 2024
by
ZZH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
news search add conditions 2024-03-6
parent
a27dbeda
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
16 deletions
+45
-16
news_info_cps.py
unify_api/modules/qkadmin/components/news_info_cps.py
+3
-0
news_mgr_srv.py
unify_api/modules/qkadmin/service/news_mgr_srv.py
+35
-14
new_mgr.py
unify_api/modules/qkadmin/views/new_mgr.py
+7
-2
No files found.
unify_api/modules/qkadmin/components/news_info_cps.py
View file @
10a425d8
...
...
@@ -48,6 +48,9 @@ class NewsPagesReq(Model):
news_type
:
int
=
Opt
(
Int
(
"文章类型(1:公司新闻, 2:行业新闻) 不传则返回所有类型文章"
)
.
eg
(
1
))
page_num
:
int
=
Int
(
"页码"
)
.
eg
(
1
)
page_size
:
int
=
Opt
(
Int
(
"条数"
)
.
eg
(
10
))
start_time
:
str
=
Opt
(
Str
(
"起始时间"
)
.
eg
(
"2024-03-07 00:00:00"
))
end_time
:
str
=
Opt
(
Str
(
"截止时间"
)
.
eg
(
"2023-12-29 18:06"
))
se_title
:
str
=
Opt
(
Str
(
"搜索的文章标题"
)
.
eg
(
"万物梁行携手清科优能"
))
@
dataclass
...
...
unify_api/modules/qkadmin/service/news_mgr_srv.py
View file @
10a425d8
...
...
@@ -78,27 +78,48 @@ async def update_news_seo(news_id, keywords, contents):
return
await
conn
.
execute
(
sql
,
(
news_id
,
keywords
,
contents
,))
async
def
load_news_pages
(
news_type
,
page_num
,
page_size
):
async
def
load_news_pages
(
params
):
page_num
,
page_size
=
params
[
"page_num"
],
params
[
"page_size"
]
news_type
,
se_title
=
params
[
"news_type"
],
params
[
"se_title"
]
s_dts
,
e_dts
=
params
[
"s_dts"
],
params
[
"e_dts"
]
offsets
=
0
if
page_num
==
0
else
(
page_num
-
1
)
*
page_size
conds
,
param_lst
=
[],
[]
if
news_type
:
param_lst
.
append
(
news_type
)
conds
.
append
(
f
"news_type=
%
s"
)
if
s_dts
:
s_dt
=
pendulum
.
parse
(
s_dts
,
tz
=
"Asia/Shanghai"
)
param_lst
.
append
(
str
(
s_dt
))
conds
.
append
(
f
"pub_time>=
%
s"
)
if
e_dts
:
e_dt
=
pendulum
.
parse
(
e_dts
,
tz
=
"Asia/Shanghai"
)
param_lst
.
append
(
str
(
e_dt
))
conds
.
append
(
f
"pub_time<
%
s"
)
if
se_title
:
param_lst
.
append
(
se_title
)
conds
.
append
(
f
"title LIKE
%
{se_title}
%
"
)
if
len
(
conds
)
>
1
:
conds_str
=
"WHERE"
+
" AND "
.
join
(
conds
)
elif
len
(
conds
)
==
1
:
conds_str
=
f
"WHERE {conds[0]} "
else
:
conds_str
=
""
param_lst
+=
[
page_size
,
offsets
]
async
with
MysqlUtil
(
db
=
"official_web"
)
as
conn
:
if
news_type
:
sql
=
"SELECT count(*) FROM official_web.news_info "
\
"WHERE news_type=
%
s;"
total
=
await
conn
.
fetch_value
(
sql
,
(
news_type
,))
sql
=
f
"SELECT id, title, author, news_type, pub_time, top "
\
f
"FROM official_web.news_info "
\
f
"WHERE news_type=
%
s "
\
f
"ORDER BY pub_time DESC, id LIMIT
%
s OFFSET
%
s;"
offsets
=
0
if
page_num
==
0
else
(
page_num
-
1
)
*
page_size
articles
=
await
conn
.
fetchall
(
sql
,
(
news_type
,
page_size
,
offsets
,))
else
:
sql
=
"SELECT count(*) FROM official_web.news_info;"
total
=
await
conn
.
fetch_value
(
sql
)
sql
=
f
"SELECT id, title, author, news_type, pub_time, top "
\
f
"FROM official_web.news_info "
\
f
"{conds_str} "
\
f
"ORDER BY pub_time DESC, id LIMIT
%
s OFFSET
%
s;"
offsets
=
0
if
page_num
==
0
else
(
page_num
-
1
)
*
page_size
articles
=
await
conn
.
fetchall
(
sql
,
(
page_size
,
offsets
,
))
articles
=
await
conn
.
fetchall
(
sql
,
(
tuple
(
param_lst
)
))
return
total
,
articles
unify_api/modules/qkadmin/views/new_mgr.py
View file @
10a425d8
...
...
@@ -50,8 +50,13 @@ async def post_revise_news_seo(request, body: ReviseNewsSeoReq) -> SuccessRsp:
async
def
post_news_pages
(
request
,
body
:
NewsPagesReq
)
->
NewsPagesRsp
:
page_num
=
int
(
body
.
page_num
)
page_size
=
int
(
body
.
page_size
)
news_type
=
int
(
body
.
page_size
)
if
body
.
page_size
else
0
total
,
articles
=
await
load_news_pages
(
news_type
,
page_num
,
page_size
)
news_type
=
int
(
body
.
news_type
)
if
body
.
news_type
else
0
s_dts
=
body
.
start_time
e_dts
=
body
.
end_time
se_title
=
body
.
se_title
params
=
dict
(
page_num
=
page_num
,
page_size
=
page_size
,
news_type
=
news_type
,
s_dts
=
s_dts
,
e_dts
=
e_dts
,
se_title
=
se_title
)
total
,
articles
=
await
load_news_pages
(
params
)
rsp_articles
=
[
NewsInfo
(
id
=
r
[
"id"
],
title
=
r
[
"title"
],
author
=
r
[
"author"
],
pub_time
=
str
(
r
[
"pub_time"
]),
news_type
=
r
[
"news_type"
],
...
...
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