招聘后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.5 KiB

using Dapper;
using System.Text;
using Znyc.Recruitment.Admin.Commons.Enums;
using Znyc.Recruitment.Admin.Commons.IDbContext;
using Znyc.Recruitment.Admin.Commons.Repositories;
using Znyc.Recruitment.Admin.Security.Entitys;
using Znyc.Recruitment.Admin.Security.IRepositories;
namespace Znyc.Recruitment.Admin.Security.Repositories
{
public class OrganizeRepository : BaseRepository<OrganizeEntity, long>, IOrganizeRepository
{
public OrganizeRepository()
{
}
public OrganizeRepository(IDbContextCore dbContext) : base(dbContext)
{
}
/// <summary>
/// ��ȡ���ڵ���֯
/// </summary>
/// <param name="id">��֯Id</param>
/// <returns></returns>
public OrganizeEntity GetRootOrganize(long id)
{
StringBuilder sb = new StringBuilder(";WITH ");
if (dbConnectionOptions.DatabaseType == DatabaseType.MySql)
{
sb.Append(" Recursive ");
}
sb.Append(" T AS (");
sb.Append(" SELECT Id, ParentId, FullName, Layers FROM sys_organize");
sb.AppendFormat(" WHERE Id = '{0}'", id);
sb.Append(" UNION ALL ");
sb.Append(
" SELECT A.Id, A.ParentId, A.FullName, A.Layers FROM sys_organize AS A JOIN T AS B ON A.Id = B.ParentId ) SELECT* FROM T ORDER BY Layers");
return DapperConn.QueryFirstOrDefault<OrganizeEntity>(sb.ToString());
}
}
}