宁虹看板
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

94 lines
3.5 KiB

using NFine.Code;
using NFine.Domain.Entity.SystemSecurity;
using NFine.Domain.IRepository.SystemSecurity;
using NFine.Repository.SystemSecurity;
using System;
using System.Collections.Generic;
namespace NFine.Application.SystemSecurity
{
public class LogApp
{
private ILogRepository service = new LogRepository();
public List<LogEntity> GetList(Pagination pagination, string queryJson)
{
var expression = ExtLinq.True<LogEntity>();
var queryParam = queryJson.ToJObject();
if (!queryParam["keyword"].IsEmpty())
{
string keyword = queryParam["keyword"].ToString();
expression = expression.And(t => t.F_Account.Contains(keyword));
}
if (!queryParam["timeType"].IsEmpty())
{
string timeType = queryParam["timeType"].ToString();
DateTime startTime = DateTime.Now.ToString("yyyy-MM-dd").ToDate();
DateTime endTime = DateTime.Now.ToString("yyyy-MM-dd").ToDate().AddDays(1);
switch (timeType)
{
case "1":
break;
case "2":
startTime = DateTime.Now.AddDays(-7);
break;
case "3":
startTime = DateTime.Now.AddMonths(-1);
break;
case "4":
startTime = DateTime.Now.AddMonths(-3);
break;
default:
break;
}
expression = expression.And(t => t.F_Date >= startTime && t.F_Date <= endTime);
}
return service.FindList(expression, pagination);
}
public void RemoveLog(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);
}
var expression = ExtLinq.True<LogEntity>();
expression = expression.And(t => t.F_Date <= operateTime);
service.Delete(expression);
}
public void WriteDbLog(bool result, string resultLog)
{
LogEntity logEntity = new LogEntity();
logEntity.F_Id = Common.GuId();
logEntity.F_Date = DateTime.Now;
logEntity.F_Account = OperatorProvider.Provider.GetCurrent().UserCode;
logEntity.F_NickName = OperatorProvider.Provider.GetCurrent().UserName;
logEntity.F_IPAddress = Net.Ip;
logEntity.F_IPAddressName = Net.GetLocation(logEntity.F_IPAddress);
logEntity.F_Result = result;
logEntity.F_Description = resultLog;
logEntity.Create();
service.Insert(logEntity);
}
public void WriteDbLog(LogEntity logEntity)
{
logEntity.F_Id = Common.GuId();
logEntity.F_Date = DateTime.Now;
logEntity.F_IPAddress = "117.81.192.182";
logEntity.F_IPAddressName = Net.GetLocation(logEntity.F_IPAddress);
logEntity.Create();
service.Insert(logEntity);
}
}
}