Commit eee8e233 by 周田

refactor:新增和删除协议,指令,字段

parent c55e0acb
......@@ -2,7 +2,7 @@ from rest_framework.routers import SimpleRouter
from .views import (TableAllDevCmdDefineView, TableDevCmdNamePollView,
TableSoftLimitAngleView, TableXproAllDevinfoView,
TableAllDevCmdDefineView_1, TableDevCmdNamePollView_1)
from .views import test
from .views import test, remove_protocol
from django.urls import re_path
router = SimpleRouter()
......@@ -16,6 +16,7 @@ router.register(r'dev_cmd_name_poll_1', TableDevCmdNamePollView_1)
urlpatterns = [
re_path(r'^test/$', test),
re_path(r'^protocol/(?P<protocol_name>.+)/$', remove_protocol),
]
......
......@@ -120,18 +120,27 @@ class TableDevCmdNamePollView_1(ModelViewSet):
def perform_destroy(self, instance):
"""
删除指令,给 TableDevCmdNamePollView 表删除记录时,同时给 AllProtocolDefineAndVersion 表删除
同时要删除指令下的字段
"""
protocol_name = instance.protocol_name
cmd_name = instance.cmd_name
# 删除指令下的字段
TableAllDevCmdDefine.objects.filter(cmd_name=cmd_name).delete()
current_obj = CurrentDevVersion.objects.filter(protocol_name=protocol_name).first()
assert current_obj is not None, "当前协议不存在"
AllProtocolDefinAndVersion.objects.filter(protocol_name=protocol_name,
cmd_name=cmd_name,
version=current_obj.version).delete()
AllDevCmdDefineAndVersion.objects.filter(cmd_name=cmd_name, version=current_obj.version).delete()
super().perform_destroy(instance)
# 当当前协议指令删完了之后,版本表里面就不存数据了
if len(TableDevCmdNamePoll.objects.filter(protocol_name=protocol_name).all()) == 0:
CurrentDevVersion.objects.filter(protocol_name=protocol_name).delete()
AllProtocolVersion.objects.filter(protocol_name=protocol_name).delete()
def perform_update(self, serializer):
"""
更新指令,给 TableDevCmdNamePollView 表更新记录时,同时给 AllProtocolDefineAndVersion 表更新
......@@ -259,3 +268,30 @@ def test(request):
cmd_fields_serializer.is_valid(raise_exception=True)
cmd_fields.perform_create(cmd_fields_serializer)
return Response(status=status.HTTP_201_CREATED)
@api_view(['delete'])
def remove_protocol(request, protocol_name):
"""
删除协议
"""
# 删除协议
cmds = TableDevCmdNamePoll.objects.filter(protocol_name=protocol_name).all()
for cmd in cmds:
cmd_name = cmd.cmd_name
TableAllDevCmdDefine.objects.filter(cmd_name=cmd_name).delete()
cmd.delete()
# 删除协议版本
CurrentDevVersion.objects.filter(protocol_name=protocol_name).delete()
AllProtocolVersion.objects.filter(protocol_name=protocol_name).delete()
# 删除管理的协议
cmds = AllProtocolDefinAndVersion.objects.filter(protocol_name=protocol_name).all()
for cmd in cmds:
cmd_name = cmd.cmd_name
TableAllDevCmdDefine.objects.filter(cmd_name=cmd_name).delete()
cmd.delete()
return Response(status=status.HTTP_204_NO_CONTENT)
......@@ -48,11 +48,11 @@ onBeforeMount(async () => {
})
await DeviceProtocol()
.then((res) => {
protocolStore.deviceProtocol = res
protocolStore.deviceProtocol = res.data
})
await ProtocolCmd()
.then((res) => {
protocolStore.protocolCmd = res
protocolStore.protocolCmd = res.data
})
})
</script>
......
......@@ -37,12 +37,18 @@
<el-collapse class="mt-4">
<el-collapse-item
v-for="cmd in cmdInfos"
:title="cmd.cmd_name + ' ' + cmd.cmd_explain + ' ' + cmd.cmd_type">
v-for="cmd in cmdInfos">
<template #title>
<div>{{ cmd.cmd_name + ' ' + cmd.cmd_explain + ' ' + cmd.cmd_type }}</div>
<div>
<el-button type="primary" text @click="removeCmd(cmd.id)">删除</el-button>
</div>
</template>
<protocol-table
v-if="fieldInfos !== undefined"
:cmd-name="cmd.cmd_name"
:version="currentVersion"
:protocol-name="props.name"
:cmd-type="cmd.cmd_type"
:message="fieldInfos[cmd.cmd_name]" />
</el-collapse-item>
......@@ -87,7 +93,7 @@
<script setup lang="ts">
import { ref, onMounted, reactive } from 'vue'
import { ElMessage, ElMessageBox } from "element-plus";
import { ProtocolInit } from "@/dao/protocol"
import { ProtocolInit, addCmdDao, removeCmdDao } from "@/dao/protocol"
import ProtocolTable from "./ProtocolTable.vue";
import type { DeviceProtocolResponse, ProtocolCmdResponse } from './types';
import { useProtocolVersionStore } from '@/stores/allProtocolVersion';
......@@ -289,7 +295,7 @@ const addCmd = () => {
}
)
.then(() => {
axios.post('/api/protocol_vesrion_manage/add_protocol_cmd/', {
addCmdDao({
protocol_name: props.name,
cmd_name: addCmdData.cmd_name,
cmd_type: addCmdData.cmd_type,
......@@ -298,21 +304,20 @@ const addCmd = () => {
cmd_explain: addCmdData.cmd_explain,
version: currentVersion.value,
})
.then(() => {
.then((res) => {
ElMessage({
type: 'success',
message: '操作成功',
})
changeProtocolVersion()
cmdInfos.value.push(res.data)
})
.catch(() => {
.catch((error) => {
ElMessage({
type: 'error',
message: '操作失败',
message: error.message,
})
})
addCmdDialog.value = false
addCmdDialog.value = false
})
.catch(() => {
ElMessage({
......@@ -322,6 +327,16 @@ const addCmd = () => {
})
}
const removeCmd = (id: number) => {
removeCmdDao(id)
.then(() => {
cmdInfos.value = cmdInfos.value.filter((item: any) => item.id !== id)
})
.catch((err) => {
console.log(err);
})
}
</script>
<style>
......
<template>
<div class="demo-collapse">
<el-collapse>
<el-collapse-item v-for="item in protocol_names">
<template #title>{{ item }}</template>
<el-collapse-item v-for="item in protocolNames">
<template #title>
<div> {{ item }} </div>
<div>
<el-button type="primary" text @click="removeProtocol(item)">删除</el-button>
</div>
</template>
<div style="margin: auto; width: 90%">
<collapse-table
v-if="props.protocolCmd !== undefined"
......@@ -20,6 +25,7 @@
import { onMounted, ref, watch } from 'vue'
import CollapseTable from "./CollapseTable.vue";
import type { DeviceProtocolResponse, ProtocolCmdResponse } from './types';
import { removeProtocolDao } from '@/dao/protocol';
type propsType = {
deviceProtocol: DeviceProtocolResponse,
......@@ -29,14 +35,24 @@ const props = defineProps<propsType>()
onMounted(() => {
let { fields } = props.deviceProtocol
protocol_names.value = fields
protocolNames.value = fields
})
const protocol_names = ref<string[]>([]);
const protocolNames = ref<string[]>([]);
watch(() => props.deviceProtocol, (val) => {
let { fields } = val
protocol_names.value = fields
protocolNames.value = fields
})
const removeProtocol = (protocolName: string) => {
removeProtocolDao(protocolName)
.then(() =>{
protocolNames.value = protocolNames.value.filter(item => item !== protocolName)
})
.catch(err => {
console.log(err)
})
}
</script>
<style>
......
......@@ -158,6 +158,7 @@ type propsType = {
cmdName: string,
cmdType: string,
version: string,
protocolName: string,
message: CmdInfo[]
}
const props = defineProps<propsType>()
......@@ -259,10 +260,11 @@ function Delete(id: number) {
}
function Add(params: any) {
params['version'] = props.version
console.log(params);
params['protocol_name'] = props.protocolName
AddProtocolCmd(params)
.then((res) => {
tableData.value.push(res.data!)
})
}
function confirm(type: string, data: CmdInfo) {
......@@ -276,10 +278,6 @@ function confirm(type: string, data: CmdInfo) {
}
)
.then(() => {
ElMessage({
type: 'success',
message: '操作成功',
})
dialogVisible.value = false
more.value = false
if (type === 'edit') {
......@@ -290,7 +288,6 @@ function confirm(type: string, data: CmdInfo) {
tableData.value.splice(data['fieldindex'] - 1, 1)
} else if (type === 'add') {
Add(fields.value)
tableData.value.push(fields.value)
}
})
.catch(() => {
......
import axios from "axios"
import type { CmdInfo } from '@/components/protocol/types'
import request from "@/plugins/axios/requests"
import type { DeviceProtocolResponse, ProtocolCmdResponse } from '@/components/protocol/types';
// const baseURL = 'http://192.168.0.214:8000/op'
export function DeviceProtocol() {
return axios.get('/api/dev_cmd_name_poll_1/').then(
function (response) {
return response.data
}
)
return request.get<DeviceProtocolResponse>('/api/dev_cmd_name_poll_1/')
}
export function ProtocolCmd() {
return axios.get('/api/all_dev_cmd_define_1/').then(
function (response) {
return response.data
}
)
return request.get<ProtocolCmdResponse>('/api/all_dev_cmd_define_1/')
}
export function EditProtocolCmd(id: number, params: any) {
return axios.put('/api/all_dev_cmd_define_1/' + id + '/', params).then(
function (response) {
return response.data
}
)
return request.put('/api/all_dev_cmd_define_1/' + id + '/', params)
}
export function DeleteProtocolCmd(id: number) {
return axios.delete('/api/all_dev_cmd_define_1/' + id + '/').then(
function (response) {
return response.data
}
)
return request.del('/api/all_dev_cmd_define_1/' + id + '/')
}
export function AddProtocolCmd(params: any) {
return axios.post('/api/protocol_version_manage/cmd_fields_manager/', params).then(
function (response) {
return response.data
}
)
return request.post<CmdInfo>('/api/all_dev_cmd_define_1/', params)
}
\ No newline at end of file
import axios from "axios"
import request from "@/plugins/axios/requests"
// const baseURL = 'http://192.168.0.214:8000/op'
export function GetProtocolVersion(){
return axios.get('/api/all_protocol_version/').then(
function (response){
return response.data
}
)
export function GetProtocolVersion() {
return axios.get('/api/all_protocol_version/').then(
function (response) {
return response.data
}
)
}
export function ProtocolInit(protocol_name: any){
return axios.post('/api/protocol_version_manage/init/', protocol_name).then(
function (response){
return response.data
}
)
export function ProtocolInit(protocol_name: any) {
return axios.post('/api/protocol_version_manage/init/', protocol_name).then(
function (response) {
return response.data
}
)
}
export function GetCurrentVersion() {
return axios.get('/api/current_versions/').then(
function (response) {
return response.data
}
)
return axios.get('/api/current_versions/').then(
function (response) {
return response.data
}
)
}
export function removeProtocolDao(protocolName: string) {
return request.del('/api/protocol/' + protocolName + '/')
}
export function addCmdDao(param: any) {
return request.post('/api/dev_cmd_name_poll_1/', param)
}
export function removeCmdDao(id: number) {
return request.del('/api/dev_cmd_name_poll_1/' + id + '/')
}
\ No newline at end of file
......@@ -71,6 +71,7 @@ service.interceptors.response.use((response: AxiosResponse) => {
type: 'error',
showClose: true
})
// 数据被 catch 接收
return Promise.reject(response.data);
}
......
......@@ -4,24 +4,24 @@ import { Get, Post, Delete, Put } from './types'; // 接口泛型
// 封装 get 方法,类型为Get
const get: Get = async (url, config) => {
const response = await service.get(url, { ...config});
return response.data;
return response;
};
const post: Post = async (url, params, config) => {
const response = await service.post(url, params, {...config});
return response.data;
return response;
};
// 封装 delete 方法
const del: Delete = async (url, config) => {
const response = await service.delete(url, {...config});
return response.data;
return response;
}
// 封装 put 方法
const put: Put = async (url, params, config) => {
const response = await service.put(url, params, {...config});
return response.data;
return response;
}
// 使用 request 统一调用
......
......@@ -2,7 +2,7 @@ import { InternalAxiosRequestConfig } from 'axios';
// 网络请求响应格式,T 是具体的接口返回类型数据
interface CustomSuccessData<T> {
code: number;
status: number;
msg?: string;
message?: string;
data?: T;
......
......@@ -33,6 +33,7 @@
import { ref, onBeforeMount } from 'vue';
import KitCollapse from '@/components/protocol/KitCollapse.vue';
import { useProtocolInfoStore } from '@/stores/protocolInfo';
import { useProtocolVersionStore } from '@/stores/allProtocolVersion';
import type { DeviceProtocolResponse, ProtocolCmdResponse } from '@/components/protocol/types';
const isShow = ref<boolean>(false)
......@@ -47,10 +48,15 @@ onBeforeMount(() => {
})
const protocolName = ref<string>('')
const store = useProtocolVersionStore()
const addProtocol = () => {
isShow.value = false
deviceProtocol.value!.fields.push(protocolName.value)
deviceProtocol.value![protocolName.value] = []
store.currentVersions.push({protocol_name: protocolName.value, version: "init"})
store.protocolVersions.push({protocol_name: protocolName.value, version_paths: JSON.stringify([{version: "init"}])
})
}
</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;
......@@ -24,7 +24,7 @@ def init_protocol_version_manage(protocol_name: str) -> None:
protocol_cmds_serializer = TableDevCmdNamePollSerializer(protocol_cmds, many=True)
all_protocol_objects: list[AllProtocolDefinAndVersion] = []
for protocol in protocol_cmds_serializer.data:
protocol['version'] = json.dumps([INIT_VERSION])
protocol['version'] = INIT_VERSION
del protocol['id']
all_protocol_objects.append(AllProtocolDefinAndVersion(**protocol))
AllProtocolDefinAndVersion.objects.bulk_create(all_protocol_objects)
......@@ -35,7 +35,7 @@ def init_protocol_version_manage(protocol_name: str) -> None:
cmd_fields_serializer = TableAllDevCmdDefineSerializer(cmd_fields, many=True)
all_cmd_fields_objects: list[AllDevCmdDefineAndVersion] = []
for cmd_field in cmd_fields_serializer.data:
cmd_field['version'] = json.dumps([INIT_VERSION])
cmd_field['version'] = INIT_VERSION
del cmd_field['id']
all_cmd_fields_objects.append(AllDevCmdDefineAndVersion(**cmd_field))
AllDevCmdDefineAndVersion.objects.bulk_create(all_cmd_fields_objects)
......
......@@ -18,7 +18,6 @@ urlpatterns = [
views.raw_file_download),
re_path(r'^all_protocol_version/$', views.AllProtocolVersionViewSet.as_view({'get': 'list'})),
re_path(r'^protocol_vesrion_manage/delete_protocol_vesrion/$', views.delete_protocol_vesrion),
re_path(r'^protocol_vesrion_manage/add_protocol_cmd/$', views.add_protocol_cmd),
]
urlpatterns += router.urls
......@@ -268,37 +268,6 @@ def delete_protocol_vesrion(request):
return Response(status=status.HTTP_200_OK)
@swagger_auto_schema(methods=['POST'], request_body=openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
'protocol_name': openapi.Schema(type=openapi.TYPE_STRING),
'cmd_name': openapi.Schema(type=openapi.TYPE_STRING),
'cmd_type': openapi.Schema(type=openapi.TYPE_STRING),
'encode': openapi.Schema(type=openapi.TYPE_STRING),
'timing_cmd_cycle_period': openapi.Schema(type=openapi.TYPE_INTEGER),
'cmd_explain': openapi.Schema(type=openapi.TYPE_STRING),
'version': openapi.Schema(type=openapi.TYPE_STRING),
}
))
@api_view(['POST'])
def add_protocol_cmd(request):
data = request.data
if (data.get('protocol_name') is None or
data.get('cmd_name') is None or
data.get('cmd_type') is None or
data.get('encode') is None or
data.get('timing_cmd_cycle_period') is None or
data.get('cmd_explain') is None or
data.get('version') is None):
return Response(status=status.HTTP_400_BAD_REQUEST)
data['version'] = json.dumps([data['version']])
obj = AllProtocolDefinAndVersion.objects.create(**data)
if obj is not None:
return Response(status=status.HTTP_200_OK)
return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
class AllDevCmdDefineAndVersionViewSet(ModelViewSet):
queryset = AllDevCmdDefineAndVersion.objects.all()
serializer_class = AllDevCmdDefineAndVersionSerializer
......
No preview for this file type
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