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
...
@@ -10,43 +10,46 @@ from pot_libs.sanic_api.column import Opt, Int, List, Str
@
dataclass
@
dataclass
class
NewsInfoReq
(
Model
):
class
NewsInfoReq
(
Model
):
news_id
:
str
=
Str
(
"新闻id"
)
.
eg
(
"12"
)
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
))
@
dataclass
@
dataclass
class
NewsInfoRsp
(
Model
):
class
NewsInfoRsp
(
Model
):
title
:
str
=
Str
(
"
新闻
标题"
)
.
eg
(
"喜报丨热烈庆祝清科优能被评定为深圳市“专精特新”企业!"
)
title
:
str
=
Str
(
"
文章
标题"
)
.
eg
(
"喜报丨热烈庆祝清科优能被评定为深圳市“专精特新”企业!"
)
contents
:
str
=
Str
(
"
新闻
内容"
)
.
eg
(
"喜报丨热烈庆祝清科优能被评定为深圳市“专精特新”企业!"
)
contents
:
str
=
Str
(
"
文章
内容"
)
.
eg
(
"喜报丨热烈庆祝清科优能被评定为深圳市“专精特新”企业!"
)
pub_time
:
str
=
Str
(
"发布时间"
)
.
eg
(
"2023-12-29 18:06"
)
pub_time
:
str
=
Str
(
"发布时间"
)
.
eg
(
"2023-12-29 18:06"
)
@
dataclass
@
dataclass
class
PubNewsReq
(
Model
):
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"
)
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
@
dataclass
class
NewsPagesReq
(
Model
):
class
NewsPagesReq
(
Model
):
news_type
:
int
=
Opt
(
Int
(
"文章类型(1:公司新闻, 2:行业新闻) 不传则返回所有类型文章"
)
.
eg
(
1
))
page_num
:
int
=
Int
(
"页码"
)
.
eg
(
1
)
page_num
:
int
=
Int
(
"页码"
)
.
eg
(
1
)
page_size
:
int
=
Opt
(
Int
(
"条数"
)
.
eg
(
10
))
page_size
:
int
=
Opt
(
Int
(
"条数"
)
.
eg
(
10
))
@
dataclass
@
dataclass
class
NewsInfo
(
Model
):
class
NewsInfo
(
Model
):
id
:
int
=
Opt
(
Int
(
"新闻ID"
)
.
eg
(
1
))
id
:
int
=
Opt
(
Int
(
"文章ID"
)
.
eg
(
1
))
title
:
str
=
Str
(
"新闻标题"
)
.
eg
(
"喜报丨热烈庆祝清科优能被评定为深圳市“专精特新”企业!"
)
title
:
str
=
Str
(
"文章标题"
)
.
eg
(
"喜报丨热烈庆祝清科优能被评定为深圳市“专精特新”企业!"
)
author
:
str
=
Str
(
"文章作者"
)
.
eg
(
"清科优能"
)
pub_time
:
str
=
Str
(
"发布时间"
)
.
eg
(
"2023-12-29 18:06"
)
pub_time
:
str
=
Str
(
"发布时间"
)
.
eg
(
"2023-12-29 18:06"
)
news_type
:
int
=
Int
(
"文章类型(1:公司新闻, 2:行业新闻)"
)
.
eg
(
1
)
top
:
int
=
Opt
(
Int
(
"是否置顶"
)
.
eg
(
0
))
top
:
int
=
Opt
(
Int
(
"是否置顶"
)
.
eg
(
0
))
contents
:
str
=
Opt
(
Str
(
"
新闻
内容"
)
.
eg
(
"喜报丨热烈庆祝清科优能被评定为深圳市“专精特新”企业!"
))
contents
:
str
=
Opt
(
Str
(
"
文章
内容"
)
.
eg
(
"喜报丨热烈庆祝清科优能被评定为深圳市“专精特新”企业!"
))
cover_url
:
str
=
Opt
(
Str
(
"
新闻
封面URL"
)
.
eg
(
"xxxxxxxxxx"
))
cover_url
:
str
=
Opt
(
Str
(
"
文章
封面URL"
)
.
eg
(
"xxxxxxxxxx"
))
@
dataclass
@
dataclass
...
...
unify_api/modules/qkadmin/service/news_mgr_srv.py
View file @
0269e24c
...
@@ -43,7 +43,7 @@ async def upload_news_qs(request):
...
@@ -43,7 +43,7 @@ async def upload_news_qs(request):
else
:
else
:
return
False
,
url_article
,
url_cover
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
return
True
,
url_article
,
url_cover
...
@@ -51,19 +51,44 @@ async def save_news_info(title, pub_time, news_url, cover_url):
...
@@ -51,19 +51,44 @@ async def save_news_info(title, pub_time, news_url, cover_url):
sql
=
"INSERT INTO official_web.news_info ("
\
sql
=
"INSERT INTO official_web.news_info ("
\
"title, pub_time, news_url, cover_url) "
\
"title, pub_time, news_url, cover_url) "
\
"VALUES (
%
s,
%
s,
%
s,
%
s);"
"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
))
await
conn
.
execute
(
sql
,
(
title
,
str
(
pub_time
),
news_url
,
cover_url
))
async
def
load_news_pages
(
page_num
,
page_size
):
async
def
update_news_info
(
news_id
,
title
,
news_url
,
cover_url
):
async
with
MysqlUtil
()
as
conn
:
async
with
MysqlUtil
(
db
=
"official_web"
)
as
conn
:
sql
=
"SELECT count(*) FROM official_web.news_info;"
if
cover_url
:
total
=
conn
.
fetch_value
(
sql
)
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
"
\
sql
=
"UPDATE official_web.news_info
"
\
f
"FROM official_web.news_info "
\
"SET title=
%
s, news_url=
%
s WHERE id=
%
s;"
f
"ORDER BY pub_time DESC, id LIMIT
%
s OFFSET
%
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
return
total
,
articles
unify_api/modules/qkadmin/views/new_mgr.py
View file @
0269e24c
...
@@ -6,30 +6,43 @@ DATE:2024/3/5 16:19
...
@@ -6,30 +6,43 @@ DATE:2024/3/5 16:19
from
pot_libs.sanic_api
import
summary
from
pot_libs.sanic_api
import
summary
from
unify_api.modules.common.components.common_cps
import
SuccessRsp
from
unify_api.modules.common.components.common_cps
import
SuccessRsp
from
unify_api.modules.qkadmin.components.news_info_cps
import
(
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
(
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
:
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
)
is_success
,
url_article
,
url_cover
=
await
upload_news_qs
(
request
)
if
is_success
:
if
is_success
:
await
save_news_info
(
title
,
pub_time
,
url_article
,
url_cover
)
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
:
async
def
get_news_pages
(
request
,
body
:
NewsPagesReq
)
->
NewsPagesRsp
:
page_num
=
int
(
body
.
page_num
)
page_num
=
int
(
body
.
page_num
)
page_size
=
int
(
body
.
page_size
)
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
=
[
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
]
top
=
r
[
"top"
])
for
r
in
articles
]
return
NewsPagesRsp
(
total
=
total
,
articles
=
rsp_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