2019-03-08 15:33:00 +08:00
using System ;
2018-10-19 23:09:52 +08:00
using System.Collections.Generic ;
2016-11-05 15:26:42 +08:00
namespace Bootstrap.DataAccess
{
2018-10-21 10:02:59 +08:00
/// <summary>
///
/// </summary>
2019-03-16 20:24:33 +08:00
public class Log : Trace
2016-11-05 15:26:42 +08:00
{
/// <summary>
/// 获得/设置 操作类型
/// </summary>
public string CRUD { get ; set ; }
2019-03-09 19:09:42 +08:00
/// <summary>
/// 获得/设置 请求数据
/// </summary>
public string RequestData { get ; set ; }
2018-10-19 23:09:52 +08:00
/// <summary>
/// 查询所有日志信息
/// </summary>
/// <returns></returns>
2019-01-14 12:33:09 +08:00
public virtual IEnumerable < Log > Retrieves ( ) = > DbManager . Create ( ) . Fetch < Log > ( "select * from Logs where LogTime > @0 order by LogTime desc" , DateTime . Now . AddDays ( - 7 ) ) ;
2019-01-11 23:20:28 +08:00
2018-10-21 10:02:59 +08:00
/// <summary>
/// 删除日志信息
/// </summary>
/// <returns></returns>
2018-10-30 22:11:27 +08:00
private static void DeleteLogAsync ( )
2018-10-21 10:02:59 +08:00
{
System . Threading . Tasks . Task . Run ( ( ) = >
{
2019-03-08 15:33:00 +08:00
var dtm = DateTime . Now . AddMonths ( 0 - DictHelper . RetrieveLogsPeriod ( ) ) ;
2019-01-14 12:33:09 +08:00
DbManager . Create ( ) . Execute ( "delete from Logs where LogTime < @0" , dtm ) ;
2018-10-21 10:02:59 +08:00
} ) ;
}
2019-01-11 23:20:28 +08:00
2018-10-19 23:09:52 +08:00
/// <summary>
/// 保存新增的日志信息
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
2019-01-11 23:20:28 +08:00
public virtual bool Save ( Log p )
2018-10-21 10:02:59 +08:00
{
2018-11-02 20:04:45 +08:00
if ( p = = null ) throw new ArgumentNullException ( nameof ( p ) ) ;
2018-10-21 10:02:59 +08:00
DeleteLogAsync ( ) ;
2019-01-11 23:20:28 +08:00
p . LogTime = DateTime . Now ;
2019-01-14 12:33:09 +08:00
DbManager . Create ( ) . Save ( p ) ;
2019-01-11 23:20:28 +08:00
return true ;
2018-10-21 10:02:59 +08:00
}
2016-11-05 15:26:42 +08:00
}
}