Skip to content

Commit

Permalink
部门表取消唯一索引,有些场景,部门名称并不唯一,而编码唯一
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Nov 27, 2024
1 parent 39ae469 commit 1c00c17
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 24 deletions.
5 changes: 3 additions & 2 deletions XCode/Membership/Member.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<Column Name="Remark" DataType="String" Length="500" Description="备注" Category="扩展" />
</Columns>
<Indexes>
<Index Columns="TenantId,ParentID,Name" Unique="True" />
<Index Columns="TenantId,ParentID,Name" />
<Index Columns="Name" />
<Index Columns="ParentID,Name" />
<Index Columns="Code" />
Expand Down Expand Up @@ -151,7 +151,8 @@
<Column Name="Remark" DataType="String" Length="500" Description="备注" Category="扩展" />
</Columns>
<Indexes>
<Index Columns="Name" Unique="True" />
<Index Columns="Name" />
<Index Columns="TenantId,Name" />
</Indexes>
</Table>
<Table Name="Menu" Description="菜单。功能权限,大多数时候也是可见页面" BaseType="EntityTree">
Expand Down
2 changes: 1 addition & 1 deletion XCode/Membership/Membership.htm
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ <h3>角色(Role)</h3>
<td>String</td>
<td>50</td>
<td></td>
<td title="唯一索引">UQ</td>
<td></td>
<td>N</td>
<td></td>
</tr>
Expand Down
30 changes: 29 additions & 1 deletion XCode/Membership/角色.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ namespace XCode.Membership;
[Serializable]
[DataObject]
[Description("角色。业务场景中的岗位,功能权限的集合。不管是用户还是租户,都以角色来管理权限")]
[BindIndex("IU_Role_Name", true, "Name")]
[BindIndex("IX_Role_Name", false, "Name")]
[BindIndex("IX_Role_TenantId_Name", false, "TenantId,Name")]
[BindTable("Role", Description = "角色。业务场景中的岗位,功能权限的集合。不管是用户还是租户,都以角色来管理权限", ConnName = "Membership", DbType = DatabaseType.None)]
public partial class Role : IRole, IEntity<IRole>
{
Expand Down Expand Up @@ -320,6 +321,33 @@ public override Object? this[String name]
#endregion

#region 扩展查询
/// <summary>根据名称查找</summary>
/// <param name="name">名称</param>
/// <returns>实体列表</returns>
public static IList<Role> FindAllByName(String name)
{
if (name.IsNullOrEmpty()) return [];

// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.FindAll(e => e.Name.EqualIgnoreCase(name));

return FindAll(_.Name == name);
}

/// <summary>根据租户、名称查找</summary>
/// <param name="tenantId">租户</param>
/// <param name="name">名称</param>
/// <returns>实体列表</returns>
public static IList<Role> FindAllByTenantIdAndName(Int32 tenantId, String name)
{
if (tenantId < 0) return [];
if (name.IsNullOrEmpty()) return [];

// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.FindAll(e => e.TenantId == tenantId && e.Name.EqualIgnoreCase(name));

return FindAll(_.TenantId == tenantId & _.Name == name);
}
#endregion

#region 字段名
Expand Down
25 changes: 5 additions & 20 deletions XCode/Membership/部门.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace XCode.Membership;
[Serializable]
[DataObject]
[Description("部门。组织机构,多级树状结构,支持多租户")]
[BindIndex("IU_Department_TenantId_ParentID_Name", true, "TenantId,ParentID,Name")]
[BindIndex("IX_Department_TenantId_ParentID_Name", false, "TenantId,ParentID,Name")]
[BindIndex("IX_Department_Name", false, "Name")]
[BindIndex("IX_Department_ParentID_Name", false, "ParentID,Name")]
[BindIndex("IX_Department_Code", false, "Code")]
Expand Down Expand Up @@ -380,32 +380,17 @@ public override Object? this[String name]
/// <param name="tenantId">租户</param>
/// <param name="parentId">父级</param>
/// <param name="name">名称</param>
/// <returns>实体对象</returns>
public static Department? FindByTenantIdAndParentIDAndName(Int32 tenantId, Int32 parentId, String name)
{
if (tenantId < 0) return null;
if (parentId < 0) return null;
if (name.IsNullOrEmpty()) return null;

// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.TenantId == tenantId && e.ParentID == parentId && e.Name.EqualIgnoreCase(name));

return Find(_.TenantId == tenantId & _.ParentID == parentId & _.Name == name);
}

/// <summary>根据租户、父级查找</summary>
/// <param name="tenantId">租户</param>
/// <param name="parentId">父级</param>
/// <returns>实体列表</returns>
public static IList<Department> FindAllByTenantIdAndParentID(Int32 tenantId, Int32 parentId)
public static IList<Department> FindAllByTenantIdAndParentIDAndName(Int32 tenantId, Int32 parentId, String name)
{
if (tenantId < 0) return [];
if (parentId < 0) return [];
if (name.IsNullOrEmpty()) return [];

// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.FindAll(e => e.TenantId == tenantId && e.ParentID == parentId);
if (Meta.Session.Count < 1000) return Meta.Cache.FindAll(e => e.TenantId == tenantId && e.ParentID == parentId && e.Name.EqualIgnoreCase(name));

return FindAll(_.TenantId == tenantId & _.ParentID == parentId);
return FindAll(_.TenantId == tenantId & _.ParentID == parentId & _.Name == name);
}

/// <summary>根据代码查找</summary>
Expand Down

0 comments on commit 1c00c17

Please sign in to comment.