diff --git a/client/src/api/cma.js b/client/src/api/cma.js index 3151e4b..64f59a7 100644 --- a/client/src/api/cma.js +++ b/client/src/api/cma.js @@ -51,6 +51,14 @@ export function importCMA(data) { data }) } +export function importCMA2(data) { + return request({ + url: `/ability/cma/import2/`, + method: 'post', + data + }) +} + export function importCNAS(data) { return request({ url: `/ability/cnas/import/`, diff --git a/client/src/layout/components/Sidebar/Logo.vue b/client/src/layout/components/Sidebar/Logo.vue index 7121590..9021d25 100644 --- a/client/src/layout/components/Sidebar/Logo.vue +++ b/client/src/layout/components/Sidebar/Logo.vue @@ -24,7 +24,7 @@ export default { }, data() { return { - title: 'Django Vue Admin', + title: '能力检索', logo: 'https://wpimg.wallstcn.com/69a1c46c-eb1c-4b46-8bd4-e9e686ef5251.png' } } diff --git a/client/src/router/index.js b/client/src/router/index.js index 9becff7..fb66366 100644 --- a/client/src/router/index.js +++ b/client/src/router/index.js @@ -50,7 +50,18 @@ export const constantRoutes = [ path: 'cma', name: 'CMA', component: () => import('@/views/ability/cma'), - meta: { title: '检测能力', icon: 'table' } + meta: { title: '检测能力(总部)', icon: 'table' } + }] + }, + { + path: '/', + component: Layout, + redirect: '/cma2', + children: [{ + path: 'cma2', + name: 'CMA2', + component: () => import('@/views/ability/cma2'), + meta: { title: '检测能力(分子公司)', icon: 'table' } }] } // { diff --git a/client/src/utils/get-page-title.js b/client/src/utils/get-page-title.js index 19f9a0e..596e579 100644 --- a/client/src/utils/get-page-title.js +++ b/client/src/utils/get-page-title.js @@ -1,6 +1,6 @@ import defaultSettings from '@/settings' -const title = defaultSettings.title || 'Django Vue Admin' +const title = defaultSettings.title || '能力检索' export default function getPageTitle(pageTitle) { if (pageTitle) { diff --git a/client/src/views/ability/cma.vue b/client/src/views/ability/cma.vue index 377498e..866dba7 100644 --- a/client/src/views/ability/cma.vue +++ b/client/src/views/ability/cma.vue @@ -223,6 +223,7 @@ const defaultCMA = { const dflistQuery = { page: 1, page_size: 20, + type:'center' } export default { components: { Pagination }, diff --git a/client/src/views/ability/cma2.vue b/client/src/views/ability/cma2.vue new file mode 100644 index 0000000..b5896f6 --- /dev/null +++ b/client/src/views/ability/cma2.vue @@ -0,0 +1,296 @@ + + diff --git a/server/apps/ability/migrations/0007_cma_type.py b/server/apps/ability/migrations/0007_cma_type.py new file mode 100644 index 0000000..b89b951 --- /dev/null +++ b/server/apps/ability/migrations/0007_cma_type.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.7 on 2020-07-03 09:18 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ability', '0006_cnas_bztk'), + ] + + operations = [ + migrations.AddField( + model_name='cma', + name='type', + field=models.CharField(choices=[('center', '总部'), ('sub', '分子公司')], default='center', max_length=50, verbose_name='所属类型'), + ), + ] diff --git a/server/apps/ability/models.py b/server/apps/ability/models.py index 154d347..2939485 100644 --- a/server/apps/ability/models.py +++ b/server/apps/ability/models.py @@ -6,6 +6,10 @@ class CMA(BaseModel): """ CMA检测能力表 """ + type_choices = ( + ('center', '总部'), + ('sub', '分子公司') + ) dlxh = models.CharField('大类序号', max_length=200,null=True,blank=True) dlmc = models.CharField('大类', max_length=200,null=True,blank=True) lbxh = models.CharField('类别序号', max_length=200,null=True,blank=True) @@ -17,6 +21,8 @@ class CMA(BaseModel): xzfw = models.TextField('限制范围',null=True,blank=True) bz = 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): """ diff --git a/server/apps/ability/views.py b/server/apps/ability/views.py index 3791ae3..2df297a 100644 --- a/server/apps/ability/views.py +++ b/server/apps/ability/views.py @@ -20,7 +20,7 @@ class CMAViewSet(ModelViewSet): queryset = CMA.objects.all() serializer_class = CMASerializer search_fields = ['bzbh', 'bzmc', 'sszx', 'xmmc'] - filterset_fields = ['sszx'] + filterset_fields = ['sszx', 'type'] ordering_fields = ['xmxh'] ordering = 'xmxh' @@ -58,8 +58,28 @@ class CMAViewSet(ModelViewSet): for f in files: import_cma(f, os.path.join(root,f)) return Response(status = status.HTTP_200_OK) - + @action(methods=['post'], detail=False, url_path='import2', url_name='cma_import2', perms_map = {'post':'cma_import2'}) + def cma_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.all().delete() + for root, dirs, files in os.walk(fulldir): + for f in files: + import_cma2(f, os.path.join(root,f)) + return Response(status = status.HTTP_200_OK) + class CNASViewSet(ModelViewSet): """ CNAS检测能力:增删改查 @@ -152,4 +172,29 @@ def import_cnas(filename, path): print(data) datalist.append(CNAS(**data)) i = i + 1 - CNAS.objects.bulk_create(datalist) \ No newline at end of file + CNAS.objects.bulk_create(datalist) + +def import_cma2(filename, path): + wb = load_workbook(path) + sheet = wb.worksheets[0] + datalist = [] + sszx = filename.split('-')[0] + i = 3 + while sheet['b'+str(i)].value: + data = {} + data['dlxh'] = sheet['a'+str(i)].value + data['dlmc'] = sheet['b'+str(i)].value + data['lbxh'] = sheet['c'+str(i)].value + data['lbmc'] = sheet['d'+str(i)].value + data['xmxh'] = sheet['e'+str(i)].value + data['xmmc'] = sheet['f'+str(i)].value + data['bzmc'] = sheet['g'+str(i)].value + data['bzbh'] = sheet['h'+str(i)].value + data['xzfw'] = sheet['i'+str(i)].value + data['bz'] = sheet['j'+str(i)].value + data['sszx'] = sszx + data['type'] = 'sub' + print(data) + datalist.append(CMA(**data)) + i = i + 1 + CMA.objects.bulk_create(datalist) \ No newline at end of file diff --git a/server/db.sqlite3 b/server/db.sqlite3 index e9d7fb6..f8567ef 100644 Binary files a/server/db.sqlite3 and b/server/db.sqlite3 differ