feat: 添加enp模块
This commit is contained in:
parent
da087ebace
commit
4a7a8f98ae
|
@ -0,0 +1,33 @@
|
|||
# Generated by Django 3.2.12 on 2024-01-10 04:32
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('em', '0009_alter_equipment_description'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='equipment',
|
||||
name='cate',
|
||||
field=models.CharField(blank=True, default='', max_length=20, verbose_name='设备分类'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='equipment',
|
||||
name='coordinates',
|
||||
field=models.JSONField(default=dict, null=True, verbose_name='坐标'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='equipment',
|
||||
name='parameter_json',
|
||||
field=models.JSONField(blank=True, default=dict, verbose_name='技术参数'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='equipment',
|
||||
name='type',
|
||||
field=models.PositiveSmallIntegerField(choices=[(10, '生产设备'), (20, '计量设备'), (30, '治理设备')], default=10, verbose_name='类型'),
|
||||
),
|
||||
]
|
|
@ -27,7 +27,8 @@ class Equipment(CommonBModel):
|
|||
EQUIP_TYPE_MEA = 20
|
||||
type_choices = (
|
||||
(10, '生产设备'),
|
||||
(20, '计量检测工具')
|
||||
(20, '计量设备'),
|
||||
(30, '治理设备'),
|
||||
)
|
||||
# mgmtype_choices = (
|
||||
# (1, 'A'),
|
||||
|
@ -43,10 +44,13 @@ class Equipment(CommonBModel):
|
|||
# (1, '专用'),
|
||||
# (2, '公用'),
|
||||
# )
|
||||
cate_list_10 = ['生产设备', '输送设备']
|
||||
cate_list_20 = ['雾炮', '干雾', '除尘器', '环卫车', '洗车台']
|
||||
mgroup = models.ForeignKey(
|
||||
'mtm.mgroup', on_delete=models.SET_NULL, null=True, blank=True)
|
||||
type = models.PositiveSmallIntegerField(
|
||||
'类型', choices=type_choices, default=10)
|
||||
cate = models.CharField('设备分类', max_length=20, default='', blank=True)
|
||||
name = models.CharField('设备名称', max_length=50)
|
||||
number_factory = models.CharField(
|
||||
'出厂编号', max_length=50, default='', blank=True)
|
||||
|
@ -58,6 +62,7 @@ class Equipment(CommonBModel):
|
|||
state = models.PositiveIntegerField(
|
||||
'设备状态', choices=state_choices, default=EQUIP_STATE_OK)
|
||||
parameter = models.TextField('技术参数', default='', blank=True)
|
||||
parameter_json = models.JSONField('技术参数', default=dict, blank=True)
|
||||
place = models.CharField('安装/存放位置', max_length=50, default='', blank=True)
|
||||
count = models.PositiveIntegerField('数量', default=1)
|
||||
keeper = models.ForeignKey(
|
||||
|
@ -84,6 +89,8 @@ class Equipment(CommonBModel):
|
|||
next_check_date = models.DateField('预计下次校准检查日期', blank=True, null=True)
|
||||
power_kw = models.PositiveSmallIntegerField('功率', null=True, blank=True)
|
||||
|
||||
coordinates = models.JSONField('坐标', default=dict, null=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = '设备信息'
|
||||
verbose_name_plural = verbose_name
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
|
@ -0,0 +1,7 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class EnpConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'apps.enp'
|
||||
verbose_name = '环保管理'
|
|
@ -0,0 +1,52 @@
|
|||
from django.db import models
|
||||
from apps.utils.models import CommonBModel, BaseModel
|
||||
from apps.mtm.models import Mgroup
|
||||
from apps.em.models import Equipment
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class Drain(CommonBModel):
|
||||
DR_TYPE_CHOICES = (
|
||||
(10, '排放口'),
|
||||
(20, '污染源'),
|
||||
)
|
||||
DR_LEVLE_CHOICES = (
|
||||
(10, '主要排放口'),
|
||||
(20, '次要排放口')
|
||||
)
|
||||
|
||||
DR_CATE_MTRAN = 'mtrans'
|
||||
DR_CATE_PRODUCT = 'product'
|
||||
DR_CATE_MSTORE = 'mstore'
|
||||
DR_CATE_CHOICES = (
|
||||
(DR_CATE_PRODUCT, '生产工艺'),
|
||||
(DR_CATE_MTRAN, '物料输送'),
|
||||
(DR_CATE_MSTORE, '物料储存'),
|
||||
)
|
||||
type = models.PositiveSmallIntegerField(
|
||||
'类型', choices=DR_TYPE_CHOICES, help_text=str(DR_TYPE_CHOICES))
|
||||
number = models.CharField('编号', max_length=20)
|
||||
name = models.CharField('名称', max_length=20)
|
||||
level = models.PositiveSmallIntegerField(
|
||||
'排口等级', default=20, choices=DR_LEVLE_CHOICES, help_text=str(DR_LEVLE_CHOICES))
|
||||
cate = models.CharField('分类', max_length=10,
|
||||
choices=DR_CATE_CHOICES, null=True, blank=True)
|
||||
height = models.PositiveSmallIntegerField('排气筒高度', default=0)
|
||||
treatment_capacity = models.CharField('处理量', max_length=20, default='')
|
||||
pm_limit = models.FloatField('PM超低排放限值', default=10, help_text='单位:mg/m³')
|
||||
measure = models.CharField('治理措施', max_length=20, default='')
|
||||
# {"x": 1.0, "y": 2.0, "z": 3.0}
|
||||
coordinates = models.JSONField('坐标', default=dict, null=True)
|
||||
mgroup = models.ForeignKey(
|
||||
Mgroup, verbose_name='所属工段', on_delete=models.CASCADE)
|
||||
|
||||
|
||||
class DrainEquip(BaseModel):
|
||||
"""
|
||||
排口/设备关系表
|
||||
"""
|
||||
drain = models.ForeignKey(
|
||||
Drain, verbose_name='排口', on_delete=models.CASCADE)
|
||||
equipment = models.ForeignKey(
|
||||
Equipment, verbose_name='关联设备', on_delete=models.CASCADE)
|
||||
params_list = models.JSONField('监测参数列表', default=list, null=True)
|
|
@ -0,0 +1,30 @@
|
|||
from apps.utils.serializers import CustomModelSerializer
|
||||
from apps.utils.constants import EXCLUDE_FIELDS_BASE, EXCLUDE_FIELDS_DEPT
|
||||
from .models import Drain, DrainEquip
|
||||
from apps.em.serializers import EquipmentSerializer
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
class DrainSerializer(CustomModelSerializer):
|
||||
"""Serializer for Drain model"""
|
||||
|
||||
class Meta:
|
||||
model = Drain
|
||||
fields = "__all__"
|
||||
read_only_fields = EXCLUDE_FIELDS_DEPT
|
||||
|
||||
def validate(self, attrs):
|
||||
attrs['belong_dept'] = attrs['mgroup'].belong_dept
|
||||
return super().validate(attrs)
|
||||
|
||||
|
||||
class DrainEquipSerializer(CustomModelSerializer):
|
||||
equipment_type = serializers.CharField(
|
||||
source='equipment.type', read_only=True)
|
||||
equipment_name = serializers.CharField(
|
||||
source='equipment.name', read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = DrainEquip
|
||||
fields = "__all__"
|
||||
read_only_fields = EXCLUDE_FIELDS_BASE
|
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
|
@ -0,0 +1,13 @@
|
|||
from django.urls import path, include
|
||||
from rest_framework.routers import DefaultRouter
|
||||
from .views import DrainViewSet, DrainEquipViewSet
|
||||
|
||||
API_BASE_URL = 'api/enp/'
|
||||
HTML_BASE_URL = 'enp/'
|
||||
|
||||
router = DefaultRouter()
|
||||
router.register('drain', DrainViewSet, basename='drain')
|
||||
router.register('drain_equip', DrainEquipViewSet, basename='drain_equip')
|
||||
urlpatterns = [
|
||||
path(API_BASE_URL, include(router.urls)),
|
||||
]
|
|
@ -0,0 +1,30 @@
|
|||
from django.shortcuts import render
|
||||
from apps.utils.viewsets import CustomModelViewSet, GenericViewSet, ListModelMixin
|
||||
from apps.utils.mixins import BulkCreateModelMixin, BulkDestroyModelMixin
|
||||
from .serializers import DrainSerializer, DrainEquipSerializer
|
||||
from .models import Drain, DrainEquip
|
||||
|
||||
# Create your views here.
|
||||
|
||||
|
||||
class DrainViewSet(CustomModelViewSet):
|
||||
"""
|
||||
list: 排口/污染源
|
||||
|
||||
排口/污染源
|
||||
"""
|
||||
queryset = Drain.objects.all()
|
||||
serializer_class = DrainSerializer
|
||||
filterset_fields = ['type', 'cate', 'mgroup']
|
||||
|
||||
|
||||
class DrainEquipViewSet(ListModelMixin, BulkCreateModelMixin, BulkDestroyModelMixin, GenericViewSet):
|
||||
"""
|
||||
list: 排口/设备关系
|
||||
|
||||
排口/设备关系
|
||||
"""
|
||||
perms_map = {'get': '*', 'post:': 'drain.update', 'delete': 'drain.update'}
|
||||
queryset = DrainEquip.objects.all()
|
||||
serializer_class = DrainEquipSerializer
|
||||
filterset_fields = ['drain', 'equipment']
|
|
@ -113,7 +113,8 @@ INSTALLED_APPS = [
|
|||
'apps.inm',
|
||||
'apps.sam',
|
||||
'apps.pum',
|
||||
'apps.pm'
|
||||
'apps.pm',
|
||||
'apps.enp'
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
|
|
@ -65,6 +65,7 @@ urlpatterns = [
|
|||
path('', include('apps.sam.urls')),
|
||||
path('', include('apps.pum.urls')),
|
||||
path('', include('apps.pm.urls')),
|
||||
path('', include('apps.enp.urls')),
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue