add 操作人

This commit is contained in:
2025-03-25 10:48:20 +08:00
parent c6bc8bf619
commit c6ad50c783
5 changed files with 41 additions and 4 deletions

View File

@@ -105,4 +105,9 @@ public class DeviceTaskAssignmentResponse
/// 创建人 /// 创建人
/// </summary> /// </summary>
public int CreateBy { get; set; } public int CreateBy { get; set; }
/// <summary>
/// 操作人
/// </summary>
public string Creator { get; set; }
} }

View File

@@ -17,11 +17,15 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService
{ {
private readonly IDbContext _dbContext; private readonly IDbContext _dbContext;
private readonly ITenantApi _tenantApi; private readonly ITenantApi _tenantApi;
private readonly IUserApi _userApi;
public DeviceTaskAssignmentService(IDbContext dbContext, ITenantApi tenantApi) public DeviceTaskAssignmentService(IDbContext dbContext,
ITenantApi tenantApi,
IUserApi userApi)
{ {
_dbContext = dbContext; _dbContext = dbContext;
_tenantApi = tenantApi; _tenantApi = tenantApi;
_userApi = userApi;
} }
public async Task<Pagination<DeviceTaskAssignmentResponse>> GetPageAsync(DeviceTaskAssignmentRequest request) public async Task<Pagination<DeviceTaskAssignmentResponse>> GetPageAsync(DeviceTaskAssignmentRequest request)
@@ -81,6 +85,17 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService
//ignore //ignore
} }
try
{
var userIds = page.Data.Select(x => x.CreateBy).Distinct().ToList();
var userInfos = await _userApi.GetUserByIdsAsync(userIds);
page.Data.ForEach(item => item.Creator = userInfos.FirstOrDefault(x => x.Id == item.CreateBy)?.OperatorName);
}
catch (Exception e)
{
//ignore
}
return page; return page;
} }

View File

@@ -3,6 +3,7 @@ using Kurisu.RemoteCall.Attributes;
namespace Dlhis.Sys.Api; namespace Dlhis.Sys.Api;
[RequestResultHandler]
[EnableRemoteClient(Name = "sys-service", BaseUrl = "${InternalRequest:SysRequestUrl}")] [EnableRemoteClient(Name = "sys-service", BaseUrl = "${InternalRequest:SysRequestUrl}")]
public interface IUserApi public interface IUserApi
{ {

View File

@@ -5,6 +5,11 @@ public class UserResponse
public int Id { get; set; } public int Id { get; set; }
public string UserName { get; set; } public string UserName { get; set; }
/// <summary>
/// 操作员名称
/// </summary>
public string OperatorName { get; set; }
public string NormalizedUserName { get; set; } public string NormalizedUserName { get; set; }

View File

@@ -90,7 +90,7 @@ public class UserService : IUserService
Role = r.Name, Role = r.Name,
OperatorName = c.ClaimValue, OperatorName = c.ClaimValue,
}, true) }, true)
.FirstAsync(); .SingleAsync();
return user; return user;
} }
@@ -102,8 +102,19 @@ public class UserService : IUserService
public async Task<List<UserResponse>> GetUserByIdsAsync(List<int> ids) public async Task<List<UserResponse>> GetUserByIdsAsync(List<int> ids)
{ {
var users = await _identityDbContext.Queryable<UserEntity>().Where(x => ids.Contains(x.Id)).Select<UserResponse>().ToListAsync(); return await _identityDbContext.Queryable<UserEntity>()
return users; .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")
.Where(x => ids.Contains(x.Id))
.Select((x, ur, r, c) => new UserResponse
{
Id = x.Id,
RoleId = ur.RoleId,
Role = r.Name,
OperatorName = c.ClaimValue,
}, true)
.ToListAsync();
} }
public async Task CreateUserAsync(UserCreateRequest request) public async Task CreateUserAsync(UserCreateRequest request)