Commit eee8e233 by 周田

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

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