using Infrastructure;
using Infrastructure.Attribute;
using ZR.Infrastructure.Constant;
using ZR.Infrastructure.Helper;
using ZR.Model;
using ZR.Model.System;
using ZR.Model.System.Dto;
using ZR.Model.System.Generate;
using ZR.Repository;
namespace ZR.ServiceCore.Services
{
///
/// 操作日志
///
[AppService(ServiceType = typeof(ISysOperLogService), ServiceLifetime = LifeTime.Transient)]
public class SysOperLogService : BaseService, ISysOperLogService
{
///
/// 新增操作日志操作
///
/// 日志对象
public void InsertOperlog(SysOperLog operLog)
{
if (operLog.OperParam != null && operLog.OperParam.Length >= 1000)
{
operLog.OperParam = operLog.OperParam[..1000];
}
//sysOperLogRepository.AddSysOperLog(operLog);
Insert(operLog);
}
///
/// 查询系统操作日志集合
///
/// 操作日志对象
/// 操作日志集合
public PagedInfo SelectOperLogList(SysOperLogQueryDto sysOper)
{
var exp = Expressionable.Create();
exp.AndIF(sysOper.BeginTime == null, it => it.OperTime >= DateTime.Now.ToShortDateString().ParseToDateTime());
exp.AndIF(sysOper.BeginTime != null, it => it.OperTime >= sysOper.BeginTime && it.OperTime <= sysOper.EndTime);
exp.AndIF(sysOper.Title.IfNotEmpty(), it => it.Title.Contains(sysOper.Title));
exp.AndIF(sysOper.OperName.IfNotEmpty(), it => it.OperName.Contains(sysOper.OperName));
exp.AndIF(sysOper.BusinessType != null, it => it.BusinessType == sysOper.BusinessType);
exp.AndIF(sysOper.Status != null, it => it.Status == sysOper.Status);
exp.AndIF(sysOper.OperParam != null, it => it.OperParam.Contains(sysOper.OperParam));
exp.AndIF(sysOper.BusinessTypes != null, it => sysOper.BusinessTypes.Contains(it.BusinessType));
var list = Queryable()
.Where(exp.ToExpression())
.OrderBy(x => x.OperId, OrderByType.Desc)
.ToPage(sysOper);
foreach (var item in list.Result)
{
if (!HttpContextExtension.HasSensitivePerm(App.HttpContext, SensitivePerms.ViewRealIP))
{
item.OperIp = MaskUtil.MaskIp(item.OperIp);
}
}
return list;
}
///
/// 清空操作日志
///
public void CleanOperLog()
{
var newTableName = $"sys_oper_log_{DateTime.Now:yyyyMMdd}";
if (Queryable().Any() && !Context.DbMaintenance.IsAnyTable(newTableName))
{
Context.DbMaintenance.BackupTable("sys_oper_log", newTableName);
}
Truncate();
}
///
/// 批量删除系统操作日志
///
/// 需要删除的操作日志ID
/// 结果
public int DeleteOperLogByIds(long[] operIds)
{
return Delete(operIds);
}
///
/// 查询操作日志详细
///
/// 操作ID
/// 操作日志对象
public SysOperLog SelectOperLogById(long operId)
{
return GetById(operId);
}
}
}