Commit 58301397 by qianmo

Merge remote-tracking branch 'origin/main'

# Conflicts:
#	database/xdc.sqlite
parents 053d9b7c 6aa86105
...@@ -2,3 +2,4 @@ __pycache__ ...@@ -2,3 +2,4 @@ __pycache__
*.pyc *.pyc
.idea .idea
assets assets
*.tar
...@@ -76,7 +76,7 @@ def set_communication_to_devinfo_table(request): ...@@ -76,7 +76,7 @@ def set_communication_to_devinfo_table(request):
# 清空设备信息表 # 清空设备信息表
# TODO:实际开始用的时候,需要将这个注释打开 # TODO:实际开始用的时候,需要将这个注释打开
# TableXproAllDevinfo.objects.all().delete() TableXproAllDevinfo.objects.all().delete()
TableXproAllDevinfo.objects.bulk_create( TableXproAllDevinfo.objects.bulk_create(
[TableXproAllDevinfo(sta_id=communication.station_id, [TableXproAllDevinfo(sta_id=communication.station_id,
......
...@@ -4,10 +4,22 @@ from .models import TableAllDevCmdDefine, TableDevCmdNamePoll, TableSoftLimitAng ...@@ -4,10 +4,22 @@ from .models import TableAllDevCmdDefine, TableDevCmdNamePoll, TableSoftLimitAng
class TableAllDevCmdDefineSerializer(ModelSerializer): class TableAllDevCmdDefineSerializer(ModelSerializer):
# 新增或修改字段时,需要用到 protocol_name 来获取当前协议的当前版本
protocol_name = serializers.CharField(max_length=50, required=True, write_only=True)
class Meta: class Meta:
model = TableAllDevCmdDefine model = TableAllDevCmdDefine
fields = '__all__' fields = ['id', 'cmd_name', 'cmd_type', 'fieldindex', 'fieldname', 'fieldsize', 'value', 'minvalue', 'maxvalue',
'datatype', 'operation_in', 'operation_in_num', 'operation_out', 'operation_out_num', 'operabo_in',
'operabo_out', 'lua_script_in', 'lua_script_out', 'protocol_name']
def create(self, validated_data):
protocol_name = validated_data.pop('protocol_name')
instance = super().create(validated_data)
# 执行额外的逻辑或将protocol_name字段与实例关联
instance.protocol_name = protocol_name
instance.save()
return instance
class TableDevCmdNamePollSerializer(ModelSerializer): class TableDevCmdNamePollSerializer(ModelSerializer):
class Meta: class Meta:
......
from rest_framework.routers import SimpleRouter from rest_framework.routers import SimpleRouter
from .views import (TableAllDevCmdDefineView, TableDevCmdNamePollView, from .views import (TableAllDevCmdDefineView, TableDevCmdNamePollView,
TableSoftLimitAngleView, TableXproAllDevinfoView) TableSoftLimitAngleView, TableXproAllDevinfoView,
from .views import test TableAllDevCmdDefineView_1, TableDevCmdNamePollView_1)
from .views import test, remove_protocol, protocol_add_version
from django.urls import re_path from django.urls import re_path
router = SimpleRouter() router = SimpleRouter()
...@@ -10,8 +11,13 @@ router.register(r'dev_cmd_name_poll', TableDevCmdNamePollView) ...@@ -10,8 +11,13 @@ router.register(r'dev_cmd_name_poll', TableDevCmdNamePollView)
router.register(r'soft_limit_angle', TableSoftLimitAngleView) router.register(r'soft_limit_angle', TableSoftLimitAngleView)
router.register(r'xpro_all_devinfo', TableXproAllDevinfoView) router.register(r'xpro_all_devinfo', TableXproAllDevinfoView)
router.register(r'all_dev_cmd_define_1', TableAllDevCmdDefineView_1)
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/protocol_add_version/$', protocol_add_version),
re_path(r'^protocol/(?P<protocol_name>.+)/$', remove_protocol),
] ]
......
...@@ -7,6 +7,8 @@ from rest_framework.response import Response ...@@ -7,6 +7,8 @@ from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet from rest_framework.viewsets import ModelViewSet
from rest_framework.decorators import api_view from rest_framework.decorators import api_view
from rest_framework import status from rest_framework import status
from protocol_version_manage.models import (CurrentDevVersion, AllDevCmdDefineAndVersion,
AllProtocolDefinAndVersion, AllProtocolVersion)
from .models import (TableAllDevCmdDefine, TableDevCmdNamePoll, from .models import (TableAllDevCmdDefine, TableDevCmdNamePoll,
TableSoftLimitAngle, TableXproAllDevinfo) TableSoftLimitAngle, TableXproAllDevinfo)
from .serializers import (TableAllDevCmdDefineSerializer, TableDevCmdNamePollSerializer, from .serializers import (TableAllDevCmdDefineSerializer, TableDevCmdNamePollSerializer,
...@@ -14,6 +16,144 @@ from .serializers import (TableAllDevCmdDefineSerializer, TableDevCmdNamePollSer ...@@ -14,6 +16,144 @@ from .serializers import (TableAllDevCmdDefineSerializer, TableDevCmdNamePollSer
from .utils import tree_data from .utils import tree_data
class TableAllDevCmdDefineView_1(ModelViewSet):
queryset = TableAllDevCmdDefine.objects.all()
serializer_class = TableAllDevCmdDefineSerializer
def list(self, request):
serializer = self.get_serializer(self.get_queryset(), many=True)
data = tree_data(serializer.data, 'cmd_name')
return Response(data)
def perform_create(self, serializer):
"""
新增指令字段,给 TableAllDevCmdDefine 表创建记录时,同时给 AllDevCmdDefineAndVersion 表创建
"""
# 给表创建值
super().perform_create(serializer)
current_obj = CurrentDevVersion.objects.filter(protocol_name=serializer.validated_data['protocol_name']).first()
assert current_obj is not None, "当前协议不存在"
current_version = current_obj.version
serializer.validated_data['version'] = current_version
serializer.validated_data.pop('protocol_name')
AllDevCmdDefineAndVersion.objects.create(**serializer.validated_data)
def perform_destroy(self, instance):
"""
删除指令字段,给 TableAllDevCmdDefine 表删除记录时,同时给 AllDevCmdDefineAndVersion 表删除
这里由于不能直接获取到 protocol_name,所以需要先通过 TableDevCmdNamePoll 获取到 protocol_name,然后再删除
"""
cmd_name = instance.cmd_name
cmd_obj = TableDevCmdNamePoll.objects.filter(cmd_name=cmd_name).first()
assert cmd_obj is not None, "当前指令不存在"
current_protocol_name = cmd_obj.protocol_name
current_obj = CurrentDevVersion.objects.filter(protocol_name=current_protocol_name).first()
assert current_obj is not None, "当前协议不存在"
current_version = current_obj.version
AllDevCmdDefineAndVersion.objects.filter(cmd_name=instance.cmd_name,
fieldname=instance.fieldname,
version=current_version).delete()
# 更新 fieldindex
super().perform_destroy(instance)
fields = self.get_queryset().filter(cmd_name=cmd_name).all()
for i in range(len(fields)):
fields[i].fieldindex = i + 1
fields[i].save()
fields_ = AllDevCmdDefineAndVersion.objects.filter(cmd_name=cmd_name, version=current_version).all()
for i in range(len(fields_)):
fields_[i].fieldindex = i + 1
fields_[i].save()
def perform_update(self, serializer):
"""
更新指令字段,给 TableAllDevCmdDefine 表更新记录时,同时给 AllDevCmdDefineAndVersion 表更新
"""
super().perform_update(serializer)
current_obj = CurrentDevVersion.objects.filter(protocol_name=serializer.validated_data['protocol_name']).first()
assert current_obj is not None, "当前协议不存在"
current_version = current_obj.version
serializer.validated_data['version'] = current_version
serializer.validated_data.pop('protocol_name')
AllDevCmdDefineAndVersion.objects.filter(cmd_name=serializer.validated_data['cmd_name'],
fieldname=serializer.validated_data['fieldname'],
version=current_version).update(**serializer.validated_data)
class TableDevCmdNamePollView_1(ModelViewSet):
queryset = TableDevCmdNamePoll.objects.all()
serializer_class = TableDevCmdNamePollSerializer
def list(self, request):
serializer = self.get_serializer(self.get_queryset(), many=True)
data = tree_data(serializer.data, 'protocol_name')
return Response(data)
def perform_create(self, serializer):
"""
新增指令,给 TableDevCmdNamePollView 表创建记录时,同时给 AllProtocolDefineAndVersion 表创建
如果当前协议不存在,则在 CurentDevVersion 表创建记录,同时在 AllProtocolVersion 表创建记录
"""
super().perform_create(serializer)
current_obj = CurrentDevVersion.objects.filter(protocol_name=serializer.validated_data['protocol_name']).first()
if current_obj is None:
current_obj = CurrentDevVersion.objects.create(protocol_name=serializer.validated_data['protocol_name'],
version="init")
current_version = "init"
AllProtocolVersion.objects.create(protocol_name=serializer.validated_data['protocol_name'],
version_paths=json.dumps([{"version": "init"}]))
else:
current_version = current_obj.version
serializer.validated_data['version'] = current_version
AllProtocolDefinAndVersion.objects.create(**serializer.validated_data)
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 表更新
"""
current_obj = CurrentDevVersion.objects.filter(protocol_name=serializer.validated_data['protocol_name']).first()
assert current_obj is not None, "当前协议不存在"
serializer.validated_data['version'] = current_obj.version
AllProtocolDefinAndVersion.objects.filter(protocol_name=serializer.validated_data['protocol_name'],
cmd_name=serializer.validated_data['cmd_name'],
version=current_obj.version).update(**serializer.validated_data)
super().perform_update(serializer)
class TableAllDevCmdDefineView(ModelViewSet): class TableAllDevCmdDefineView(ModelViewSet):
queryset = TableAllDevCmdDefine.objects.all() queryset = TableAllDevCmdDefine.objects.all()
serializer_class = TableAllDevCmdDefineSerializer serializer_class = TableAllDevCmdDefineSerializer
...@@ -26,7 +166,6 @@ class TableAllDevCmdDefineView(ModelViewSet): ...@@ -26,7 +166,6 @@ class TableAllDevCmdDefineView(ModelViewSet):
def perform_destroy(self, instance): def perform_destroy(self, instance):
""" """
删除某个字段,需要将字段的 index 更新 删除某个字段,需要将字段的 index 更新
TODO: 返回更新后的数据(不能做完一个操作之后,页面就刷新)
""" """
# 获取改字段的 cmd_name # 获取改字段的 cmd_name
...@@ -129,3 +268,152 @@ def test(request): ...@@ -129,3 +268,152 @@ 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
AllDevCmdDefineAndVersion.objects.filter(cmd_name=cmd_name).delete()
cmd.delete()
return Response(status=status.HTTP_204_NO_CONTENT)
@swagger_auto_schema(method='post', request_body=openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
'protocol_name': openapi.Schema(type=openapi.TYPE_STRING),
'version_name': openapi.Schema(type=openapi.TYPE_STRING),
'is_extend': openapi.Schema(type=openapi.TYPE_BOOLEAN),
'extend_version_name': openapi.Schema(type=openapi.TYPE_STRING),
}
))
@api_view(['POST'])
def protocol_add_version(request):
"""
协议添加版本
"""
protocol_name = request.data.get('protocol_name')
version_name = request.data.get('version_name')
is_extend = request.data.get('is_extend')
extend_version_name = request.data.get('extend_version_name')
if version_name is None or protocol_name is None:
return Response(status=status.HTTP_400_BAD_REQUEST)
if is_extend:
# 如果是继承版本,则需要判断继承的版本是否存在
if extend_version_name is None:
return Response(status=status.HTTP_400_BAD_REQUEST)
# current_version = CurrentDevVersion.objects.filter(protocol_name=protocol_name).first().version
# if current_version != extend_version_name:
# # 继承的版本和当前的版本不一样,需要将当前版本的指令和字段删除
# cmds = TableDevCmdNamePoll.objects.filter(protocol_name=protocol_name).all()
# for cmd in cmds:
# TableAllDevCmdDefine.objects.filter(cmd_name=cmd.cmd_name).delete()
# cmd.delete()
# # 获取继承版本的字段
# cmds = AllProtocolDefinAndVersion.objects.filter(protocol_name=protocol_name,
# version=extend_version_name).all()
# for cmd in cmds:
# TableDevCmdNamePoll(protocol_name=_cmd.protocol_name,
# cmd_name=_cmd.cmd_name,
# cmd_type=_cmd.cmd_type,
# encode=_cmd.encode,
# timing_cmd_cycle_period=_cmd.timing_cmd_cycle_period,
# cmd_explain=_cmd.cmd_explain).save()
# fields = AllDevCmdDefineAndVersion.objects.filter(cmd_name=cmd.cmd_name,
# version=extend_version_name).all()
# # 新增字段
# for field in fields:
# TableAllDevCmdDefine(cmd_name=_field.cmd_name,
# cmd_type=_field.cmd_type,
# fieldindex=_field.fieldindex,
# fieldname=_field.fieldname,
# fieldsize=_field.fieldsize,
# value=_field.value,
# minvalue=_field.minvalue,
# maxvalue=_field.maxvalue,
# datatype=_field.datatype,
# operation_in=_field.operation_in,
# operation_in_num=_field.operation_in_num,
# operation_out=_field.operation_out,
# operation_out_num=_field.operation_out_num,
# operabo_in=_field.operabo_in,
# operabo_out=_field.operabo_out,
# lua_script_in=_field.lua_script_in,
# lua_script_out=_field.lua_script_out).save()
# 获取继承版本的字段
cmds = AllProtocolDefinAndVersion.objects.filter(protocol_name=protocol_name,
version=extend_version_name).all()
for cmd in cmds:
# 给当前版本的指令和字段创建记录
_cmd = AllProtocolDefinAndVersion(protocol_name=protocol_name,
cmd_name=cmd.cmd_name,
cmd_type=cmd.cmd_type,
encode=cmd.encode,
timing_cmd_cycle_period=cmd.timing_cmd_cycle_period,
cmd_explain=cmd.cmd_explain,
version=version_name)
_cmd.save()
fields = AllDevCmdDefineAndVersion.objects.filter(cmd_name=cmd.cmd_name,
version=extend_version_name).all()
# 新增字段
for field in fields:
_field = AllDevCmdDefineAndVersion(cmd_name=field.cmd_name,
cmd_type=field.cmd_type,
fieldindex=field.fieldindex,
fieldname=field.fieldname,
fieldsize=field.fieldsize,
value=field.value,
minvalue=field.minvalue,
maxvalue=field.maxvalue,
datatype=field.datatype,
operation_in=field.operation_in,
operation_in_num=field.operation_in_num,
operation_out=field.operation_out,
operation_out_num=field.operation_out_num,
operabo_in=field.operabo_in,
operabo_out=field.operabo_out,
lua_script_in=field.lua_script_in,
lua_script_out=field.lua_script_out,
version=version_name)
_field.save()
else:
# 如果不用继承版本,先直接删除两张表上所有的记录
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()
# 添加版本
protoocl_version = AllProtocolVersion.objects.filter(protocol_name=protocol_name).first()
version = json.loads(protoocl_version.version_paths)
version.append({"version": version_name})
protoocl_version.version_paths = json.dumps(version)
protoocl_version.save()
return Response(status=status.HTTP_200_OK)
version: '3'
services:
device_web_dockerfile:
# 通过 dockerfile 创建镜像
# build:
# context: .
# dockerfile: Dockerfile
# 如果使用上面的内容下面 image 就不需要了
image: device_web_dockerfile_compose
container_name: device_web
tty: true
# 容器的网络模式,如果使用 host 模式,就不需要下面 ports 的内容
# ports 的内容是在默认的网络模式 bridge 的情况下设置的
network_mode: host
# ports:
# - "8080:8080"
# 文件映射,会将整个目录全部替换
# volumes:
# - .:/app
environment:
TZ: "Asia/Shanghai"
entrypoint: "python manage.py runserver 0.0.0.0:8080"
# 使用的环境
FROM ubuntu:20.04
# 升级 apt-get 和 下载 python3.9
# DEBIAN_FRONTEND="noninteractive" 禁用交互
RUN apt-get update && DEBIAN_FRONTEND="nointeractive" apt-get install -y \
python3.9 \
python3.9-venv \
python3.9-dev \
python3-pip
# 工作目录为 /app
# 意味着进入容器后的目录为 /app
WORKDIR /app
# 将当前目录下的所有内容拷贝到 /app 目录下
COPY . .
# 使用 python3.9 创建虚拟环境
RUN python3.9 -m venv ./venv
# 将虚拟环境添加到 PATH 中
ENV PATH="/app/venv/bin:$PATH"
# 使用虚拟环境中的 pip3.9 安装 poetry
RUN pip3.9 install poetry -i https://pypi.tuna.tsinghua.edu.cn/simple
# 使用 poetry 下载项目所需要的依赖
# poetry config virtualenvs.create false 为禁用创建虚拟环境
# 即直接将内容下到刚刚创建的虚拟环境中
RUN poetry config virtualenvs.create false && poetry install
# 向外部暴露 8000 端口
EXPOSE 8000
# 启动容器后运行的命令
ENTRYPOINT ["python", "manage.py", "runserver", "0.0.0.0:8000" ]
...@@ -27,8 +27,34 @@ ...@@ -27,8 +27,34 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref } from 'vue' import { onMounted, ref } from 'vue'
const activeIndex = ref('1') const activeIndex = ref('1')
import { DeviceProtocol, ProtocolCmd } from "@/dao/device";
import { GetProtocolVersion, GetCurrentVersion } from '@/dao/protocol';
import { useProtocolInfoStore } from './stores/protocolInfo';
import { useProtocolVersionStore } from '@/stores/allProtocolVersion';
const store = useProtocolVersionStore()
const protocolStore = useProtocolInfoStore()
onMounted(async () => {
await GetProtocolVersion()
.then(res => {
store.protocolVersions.push(...res)
})
await GetCurrentVersion()
.then(res => {
store.currentVersions = res
})
await DeviceProtocol()
.then((res) => {
protocolStore.deviceProtocol = res.data
})
await ProtocolCmd()
.then((res) => {
protocolStore.protocolCmd = res.data
})
})
</script> </script>
<style> <style>
......
<template> <template>
<div class="text-right mb-5"> <div class="text-right mb-5">
<el-button type="primary" @click="applyComunications"> 应用 </el-button> <el-button type="primary" @click="applyComunications"> 应用 </el-button>
<el-button type="primary" @click="copy">copy to ini</el-button> <el-button type="primary" @click="copy">复制配置</el-button>
<el-button type="primary" @click="addDevice">Add device</el-button> <el-button type="primary" @click="addDevice">添加通信参数</el-button>
</div> </div>
<div class="demo-collapse"> <div class="demo-collapse">
<el-collapse> <el-collapse>
......
<template> <template>
<el-descriptions :title="deviceInfo.device_name" :column=1> <el-descriptions :title="deviceInfo.device_name" :column=1>
<template #extra> <template #extra>
<el-button type="danger" size="small" @click="del">delete</el-button> <el-button type="danger" size="small" @click="del">删除</el-button>
<el-button type="primary" size="small" @click="dialogFormVisible = true">Edit</el-button> <el-button type="primary" size="small" @click="dialogFormVisible = true">编辑</el-button>
</template> </template>
<el-descriptions-item label="协议名">{{ deviceInfo.protocol_name }}</el-descriptions-item> <el-descriptions-item label="协议名">{{ deviceInfo.protocol_name }}</el-descriptions-item>
<el-descriptions-item label="通信参数" :column=3> <el-descriptions-item label="通信参数" :column=3>
......
...@@ -62,9 +62,9 @@ ...@@ -62,9 +62,9 @@
</el-form> </el-form>
<template #footer> <template #footer>
<span class="dialog-footer"> <span class="dialog-footer">
<el-button @click="dialogFormVisible = false">Cancel</el-button> <el-button @click="dialogFormVisible = false">取消</el-button>
<el-button type="primary" @click="submit_form"> <el-button type="primary" @click="submit_form">
Confirm 确定
</el-button> </el-button>
</span> </span>
</template> </template>
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
</el-scrollbar> </el-scrollbar>
<div> <div>
<el-button class="ml-4" @click="showCmdDialog">Send Cmd</el-button> <el-button class="ml-4" @click="showCmdDialog">发送指令</el-button>
</div> </div>
</div> </div>
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
:type="activeName==='device'?'1': '2'" :type="activeName==='device'?'1': '2'"
@delete-table="deleteDeviceInfo(param)" /> @delete-table="deleteDeviceInfo(param)" />
</el-scrollbar> </el-scrollbar>
<el-button @click="dialogVisible = true">Add table</el-button> <el-button @click="dialogVisible = true">添加监控设备表</el-button>
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="虚拟设备" name="simulateDevice"> <el-tab-pane label="虚拟设备" name="simulateDevice">
<el-scrollbar style="height: 30rem;" class="mb-10" always> <el-scrollbar style="height: 30rem;" class="mb-10" always>
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
:type="activeName==='device'?'1': '2'" :type="activeName==='device'?'1': '2'"
@delete-table="deleteDeviceInfo(param)" /> @delete-table="deleteDeviceInfo(param)" />
</el-scrollbar> </el-scrollbar>
<el-button @click="dialogVisible = true">Add table</el-button> <el-button @click="dialogVisible = true">添加监控设备表</el-button>
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
</div> </div>
...@@ -54,15 +54,15 @@ ...@@ -54,15 +54,15 @@
</el-select> </el-select>
<template #footer> <template #footer>
<span class="dialog-footer"> <span class="dialog-footer">
<el-button @click="dialogVisible = false">Cancel</el-button> <el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="addDeviceTable"> <el-button type="primary" @click="addDeviceTable">
Confirm 确定
</el-button> </el-button>
</span> </span>
</template> </template>
</el-dialog> </el-dialog>
<el-dialog v-model="dialogCmdVisible" class="w-150" title="Send Cmd"> <el-dialog v-model="dialogCmdVisible" class="w-150" title="发送指令" draggable>
<el-form :model="formData" label-width="120px"> <el-form :model="formData" label-width="120px">
<el-form-item label="设备名称"> <el-form-item label="设备名称">
<el-select v-model="formData.deviceName" w-100 @change="showCmds"> <el-select v-model="formData.deviceName" w-100 @change="showCmds">
...@@ -86,9 +86,9 @@ ...@@ -86,9 +86,9 @@
</el-form> </el-form>
<template #footer> <template #footer>
<span class="dialog-footer"> <span class="dialog-footer">
<el-button @click="dialogCmdVisible = false">Cancel</el-button> <el-button @click="dialogCmdVisible = false">取消</el-button>
<el-button type="primary" @click="sendCmd"> <el-button type="primary" @click="sendCmd">
Confirm 确定
</el-button> </el-button>
</span> </span>
</template> </template>
......
...@@ -3,21 +3,34 @@ ...@@ -3,21 +3,34 @@
<div class="container"> <div class="container">
<div class="left"> <div class="left">
<div class="mr-4">协议版本</div> <div class="mr-4">协议版本</div>
<el-select v-model="currentVersion"> <el-select v-model="currentVersion" @change="changeProtocolVersion">
<!-- TODO: 选择协议版本 -->
<el-option <el-option
v-for="option in options" v-for="option in options"
:key="option.value" :key="option.value"
:label="option.label" :label="option.label"
:value="option.value" :value="option.value"
> >
</el-option> </el-option>
</el-select> </el-select>
</div> </div>
<div class="right"> <div class="right">
<el-button @click="addCmd = true">新增指令</el-button> <el-upload
<el-button>导出协议</el-button> v-if="isUpload"
action="/api/protocol_version_manage/file_upload/"
:show-file-list="false"
:data="{
protocol_name: props.name,
version: currentVersion
}"
:on-success="uploadFileSuccess"
:on-error="uploadFileFail"
mr-4>
<el-button>上传原始文件</el-button>
</el-upload>
<el-button v-else @click="downloadFile"> 下载原始文件 </el-button>
<el-button @click="newVersionDialog = true">新增版本</el-button>
<el-button @click="addCmdDialog = true">新增指令</el-button>
<!-- <el-button @click="deleteProtocol">删除该版本协议</el-button> -->
</div> </div>
</div> </div>
...@@ -25,64 +38,97 @@ ...@@ -25,64 +38,97 @@
<el-collapse class="mt-4"> <el-collapse class="mt-4">
<el-collapse-item <el-collapse-item
v-for="cmd in props.info[props.name]" v-for="cmd in cmdInfos">
:title="cmd.cmd_name + ' ' + cmd.cmd_explain + ' ' + cmd.cmd_type"> <template #title>
<protocol-table <div>{{ cmd.cmd_name + ' ' + cmd.cmd_explain + ' ' + cmd.cmd_type }}</div>
v-if="props.protocolCmd !== undefined" <div>
<el-button type="danger" text @click="removeCmd(cmd.id)">删除</el-button>
</div>
</template>
<protocol-table
v-if="fieldInfos !== undefined"
:cmd-name="cmd.cmd_name" :cmd-name="cmd.cmd_name"
:version="currentVersion"
:protocol-name="props.name"
:cmd-type="cmd.cmd_type" :cmd-type="cmd.cmd_type"
:message="props.protocolCmd[cmd.cmd_name]" /> :message="fieldInfos[cmd.cmd_name]" />
</el-collapse-item> </el-collapse-item>
</el-collapse> </el-collapse>
<el-dialog v-model="addCmd" title="新增指令"> <el-dialog v-model="addCmdDialog" title="新增指令">
<el-form> <el-form :model="addCmdData">
<el-form-item label="协议名称" :label-width="formLabelWidth"> <el-form-item prop="cmd_name" label="指令名称" :label-width="formLabelWidth">
<el-input autocomplete="off" /> <el-input v-model="addCmdData.cmd_name" autocomplete="off" />
</el-form-item>
<el-form-item label="指令名称" :label-width="formLabelWidth">
<el-input autocomplete="off" />
</el-form-item> </el-form-item>
<el-form-item label="指令类型" :label-width="formLabelWidth"> <el-form-item prop="cmd_type" label="指令类型" :label-width="formLabelWidth">
<el-select> <el-select v-model="addCmdData.cmd_type">
<el-option label="TX" value="TX"></el-option> <el-option label="TX" value="TX"></el-option>
<el-option label="RX" value="RX"></el-option> <el-option label="RX" value="RX"></el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="协议类型" :label-width="formLabelWidth"> <el-form-item prop="encode" label="协议类型" :label-width="formLabelWidth">
<el-select> <el-select v-model="addCmdData.encode">
<el-option label="ASCII" value="ASCII"></el-option> <el-option label="ASCII" value="ASCII"></el-option>
<el-option label="HEX" value="HEX"></el-option> <el-option label="HEX" value="HEX"></el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="定时发送" :label-width="formLabelWidth"> <el-form-item prop="timing_cmd_cycle_period" label="定时发送(单位s)" :label-width="formLabelWidth">
<el-input autocomplete="off" /> <el-input v-model="addCmdData.timing_cmd_cycle_period" autocomplete="off" />
</el-form-item> </el-form-item>
<el-form-item label="说明" :label-width="formLabelWidth"> <el-form-item prop="cmd_explain" label="说明" :label-width="formLabelWidth">
<el-input autocomplete="off" /> <el-input v-model="addCmdData.cmd_explain" autocomplete="off" />
</el-form-item> </el-form-item>
</el-form> </el-form>
<template #footer> <template #footer>
<span class="dialog-footer"> <span class="dialog-footer">
<el-button @click="addCmd = false">取消</el-button> <el-button @click="addCmdDialog = false">取消</el-button>
<el-button type="primary" @click="open"> <el-button type="primary" @click="addCmd">
确定 确定
</el-button> </el-button>
</span> </span>
</template> </template>
</el-dialog> </el-dialog>
<el-dialog v-model="newVersionDialog" :width="500" title="新增协议版本">
<el-form :model="newVersionForm">
<el-form-item prop="versionName" label="版本名称" :label-width="formLabelWidth">
<el-input v-model="newVersionForm.versionName" autocomplete="off" />
</el-form-item>
<el-form-item prop="isExtend" label="是否继承版本" :label-width="formLabelWidth">
<el-switch v-model="newVersionForm.isExtend" />
</el-form-item>
<el-form-item v-show="newVersionForm.isExtend" prop="extendVersionName" label="继承版本名称" :label-width="formLabelWidth">
<el-select v-model="newVersionForm.extendVersionName">
<el-option
v-for="option in options"
:label="option.label"
:value="option.value"
>
</el-option>
</el-select>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="newVersionDialog = false">取消</el-button>
<el-button type="primary" @click="addNewVersion"> 确定 </el-button>
</span>
</template>
</el-dialog>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref,onMounted } 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';
import axios from 'axios';
import request from '@/plugins/axios/requests';
const addCmd = ref<boolean>(false) const addCmdDialog = ref<boolean>(false)
const currentVersion = ref('') const currentVersion = ref('')
type OptionType = { type OptionType = {
value: string value: string
...@@ -97,31 +143,6 @@ type propsType = { ...@@ -97,31 +143,6 @@ type propsType = {
protocolCmd: ProtocolCmdResponse protocolCmd: ProtocolCmdResponse
} }
const props = defineProps<propsType>() const props = defineProps<propsType>()
const open = () => {
ElMessageBox.confirm(
'是否确认增加?',
'Warning',
{
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}
)
.then(() => {
ElMessage({
type: 'success',
message: '增加成功',
})
addCmd.value = false
})
.catch(() => {
ElMessage({
type: 'info',
message: '已取消',
})
})
}
function Init(){ function Init(){
ProtocolInit({protocol_name: props.name}) ProtocolInit({protocol_name: props.name})
...@@ -135,14 +156,25 @@ function Init(){ ...@@ -135,14 +156,25 @@ function Init(){
} }
const store = useProtocolVersionStore() const store = useProtocolVersionStore()
onMounted(() => { const cmdInfos = ref()
const fieldInfos = ref<Record<string, any>>({})
const isUpload = ref(true)
// 需要延时一下,不然 store 里面的数据可能没有被赋值上去,组件就被渲染了
onMounted(() => setTimeout(() => {
// 判断是否需要初始化 // 判断是否需要初始化
let flag = true let flag = true
cmdInfos.value = props.info[props.name]
// 将 props.protocolCmd 转成 Record<string, any> 类型, 统一类型,方便后面过来的数据操作
for (const [key, value] of Object.entries(props.protocolCmd)){
fieldInfos.value[key] = value
}
// 对 options 添加协议的版本
let version_paths
for (let protocolVersion of store.protocolVersions){ for (let protocolVersion of store.protocolVersions){
if (protocolVersion.protocol_name === props.name) { if (protocolVersion.protocol_name === props.name) {
let version_paths = JSON.parse(protocolVersion.version_paths) version_paths = JSON.parse(protocolVersion.version_paths)
for (let version_path of version_paths){ for (let version_path of version_paths){
options.value.push({value: version_path.version, label: version_path.version}) options.value.push({value: version_path.version, label: version_path.version})
} }
...@@ -152,10 +184,12 @@ onMounted(() => { ...@@ -152,10 +184,12 @@ onMounted(() => {
} }
} }
// 设置当前协议版本
if (!flag) { if (!flag) {
for (let item of store.currentVersions){ for (let item of store.currentVersions){
if (item.protocol_name === props.name) { if (item.protocol_name === props.name) {
currentVersion.value = item.version currentVersion.value = item.version
break
} }
} }
} }
...@@ -164,7 +198,210 @@ onMounted(() => { ...@@ -164,7 +198,210 @@ onMounted(() => {
if (flag){ if (flag){
Init() Init()
} }
// 更新上传下载按钮
for (let version_path of version_paths) {
if (version_path.version === currentVersion.value) {
if (version_path.path !== undefined) {
isUpload.value = false
} else {
isUpload.value = true
}
}
}
}, 50))
// 修改协议版本
const changeProtocolVersion = () => {
axios.post('/api/protocol_version_manage/change_protocol_version/',
{
version: currentVersion.value,
protocol_name: props.name,
})
.then((res) => {
console.log(res);
const { cmds } = res.data
cmdInfos.value = cmds
// 转成和上面 ProtocolCmdResponse 一样的类型
for (let cmd of cmds) {
const { fields, ...info} = cmd
fieldInfos.value[info.cmd_name] = fields
}
// 修改按钮文件
for (let protocolVersion of store.protocolVersions){
if (protocolVersion.protocol_name === props.name) {
const version_paths = JSON.parse(protocolVersion.version_paths)
for (let version_path of version_paths){
if (version_path.version === currentVersion.value) {
if (version_path.path !== undefined) {
isUpload.value = false
} else {
isUpload.value = true
}
}
}
}
}
})
.catch((err) => {
console.log(err);
})
}
// 文件上传下载相关
const uploadFileSuccess = () => {
isUpload.value = false
ElMessage({
type: 'success',
message: '上传成功',
})
}
const uploadFileFail = () => {
ElMessage({
type: 'error',
message: '上传失败',
})
}
const downloadFile = () => {
let url = `/api/protocol_version_manage/file_download/${props.name}/${currentVersion.value}/`;
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 = decodeURIComponent(res.headers["filename"]);
link.click();
});
console.log("downloadFile");
};
// 删除协议的某个版本
// const deleteProtocol = () => {
// console.log(currentVersion.value, props.name);
// axios.post('/api/protocol_vesrion_manage/delete_protocol_vesrion/',
// {
// version: currentVersion.value,
// protocol_name: props.name,
// })
// .then(() => {
// ElMessage({
// type: 'success',
// message: '删除成功',
// })
// options.value = options.value.filter((item) => item.value !== currentVersion.value)
// currentVersion.value = options.value[0].value
// changeProtocolVersion()
// })
// .catch((err) => {
// console.log(err);
// ElMessage.error('删除失败')
// })
// }
// 新增协议指令
const addCmdData = reactive({
cmd_name: '',
cmd_type: '',
encode: '',
timing_cmd_cycle_period: '',
cmd_explain: '',
}) })
const addCmd = () => {
ElMessageBox.confirm(
'是否确认增加?',
'Warning',
{
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}
)
.then(() => {
addCmdDao({
protocol_name: props.name,
cmd_name: addCmdData.cmd_name,
cmd_type: addCmdData.cmd_type,
encode: addCmdData.encode,
timing_cmd_cycle_period: addCmdData.timing_cmd_cycle_period,
cmd_explain: addCmdData.cmd_explain,
version: currentVersion.value,
})
.then((res) => {
ElMessage({
type: 'success',
message: '操作成功',
})
cmdInfos.value.push(res.data)
})
.catch((error) => {
ElMessage({
type: 'error',
message: error.message,
})
})
addCmdDialog.value = false
})
.catch(() => {
ElMessage({
type: 'info',
message: '已取消',
})
})
}
const removeCmd = (id: number) => {
removeCmdDao(id)
.then(() => {
cmdInfos.value = cmdInfos.value.filter((item: any) => item.id !== id)
})
.catch((err) => {
console.log(err);
})
}
// ===================================================
// 新增协议版本
const newVersionDialog = ref<boolean>(false)
const newVersionForm = reactive({
versionName: '',
isExtend: false,
extendVersionName: '',
})
const addNewVersion = () => {
// 继承版本问题
const body = {
protocol_name: props.name,
version_name: newVersionForm.versionName,
is_extend: newVersionForm.isExtend,
extend_version_name: newVersionForm.extendVersionName,
}
console.log(body);
request.post('/api/protocol/protocol_add_version/', body)
.then((res) => {
newVersionDialog.value = false
console.log(res);
ElMessage({
type: 'success',
message: '操作成功',
})
options.value.push({value: newVersionForm.versionName, label: newVersionForm.versionName})
currentVersion.value = newVersionForm.versionName
changeProtocolVersion()
})
}
</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="danger" 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="protocolCmd !== undefined" v-if="props.protocolCmd !== undefined && props.deviceProtocol !== undefined"
class="mt-4" class="mt-4"
:info="deviceProtocol!" :info="props.deviceProtocol!"
:name="item" :name="item"
:protocol-cmd="protocolCmd!" /> :protocol-cmd="props.protocolCmd!" />
</div> </div>
</el-collapse-item> </el-collapse-item>
</el-collapse> </el-collapse>
...@@ -17,40 +22,37 @@ ...@@ -17,40 +22,37 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted } from 'vue' import { onMounted, ref, watch } from 'vue'
import CollapseTable from "./CollapseTable.vue"; import CollapseTable from "./CollapseTable.vue";
import { DeviceProtocol, ProtocolCmd } from "@/dao/device";
import type { DeviceProtocolResponse, ProtocolCmdResponse } from './types'; import type { DeviceProtocolResponse, ProtocolCmdResponse } from './types';
import { removeProtocolDao } from '@/dao/protocol';
const protocol_names = ref<string[]>([]); type propsType = {
const deviceProtocol = ref<DeviceProtocolResponse>() deviceProtocol: DeviceProtocolResponse,
const protocolCmd = ref<ProtocolCmdResponse>() protocolCmd: ProtocolCmdResponse
function getDeviceProtocol() {
DeviceProtocol()
.then((res) => {
deviceProtocol.value = res
protocol_names.value = res.fields
})
.catch((err) => {
console.log(err)
})
} }
const props = defineProps<propsType>()
onMounted(() => {
let { fields } = props.deviceProtocol
protocolNames.value = fields
})
function getProtocolCmd() { const protocolNames = ref<string[]>([]);
ProtocolCmd() watch(() => props.deviceProtocol, (val) => {
.then((res) => { let { fields } = val
protocolCmd.value = res protocolNames.value = fields
})
const removeProtocol = (protocolName: string) => {
removeProtocolDao(protocolName)
.then(() =>{
protocolNames.value = protocolNames.value.filter(item => item !== protocolName)
}) })
.catch((err) => { .catch(err => {
console.log(err); console.log(err)
}) })
} }
onMounted(async () => {
getDeviceProtocol()
getProtocolCmd()
})
</script> </script>
<style> <style>
......
...@@ -147,7 +147,7 @@ ...@@ -147,7 +147,7 @@
import { reactive, ref } from 'vue' import { reactive, ref } from 'vue'
import { ElMessage, ElMessageBox, FormRules, ElForm } from "element-plus"; import { ElMessage, ElMessageBox, FormRules, ElForm } from "element-plus";
import { AddProtocolCMd, DeleteProtocolCmd, EditProtocolCmd } from "@/dao/device"; import { AddProtocolCmd, DeleteProtocolCmd, EditProtocolCmd } from "@/dao/device";
import type { CmdInfo } from './types'; import type { CmdInfo } from './types';
const flag = ref(false) const flag = ref(false)
...@@ -157,6 +157,8 @@ const more = ref(false) ...@@ -157,6 +157,8 @@ const more = ref(false)
type propsType = { type propsType = {
cmdName: string, cmdName: string,
cmdType: string, cmdType: string,
version: string,
protocolName: string,
message: CmdInfo[] message: CmdInfo[]
} }
const props = defineProps<propsType>() const props = defineProps<propsType>()
...@@ -239,7 +241,6 @@ const addField = () => { ...@@ -239,7 +241,6 @@ const addField = () => {
fields.value.operabo_out = 0 fields.value.operabo_out = 0
dialogVisible.value = true; dialogVisible.value = true;
} }
function editField(data: CmdInfo) { function editField(data: CmdInfo) {
...@@ -251,6 +252,7 @@ function editField(data: CmdInfo) { ...@@ -251,6 +252,7 @@ function editField(data: CmdInfo) {
} }
function Edit(id: number, params: any) { function Edit(id: number, params: any) {
params['protocol_name'] = props.protocolName
EditProtocolCmd(id, params) EditProtocolCmd(id, params)
} }
...@@ -259,7 +261,11 @@ function Delete(id: number) { ...@@ -259,7 +261,11 @@ function Delete(id: number) {
} }
function Add(params: any) { function Add(params: any) {
AddProtocolCMd(params) params['protocol_name'] = props.protocolName
AddProtocolCmd(params)
.then((res) => {
tableData.value.push(res.data!)
})
} }
function confirm(type: string, data: CmdInfo) { function confirm(type: string, data: CmdInfo) {
...@@ -273,10 +279,6 @@ function confirm(type: string, data: CmdInfo) { ...@@ -273,10 +279,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') {
......
...@@ -59,9 +59,14 @@ interface ProtocolCmdResponse { ...@@ -59,9 +59,14 @@ interface ProtocolCmdResponse {
fields: any[]; fields: any[];
} }
interface ChangeCmdInfo extends ProtocolInfo {
version: string
fields: any[]
}
export type { export type {
DeviceProtocolResponse, DeviceProtocolResponse,
ProtocolCmdResponse, ProtocolCmdResponse,
CmdInfo, CmdInfo,
ChangeCmdInfo
} }
\ No newline at end of file
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').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').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/' + 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/' + 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/all_dev_cmd_define/', 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
} }
) )
} }
export function GetCurrentVersion() { export function GetCurrentVersion() {
return axios.get('/api/current_versions/').then( return axios.get('/api/current_versions/').then(
function (response) { function (response) {
return response.data 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) => { ...@@ -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;
......
import { createRouter, createWebHistory } from 'vue-router'; import { createRouter, createWebHashHistory } from 'vue-router';
const router = createRouter({ const router = createRouter({
history: createWebHistory(), history: createWebHashHistory(),
routes: [ routes: [
{ {
path: '/', path: '/',
......
import { defineStore } from 'pinia'
import { ref } from 'vue';
import type { DeviceProtocolResponse, ProtocolCmdResponse } from '@/components/protocol/types';
export const useProtocolInfoStore = defineStore('protocolInfo', () => {
const deviceProtocol = ref<DeviceProtocolResponse>()
const protocolCmd = ref<ProtocolCmdResponse>()
return {
deviceProtocol,
protocolCmd
}
});
<template> <template>
<el-tabs v-model="activeName" type="border-card" class="demo-tabs"> <el-tabs v-model="activeName" type="border-card" class="demo-tabs">
<el-tab-pane label="device" name="device"> <el-tab-pane label="设备通信参数" name="device">
<div class="contain"> <div class="contain">
<communication-tab tab-type="communicate" /> <communication-tab tab-type="communicate" />
</div> </div>
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="simulate_device" name="simulate_device"> <el-tab-pane label="虚拟设备通信参数" name="simulate_device">
<div class="contain"> <div class="contain">
<communication-tab tab-type="simulate_communicate" /> <communication-tab tab-type="simulate_communicate" />
</div> </div>
......
<template> <template>
<div class="button-container"> <div class="button-container">
<el-button class="left-button" @click="isShow = true">新增协议</el-button> <el-button class="ml-10" @click="isShow = true">新增协议</el-button>
<div class="right-buttons"> <!-- <div>
<el-button>导出数据库</el-button> <el-button>导出数据库</el-button>
</div> </div> -->
</div> </div>
<!-- 下拉列表 --> <!-- 折叠面板 -->
<kit-collapse class="mt-4"></kit-collapse> <kit-collapse
class="mt-4"
v-if="protocolStore.deviceProtocol !== undefined && protocolStore.protocolCmd !== undefined"
:device-protocol="protocolStore.deviceProtocol!"
:protocol-cmd="protocolStore.protocolCmd!" />
<el-dialog title="新增协议" v-model="isShow"> <el-dialog title="新增协议" v-model="isShow">
<el-form> <el-form>
<el-form-item label="协议名称" :label-width="formLabelWidth"> <el-form-item label="协议名称" :label-width="formLabelWidth">
<el-input autocomplete="off" /> <el-input v-model="protocolName" autocomplete="off" />
</el-form-item> </el-form-item>
</el-form> </el-form>
<template #footer> <template #footer>
...@@ -27,31 +31,25 @@ ...@@ -27,31 +31,25 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted } from 'vue'; import { ref } from 'vue';
import KitCollapse from "@/components/protocol/KitCollapse"; import KitCollapse from '@/components/protocol/KitCollapse.vue';
import { GetProtocolVersion, GetCurrentVersion } from '@/dao/protocol'; import { useProtocolInfoStore } from '@/stores/protocolInfo';
import { useProtocolVersionStore } from '@/stores/allProtocolVersion'; import { useProtocolVersionStore } from '@/stores/allProtocolVersion';
const isShow = ref<boolean>(false) const isShow = ref<boolean>(false)
const formLabelWidth = '140px' const formLabelWidth = '140px'
const store = useProtocolVersionStore() const protocolStore = useProtocolInfoStore()
onMounted(() => {
GetProtocolVersion()
.then(res => {
store.protocolVersions.push(...res)
})
GetCurrentVersion()
.then(res => {
store.currentVersions = res
})
})
// TODO:添加协议 const protocolName = ref<string>('')
const store = useProtocolVersionStore()
const addProtocol = () => { const addProtocol = () => {
isShow.value = false isShow.value = false
console.log('addProtocol')
protocolStore.deviceProtocol!.fields.push(protocolName.value)
protocolStore.deviceProtocol![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>
...@@ -63,15 +61,5 @@ const addProtocol = () => { ...@@ -63,15 +61,5 @@ const addProtocol = () => {
align-items: center; align-items: center;
/* 垂直居中 */ /* 垂直居中 */
} }
</style>
.left-button {
margin-right: auto;
/* 将按钮1靠左 */
}
.right-buttons {
display: flex;
align-items: center;
/* 垂直居中 */
}</style>
// vite.config.ts
import { defineConfig } from "file:///W:/work/NetCopilot/test/vue_django/frontend/node_modules/vite/dist/node/index.js";
import vue from "file:///W:/work/NetCopilot/test/vue_django/frontend/node_modules/@vitejs/plugin-vue/dist/index.mjs";
import legacy from "file:///W:/work/NetCopilot/test/vue_django/frontend/node_modules/@vitejs/plugin-legacy/dist/index.mjs";
import UnoCSS from "file:///W:/work/NetCopilot/test/vue_django/frontend/node_modules/unocss/dist/vite.mjs";
import { resolve } from "path";
import process from "process";
function pathResolve(dir) {
return resolve(process.cwd(), ".", dir);
}
var vite_config_default = defineConfig({
resolve: {
alias: {
"@": pathResolve("src")
},
extensions: [".ts", ".js", ".vue"]
// 使用路径别名时想要省略的后缀名,可以自己 增减
},
plugins: [
legacy({
targets: ["defaults", "not IE 11"]
}),
vue(),
UnoCSS()
],
base: "./",
server: {
host: "0.0.0.0"
}
});
export {
vite_config_default as default
};
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsidml0ZS5jb25maWcudHMiXSwKICAic291cmNlc0NvbnRlbnQiOiBbImNvbnN0IF9fdml0ZV9pbmplY3RlZF9vcmlnaW5hbF9kaXJuYW1lID0gXCJXOlxcXFx3b3JrXFxcXE5ldENvcGlsb3RcXFxcdGVzdFxcXFx2dWVfZGphbmdvXFxcXGZyb250ZW5kXCI7Y29uc3QgX192aXRlX2luamVjdGVkX29yaWdpbmFsX2ZpbGVuYW1lID0gXCJXOlxcXFx3b3JrXFxcXE5ldENvcGlsb3RcXFxcdGVzdFxcXFx2dWVfZGphbmdvXFxcXGZyb250ZW5kXFxcXHZpdGUuY29uZmlnLnRzXCI7Y29uc3QgX192aXRlX2luamVjdGVkX29yaWdpbmFsX2ltcG9ydF9tZXRhX3VybCA9IFwiZmlsZTovLy9XOi93b3JrL05ldENvcGlsb3QvdGVzdC92dWVfZGphbmdvL2Zyb250ZW5kL3ZpdGUuY29uZmlnLnRzXCI7aW1wb3J0IHsgZGVmaW5lQ29uZmlnIH0gZnJvbSAndml0ZSdcbmltcG9ydCB2dWUgZnJvbSAnQHZpdGVqcy9wbHVnaW4tdnVlJ1xuaW1wb3J0IGxlZ2FjeSBmcm9tICdAdml0ZWpzL3BsdWdpbi1sZWdhY3knXG5pbXBvcnQgVW5vQ1NTIGZyb20gJ3Vub2Nzcy92aXRlJ1xuaW1wb3J0IHsgcmVzb2x2ZSB9IGZyb20gJ3BhdGgnXG5pbXBvcnQgcHJvY2VzcyBmcm9tICdwcm9jZXNzJ1xuXG5mdW5jdGlvbiBwYXRoUmVzb2x2ZShkaXI6IHN0cmluZyk6IHN0cmluZyB7XG4gIHJldHVybiByZXNvbHZlKHByb2Nlc3MuY3dkKCksICcuJywgZGlyKVxufTtcblxuXG4vLyBodHRwczovL3ZpdGVqcy5kZXYvY29uZmlnL1xuZXhwb3J0IGRlZmF1bHQgZGVmaW5lQ29uZmlnKHtcbiAgcmVzb2x2ZToge1xuICAgIGFsaWFzOiB7XG4gICAgICBcIkBcIjogcGF0aFJlc29sdmUoJ3NyYycpXG4gICAgfSxcbiAgICBleHRlbnNpb25zOiBbJy50cycsICcuanMnLCAnLnZ1ZSddIC8vIFx1NEY3Rlx1NzUyOFx1OERFRlx1NUY4NFx1NTIyQlx1NTQwRFx1NjVGNlx1NjBGM1x1ODk4MVx1NzcwMVx1NzU2NVx1NzY4NFx1NTQwRVx1N0YwMFx1NTQwRFx1RkYwQ1x1NTNFRlx1NEVFNVx1ODFFQVx1NURGMSBcdTU4OUVcdTUxQ0ZcbiAgfSxcbiAgcGx1Z2luczogW1xuICAgIGxlZ2FjeSh7XG4gICAgICB0YXJnZXRzOiBbJ2RlZmF1bHRzJywgJ25vdCBJRSAxMSddLFxuICAgIH0pLFxuICAgIHZ1ZSgpLFxuICAgIFVub0NTUygpXG4gIF0sXG4gIGJhc2U6ICAnLi8nLFxuICBzZXJ2ZXI6IHtcbiAgICBob3N0OiAnMC4wLjAuMCcsXG4gIH1cbn0pXG4iXSwKICAibWFwcGluZ3MiOiAiO0FBQStULFNBQVMsb0JBQW9CO0FBQzVWLE9BQU8sU0FBUztBQUNoQixPQUFPLFlBQVk7QUFDbkIsT0FBTyxZQUFZO0FBQ25CLFNBQVMsZUFBZTtBQUN4QixPQUFPLGFBQWE7QUFFcEIsU0FBUyxZQUFZLEtBQXFCO0FBQ3hDLFNBQU8sUUFBUSxRQUFRLElBQUksR0FBRyxLQUFLLEdBQUc7QUFDeEM7QUFJQSxJQUFPLHNCQUFRLGFBQWE7QUFBQSxFQUMxQixTQUFTO0FBQUEsSUFDUCxPQUFPO0FBQUEsTUFDTCxLQUFLLFlBQVksS0FBSztBQUFBLElBQ3hCO0FBQUEsSUFDQSxZQUFZLENBQUMsT0FBTyxPQUFPLE1BQU07QUFBQTtBQUFBLEVBQ25DO0FBQUEsRUFDQSxTQUFTO0FBQUEsSUFDUCxPQUFPO0FBQUEsTUFDTCxTQUFTLENBQUMsWUFBWSxXQUFXO0FBQUEsSUFDbkMsQ0FBQztBQUFBLElBQ0QsSUFBSTtBQUFBLElBQ0osT0FBTztBQUFBLEVBQ1Q7QUFBQSxFQUNBLE1BQU87QUFBQSxFQUNQLFFBQVE7QUFBQSxJQUNOLE1BQU07QUFBQSxFQUNSO0FBQ0YsQ0FBQzsiLAogICJuYW1lcyI6IFtdCn0K
...@@ -9,6 +9,7 @@ from device_data_op.models import TableXproAllDevinfo ...@@ -9,6 +9,7 @@ from device_data_op.models import TableXproAllDevinfo
def on_connect(mqtt_client, userdata, flags, rc): def on_connect(mqtt_client, userdata, flags, rc):
if rc == 0: if rc == 0:
print('Connected successfully') print('Connected successfully')
# TODO: 不能一次性订阅这么多,检测哪个站就订阅哪个站,不然往下27行报错
mqtt_client.subscribe([('/1/0/0/6', 2), mqtt_client.subscribe([('/1/0/0/6', 2),
('/1/1/0/6', 2), ('/1/1/0/6', 2),
('/1/1/1/6', 2)]) ('/1/1/1/6', 2)])
...@@ -31,9 +32,8 @@ def on_message(mqtt_client, userdata, msg): ...@@ -31,9 +32,8 @@ def on_message(mqtt_client, userdata, msg):
def send_message(data: dict, device_name: str): def send_message(data: dict, device_name: str):
""" """
发送 websocket 消息 发送 websocket 消息
TODO: 通过不同的 port 发向不同的 group name
""" """
send_websocket_message(data) send_websocket_message(data)
dev_info = TableXproAllDevinfo.objects.filter(dev_name=device_name).first() dev_info = TableXproAllDevinfo.objects.filter(dev_name=device_name).first()
if "TCP" in dev_info.comunitate_mode.upper(): if "TCP" in dev_info.comunitate_mode.upper():
......
{
"systemParams": "linux-x64-93",
"modulesFolders": [
"node_modules"
],
"flags": [],
"linkedModules": [],
"topLevelPatterns": [],
"lockfileEntries": {},
"files": [],
"artifacts": {}
}
\ No newline at end of file
/*
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;
create table if not exists alarm_attribution
(
id bigserial
primary key,
alarmid bigint null,
alarmlevel varchar(30) null,
alarmdescriptionchn varchar(255) null,
alarmdescriptioneng varchar(255) null,
ismon int null,
updatetime varchar(20) null
);
create table if not exists current_alarm
(
id bigserial
primary key,
alarmid bigint null,
stationid int null,
deviceid int null,
alarmlevel varchar(30) null,
alarmdescriptionchn varchar(255) null,
alarmdescriptioneng varchar(255) null,
reporttime varchar(20) null
);
create table if not exists current_performance
(
id bigserial
primary key,
perid int null,
stationid int null,
deviceid int null,
datacatlog varchar(40) null,
fieldname varchar(40) null,
fieldvalue varchar(40) null,
perdescriptionchn varchar(255) null,
perdescriptioneng varchar(255) null,
updatetime varchar(20) null
);
create table if not exists history_alarm
(
id bigserial
primary key,
alarmid int null,
stationid int null,
deviceid int null,
alarmlevel varchar(30) null,
alarmdescriptionchn varchar(255) null,
alarmdescriptioneng varchar(255) null,
starttime varchar(20) null,
endtime varchar(20) null
);
create table if not exists history_performance
(
id serial
primary key,
suid int not null,
value varchar(100) not null,
time varchar(30) not null
);
create table if not exists log_info
(
id bigserial
primary key,
stationid int null,
deviceid int null,
manipunator varchar(20) null,
loglevel varchar(20) null,
classification varchar(20) null,
loginfochn varchar(500) null,
loginfoeng varchar(500) null,
reporttime varchar(20) null
);
create table if not exists per_attribution
(
id bigserial
primary key,
perid bigint null,
datacatlog varchar(50) null,
fieldname varchar(50) null,
perdescriptionchn varchar(255) null,
perdescriptioneng varchar(255) null,
ismon int null,
isfixed int null,
fieldunit varchar(20) null,
fieldtype varchar(20) null,
operator1 varchar(20) null,
operand1 varchar(20) null,
relation varchar(20) null,
operator2 varchar(20) null,
operand2 varchar(20) null,
alarmlevel varchar(20) null,
alarmdeschn varchar(255) null,
alarmdeseng varchar(255) null,
updatetime varchar(20) null
);
\ No newline at end of file
/*
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;
/*
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;
...@@ -22,6 +22,9 @@ class AllDevCmdDefineAndVersion(models.Model): ...@@ -22,6 +22,9 @@ 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 __hash__(self) -> int:
return super().__hash__()
def __eq__(self, __value: object) -> bool: def __eq__(self, __value: object) -> bool:
if not isinstance(__value, AllDevCmdDefineAndVersion): if not isinstance(__value, AllDevCmdDefineAndVersion):
return False return False
...@@ -66,6 +69,9 @@ class AllProtocolDefinAndVersion(models.Model): ...@@ -66,6 +69,9 @@ 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 __hash__(self) -> int:
return super().__hash__()
def __eq__(self, __value: object) -> bool: def __eq__(self, __value: object) -> bool:
if not isinstance(__value, AllProtocolDefinAndVersion): if not isinstance(__value, AllProtocolDefinAndVersion):
return False return False
...@@ -87,6 +93,10 @@ class AllProtocolDefinAndVersion(models.Model): ...@@ -87,6 +93,10 @@ class AllProtocolDefinAndVersion(models.Model):
class CurrentDevVersion(models.Model): class CurrentDevVersion(models.Model):
protocol_name = models.TextField(primary_key=True) # Field name made lowercase. protocol_name = models.TextField(primary_key=True) # Field name made lowercase.
version = models.TextField() version = models.TextField()
def __hash__(self) -> int:
return super().__hash__()
class Meta: class Meta:
db_table = 'CurrentDevVersion' db_table = 'CurrentDevVersion'
......
...@@ -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)
...@@ -66,19 +66,17 @@ def update_device_protocol_and_cmds(protocol_name: str, version: str) -> Respons ...@@ -66,19 +66,17 @@ def update_device_protocol_and_cmds(protocol_name: str, version: str) -> Respons
CurrentDevVersion.objects.filter(protocol_name=protocol_name).update(version=version) CurrentDevVersion.objects.filter(protocol_name=protocol_name).update(version=version)
# 更新协议版本信息 # 更新协议版本信息
all_protocol = AllProtocolDefinAndVersion.objects.filter(protocol_name=protocol_name).all() current_version_protocols = AllProtocolDefinAndVersion.objects.filter(protocol_name=protocol_name,
current_version_protocols = [protocol for protocol in all_protocol version=version).all()
if version in json.loads(protocol.version)]
cmd_fields = [] cmd_fields = []
for current_version_protocol in current_version_protocols: for current_version_protocol in current_version_protocols:
cmd_name = current_version_protocol.cmd_name cmd_name = current_version_protocol.cmd_name
cmd_fields.extend([item for item in AllDevCmdDefineAndVersion.objects.filter(cmd_name=cmd_name).all() cmd_fields.extend(AllDevCmdDefineAndVersion.objects.filter(cmd_name=cmd_name, version=version).all())
if version in json.loads(item.version)])
current_version_protocol_serializer = AllProtocolDefinAndVersionSerializer(current_version_protocols, many=True) current_version_protocol_serializer = AllProtocolDefinAndVersionSerializer(current_version_protocols, many=True)
cmd_fields_serializer = AllDevCmdDefineAndVersionSerializer(cmd_fields, many=True) cmd_fields_serializer = AllDevCmdDefineAndVersionSerializer(cmd_fields, many=True)
# 更新 device 所使用的命令表数据 # 要先删除这,因为它使用的是 TableDevCmdNamePoll 的旧数据,更新 device 所使用的字段表数据
try: try:
TableAllDevCmdDefine.objects.filter(cmd_name__in=[cmd.cmd_name TableAllDevCmdDefine.objects.filter(cmd_name__in=[cmd.cmd_name
for cmd in TableDevCmdNamePoll.objects.filter(protocol_name=protocol_name).all()]).delete() for cmd in TableDevCmdNamePoll.objects.filter(protocol_name=protocol_name).all()]).delete()
...@@ -88,7 +86,8 @@ def update_device_protocol_and_cmds(protocol_name: str, version: str) -> Respons ...@@ -88,7 +86,8 @@ def update_device_protocol_and_cmds(protocol_name: str, version: str) -> Respons
except Exception as e: except Exception as e:
print(e) print(e)
return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR) return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
# 更新 device 所使用的协议表数据
# 更新 device 所使用的指令表数据
try: try:
TableDevCmdNamePoll.objects.filter(protocol_name=protocol_name).delete() TableDevCmdNamePoll.objects.filter(protocol_name=protocol_name).delete()
TableDevCmdNamePoll.objects.bulk_create([TableDevCmdNamePoll( TableDevCmdNamePoll.objects.bulk_create([TableDevCmdNamePoll(
...@@ -97,11 +96,15 @@ def update_device_protocol_and_cmds(protocol_name: str, version: str) -> Respons ...@@ -97,11 +96,15 @@ def update_device_protocol_and_cmds(protocol_name: str, version: str) -> Respons
except Exception as e: except Exception as e:
print(e) print(e)
return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR) return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
# 返回数据 # 返回数据,需要返回生成之后的数据,特别是 id,因此需要重新请求一次
cmds = [] cmds = []
for protocol in current_version_protocol_serializer.data: new_cmds = TableDevCmdNamePoll.objects.filter(protocol_name=protocol_name).all()
protocol['fields'] = sorted([item for item in cmd_fields_serializer.data new_cmds_serializer = TableDevCmdNamePollSerializer(new_cmds, many=True)
new_cmd_fields = TableAllDevCmdDefine.objects.filter(cmd_name__in=[cmd.cmd_name for cmd in new_cmds]).all()
new_cmd_fields_serializer = TableAllDevCmdDefineSerializer(new_cmd_fields, many=True)
for protocol in new_cmds_serializer.data:
protocol['fields'] = sorted([item for item in new_cmd_fields_serializer.data
if item['cmd_name'] == protocol['cmd_name']], if item['cmd_name'] == protocol['cmd_name']],
key=lambda item: item['fieldindex']) key=lambda item: item['fieldindex'])
cmds.append(protocol) cmds.append(protocol)
......
...@@ -4,7 +4,9 @@ from rest_framework.routers import DefaultRouter ...@@ -4,7 +4,9 @@ from rest_framework.routers import DefaultRouter
from . import views from . import views
router = DefaultRouter() router = DefaultRouter()
router.register(r'current_versions', views.CurrentDevVersionViewSet) router.register('current_versions', views.CurrentDevVersionViewSet)
router.register('protocol_version_manage/cmd_fields_manager',
views.AllDevCmdDefineAndVersionViewSet)
urlpatterns = [ urlpatterns = [
re_path(r'^protocol_version_manage/init/$', views.init), re_path(r'^protocol_version_manage/init/$', views.init),
...@@ -15,6 +17,7 @@ urlpatterns = [ ...@@ -15,6 +17,7 @@ urlpatterns = [
re_path(r'^protocol_version_manage/file_download/(?P<protocol_name>.+)/(?P<version>.+)/$', re_path(r'^protocol_version_manage/file_download/(?P<protocol_name>.+)/(?P<version>.+)/$',
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),
] ]
urlpatterns += router.urls urlpatterns += router.urls
...@@ -8,10 +8,11 @@ from rest_framework.decorators import api_view, parser_classes ...@@ -8,10 +8,11 @@ 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
from rest_framework import status from rest_framework import status
from rest_framework.viewsets import GenericViewSet from rest_framework.viewsets import GenericViewSet, ModelViewSet
from rest_framework.mixins import ListModelMixin from rest_framework.mixins import ListModelMixin
from drf_yasg.utils import swagger_auto_schema from drf_yasg.utils import swagger_auto_schema
from drf_yasg import openapi from drf_yasg import openapi
from device_data_op.models import TableAllDevCmdDefine, TableDevCmdNamePoll
from .models import (AllDevCmdDefineAndVersion, AllProtocolDefinAndVersion, from .models import (AllDevCmdDefineAndVersion, AllProtocolDefinAndVersion,
AllProtocolVersion, CurrentDevVersion) AllProtocolVersion, CurrentDevVersion)
from .serializers import (AllDevCmdDefineAndVersionSerializer, AllProtocolDefinAndVersionSerializer, from .serializers import (AllDevCmdDefineAndVersionSerializer, AllProtocolDefinAndVersionSerializer,
...@@ -134,6 +135,7 @@ def raw_file_upload(request): ...@@ -134,6 +135,7 @@ def raw_file_upload(request):
file_obj = request.FILES.get('file') file_obj = request.FILES.get('file')
protocol_name = request.data.get('protocol_name') protocol_name = request.data.get('protocol_name')
version = request.data.get('version') version = request.data.get('version')
print(version, protocol_name)
if protocol_name is None or version is None: if protocol_name is None or version is None:
return Response(status=status.HTTP_400_BAD_REQUEST) return Response(status=status.HTTP_400_BAD_REQUEST)
...@@ -196,5 +198,83 @@ def raw_file_download(request, protocol_name, version): ...@@ -196,5 +198,83 @@ def raw_file_download(request, protocol_name, version):
class CurrentDevVersionViewSet(GenericViewSet, ListModelMixin): class CurrentDevVersionViewSet(GenericViewSet, ListModelMixin):
"""
获取所有协议当前的版本
"""
"""
获取所有协议当前的版本
"""
queryset = CurrentDevVersion.objects.all() queryset = CurrentDevVersion.objects.all()
serializer_class = CurrentDevVersionSerializer serializer_class = CurrentDevVersionSerializer
@swagger_auto_schema(methods=['POST'], request_body=openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
'protocol_name': openapi.Schema(type=openapi.TYPE_STRING),
'version': openapi.Schema(type=openapi.TYPE_STRING),
}
))
@api_view(['POST'])
def delete_protocol_vesrion(request):
"""
删除特定版本的协议
"""
protocol_name = request.data.get('protocol_name')
version = request.data.get('version')
print(version, protocol_name)
if protocol_name is None or version is None:
return Response(status=status.HTTP_400_BAD_REQUEST)
all_cmds = AllProtocolDefinAndVersion.objects.filter(protocol_name=protocol_name).all()
for cmd in all_cmds:
cmd_vesrions = json.loads(cmd.version)
if len(cmd_vesrions) == 1 and version in cmd_vesrions:
# 这个命令是这个版本独有的
cmd.delete()
elif version in cmd_vesrions:
cmd_vesrions.remove(version)
cmd.version = json.dumps(cmd_vesrions)
cmd.save()
else:
# 这个命令不在这个版本中
continue
all_fields = AllDevCmdDefineAndVersion.objects.filter(cmd_name=cmd.cmd_name).all()
for field in all_fields:
field_versions = json.loads(field.version)
if len(field_versions) == 1 and version in field_versions:
# 这个字段是这个版本独有的
field.delete()
elif version in field_versions:
field_versions.remove(version)
field.version = json.dumps(field_versions)
field.save()
else:
# 这个字段不在这个版本中
continue
protocol_vesrions = AllProtocolVersion.objects.filter(protocol_name=protocol_name).first()
protocol_vesrions_l: list = json.loads(protocol_vesrions.version_paths)
vesrions_l: list = [version_paths['version'] for version_paths in protocol_vesrions_l]
if len(vesrions_l) == 1:
# 这个版本是这个协议独有的
protocol_vesrions.delete()
elif version in vesrions_l:
protocol_vesrions_l.pop(vesrions_l.index(version))
protocol_vesrions.version_paths = json.dumps(protocol_vesrions_l)
protocol_vesrions.save()
return Response(status=status.HTTP_200_OK)
class AllDevCmdDefineAndVersionViewSet(ModelViewSet):
queryset = AllDevCmdDefineAndVersion.objects.all()
serializer_class = AllDevCmdDefineAndVersionSerializer
def perform_create(self, serializer):
serializer.validated_data['version'] = json.dumps([serializer.validated_data['version']])
super().perform_create(serializer)
serializer.validated_data.pop('version')
TableAllDevCmdDefine.objects.create(**serializer.validated_data)
...@@ -44,7 +44,7 @@ INSTALLED_APPS = [ ...@@ -44,7 +44,7 @@ INSTALLED_APPS = [
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'corsheaders', # 'corsheaders',
'rest_framework', 'rest_framework',
'drf_yasg', 'drf_yasg',
] ]
...@@ -88,7 +88,7 @@ WSGI_APPLICATION = 'vue_django.wsgi.application' ...@@ -88,7 +88,7 @@ WSGI_APPLICATION = 'vue_django.wsgi.application'
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'xdc.sqlite', 'NAME': os.path.join(BASE_DIR, 'database', 'xdc.sqlite'),
} }
} }
......
...@@ -34,7 +34,6 @@ schema_view = get_schema_view( ...@@ -34,7 +34,6 @@ schema_view = get_schema_view(
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path("", index),
path("test/upload/", upload), path("test/upload/", upload),
path("test/download/", download), path("test/download/", download),
path("api/mqtt/", include("mqtt.urls")), path("api/mqtt/", include("mqtt.urls")),
...@@ -47,5 +46,6 @@ urlpatterns = [ ...@@ -47,5 +46,6 @@ urlpatterns = [
re_path(r'^assets/(?P<path>.*)/$', serve, {'document_root': settings.STATIC_ROOT}), re_path(r'^assets/(?P<path>.*)/$', serve, {'document_root': settings.STATIC_ROOT}),
re_path(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), re_path(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
re_path(r'^[a-zA-Z]*', index),
] ]
File deleted
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