Commit d6d919bf by 周田

feat: 对 device 数据库中数据的增删改查

parent 644a48e3
from django.contrib import admin
from .models import (TableAllDevCmdDefine, TableDevCmdNamePoll,
TableSoftLimitAngle, TableXproAllDevinfo)
# Register your models here.
admin.site.register(TableAllDevCmdDefine)
admin.site.register(TableDevCmdNamePoll)
admin.site.register(TableSoftLimitAngle)
admin.site.register(TableXproAllDevinfo)
from django.apps import AppConfig
class DeviceDataOpConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'device_data_op'
# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
# * Rearrange models' order
# * Make sure each model has one field with primary_key=True
# * Make sure each ForeignKey and OneToOneField has `on_delete` set to the desired behavior
# * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or field names.
from django.db import models
class TableAllDevCmdDefine(models.Model):
id = models.AutoField(db_column='ID', primary_key=True) # Field name made lowercase.
cmd_name = models.TextField(db_column='CMD_NAME') # Field name made lowercase.
cmd_type = models.TextField(db_column='CMD_TYPE') # Field name made lowercase.
fieldindex = models.IntegerField(db_column='fieldIndex') # Field name made lowercase.
fieldname = models.TextField(db_column='fieldName') # Field name made lowercase.
fieldsize = models.IntegerField(db_column='fieldSize') # Field name made lowercase.
value = models.TextField()
minvalue = models.TextField(db_column='minValue') # Field name made lowercase.
maxvalue = models.TextField(db_column='maxValue') # Field name made lowercase.
datatype = models.IntegerField(db_column='dataType') # Field name made lowercase.
operation_in = models.IntegerField()
operation_in_num = models.IntegerField()
operation_out = models.IntegerField()
operation_out_num = models.IntegerField()
operabo_in = models.IntegerField(db_column='operaBO_in') # Field name made lowercase.
operabo_out = models.IntegerField(db_column='operaBO_out') # Field name made lowercase.
lua_script_in = models.TextField(db_column='Lua_Script_in') # Field name made lowercase.
lua_script_out = models.TextField(db_column='Lua_Script_out') # Field name made lowercase.
class Meta:
managed = False
db_table = 'Table_ALL_DEV_CMD_DEFINE'
class TableDevCmdNamePoll(models.Model):
id = models.AutoField(db_column='ID', primary_key=True) # Field name made lowercase.
protocol_name = models.TextField(db_column='PROTOCOL_NAME') # Field name made lowercase.
cmd_name = models.TextField(db_column='CMD_NAME') # Field name made lowercase.
cmd_type = models.TextField(db_column='CMD_TYPE') # Field name made lowercase.
encode = models.TextField(db_column='ENCODE') # Field name made lowercase.
timing_cmd_cycle_period = models.IntegerField(db_column='TIMING_CMD_CYCLE_PERIOD') # Field name made lowercase.
cmd_explain = models.TextField(db_column='CMD_EXPLAIN') # Field name made lowercase.
class Meta:
managed = False
db_table = 'Table_DEV_CMD_NAME_POLL'
class TableSoftLimitAngle(models.Model):
id = models.AutoField(db_column='ID', primary_key=True) # Field name made lowercase.
sta_id = models.TextField(db_column='STA_ID') # Field name made lowercase.
dev_name = models.TextField(db_column='DEV_NAME') # Field name made lowercase.
dev_name_chn = models.TextField(db_column='DEV_NAME_CHN') # Field name made lowercase.
protocol_name = models.TextField(db_column='PROTOCOL_NAME') # Field name made lowercase.
pitch_soft_limit_angle = models.TextField(db_column='PITCH_SOFT_LIMIT_ANGLE') # Field name made lowercase.
remarks = models.TextField(db_column='REMARKS', null=True) # Field name made lowercase.
class Meta:
managed = False
db_table = 'Table_SOFT_LIMIT_ANGLE'
class TableXproAllDevinfo(models.Model):
id = models.AutoField(db_column='ID', primary_key=True) # Field name made lowercase.
sta_id = models.TextField(db_column='STA_ID') # Field name made lowercase.
dev_id = models.IntegerField(db_column='DEV_ID') # Field name made lowercase.
dev_name = models.TextField(db_column='DEV_NAME') # Field name made lowercase.
dev_name_chn = models.TextField(db_column='DEV_NAME_CHN') # Field name made lowercase.
protocol_name = models.TextField(db_column='PROTOCOL_NAME') # Field name made lowercase.
cmd_excel_path = models.TextField(db_column='CMD_EXCEL_PATH') # Field name made lowercase.
comunitate_mode = models.TextField(db_column='COMUNITATE_MODE') # Field name made lowercase.
tcp_ip = models.TextField(db_column='TCP_IP') # Field name made lowercase.
tcp_port = models.IntegerField(db_column='TCP_PORT') # Field name made lowercase.
udp_ip_src = models.TextField(db_column='UDP_IP_SRC') # Field name made lowercase.
udp_port_src = models.IntegerField(db_column='UDP_PORT_SRC') # Field name made lowercase.
udp_ip_dst = models.TextField(db_column='UDP_IP_DST') # Field name made lowercase.
udp_port_dst = models.IntegerField(db_column='UDP_PORT_DST') # Field name made lowercase.
udpmc_ip = models.TextField(db_column='UDPMC_IP') # Field name made lowercase.
udpmc_ip_tx = models.TextField(db_column='UDPMC_IP_TX') # Field name made lowercase.
udpmc_port_tx = models.IntegerField(db_column='UDPMC_PORT_TX') # Field name made lowercase.
udpmc_ip_rx = models.TextField(db_column='UDPMC_IP_RX') # Field name made lowercase.
udpmc_port_rx = models.IntegerField(db_column='UDPMC_PORT_RX') # Field name made lowercase.
remarks = models.TextField(db_column='REMARKS') # Field name made lowercase.
class Meta:
managed = False
db_table = 'Table_XPRO_ALL_DEVINFO'
from rest_framework.serializers import ModelSerializer
from rest_framework import serializers
from .models import TableAllDevCmdDefine, TableDevCmdNamePoll, TableSoftLimitAngle, TableXproAllDevinfo
class TableAllDevCmdDefineSerializer(ModelSerializer):
class Meta:
model = TableAllDevCmdDefine
fields = '__all__'
class TableDevCmdNamePollSerializer(ModelSerializer):
class Meta:
model = TableDevCmdNamePoll
fields = '__all__'
class TableSoftLimitAngleSerializer(ModelSerializer):
def validate_remarks(self, value):
"""
当传过来的值为 none 时,则在数据库里存一个空值
@param value: 通过基本校验之后的值
"""
if value == "none":
return ""
return value
class Meta:
model = TableSoftLimitAngle
fields = '__all__'
class TableXproAllDevinfoSerializer(ModelSerializer):
def allow_none(self, value):
"""
当传过来的值为 none 时,则在数据库里存一个空值
@param value: 通过基本校验之后的值
"""
if value == "none":
return ""
return value
def validate(self, attrs: dict):
"""
校验字段,在进行基础校验之后,如果字段名称为下面的字段,
且当传过来的值为 none 时,存一个空值
@param attrs: 通过基本校验之后的值
"""
for field_name, value in attrs.items():
if field_name in (['cmd_excel_path', 'udp_ip_src', 'udp_ip_dst',
'udpmc_ip', 'udpmc_ip_tx', 'udpmc_ip_rx', 'remarks']):
attrs[field_name] = self.allow_none(value)
return attrs
class Meta:
model = TableXproAllDevinfo
fields = '__all__'
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from rest_framework.routers import SimpleRouter
from .views import (TableAllDevCmdDefineView, TableDevCmdNamePollView,
TableSoftLimitAngleView, TableXproAllDevinfoView)
router = SimpleRouter()
router.register(r'all_dev_cmd_define', TableAllDevCmdDefineView)
router.register(r'dev_cmd_name_poll', TableDevCmdNamePollView)
router.register(r'soft_limit_angle', TableSoftLimitAngleView)
router.register(r'xpro_all_devinfo', TableXproAllDevinfoView)
urlpatterns = router.urls
from django.shortcuts import render
from rest_framework.viewsets import ModelViewSet
from .models import (TableAllDevCmdDefine, TableDevCmdNamePoll,
TableSoftLimitAngle, TableXproAllDevinfo)
from .serializers import (TableAllDevCmdDefineSerializer, TableDevCmdNamePollSerializer,
TableSoftLimitAngleSerializer, TableXproAllDevinfoSerializer)
# Create your views here.
class TableAllDevCmdDefineView(ModelViewSet):
queryset = TableAllDevCmdDefine.objects.all()
serializer_class = TableAllDevCmdDefineSerializer
class TableDevCmdNamePollView(ModelViewSet):
queryset = TableDevCmdNamePoll.objects.all()
serializer_class = TableDevCmdNamePollSerializer
class TableSoftLimitAngleView(ModelViewSet):
queryset = TableSoftLimitAngle.objects.all()
serializer_class = TableSoftLimitAngleSerializer
class TableXproAllDevinfoView(ModelViewSet):
queryset = TableXproAllDevinfo.objects.all()
serializer_class = TableXproAllDevinfoSerializer
......@@ -31,8 +31,9 @@ ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'daphne',
'chat',
# 'daphne',
# 'chat',
'device_data_op',
'django.contrib.admin',
'django.contrib.auth',
......@@ -42,6 +43,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'rest_framework',
'drf_yasg',
]
MIDDLEWARE = [
......@@ -83,7 +85,7 @@ WSGI_APPLICATION = 'vue_django.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
'NAME': BASE_DIR / 'xdc.sqlite',
}
}
......
......@@ -14,13 +14,28 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from django.urls import path, include, re_path
from .views import index, test
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
schema_view = get_schema_view(
openapi.Info(
title="My API",
default_version='v1',
description="My API description",
),
public=True,
)
urlpatterns = [
path('admin/', admin.site.urls),
path("", index),
path("test/", test),
path("mqtt/", include("mqtt.urls")),
path("chat/", include("chat.urls")),
# path("test/", test),
# path("mqtt/", include("mqtt.urls")),
# path("chat/", include("chat.urls")),
path("op/", include("device_data_op.urls")),
re_path(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
]
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment