Browse Source

[commit] commit log folder

master
fajiao 2 years ago
parent
commit
3708ed8018
  1. 45
      EC.Web/Areas/LR_SystemModule/Views/Log/Form.cshtml
  2. 196
      EC.Web/Areas/LR_SystemModule/Views/Log/Index.cshtml
  3. 78
      learun.core/learun.application/BaseInfo/Log/LogBLL.cs
  4. 146
      learun.core/learun.application/BaseInfo/Log/LogService.cs
  5. 70
      learun.core/learun.application/TaskScheduling/Log/TSLogBLL.cs
  6. 113
      learun.core/learun.application/TaskScheduling/Log/TSLogService.cs
  7. 116
      learun.core/learun.iapplication/BaseInfo/Log/LogEntity.cs
  8. 58
      learun.core/learun.iapplication/BaseInfo/Log/LogIBLL.cs

45
EC.Web/Areas/LR_SystemModule/Views/Log/Form.cshtml

@ -0,0 +1,45 @@
@{
ViewBag.Title = "清空日志";
Layout = "~/Views/Shared/_Form.cshtml";
}
<div class="lr-form-wrap" id="form">
<div class="col-xs-12 lr-form-item">
<div class="lr-form-item-title">日志保留时间</div>
<div id="keepTime">
<ul>
<li data-value="7">保留近一周</li>
<li data-value="1">保留近一个月</li>
<li data-value="3">保留近三个月</li>
<li data-value="0">不保留,全部删除</li>
</ul>
</div>
</div>
</div>
<script>
var categoryId = request('categoryId');
var acceptClick;
var bootstrap = function ($, learun) {
"use strict";
var page = {
init: function () {
$('#keepTime').lrselect({maxHeight:75,placeholder:false}).lrselectSet(7);
}
};
// 保存数据
acceptClick = function (callBack) {
if (!$('#form').lrValidform()) {
return false;
}
var postData = $('#form').lrGetFormData();
postData['categoryId'] = categoryId;
$.lrSaveForm(top.$.rootUrl + '/LR_SystemModule/Log/SaveRemoveLog', postData, function (res) {
// 保存成功后才回调
if (!!callBack) {
callBack();
}
});
};
page.init();
}
</script>

196
EC.Web/Areas/LR_SystemModule/Views/Log/Index.cshtml

@ -0,0 +1,196 @@
@{
ViewBag.Title = "日志管理";
Layout = "~/Views/Shared/_Index.cshtml";
}
<div id="lr_layout" class="lr-layout lr-layout-left-center">
<div class="lr-layout-left">
<div class="lr-layout-wrap lr-layout-wrap-notitle" style="padding-top:10px;">
<div class="lr-layout-body">
<ul class="lr-left-list" id="lr_left_list">
<li class="active lrlg" data-value="1">登录日志</li>
<li data-value="2" class="lrlg" >访问日志</li>
<li data-value="3" class="lrlg" >操作日志</li>
<li data-value="4" class="lrlg" >异常日志</li>
</ul>
</div>
</div>
</div>
<div class="lr-layout-center">
<div class="lr-layout-wrap lr-layout-wrap-notitle">
<div class="lr-layout-tool">
<div class="lr-layout-tool-left">
<div class="lr-layout-tool-item">
<div id="datesearch" class="datetime"></div>
</div>
<div class="lr-layout-tool-item">
<input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" />
</div>
<div class="lr-layout-tool-item">
<a id="btn_Search" class="btn btn-primary btn-sm"><i class="fa fa-search"></i>&nbsp;<span class="lrlg">查询</span></a>
</div>
</div>
<div class="lr-layout-tool-right">
<div class=" btn-group btn-group-sm">
<a id="lr_refresh" class="btn btn-default"><i class="fa fa-refresh"></i></a>
</div>
<div class=" btn-group btn-group-sm" learun-authorize="yes">
<a id="lr_removelog" class="btn btn-default"><i class="fa fa-eraser"></i>&nbsp;<span class="lrlg">清空</span></a>
<a id="lr_export" class="btn btn-default"><i class="fa fa-sign-out"></i>&nbsp;<span class="lrlg">导出</span></a>
</div>
</div>
</div>
<div class="lr-layout-body" id="gridtable">
</div>
</div>
</div>
</div>
<script>
var bootstrap = function ($, learun) {
"use strict";
var categoryId = '1';
var logbegin = '';
var logend = '';
var refreshGirdData = function () {
$('#gridtable').jfGridSet('reload');
}
var page = {
init: function () {
page.initleft();
page.initGrid();
page.bind();
},
bind: function () {
$('.datetime').each(function () {
$(this).lrdate({
dfdata: [
{ name: '今天', begin: function () { return learun.getDate('yyyy-MM-dd 00:00:00') }, end: function () { return learun.getDate('yyyy-MM-dd 23:59:59') } },
{ name: '近7天', begin: function () { return learun.getDate('yyyy-MM-dd 00:00:00', 'd', -6) }, end: function () { return learun.getDate('yyyy-MM-dd 23:59:59') } },
{ name: '近1个月', begin: function () { return learun.getDate('yyyy-MM-dd 00:00:00', 'm', -1) }, end: function () { return learun.getDate('yyyy-MM-dd 23:59:59') } },
{ name: '近3个月', begin: function () { return learun.getDate('yyyy-MM-dd 00:00:00', 'm', -3) }, end: function () { return learun.getDate('yyyy-MM-dd 23:59:59') } },
],
// 月
mShow: false,
premShow: false,
// 季度
jShow: false,
prejShow: false,
// 年
ysShow: false,
yxShow: false,
preyShow: false,
yShow: false,
// 默认
dfvalue: '1',
selectfn: function (begin, end) {
logbegin = begin;
logend = end;
page.search();
}
});
});
// 查询
$('#btn_Search').on('click', function () {
var keyword = $('#txt_Keyword').val();
page.search({ keyword: keyword });
});
// 刷新
$('#lr_refresh').on('click', function () {
location.reload();
});
// 清空
$('#lr_removelog').on('click', function () {
learun.layerForm({
id: 'form',
title: '清空',
url: top.$.rootUrl + '/LR_SystemModule/Log/Form?categoryId=' + categoryId,
height: 200,
width: 400,
callBack: function (id) {
return top[id].acceptClick(refreshGirdData);
}
});
});
// 导出
$('#lr_export').on('click', function () {
learun.layerForm({
id: "ExcelExportForm",
title: '导出Excel数据',
url: top.$.rootUrl + '/Utility/ExcelExportForm?gridId=gridtable',
width: 500,
height: 380,
callBack: function (id) {
return top[id].acceptClick();
},
btn: ['导出Excel', '关闭']
});
});
},
initleft: function () {
$('#lr_left_list li').on('click', function () {
var $this = $(this);
var $parent = $this.parent();
$parent.find('.active').removeClass('active');
$this.addClass('active');
categoryId = $this.attr('data-value');
page.search();
});
},
initGrid: function () {
$('#gridtable').jfGrid({
url: top.$.rootUrl + '/LR_SystemModule/Log/GetPageList',
headData: [
{
label: "操作时间", name: "F_OperateTime",width: 135, align: "left",
formatter: function (cellvalue) {
return learun.formatDate(cellvalue, 'yyyy-MM-dd hh:mm:ss');
}
},
{ label: "操作用户", name: "F_OperateAccount",width: 80, align: "center" },
{
label: "IP地址", name: "F_IPAddress", width: 100, align: "left",
formatter: function (cellvalue) {
if (cellvalue == '::1') {
return "本地";
} else {
return cellvalue;
}
}
},
{ label: "系统功能", name: "F_Module", width: 160, align: "left" },
{ label: "操作类型", name: "F_OperateType", width: 65, align: "center" },
{
label: "执行结果", name: "F_ExecuteResult", width: 65, align: "center",
formatter: function (cellvalue) {
if (cellvalue == '1') {
return "<span class=\"label label-success\">成功</span>";
} else {
return "<span class=\"label label-danger\">失败</span>";
}
}
},
{ label: "执行结果描述", name: "F_ExecuteResultJson", width: 300, align: "left" }
],
mainId: 'F_ItemDetailId',
isPage: true,
rows:200,
sidx: 'F_OperateTime DESC'
});
},
search: function (param) {
param = param || {};
param.CategoryId = categoryId;
param.StartTime = logbegin;
param.EndTime = logend;
$('#gridtable').jfGridSet('reload', { queryJson: JSON.stringify(param) });
}
};
page.init();
}
</script>

78
learun.core/learun.application/BaseInfo/Log/LogBLL.cs

@ -0,0 +1,78 @@
using learun.iapplication;
using learun.util;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace learun.application
{
/// <summary>
/// 版 本 EasyCode EC管理后台
/// Copyright (c) 2019-present EC管理有限公司
/// 创建人:tobin
/// 日 期:2019.09.25
/// 描 述:系统日志
/// </summary>
public class LogBLL : LogIBLL
{
private readonly LogService service = new LogService();
#region 获取数据
/// <summary>
/// 日志列表
/// </summary>
/// <param name="pagination">分页</param>
/// <param name="queryJson">查询参数</param>
/// <param name="userId">用户主键</param>
/// <returns></returns>
public Task<IEnumerable<LogEntity>> GetPageList(Pagination pagination, string queryJson, string userId)
{
return service.GetPageList(pagination, queryJson, userId);
}
#endregion 获取数据
#region 提交数据
/// <summary>
/// 清空日志
/// </summary>
/// <param name="categoryId">日志分类Id</param>
/// <param name="keepTime">保留时间段内</param>
public async Task Remove(int categoryId, string keepTime)
{
await service.Remove(categoryId, keepTime);
}
/// <summary>
/// 写日志
/// </summary>
/// <param name="logEntity">对象</param>
public async Task Write(LogEntity logEntity)
{
await service.Write(logEntity);
}
#endregion 提交数据
#region 扩展方法
/// <summary>
/// 生成异常信息
/// </summary>
/// <param name="ex">异常对象</param>
/// <returns></returns>
public string ExceptionFormat(Exception ex)
{
StringBuilder strInfo = new StringBuilder();
strInfo.Append("1. 异常: " + ex.Message + "\r\n");
strInfo.Append("2. 来源: " + ex.Source + "\r\n");
strInfo.Append("3. 实例: " + ex.StackTrace + "\r\n");
return strInfo.ToString();
}
#endregion 扩展方法
}
}

146
learun.core/learun.application/BaseInfo/Log/LogService.cs

@ -0,0 +1,146 @@
using learun.iapplication;
using learun.util;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace learun.application
{
/// <summary>
/// 版 本 EasyCode EC管理后台
/// Copyright (c) 2019-present EC管理有限公司
/// 创建人:tobin
/// 日 期:2019.09.25
/// 描 述:系统日志数据库服务类
/// </summary>
public class LogService : ServiceBase
{
#region 获取数据
/// <summary>
/// 日志列表
/// </summary>
/// <param name="pagination">分页</param>
/// <param name="queryJson">查询参数</param>
/// <param name="userId">操作用户Id</param>
/// <returns></returns>
public Task<IEnumerable<LogEntity>> GetPageList(Pagination pagination, string queryJson, string userId)
{
var strSql = new StringBuilder();
strSql.Append("SELECT * FROM lr_base_log t WHERE 1=1");
var queryParam = queryJson.ToJObject();
int categoryId = 0;
DateTime startTime = DateTime.Now;
DateTime endTime = DateTime.Now;
string operateUserId = null;
string operateAccount = null;
string operateType = null;
string module = null;
string keyword = null;
// 日志分类
if (!queryParam["CategoryId"].IsEmpty())
{
categoryId = queryParam["CategoryId"].ToInt();
strSql.Append(" AND F_CategoryId = @categoryId ");
}
// 操作时间
if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
{
startTime = queryParam["StartTime"].ToDate();
endTime = queryParam["EndTime"].ToDate();
strSql.Append(" AND( F_OperateTime >= @startTime AND F_OperateTime <= @endTime )");
}
// 操作用户Id
if (!queryParam["OperateUserId"].IsEmpty())
{
operateUserId = queryParam["OperateUserId"].ToString();
strSql.Append(" AND F_OperateUserId = @operateUserId ");
}
// 操作用户账户
if (!queryParam["OperateAccount"].IsEmpty())
{
operateAccount = "%" + queryParam["OperateAccount"].ToString() + "%";
strSql.Append(" AND F_OperateAccount like @operateAccount ");
}
// 操作类型
if (!queryParam["OperateType"].IsEmpty())
{
operateType = queryParam["OperateType"].ToString();
strSql.Append(" AND F_OperateType = @operateType ");
}
// 功能模块
if (!queryParam["Module"].IsEmpty())
{
module = queryParam["Module"].ToString();
strSql.Append(" AND F_Module = @module ");
}
// 登录用户id
if (!string.IsNullOrEmpty(userId))
{
strSql.Append(" AND F_OperateUserId = @userId ");
}
// 关键字
if (!queryParam["keyword"].IsEmpty())
{
keyword = "%" + queryParam["keyword"] + "%";
strSql.Append(" AND (F_Module like @keyword || F_OperateType like @keyword || F_IPAddress like @keyword )");
}
return BaseRepository().FindList<LogEntity>(strSql.ToString(), new { categoryId, startTime, endTime, operateUserId, operateAccount, operateType, module, userId, keyword }, pagination);
}
/// <summary>
/// 日志实体
/// </summary>
/// <param name="keyValue">主键值</param>
/// <returns></returns>
public Task<LogEntity> GetEntity(string keyValue)
{
return BaseRepository().FindEntity<LogEntity>(keyValue);
}
#endregion 获取数据
#region 提交数据
/// <summary>
/// 清空日志
/// </summary>
/// <param name="categoryId">日志分类Id</param>
/// <param name="keepTime">保留时间段内</param>
public async Task Remove(int categoryId, string keepTime)
{
DateTime operateTime = DateTime.Now;
if (keepTime == "7")//保留近一周
{
operateTime = DateTime.Now.AddDays(-7);
}
else if (keepTime == "1")//保留近一个月
{
operateTime = DateTime.Now.AddMonths(-1);
}
else if (keepTime == "3")//保留近三个月
{
operateTime = DateTime.Now.AddMonths(-3);
}
await BaseRepository().ExecuteSql(" Delete From lr_base_log where F_CategoryId = @categoryId AND F_OperateTime <= @operateTime ", new { categoryId, operateTime });
}
/// <summary>
/// 写日志
/// </summary>
/// <param name="logEntity">对象</param>
public async Task Write(LogEntity logEntity)
{
logEntity.F_LogId = Guid.NewGuid().ToString();
logEntity.F_OperateTime = DateTime.Now;
logEntity.F_DeleteMark = 0;
logEntity.F_EnabledMark = 1;
await BaseRepository().Insert(logEntity);
}
#endregion 提交数据
}
}

70
learun.core/learun.application/TaskScheduling/Log/TSLogBLL.cs

@ -0,0 +1,70 @@
using ce.autofac.extension;
using learun.iapplication;
using learun.util;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace learun.application
{
/// <summary>
/// 版 本 EasyCode EC管理后台
/// Copyright (c) 2019-present EC管理有限公司
/// 创建人:tobin
/// 日 期:2019.11.01
/// 描 述:任务执行日志
/// </summary>
public class TSLogBLL : BLLBase, TSLogIBLL, BLL
{
private readonly TSLogService logService = new TSLogService();
#region 获取数据
/// <summary>
/// 获取页面显示列表数据
/// </summary>
/// <param name="pagination">分页参数</param>
/// <param name="queryJson">查询参数</param>
/// <returns></returns>
public Task<IEnumerable<TSLogEntity>> GetPageList(Pagination pagination, string queryJson)
{
return logService.GetPageList(pagination, queryJson);
}
/// <summary>
/// 获取LR_TS_Log表实体数据
/// </summary>
/// <param name="keyValue">主键</param>
/// <returns></returns>
public Task<TSLogEntity> GetLogEntity(string keyValue)
{
return logService.GetLogEntity(keyValue);
}
#endregion 获取数据
#region 提交数据
/// <summary>
/// 删除实体数据
/// </summary>
/// <param name="keyValue">主键</param>
/// <returns></returns>
public async Task DeleteEntity(string keyValue)
{
await logService.DeleteEntity(keyValue);
}
/// <summary>
/// 保存实体数据(新增、修改)
/// </summary>
/// <param name="keyValue">主键</param>
/// <param name="entity">实体</param>
/// <returns></returns>
public async Task SaveEntity(string keyValue, TSLogEntity entity)
{
await logService.SaveEntity(keyValue, entity);
}
#endregion 提交数据
}
}

113
learun.core/learun.application/TaskScheduling/Log/TSLogService.cs

@ -0,0 +1,113 @@
using learun.iapplication;
using learun.util;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace learun.application
{
/// <summary>
/// 版 本 EasyCode EC管理后台
/// Copyright (c) 2019-present EC管理有限公司
/// 创建人:tobin
/// 日 期:2019.11.01
/// 描 述:任务执行日志
/// </summary>
public class TSLogService : ServiceBase
{
#region 获取数据
/// <summary>
/// 获取页面显示列表数据
/// </summary>
/// <param name="pagination">分页参数</param>
/// <param name="queryJson">查询参数</param>
/// <returns></returns>
public Task<IEnumerable<TSLogEntity>> GetPageList(Pagination pagination, string queryJson)
{
var strSql = new StringBuilder();
strSql.Append(@"
SELECT
t.F_Id,
t.F_Name,
t.F_ExecuteResult,
t.F_CreateDate,
t.F_Des
FROM
LR_TS_Log t
");
strSql.Append(" WHERE 1=1 ");
var queryParam = queryJson.ToJObject();
DateTime startTime = DateTime.Now, endTime = DateTime.Now;
if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
{
startTime = queryParam["StartTime"].ToDate();
endTime = queryParam["EndTime"].ToDate();
strSql.Append(" AND ( t.F_CreateDate >= @startTime AND t.F_CreateDate <= @endTime ) ");
}
string keyword = "";
if (!queryParam["keyword"].IsEmpty())
{
keyword = "%" + queryParam["keyword"].ToString() + "%";
strSql.Append(" AND ( t.F_Name like @keyword ) ");
}
int executeResult = 1;
if (!queryParam["executeResult"].IsEmpty())
{
executeResult = Convert.ToInt32(queryParam["executeResult"].ToString());
strSql.Append(" AND t.F_ExecuteResult = @executeResult ");
}
return this.BaseRepository().FindList<TSLogEntity>(strSql.ToString(), new { startTime, endTime, keyword, executeResult }, pagination);
}
/// <summary>
/// 获取LR_TS_Log表实体数据
/// </summary>
/// <param name="keyValue">主键</param>
/// <returns></returns>
public Task<TSLogEntity> GetLogEntity(string keyValue)
{
return this.BaseRepository().FindEntityByKey<TSLogEntity>(keyValue);
}
#endregion 获取数据
#region 提交数据
/// <summary>
/// 删除实体数据
/// </summary>
/// <param name="keyValue">主键</param>
/// <returns></returns>
public async Task DeleteEntity(string keyValue)
{
await this.BaseRepository().DeleteAny<TSLogEntity>(new { F_Id = keyValue });
}
/// <summary>
/// 保存实体数据(新增、修改)
/// </summary>
/// <param name="keyValue">主键</param>
/// <param name="entity">实体</param>
/// <returns></returns>
public async Task SaveEntity(string keyValue, TSLogEntity entity)
{
if (!string.IsNullOrEmpty(keyValue))
{
entity.F_Id = keyValue;
await this.BaseRepository().Update(entity);
}
else
{
entity.F_Id = Guid.NewGuid().ToString();
entity.F_CreateDate = DateTime.Now;
await this.BaseRepository().Insert(entity);
}
}
#endregion 提交数据
}
}

116
learun.core/learun.iapplication/BaseInfo/Log/LogEntity.cs

@ -0,0 +1,116 @@
using cd.dapper.extension;
using System;
namespace learun.iapplication
{
/// <summary>
/// 版 本 EasyCode EC管理后台
/// Copyright (c) 2019-present EC管理有限公司
/// 创建人:tobin
/// 日 期:2019.09.25
/// 描 述:系统日志数据库实体类
/// </summary>
[Table("lr_base_log")]
public class LogEntity
{
#region 实体成员
/// <summary>
/// 日志主键
/// </summary>
[Key]
public string F_LogId { get; set; }
/// <summary>
/// 分类Id 1-登陆2-访问3-操作4-异常
/// </summary>
public int? F_CategoryId { get; set; }
/// <summary>
/// 来源对象主键
/// </summary>
public string F_SourceObjectId { get; set; }
/// <summary>
/// 来源日志内容
/// </summary>
public string F_SourceContentJson { get; set; }
/// <summary>
/// 操作时间
/// </summary>
public DateTime? F_OperateTime { get; set; }
/// <summary>
/// 操作用户Id
/// </summary>
public string F_OperateUserId { get; set; }
/// <summary>
/// 操作用户
/// </summary>
public string F_OperateAccount { get; set; }
/// <summary>
/// 操作类型Id
/// </summary>
public string F_OperateTypeId { get; set; }
/// <summary>
/// 操作类型
/// </summary>
public string F_OperateType { get; set; }
/// <summary>
/// 系统功能
/// </summary>
public string F_Module { get; set; }
/// <summary>
/// IP地址
/// </summary>
public string F_IPAddress { get; set; }
/// <summary>
/// IP地址所在城市
/// </summary>
public string F_IPAddressName { get; set; }
/// <summary>
/// 主机
/// </summary>
public string F_Host { get; set; }
/// <summary>
/// 浏览器
/// </summary>
public string F_Browser { get; set; }
/// <summary>
/// 执行结果状态
/// </summary>
public int? F_ExecuteResult { get; set; }
/// <summary>
/// 执行结果信息
/// </summary>
public string F_ExecuteResultJson { get; set; }
/// <summary>
/// 备注
/// </summary>
public string F_Description { get; set; }
/// <summary>
/// 删除标记
/// </summary>
public int? F_DeleteMark { get; set; }
/// <summary>
/// 有效标志
/// </summary>
public int? F_EnabledMark { get; set; }
#endregion 实体成员
}
}

58
learun.core/learun.iapplication/BaseInfo/Log/LogIBLL.cs

@ -0,0 +1,58 @@
using learun.util;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace learun.iapplication
{
/// <summary>
/// 版 本 EasyCode EC管理后台
/// Copyright (c) 2019-present EC管理有限公司
/// 创建人:tobin
/// 日 期:2019.09.25
/// 描 述:系统日志
/// </summary>
public interface LogIBLL
{
#region 获取数据
/// <summary>
/// 日志列表
/// </summary>
/// <param name="pagination">分页</param>
/// <param name="queryJson">查询参数</param>
/// <param name="userId">用户主键</param>
/// <returns></returns>
Task<IEnumerable<LogEntity>> GetPageList(Pagination pagination, string queryJson, string userId);
#endregion 获取数据
#region 提交数据
/// <summary>
/// 清空日志
/// </summary>
/// <param name="categoryId">日志分类Id</param>
/// <param name="keepTime">保留时间段内</param>
Task Remove(int categoryId, string keepTime);
/// <summary>
/// 写日志
/// </summary>
/// <param name="logEntity">对象</param>
Task Write(LogEntity logEntity);
#endregion 提交数据
#region 扩展方法
/// <summary>
/// 生成异常信息
/// </summary>
/// <param name="ex">异常对象</param>
/// <returns></returns>
string ExceptionFormat(Exception ex);
#endregion 扩展方法
}
}
Loading…
Cancel
Save