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
ebd02fbc
Commit
ebd02fbc
authored
Aug 23, 2023
by
周田
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 文件的上传和下载
parent
4681552d
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
62 additions
and
145 deletions
+62
-145
Upload.vue
frontend/src/views/Upload.vue
+2
-2
My SQL.txt
protocol_raw_files/HY_VirtualDevice_PROTOCOL/222/My SQL.txt
+0
-140
Table_DevInfo.xlsx
...aw_files/HY_VirtualDevice_PROTOCOL/222/Table_DevInfo.xlsx
+0
-0
urls.py
protocol_version_manage/urls.py
+3
-1
views.py
protocol_version_manage/views.py
+57
-2
xdc.sqlite
xdc.sqlite
+0
-0
No files found.
frontend/src/views/Upload.vue
View file @
ebd02fbc
<
template
>
<
template
>
<el-upload
<el-upload
class=
"upload-demo"
class=
"upload-demo"
action=
"
test/
upload/"
action=
"
api/protocol_version_manage/file_
upload/"
:show-file-list=
"false"
:show-file-list=
"false"
:data=
"data"
:data=
"data"
>
>
...
@@ -23,7 +23,7 @@ const data = ref({
...
@@ -23,7 +23,7 @@ const data = ref({
});
});
const
downloadFile
=
()
=>
{
const
downloadFile
=
()
=>
{
let
url
=
"
test/download/?protocol_name=HY_VirtualDevice_PROTOCOL&version=222
"
;
let
url
=
"
api/protocol_version_manage/file_download/HY_VirtualDevice_PROTOCOL/222/
"
;
axios
({
axios
({
url
,
url
,
method
:
"GET"
,
method
:
"GET"
,
...
...
protocol_raw_files/HY_VirtualDevice_PROTOCOL/222/My SQL.txt
deleted
100644 → 0
View file @
4681552d
/*
Navicat Premium Data Transfer
Source Server : test
Source Server Type : MySQL
Source Server Version : 80030
Source Host : 192.168.3.11:3306
Source Schema : mysql_oam_110
Target Server Type : MySQL
Target Server Version : 80030
File Encoding : 65001
Date: 22/12/2022 16:36:32
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for alarm_attribution
-- ----------------------------
DROP TABLE IF EXISTS `alarm_attribution`;
CREATE TABLE `alarm_attribution` (
`id` bigint(0) NOT NULL AUTO_INCREMENT COMMENT '序号,自增',
`alarmid` bigint(0) NULL DEFAULT NULL COMMENT '告警 ID',
`alarmlevel` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '告警级别',
`alarmdescriptionchn` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '中文描述,应该描述故障现象 和解决问题的方法',
`alarmdescriptioneng` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '英文描述',
`ismon` int(0) NULL DEFAULT NULL COMMENT '是否监视',
`updatetime` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '最新更新时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 176 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for current_alarm
-- ----------------------------
DROP TABLE IF EXISTS `current_alarm`;
CREATE TABLE `current_alarm` (
`id` bigint(0) NOT NULL AUTO_INCREMENT COMMENT '告警序号',
`alarmid` bigint(0) NULL DEFAULT NULL COMMENT '告警 ID,取自告警配置列表中的 ID',
`stationid` int(0) NULL DEFAULT NULL COMMENT '告警源头,SUID 标识',
`deviceid` int(0) NULL DEFAULT NULL COMMENT '告警子设备',
`alarmlevel` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`alarmdescriptionchn` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '告警描述',
`alarmdescriptioneng` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`reporttime` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '告警产生时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for current_performance
-- ----------------------------
DROP TABLE IF EXISTS `current_performance`;
CREATE TABLE `current_performance` (
`id` bigint(0) NOT NULL AUTO_INCREMENT,
`perid` int(0) NULL DEFAULT NULL,
`stationid` int(0) NULL DEFAULT NULL,
`deviceid` int(0) NULL DEFAULT NULL,
`datacatlog` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`fieldname` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`fieldvalue` varchar(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`perdescriptionchn` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`perdescriptioneng` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`updatetime` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for history_alarm
-- ----------------------------
DROP TABLE IF EXISTS `history_alarm`;
CREATE TABLE `history_alarm` (
`id` bigint(0) NOT NULL AUTO_INCREMENT,
`alarmid` int(0) NULL DEFAULT NULL COMMENT '告警 ID,取自告警配置列表中的 ID',
`stationid` int(0) NULL DEFAULT NULL COMMENT '告警源头,SUID标识',
`deviceid` int(0) NULL DEFAULT NULL,
`alarmlevel` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`alarmdescriptionchn` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`alarmdescriptioneng` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`starttime` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '告警产生时间 ',
`endtime` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '告警结束时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for log_info
-- ----------------------------
DROP TABLE IF EXISTS `log_info`;
CREATE TABLE `log_info` (
`id` bigint(0) NOT NULL AUTO_INCREMENT,
`stationid` int(0) NULL DEFAULT NULL,
`deviceid` int(0) NULL DEFAULT NULL,
`manipunator` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`loglevel` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`classification` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`loginfochn` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`loginfoeng` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`reporttime` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for per_attribution
-- ----------------------------
DROP TABLE IF EXISTS `per_attribution`;
CREATE TABLE `per_attribution` (
`id` bigint(0) NOT NULL AUTO_INCREMENT,
`perid` bigint(0) NULL DEFAULT NULL,
`datacatlog` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`fieldname` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`perdescriptionchn` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`perdescriptioneng` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`ismon` int(0) NULL DEFAULT NULL,
`isfixed` int(0) NULL DEFAULT NULL,
`fieldunit` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`fieldtype` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`operator1` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`operand1` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`relation` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`operator2` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`operand2` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`alarmlevel` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`alarmdeschn` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`alarmdeseng` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`updatetime` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3435 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
-- auto-generated definition
create table history_performance
(
id int auto_increment
primary key,
suid int not null comment '1/1/1/9 1/1/2/6 ',
value varchar(100) not null comment 'EbN0,BER,中频输入电压,ACU 20.5,1.2-34,-12.5,255',
time varchar(30) not null comment '2023-06-05 06:05:25'
);
SET FOREIGN_KEY_CHECKS = 1;
protocol_raw_files/HY_VirtualDevice_PROTOCOL/222/Table_DevInfo.xlsx
deleted
100644 → 0
View file @
4681552d
File deleted
protocol_version_manage/urls.py
View file @
ebd02fbc
...
@@ -8,6 +8,8 @@ urlpatterns = [
...
@@ -8,6 +8,8 @@ urlpatterns = [
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'^protocol_version_manage/add_protocol_version/$'
,
views
.
add_protocol_version
),
re_path
(
r'^protocol_version_manage/update_protocol_version/$'
,
views
.
update_protocol_version
),
re_path
(
r'^protocol_version_manage/update_protocol_version/$'
,
views
.
update_protocol_version
),
# re_path(r'^protocol_version_manage/file_upload/$', views.file_upload),
re_path
(
r'^protocol_version_manage/file_upload/$'
,
views
.
raw_file_upload
),
re_path
(
r'^protocol_version_manage/file_download/(?P<protocol_name>.+)/(?P<version>.+)/$'
,
views
.
raw_file_download
),
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 @
ebd02fbc
import
os
import
json
import
json
import
urllib.parse
from
django.conf
import
settings
from
django.http
import
FileResponse
from
rest_framework.decorators
import
api_view
,
parser_classes
from
rest_framework.decorators
import
api_view
,
parser_classes
from
rest_framework.parsers
import
MultiPartParser
from
rest_framework.parsers
import
MultiPartParser
from
rest_framework.response
import
Response
from
rest_framework.response
import
Response
...
@@ -79,5 +83,56 @@ class AllProtocolVersionViewSet(GenericViewSet, ListModelMixin):
...
@@ -79,5 +83,56 @@ class AllProtocolVersionViewSet(GenericViewSet, ListModelMixin):
@api_view
([
'POST'
])
@api_view
([
'POST'
])
@parser_classes
([
MultiPartParser
])
@parser_classes
([
MultiPartParser
])
def
file_upload
(
request
):
def
raw_file_upload
(
request
):
pass
# 将上传来的文件保存下来
file_obj
=
request
.
FILES
.
get
(
'file'
)
protocol_name
=
request
.
data
.
get
(
'protocol_name'
)
version
=
request
.
data
.
get
(
'version'
)
assert
protocol_name
is
not
None
and
version
is
not
None
,
Response
(
status
=
status
.
HTTP_400_BAD_REQUEST
)
try
:
folder_path
=
os
.
path
.
join
(
settings
.
BASE_DIR
,
'protocol_raw_files'
,
protocol_name
,
version
)
if
not
os
.
path
.
exists
(
folder_path
):
os
.
makedirs
(
folder_path
)
file_path
=
os
.
path
.
join
(
folder_path
,
file_obj
.
name
)
with
open
(
file_path
,
'wb'
)
as
f
:
for
chunk
in
file_obj
.
chunks
():
f
.
write
(
chunk
)
except
Exception
as
e
:
print
(
e
)
return
Response
(
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
# 更新协议版本信息,将文件路径保存下来
protocol_versions
=
AllProtocolVersion
.
objects
.
filter
(
protocol_name
=
protocol_name
)
.
first
()
version_path_list
=
json
.
loads
(
protocol_versions
.
version_paths
)
for
version_path
in
version_path_list
:
if
version_path
[
'version'
]
==
version
:
if
version_path
.
get
(
'path'
,
None
)
is
not
None
:
os
.
remove
(
version_path
[
'path'
])
version_path
[
'path'
]
=
file_path
break
protocol_versions
.
version_paths
=
json
.
dumps
(
version_path_list
)
protocol_versions
.
save
()
return
Response
(
data
=
{
'path'
:
file_path
},
status
=
status
.
HTTP_200_OK
)
@api_view
([
'GET'
])
@parser_classes
([
MultiPartParser
])
def
raw_file_download
(
request
,
protocol_name
,
version
):
try
:
protocol_versions
=
AllProtocolVersion
.
objects
.
filter
(
protocol_name
=
protocol_name
)
.
first
()
for
version_path
in
json
.
loads
(
protocol_versions
.
version_paths
):
if
version_path
[
'version'
]
==
version
:
file_path
=
version_path
[
'path'
]
break
file_name
=
urllib
.
parse
.
quote
(
os
.
path
.
basename
(
file_path
))
response
=
FileResponse
(
open
(
file_path
,
'rb'
))
except
Exception
as
e
:
print
(
e
)
return
Response
(
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
response
[
'Content-Disposition'
]
=
'attachment; filename='
+
file_name
response
[
'Content-Type'
]
=
'multipart/form-data'
response
[
'filename'
]
=
file_name
return
response
xdc.sqlite
View file @
ebd02fbc
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