62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
using DispenserCommon.DB;
|
|
using DispenserCommon.DTO;
|
|
using DispenserCommon.Ioc;
|
|
using DispenserCommon.Utils;
|
|
using DispenserCore.Model.DTO;
|
|
using DispenserCore.Model.Entity;
|
|
using Masuit.Tools;
|
|
|
|
namespace DispenserCore.Service;
|
|
|
|
/// <summary>
|
|
/// 操作日志业务类
|
|
/// </summary>
|
|
[Component]
|
|
public class OperationLogService
|
|
{
|
|
private readonly SqliteHelper _db = ServiceLocator.GetService<SqliteHelper>();
|
|
|
|
|
|
/// <summary>
|
|
/// 批量插入操作日志
|
|
/// </summary>
|
|
/// <param name="logs"></param>
|
|
public void BatchInsert(IEnumerable<OperationLog> logs)
|
|
{
|
|
_db.BatchInsert(logs);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分页查询
|
|
/// </summary>
|
|
/// <param name="query"></param>
|
|
/// <returns></returns>
|
|
public Page<OperationLog> QueryPage(QueryOperationLog query)
|
|
{
|
|
// 构建查询sql
|
|
var sql = "select * from operation_logs where 1 = 1 ";
|
|
if (!query.StartTime.IsDefaultValue() && !query.EndTime.IsDefaultValue())
|
|
{
|
|
sql += "and operate_time between '" + query.StartTime + "' and '" +
|
|
query.EndTime + "' ";
|
|
}
|
|
else if (!query.StartTime.IsDefaultValue())
|
|
{
|
|
sql += "and operate_time >= '" + query.StartTime + "'";
|
|
}
|
|
else if (!query.EndTime.IsDefaultValue())
|
|
{
|
|
sql += "and operate_time <= '" + query.EndTime + "'";
|
|
}
|
|
|
|
if (!query.UserName.IsNullOrEmpty())
|
|
{
|
|
sql += "and user_name like '%" + query.UserName + "%' ";
|
|
}
|
|
|
|
sql += " order by operate_time desc ";
|
|
|
|
Console.WriteLine(sql);
|
|
return _db.Page<OperationLog>(query.CurrentPage, query.PageSize, sql);
|
|
}
|
|
} |