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
0269e24c
Commit
0269e24c
authored
Mar 06, 2024
by
ZZH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update news info 2024-03-6
parent
916d9f4b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
35 deletions
+76
-35
news_info_cps.py
unify_api/modules/qkadmin/components/news_info_cps.py
+18
-15
news_mgr_srv.py
unify_api/modules/qkadmin/service/news_mgr_srv.py
+36
-11
new_mgr.py
unify_api/modules/qkadmin/views/new_mgr.py
+22
-9
No files found.
unify_api/modules/qkadmin/components/news_info_cps.py
View file @
0269e24c
...
...
@@ -10,43 +10,46 @@ from pot_libs.sanic_api.column import Opt, Int, List, Str
@
dataclass
class
NewsInfoReq
(
Model
):
news_id
:
str
=
Str
(
"新闻id"
)
.
eg
(
"12"
)
@
dataclass
class
EntIndustryNewsPagesReq
(
Model
):
news_type
:
int
=
Int
(
"新闻类型(1:公司新闻, 2:行业新闻)"
)
.
eg
(
1
)
page_num
:
int
=
Int
(
"页码"
)
.
eg
(
1
)
page_size
:
int
=
Opt
(
Int
(
"条数"
)
.
eg
(
10
))
news_id
:
str
=
Str
(
"文章id"
)
.
eg
(
"12"
)
@
dataclass
class
NewsInfoRsp
(
Model
):
title
:
str
=
Str
(
"
新闻
标题"
)
.
eg
(
"喜报丨热烈庆祝清科优能被评定为深圳市“专精特新”企业!"
)
contents
:
str
=
Str
(
"
新闻
内容"
)
.
eg
(
"喜报丨热烈庆祝清科优能被评定为深圳市“专精特新”企业!"
)
title
:
str
=
Str
(
"
文章
标题"
)
.
eg
(
"喜报丨热烈庆祝清科优能被评定为深圳市“专精特新”企业!"
)
contents
:
str
=
Str
(
"
文章
内容"
)
.
eg
(
"喜报丨热烈庆祝清科优能被评定为深圳市“专精特新”企业!"
)
pub_time
:
str
=
Str
(
"发布时间"
)
.
eg
(
"2023-12-29 18:06"
)
@
dataclass
class
PubNewsReq
(
Model
):
title
:
str
=
Str
(
"新闻标题"
)
.
eg
(
"喜报丨热烈庆祝清科优能被评定为深圳市“专精特新”企业!"
)
title
:
str
=
Str
(
"文章标题"
)
.
eg
(
"喜报丨热烈庆祝清科优能被评定为深圳市“专精特新”企业!"
)
author
:
str
=
Opt
(
Str
(
"文章作者"
)
.
eg
(
"清科优能"
))
pub_time
:
str
=
Str
(
"发布时间"
)
.
eg
(
"2023-12-29 18:06"
)
@
dataclass
class
ReviseNewsReq
(
Model
):
news_id
:
str
=
Str
(
"文章id"
)
.
eg
(
"12"
)
title
:
str
=
Str
(
"文章标题"
)
.
eg
(
"喜报丨热烈庆祝清科优能被评定为深圳市“专精特新”企业!"
)
@
dataclass
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
))
@
dataclass
class
NewsInfo
(
Model
):
id
:
int
=
Opt
(
Int
(
"新闻ID"
)
.
eg
(
1
))
title
:
str
=
Str
(
"新闻标题"
)
.
eg
(
"喜报丨热烈庆祝清科优能被评定为深圳市“专精特新”企业!"
)
id
:
int
=
Opt
(
Int
(
"文章ID"
)
.
eg
(
1
))
title
:
str
=
Str
(
"文章标题"
)
.
eg
(
"喜报丨热烈庆祝清科优能被评定为深圳市“专精特新”企业!"
)
author
:
str
=
Str
(
"文章作者"
)
.
eg
(
"清科优能"
)
pub_time
:
str
=
Str
(
"发布时间"
)
.
eg
(
"2023-12-29 18:06"
)
news_type
:
int
=
Int
(
"文章类型(1:公司新闻, 2:行业新闻)"
)
.
eg
(
1
)
top
:
int
=
Opt
(
Int
(
"是否置顶"
)
.
eg
(
0
))
contents
:
str
=
Opt
(
Str
(
"
新闻
内容"
)
.
eg
(
"喜报丨热烈庆祝清科优能被评定为深圳市“专精特新”企业!"
))
cover_url
:
str
=
Opt
(
Str
(
"
新闻
封面URL"
)
.
eg
(
"xxxxxxxxxx"
))
contents
:
str
=
Opt
(
Str
(
"
文章
内容"
)
.
eg
(
"喜报丨热烈庆祝清科优能被评定为深圳市“专精特新”企业!"
))
cover_url
:
str
=
Opt
(
Str
(
"
文章
封面URL"
)
.
eg
(
"xxxxxxxxxx"
))
@
dataclass
...
...
unify_api/modules/qkadmin/service/news_mgr_srv.py
View file @
0269e24c
...
...
@@ -43,7 +43,7 @@ async def upload_news_qs(request):
else
:
return
False
,
url_article
,
url_cover
log
.
info
(
f
"上传
新闻
和封面成功 {url_article} {url_cover}"
)
log
.
info
(
f
"上传
文章
和封面成功 {url_article} {url_cover}"
)
return
True
,
url_article
,
url_cover
...
...
@@ -51,19 +51,44 @@ async def save_news_info(title, pub_time, news_url, cover_url):
sql
=
"INSERT INTO official_web.news_info ("
\
"title, pub_time, news_url, cover_url) "
\
"VALUES (
%
s,
%
s,
%
s,
%
s);"
async
with
MysqlUtil
()
as
conn
:
async
with
MysqlUtil
(
db
=
"official_web"
)
as
conn
:
await
conn
.
execute
(
sql
,
(
title
,
str
(
pub_time
),
news_url
,
cover_url
))
async
def
load_news_pages
(
page_num
,
page_size
):
async
with
MysqlUtil
()
as
conn
:
sql
=
"SELECT count(*) FROM official_web.news_info;"
total
=
conn
.
fetch_value
(
sql
)
async
def
update_news_info
(
news_id
,
title
,
news_url
,
cover_url
):
async
with
MysqlUtil
(
db
=
"official_web"
)
as
conn
:
if
cover_url
:
sql
=
"UPDATE official_web.news_info "
\
"SET title=
%
s, news_url=
%
s, cover_url=
%
s WHERE id=
%
s;"
return
await
conn
.
execute
(
sql
,
(
news_id
,
title
,
news_url
,
cover_url
))
sql
=
f
"SELECT id, title, pub_time, top
"
\
f
"FROM official_web.news_info "
\
f
"ORDER BY pub_time DESC, id LIMIT
%
s OFFSET
%
s;"
sql
=
"UPDATE official_web.news_info
"
\
"SET title=
%
s, news_url=
%
s WHERE id=
%
s;"
return
await
conn
.
execute
(
sql
,
(
news_id
,
title
,
news_url
,))
offsets
=
0
if
page_num
==
0
else
(
page_num
-
1
)
*
page_size
articles
=
await
conn
.
fetchall
(
sql
,
(
page_size
,
offsets
))
async
def
load_news_pages
(
news_type
,
page_num
,
page_size
):
async
with
MysqlUtil
(
db
=
"official_web"
)
as
conn
:
if
news_type
:
sql
=
"SELECT count(*) FROM official_web.news_info "
\
"WHERE news_type=
%
s;"
total
=
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
=
conn
.
fetch_value
(
sql
)
sql
=
f
"SELECT id, title, author, news_type, pub_time, top "
\
f
"FROM official_web.news_info "
\
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
,))
return
total
,
articles
unify_api/modules/qkadmin/views/new_mgr.py
View file @
0269e24c
...
...
@@ -6,30 +6,43 @@ DATE:2024/3/5 16:19
from
pot_libs.sanic_api
import
summary
from
unify_api.modules.common.components.common_cps
import
SuccessRsp
from
unify_api.modules.qkadmin.components.news_info_cps
import
(
PubNewsReq
,
NewsPagesReq
,
NewsPagesRsp
,
NewsInfo
PubNewsReq
,
NewsPagesReq
,
NewsPagesRsp
,
NewsInfo
,
ReviseNewsReq
)
from
unify_api.modules.qkadmin.service.news_mgr_srv
import
(
upload_news_qs
,
save_news_info
,
load_news_pages
upload_news_qs
,
save_news_info
,
load_news_pages
,
update_news_info
)
@
summary
(
"发布
新闻
"
)
@
summary
(
"发布
文章
"
)
async
def
post_publish_news
(
request
,
body
:
PubNewsReq
)
->
SuccessRsp
:
title
,
pub_time
=
body
.
title
,
body
.
pub_time
title
,
pub_time
,
author
=
body
.
title
,
body
.
pub_time
,
body
.
author
is_success
,
url_article
,
url_cover
=
await
upload_news_qs
(
request
)
if
is_success
:
await
save_news_info
(
title
,
pub_time
,
url_article
,
url_cover
)
return
SuccessRsp
(
success
=
1
,
message
=
"发布
新闻
成功"
)
return
SuccessRsp
(
success
=
1
,
message
=
"发布
文章
成功"
)
return
SuccessRsp
(
success
=
0
,
message
=
"发布
新闻
失败"
)
return
SuccessRsp
(
success
=
0
,
message
=
"发布
文章
失败"
)
@
summary
(
"后台新闻列表"
)
@
summary
(
"修改文章"
)
async
def
post_revise_news
(
request
,
body
:
ReviseNewsReq
)
->
SuccessRsp
:
news_id
,
title
=
body
.
news_id
,
body
.
title
is_success
,
url_article
,
url_cover
=
await
upload_news_qs
(
request
)
if
is_success
:
await
update_news_info
(
news_id
,
title
,
url_article
,
url_cover
)
return
SuccessRsp
(
success
=
1
,
message
=
"修改文章成功"
)
return
SuccessRsp
(
success
=
0
,
message
=
"修改文章失败"
)
@
summary
(
"后台文章列表"
)
async
def
get_news_pages
(
request
,
body
:
NewsPagesReq
)
->
NewsPagesRsp
:
page_num
=
int
(
body
.
page_num
)
page_size
=
int
(
body
.
page_size
)
total
,
articles
=
load_news_pages
(
page_num
,
page_size
)
news_type
=
int
(
body
.
page_size
)
if
body
.
page_size
else
0
total
,
articles
=
load_news_pages
(
news_type
,
page_num
,
page_size
)
rsp_articles
=
[
NewsInfo
(
id
=
r
[
"id"
],
title
=
r
[
"title"
],
pub_time
=
r
[
"pub_time"
],
NewsInfo
(
id
=
r
[
"id"
],
title
=
r
[
"title"
],
author
=
r
[
"author"
],
pub_time
=
r
[
"pub_time"
],
news_type
=
r
[
"news_type"
],
top
=
r
[
"top"
])
for
r
in
articles
]
return
NewsPagesRsp
(
total
=
total
,
articles
=
rsp_articles
)
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