diff --git a/client/src/api/cma.js b/client/src/api/cma.js index 2859aa4..584a85d 100644 --- a/client/src/api/cma.js +++ b/client/src/api/cma.js @@ -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/', diff --git a/client/src/views/ability/cma.vue b/client/src/views/ability/cma.vue index 3cc81d8..746c6a9 100644 --- a/client/src/views/ability/cma.vue +++ b/client/src/views/ability/cma.vue @@ -182,6 +182,7 @@ stripe highlight-current-row max-height="300" + @filter-change="filterChange2" > @@ -209,7 +210,10 @@ > - + @@ -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) => { @@ -419,6 +435,7 @@ export default { this.getList(); this.getList2(); this.getGroup(); + this.getGroup2(); }, handleFilter() { this.listQuery.page = 1; @@ -427,6 +444,7 @@ export default { this.listQuery2.search = this.listQuery.search; this.getList2(); this.getGroup(); + this.getGroup2(); }, handleAdd() { this.cma = Object.assign({}, defaultCMA); @@ -469,6 +487,13 @@ export default { this.listQuery.page = 1; this.getList(); }, + filterChange2(obj) { + for (let key in obj) { + this.listQuery2[key] = obj[key][0]; + } + this.listQuery2.page = 1; + this.getList2(); + }, async confirm(form) { this.$refs[form].validate((valid) => { if (valid) { diff --git a/client/src/views/ability/cma2.vue b/client/src/views/ability/cma2.vue index aa0058d..8b4e756 100644 --- a/client/src/views/ability/cma2.vue +++ b/client/src/views/ability/cma2.vue @@ -89,7 +89,7 @@ highlight-current-row max-height="700" ref="filterTable" - @selection-change="handleSelectionChange"> + @selection-change="handleSelectionChange" @filter-change="filterChange" > { this.groupBy[key] = response.data; - console.log(this.groupBy); }); } }, @@ -372,7 +371,6 @@ export default { }); }) .catch((err) => { - console.error(err); }); }, @@ -399,7 +397,6 @@ export default { }) }) .catch((err) => { - console.error(err); }); }, @@ -407,6 +404,7 @@ export default { this.multipleSelection = val; }, filterChange(obj) { + console.log(obj) for (let key in obj) { this.listQuery[key] = obj[key][0]; } diff --git a/server/apps/ability/views.py b/server/apps/ability/views.py index ec75f31..2c7bc8b 100644 --- a/server/apps/ability/views.py +++ b/server/apps/ability/views.py @@ -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): """ @@ -321,10 +336,6 @@ class CNASViewSet(ModelViewSet): zzz.extractall(fulldir) for root, dirs, files in os.walk(fulldir): for f in files: - print(f) - if f.endswith('.xls'): - return Response('不支持旧xls格式', status = status.HTTP_400_BAD_REQUEST) - print(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) @@ -388,38 +399,26 @@ def import_cma(filename, path): i = i + 1 CMA.objects.bulk_create(datalist) +import xlrd def import_cnas(filename, path): - print(path) - wb = load_workbook(path) - - sheet = wb.get_sheet_by_name('检测能力范围') - print(wb) + 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 @@ -435,84 +434,49 @@ def import_cma2(filename, path): CMA.objects.filter(sszx=sszx, type='sub').delete() i = 3 max_row = sheet.max_row + defaultv = {} while i