Commit 0614881a by 周田

feat:测试 文件下载

parent dceb1c5f
...@@ -7,14 +7,37 @@ ...@@ -7,14 +7,37 @@
> >
<el-button type="primary">Click to upload</el-button> <el-button type="primary">Click to upload</el-button>
</el-upload> </el-upload>
<br>
<el-button type="primary" @click="downloadFile">下载原始文件</el-button>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref } from "vue"; import { ref } from "vue";
import axios from "axios";
const data = ref({ const data = ref({
"protocol_name": "HY_VirtualDevice_PROTOCOL", "protocol_name": "HY_VirtualDevice_PROTOCOL",
"version": "222", "version": "222",
}); });
const downloadFile = () => {
let url = "test/download/?protocol_name=HY_VirtualDevice_PROTOCOL&version=222";
axios({
url,
method: "GET",
responseType: "blob",
}).then((res) => {
// 下载文件
console.log(res);
const blob = new Blob([res.data], { type: "multipart/form-data" });
const link = document.createElement("a");
link.href = window.URL.createObjectURL(blob);
link.download = res.headers["filename"]
link.click();
});
console.log("downloadFile");
};
</script> </script>
/*
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;
...@@ -15,7 +15,7 @@ Including another URLconf ...@@ -15,7 +15,7 @@ Including another URLconf
""" """
from django.contrib import admin from django.contrib import admin
from django.urls import path, include, re_path from django.urls import path, include, re_path
from .views import index, test, upload from .views import index, test, upload, download
from django.conf import settings from django.conf import settings
from django.views.static import serve from django.views.static import serve
...@@ -36,6 +36,7 @@ urlpatterns = [ ...@@ -36,6 +36,7 @@ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path("", index), path("", index),
path("test/upload/", upload), path("test/upload/", upload),
path("test/download/", download),
path("mqtt/", include("mqtt.urls")), path("mqtt/", include("mqtt.urls")),
path("chat/", include("chat.urls")), path("chat/", include("chat.urls")),
path("op/", include("device_data_op.urls")), path("op/", include("device_data_op.urls")),
......
import os
from django.conf import settings
from django.http import FileResponse
from django.shortcuts import render from django.shortcuts import render
from rest_framework.decorators import api_view, parser_classes from rest_framework.decorators import api_view, parser_classes
from rest_framework.response import Response from rest_framework.response import Response
...@@ -5,6 +8,7 @@ from rest_framework.parsers import MultiPartParser ...@@ -5,6 +8,7 @@ from rest_framework.parsers import MultiPartParser
from rest_framework import status from rest_framework import status
def index(request): def index(request):
return render(request, 'index.html') return render(request, 'index.html')
...@@ -24,7 +28,32 @@ def upload(request): ...@@ -24,7 +28,32 @@ def upload(request):
print(protocol_name) print(protocol_name)
print(version) print(version)
print(file_obj.name) print(file_obj.name)
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)
with open(f'./protocol_raw_files/{protocol_name}/{version}/{file_obj.name}', 'wb+') as destination: with open(f'./protocol_raw_files/{protocol_name}/{version}/{file_obj.name}', 'wb+') as destination:
for chunk in file_obj.chunks(): for chunk in file_obj.chunks():
destination.write(chunk) destination.write(chunk)
return Response(status=status.HTTP_200_OK) return Response(status=status.HTTP_200_OK)
@api_view(['GET'])
def download(request):
protocol_name = request.GET.get('protocol_name')
version = request.GET.get('version')
print(protocol_name)
print(version)
file_path = os.path.join(settings.BASE_DIR, 'protocol_raw_files', protocol_name, version)
print(file_path)
for root, _, files in os.walk(file_path):
print(f"root ==> {root}")
file_path = os.path.join(root, files[1])
response = FileResponse(open(file_path, 'rb'))
response['Content-Disposition'] = 'inline; filename=' + os.path.basename(file_path)
response['Content-Type'] = 'multipart/form-data'
response['filename'] = os.path.basename(file_path)
return response
return Response(status=status.HTTP_200_OK)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment