资质导入方法已完成
This commit is contained in:
parent
911e548e01
commit
9c999dcba6
|
@ -37,27 +37,35 @@
|
||||||
</el-row>
|
</el-row>
|
||||||
<div style="margin-top:10px">
|
<div style="margin-top:10px">
|
||||||
<el-button type="primary" icon="el-icon-plus" @click="handleAdd" v-if="checkPermission(['qualification_create'])">新增</el-button>
|
<el-button type="primary" icon="el-icon-plus" @click="handleAdd" v-if="checkPermission(['qualification_create'])">新增</el-button>
|
||||||
<!-- <el-popover
|
|
||||||
|
<el-popover
|
||||||
placement="top"
|
placement="top"
|
||||||
width="160"
|
width="160"
|
||||||
v-if="checkPermission(['ability_import'])"
|
v-if="checkPermission(['qualification_import'])"
|
||||||
v-model="popovervisible"
|
v-model="popovervisible"
|
||||||
>
|
>
|
||||||
<p>导入能力列表压缩包.</p>
|
<p>导入资质excel.</p>
|
||||||
<div style="text-align: left; margin: 0;">
|
|
||||||
<el-upload
|
<el-upload
|
||||||
:action="upUrl"
|
:action="upUrl"
|
||||||
:on-success="handleUploadSuccess"
|
:on-success="handleUploadSuccess"
|
||||||
accept=".rar,.zip"
|
accept=".xlsx"
|
||||||
:headers="upHeaders"
|
:headers="upHeaders"
|
||||||
:show-file-list ="false"
|
:show-file-list ="false"
|
||||||
>
|
>
|
||||||
|
<div style="text-align: left; margin: 0;">
|
||||||
|
<el-link
|
||||||
|
href="/media/muban/qualification.xlsx"
|
||||||
|
target="_blank"
|
||||||
|
@click="popovervisible = false"
|
||||||
|
type="primary"
|
||||||
|
>下载模板</el-link>
|
||||||
<el-button size="small" type="primary" @click="popovervisible = false">上传导入</el-button>
|
<el-button size="small" type="primary" @click="popovervisible = false">上传导入</el-button>
|
||||||
</el-upload>
|
|
||||||
</div>
|
</div>
|
||||||
|
</el-upload>
|
||||||
|
|
||||||
|
|
||||||
<el-button slot="reference">导入资质</el-button>
|
<el-button slot="reference">导入资质</el-button>
|
||||||
</el-popover> -->
|
</el-popover>
|
||||||
</div>
|
</div>
|
||||||
<el-table
|
<el-table
|
||||||
v-loading="listLoading"
|
v-loading="listLoading"
|
||||||
|
@ -90,9 +98,9 @@
|
||||||
<span v-html="showlight(scope.row.cnas)"></span>
|
<span v-html="showlight(scope.row.cnas)"></span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="其它资质">
|
<el-table-column label="其它资质" show-overflow-tooltip>
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<span v-html="showlight(scope.row.other)"></span>
|
<span v-html="showlight(scope.row.other)" ></span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="主要服务">
|
<el-table-column label="主要服务">
|
||||||
|
@ -165,7 +173,7 @@
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<script>
|
<script>
|
||||||
import { getQualificationList, getQualificationGroup, createQualification, updateQualification, deleteQualification } from "@/api/qualification";
|
import { getQualificationList, getQualificationGroup, createQualification, updateQualification, deleteQualification, importQualification } from "@/api/qualification";
|
||||||
import checkPermission from "@/utils/permission"
|
import checkPermission from "@/utils/permission"
|
||||||
import { upUrl, upHeaders } from "@/api/file"
|
import { upUrl, upHeaders } from "@/api/file"
|
||||||
import Pagination from "@/components/Pagination" // secondary package based on el-pagination
|
import Pagination from "@/components/Pagination" // secondary package based on el-pagination
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
# Generated by Django 3.0.7 on 2020-10-19 07:31
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
import django.utils.timezone
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('ability', '0010_cma_glzz'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Qualificationother',
|
||||||
|
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='删除标记')),
|
||||||
|
('name', models.TextField(blank=True, null=True, verbose_name='其他资质')),
|
||||||
|
('description', models.TextField(blank=True, null=True, verbose_name='资质范围')),
|
||||||
|
('qualification', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ability.Qualification')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'abstract': False,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
|
@ -42,3 +42,8 @@ class Qualification(BaseModel):
|
||||||
cnas = models.TextField('cnas资质', null=True, blank=True)
|
cnas = models.TextField('cnas资质', null=True, blank=True)
|
||||||
other = models.TextField('检验检测相关其它资质', null=True, blank=True)
|
other = models.TextField('检验检测相关其它资质', null=True, blank=True)
|
||||||
service = models.TextField('主要检验检测服务', null=True, blank=True)
|
service = models.TextField('主要检验检测服务', null=True, blank=True)
|
||||||
|
|
||||||
|
class Qualificationother(BaseModel):
|
||||||
|
qualification = models.ForeignKey(Qualification, on_delete=models.CASCADE, related_name='other_qualification')
|
||||||
|
name = models.TextField('其他资质', null=True, blank=True)
|
||||||
|
description = models.TextField('资质范围', null=True, blank=True)
|
|
@ -17,10 +17,23 @@ class CNASSerializer(serializers.ModelSerializer):
|
||||||
model = CNAS
|
model = CNAS
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
|
class QualificationotherSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Qualificationother
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
class QualificationSerializer(serializers.ModelSerializer):
|
class QualificationSerializer(serializers.ModelSerializer):
|
||||||
"""
|
"""
|
||||||
资质能力序列化
|
资质能力序列化
|
||||||
"""
|
"""
|
||||||
|
otherqualification = QualificationotherSerializer(source='other_qualification', many=True)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def setup_eager_loading(queryset):
|
||||||
|
""" Perform necessary eager loading of data. """
|
||||||
|
queryset = queryset.prefetch_related('other_qualification',)
|
||||||
|
return queryset
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Qualification
|
model = Qualification
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
|
|
|
@ -118,6 +118,7 @@ class CMAViewSet(ModelViewSet):
|
||||||
return Response('不支持非xlsx格式', status = status.HTTP_400_BAD_REQUEST)
|
return Response('不支持非xlsx格式', status = status.HTTP_400_BAD_REQUEST)
|
||||||
return Response(status = status.HTTP_200_OK)
|
return Response(status = status.HTTP_200_OK)
|
||||||
|
|
||||||
|
from django.db.models.query import QuerySet
|
||||||
class QualificationViewSet(ModelViewSet):
|
class QualificationViewSet(ModelViewSet):
|
||||||
"""
|
"""
|
||||||
资质能力:增删改查
|
资质能力:增删改查
|
||||||
|
@ -127,10 +128,24 @@ class QualificationViewSet(ModelViewSet):
|
||||||
queryset = Qualification.objects.all()
|
queryset = Qualification.objects.all()
|
||||||
serializer_class = QualificationSerializer
|
serializer_class = QualificationSerializer
|
||||||
search_fields = ['cma', 'cnas', 'sszx', 'other', 'service']
|
search_fields = ['cma', 'cnas', 'sszx', 'other', 'service']
|
||||||
# ordering_fields = ['sszx']
|
ordering_fields = ['sszx']
|
||||||
ordering = 'sszx'
|
ordering = ['sszx']
|
||||||
filterset_fields = ['sszx']
|
filterset_fields = ['sszx']
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
assert self.queryset is not None, (
|
||||||
|
"'%s' should either include a `queryset` attribute, "
|
||||||
|
"or override the `get_queryset()` method."
|
||||||
|
% self.__class__.__name__
|
||||||
|
)
|
||||||
|
|
||||||
|
queryset = self.queryset
|
||||||
|
if isinstance(queryset, QuerySet):
|
||||||
|
# Ensure queryset is re-evaluated on each request.
|
||||||
|
queryset = queryset.all()
|
||||||
|
if hasattr(self.get_serializer_class(), 'setup_eager_loading'):
|
||||||
|
queryset = self.get_serializer_class().setup_eager_loading(queryset)
|
||||||
|
return queryset
|
||||||
@action(methods=['get'], detail=False,url_name='qualification_group_by', perms_map = {'*':'*'})
|
@action(methods=['get'], detail=False,url_name='qualification_group_by', perms_map = {'*':'*'})
|
||||||
def group(self, request, pk=None):
|
def group(self, request, pk=None):
|
||||||
"""
|
"""
|
||||||
|
@ -146,6 +161,15 @@ class QualificationViewSet(ModelViewSet):
|
||||||
ret.append({'text':i[group_by]+'('+ str(i['count']) +')','value':i[group_by]})
|
ret.append({'text':i[group_by]+'('+ str(i['count']) +')','value':i[group_by]})
|
||||||
return Response(ret)
|
return Response(ret)
|
||||||
|
|
||||||
|
@action(methods=['post'], detail=False, url_path='import', url_name='qualification_import', perms_map = {'post':'qualification_import'})
|
||||||
|
def qualification_import(self, request, pk=None):
|
||||||
|
filepath = request.data['path']
|
||||||
|
fullpath = settings.BASE_DIR + filepath
|
||||||
|
if fullpath.endswith('.xlsx'):
|
||||||
|
import_qualification(fullpath)
|
||||||
|
return Response(status = status.HTTP_200_OK)
|
||||||
|
else:
|
||||||
|
return Response('不支持非xlsx格式', status = status.HTTP_400_BAD_REQUEST)
|
||||||
class CNASViewSet(ModelViewSet):
|
class CNASViewSet(ModelViewSet):
|
||||||
"""
|
"""
|
||||||
CNAS检测能力:增删改查
|
CNAS检测能力:增删改查
|
||||||
|
@ -194,6 +218,34 @@ class CNASViewSet(ModelViewSet):
|
||||||
import_cnas(f.encode('cp437').decode('gbk'), os.path.join(root,f))
|
import_cnas(f.encode('cp437').decode('gbk'), os.path.join(root,f))
|
||||||
return Response(status = status.HTTP_200_OK)
|
return Response(status = status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
|
def import_qualification(path):
|
||||||
|
wb = load_workbook(path)
|
||||||
|
sheet = wb.worksheets[0]
|
||||||
|
i = 3
|
||||||
|
max_row = sheet.max_row
|
||||||
|
while i<max_row+1:
|
||||||
|
sszx = sheet['b'+str(i)].value
|
||||||
|
cma = sheet['c'+str(i)].value
|
||||||
|
cnas = sheet['d'+str(i)].value
|
||||||
|
service = sheet['g'+str(i)].value
|
||||||
|
name = sheet['g'+str(i)].value
|
||||||
|
description = sheet['f'+str(i)].value
|
||||||
|
if sszx:
|
||||||
|
if Qualification.objects.filter(sszx=sszx).exists():
|
||||||
|
qualification = Qualification.objects.get(sszx=sszx)
|
||||||
|
else:
|
||||||
|
qualification = Qualification.objects.create(sszx=sszx)
|
||||||
|
qualification.cma = cma
|
||||||
|
qualification.cnas = cnas
|
||||||
|
qualification.service = service
|
||||||
|
qualification.save()
|
||||||
|
Qualificationother.objects.create(qualification=qualification, name=name, description=description)
|
||||||
|
else:
|
||||||
|
Qualificationother.objects.create(qualification=qualification, name=name, description=description)
|
||||||
|
i = i + 1
|
||||||
|
|
||||||
|
|
||||||
def import_cma(filename, path):
|
def import_cma(filename, path):
|
||||||
wb = load_workbook(path)
|
wb = load_workbook(path)
|
||||||
sheet = wb.worksheets[0]
|
sheet = wb.worksheets[0]
|
||||||
|
@ -214,7 +266,6 @@ def import_cma(filename, path):
|
||||||
data['bz'] = sheet['j'+str(i)].value
|
data['bz'] = sheet['j'+str(i)].value
|
||||||
data['sszx'] = sszx
|
data['sszx'] = sszx
|
||||||
data['type'] = 'center'
|
data['type'] = 'center'
|
||||||
# print(data)
|
|
||||||
datalist.append(CMA(**data))
|
datalist.append(CMA(**data))
|
||||||
i = i + 1
|
i = i + 1
|
||||||
CMA.objects.bulk_create(datalist)
|
CMA.objects.bulk_create(datalist)
|
||||||
|
@ -249,7 +300,6 @@ def import_cnas(filename, path):
|
||||||
data['bzbh'] = sheet['n'+str(i)].value
|
data['bzbh'] = sheet['n'+str(i)].value
|
||||||
data['bztk'] = sheet['p'+str(i)].value
|
data['bztk'] = sheet['p'+str(i)].value
|
||||||
data['sszx'] = sszx
|
data['sszx'] = sszx
|
||||||
# print(data)
|
|
||||||
datalist.append(CNAS(**data))
|
datalist.append(CNAS(**data))
|
||||||
i = i + 1
|
i = i + 1
|
||||||
CNAS.objects.bulk_create(datalist)
|
CNAS.objects.bulk_create(datalist)
|
||||||
|
@ -263,7 +313,6 @@ def import_cma2(filename, path):
|
||||||
CMA.objects.filter(sszx=sszx, type='sub').delete()
|
CMA.objects.filter(sszx=sszx, type='sub').delete()
|
||||||
i = 3
|
i = 3
|
||||||
max_row = sheet.max_row
|
max_row = sheet.max_row
|
||||||
print(max_row)
|
|
||||||
while i<max_row+1:
|
while i<max_row+1:
|
||||||
data = {}
|
data = {}
|
||||||
if sheet['a'+str(i)].value:
|
if sheet['a'+str(i)].value:
|
||||||
|
|
Loading…
Reference in New Issue