feat: 增加SQL日志界面

This commit is contained in:
Argo Zhang 2019-09-23 01:14:11 +08:00 committed by Argo Zhang
parent 6821f4ae74
commit 04ed934d82
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
8 changed files with 184 additions and 2 deletions

View File

@ -53,6 +53,12 @@ namespace Bootstrap.Admin.Controllers
/// <returns></returns>
public ActionResult Logs() => View(new NavigatorBarModel(this));
/// <summary>
///
/// </summary>
/// <returns></returns>
public ActionResult SQL() => View(new NavigatorBarModel(this));
/// <summary>
///
/// </summary>

View File

@ -0,0 +1,26 @@
using Bootstrap.Admin.Query;
using Bootstrap.DataAccess;
using Longbow.Web.Mvc;
using Microsoft.AspNetCore.Mvc;
namespace Bootstrap.Admin.Controllers.Api
{
/// <summary>
/// SQL 语句执行日志 webapi
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class SQLController : ControllerBase
{
/// <summary>
/// 获取执行日志数据
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
[HttpGet]
public QueryData<DBLog> Get([FromQuery]QuerySQLOption value)
{
return value.RetrieveData();
}
}
}

View File

@ -0,0 +1,40 @@
using Bootstrap.DataAccess;
using Longbow.Web.Mvc;
using System;
namespace Bootstrap.Admin.Query
{
/// <summary>
/// SQL执行查询配置类
/// </summary>
public class QuerySQLOption : PaginationOption
{
/// <summary>
/// 获得/设置 用户登录名
/// </summary>
public string UserName { get; set; }
/// <summary>
/// 获得/设置 开始时间
/// </summary>
public DateTime? OperateTimeStart { get; set; }
/// <summary>
/// 获得/设置 结束时间
/// </summary>
public DateTime? OperateTimeEnd { get; set; }
/// <summary>
/// 查询数据方法
/// </summary>
/// <returns></returns>
public QueryData<DBLog> RetrieveData()
{
var data = LogHelper.RetrieveDBLogs(this, OperateTimeStart, OperateTimeEnd, UserName);
var ret = new QueryData<DBLog>();
ret.total = data.TotalItems;
ret.rows = data.Items;
return ret;
}
}
}

View File

@ -52,7 +52,7 @@ namespace Microsoft.Extensions.DependencyInjection
TaskServicesManager.GetOrAdd("禁用任务", token => Task.Delay(1000)).Status = SchedulerStatus.Disabled;
// 真实任务负责批次写入数据执行脚本到日志中
TaskServicesManager.GetOrAdd<LogHelper.DbLogTask>("数据库脚本执行日志", TriggerBuilder.Build(Cron.Minutely()));
TaskServicesManager.GetOrAdd<LogHelper.DbLogTask>("SQL日志", TriggerBuilder.Build(Cron.Minutely()));
});
}
}

View File

@ -0,0 +1,80 @@
@model NavigatorBarModel
@{
ViewBag.Title = "SQL日志";
}
@section css {
<environment include="Development">
<link href="~/lib/datetimepicker/css//bootstrap-datetimepicker.css" rel="stylesheet" />
<link href="~/lib/bootstrap-table/bootstrap-table.css" rel="stylesheet" />
</environment>
<environment exclude="Development">
<link href="~/lib/datetimepicker/css//bootstrap-datetimepicker.min.css" rel="stylesheet" />
<link href="~/lib/bootstrap-table/bootstrap-table.min.css" rel="stylesheet" />
</environment>
}
@section javascript {
<environment include="Development">
<script src="~/lib/bootstrap-table/bootstrap-table.js"></script>
<script src="~/lib/bootstrap-table/extensions/export/bootstrap-table-export.js"></script>
<script src="~/lib/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
<script src="~/lib/tablexport/tableExport.js"></script>
<script src="~/lib/datetimepicker/js/bootstrap-datetimepicker.js"></script>
</environment>
<environment exclude="Development">
<script src="~/lib/bootstrap-table/bootstrap-table.min.js"></script>
<script src="~/lib/bootstrap-table/extensions/export/bootstrap-table-export.min.js"></script>
<script src="~/lib/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="~/lib/tablexport/tableExport.min.js"></script>
<script src="~/lib/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
</environment>
<script src="~/lib/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="~/js/sql.js" asp-append-version="true"></script>
}
<div class="card">
<div class="card-header">查询条件</div>
<div class="card-body">
<form class="form-inline">
<div class="row">
<div class="form-group col-sm-6 col-lg-auto">
<label class="control-label" for="txt_operate_start">起始时间</label>
<div class="input-group date">
<input id="txt_operate_start" class="form-control" size="16" type="text" value="@DateTime.Today.ToString("yyyy-MM-dd")" readonly>
<div class="input-group-append input-group-addon">
<div class="input-group-text"><span class="fa fa-times"></span></div>
</div>
<div class="input-group-append input-group-addon">
<div class="input-group-text"><span class="fa fa-calendar"></span></div>
</div>
</div>
</div>
<div class="form-group col-sm-6 col-lg-auto">
<label class="control-label" for="txt_operate_end">终止时间</label>
<div class="input-group date">
<input id="txt_operate_end" class="form-control" size="16" type="text" value="" readonly>
<div class="input-group-append input-group-addon">
<div class="input-group-text"><span class="fa fa-times"></span></div>
</div>
<div class="input-group-append input-group-addon">
<div class="input-group-text"><span class="fa fa-calendar"></span></div>
</div>
</div>
</div>
<div class="form-group col-sm-6 col-lg-auto">
<label class="control-label" for="txt_username">登录用户</label>
<input type="text" class="form-control" id="txt_username" />
</div>
<div class="form-group col-sm-6 col-lg-auto flex-sm-fill justify-content-sm-end align-self-sm-end">
<button type="button" id="btn_query" class="btn btn-primary btn-fill"><i class="fa fa-search" aria-hidden="true"></i><span>查询</span></button>
</div>
</div>
</form>
</div>
</div>
<div class="card">
<div class="card-header">
查询结果
</div>
<div class="card-body">
<table></table>
</div>
</div>

View File

@ -0,0 +1,20 @@
$(function () {
var url = 'api/SQL';
var $data = $('#requestData');
var $dialog = $('#dialogRequestData');
$('.card-body table').smartTable({
url: url,
sortName: 'LogTime',
sortOrder: 'desc',
queryParams: function (params) { return $.extend(params, { UserName: $("#txt_username").val(), OperateTimeStart: $("#txt_operate_start").val(), OperateTimeEnd: $("#txt_operate_end").val() }); },
columns: [
{ title: "所属用户", field: "UserName", sortable: true },
{ title: "执行时间", field: "LogTime", sortable: true },
{ title: "脚本内容", field: "SQL", sortable: false }
],
exportOptions: {
fileName: "SQL日志数据"
}
});
});

View File

@ -31,7 +31,7 @@ namespace Bootstrap.DataAccess
public DateTime LogTime { get; set; }
/// <summary>
/// 查询所有操作日志信息
/// 查询所有SQL日志信息
/// </summary>
/// <param name="po"></param>
/// <param name="startTime"></param>

View File

@ -54,6 +54,16 @@ namespace Bootstrap.DataAccess
}
});
/// <summary>
/// 查询所有SQL日志信息
/// </summary>
/// <param name="op"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <param name="userName"></param>
/// <returns></returns>
public static Page<DBLog> RetrieveDBLogs(PaginationOption op, DateTime? startTime, DateTime? endTime, string userName) => DbContextManager.Create<DBLog>().RetrievePages(op, startTime, endTime, userName);
/// <summary>
/// 数据库脚本执行日志任务实体类
/// </summary>