|
|
|
@ -31,6 +31,7 @@ public class AuthService : IAuthService, IDynamicApiController, ITransient
|
|
|
|
|
private readonly SqlSugarRepository<SysUser> _sysUserRep; // 用户表仓储
|
|
|
|
|
private readonly SqlSugarRepository<SysLogVis> _sysLogVisRep;
|
|
|
|
|
private readonly SqlSugarRepository<SysTenant> _sysTenantRep;
|
|
|
|
|
private readonly SqlSugarRepository<SysUserAccountRelation> _sysUserAccountRelation;
|
|
|
|
|
private readonly ISysCacheService _cache;
|
|
|
|
|
|
|
|
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
|
|
@ -50,7 +51,7 @@ public class AuthService : IAuthService, IDynamicApiController, ITransient
|
|
|
|
|
ISysEmpService sysEmpService, ISysRoleService sysRoleService, ISysMenuService sysMenuService,
|
|
|
|
|
ISysAppService sysAppService, IClickWordCaptcha captchaHandle, ISysConfigService sysConfigService,
|
|
|
|
|
IEventPublisher eventPublisher,
|
|
|
|
|
ILogger<AuthService> logger, IDjyTenantParamService djyTenantParamService)
|
|
|
|
|
ILogger<AuthService> logger, IDjyTenantParamService djyTenantParamService, SqlSugarRepository<SysUserAccountRelation> sysUserAccountRelation)
|
|
|
|
|
{
|
|
|
|
|
_sysUserRep = sysUserRep;
|
|
|
|
|
_sysLogVisRep = sysLogVisRep;
|
|
|
|
@ -66,6 +67,7 @@ public class AuthService : IAuthService, IDynamicApiController, ITransient
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_cache = cache;
|
|
|
|
|
_djyTenantParamService = djyTenantParamService;
|
|
|
|
|
_sysUserAccountRelation = sysUserAccountRelation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -258,6 +260,14 @@ public class AuthService : IAuthService, IDynamicApiController, ITransient
|
|
|
|
|
var paraCodeArr = new string[] { TenantParamCode.ENABLE_SLOT_ABILITY, TenantParamCode.ENABLE_FEE_ABILITY, TenantParamCode.VESSEL_FROM_CONFIG_ONLY };
|
|
|
|
|
loginOutput.TenantParams = await _djyTenantParamService.GetParaCodeWithValue(paraCodeArr);
|
|
|
|
|
|
|
|
|
|
//多账号关联
|
|
|
|
|
var accRela = await _sysUserAccountRelation.AsQueryable().Filter(null, true).Where(x => x.UserId == userId && x.IsDeleted == false).FirstAsync();
|
|
|
|
|
if (accRela != null)
|
|
|
|
|
{
|
|
|
|
|
var accRelaList = await _sysUserAccountRelation.AsQueryable().Filter(null, true).Where(x => x.GroupId == accRela.GroupId && x.IsDeleted == false && x.UserId != userId).ToListAsync();
|
|
|
|
|
loginOutput.UserAccountRelation = accRelaList.Adapt<List<UserAccountRelationDto>>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 增加登录日志
|
|
|
|
|
await _eventPublisher.PublishAsync(new ChannelEventSource("Create:VisLog",
|
|
|
|
|
new SysLogVis
|
|
|
|
@ -427,4 +437,34 @@ public class AuthService : IAuthService, IDynamicApiController, ITransient
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 切换登录账号
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="changeTo"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/ChangeLogin")]
|
|
|
|
|
public async Task<string> ChangeLogin(long changeTo)
|
|
|
|
|
{
|
|
|
|
|
var accRela = await _sysUserAccountRelation.AsQueryable().Filter(null, true).FirstAsync(x => x.Id == changeTo && x.IsDeleted == false);
|
|
|
|
|
if (accRela == null)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah("未找到账号关联数据");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//判断当前用户的账号和要切换到的账号是否在一个关联配置中
|
|
|
|
|
var cc = await _sysUserAccountRelation.AsQueryable().Filter(null, true).CountAsync(x => x.GroupId == accRela.GroupId && x.UserId == UserManager.UserId && x.IsDeleted == false);
|
|
|
|
|
if (cc == 0)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah("无权切换到此账号");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var user = await _sysUserRep.AsQueryable().Filter(null, true).FirstAsync(u => u.Id == accRela.UserId);
|
|
|
|
|
|
|
|
|
|
//获取对应租户
|
|
|
|
|
var tenant = _sysTenantRep.Single(user.TenantId);
|
|
|
|
|
// 生成Token令牌
|
|
|
|
|
return await GetLoginToken(user, tenant);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|