From 3708ed801876d464d394a8173600e11c6d38dd99 Mon Sep 17 00:00:00 2001
From: fajiao <1519100073@qq.com>
Date: Wed, 14 Jun 2023 17:09:21 +0800
Subject: [PATCH] [commit] commit log folder
---
.../LR_SystemModule/Views/Log/Form.cshtml | 45 ++++
.../LR_SystemModule/Views/Log/Index.cshtml | 196 ++++++++++++++++++
.../learun.application/BaseInfo/Log/LogBLL.cs | 78 +++++++
.../BaseInfo/Log/LogService.cs | 146 +++++++++++++
.../TaskScheduling/Log/TSLogBLL.cs | 70 +++++++
.../TaskScheduling/Log/TSLogService.cs | 113 ++++++++++
.../BaseInfo/Log/LogEntity.cs | 116 +++++++++++
.../BaseInfo/Log/LogIBLL.cs | 58 ++++++
8 files changed, 822 insertions(+)
create mode 100644 EC.Web/Areas/LR_SystemModule/Views/Log/Form.cshtml
create mode 100644 EC.Web/Areas/LR_SystemModule/Views/Log/Index.cshtml
create mode 100644 learun.core/learun.application/BaseInfo/Log/LogBLL.cs
create mode 100644 learun.core/learun.application/BaseInfo/Log/LogService.cs
create mode 100644 learun.core/learun.application/TaskScheduling/Log/TSLogBLL.cs
create mode 100644 learun.core/learun.application/TaskScheduling/Log/TSLogService.cs
create mode 100644 learun.core/learun.iapplication/BaseInfo/Log/LogEntity.cs
create mode 100644 learun.core/learun.iapplication/BaseInfo/Log/LogIBLL.cs
diff --git a/EC.Web/Areas/LR_SystemModule/Views/Log/Form.cshtml b/EC.Web/Areas/LR_SystemModule/Views/Log/Form.cshtml
new file mode 100644
index 0000000..523d5b3
--- /dev/null
+++ b/EC.Web/Areas/LR_SystemModule/Views/Log/Form.cshtml
@@ -0,0 +1,45 @@
+@{
+ ViewBag.Title = "清空日志";
+ Layout = "~/Views/Shared/_Form.cshtml";
+}
+
+
\ No newline at end of file
diff --git a/EC.Web/Areas/LR_SystemModule/Views/Log/Index.cshtml b/EC.Web/Areas/LR_SystemModule/Views/Log/Index.cshtml
new file mode 100644
index 0000000..f582520
--- /dev/null
+++ b/EC.Web/Areas/LR_SystemModule/Views/Log/Index.cshtml
@@ -0,0 +1,196 @@
+@{
+ ViewBag.Title = "日志管理";
+ Layout = "~/Views/Shared/_Index.cshtml";
+}
+
+
+
+
+
+ - 登录日志
+ - 访问日志
+ - 操作日志
+ - 异常日志
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/learun.core/learun.application/BaseInfo/Log/LogBLL.cs b/learun.core/learun.application/BaseInfo/Log/LogBLL.cs
new file mode 100644
index 0000000..d27d109
--- /dev/null
+++ b/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
+{
+ ///
+ /// 版 本 EasyCode EC管理后台
+ /// Copyright (c) 2019-present EC管理有限公司
+ /// 创建人:tobin
+ /// 日 期:2019.09.25
+ /// 描 述:系统日志
+ ///
+ public class LogBLL : LogIBLL
+ {
+ private readonly LogService service = new LogService();
+
+ #region 获取数据
+
+ ///
+ /// 日志列表
+ ///
+ /// 分页
+ /// 查询参数
+ /// 用户主键
+ ///
+ public Task> GetPageList(Pagination pagination, string queryJson, string userId)
+ {
+ return service.GetPageList(pagination, queryJson, userId);
+ }
+
+ #endregion 获取数据
+
+ #region 提交数据
+
+ ///
+ /// 清空日志
+ ///
+ /// 日志分类Id
+ /// 保留时间段内
+ public async Task Remove(int categoryId, string keepTime)
+ {
+ await service.Remove(categoryId, keepTime);
+ }
+
+ ///
+ /// 写日志
+ ///
+ /// 对象
+ public async Task Write(LogEntity logEntity)
+ {
+ await service.Write(logEntity);
+ }
+
+ #endregion 提交数据
+
+ #region 扩展方法
+
+ ///
+ /// 生成异常信息
+ ///
+ /// 异常对象
+ ///
+ 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 扩展方法
+ }
+}
\ No newline at end of file
diff --git a/learun.core/learun.application/BaseInfo/Log/LogService.cs b/learun.core/learun.application/BaseInfo/Log/LogService.cs
new file mode 100644
index 0000000..f9fb751
--- /dev/null
+++ b/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
+{
+ ///
+ /// 版 本 EasyCode EC管理后台
+ /// Copyright (c) 2019-present EC管理有限公司
+ /// 创建人:tobin
+ /// 日 期:2019.09.25
+ /// 描 述:系统日志数据库服务类
+ ///
+ public class LogService : ServiceBase
+ {
+ #region 获取数据
+
+ ///
+ /// 日志列表
+ ///
+ /// 分页
+ /// 查询参数
+ /// 操作用户Id
+ ///
+ public Task> 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(strSql.ToString(), new { categoryId, startTime, endTime, operateUserId, operateAccount, operateType, module, userId, keyword }, pagination);
+ }
+
+ ///
+ /// 日志实体
+ ///
+ /// 主键值
+ ///
+ public Task GetEntity(string keyValue)
+ {
+ return BaseRepository().FindEntity(keyValue);
+ }
+
+ #endregion 获取数据
+
+ #region 提交数据
+
+ ///
+ /// 清空日志
+ ///
+ /// 日志分类Id
+ /// 保留时间段内
+ 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 });
+ }
+
+ ///
+ /// 写日志
+ ///
+ /// 对象
+ 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 提交数据
+ }
+}
\ No newline at end of file
diff --git a/learun.core/learun.application/TaskScheduling/Log/TSLogBLL.cs b/learun.core/learun.application/TaskScheduling/Log/TSLogBLL.cs
new file mode 100644
index 0000000..f9f7fa4
--- /dev/null
+++ b/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
+{
+ ///
+ /// 版 本 EasyCode EC管理后台
+ /// Copyright (c) 2019-present EC管理有限公司
+ /// 创建人:tobin
+ /// 日 期:2019.11.01
+ /// 描 述:任务执行日志
+ ///
+ public class TSLogBLL : BLLBase, TSLogIBLL, BLL
+ {
+ private readonly TSLogService logService = new TSLogService();
+
+ #region 获取数据
+
+ ///
+ /// 获取页面显示列表数据
+ ///
+ /// 分页参数
+ /// 查询参数
+ ///
+ public Task> GetPageList(Pagination pagination, string queryJson)
+ {
+ return logService.GetPageList(pagination, queryJson);
+ }
+
+ ///
+ /// 获取LR_TS_Log表实体数据
+ ///
+ /// 主键
+ ///
+ public Task GetLogEntity(string keyValue)
+ {
+ return logService.GetLogEntity(keyValue);
+ }
+
+ #endregion 获取数据
+
+ #region 提交数据
+
+ ///
+ /// 删除实体数据
+ ///
+ /// 主键
+ ///
+ public async Task DeleteEntity(string keyValue)
+ {
+ await logService.DeleteEntity(keyValue);
+ }
+
+ ///
+ /// 保存实体数据(新增、修改)
+ ///
+ /// 主键
+ /// 实体
+ ///
+ public async Task SaveEntity(string keyValue, TSLogEntity entity)
+ {
+ await logService.SaveEntity(keyValue, entity);
+ }
+
+ #endregion 提交数据
+ }
+}
\ No newline at end of file
diff --git a/learun.core/learun.application/TaskScheduling/Log/TSLogService.cs b/learun.core/learun.application/TaskScheduling/Log/TSLogService.cs
new file mode 100644
index 0000000..577bf44
--- /dev/null
+++ b/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
+{
+ ///
+ /// 版 本 EasyCode EC管理后台
+ /// Copyright (c) 2019-present EC管理有限公司
+ /// 创建人:tobin
+ /// 日 期:2019.11.01
+ /// 描 述:任务执行日志
+ ///
+ public class TSLogService : ServiceBase
+ {
+ #region 获取数据
+
+ ///
+ /// 获取页面显示列表数据
+ ///
+ /// 分页参数
+ /// 查询参数
+ ///
+ public Task> 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(strSql.ToString(), new { startTime, endTime, keyword, executeResult }, pagination);
+ }
+
+ ///
+ /// 获取LR_TS_Log表实体数据
+ ///
+ /// 主键
+ ///
+ public Task GetLogEntity(string keyValue)
+ {
+ return this.BaseRepository().FindEntityByKey(keyValue);
+ }
+
+ #endregion 获取数据
+
+ #region 提交数据
+
+ ///
+ /// 删除实体数据
+ ///
+ /// 主键
+ ///
+ public async Task DeleteEntity(string keyValue)
+ {
+ await this.BaseRepository().DeleteAny(new { F_Id = keyValue });
+ }
+
+ ///
+ /// 保存实体数据(新增、修改)
+ ///
+ /// 主键
+ /// 实体
+ ///
+ 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 提交数据
+ }
+}
\ No newline at end of file
diff --git a/learun.core/learun.iapplication/BaseInfo/Log/LogEntity.cs b/learun.core/learun.iapplication/BaseInfo/Log/LogEntity.cs
new file mode 100644
index 0000000..5626018
--- /dev/null
+++ b/learun.core/learun.iapplication/BaseInfo/Log/LogEntity.cs
@@ -0,0 +1,116 @@
+using cd.dapper.extension;
+using System;
+
+namespace learun.iapplication
+{
+ ///
+ /// 版 本 EasyCode EC管理后台
+ /// Copyright (c) 2019-present EC管理有限公司
+ /// 创建人:tobin
+ /// 日 期:2019.09.25
+ /// 描 述:系统日志数据库实体类
+ ///
+ [Table("lr_base_log")]
+ public class LogEntity
+ {
+ #region 实体成员
+
+ ///
+ /// 日志主键
+ ///
+ [Key]
+ public string F_LogId { get; set; }
+
+ ///
+ /// 分类Id 1-登陆2-访问3-操作4-异常
+ ///
+ public int? F_CategoryId { get; set; }
+
+ ///
+ /// 来源对象主键
+ ///
+ public string F_SourceObjectId { get; set; }
+
+ ///
+ /// 来源日志内容
+ ///
+ public string F_SourceContentJson { get; set; }
+
+ ///
+ /// 操作时间
+ ///
+ public DateTime? F_OperateTime { get; set; }
+
+ ///
+ /// 操作用户Id
+ ///
+ public string F_OperateUserId { get; set; }
+
+ ///
+ /// 操作用户
+ ///
+ public string F_OperateAccount { get; set; }
+
+ ///
+ /// 操作类型Id
+ ///
+ public string F_OperateTypeId { get; set; }
+
+ ///
+ /// 操作类型
+ ///
+ public string F_OperateType { get; set; }
+
+ ///
+ /// 系统功能
+ ///
+ public string F_Module { get; set; }
+
+ ///
+ /// IP地址
+ ///
+ public string F_IPAddress { get; set; }
+
+ ///
+ /// IP地址所在城市
+ ///
+ public string F_IPAddressName { get; set; }
+
+ ///
+ /// 主机
+ ///
+ public string F_Host { get; set; }
+
+ ///
+ /// 浏览器
+ ///
+ public string F_Browser { get; set; }
+
+ ///
+ /// 执行结果状态
+ ///
+ public int? F_ExecuteResult { get; set; }
+
+ ///
+ /// 执行结果信息
+ ///
+ public string F_ExecuteResultJson { get; set; }
+
+ ///
+ /// 备注
+ ///
+ public string F_Description { get; set; }
+
+ ///
+ /// 删除标记
+ ///
+ public int? F_DeleteMark { get; set; }
+
+ ///
+ /// 有效标志
+ ///
+ public int? F_EnabledMark { get; set; }
+
+ #endregion 实体成员
+ }
+}
\ No newline at end of file
diff --git a/learun.core/learun.iapplication/BaseInfo/Log/LogIBLL.cs b/learun.core/learun.iapplication/BaseInfo/Log/LogIBLL.cs
new file mode 100644
index 0000000..29db978
--- /dev/null
+++ b/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
+{
+ ///
+ /// 版 本 EasyCode EC管理后台
+ /// Copyright (c) 2019-present EC管理有限公司
+ /// 创建人:tobin
+ /// 日 期:2019.09.25
+ /// 描 述:系统日志
+ ///
+ public interface LogIBLL
+ {
+ #region 获取数据
+
+ ///
+ /// 日志列表
+ ///
+ /// 分页
+ /// 查询参数
+ /// 用户主键
+ ///
+ Task> GetPageList(Pagination pagination, string queryJson, string userId);
+
+ #endregion 获取数据
+
+ #region 提交数据
+
+ ///
+ /// 清空日志
+ ///
+ /// 日志分类Id
+ /// 保留时间段内
+ Task Remove(int categoryId, string keepTime);
+
+ ///
+ /// 写日志
+ ///
+ /// 对象
+ Task Write(LogEntity logEntity);
+
+ #endregion 提交数据
+
+ #region 扩展方法
+
+ ///
+ /// 生成异常信息
+ ///
+ /// 异常对象
+ ///
+ string ExceptionFormat(Exception ex);
+
+ #endregion 扩展方法
+ }
+}
\ No newline at end of file