diff --git a/client/src/api/queryrecord.js b/client/src/api/queryrecord.js
new file mode 100644
index 0000000..95b6294
--- /dev/null
+++ b/client/src/api/queryrecord.js
@@ -0,0 +1,11 @@
+
+import request from '@/utils/request'
+
+
+export function getRecord(query) {
+ return request({
+ url: '/ability/queryrecord/',
+ method: 'get',
+ params: query
+ })
+}
\ No newline at end of file
diff --git a/client/src/router/index.js b/client/src/router/index.js
index 0f5527f..4fe1687 100644
--- a/client/src/router/index.js
+++ b/client/src/router/index.js
@@ -132,6 +132,12 @@ export const asyncRoutes = [
component: () => import('@/views/system/role'),
meta: { title: '角色管理', icon: 'lock', perms: ['role_manage'] }
},
+ {
+ path: 'queryrecord',
+ name: 'queryrecord',
+ component: () => import('@/views/ability/queryrecord'),
+ meta: { title: '查询日志', icon: 'table', perms: ['queryrecord_view'] }
+ },
{
path: 'position',
name: 'Postion',
diff --git a/client/src/store/modules/user.js b/client/src/store/modules/user.js
index 185db55..c755f77 100644
--- a/client/src/store/modules/user.js
+++ b/client/src/store/modules/user.js
@@ -97,10 +97,28 @@ const actions = {
const { data } = response
if (!data) {
- reject('验证失败,重新登录.')
- }
-
- const { perms, name, avatar } = data
+ getInfo(state.token).then(response => {
+ const { data } = response
+
+ if (!data) {
+ reject('验证失败,重新登录.')
+ }
+
+ const { perms, name, avatar } = data
+
+ // perms must be a non-empty array
+ if (!perms || perms.length <= 0) {
+ reject('没有任何权限!')
+ }
+
+ commit('SET_PERMS', perms)
+ commit('SET_NAME', name)
+ commit('SET_AVATAR', avatar)
+ resolve(data)
+ }).catch(error => {
+ reject(error)})
+ }else{
+ const { perms, name, avatar } = data
// perms must be a non-empty array
if (!perms || perms.length <= 0) {
@@ -111,26 +129,11 @@ const actions = {
commit('SET_NAME', name)
commit('SET_AVATAR', avatar)
resolve(data)
+ }
+
+
}).catch(error => {
- getInfo(state.token).then(response => {
- const { data } = response
-
- if (!data) {
- reject('验证失败,重新登录.')
- }
-
- const { perms, name, avatar } = data
-
- // perms must be a non-empty array
- if (!perms || perms.length <= 0) {
- reject('没有任何权限!')
- }
-
- commit('SET_PERMS', perms)
- commit('SET_NAME', name)
- commit('SET_AVATAR', avatar)
- resolve(data)
- }).catch(e=>{})
+ reject(error)
})
})
},
diff --git a/client/src/views/ability/queryrecord.vue b/client/src/views/ability/queryrecord.vue
new file mode 100644
index 0000000..a057bc5
--- /dev/null
+++ b/client/src/views/ability/queryrecord.vue
@@ -0,0 +1,108 @@
+
+
+
+
+ 搜索
+ 刷新重置
+
+
+
+
+ {{ scope.row.create_time }}
+
+
+
+ {{ scope.row.user_.name }}
+
+
+ {{ scope.row.user_.dept }}
+
+
+ {{ scope.row.path }}
+
+
+ {{ scope.row.ip }}
+
+
+ {{ scope.row.search }}
+
+
+
+
+
+
+
+
diff --git a/server/apps/ability/migrations/0018_queryrecord.py b/server/apps/ability/migrations/0018_queryrecord.py
new file mode 100644
index 0000000..98aa910
--- /dev/null
+++ b/server/apps/ability/migrations/0018_queryrecord.py
@@ -0,0 +1,37 @@
+# Generated by Django 3.0.11 on 2020-12-31 07:59
+
+from django.conf import settings
+import django.contrib.postgres.fields.jsonb
+from django.db import migrations, models
+import django.db.models.deletion
+import django.utils.timezone
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ('ability', '0017_auto_20201230_1626'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='QueryRecord',
+ 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='删除标记')),
+ ('path', models.CharField(max_length=200, verbose_name='访问地址')),
+ ('ip', models.CharField(max_length=200, verbose_name='IP地址')),
+ ('method', models.CharField(default='GET', max_length=100, verbose_name='方法')),
+ ('query', django.contrib.postgres.fields.jsonb.JSONField(blank=True, null=True)),
+ ('search', models.TextField(blank=True, null=True, verbose_name='搜索字符')),
+ ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='record_user', to=settings.AUTH_USER_MODEL)),
+ ],
+ options={
+ 'verbose_name': '查询记录',
+ 'verbose_name_plural': '查询记录',
+ },
+ ),
+ ]
diff --git a/server/apps/ability/migrations/0019_auto_20210129_0957.py b/server/apps/ability/migrations/0019_auto_20210129_0957.py
new file mode 100644
index 0000000..6a28113
--- /dev/null
+++ b/server/apps/ability/migrations/0019_auto_20210129_0957.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.0.11 on 2021-01-29 01:57
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('ability', '0018_queryrecord'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='queryrecord',
+ name='ip',
+ field=models.CharField(blank=True, max_length=200, null=True, verbose_name='IP地址'),
+ ),
+ ]
diff --git a/server/apps/ability/models.py b/server/apps/ability/models.py
index 68c0f8a..d6d0058 100644
--- a/server/apps/ability/models.py
+++ b/server/apps/ability/models.py
@@ -3,14 +3,20 @@ from django.db import models
from django.db.models.fields import related
from utils.model import BaseModel
from apps.system.models import Organization, User
-
# Create your models here.
+from django.contrib.postgres.fields import JSONField
-# class GetRecord(BaseModel):
-# user = models.ForeignKey(User, related_name='record_user', on_delete=models.CASCADE)
-# path = models.CharField('访问地址', max_length=100)
-# ip = models.CharField('IP地址', max_length=100)
-# method = models.CharField('方法', max_length=100, default='GET')
+class QueryRecord(BaseModel):
+ user = models.ForeignKey(User, related_name='record_user', on_delete=models.CASCADE)
+ path = models.CharField('访问地址', max_length=200)
+ ip = models.CharField('IP地址', max_length=200, null=True, blank=True)
+ method = models.CharField('方法', max_length=100, default='GET')
+ query = JSONField(null=True,blank=True)
+ search = models.TextField('搜索字符', null=True, blank=True)
+
+ class Meta:
+ verbose_name = '查询记录'
+ verbose_name_plural = verbose_name
class CMA(BaseModel):
diff --git a/server/apps/ability/serializers.py b/server/apps/ability/serializers.py
index 62dae5a..53f2e6a 100644
--- a/server/apps/ability/serializers.py
+++ b/server/apps/ability/serializers.py
@@ -2,6 +2,23 @@ from rest_framework import serializers
from .models import *
from apps.system.serializers import OrganizationSerializer
+class QueryRecordSerializer(serializers.ModelSerializer):
+ user_ = serializers.SerializerMethodField()
+ class Meta:
+ model = QueryRecord
+ fields = '__all__'
+
+ @staticmethod
+ def setup_eager_loading(queryset):
+ """ Perform necessary eager loading of data. """
+ queryset = queryset.select_related('user')
+ return queryset
+
+ def get_user_(self, obj):
+ data = {'name':'', 'dept':''}
+ data['name'] = obj.user.name if obj.user.name else obj.user.username
+ data['dept'] = obj.user.dept.name if obj.user.dept else ""
+ return data
class CMASerializer(serializers.ModelSerializer):
"""
diff --git a/server/apps/ability/urls.py b/server/apps/ability/urls.py
index 15ffed0..41228a7 100644
--- a/server/apps/ability/urls.py
+++ b/server/apps/ability/urls.py
@@ -1,6 +1,6 @@
from django.urls import path, include
from rest_framework import routers
-from .views import CMAViewSet, CNASViewSet, QualificationViewSet,InspectionViewSet,QualificationotherViewSet
+from .views import CMAViewSet, CNASViewSet, QualificationViewSet,InspectionViewSet,QualificationotherViewSet, QueryRecordListViewSet
router = routers.DefaultRouter()
router.register('cma', CMAViewSet, basename="cma")
@@ -8,6 +8,7 @@ router.register('cnas', CNASViewSet, basename="cnas")
router.register('qualification', QualificationViewSet, basename="qualification")
router.register('qualificationother', QualificationotherViewSet, basename="qualificationother")
router.register('inspection', InspectionViewSet, basename="inspection")
+router.register('queryrecord', QueryRecordListViewSet, basename="queryrecord")
urlpatterns = [
path('', include(router.urls))
]
\ No newline at end of file
diff --git a/server/apps/ability/views.py b/server/apps/ability/views.py
index 191fdaa..9ef51b5 100644
--- a/server/apps/ability/views.py
+++ b/server/apps/ability/views.py
@@ -1,5 +1,6 @@
from django.shortcuts import render
-from rest_framework.viewsets import ModelViewSet
+from rest_framework.mixins import ListModelMixin
+from rest_framework.viewsets import GenericViewSet, ModelViewSet
from .models import *
from .serializers import *
from rest_framework.decorators import action
@@ -25,14 +26,22 @@ class RecordMixin():
`request.user` or `request.auth` is accessed.
"""
user = request.user
- # if request.method == 'GET':
- # print(json.dumps(request.query_params), request.method, request.path)
+ if request.method == 'GET':
+ QueryRecord.objects.create(user=user,path=request.path,ip=request.META.get('HTTP_X_FORWARDED_FOR'),method=\
+ request.method,search=request.query_params.get('search',None),query=request.query_params)
+class QueryRecordListViewSet(ListModelMixin, GenericViewSet):
+ perms_map = {'get': 'queryrecord_view'}
+ queryset = QueryRecord.objects.all()
+ serializer_class = QueryRecordSerializer
+ search_fields = ['user__name', 'user__dept__name']
+ ordering = ['-create_time']
+
class CMAViewSet(RecordMixin, ModelViewSet):
"""
CMA检测能力:增删改查
"""
- perms_map = {'get': '*', 'post': 'cma_create',
+ perms_map = {'get': 'cma_view', 'post': 'cma_create',
'put': 'cma_update', 'delete': 'cma_delete'}
queryset = CMA.objects.all()
serializer_class = CMASerializer
@@ -136,11 +145,11 @@ class CMAViewSet(RecordMixin, ModelViewSet):
return Response(status = status.HTTP_200_OK)
from django.db.models.query import QuerySet
-class QualificationViewSet(ModelViewSet):
+class QualificationViewSet(RecordMixin, ModelViewSet):
"""
资质能力:增删改查
"""
- perms_map = {'get': '*', 'post': 'qualificaiton_create',
+ perms_map = {'get': 'qualification_view', 'post': 'qualificaiton_create',
'put': 'qualification_update', 'delete': 'qualification_delete'}
queryset = Qualification.objects.all()
serializer_class = QualificationSerializer
@@ -187,11 +196,11 @@ class QualificationViewSet(ModelViewSet):
return Response(status = status.HTTP_200_OK)
else:
return Response('不支持非xlsx格式', status = status.HTTP_400_BAD_REQUEST)
-class QualificationotherViewSet(PageOrNot,ModelViewSet):
+class QualificationotherViewSet(RecordMixin, PageOrNot,ModelViewSet):
"""
资质能力:增删改查
"""
- perms_map = {'get': '*', 'post': 'qualificationother_create',
+ perms_map = {'get': 'qualification_view', 'post': 'qualificationother_create',
'put': 'qualificationother_update', 'delete': 'qualificationother_delete'}
queryset = Qualificationother.objects.all()
serializer_class = QualificationotherSerializer
@@ -220,11 +229,11 @@ class QualificationotherViewSet(PageOrNot,ModelViewSet):
ret.append({'text':i[group_by]+'('+ str(i['count']) +')','value':i[group_by]})
return Response(ret)
-class InspectionViewSet(ModelViewSet):
+class InspectionViewSet(RecordMixin, ModelViewSet):
"""
检验能力:增删改查
"""
- perms_map = {'get': '*', 'post': 'inspection_create',
+ perms_map = {'get': 'inspection_view', 'post': 'inspection_create',
'put': 'inspection_update', 'delete': 'inspection_delete'}
queryset = Inspection.objects.all()
serializer_class = InspectionSerializer
@@ -292,11 +301,11 @@ class InspectionViewSet(ModelViewSet):
return Response(status = status.HTTP_200_OK)
-class CNASViewSet(ModelViewSet):
+class CNASViewSet(RecordMixin, ModelViewSet):
"""
CNAS检测能力:增删改查
"""
- perms_map = {'get': '*', 'post': 'cnas_create',
+ perms_map = {'get': 'cma_view', 'post': 'cnas_create',
'put': 'cnas_update', 'delete': 'cnas_delete'}
queryset = CNAS.objects.all()
serializer_class = CNASSerializer
@@ -347,7 +356,6 @@ class CNASViewSet(ModelViewSet):
os.chdir(fulldir)
CNAS.objects.all().delete()
with zipfile.ZipFile(fullpath,'r') as zzz:
- print(zzz)
zzz.extractall(fulldir)
for root, dirs, files in os.walk(fulldir):
for f in files:
@@ -437,7 +445,6 @@ def import_cnas(filename, path):
data['sszx'] = sszx
datalist.append(CNAS(**data))
i = i + 1
- print(i,data)
CNAS.objects.bulk_create(datalist)
def import_cma2(filename, path):
diff --git a/server/server/settings_dev.py b/server/server/settings_dev.py
index 2e98f3d..f1d0467 100644
--- a/server/server/settings_dev.py
+++ b/server/server/settings_dev.py
@@ -1,8 +1,12 @@
from .settings import *
-DEBUG = False
+DEBUG = True
DATABASES = {
'default': {
- 'ENGINE': 'django.db.backends.sqlite3',
- 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
+ 'ENGINE': 'django.db.backends.postgresql',
+ 'NAME': 'cma',
+ 'USER': 'cma',
+ 'PASSWORD': 'cma123',
+ 'HOST': '172.16.80.102',
+ 'PORT': '5432',
}
}