检验能力
This commit is contained in:
parent
0bb202749b
commit
2c6d6b8599
|
@ -0,0 +1,54 @@
|
|||
import request from '@/utils/request'
|
||||
|
||||
export function getInspectionList(query) {
|
||||
return request({
|
||||
url: '/ability/inspection/',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function createInspection(data) {
|
||||
return request({
|
||||
url: '/ability/inspection/',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
export function updateInspection(id, data) {
|
||||
return request({
|
||||
url: `/ability/inspection/${id}/`,
|
||||
method: 'put',
|
||||
data
|
||||
})
|
||||
}
|
||||
export function deleteInspection(id) {
|
||||
return request({
|
||||
url: `/ability/inspection/${id}/`,
|
||||
method: 'delete'
|
||||
})
|
||||
}
|
||||
export function inspectionimport(data) {
|
||||
return request({
|
||||
url: `/ability/inspection/inspection2/`,
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
export function getInspectionGroup(query) {
|
||||
return request({
|
||||
url: '/ability/inspection/group/',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
export function deletes(data)
|
||||
{
|
||||
return request({
|
||||
url: `/ability/inspection/deletes/`,
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
|
@ -81,6 +81,7 @@ export const asyncRoutes = [
|
|||
meta: { title: '检测能力(总部CMA+CNAS)', icon: 'table', perms: ['cma_view'] }
|
||||
}]
|
||||
},
|
||||
|
||||
{
|
||||
path: '/cma2',
|
||||
component: Layout,
|
||||
|
@ -92,7 +93,20 @@ export const asyncRoutes = [
|
|||
meta: { title: '检测能力(分子公司CMA)', icon: 'table', perms: ['cma2_view'] }
|
||||
}
|
||||
]
|
||||
},
|
||||
}
|
||||
,
|
||||
{
|
||||
path: '/inspection',
|
||||
component: Layout,
|
||||
redirect: '/inspection',
|
||||
children: [{
|
||||
path: '',
|
||||
name: 'inspection',
|
||||
component: () => import('@/views/ability/inspection'),
|
||||
meta: { title: '检验能力', icon: 'table', perms: ['inspection_view'] }
|
||||
}]
|
||||
},
|
||||
|
||||
{
|
||||
path: '/system',
|
||||
component: Layout,
|
||||
|
|
|
@ -0,0 +1,360 @@
|
|||
<template>
|
||||
<div class="app-container">
|
||||
<el-row :gutter="6">
|
||||
<el-col :xs="24" :md="4">
|
||||
<el-select
|
||||
v-model="listQuery.sszx"
|
||||
placeholder="所属公司"
|
||||
@change="handleFilter2"
|
||||
clearable
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in groupBy.sszx"
|
||||
:key="item.value"
|
||||
:label="item.text"
|
||||
:value="item.value"
|
||||
>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-col>
|
||||
|
||||
|
||||
</el-row>
|
||||
<div style="margin-top: 10px">
|
||||
<el-popover
|
||||
placement="top"
|
||||
width="160"
|
||||
|
||||
v-model="popovervisible"
|
||||
>
|
||||
<p>导入能力列表压缩包.</p>
|
||||
<div style="text-align: left; margin: 0">
|
||||
<el-upload
|
||||
:action="upUrl"
|
||||
:on-success="handleUploadSuccess"
|
||||
accept=".zip"
|
||||
:headers="upHeaders"
|
||||
:show-file-list="false"
|
||||
>
|
||||
<el-button
|
||||
size="small"
|
||||
type="primary"
|
||||
@click="popovervisible = false"
|
||||
>上传导入</el-button
|
||||
>
|
||||
</el-upload>
|
||||
</div>
|
||||
|
||||
|
||||
<el-button slot="reference">导入检验能力</el-button>
|
||||
|
||||
</el-popover>
|
||||
<el-button @click="delAll()" >批量删除</el-button>
|
||||
</div>
|
||||
|
||||
<el-table
|
||||
v-loading="listLoading"
|
||||
:data="istList.results"
|
||||
style="width: 100%; margin-top: 10px"
|
||||
border
|
||||
fit
|
||||
stripe
|
||||
highlight-current-row
|
||||
max-height="700"
|
||||
ref="filterTable"
|
||||
@selection-change="handleSelectionChange"
|
||||
@filter-change="filterChange"
|
||||
>
|
||||
<el-table-column
|
||||
type="selection"
|
||||
width="55">
|
||||
</el-table-column>
|
||||
<el-table-column type="index" width="50" />
|
||||
<el-table-column label="大类序号">
|
||||
<template slot-scope="scope"
|
||||
><span v-html="showlight(scope.row.dlxh)" ></span
|
||||
></template>
|
||||
</el-table-column>
|
||||
<el-table-column label="大类名称">
|
||||
<template slot-scope="scope"
|
||||
><span v-html="showlight(scope.row.dlmc)"></span
|
||||
></template>
|
||||
</el-table-column>
|
||||
<el-table-column label="对象序号">
|
||||
<template slot-scope="scope"
|
||||
><span v-html="showlight(scope.row.dxxh)"></span
|
||||
></template>
|
||||
</el-table-column>
|
||||
<el-table-column label="检验对象">
|
||||
<template slot-scope="scope"
|
||||
><span v-html="showlight(scope.row.jydx)"></span
|
||||
></template>
|
||||
</el-table-column>
|
||||
<el-table-column label="检验项目">
|
||||
<el-table-column label="序号">
|
||||
<template slot-scope="scope"
|
||||
><span v-html="showlight(scope.row.jyxmxh)"></span
|
||||
></template>
|
||||
</el-table-column>
|
||||
<el-table-column label="名称">
|
||||
<template slot-scope="scope"
|
||||
><span v-html="showlight(scope.row.jyxmmc)"></span
|
||||
></template>
|
||||
</el-table-column>
|
||||
</el-table-column>
|
||||
<el-table-column label="检验标准">
|
||||
<template slot-scope="scope"
|
||||
><span v-html="showlight(scope.row.jybz)"></span
|
||||
></template>
|
||||
</el-table-column>
|
||||
<el-table-column label="说明">
|
||||
<template slot-scope="scope" v-if="showlight(scope.row.sm)!='null'"
|
||||
><span v-html="showlight(scope.row.sm)"></span
|
||||
></template>
|
||||
</el-table-column>
|
||||
<el-table-column label="生效日期">
|
||||
<template slot-scope="scope"
|
||||
><span v-html="showlight(scope.row.sxrq)"></span
|
||||
></template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column
|
||||
align="header-center"
|
||||
label="所属中心"
|
||||
prop="sszx"
|
||||
column-key="sszx"
|
||||
:filters="groupBy.sszx"
|
||||
:filter-multiple="false"
|
||||
fixed="right"
|
||||
>
|
||||
<template slot-scope="scope"
|
||||
><span v-html="showlight(scope.row.sszx)"></span
|
||||
></template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<pagination
|
||||
v-show="istList.count > 0"
|
||||
:total="istList.count"
|
||||
:page.sync="listQuery.page"
|
||||
:limit.sync="listQuery.page_size"
|
||||
@pagination="getList"
|
||||
/>
|
||||
|
||||
|
||||
</div>
|
||||
</template>
|
||||
<style >
|
||||
.el-table-filter {
|
||||
width: 400px;
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
import {getInspectionList,inspectionimport,getInspectionGroup,deletes
|
||||
} from "@/api/inspection";
|
||||
import checkPermission from "@/utils/permission";
|
||||
import { upUrl, upHeaders } from "@/api/file";
|
||||
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
|
||||
const defaultCMA = {
|
||||
id: "",
|
||||
dlxh: null,
|
||||
dlmc: null,
|
||||
};
|
||||
const dflistQuery = {
|
||||
page: 1,
|
||||
page_size: 20,
|
||||
search:""
|
||||
};
|
||||
export default {
|
||||
components: { Pagination },
|
||||
data() {
|
||||
return {
|
||||
delarr: [],
|
||||
groupBy: { sszx: []},
|
||||
upHeaders: upHeaders(),
|
||||
upUrl: upUrl(),
|
||||
istList: { count: 0 },
|
||||
listLoading: true,
|
||||
listQuery: Object.assign({}, dflistQuery),
|
||||
popovervisible: false,
|
||||
|
||||
};
|
||||
},
|
||||
computed: {},
|
||||
watch: {},
|
||||
created() {
|
||||
this.getList();
|
||||
this.getGroup();
|
||||
},
|
||||
methods: {
|
||||
showlight(val) {
|
||||
val = val + "";
|
||||
if (this.listQuery.search != "") {
|
||||
let searchList = this.listQuery.search.split(" ");
|
||||
for (var i = 0; i < searchList.length; i++) {
|
||||
val = val.replace(
|
||||
searchList[i],
|
||||
'<span style="color:red;font-weight:bold">' +
|
||||
searchList[i] +
|
||||
"</span>"
|
||||
);
|
||||
}
|
||||
return val;
|
||||
} else {
|
||||
return val;
|
||||
}
|
||||
},
|
||||
checkPermission,
|
||||
handleUploadSuccess(res, file) {
|
||||
const loading = this.openLoading();
|
||||
let data = { path: res.data.path };
|
||||
inspectionimport(data)
|
||||
.then((res) => {
|
||||
this.$message({
|
||||
message: "导入成功",
|
||||
type: "success",
|
||||
});
|
||||
loading.close();
|
||||
this.resetFilter();
|
||||
})
|
||||
.catch((error) => {
|
||||
loading.close();
|
||||
});
|
||||
},
|
||||
getList() {
|
||||
this.listLoading = true;
|
||||
console.log(this.listQuery)
|
||||
getInspectionList(this.listQuery).then((response) => {
|
||||
if (response.data) {
|
||||
this.istList = response.data;
|
||||
}
|
||||
this.listLoading = false;
|
||||
});
|
||||
},
|
||||
|
||||
resetFilter() {
|
||||
(this.listQuery = Object.assign({}, dflistQuery)), this.getList();
|
||||
this.getGroup();
|
||||
},
|
||||
getGroup() {
|
||||
for (let key in this.groupBy) {
|
||||
let data = Object.assign({}, this.listQuery);
|
||||
data.group_by = key;
|
||||
getInspectionGroup(data).then((response) => {
|
||||
this.groupBy[key] = response.data;
|
||||
console.log(this.groupBy);
|
||||
});
|
||||
}
|
||||
},
|
||||
resetFilter() {
|
||||
(this.listQuery = Object.assign({}, dflistQuery)), this.getList();
|
||||
this.getGroup();
|
||||
},
|
||||
handleFilter() {
|
||||
this.listQuery.page = 1;
|
||||
this.getList();
|
||||
this.getGroup();
|
||||
},
|
||||
handleFilter2() {
|
||||
this.listQuery.page = 1;
|
||||
this.getList();
|
||||
},
|
||||
|
||||
handleDelete(scope) {
|
||||
this.$confirm("确认删除?", "警告", {
|
||||
confirmButtonText: "确认",
|
||||
cancelButtonText: "取消",
|
||||
type: "error",
|
||||
})
|
||||
.then(async () => {
|
||||
await deleteCMA(scope.row.id);
|
||||
this.istList.splice(scope.row.index, 1);
|
||||
this.$message({
|
||||
type: "success",
|
||||
message: "成功删除!",
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
});
|
||||
},
|
||||
handleSelectionChange(val) {
|
||||
this.multipleSelection = val;
|
||||
},
|
||||
delAll() {
|
||||
this.$confirm("确认删除?", "警告", {
|
||||
confirmButtonText: "确认",
|
||||
cancelButtonText: "取消",
|
||||
type: "error",
|
||||
})
|
||||
.then(async () => {
|
||||
const lengths = this.multipleSelection.length;
|
||||
for (let i = 0; i < lengths; i++) {
|
||||
this.delarr.push(this.multipleSelection[i].id);
|
||||
}
|
||||
|
||||
let data = { ids: this.delarr };
|
||||
deletes(data)
|
||||
.then((res) => {
|
||||
this.$message({
|
||||
message: "删除成功",
|
||||
type: "success",
|
||||
});
|
||||
this.getList();
|
||||
})
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
filterChange(obj) {
|
||||
for (let key in obj) {
|
||||
this.listQuery[key] = obj[key][0];
|
||||
}
|
||||
this.listQuery.page = 1;
|
||||
this.getList();
|
||||
},
|
||||
async confirm(form) {
|
||||
this.$refs[form].validate((valid) => {
|
||||
if (valid) {
|
||||
const isEdit = this.dialogType === "edit";
|
||||
if (isEdit) {
|
||||
updateCMA(this.cma.id, this.cma).then((res) => {
|
||||
if (res.code >= 200) {
|
||||
this.getList();
|
||||
this.dialogVisible = false;
|
||||
this.$notify({
|
||||
title: "成功",
|
||||
message: "编辑成功",
|
||||
type: "success",
|
||||
duration: 2000,
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
createCMA(this.cma).then((res) => {
|
||||
if (res.code >= 200) {
|
||||
this.getList();
|
||||
this.dialogVisible = false;
|
||||
this.$notify({
|
||||
title: "成功",
|
||||
message: "新增成功",
|
||||
type: "success",
|
||||
duration: 2000,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
|
@ -41,13 +41,13 @@
|
|||
</div>
|
||||
</el-col>
|
||||
<el-col :xs="12" :sm="12" :lg="12" :xl="6" class="card-panel-col">
|
||||
<div class="card-panel" >
|
||||
<div class="card-panel" @click="toPath('/inspection')">
|
||||
<div class="card-panel-icon-wrapper icon-money">
|
||||
<svg-icon icon-class="table" class-name="card-panel-icon" />
|
||||
</div>
|
||||
<div class="card-panel-description">
|
||||
<div class="card-panel-text">
|
||||
检验能力-建设中
|
||||
检验能力
|
||||
</div>
|
||||
<!-- <count-to :start-val="0" v-bind:end-val="ret.test_count" :duration="1600" class="card-panel-num" /> -->
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
# Generated by Django 3.0.5 on 2020-10-20 06:57
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('ability', '0012_auto_20201020_0920'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Inspection',
|
||||
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='大类名称')),
|
||||
('dxxh', models.TextField(blank=True, null=True, verbose_name='对象序号')),
|
||||
('jydx', models.TextField(blank=True, null=True, verbose_name='检验对象')),
|
||||
('jyxmxh', models.TextField(blank=True, null=True, verbose_name='检验项目序号')),
|
||||
('jyxmmc', models.TextField(blank=True, null=True, verbose_name='检验项目名称')),
|
||||
('jybz', models.TextField(blank=True, null=True, verbose_name='检验标准')),
|
||||
('sm', models.TextField(blank=True, null=True, verbose_name='说明')),
|
||||
('sxrq', models.TextField(blank=True, null=True, verbose_name='生效日期')),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 3.0.5 on 2020-10-20 08:01
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('ability', '0013_inspection'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='inspection',
|
||||
name='sszx',
|
||||
field=models.TextField(blank=True, null=True, verbose_name='所属中心'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='inspection',
|
||||
name='type',
|
||||
field=models.CharField(choices=[('center', '总部'), ('sub', '分子公司')], default='center', max_length=50, verbose_name='所属类型'),
|
||||
),
|
||||
]
|
|
@ -25,6 +25,27 @@ class CMA(BaseModel):
|
|||
choices=type_choices, default='center')
|
||||
glzz = models.TextField('关联资质', null=True, blank=True)
|
||||
|
||||
class Inspection(BaseModel):
|
||||
"""
|
||||
检验能力表
|
||||
"""
|
||||
type_choices = (
|
||||
('center', '总部'),
|
||||
('sub', '分子公司')
|
||||
)
|
||||
dlxh = models.TextField('大类序号', null=True,blank=True)
|
||||
dlmc = models.TextField('大类名称', null=True,blank=True)
|
||||
dxxh = models.TextField('对象序号', null=True,blank=True)
|
||||
jydx = models.TextField('检验对象', null=True,blank=True)
|
||||
jyxmxh = models.TextField('检验项目序号', null=True,blank=True)
|
||||
jyxmmc = models.TextField('检验项目名称', null=True,blank=True)
|
||||
jybz = models.TextField('检验标准', null=True,blank=True)
|
||||
sm = models.TextField('说明', null=True,blank=True)
|
||||
sxrq = models.TextField('生效日期', null=True,blank=True)
|
||||
sszx = models.TextField('所属中心',null=True,blank=True)
|
||||
type = models.CharField('所属类型', max_length=50,
|
||||
choices=type_choices, default='center')
|
||||
|
||||
class CNAS(BaseModel):
|
||||
"""
|
||||
CNAS检测能力表
|
||||
|
|
|
@ -16,7 +16,13 @@ class CNASSerializer(serializers.ModelSerializer):
|
|||
class Meta:
|
||||
model = CNAS
|
||||
fields = '__all__'
|
||||
|
||||
class InspectionSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
检验能力反馈
|
||||
"""
|
||||
class Meta:
|
||||
model = Inspection
|
||||
fields = '__all__'
|
||||
class QualificationotherSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Qualificationother
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
from django.urls import path, include
|
||||
from rest_framework import routers
|
||||
from .views import CMAViewSet, CNASViewSet, QualificationViewSet
|
||||
from .views import CMAViewSet, CNASViewSet, QualificationViewSet,InspectionViewSet
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register('cma', CMAViewSet, basename="cma")
|
||||
router.register('cnas', CNASViewSet, basename="cnas")
|
||||
router.register('qualification', QualificationViewSet, basename="qualification")
|
||||
router.register('inspection', InspectionViewSet, basename="inspection")
|
||||
urlpatterns = [
|
||||
path('', include(router.urls))
|
||||
]
|
|
@ -170,6 +170,78 @@ class QualificationViewSet(ModelViewSet):
|
|||
return Response(status = status.HTTP_200_OK)
|
||||
else:
|
||||
return Response('不支持非xlsx格式', status = status.HTTP_400_BAD_REQUEST)
|
||||
class InspectionViewSet(ModelViewSet):
|
||||
"""
|
||||
CNAS检测能力:增删改查
|
||||
"""
|
||||
perms_map = {'get': '*', 'post': 'inspection_create',
|
||||
'put': 'inspection_update', 'delete': 'inspection_delete'}
|
||||
queryset = Inspection.objects.all()
|
||||
serializer_class = InspectionSerializer
|
||||
search_fields = ['dlmc', 'jydx', 'dxxh']
|
||||
ordering_fields = ['dlmc']
|
||||
ordering = 'dlmc'
|
||||
filterset_fields = ['sszx']
|
||||
@action(methods=['post'], detail=False, url_path='deletes', url_name='inspection_deletes', perms_map = {'post':'inspection_deletes'})
|
||||
def deletes(self, request):
|
||||
|
||||
array = request.data['ids']
|
||||
Inspection.objects.filter(pk__in=array).delete()
|
||||
|
||||
return Response(status = status.HTTP_200_OK)
|
||||
@action(methods=['get'], detail=False,url_name='inspection_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)
|
||||
|
||||
@action(methods=['post'], detail=False, url_path='inspection2', url_name='inspection_inspection2', perms_map = {'post':'inspection_inspection2'})
|
||||
def inspection_import2(self, request, pk=None):
|
||||
"""
|
||||
导入能力2
|
||||
"""
|
||||
filepath = request.data['path']
|
||||
fullpath = settings.BASE_DIR + filepath
|
||||
import os
|
||||
if fullpath.endswith('.rar'):
|
||||
rar = rarfile.RarFile(fullpath)
|
||||
fulldir = fullpath.replace('.rar','')
|
||||
os.mkdir(fulldir)
|
||||
os.chdir(fulldir)
|
||||
rar.extractall()
|
||||
rar.close()
|
||||
# CMA.objects.filter(type='sub').delete()
|
||||
for root, dirs, files in os.walk(fulldir):
|
||||
for f in files:
|
||||
if f.endswith('.xlsx'):
|
||||
import_inspection(f, os.path.join(root,f))
|
||||
else:
|
||||
return Response('不支持非xlsx格式', status = status.HTTP_400_BAD_REQUEST)
|
||||
elif 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)
|
||||
|
||||
|
||||
class CNASViewSet(ModelViewSet):
|
||||
"""
|
||||
CNAS检测能力:增删改查
|
||||
|
@ -401,4 +473,103 @@ def import_cma2(filename, path):
|
|||
data['type'] = 'sub'
|
||||
datalist.append(CMA(**data))
|
||||
i = i + 1
|
||||
CMA.objects.bulk_create(datalist)
|
||||
CMA.objects.bulk_create(datalist)
|
||||
def import_inspection(filename, path):
|
||||
wb = load_workbook(path,data_only=True)
|
||||
sheet = wb.worksheets[0]
|
||||
datalist = []
|
||||
sszx = filename.split('-')[0]
|
||||
if Inspection.objects.filter(sszx=sszx).exists():
|
||||
Inspection.objects.filter(sszx=sszx).delete()
|
||||
i = 3
|
||||
max_row = sheet.max_row
|
||||
while i<max_row+1:
|
||||
data = {}
|
||||
if sheet['a'+str(i)].value:
|
||||
data['dlxh'] = sheet['a'+str(i)].value
|
||||
elif sheet['a3'].value:
|
||||
m = i - 1
|
||||
while True:
|
||||
if sheet['a'+str(m)].value:
|
||||
data['dlxh'] = sheet['a'+str(m)].value
|
||||
break
|
||||
m = m - 1
|
||||
if sheet['b'+str(i)].value:
|
||||
data['dlmc'] = sheet['b'+str(i)].value
|
||||
elif sheet['b3'].value:
|
||||
m = i - 1
|
||||
while True:
|
||||
if sheet['b'+str(m)].value:
|
||||
data['dlmc'] = sheet['b'+str(m)].value
|
||||
break
|
||||
m = m - 1
|
||||
if sheet['c'+str(i)].value:
|
||||
data['dxxh'] = sheet['c'+str(i)].value
|
||||
elif sheet['c3'].value:
|
||||
m = i - 1
|
||||
while True:
|
||||
if sheet['c'+str(m)].value:
|
||||
data['dxxh'] = sheet['c'+str(m)].value
|
||||
break
|
||||
m = m - 1
|
||||
if sheet['d'+str(i)].value:
|
||||
data['jydx'] = sheet['d'+str(i)].value
|
||||
elif sheet['d3'].value:
|
||||
m = i - 1
|
||||
while True:
|
||||
if sheet['d'+str(m)].value:
|
||||
data['jydx'] = sheet['d'+str(m)].value
|
||||
break
|
||||
m = m - 1
|
||||
if sheet['e'+str(i)].value:
|
||||
data['jyxmxh'] = sheet['e'+str(i)].value
|
||||
elif sheet['e3'].value: # 该表存在项目序号
|
||||
m = i - 1
|
||||
while True:
|
||||
if sheet['e'+str(m)].value:
|
||||
data['jyxmxh'] = sheet['e'+str(m)].value
|
||||
break
|
||||
m = m - 1
|
||||
else: #该表没有项目序号,自己定
|
||||
pass
|
||||
if sheet['f'+str(i)].value:
|
||||
data['jyxmmc'] = sheet['f'+str(i)].value
|
||||
else:
|
||||
m = i - 1
|
||||
while True:
|
||||
if sheet['f'+str(m)].value:
|
||||
data['jyxmmc'] = sheet['f'+str(m)].value
|
||||
break
|
||||
m = m - 1
|
||||
if sheet['g'+str(i)].value:
|
||||
data['jybz'] = sheet['g'+str(i)].value
|
||||
elif sheet['g3'].value:
|
||||
m = i - 1
|
||||
while True:
|
||||
if sheet['g'+str(m)].value:
|
||||
data['jybz'] = sheet['g'+str(m)].value
|
||||
break
|
||||
m = m - 1
|
||||
if sheet['h'+str(i)].value:
|
||||
data['sm'] = sheet['h'+str(i)].value
|
||||
elif sheet['h3'].value:
|
||||
m = i - 1
|
||||
while True:
|
||||
if sheet['h'+str(m)].value:
|
||||
data['sm'] = sheet['h'+str(m)].value
|
||||
break
|
||||
m = m - 1
|
||||
if sheet['i'+str(i)].value:
|
||||
data['sxrq'] = sheet['i'+str(i)].value
|
||||
elif sheet['i3'].value:
|
||||
m = i - 1
|
||||
while True:
|
||||
if sheet['i'+str(m)].value:
|
||||
data['sxrq'] = sheet['i'+str(m)].value
|
||||
break
|
||||
m = m - 1
|
||||
|
||||
data['sszx'] = sszx
|
||||
datalist.append(Inspection(**data))
|
||||
i = i + 1
|
||||
Inspection.objects.bulk_create(datalist)
|
Loading…
Reference in New Issue