检验资质

This commit is contained in:
shilixia 2020-10-28 09:38:47 +08:00
parent f6ea77f58b
commit 4905729e07
8 changed files with 109 additions and 89 deletions

View File

@ -9,7 +9,7 @@ export function getQualificationList(query) {
} }
export function getQualificationGroup(query) { export function getQualificationGroup(query) {
return request({ return request({
url: '/ability/qualification/group/', url: '/system/organization/group/',
method: 'get', method: 'get',
params: query params: query
}) })

View File

@ -2,9 +2,9 @@
<div class="app-container"> <div class="app-container">
<el-row :gutter="6"> <el-row :gutter="6">
<el-col :xs="24" :md="4"> <el-col :xs="24" :md="4">
<el-select v-model="listQuery.qualification__sszx" placeholder="所属单位" @change="handleFilter2" clearable style="width: 100%;"> <el-select v-model="listQuery.qualification__ssbm__name" placeholder="所属单位" @change="handleFilter2" clearable style="width: 100%;">
<el-option <el-option
v-for="item in groupBy.sszx" v-for="item in groupBy.name"
:key="item.value" :key="item.value"
:label="item.text" :label="item.text"
:value="item.value"> :value="item.value">
@ -71,14 +71,14 @@
</div> </div>
<el-table <el-table
v-loading="listLoading" v-loading="listLoading"
:data="tableData.results" :data="tableData"
:span-method="objectSpanMethod" :span-method="objectSpanMethod"
style="width: 100%;margin-top:10px;" style="width: 100%;margin-top:10px;"
border border
fit fit
stripe stripe
highlight-current-row highlight-current-row
height="600" height="650"
ref="filterTable" ref="filterTable"
@selection-change="handleSelectionChange" @selection-change="handleSelectionChange"
@filter-change="filterChange" @filter-change="filterChange"
@ -88,76 +88,43 @@
type="selection" type="selection"
width="55"> width="55">
</el-table-column> </el-table-column>
<el-table-column label="所属单位" <el-table-column align="center" label="所属单位"
prop="sszx"
column-key="sszx"
:filters="groupBy.sszx"
:filter-multiple="false"
> >
<template slot-scope="scope">{{ scope.row.qualification_.sszx }}</template> <template style="text-align:left;" slot-scope="scope">{{ scope.row.qualification_.bm_.name }}</template>
</el-table-column> </el-table-column>
<el-table-column label="CMA资质"> <el-table-column header-align="center" label="CMA资质">
<template slot-scope="scope"> <template style="text-align:left;" slot-scope="scope">
<span v-html="showlight(scope.row.qualification_.cma)"></span> <span style="margin-top:0px" v-html="showlight(scope.row.qualification_.cma)"></span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="CNAS资质"> <el-table-column header-align="center" label="CNAS资质">
<template slot-scope="scope"> <template style="text-align:left;" slot-scope="scope">
<span v-html="showlight(scope.row.qualification_.cnas)"></span> <span v-html="showlight(scope.row.qualification_.cnas)"></span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="检验检测相关其他资质及校准资质"> <el-table-column width="800" header-align="center" label="检验检测相关其他资质及校准资质">
<el-table-column label="其它资质" > <el-table-column width="300" header-align="center" label="其它资质" >
<template slot-scope="scope"> <template style="text-align:left;" slot-scope="scope">
<span v-html="showlight(scope.row.name)" ></span> <span v-html="showlight(scope.row.name)" ></span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="资质范围" > <el-table-column width="500" header-align="center" label="资质范围" >
<template slot-scope="scope"> <template style="text-align:left;" slot-scope="scope">
<span v-html="showlight(scope.row.description)" ></span> <span v-html="showlight(scope.row.description)" ></span>
</template> </template>
</el-table-column> </el-table-column>
</el-table-column> </el-table-column>
<el-table-column label="主要服务"> <el-table-column header-align="center" label="主要服务">
<template slot-scope="scope"> <template style="text-align:left;" slot-scope="scope">
<span v-html="showlight(scope.row.qualification_.service)"></span> <span v-html="showlight(scope.row.qualification_.service)"></span>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<pagination
v-show="tableData.count>0"
:total="tableData.count"
:page.sync="listQuery.page"
:limit.sync="listQuery.page_size"
@pagination="getList"
/>
<el-dialog :visible.sync="dialogVisible" :title="dialogType==='edit'?'编辑':'新增'">
<el-form ref="Form" :model="formData" label-width="100px" label-position="right" :rules="rule1">
<el-form-item label="所属单位" prop="sszx">
<el-input v-model="formData.sszx" placeholder="所属单位" />
</el-form-item>
<el-form-item label="CMA资质" prop="cma">
<el-input v-model="formData.cma" placeholder="CMA资质" type="textarea" :autosize="{ minRows: 2, maxRows: 4}"/>
</el-form-item>
<el-form-item label="CNAS资质" prop="cnas">
<el-input v-model="formData.cnas" placeholder="CNAS资质" type="textarea" :autosize="{ minRows: 2, maxRows: 4}"/>
</el-form-item>
<el-form-item label="其它资质" prop="other">
<el-input v-model="formData.other" placeholder="其它资质" type="textarea" :autosize="{ minRows: 2, maxRows: 4}"/>
</el-form-item>
<el-form-item label="主要服务" prop="service">
<el-input v-model="formData.service" placeholder="主要服务" type="textarea" :autosize="{ minRows: 2, maxRows: 4}"/>
</el-form-item>
</el-form>
<div style="text-align:right;">
<el-button type="danger" @click="dialogVisible=false">取消</el-button>
<el-button type="primary" @click="confirm('Form')">确认</el-button>
</div>
</el-dialog>
</div> </div>
</template> </template>
<style > <style >
@ -184,32 +151,24 @@ const defaultCMA = {
}; };
const dflistQuery = { const dflistQuery = {
page: 1, pageoff:true,
page_size: 20,
search:'' search:''
} }
export default { export default {
components: { Pagination }, components: { },
data() { data() {
return { return {
formData: {
id: null,
cma:null,
cnas:null,
other:null,
service:null
},
delarr:[], delarr:[],
upHeaders: upHeaders(), upHeaders: upHeaders(),
upUrl: upUrl(), upUrl: upUrl(),
groupBy:{sszx:[]}, groupBy:{name:[]},
tableData: {count:0}, tableData: [],
rowIndex: '-1', rowIndex: '-1',
OrderIndexArr: [], OrderIndexArr: [],
hoverOrderArr: [], hoverOrderArr: [],
listLoading: true, listLoading: true,
listQuery: Object.assign({}, dflistQuery), listQuery: dflistQuery,
enabledOptions: [ enabledOptions: [
{ key: "true", display_name: "激活" }, { key: "true", display_name: "激活" },
{ key: "false", display_name: "禁用" } { key: "false", display_name: "禁用" }
@ -277,7 +236,7 @@ delarr:[],
let OrderObj = {} let OrderObj = {}
this.tableData.results.forEach((element, index) => { this.tableData.forEach((element, index) => {
element.rowIndex = index element.rowIndex = index
if (OrderObj[element.qualification_.id]) { if (OrderObj[element.qualification_.id]) {
OrderObj[element.qualification_.id].push(index) OrderObj[element.qualification_.id].push(index)
@ -360,6 +319,7 @@ delarr:[],
data.group_by = key data.group_by = key
getQualificationGroup(data).then(response => { getQualificationGroup(data).then(response => {
this.groupBy[key] = response.data this.groupBy[key] = response.data
console.log(response.data)
}) })
} }
}, },
@ -369,12 +329,10 @@ delarr:[],
this.getGroup() this.getGroup()
}, },
handleFilter() { handleFilter() {
this.listQuery.page = 1
this.getList() this.getList()
this.getGroup() this.getGroup()
}, },
handleFilter2() { handleFilter2() {
this.listQuery.page = 1
this.getList() this.getList()
}, },
handleAdd() { handleAdd() {
@ -414,7 +372,7 @@ delarr:[],
for(let key in obj){ for(let key in obj){
this.listQuery[key] = obj[key][0] this.listQuery[key] = obj[key][0]
} }
this.listQuery.page=1
this.getList() this.getList()
}, },
async confirm(form) { async confirm(form) {

View File

@ -0,0 +1,20 @@
# Generated by Django 3.0.5 on 2020-10-27 08:24
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('system', '0005_organization_sort'),
('ability', '0015_remove_inspection_type'),
]
operations = [
migrations.AddField(
model_name='qualification',
name='ssbm',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='system_ssbm', to='system.Organization'),
),
]

View File

@ -1,5 +1,7 @@
from django.db import models from django.db import models
from utils.model import BaseModel from utils.model import BaseModel
from apps.system.models import Organization
# Create your models here. # Create your models here.
class CMA(BaseModel): class CMA(BaseModel):
@ -54,6 +56,7 @@ class CNAS(BaseModel):
class Qualification(BaseModel): class Qualification(BaseModel):
sszx = models.TextField('所属中心', null=True, blank=True) sszx = models.TextField('所属中心', null=True, blank=True)
ssbm = models.ForeignKey(Organization, on_delete=models.CASCADE, null=True, blank=True, related_name='system_ssbm')
cma = models.TextField('cma资质', null=True, blank=True) cma = models.TextField('cma资质', null=True, blank=True)
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)

View File

@ -1,5 +1,7 @@
from rest_framework import serializers from rest_framework import serializers
from .models import * from .models import *
from apps.system.serializers import OrganizationSerializer
class CMASerializer(serializers.ModelSerializer): class CMASerializer(serializers.ModelSerializer):
""" """
@ -28,10 +30,15 @@ class QualificationSerializer(serializers.ModelSerializer):
""" """
资质能力序列化 资质能力序列化
""" """
bm_=OrganizationSerializer(source = 'ssbm', read_only=True)
class Meta: class Meta:
model = Qualification model = Qualification
fields = '__all__' fields = '__all__'
@staticmethod
def setup_eager_loading(queryset):
""" Perform necessary eager loading of data. """
queryset = queryset.select_related('ssbm')
return queryset
class QualificationotherSerializer(serializers.ModelSerializer): class QualificationotherSerializer(serializers.ModelSerializer):
qualification_ = QualificationSerializer(source = 'qualification', read_only=True) qualification_ = QualificationSerializer(source = 'qualification', read_only=True)

View File

@ -8,8 +8,10 @@ from rest_framework import status
from rest_framework.response import Response from rest_framework.response import Response
import zipfile import zipfile
import rarfile import rarfile
from apps.system.models import Organization
from openpyxl import Workbook, load_workbook from openpyxl import Workbook, load_workbook
from django.db.models import Count from django.db.models import Count
from utils.pagination import PageOrNot
# Create your views here. # Create your views here.
class CMAViewSet(ModelViewSet): class CMAViewSet(ModelViewSet):
""" """
@ -170,7 +172,7 @@ class QualificationViewSet(ModelViewSet):
return Response(status = status.HTTP_200_OK) return Response(status = status.HTTP_200_OK)
else: else:
return Response('不支持非xlsx格式', status = status.HTTP_400_BAD_REQUEST) return Response('不支持非xlsx格式', status = status.HTTP_400_BAD_REQUEST)
class QualificationotherViewSet(ModelViewSet): class QualificationotherViewSet(PageOrNot,ModelViewSet):
""" """
资质能力增删改查 资质能力增删改查
""" """
@ -178,9 +180,10 @@ class QualificationotherViewSet(ModelViewSet):
'put': 'qualificationother_update', 'delete': 'qualificationother_delete'} 'put': 'qualificationother_update', 'delete': 'qualificationother_delete'}
queryset = Qualificationother.objects.all() queryset = Qualificationother.objects.all()
serializer_class = QualificationotherSerializer serializer_class = QualificationotherSerializer
search_fields = ['qualification__cma', 'name','description','qualification__cnas', 'qualification__sszx', 'qualification__service'] search_fields = ['qualification__cma', 'name','description','qualification__cnas', 'qualification__ssbm__name', 'qualification__service']
filterset_fields = ['qualification__sszx'] filterset_fields = ['qualification__ssbm__name']
ordering = ['qualification__sszx'] ordering_fields = ['qualification__ssbm__name']
ordering = ['qualification__ssbm__name']
@action(methods=['post'], detail=False, url_path='deletes', url_name='qualificationother_deletes', perms_map = {'post':'qualificationother_deletes'}) @action(methods=['post'], detail=False, url_path='deletes', url_name='qualificationother_deletes', perms_map = {'post':'qualificationother_deletes'})
def deletes(self, request): def deletes(self, request):
@ -315,6 +318,7 @@ def import_qualification(path):
max_row = sheet.max_row max_row = sheet.max_row
obj = {} obj = {}
Qualificationother.objects.all().delete() Qualificationother.objects.all().delete()
Qualification.objects.all().delete()
while i<max_row+1: while i<max_row+1:
sszx = sheet['b'+str(i)].value sszx = sheet['b'+str(i)].value
cma = sheet['c'+str(i)].value cma = sheet['c'+str(i)].value
@ -323,16 +327,20 @@ def import_qualification(path):
name = sheet['e'+str(i)].value name = sheet['e'+str(i)].value
description = sheet['f'+str(i)].value description = sheet['f'+str(i)].value
if sszx: if sszx:
if Qualification.objects.filter(sszx=sszx).exists(): if Organization.objects.filter(name=sszx).exists():
qualification = Qualification.objects.get(sszx=sszx) ssbm=Organization.objects.get(name=sszx)
else: if Qualification.objects.filter(ssbm=ssbm).exists():
qualification = Qualification.objects.create(sszx=sszx) qualification = Qualification.objects.get(ssbm=ssbm)
qualification.cma = cma Qualificationother.objects.create(qualification=qualification, name=name, description=description)
qualification.cnas = cnas else:
qualification.service = service qualification = Qualification.objects.create(ssbm=ssbm)
qualification.save() qualification.cma = cma
obj = qualification qualification.cnas = cnas
Qualificationother.objects.create(qualification=qualification, name=name, description=description) qualification.service = service
qualification.save()
obj = qualification
Qualificationother.objects.create(qualification=qualification, name=name, description=description)
else: else:
Qualificationother.objects.create(qualification=obj, name=name, description=description) Qualificationother.objects.create(qualification=obj, name=name, description=description)
i = i + 1 i = i + 1

View File

@ -19,6 +19,7 @@ from rest_framework.views import APIView
from rest_framework.viewsets import GenericViewSet, ModelViewSet from rest_framework.viewsets import GenericViewSet, ModelViewSet
from rest_framework_simplejwt.tokens import RefreshToken from rest_framework_simplejwt.tokens import RefreshToken
from utils.queryset import get_child_queryset2 from utils.queryset import get_child_queryset2
from django.db.models import Count
from .filters import UserFilter from .filters import UserFilter
from .models import (Dict, DictType, File, Message, Organization, Permission, from .models import (Dict, DictType, File, Message, Organization, Permission,
@ -185,7 +186,20 @@ class OrganizationViewSet(ModelViewSet):
search_fields = ['name'] search_fields = ['name']
ordering_fields = ['sort'] ordering_fields = ['sort']
ordering = ['sort', 'pk'] ordering = ['sort', 'pk']
@action(methods=['get'], detail=False,url_name='organization_group_by', 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)
class RoleViewSet(ModelViewSet): class RoleViewSet(ModelViewSet):
""" """

View File

@ -1,6 +1,16 @@
from rest_framework.pagination import PageNumberPagination from rest_framework.pagination import PageNumberPagination
from rest_framework.exceptions import ParseError
class MyPagination(PageNumberPagination): class MyPagination(PageNumberPagination):
page_size = 10 page_size = 10
page_size_query_param = 'page_size' page_size_query_param = 'page_size'
class PageOrNot:
def paginate_queryset(self, queryset):
if (self.paginator is None):
return None
elif self.request.query_params.get('pageoff', None) and self.get_queryset().count()<500:
return None
elif self.request.query_params.get('pageoff', None) and self.get_queryset().count()>=500:
return ParseError('单次请求数据量大,请求中止')
return self.paginator.paginate_queryset(queryset, self.request, view=self)