cnas导入
This commit is contained in:
parent
fc942497ce
commit
430a41a7e0
|
@ -15,6 +15,14 @@ export function getCMAGroup(query) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getCNASGroup(query) {
|
||||||
|
return request({
|
||||||
|
url: '/ability/cnas/group/',
|
||||||
|
method: 'get',
|
||||||
|
params: query
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export function getCNASList(query) {
|
export function getCNASList(query) {
|
||||||
return request({
|
return request({
|
||||||
url: '/ability/cnas/',
|
url: '/ability/cnas/',
|
||||||
|
|
|
@ -182,6 +182,7 @@
|
||||||
stripe
|
stripe
|
||||||
highlight-current-row
|
highlight-current-row
|
||||||
max-height="300"
|
max-height="300"
|
||||||
|
@filter-change="filterChange2"
|
||||||
>
|
>
|
||||||
<el-table-column type="index" width="50" />
|
<el-table-column type="index" width="50" />
|
||||||
<el-table-column align="header-center" label="类别名称">
|
<el-table-column align="header-center" label="类别名称">
|
||||||
|
@ -209,7 +210,10 @@
|
||||||
><span v-html="showlight(scope.row.bztk)"></span
|
><span v-html="showlight(scope.row.bztk)"></span
|
||||||
></template>
|
></template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column align="header-center" label="所属地点">
|
<el-table-column align="header-center" label="所属地点" prop="sszx"
|
||||||
|
column-key="sszx"
|
||||||
|
:filters="groupBy2.sszx"
|
||||||
|
:filter-multiple="false">
|
||||||
<template slot-scope="scope"
|
<template slot-scope="scope"
|
||||||
><span v-html="showlight(scope.row.sszx)"></span
|
><span v-html="showlight(scope.row.sszx)"></span
|
||||||
></template>
|
></template>
|
||||||
|
@ -283,6 +287,7 @@ import {
|
||||||
getCNASList,
|
getCNASList,
|
||||||
importCNAS,
|
importCNAS,
|
||||||
getCMAGroup,
|
getCMAGroup,
|
||||||
|
getCNASGroup
|
||||||
} from "@/api/cma";
|
} from "@/api/cma";
|
||||||
import checkPermission from "@/utils/permission";
|
import checkPermission from "@/utils/permission";
|
||||||
import { upUrl, upHeaders } from "@/api/file";
|
import { upUrl, upHeaders } from "@/api/file";
|
||||||
|
@ -306,6 +311,7 @@ export default {
|
||||||
upHeaders: upHeaders(),
|
upHeaders: upHeaders(),
|
||||||
upUrl: upUrl(),
|
upUrl: upUrl(),
|
||||||
groupBy: { sszx: [] },
|
groupBy: { sszx: [] },
|
||||||
|
groupBy2: { sszx: [] },
|
||||||
cmaList: { count: 0 },
|
cmaList: { count: 0 },
|
||||||
cnasList: { count: 0 },
|
cnasList: { count: 0 },
|
||||||
listLoading: true,
|
listLoading: true,
|
||||||
|
@ -330,6 +336,7 @@ export default {
|
||||||
created() {
|
created() {
|
||||||
this.getList();
|
this.getList();
|
||||||
this.getGroup();
|
this.getGroup();
|
||||||
|
this.getGroup2();
|
||||||
this.getList2();
|
this.getList2();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -401,6 +408,15 @@ export default {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
getGroup2() {
|
||||||
|
for (let key in this.groupBy2) {
|
||||||
|
let data = Object.assign({}, this.listQuery2);
|
||||||
|
data.group_by = key;
|
||||||
|
getCNASGroup(data).then((response) => {
|
||||||
|
this.groupBy2[key] = response.data;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
getList2() {
|
getList2() {
|
||||||
this.listLoading2 = true;
|
this.listLoading2 = true;
|
||||||
getCNASList(this.listQuery2).then((response) => {
|
getCNASList(this.listQuery2).then((response) => {
|
||||||
|
|
|
@ -290,6 +290,21 @@ class CNASViewSet(ModelViewSet):
|
||||||
filterset_fields = ['sszx']
|
filterset_fields = ['sszx']
|
||||||
ordering = 'bzmc'
|
ordering = 'bzmc'
|
||||||
|
|
||||||
|
@action(methods=['get'], detail=False,url_name='cnas_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='import', url_name='cnas_import', perms_map = {'post':'cnas_import'})
|
@action(methods=['post'], detail=False, url_path='import', url_name='cnas_import', perms_map = {'post':'cnas_import'})
|
||||||
def cnas_import(self, request, pk=None):
|
def cnas_import(self, request, pk=None):
|
||||||
"""
|
"""
|
||||||
|
@ -320,8 +335,6 @@ class CNASViewSet(ModelViewSet):
|
||||||
zzz.extractall(fulldir)
|
zzz.extractall(fulldir)
|
||||||
for root, dirs, files in os.walk(fulldir):
|
for root, dirs, files in os.walk(fulldir):
|
||||||
for f in files:
|
for f in files:
|
||||||
if f.endswith('.xls'):
|
|
||||||
return Response('不支持旧xls格式', status = status.HTTP_400_BAD_REQUEST)
|
|
||||||
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)
|
||||||
|
|
||||||
|
@ -385,35 +398,26 @@ def import_cma(filename, path):
|
||||||
i = i + 1
|
i = i + 1
|
||||||
CMA.objects.bulk_create(datalist)
|
CMA.objects.bulk_create(datalist)
|
||||||
|
|
||||||
|
import xlrd
|
||||||
def import_cnas(filename, path):
|
def import_cnas(filename, path):
|
||||||
wb = load_workbook(path)
|
sheet = xlrd.open_workbook(path).sheet_by_name('检测能力范围')
|
||||||
sheet = wb.get_sheet_by_name('检测能力范围')
|
|
||||||
datalist = []
|
datalist = []
|
||||||
sszx = filename.replace('.xlsx','').replace('检测能力范围(含能源之星)-','')
|
sszx = filename.replace('.xlsx','').replace('.xls', '').replace('检测能力范围(含能源之星)-','')
|
||||||
i = 3
|
i = 2
|
||||||
while sheet['l'+str(i)].value:
|
lbmc = ''
|
||||||
|
xmmc = ''
|
||||||
|
while i < sheet.nrows:
|
||||||
data = {}
|
data = {}
|
||||||
if sheet['b'+str(i)].value:
|
data_list = sheet.row_values(i)
|
||||||
data['lbmc'] = sheet['b'+str(i)].value
|
if data_list[1]:
|
||||||
else:
|
lbmc = data_list[1]
|
||||||
m = i - 1
|
if data_list[6]:
|
||||||
while True:
|
xmmc = data_list[6]
|
||||||
if sheet['b'+str(m)].value:
|
data['lbmc'] = lbmc
|
||||||
data['lbmc'] = sheet['b'+str(m)].value
|
data['xmmc'] = xmmc
|
||||||
break
|
data['bzmc'] = data_list[11]
|
||||||
m = m - 1
|
data['bzbh'] = data_list[13]
|
||||||
if sheet['g'+str(i)].value:
|
data['bztk'] = data_list[15]
|
||||||
data['xmmc'] = sheet['g'+str(i)].value
|
|
||||||
else:
|
|
||||||
m = i - 1
|
|
||||||
while True:
|
|
||||||
if sheet['g'+str(m)].value:
|
|
||||||
data['xmmc'] = sheet['g'+str(m)].value
|
|
||||||
break
|
|
||||||
m = m - 1
|
|
||||||
data['bzmc'] = sheet['l'+str(i)].value
|
|
||||||
data['bzbh'] = sheet['n'+str(i)].value
|
|
||||||
data['bztk'] = sheet['p'+str(i)].value
|
|
||||||
data['sszx'] = sszx
|
data['sszx'] = sszx
|
||||||
datalist.append(CNAS(**data))
|
datalist.append(CNAS(**data))
|
||||||
i = i + 1
|
i = i + 1
|
||||||
|
|
Loading…
Reference in New Issue