Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
vue_django_test
Overview
Overview
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
周田
vue_django_test
Commits
ab0d4589
Commit
ab0d4589
authored
Aug 22, 2023
by
周田
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:添加协议版本接口
parent
4a18245e
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
105 additions
and
1 deletions
+105
-1
models.py
protocol_version_manage/models.py
+39
-0
services.py
protocol_version_manage/services.py
+54
-0
urls.py
protocol_version_manage/urls.py
+1
-0
views.py
protocol_version_manage/views.py
+11
-1
xdc.sqlite
xdc.sqlite
+0
-0
No files found.
protocol_version_manage/models.py
View file @
ab0d4589
...
@@ -22,6 +22,31 @@ class AllDevCmdDefineAndVersion(models.Model):
...
@@ -22,6 +22,31 @@ class AllDevCmdDefineAndVersion(models.Model):
lua_script_out
=
models
.
TextField
()
# Field name made lowercase.
lua_script_out
=
models
.
TextField
()
# Field name made lowercase.
version
=
models
.
TextField
()
version
=
models
.
TextField
()
def
__eq__
(
self
,
__value
:
object
)
->
bool
:
if
not
isinstance
(
__value
,
AllDevCmdDefineAndVersion
):
return
False
if
(
self
.
cmd_name
==
__value
.
cmd_name
and
self
.
cmd_type
==
__value
.
cmd_type
and
self
.
fieldindex
==
__value
.
fieldindex
and
self
.
fieldname
==
__value
.
fieldname
and
self
.
fieldsize
==
__value
.
fieldsize
and
self
.
value
==
__value
.
value
and
self
.
minvalue
==
__value
.
minvalue
and
self
.
maxvalue
==
__value
.
maxvalue
and
self
.
datatype
==
__value
.
datatype
and
self
.
operation_in
==
__value
.
operation_in
and
self
.
operation_in_num
==
__value
.
operation_in_num
and
self
.
operation_out
==
__value
.
operation_out
and
self
.
operation_out_num
==
__value
.
operation_out_num
and
self
.
operabo_in
==
__value
.
operabo_in
and
self
.
operabo_out
==
__value
.
operabo_out
and
self
.
lua_script_in
==
__value
.
lua_script_in
and
self
.
lua_script_out
==
__value
.
lua_script_out
):
return
True
return
False
class
Meta
:
class
Meta
:
db_table
=
'AllDevCmdDefineAndVersion'
db_table
=
'AllDevCmdDefineAndVersion'
...
@@ -41,6 +66,20 @@ class AllProtocolDefinAndVersion(models.Model):
...
@@ -41,6 +66,20 @@ class AllProtocolDefinAndVersion(models.Model):
cmd_explain
=
models
.
TextField
()
# Field name made lowercase.
cmd_explain
=
models
.
TextField
()
# Field name made lowercase.
version
=
models
.
TextField
()
version
=
models
.
TextField
()
def
__eq__
(
self
,
__value
:
object
)
->
bool
:
if
not
isinstance
(
__value
,
AllProtocolDefinAndVersion
):
return
False
if
(
self
.
protocol_name
==
__value
.
protocol_name
and
self
.
cmd_name
==
__value
.
cmd_name
and
self
.
cmd_type
==
__value
.
cmd_type
and
self
.
encode
==
__value
.
encode
and
self
.
timing_cmd_cycle_period
==
__value
.
timing_cmd_cycle_period
and
self
.
cmd_explain
==
__value
.
cmd_explain
):
return
True
return
False
class
Meta
:
class
Meta
:
db_table
=
'AllProtocolDefinAndVersion'
db_table
=
'AllProtocolDefinAndVersion'
...
...
protocol_version_manage/services.py
View file @
ab0d4589
...
@@ -115,7 +115,61 @@ def update_device_protocol_and_cmds(protocol_name: str, version: str) -> Respons
...
@@ -115,7 +115,61 @@ def update_device_protocol_and_cmds(protocol_name: str, version: str) -> Respons
return
Response
(
data
=
res_data
,
status
=
status
.
HTTP_200_OK
)
return
Response
(
data
=
res_data
,
status
=
status
.
HTTP_200_OK
)
def
add_protocol_version_manage
(
protocol_name
:
str
,
version
:
str
,
cmds
:
list
)
->
Response
:
"""
添加协议版本信息
:param protocol_name: 协议名
:param version: 版本号
:param cmds: 协议相关的命令
:return: 当前版本,协议相关的数据
"""
# 给协议添加新的版本号
all_protocol_version_manage
=
AllProtocolVersion
.
objects
.
filter
(
protocol_name
=
protocol_name
)
.
first
()
version_paths
=
json
.
loads
(
all_protocol_version_manage
.
version_paths
)
version_paths
.
append
({
"version"
:
version
})
all_protocol_version_manage
.
version_paths
=
json
.
dumps
(
version_paths
)
all_protocol_version_manage
.
save
()
try
:
# 更新协议下的指令
for
cmd
in
cmds
:
# 获取指令字段
fields
=
cmd
.
pop
(
'fields'
)
# 处理协议指令
_cmd
=
AllProtocolDefinAndVersion
.
objects
.
filter
(
protocol_name
=
protocol_name
,
cmd_name
=
cmd
[
'cmd_name'
])
.
first
()
new_cmd
=
AllProtocolDefinAndVersion
(
**
cmd
)
if
_cmd
==
new_cmd
:
# 如果指令已经存在,则更新版本号
version_list
=
json
.
loads
(
_cmd
.
version
)
version_list
.
append
(
version
)
if
version
not
in
version_list
else
version_list
_cmd
.
version
=
json
.
dumps
(
version_list
)
_cmd
.
save
()
else
:
# 指令不存在,则存储指令信息
new_cmd
.
version
=
json
.
dumps
([
version
])
new_cmd
.
save
()
# 处理指令
for
field
in
fields
:
_field
=
AllDevCmdDefineAndVersion
.
objects
.
filter
(
cmd_name
=
cmd
[
'cmd_name'
],
fieldname
=
field
[
'fieldname'
])
.
first
()
new_field
=
AllDevCmdDefineAndVersion
(
**
field
)
if
_field
==
new_field
:
# 如果指令字段已经存在,则更新版本号
version_list
=
json
.
loads
(
_field
.
version
)
version_list
.
append
(
version
)
if
version
not
in
version_list
else
version_list
_field
.
version
=
json
.
dumps
(
version_list
)
_field
.
save
()
else
:
# 指令字段不存在,则存储指令信息
new_field
.
version
=
json
.
dumps
([
version
])
new_field
.
save
()
except
Exception
as
e
:
print
(
e
)
return
Response
(
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
return
Response
(
status
=
status
.
HTTP_200_OK
)
protocol_version_manage/urls.py
View file @
ab0d4589
...
@@ -6,5 +6,6 @@ from . import views
...
@@ -6,5 +6,6 @@ from . import views
urlpatterns
=
[
urlpatterns
=
[
re_path
(
r'^protocol_version_manage/init/$'
,
views
.
init
),
re_path
(
r'^protocol_version_manage/init/$'
,
views
.
init
),
re_path
(
r'^protocol_version_manage/change_protocol_version/$'
,
views
.
change_protocol_version
),
re_path
(
r'^protocol_version_manage/change_protocol_version/$'
,
views
.
change_protocol_version
),
re_path
(
r'^protocol_version_manage/add_protocol_version/$'
,
views
.
add_protocol_version
),
re_path
(
r'^all_protocol_version/$'
,
views
.
AllProtocolVersionViewSet
.
as_view
({
'get'
:
'list'
})),
re_path
(
r'^all_protocol_version/$'
,
views
.
AllProtocolVersionViewSet
.
as_view
({
'get'
:
'list'
})),
]
]
protocol_version_manage/views.py
View file @
ab0d4589
...
@@ -9,7 +9,7 @@ from .models import (AllDevCmdDefineAndVersion, AllProtocolDefinAndVersion,
...
@@ -9,7 +9,7 @@ from .models import (AllDevCmdDefineAndVersion, AllProtocolDefinAndVersion,
AllProtocolVersion
,
CurrentDevVersion
)
AllProtocolVersion
,
CurrentDevVersion
)
from
.serializers
import
(
AllDevCmdDefineAndVersionSerializer
,
AllProtocolDefinAndVersionSerializer
,
from
.serializers
import
(
AllDevCmdDefineAndVersionSerializer
,
AllProtocolDefinAndVersionSerializer
,
AllProtocolVersionSerializer
,
CurrentDevVersionSerializer
)
AllProtocolVersionSerializer
,
CurrentDevVersionSerializer
)
from
.services
import
init_protocol_version_manage
,
update_device_protocol_and_cmds
from
.services
import
init_protocol_version_manage
,
update_device_protocol_and_cmds
,
add_protocol_version_manage
@api_view
([
'POST'
])
@api_view
([
'POST'
])
...
@@ -48,6 +48,16 @@ def change_protocol_version(request):
...
@@ -48,6 +48,16 @@ def change_protocol_version(request):
return
update_device_protocol_and_cmds
(
protocol_name
,
version
)
return
update_device_protocol_and_cmds
(
protocol_name
,
version
)
@api_view
([
'POST'
])
def
add_protocol_version
(
request
):
version
=
request
.
data
.
get
(
'version'
)
protocol_name
=
request
.
data
.
get
(
'protocol_name'
)
cmds
=
request
.
data
.
get
(
'cmds'
)
assert
(
protocol_name
is
not
None
and
cmds
is
not
None
and
version
is
not
None
),
Response
(
status
=
status
.
HTTP_400_BAD_REQUEST
)
return
add_protocol_version_manage
(
protocol_name
,
version
,
cmds
)
class
AllProtocolVersionViewSet
(
GenericViewSet
,
ListModelMixin
):
class
AllProtocolVersionViewSet
(
GenericViewSet
,
ListModelMixin
):
queryset
=
AllProtocolVersion
.
objects
.
all
()
queryset
=
AllProtocolVersion
.
objects
.
all
()
...
...
xdc.sqlite
View file @
ab0d4589
No preview for this file 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