fix 数据过滤调整
This commit is contained in:
@@ -25,7 +25,7 @@ public class HeartbeatJob : BaseJob
|
||||
|
||||
public override async Task RunAsync(IServiceProvider serviceProvider)
|
||||
{
|
||||
var key = "heardbeat-devices";
|
||||
const string key = "heartbeat-devices";
|
||||
await _redisCache.KeyDeleteAsync(key);
|
||||
|
||||
var devices = await DbContext.Queryable<DeviceEntity>().Where(x => x.Enable).Where(x => x.HeartbeatInterval > 0).ToListAsync();
|
||||
@@ -36,11 +36,11 @@ public class HeartbeatJob : BaseJob
|
||||
var ipInfo = JsonConvert.DeserializeObject<IPPortDto>(device.ConnectionInfo);
|
||||
|
||||
//超时时间
|
||||
var CancellationTokenSource = new CancellationTokenSource(300);
|
||||
await new TcpClient().ConnectAsync(IPAddress.Parse(ipInfo.IP), ipInfo.Port, CancellationTokenSource.Token);
|
||||
var cancellationTokenSource = new CancellationTokenSource(300);
|
||||
await new TcpClient().ConnectAsync(IPAddress.Parse(ipInfo.IP), ipInfo.Port, cancellationTokenSource.Token);
|
||||
|
||||
await DbContext.Updateable<DeviceRegistryEntity>().SetColumns(x => x.LastHeartbeatTime == DateTime.Now)
|
||||
.Where(x => x.DeviceUniqueNo == device.UniqueNo).ExecuteCommandAsync();
|
||||
.Where(x => x.DeviceUniqueNo == device.UniqueNo).ExecuteCommandAsync(cancellationTokenSource.Token);
|
||||
|
||||
await _redisCache.ListLeftPushAsync(key, device.UniqueNo);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Dlhis.Entity.Sys.Entities;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Sys.Entities;
|
||||
using Dlhis.Sys.Identity.Request;
|
||||
using Dlhis.Sys.Identity.Response;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
@@ -13,26 +14,27 @@ namespace Dlhis.Sys.Identity.Services.Implements;
|
||||
|
||||
public class UserService : IUserService
|
||||
{
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly IDbContext _identityDbContext;
|
||||
|
||||
public UserService(IDbContext dbContext, ICurrentUser currentUser)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_currentUser = currentUser;
|
||||
_dbContext = dbContext.ChangeDb("identity");
|
||||
_identityDbContext = dbContext.ChangeDb("identity");
|
||||
}
|
||||
|
||||
public async Task<Pagination<UserResponse>> GetPageAsync(UserPageRequest request)
|
||||
{
|
||||
var tenant = _currentUser.GetStringTenantId();
|
||||
var userCodes = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Factory == tenant).Select(x => x.Code).ToListAsync();
|
||||
|
||||
var page = await _dbContext.Queryable<UserEntity>()
|
||||
var page = await _identityDbContext.Queryable<UserEntity>()
|
||||
.LeftJoin<UserRoleEntity>((x, ur) => x.Id == ur.UserId)
|
||||
.LeftJoin<RoleEntity>((x, ur, r) => ur.RoleId == r.Id)
|
||||
.LeftJoin<UserClaimEntity>((x, ur, r, c) => x.Id == c.UserId && c.ClaimType == "preferred_username")
|
||||
.LeftJoin<UserClaimEntity>((x, ur, r, c, cc) => x.Id == cc.UserId && cc.ClaimType == "tenant")
|
||||
.Where(x => x.UserName != "admin")
|
||||
.Where((x, ur, r, c, cc) => cc.ClaimValue == tenant)
|
||||
.WhereIF(request.IsOperator, (x, ur, r, c) => !SqlFunc.IsNullOrEmpty(r.Name))
|
||||
.WhereIF(!request.IsOperator, (x, ur, r, c) => SqlFunc.IsNullOrEmpty(r.Name))
|
||||
.WhereIF(request.Search.IsPresent(), (x, ur, r, c) => x.UserName == request.Search
|
||||
@@ -40,7 +42,8 @@ public class UserService : IUserService
|
||||
|| x.PhoneNumber == request.Search
|
||||
|| c.ClaimValue == request.Search
|
||||
)
|
||||
.Select((x, ur, r, c, cc) => new UserResponse
|
||||
.Where(x => userCodes.Contains(x.UserName))
|
||||
.Select((x, ur, r, c) => new UserResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
RoleId = ur.RoleId,
|
||||
@@ -54,16 +57,16 @@ public class UserService : IUserService
|
||||
|
||||
public async Task ResetAccessFailedCountAsync(int id)
|
||||
{
|
||||
var user = await _dbContext.Queryable<UserEntity>().Where(x => x.Id == id).FirstAsync();
|
||||
var user = await _identityDbContext.Queryable<UserEntity>().Where(x => x.Id == id).FirstAsync();
|
||||
user.ThrowIfNull("用户不存在,无法重置");
|
||||
|
||||
user.AccessFailedCount = 0;
|
||||
await _dbContext.UpdateAsync(user);
|
||||
await _identityDbContext.UpdateAsync(user);
|
||||
}
|
||||
|
||||
public async Task<List<UserResponse>> GetUsersAsync()
|
||||
{
|
||||
var users = await _dbContext.Queryable<UserEntity>()
|
||||
var users = await _identityDbContext.Queryable<UserEntity>()
|
||||
.Where(x => x.UserName != "admin")
|
||||
.Select<UserResponse>()
|
||||
.ToListAsync();
|
||||
@@ -72,7 +75,7 @@ public class UserService : IUserService
|
||||
|
||||
public async Task<UserResponse> GetUserByIdAsync(int id)
|
||||
{
|
||||
var user = await _dbContext.Queryable<UserEntity>()
|
||||
var user = await _identityDbContext.Queryable<UserEntity>()
|
||||
.LeftJoin<UserRoleEntity>((x, ur) => x.Id == ur.UserId)
|
||||
.LeftJoin<RoleEntity>((x, ur, r) => ur.RoleId == r.Id)
|
||||
.LeftJoin<UserClaimEntity>((x, ur, r, c) => x.Id == c.UserId && c.ClaimType == "preferred_username")
|
||||
@@ -91,12 +94,12 @@ public class UserService : IUserService
|
||||
|
||||
public async Task UploadUserAvatarAsync(UserAvatarUploadRequest request)
|
||||
{
|
||||
var user = await _dbContext.Queryable<UserEntity>().Where(x => x.Id == request.UserNo).Select<UserResponse>().FirstAsync();
|
||||
var user = await _identityDbContext.Queryable<UserEntity>().Where(x => x.Id == request.UserNo).Select<UserResponse>().FirstAsync();
|
||||
}
|
||||
|
||||
public async Task<List<UserResponse>> GetUserByIdsAsync(List<int> ids)
|
||||
{
|
||||
var users = await _dbContext.Queryable<UserEntity>().Where(x => ids.Contains(x.Id)).Select<UserResponse>().ToListAsync();
|
||||
var users = await _identityDbContext.Queryable<UserEntity>().Where(x => ids.Contains(x.Id)).Select<UserResponse>().ToListAsync();
|
||||
return users;
|
||||
}
|
||||
|
||||
@@ -114,9 +117,9 @@ public class UserService : IUserService
|
||||
request.Password = hasher.HashPassword(user, request.Password);
|
||||
user.PasswordHash = request.Password;
|
||||
|
||||
var id = (int)await _dbContext.InsertReturnIdentityAsync(user);
|
||||
var id = (int)await _identityDbContext.InsertReturnIdentityAsync(user);
|
||||
|
||||
await _dbContext.InsertAsync(request.Tenants.Select(x => new UserTenantEntity
|
||||
await _identityDbContext.InsertAsync(request.Tenants.Select(x => new UserTenantEntity
|
||||
{
|
||||
TenantCode = x,
|
||||
UserId = id
|
||||
@@ -124,7 +127,7 @@ public class UserService : IUserService
|
||||
|
||||
if (request.Name.IsPresent())
|
||||
{
|
||||
await _dbContext.InsertAsync(new UserClaimEntity
|
||||
await _identityDbContext.InsertAsync(new UserClaimEntity
|
||||
{
|
||||
ClaimType = "preferred_username",
|
||||
ClaimValue = request.Name,
|
||||
|
||||
Reference in New Issue
Block a user