45 lines
1.7 KiB
C#
45 lines
1.7 KiB
C#
using MongoRepository;
|
|||
|
|
using UserDomain;
|
||
|
|
using UserDomain.Entity;
|
||
|
|
using UserDomain.Param;
|
||
|
|
|
||
|
|
namespace UserService
|
||
|
|
{
|
||
|
|
public class UserLoginLogService : IUserLoginLogService
|
||
|
|
{
|
||
|
|
private readonly IMongoBaseRepository<UserLoginLog> _logRepo;
|
||
|
|
|
||
|
|
public UserLoginLogService(IMongoBaseRepository<UserLoginLog> logRepo)
|
||
|
|
{
|
||
|
|
_logRepo = logRepo;
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task<bool> AddLog(UserLoginLog log)
|
||
|
|
{
|
||
|
|
var result = await _logRepo.InsertOneAsync(log);
|
||
|
|
return result.ok;
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task<(List<UserLoginLog> list, long count)> QueryPage(UserLoginLogQueryParam param)
|
||
|
|
{
|
||
|
|
var result = await _logRepo.QueryPageAsync(
|
||
|
|
filterExpression: x =>
|
||
|
|
(string.IsNullOrEmpty(param.UserId) || x.UserId == param.UserId) &&
|
||
|
|
(string.IsNullOrEmpty(param.UserNumber) || x.UserNumber == param.UserNumber) &&
|
||
|
|
(string.IsNullOrEmpty(param.UserName) || (x.UserName != null && x.UserName.Contains(param.UserName))) &&
|
||
|
|
(!param.LoginType.HasValue || x.LoginType == param.LoginType) &&
|
||
|
|
(!param.Status.HasValue || x.Status == param.Status) &&
|
||
|
|
(!param.Platform.HasValue || x.Platform == param.Platform) &&
|
||
|
|
(!param.StartTime.HasValue || x.LoginTime >= param.StartTime) &&
|
||
|
|
(!param.EndTime.HasValue || x.LoginTime <= param.EndTime),
|
||
|
|
orderExpression: x => x.LoginTime,
|
||
|
|
desc: true,
|
||
|
|
pageSize: param.PageSize,
|
||
|
|
pageIndex: param.PageIndex
|
||
|
|
);
|
||
|
|
|
||
|
|
return (result.list.ToList(), result.count);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|