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
3a4c181f
Commit
3a4c181f
authored
Mar 06, 2024
by
ZZH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add amber admin 2024-03-6
parent
8cd74ae9
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
207 additions
and
1 deletion
+207
-1
constants.py
unify_api/constants.py
+2
-0
__init__.py
unify_api/modules/amber_admin/__init__.py
+5
-0
__init__.py
unify_api/modules/amber_admin/components/__init__.py
+5
-0
news_info_cps.py
unify_api/modules/amber_admin/components/news_info_cps.py
+55
-0
__init__.py
unify_api/modules/amber_admin/service/__init__.py
+5
-0
news_mgr_srv.py
unify_api/modules/amber_admin/service/news_mgr_srv.py
+69
-0
__init__.py
unify_api/modules/amber_admin/views/__init__.py
+5
-0
new_mgr.py
unify_api/modules/amber_admin/views/new_mgr.py
+35
-0
common_cps.py
unify_api/modules/common/components/common_cps.py
+8
-1
file_operate_pds.py
unify_api/modules/common/procedures/file_operate_pds.py
+18
-0
No files found.
unify_api/constants.py
View file @
3a4c181f
...
@@ -483,3 +483,5 @@ TD_TBL_POSTFIX = {"electric": "ele", "soe": "soe", "scope": "scp",
...
@@ -483,3 +483,5 @@ TD_TBL_POSTFIX = {"electric": "ele", "soe": "soe", "scope": "scp",
S030_TOPIC
=
[
"electric"
,
"soe"
,
"scope"
,
"adio"
,
"scope"
,
"appliance"
,
S030_TOPIC
=
[
"electric"
,
"soe"
,
"scope"
,
"adio"
,
"scope"
,
"appliance"
,
"workshop"
,
"log"
]
"workshop"
,
"log"
]
WG_TOPIC
=
[
"tsp"
,
"water"
,
"water_bromake"
,
"ws"
]
WG_TOPIC
=
[
"tsp"
,
"water"
,
"water_bromake"
,
"ws"
]
OSS_NEWS
=
"filedata/official_web/news_info"
\ No newline at end of file
unify_api/modules/amber_admin/__init__.py
0 → 100644
View file @
3a4c181f
# -*- coding:utf-8 -*-
"""
DATE:2024/3/6 11:39
"""
unify_api/modules/amber_admin/components/__init__.py
0 → 100644
View file @
3a4c181f
# -*- coding:utf-8 -*-
"""
DATE:2024/3/6 11:40
"""
unify_api/modules/amber_admin/components/news_info_cps.py
0 → 100644
View file @
3a4c181f
# -*- coding:utf-8 -*-
"""
DATE:2024/3/5 13:56
"""
from
dataclasses
import
dataclass
from
pot_libs.sanic_api
import
Model
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
))
@
dataclass
class
NewsInfoRsp
(
Model
):
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
(
"喜报丨热烈庆祝清科优能被评定为深圳市“专精特新”企业!"
)
pub_time
:
str
=
Str
(
"发布时间"
)
.
eg
(
"2023-12-29 18:06"
)
@
dataclass
class
NewsPagesReq
(
Model
):
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
(
"喜报丨热烈庆祝清科优能被评定为深圳市“专精特新”企业!"
)
pub_time
:
str
=
Str
(
"发布时间"
)
.
eg
(
"2023-12-29 18:06"
)
top
:
int
=
Opt
(
Int
(
"是否置顶"
)
.
eg
(
0
))
contents
:
str
=
Opt
(
Str
(
"新闻内容"
)
.
eg
(
"喜报丨热烈庆祝清科优能被评定为深圳市“专精特新”企业!"
))
cover_url
:
str
=
Opt
(
Str
(
"新闻封面URL"
)
.
eg
(
"xxxxxxxxxx"
))
@
dataclass
class
NewsPagesRsp
(
Model
):
total
:
int
=
Int
(
"文章总数"
)
.
eg
(
99
)
articles
:
list
=
List
(
"文章列表"
)
.
items
(
NewsInfo
)
unify_api/modules/amber_admin/service/__init__.py
0 → 100644
View file @
3a4c181f
# -*- coding:utf-8 -*-
"""
DATE:2024/3/6 11:48
"""
unify_api/modules/amber_admin/service/news_mgr_srv.py
0 → 100644
View file @
3a4c181f
# -*- coding:utf-8 -*-
"""
DATE:2024/3/5 16:27
"""
import
pendulum
from
uuid
import
uuid4
from
unify_api.constants
import
OSS_NEWS
from
pot_libs.logger
import
log
from
unify_api.modules.common.procedures.file_operate_pds
import
upload_file
from
pot_libs.mysql_util.mysql_util
import
MysqlUtil
async
def
upload_news_qs
(
request
):
"""附件上传"""
files
=
request
.
files
.
getlist
(
"file"
)
url_article
,
url_cover
=
""
,
""
file_name_lst
=
[
file
.
name
for
file
in
files
]
if
len
(
file_name_lst
)
!=
len
(
set
(
file_name_lst
)):
return
False
,
url_article
,
url_cover
for
i
,
file
in
enumerate
(
files
):
file_name
=
file
.
name
file_name_lst
=
file_name
.
rsplit
(
"."
,
1
)
if
len
(
file_name_lst
)
<=
1
:
return
False
,
url_article
,
url_cover
file_body
=
file
.
body
if
file_body
:
now_dt
=
pendulum
.
now
()
yr
,
month
=
now_dt
.
year
,
now_dt
.
month
file_url
=
f
"{OSS_NEWS}/{yr}/{month}/{uuid4()}.{file_name_lst[1]}"
log
.
info
(
f
"准备上传文件 {file_name} {file_url}"
)
is_upload
=
await
upload_file
(
file
,
file_url
)
if
not
is_upload
:
return
False
,
url_article
,
url_cover
if
i
==
0
:
url_article
=
file_url
else
:
url_cover
=
file_url
else
:
return
False
,
url_article
,
url_cover
log
.
info
(
f
"上传新闻和封面成功 {url_article} {url_cover}"
)
return
True
,
url_article
,
url_cover
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
:
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
)
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;"
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/amber_admin/views/__init__.py
0 → 100644
View file @
3a4c181f
# -*- coding:utf-8 -*-
"""
DATE:2024/3/6 11:48
"""
unify_api/modules/amber_admin/views/new_mgr.py
0 → 100644
View file @
3a4c181f
# -*- coding:utf-8 -*-
"""
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.amber_admin.components.news_info_cps
import
(
PubNewsReq
,
NewsPagesReq
,
NewsPagesRsp
,
NewsInfo
)
from
unify_api.modules.amber_admin.service.news_mgr_srv
import
(
upload_news_qs
,
save_news_info
,
load_news_pages
)
@
summary
(
"发布新闻"
)
async
def
post_publish_news
(
request
,
body
:
PubNewsReq
)
->
SuccessRsp
:
title
,
pub_time
=
body
.
title
,
body
.
pub_time
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
=
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
)
rsp_articles
=
[
NewsInfo
(
id
=
r
[
"id"
],
title
=
r
[
"title"
],
pub_time
=
r
[
"pub_time"
],
top
=
r
[
"top"
])
for
r
in
articles
]
return
NewsPagesRsp
(
total
=
total
,
articles
=
rsp_articles
)
unify_api/modules/common/components/common_cps.py
View file @
3a4c181f
...
@@ -2,7 +2,7 @@ from dataclasses import dataclass
...
@@ -2,7 +2,7 @@ from dataclasses import dataclass
from
pot_libs.common.components.fields
import
Cid
from
pot_libs.common.components.fields
import
Cid
from
pot_libs.sanic_api
import
Model
from
pot_libs.sanic_api
import
Model
from
pot_libs.sanic_api.column
import
List
,
Str
from
pot_libs.sanic_api.column
import
List
,
Str
,
Int
,
Opt
@
dataclass
@
dataclass
...
@@ -36,3 +36,10 @@ class CidStartEndReq(Model):
...
@@ -36,3 +36,10 @@ class CidStartEndReq(Model):
cid
:
Cid
cid
:
Cid
start
:
str
=
Str
(
"开始时间"
)
.
eg
(
"2021-06-01 00:00:00"
)
start
:
str
=
Str
(
"开始时间"
)
.
eg
(
"2021-06-01 00:00:00"
)
end
:
str
=
Str
(
"结束时间"
)
.
eg
(
"2021-06-30 23:59:59"
)
end
:
str
=
Str
(
"结束时间"
)
.
eg
(
"2021-06-30 23:59:59"
)
@
dataclass
class
SuccessRsp
(
Model
):
success
:
int
=
Int
(
'请求成功'
)
.
eg
(
1
)
message
:
str
=
Str
(
"具体错误信息"
)
.
eg
(
"操作成功"
)
fid
:
list
=
Opt
(
List
(
"文件列表id,这里的id是字符串"
)
.
eg
([
"212122121"
,
"2323232332"
]))
unify_api/modules/common/procedures/file_operate_pds.py
0 → 100644
View file @
3a4c181f
# -*- coding:utf-8 -*-
"""
DATE:2024/3/6 13:47
"""
from
pot_libs.logger
import
log
from
pot_libs.qingstor_util.qs_client
import
QsClient
async
def
upload_file
(
file
,
qs_url
):
file_body
=
file
.
body
if
file_body
:
async
with
QsClient
()
as
client
:
resp
=
await
client
.
put_file
(
key
=
qs_url
,
data
=
file_body
)
log
.
info
(
f
"upload to qingstor the resp: {resp} {qs_url}"
)
return
1
else
:
return
None
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