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) {
|
||||
return request({
|
||||
url: '/ability/cnas/',
|
||||
|
|
|
@ -182,6 +182,7 @@
|
|||
stripe
|
||||
highlight-current-row
|
||||
max-height="300"
|
||||
@filter-change="filterChange2"
|
||||
>
|
||||
<el-table-column type="index" width="50" />
|
||||
<el-table-column align="header-center" label="类别名称">
|
||||
|
@ -209,7 +210,10 @@
|
|||
><span v-html="showlight(scope.row.bztk)"></span
|
||||
></template>
|
||||
</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"
|
||||
><span v-html="showlight(scope.row.sszx)"></span
|
||||
></template>
|
||||
|
@ -283,6 +287,7 @@ import {
|
|||
getCNASList,
|
||||
importCNAS,
|
||||
getCMAGroup,
|
||||
getCNASGroup
|
||||
} from "@/api/cma";
|
||||
import checkPermission from "@/utils/permission";
|
||||
import { upUrl, upHeaders } from "@/api/file";
|
||||
|
@ -306,6 +311,7 @@ export default {
|
|||
upHeaders: upHeaders(),
|
||||
upUrl: upUrl(),
|
||||
groupBy: { sszx: [] },
|
||||
groupBy2: { sszx: [] },
|
||||
cmaList: { count: 0 },
|
||||
cnasList: { count: 0 },
|
||||
listLoading: true,
|
||||
|
@ -330,6 +336,7 @@ export default {
|
|||
created() {
|
||||
this.getList();
|
||||
this.getGroup();
|
||||
this.getGroup2();
|
||||
this.getList2();
|
||||
},
|
||||
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() {
|
||||
this.listLoading2 = true;
|
||||
getCNASList(this.listQuery2).then((response) => {
|
||||
|
|
|
@ -290,6 +290,21 @@ class CNASViewSet(ModelViewSet):
|
|||
filterset_fields = ['sszx']
|
||||
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'})
|
||||
def cnas_import(self, request, pk=None):
|
||||
"""
|
||||
|
@ -320,8 +335,6 @@ class CNASViewSet(ModelViewSet):
|
|||
zzz.extractall(fulldir)
|
||||
for root, dirs, files in os.walk(fulldir):
|
||||
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))
|
||||
return Response(status = status.HTTP_200_OK)
|
||||
|
||||
|
@ -385,35 +398,26 @@ def import_cma(filename, path):
|
|||
i = i + 1
|
||||
CMA.objects.bulk_create(datalist)
|
||||
|
||||
import xlrd
|
||||
def import_cnas(filename, path):
|
||||
wb = load_workbook(path)
|
||||
sheet = wb.get_sheet_by_name('检测能力范围')
|
||||
sheet = xlrd.open_workbook(path).sheet_by_name('检测能力范围')
|
||||
datalist = []
|
||||
sszx = filename.replace('.xlsx','').replace('检测能力范围(含能源之星)-','')
|
||||
i = 3
|
||||
while sheet['l'+str(i)].value:
|
||||
sszx = filename.replace('.xlsx','').replace('.xls', '').replace('检测能力范围(含能源之星)-','')
|
||||
i = 2
|
||||
lbmc = ''
|
||||
xmmc = ''
|
||||
while i < sheet.nrows:
|
||||
data = {}
|
||||
if sheet['b'+str(i)].value:
|
||||
data['lbmc'] = sheet['b'+str(i)].value
|
||||
else:
|
||||
m = i - 1
|
||||
while True:
|
||||
if sheet['b'+str(m)].value:
|
||||
data['lbmc'] = sheet['b'+str(m)].value
|
||||
break
|
||||
m = m - 1
|
||||
if sheet['g'+str(i)].value:
|
||||
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_list = sheet.row_values(i)
|
||||
if data_list[1]:
|
||||
lbmc = data_list[1]
|
||||
if data_list[6]:
|
||||
xmmc = data_list[6]
|
||||
data['lbmc'] = lbmc
|
||||
data['xmmc'] = xmmc
|
||||
data['bzmc'] = data_list[11]
|
||||
data['bzbh'] = data_list[13]
|
||||
data['bztk'] = data_list[15]
|
||||
data['sszx'] = sszx
|
||||
datalist.append(CNAS(**data))
|
||||
i = i + 1
|
||||
|
|
Loading…
Reference in New Issue