375 lines
14 KiB
C#
375 lines
14 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Runtime.Serialization;
|
|
using System.Web.Script.Serialization;
|
|
using System.Xml.Serialization;
|
|
using NewLife;
|
|
using NewLife.Data;
|
|
using XCode;
|
|
using XCode.Cache;
|
|
using XCode.Configuration;
|
|
using XCode.DataAccessLayer;
|
|
|
|
namespace XCode.Membership666;
|
|
|
|
/// <summary>租户关系。用户选择租户进入系统后,以租户关系角色组替代自有角色组来进行鉴权</summary>
|
|
[Serializable]
|
|
[DataObject]
|
|
[Description("租户关系。用户选择租户进入系统后,以租户关系角色组替代自有角色组来进行鉴权")]
|
|
[BindIndex("IU_TenantUser_TenantId_UserId", true, "TenantId,UserId")]
|
|
[BindIndex("IX_TenantUser_UserId", false, "UserId")]
|
|
[BindTable("TenantUser", Description = "租户关系。用户选择租户进入系统后,以租户关系角色组替代自有角色组来进行鉴权", ConnName = "Membership666", DbType = DatabaseType.None)]
|
|
public partial class TenantUser : ITenantUser, IEntity<ITenantUser>
|
|
{
|
|
#region 属性
|
|
private Int32 _Id;
|
|
/// <summary>编号</summary>
|
|
[DisplayName("编号")]
|
|
[Description("编号")]
|
|
[DataObjectField(true, true, false, 0)]
|
|
[BindColumn("Id", "编号", "")]
|
|
public Int32 Id { get => _Id; set { if (OnPropertyChanging("Id", value)) { _Id = value; OnPropertyChanged("Id"); } } }
|
|
|
|
private Int32 _TenantId;
|
|
/// <summary>租户</summary>
|
|
[DisplayName("租户")]
|
|
[Description("租户")]
|
|
[DataObjectField(false, false, false, 0)]
|
|
[BindColumn("TenantId", "租户", "")]
|
|
public Int32 TenantId { get => _TenantId; set { if (OnPropertyChanging("TenantId", value)) { _TenantId = value; OnPropertyChanged("TenantId"); } } }
|
|
|
|
private Int32 _UserId;
|
|
/// <summary>用户</summary>
|
|
[DisplayName("用户")]
|
|
[Description("用户")]
|
|
[DataObjectField(false, false, false, 0)]
|
|
[BindColumn("UserId", "用户", "")]
|
|
public Int32 UserId { get => _UserId; set { if (OnPropertyChanging("UserId", value)) { _UserId = value; OnPropertyChanged("UserId"); } } }
|
|
|
|
private Boolean _Enable;
|
|
/// <summary>启用</summary>
|
|
[DisplayName("启用")]
|
|
[Description("启用")]
|
|
[DataObjectField(false, false, false, 0)]
|
|
[BindColumn("Enable", "启用", "")]
|
|
public Boolean Enable { get => _Enable; set { if (OnPropertyChanging("Enable", value)) { _Enable = value; OnPropertyChanged("Enable"); } } }
|
|
|
|
private Int32 _RoleId;
|
|
/// <summary>角色。用户在该租户所对应的主要角色,替换用户自身的角色组</summary>
|
|
[DisplayName("角色")]
|
|
[Description("角色。用户在该租户所对应的主要角色,替换用户自身的角色组")]
|
|
[DataObjectField(false, false, false, 0)]
|
|
[BindColumn("RoleId", "角色。用户在该租户所对应的主要角色,替换用户自身的角色组", "")]
|
|
public Int32 RoleId { get => _RoleId; set { if (OnPropertyChanging("RoleId", value)) { _RoleId = value; OnPropertyChanged("RoleId"); } } }
|
|
|
|
private String? _RoleIds;
|
|
/// <summary>角色组。次要角色集合</summary>
|
|
[DisplayName("角色组")]
|
|
[Description("角色组。次要角色集合")]
|
|
[DataObjectField(false, false, true, 200)]
|
|
[BindColumn("RoleIds", "角色组。次要角色集合", "")]
|
|
public String? RoleIds { get => _RoleIds; set { if (OnPropertyChanging("RoleIds", value)) { _RoleIds = value; OnPropertyChanged("RoleIds"); } } }
|
|
|
|
private Int32 _CreateUserId;
|
|
/// <summary>创建者</summary>
|
|
[Category("扩展")]
|
|
[DisplayName("创建者")]
|
|
[Description("创建者")]
|
|
[DataObjectField(false, false, false, 0)]
|
|
[BindColumn("CreateUserId", "创建者", "")]
|
|
public Int32 CreateUserId { get => _CreateUserId; set { if (OnPropertyChanging("CreateUserId", value)) { _CreateUserId = value; OnPropertyChanged("CreateUserId"); } } }
|
|
|
|
private DateTime _CreateTime;
|
|
/// <summary>创建时间</summary>
|
|
[Category("扩展")]
|
|
[DisplayName("创建时间")]
|
|
[Description("创建时间")]
|
|
[DataObjectField(false, false, true, 0)]
|
|
[BindColumn("CreateTime", "创建时间", "")]
|
|
public DateTime CreateTime { get => _CreateTime; set { if (OnPropertyChanging("CreateTime", value)) { _CreateTime = value; OnPropertyChanged("CreateTime"); } } }
|
|
|
|
private String? _CreateIP;
|
|
/// <summary>创建地址</summary>
|
|
[Category("扩展")]
|
|
[DisplayName("创建地址")]
|
|
[Description("创建地址")]
|
|
[DataObjectField(false, false, true, 50)]
|
|
[BindColumn("CreateIP", "创建地址", "")]
|
|
public String? CreateIP { get => _CreateIP; set { if (OnPropertyChanging("CreateIP", value)) { _CreateIP = value; OnPropertyChanged("CreateIP"); } } }
|
|
|
|
private Int32 _UpdateUserId;
|
|
/// <summary>更新者</summary>
|
|
[Category("扩展")]
|
|
[DisplayName("更新者")]
|
|
[Description("更新者")]
|
|
[DataObjectField(false, false, false, 0)]
|
|
[BindColumn("UpdateUserId", "更新者", "")]
|
|
public Int32 UpdateUserId { get => _UpdateUserId; set { if (OnPropertyChanging("UpdateUserId", value)) { _UpdateUserId = value; OnPropertyChanged("UpdateUserId"); } } }
|
|
|
|
private DateTime _UpdateTime;
|
|
/// <summary>更新时间</summary>
|
|
[Category("扩展")]
|
|
[DisplayName("更新时间")]
|
|
[Description("更新时间")]
|
|
[DataObjectField(false, false, true, 0)]
|
|
[BindColumn("UpdateTime", "更新时间", "")]
|
|
public DateTime UpdateTime { get => _UpdateTime; set { if (OnPropertyChanging("UpdateTime", value)) { _UpdateTime = value; OnPropertyChanged("UpdateTime"); } } }
|
|
|
|
private String? _UpdateIP;
|
|
/// <summary>更新地址</summary>
|
|
[Category("扩展")]
|
|
[DisplayName("更新地址")]
|
|
[Description("更新地址")]
|
|
[DataObjectField(false, false, true, 50)]
|
|
[BindColumn("UpdateIP", "更新地址", "")]
|
|
public String? UpdateIP { get => _UpdateIP; set { if (OnPropertyChanging("UpdateIP", value)) { _UpdateIP = value; OnPropertyChanged("UpdateIP"); } } }
|
|
|
|
private String? _Remark;
|
|
/// <summary>描述</summary>
|
|
[Category("扩展")]
|
|
[DisplayName("描述")]
|
|
[Description("描述")]
|
|
[DataObjectField(false, false, true, 500)]
|
|
[BindColumn("Remark", "描述", "")]
|
|
public String? Remark { get => _Remark; set { if (OnPropertyChanging("Remark", value)) { _Remark = value; OnPropertyChanged("Remark"); } } }
|
|
#endregion
|
|
|
|
#region 拷贝
|
|
/// <summary>拷贝模型对象</summary>
|
|
/// <param name="model">模型</param>
|
|
public void Copy(ITenantUser model)
|
|
{
|
|
Id = model.Id;
|
|
TenantId = model.TenantId;
|
|
UserId = model.UserId;
|
|
Enable = model.Enable;
|
|
RoleId = model.RoleId;
|
|
RoleIds = model.RoleIds;
|
|
Remark = model.Remark;
|
|
}
|
|
#endregion
|
|
|
|
#region 获取/设置 字段值
|
|
/// <summary>获取/设置 字段值</summary>
|
|
/// <param name="name">字段名</param>
|
|
/// <returns></returns>
|
|
public override Object? this[String name]
|
|
{
|
|
get => name switch
|
|
{
|
|
"Id" => _Id,
|
|
"TenantId" => _TenantId,
|
|
"UserId" => _UserId,
|
|
"Enable" => _Enable,
|
|
"RoleId" => _RoleId,
|
|
"RoleIds" => _RoleIds,
|
|
"CreateUserId" => _CreateUserId,
|
|
"CreateTime" => _CreateTime,
|
|
"CreateIP" => _CreateIP,
|
|
"UpdateUserId" => _UpdateUserId,
|
|
"UpdateTime" => _UpdateTime,
|
|
"UpdateIP" => _UpdateIP,
|
|
"Remark" => _Remark,
|
|
_ => base[name]
|
|
};
|
|
set
|
|
{
|
|
switch (name)
|
|
{
|
|
case "Id": _Id = value.ToInt(); break;
|
|
case "TenantId": _TenantId = value.ToInt(); break;
|
|
case "UserId": _UserId = value.ToInt(); break;
|
|
case "Enable": _Enable = value.ToBoolean(); break;
|
|
case "RoleId": _RoleId = value.ToInt(); break;
|
|
case "RoleIds": _RoleIds = Convert.ToString(value); break;
|
|
case "CreateUserId": _CreateUserId = value.ToInt(); break;
|
|
case "CreateTime": _CreateTime = value.ToDateTime(); break;
|
|
case "CreateIP": _CreateIP = Convert.ToString(value); break;
|
|
case "UpdateUserId": _UpdateUserId = value.ToInt(); break;
|
|
case "UpdateTime": _UpdateTime = value.ToDateTime(); break;
|
|
case "UpdateIP": _UpdateIP = Convert.ToString(value); break;
|
|
case "Remark": _Remark = Convert.ToString(value); break;
|
|
default: base[name] = value; break;
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 关联映射
|
|
/// <summary>租户</summary>
|
|
[XmlIgnore, IgnoreDataMember, ScriptIgnore]
|
|
public Tenant? Tenant => Extends.Get(nameof(Tenant), k => Tenant.FindById(TenantId));
|
|
|
|
/// <summary>租户</summary>
|
|
[Map(nameof(TenantId), typeof(Tenant), "Id")]
|
|
public String? TenantName => Tenant?.ToString();
|
|
|
|
/// <summary>用户</summary>
|
|
[XmlIgnore, IgnoreDataMember, ScriptIgnore]
|
|
public User? User => Extends.Get(nameof(User), k => User.FindByID(UserId));
|
|
|
|
/// <summary>用户</summary>
|
|
[Map(nameof(UserId), typeof(User), "ID")]
|
|
public String? UserName => User?.ToString();
|
|
|
|
/// <summary>角色</summary>
|
|
[XmlIgnore, IgnoreDataMember, ScriptIgnore]
|
|
public Role? Role => Extends.Get(nameof(Role), k => Role.FindByID(RoleId));
|
|
|
|
/// <summary>角色</summary>
|
|
[Map(nameof(RoleId), typeof(Role), "ID")]
|
|
public String? RoleName => Role?.Name;
|
|
|
|
#endregion
|
|
|
|
#region 扩展查询
|
|
/// <summary>根据编号查找</summary>
|
|
/// <param name="id">编号</param>
|
|
/// <returns>实体对象</returns>
|
|
public static TenantUser? FindById(Int32 id)
|
|
{
|
|
if (id < 0) return null;
|
|
|
|
// 实体缓存
|
|
if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.Id == id);
|
|
|
|
// 单对象缓存
|
|
return Meta.SingleCache[id];
|
|
|
|
//return Find(_.Id == id);
|
|
}
|
|
|
|
/// <summary>根据租户、用户查找</summary>
|
|
/// <param name="tenantId">租户</param>
|
|
/// <param name="userId">用户</param>
|
|
/// <returns>实体对象</returns>
|
|
public static TenantUser? FindByTenantIdAndUserId(Int32 tenantId, Int32 userId)
|
|
{
|
|
if (tenantId < 0) return null;
|
|
if (userId < 0) return null;
|
|
|
|
// 实体缓存
|
|
if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.TenantId == tenantId && e.UserId == userId);
|
|
|
|
return Find(_.TenantId == tenantId & _.UserId == userId);
|
|
}
|
|
|
|
/// <summary>根据租户查找</summary>
|
|
/// <param name="tenantId">租户</param>
|
|
/// <returns>实体列表</returns>
|
|
public static IList<TenantUser> FindAllByTenantId(Int32 tenantId)
|
|
{
|
|
if (tenantId < 0) return [];
|
|
|
|
// 实体缓存
|
|
if (Meta.Session.Count < 1000) return Meta.Cache.FindAll(e => e.TenantId == tenantId);
|
|
|
|
return FindAll(_.TenantId == tenantId);
|
|
}
|
|
|
|
/// <summary>根据用户查找</summary>
|
|
/// <param name="userId">用户</param>
|
|
/// <returns>实体列表</returns>
|
|
public static IList<TenantUser> FindAllByUserId(Int32 userId)
|
|
{
|
|
if (userId < 0) return [];
|
|
|
|
// 实体缓存
|
|
if (Meta.Session.Count < 1000) return Meta.Cache.FindAll(e => e.UserId == userId);
|
|
|
|
return FindAll(_.UserId == userId);
|
|
}
|
|
#endregion
|
|
|
|
#region 字段名
|
|
/// <summary>取得租户关系字段信息的快捷方式</summary>
|
|
public partial class _
|
|
{
|
|
/// <summary>编号</summary>
|
|
public static readonly Field Id = FindByName("Id");
|
|
|
|
/// <summary>租户</summary>
|
|
public static readonly Field TenantId = FindByName("TenantId");
|
|
|
|
/// <summary>用户</summary>
|
|
public static readonly Field UserId = FindByName("UserId");
|
|
|
|
/// <summary>启用</summary>
|
|
public static readonly Field Enable = FindByName("Enable");
|
|
|
|
/// <summary>角色。用户在该租户所对应的主要角色,替换用户自身的角色组</summary>
|
|
public static readonly Field RoleId = FindByName("RoleId");
|
|
|
|
/// <summary>角色组。次要角色集合</summary>
|
|
public static readonly Field RoleIds = FindByName("RoleIds");
|
|
|
|
/// <summary>创建者</summary>
|
|
public static readonly Field CreateUserId = FindByName("CreateUserId");
|
|
|
|
/// <summary>创建时间</summary>
|
|
public static readonly Field CreateTime = FindByName("CreateTime");
|
|
|
|
/// <summary>创建地址</summary>
|
|
public static readonly Field CreateIP = FindByName("CreateIP");
|
|
|
|
/// <summary>更新者</summary>
|
|
public static readonly Field UpdateUserId = FindByName("UpdateUserId");
|
|
|
|
/// <summary>更新时间</summary>
|
|
public static readonly Field UpdateTime = FindByName("UpdateTime");
|
|
|
|
/// <summary>更新地址</summary>
|
|
public static readonly Field UpdateIP = FindByName("UpdateIP");
|
|
|
|
/// <summary>描述</summary>
|
|
public static readonly Field Remark = FindByName("Remark");
|
|
|
|
static Field FindByName(String name) => Meta.Table.FindByName(name);
|
|
}
|
|
|
|
/// <summary>取得租户关系字段名称的快捷方式</summary>
|
|
public partial class __
|
|
{
|
|
/// <summary>编号</summary>
|
|
public const String Id = "Id";
|
|
|
|
/// <summary>租户</summary>
|
|
public const String TenantId = "TenantId";
|
|
|
|
/// <summary>用户</summary>
|
|
public const String UserId = "UserId";
|
|
|
|
/// <summary>启用</summary>
|
|
public const String Enable = "Enable";
|
|
|
|
/// <summary>角色。用户在该租户所对应的主要角色,替换用户自身的角色组</summary>
|
|
public const String RoleId = "RoleId";
|
|
|
|
/// <summary>角色组。次要角色集合</summary>
|
|
public const String RoleIds = "RoleIds";
|
|
|
|
/// <summary>创建者</summary>
|
|
public const String CreateUserId = "CreateUserId";
|
|
|
|
/// <summary>创建时间</summary>
|
|
public const String CreateTime = "CreateTime";
|
|
|
|
/// <summary>创建地址</summary>
|
|
public const String CreateIP = "CreateIP";
|
|
|
|
/// <summary>更新者</summary>
|
|
public const String UpdateUserId = "UpdateUserId";
|
|
|
|
/// <summary>更新时间</summary>
|
|
public const String UpdateTime = "UpdateTime";
|
|
|
|
/// <summary>更新地址</summary>
|
|
public const String UpdateIP = "UpdateIP";
|
|
|
|
/// <summary>描述</summary>
|
|
public const String Remark = "Remark";
|
|
}
|
|
#endregion
|
|
}
|