校准能力 part1
This commit is contained in:
parent
e99cab6d03
commit
064e44f6fc
|
@ -0,0 +1,46 @@
|
|||
# Generated by Django 3.0.5 on 2021-07-28 01:02
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('system', '0018_auto_20210430_1156'),
|
||||
('ability', '0022_auto_20210719_1411'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='qualification',
|
||||
name='ssbm',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='qualification_ssbm', to='system.Organization'),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Correct',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('create_time', models.DateTimeField(default=django.utils.timezone.now, help_text='创建时间', verbose_name='创建时间')),
|
||||
('update_time', models.DateTimeField(auto_now=True, help_text='修改时间', verbose_name='修改时间')),
|
||||
('is_deleted', models.BooleanField(default=False, help_text='删除标记', verbose_name='删除标记')),
|
||||
('dlxh', models.TextField(blank=True, null=True, verbose_name='大类序号')),
|
||||
('dlmc', models.TextField(blank=True, null=True, verbose_name='大类')),
|
||||
('lbxh', models.TextField(blank=True, null=True, verbose_name='类别序号')),
|
||||
('lbmc', models.TextField(blank=True, null=True, verbose_name='类别名称')),
|
||||
('bclxh', models.TextField(blank=True, null=True, verbose_name='被测量序号')),
|
||||
('bclmc', models.TextField(blank=True, null=True, verbose_name='被测量名称')),
|
||||
('jzgc', models.TextField(blank=True, null=True, verbose_name='校准规程')),
|
||||
('clfw', models.TextField(blank=True, null=True, verbose_name='测量范围')),
|
||||
('zqddj', models.TextField(blank=True, null=True, verbose_name='准确度等级')),
|
||||
('note', models.TextField(blank=True, null=True, verbose_name='说明')),
|
||||
('ssgs', models.TextField(blank=True, null=True, verbose_name='所属公司')),
|
||||
('ssbm', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='correct_ssbm', to='system.Organization')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': '校验能力',
|
||||
'verbose_name_plural': '校验能力',
|
||||
},
|
||||
),
|
||||
]
|
|
@ -39,6 +39,23 @@ class QueryRecord(BaseModel):
|
|||
verbose_name = '查询记录'
|
||||
verbose_name_plural = verbose_name
|
||||
|
||||
class Correct(BaseModel):
|
||||
dlxh = models.TextField('大类序号', null=True,blank=True)
|
||||
dlmc = models.TextField('大类', null=True,blank=True)
|
||||
lbxh = models.TextField('类别序号', null=True,blank=True)
|
||||
lbmc = models.TextField('类别名称', null=True,blank=True)
|
||||
bclxh = models.TextField('被测量序号', null=True,blank=True)
|
||||
bclmc = models.TextField('被测量名称', null=True,blank=True)
|
||||
jzgc = models.TextField('校准规程', null=True, blank=True)
|
||||
clfw = models.TextField('测量范围', null=True, blank=True)
|
||||
zqddj = models.TextField('准确度等级', null=True, blank=True)
|
||||
note = models.TextField('说明', null=True, blank=True)
|
||||
ssgs = models.TextField('所属公司', null=True, blank=True)
|
||||
ssbm = models.ForeignKey(Organization, on_delete=models.CASCADE, null=True, blank=True, related_name='correct_ssbm')
|
||||
|
||||
class Meta:
|
||||
verbose_name='校验能力'
|
||||
verbose_name_plural=verbose_name
|
||||
|
||||
class CMA(BaseModel):
|
||||
"""
|
||||
|
@ -92,7 +109,7 @@ class CNAS(BaseModel):
|
|||
|
||||
class Qualification(BaseModel):
|
||||
sszx = models.TextField('所属中心', null=True, blank=True)
|
||||
ssbm = models.ForeignKey(Organization, on_delete=models.CASCADE, null=True, blank=True, related_name='system_ssbm')
|
||||
ssbm = models.ForeignKey(Organization, on_delete=models.CASCADE, null=True, blank=True, related_name='qualification_ssbm')
|
||||
cma = models.TextField('cma资质', null=True, blank=True)
|
||||
cnas = models.TextField('cnas资质', null=True, blank=True)
|
||||
other = models.TextField('检验检测相关其它资质', null=True, blank=True)
|
||||
|
|
|
@ -66,4 +66,18 @@ class QualificationotherSerializer(serializers.ModelSerializer):
|
|||
def setup_eager_loading(queryset):
|
||||
""" Perform necessary eager loading of data. """
|
||||
queryset = queryset.select_related('qualification')
|
||||
return queryset
|
||||
|
||||
class CorrectSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
校验能力序列化
|
||||
"""
|
||||
bm_ =OrganizationSerializer(source = 'ssbm', read_only=True)
|
||||
class Meta:
|
||||
model = Correct
|
||||
fields = '__all__'
|
||||
@staticmethod
|
||||
def setup_eager_loading(queryset):
|
||||
""" Perform necessary eager loading of data. """
|
||||
queryset = queryset.select_related('ssbm')
|
||||
return queryset
|
|
@ -1,6 +1,7 @@
|
|||
from django.db.models import base
|
||||
from django.urls import path, include
|
||||
from rest_framework import routers
|
||||
from .views import CMAViewSet, CNASViewSet, QualificationViewSet,InspectionViewSet,QualificationotherViewSet, QueryRecordListViewSet, correct_ability, merge_cma, merge_cnas
|
||||
from .views import CMAViewSet, CNASViewSet, CorrectViewSet, QualificationViewSet,InspectionViewSet,QualificationotherViewSet, QueryRecordListViewSet, correct_ability, merge_cma, merge_cnas
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register('cma', CMAViewSet, basename="cma")
|
||||
|
@ -9,9 +10,10 @@ router.register('qualification', QualificationViewSet, basename="qualification")
|
|||
router.register('qualificationother', QualificationotherViewSet, basename="qualificationother")
|
||||
router.register('inspection', InspectionViewSet, basename="inspection")
|
||||
router.register('queryrecord', QueryRecordListViewSet, basename="queryrecord")
|
||||
router.register('correct', CorrectViewSet, basename="correct")
|
||||
urlpatterns = [
|
||||
path('merge/cma/', merge_cma),
|
||||
path('merge/cnas/', merge_cnas),
|
||||
path('correct/', correct_ability),
|
||||
# path('correct/', correct_ability),
|
||||
path('', include(router.urls))
|
||||
]
|
|
@ -27,8 +27,7 @@ class RecordMixin():
|
|||
will instead be performed lazily, the first time either
|
||||
`request.user` or `request.auth` is accessed.
|
||||
"""
|
||||
user = request.user
|
||||
if request.method == 'GET' and user.username != 'admin':
|
||||
if request.user and request.method == 'GET' and request.user.username != 'admin':
|
||||
QueryRecord.objects.create(user=user,path=request.path,ip=request.META.get('HTTP_X_FORWARDED_FOR'),method=\
|
||||
request.method,search=request.query_params.get('search',None),query=request.query_params)
|
||||
|
||||
|
@ -365,6 +364,56 @@ class CNASViewSet(RecordMixin, ModelViewSet):
|
|||
return Response(status = status.HTTP_200_OK)
|
||||
|
||||
|
||||
class CorrectViewSet(RecordMixin, ModelViewSet):
|
||||
"""
|
||||
校验能力:增删改查
|
||||
"""
|
||||
perms_map = {'get': 'correct_view', 'post': 'correct_create',
|
||||
'put': 'correct_update', 'delete': 'correct_delete'}
|
||||
queryset = Correct.objects.all()
|
||||
serializer_class = CorrectSerializer
|
||||
search_fields = ['dlmc', 'lbmc', 'bclmc','jzgc']
|
||||
ordering_fields = ['dlmc']
|
||||
ordering = ['create_time', 'dlmc']
|
||||
filterset_fields = ['ssbm']
|
||||
@action(methods=['get'], detail=False, perms_map = {'*':'*'})
|
||||
def group(self, request, pk=None):
|
||||
"""
|
||||
聚合查询列
|
||||
"""
|
||||
queryset = self.filter_queryset(self.get_queryset())
|
||||
ret = []
|
||||
if request.query_params.get('group_by', None):
|
||||
group_by = request.query_params.get('group_by')
|
||||
group_by_data = list(queryset.values(group_by).annotate(count=Count(group_by)).order_by(group_by))
|
||||
for i in group_by_data:
|
||||
if i[group_by] and i['count']:
|
||||
ret.append({'text':i[group_by]+'('+ str(i['count']) +')','value':i[group_by]})
|
||||
return Response(ret)
|
||||
|
||||
@action(methods=['post'], detail=False)
|
||||
def correct_import(self, request, pk=None):
|
||||
"""
|
||||
导入校验能力
|
||||
"""
|
||||
filepath = request.data['path']
|
||||
fullpath = settings.BASE_DIR + filepath
|
||||
import os
|
||||
if fullpath.endswith('.zip'):
|
||||
fulldir = fullpath.replace('.zip','')
|
||||
os.mkdir(fulldir)
|
||||
os.chdir(fulldir)
|
||||
# CMA.objects.filter(type='sub').delete()
|
||||
with zipfile.ZipFile(fullpath,'r') as zzz:
|
||||
zzz.extractall(fulldir)
|
||||
for root, dirs, files in os.walk(fulldir):
|
||||
for f in files:
|
||||
if f.endswith('.xlsx'):
|
||||
import_inspection(f.encode('cp437').decode('gbk'), os.path.join(root,f))
|
||||
else:
|
||||
return Response('不支持非xlsx格式', status = status.HTTP_400_BAD_REQUEST)
|
||||
return Response(status = status.HTTP_200_OK)
|
||||
|
||||
def import_qualification(path):
|
||||
wb = load_workbook(path)
|
||||
sheet = wb.worksheets[0]
|
||||
|
@ -596,6 +645,9 @@ def import_inspection(filename, path):
|
|||
i = i + 1
|
||||
Inspection.objects.bulk_create(datalist)
|
||||
|
||||
def import_correct(filename, path):
|
||||
pass
|
||||
|
||||
from django.db.models.functions import Cast
|
||||
def merge_cnas(request):
|
||||
for i in CNAS.objects.all():
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
from .settings import *
|
||||
DEBUG = True
|
||||
DATABASES = {
|
||||
# 'default': {
|
||||
# 'ENGINE': 'django.db.backends.postgresql',
|
||||
# 'NAME': 'cma',
|
||||
# 'USER': 'postgres',
|
||||
# 'PASSWORD': 'zctest1234',
|
||||
# 'HOST': '47.95.0.242',
|
||||
# 'PORT': '5432',
|
||||
# }
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql',
|
||||
'NAME': 'cma',
|
||||
'USER': 'cma',
|
||||
'PASSWORD': 'cma123',
|
||||
'HOST': '172.16.80.102',
|
||||
'USER': 'postgres',
|
||||
'PASSWORD': 'zctest1234',
|
||||
'HOST': '47.95.0.242',
|
||||
'PORT': '5432',
|
||||
}
|
||||
# 'default': {
|
||||
# 'ENGINE': 'django.db.backends.postgresql',
|
||||
# 'NAME': 'cma',
|
||||
# 'USER': 'cma',
|
||||
# 'PASSWORD': 'cma123',
|
||||
# 'HOST': '172.16.80.102',
|
||||
# 'PORT': '5432',
|
||||
# }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue