using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Crm.Core.Domain { internal class UserDomain : IUserDomain { private readonly ICacheDomain _cacheDomain; private readonly IHttpClient _httpClient; private readonly IConfiguration _configuration; private readonly IServiceProvider _serviceProvider; public UserDomain(ICacheDomain cacheDomain, IHttpClient httpClient, IConfiguration configuration, IServiceProvider serviceProvider) { _cacheDomain = cacheDomain; _httpClient = httpClient; _configuration = configuration; _serviceProvider = serviceProvider; } public async Task GetCrmUser(int eid) { var appid = _cacheDomain.GetApp(); using var scope = _serviceProvider.CreateAsyncScope(); var repository = scope.ServiceProvider.GetRequiredService>(); await _cacheDomain.SetApp(repository, appid); var user = await repository.GetRepository().Query() .Where(x => x.EID == eid) .Select(x=>new CrmUserDto { Eid = x.EID, Username = x.UNAME }).FirstOrDefaultAsync() ?? throw new ApiException("用户不存或已删除!"); return user; } } }