增加queryrecord
This commit is contained in:
parent
3b6d6bce6a
commit
8b322f25b4
|
@ -0,0 +1,11 @@
|
||||||
|
|
||||||
|
import request from '@/utils/request'
|
||||||
|
|
||||||
|
|
||||||
|
export function getRecord(query) {
|
||||||
|
return request({
|
||||||
|
url: '/ability/queryrecord/',
|
||||||
|
method: 'get',
|
||||||
|
params: query
|
||||||
|
})
|
||||||
|
}
|
|
@ -132,6 +132,12 @@ export const asyncRoutes = [
|
||||||
component: () => import('@/views/system/role'),
|
component: () => import('@/views/system/role'),
|
||||||
meta: { title: '角色管理', icon: 'lock', perms: ['role_manage'] }
|
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',
|
path: 'position',
|
||||||
name: 'Postion',
|
name: 'Postion',
|
||||||
|
|
|
@ -0,0 +1,108 @@
|
||||||
|
<template>
|
||||||
|
<div class="app-container">
|
||||||
|
<div>
|
||||||
|
<el-input
|
||||||
|
v-model="listQuery.search"
|
||||||
|
placeholder="用户名"
|
||||||
|
style="width: 400px;"
|
||||||
|
class="filter-item"
|
||||||
|
@keyup.enter.native="handleFilter"
|
||||||
|
/>
|
||||||
|
<el-button
|
||||||
|
class="filter-item"
|
||||||
|
type="primary"
|
||||||
|
icon="el-icon-search"
|
||||||
|
@click="handleFilter"
|
||||||
|
>搜索</el-button>
|
||||||
|
<el-button
|
||||||
|
class="filter-item"
|
||||||
|
style="margin-left: 10px;"
|
||||||
|
type="primary"
|
||||||
|
icon="el-icon-refresh-left"
|
||||||
|
@click="resetFilter"
|
||||||
|
>刷新重置</el-button>
|
||||||
|
</div>
|
||||||
|
<el-table
|
||||||
|
v-loading="listLoading"
|
||||||
|
:data="tableData.results"
|
||||||
|
style="width: 100%;margin-top:10px;"
|
||||||
|
border
|
||||||
|
fit
|
||||||
|
stripe
|
||||||
|
highlight-current-row
|
||||||
|
max-height="600"
|
||||||
|
>
|
||||||
|
<el-table-column label="访问时间">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<span>{{ scope.row.create_time }}</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="用户">
|
||||||
|
<template slot-scope="scope" v-if="scope.row.user_">{{ scope.row.user_.name }}</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="部门">
|
||||||
|
<template slot-scope="scope" v-if="scope.row.user_">{{ scope.row.user_.dept }}</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="访问地址">
|
||||||
|
<template slot-scope="scope">{{ scope.row.path }}</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="ip地址">
|
||||||
|
<template slot-scope="scope">{{ scope.row.ip }}</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column label="查询字符">
|
||||||
|
<template slot-scope="scope">{{ scope.row.search }}</template>
|
||||||
|
</el-table-column>
|
||||||
|
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<pagination
|
||||||
|
v-show="tableData.count>0"
|
||||||
|
:total="tableData.count"
|
||||||
|
:page.sync="listQuery.page"
|
||||||
|
:limit.sync="listQuery.page_size"
|
||||||
|
@pagination="getList"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<script>
|
||||||
|
import { getRecord } from "@/api/queryrecord"
|
||||||
|
import Pagination from "@/components/Pagination"
|
||||||
|
export default {
|
||||||
|
components: { Pagination },
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
tableData: {count:0},
|
||||||
|
listLoading: true,
|
||||||
|
listQuery: {
|
||||||
|
page: 1,
|
||||||
|
page_size: 20
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.getList();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
getList() {
|
||||||
|
this.listLoading = true;
|
||||||
|
getRecord(this.listQuery).then(response => {
|
||||||
|
if (response.data) {
|
||||||
|
this.tableData = response.data
|
||||||
|
}
|
||||||
|
this.listLoading = false;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
resetFilter() {
|
||||||
|
this.listQuery = {
|
||||||
|
page: 1,
|
||||||
|
page_size: 20
|
||||||
|
};
|
||||||
|
this.getList();
|
||||||
|
},
|
||||||
|
handleFilter() {
|
||||||
|
this.listQuery.page = 1;
|
||||||
|
this.getList();
|
||||||
|
},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
|
@ -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': '查询记录',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
|
@ -3,14 +3,20 @@ from django.db import models
|
||||||
from django.db.models.fields import related
|
from django.db.models.fields import related
|
||||||
from utils.model import BaseModel
|
from utils.model import BaseModel
|
||||||
from apps.system.models import Organization, User
|
from apps.system.models import Organization, User
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
from django.contrib.postgres.fields import JSONField
|
||||||
|
|
||||||
# class GetRecord(BaseModel):
|
class QueryRecord(BaseModel):
|
||||||
# user = models.ForeignKey(User, related_name='record_user', on_delete=models.CASCADE)
|
user = models.ForeignKey(User, related_name='record_user', on_delete=models.CASCADE)
|
||||||
# path = models.CharField('访问地址', max_length=100)
|
path = models.CharField('访问地址', max_length=200)
|
||||||
# ip = models.CharField('IP地址', max_length=100)
|
ip = models.CharField('IP地址', max_length=200)
|
||||||
# method = models.CharField('方法', max_length=100, default='GET')
|
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):
|
class CMA(BaseModel):
|
||||||
|
|
|
@ -2,6 +2,23 @@ from rest_framework import serializers
|
||||||
from .models import *
|
from .models import *
|
||||||
from apps.system.serializers import OrganizationSerializer
|
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):
|
class CMASerializer(serializers.ModelSerializer):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
from rest_framework import routers
|
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 = routers.DefaultRouter()
|
||||||
router.register('cma', CMAViewSet, basename="cma")
|
router.register('cma', CMAViewSet, basename="cma")
|
||||||
|
@ -8,6 +8,7 @@ router.register('cnas', CNASViewSet, basename="cnas")
|
||||||
router.register('qualification', QualificationViewSet, basename="qualification")
|
router.register('qualification', QualificationViewSet, basename="qualification")
|
||||||
router.register('qualificationother', QualificationotherViewSet, basename="qualificationother")
|
router.register('qualificationother', QualificationotherViewSet, basename="qualificationother")
|
||||||
router.register('inspection', InspectionViewSet, basename="inspection")
|
router.register('inspection', InspectionViewSet, basename="inspection")
|
||||||
|
router.register('queryrecord', QueryRecordListViewSet, basename="queryrecord")
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', include(router.urls))
|
path('', include(router.urls))
|
||||||
]
|
]
|
|
@ -1,5 +1,6 @@
|
||||||
from django.shortcuts import render
|
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 .models import *
|
||||||
from .serializers import *
|
from .serializers import *
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
|
@ -25,14 +26,20 @@ class RecordMixin():
|
||||||
`request.user` or `request.auth` is accessed.
|
`request.user` or `request.auth` is accessed.
|
||||||
"""
|
"""
|
||||||
user = request.user
|
user = request.user
|
||||||
# if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
# print(json.dumps(request.query_params), request.method, request.path)
|
QueryRecord.objects.create(user=user,path=request.path,ip=request.META.get('REMOTE_ADDR'),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
|
||||||
|
|
||||||
class CMAViewSet(RecordMixin, ModelViewSet):
|
class CMAViewSet(RecordMixin, ModelViewSet):
|
||||||
"""
|
"""
|
||||||
CMA检测能力:增删改查
|
CMA检测能力:增删改查
|
||||||
"""
|
"""
|
||||||
perms_map = {'get': '*', 'post': 'cma_create',
|
perms_map = {'get': 'cma_view', 'post': 'cma_create',
|
||||||
'put': 'cma_update', 'delete': 'cma_delete'}
|
'put': 'cma_update', 'delete': 'cma_delete'}
|
||||||
queryset = CMA.objects.all()
|
queryset = CMA.objects.all()
|
||||||
serializer_class = CMASerializer
|
serializer_class = CMASerializer
|
||||||
|
@ -136,11 +143,11 @@ class CMAViewSet(RecordMixin, ModelViewSet):
|
||||||
return Response(status = status.HTTP_200_OK)
|
return Response(status = status.HTTP_200_OK)
|
||||||
|
|
||||||
from django.db.models.query import QuerySet
|
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'}
|
'put': 'qualification_update', 'delete': 'qualification_delete'}
|
||||||
queryset = Qualification.objects.all()
|
queryset = Qualification.objects.all()
|
||||||
serializer_class = QualificationSerializer
|
serializer_class = QualificationSerializer
|
||||||
|
@ -187,11 +194,11 @@ class QualificationViewSet(ModelViewSet):
|
||||||
return Response(status = status.HTTP_200_OK)
|
return Response(status = status.HTTP_200_OK)
|
||||||
else:
|
else:
|
||||||
return Response('不支持非xlsx格式', status = status.HTTP_400_BAD_REQUEST)
|
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'}
|
'put': 'qualificationother_update', 'delete': 'qualificationother_delete'}
|
||||||
queryset = Qualificationother.objects.all()
|
queryset = Qualificationother.objects.all()
|
||||||
serializer_class = QualificationotherSerializer
|
serializer_class = QualificationotherSerializer
|
||||||
|
@ -220,11 +227,11 @@ class QualificationotherViewSet(PageOrNot,ModelViewSet):
|
||||||
ret.append({'text':i[group_by]+'('+ str(i['count']) +')','value':i[group_by]})
|
ret.append({'text':i[group_by]+'('+ str(i['count']) +')','value':i[group_by]})
|
||||||
return Response(ret)
|
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'}
|
'put': 'inspection_update', 'delete': 'inspection_delete'}
|
||||||
queryset = Inspection.objects.all()
|
queryset = Inspection.objects.all()
|
||||||
serializer_class = InspectionSerializer
|
serializer_class = InspectionSerializer
|
||||||
|
@ -292,11 +299,11 @@ class InspectionViewSet(ModelViewSet):
|
||||||
return Response(status = status.HTTP_200_OK)
|
return Response(status = status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
class CNASViewSet(ModelViewSet):
|
class CNASViewSet(RecordMixin, ModelViewSet):
|
||||||
"""
|
"""
|
||||||
CNAS检测能力:增删改查
|
CNAS检测能力:增删改查
|
||||||
"""
|
"""
|
||||||
perms_map = {'get': '*', 'post': 'cnas_create',
|
perms_map = {'get': 'cma_view', 'post': 'cnas_create',
|
||||||
'put': 'cnas_update', 'delete': 'cnas_delete'}
|
'put': 'cnas_update', 'delete': 'cnas_delete'}
|
||||||
queryset = CNAS.objects.all()
|
queryset = CNAS.objects.all()
|
||||||
serializer_class = CNASSerializer
|
serializer_class = CNASSerializer
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
from .settings import *
|
from .settings import *
|
||||||
DEBUG = False
|
DEBUG = True
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
'ENGINE': 'django.db.backends.sqlite3',
|
'ENGINE': 'django.db.backends.postgresql',
|
||||||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
'NAME': 'cma',
|
||||||
|
'USER': 'cma',
|
||||||
|
'PASSWORD': 'cma123',
|
||||||
|
'HOST': '172.16.80.102',
|
||||||
|
'PORT': '5432',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue