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, IOrganizeRepository { public OrganizeRepository() { } public OrganizeRepository(IDbContextCore dbContext) : base(dbContext) { } /// /// 获取根节点组织 /// /// 组织Id /// 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(sb.ToString()); } } }