diff --git a/Myshipping.Core/Entity/SysUserAccountRelation.cs b/Myshipping.Core/Entity/SysUserAccountRelation.cs
new file mode 100644
index 00000000..f943352a
--- /dev/null
+++ b/Myshipping.Core/Entity/SysUserAccountRelation.cs
@@ -0,0 +1,46 @@
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Myshipping.Core.Entity
+{
+ ///
+ /// 用户账号关联
+ ///
+ [SugarTable("sys_user_account_relation", TableDescription = "用户账号关联")]
+ public class SysUserAccountRelation : DBEntityTenant
+ {
+ ///
+ /// 分组ID
+ ///
+ [SugarColumn(ColumnName = "GroupId")]
+ [Description("分组ID")]
+ public long GroupId { get; set; }
+
+ ///
+ /// 用户ID
+ ///
+ [SugarColumn(ColumnName = "UserId")]
+ [Description("用户ID")]
+ public long UserId { get; set; }
+
+ ///
+ /// 用户名称
+ ///
+ [SugarColumn(ColumnName = "UserName")]
+ [Description("用户名称")]
+ public string UserName { get; set; }
+
+ ///
+ /// 租户名称
+ ///
+ [SugarColumn(ColumnName = "TenantName")]
+ [Description("租户名称")]
+ public string TenantName { get; set; }
+
+ }
+}
diff --git a/Myshipping.Core/Myshipping.Core.xml b/Myshipping.Core/Myshipping.Core.xml
index 2c856239..89183693 100644
--- a/Myshipping.Core/Myshipping.Core.xml
+++ b/Myshipping.Core/Myshipping.Core.xml
@@ -4460,6 +4460,31 @@
状态-正常_0、停用_1、删除_2
+
+
+ 用户账号关联
+
+
+
+
+ 分组ID
+
+
+
+
+ 用户ID
+
+
+
+
+ 用户名称
+
+
+
+
+ 租户名称
+
+
用户数据范围表
@@ -7134,6 +7159,13 @@
+
+
+ 切换登录账号
+
+
+
+
登录输入参数
@@ -7282,6 +7314,36 @@
前端需要使用的租户参数列表
+
+
+ 用户账号关联
+
+
+
+
+ ID
+
+
+
+
+ 用户ID
+
+
+
+
+ 用户名称
+
+
+
+
+ 租户ID
+
+
+
+
+ 租户名称
+
+
注册输入参数
diff --git a/Myshipping.Core/Service/Auth/AuthService.cs b/Myshipping.Core/Service/Auth/AuthService.cs
index 38cc35d7..e8cea526 100644
--- a/Myshipping.Core/Service/Auth/AuthService.cs
+++ b/Myshipping.Core/Service/Auth/AuthService.cs
@@ -31,6 +31,7 @@ public class AuthService : IAuthService, IDynamicApiController, ITransient
private readonly SqlSugarRepository _sysUserRep; // 用户表仓储
private readonly SqlSugarRepository _sysLogVisRep;
private readonly SqlSugarRepository _sysTenantRep;
+ private readonly SqlSugarRepository _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 logger, IDjyTenantParamService djyTenantParamService)
+ ILogger logger, IDjyTenantParamService djyTenantParamService, SqlSugarRepository sysUserAccountRelation)
{
_sysUserRep = sysUserRep;
_sysLogVisRep = sysLogVisRep;
@@ -66,6 +67,7 @@ public class AuthService : IAuthService, IDynamicApiController, ITransient
_logger = logger;
_cache = cache;
_djyTenantParamService = djyTenantParamService;
+ _sysUserAccountRelation = sysUserAccountRelation;
}
///
@@ -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>();
+ }
+
// 增加登录日志
await _eventPublisher.PublishAsync(new ChannelEventSource("Create:VisLog",
new SysLogVis
@@ -427,4 +437,34 @@ public class AuthService : IAuthService, IDynamicApiController, ITransient
}
}
+
+
+ ///
+ /// 切换登录账号
+ ///
+ ///
+ ///
+ [HttpPost("/ChangeLogin")]
+ public async Task 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);
+ }
}
diff --git a/Myshipping.Core/Service/Auth/Dto/LoginOutput.cs b/Myshipping.Core/Service/Auth/Dto/LoginOutput.cs
index f003339c..20089596 100644
--- a/Myshipping.Core/Service/Auth/Dto/LoginOutput.cs
+++ b/Myshipping.Core/Service/Auth/Dto/LoginOutput.cs
@@ -1,6 +1,8 @@
using Furion.DependencyInjection;
+using SqlSugar;
using System;
using System.Collections.Generic;
+using System.ComponentModel;
namespace Myshipping.Core.Service;
@@ -130,6 +132,11 @@ public class LoginOutput
///
public List TenantParams { get; set; } = new List();
+ ///
+ /// 用户账号关联
+ ///
+ public List UserAccountRelation { get; set; }
+
/////
///// 租户信息
/////
@@ -170,3 +177,32 @@ public class LoginOutput
/////
//public bool Enabled { get; set; }
}
+
+
+public class UserAccountRelationDto
+{
+ ///
+ /// ID
+ ///
+ public long Id { get; set; }
+
+ ///
+ /// 用户ID
+ ///
+ public long UserId { get; set; }
+
+ ///
+ /// 用户名称
+ ///
+ public string UserName { get; set; }
+
+ ///
+ /// 租户ID
+ ///
+ public long TenantId { get; set; }
+
+ ///
+ /// 租户名称
+ ///
+ public string TenantName { get; set; }
+}
\ No newline at end of file