102 lines
3.7 KiB
C#
102 lines
3.7 KiB
C#
/***********************************************************
|
|
**项目名称: BZPT.Repositories
|
|
**功能描述: 系统注册表
|
|
**作 者: 初版由CodeSmith生成。
|
|
**版 本 号: 1.0
|
|
**修改历史:
|
|
************************************************************/
|
|
namespace BZPT.Repositories.Sys
|
|
{
|
|
using System;
|
|
using System.Linq;
|
|
using BZPT.Domains.IRepositories.Sys;
|
|
using BZPT.Domains.Entity.Sys;
|
|
using System.Threading.Tasks;
|
|
using System.Collections.Generic;
|
|
using BZPT.Dto.Sys;
|
|
|
|
/// <summary>
|
|
/// ProjectInfoService仓储操作
|
|
/// </summary>
|
|
public partial class ProjectInfoRepository : DefaultRepository<ProjectInfo>, IProjectInfoRepository
|
|
{
|
|
private readonly DBContext _dbContext;
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="ProjectInfoRepository"/> class.
|
|
/// </summary>
|
|
/// <param name="options">
|
|
/// The options.
|
|
/// </param>
|
|
public ProjectInfoRepository(IRepositoryOptions options, DBContext db)
|
|
: base(options,db)
|
|
{
|
|
_dbContext = db; // 存储上下文实例
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据名称获取
|
|
/// </summary>
|
|
/// <param name="name">名称</param>
|
|
/// <returns>匹配的组织实体</returns>
|
|
public async Task<IEnumerable<ProjectInfo>> GetByNameAsync(string name, string proID)
|
|
{
|
|
try
|
|
{
|
|
if (!string.IsNullOrEmpty(proID))
|
|
{
|
|
return await _dbContext.Queryable<ProjectInfo>()
|
|
.Where(ac => ac.AC002 == name && !ac.IsDeleted && ac.Id != proID)// 假设 IsDeleted 是逻辑删除标识
|
|
.ToListAsync();
|
|
}
|
|
else
|
|
{
|
|
return await _dbContext.Queryable<ProjectInfo>()
|
|
.Where(ac => ac.AC002 == name && !ac.IsDeleted)// 假设 IsDeleted 是逻辑删除标识
|
|
.ToListAsync();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
// 记录日志或处理异常
|
|
throw new RepositoryException("查询时发生错误", ex);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//// 获取下级全部机构 ID 的方法
|
|
//public async Task<List<string>> GetAllSubOrganizationIdsAsync(string projectId)
|
|
//{
|
|
// List<string> subOrganizationIds = new List<string>();
|
|
|
|
// // 使用 Queryable 查询获取所有下级机构
|
|
// var organizations = await _dbContext.Queryable<Organization>()
|
|
// .Where(o => o.ParentId == projectId)
|
|
// .ToListAsync();
|
|
|
|
// foreach (var org in organizations)
|
|
// {
|
|
// subOrganizationIds.Add(org.Id);
|
|
// // 递归调用获取下级机构
|
|
// subOrganizationIds.AddRange(await GetAllSubOrganizationIdsAsync(org.Id));
|
|
// }
|
|
|
|
// return subOrganizationIds;
|
|
//}
|
|
//// 获取下级机构 ID 的方法
|
|
//public async Task<List<string>> GetSubOrganizationIdsAsync(string projectId)
|
|
//{
|
|
// // 使用 Queryable 查询获取所有直接下级机构
|
|
// var organizations = await _dbContext.Queryable<Organization>()
|
|
// .Where(o => o.ParentId == projectId)
|
|
// .ToListAsync();
|
|
|
|
// // 提取下级机构的 ID 到列表
|
|
// List<string> subOrganizationIds = organizations.Select(org => org.Id).ToList();
|
|
|
|
// return subOrganizationIds;
|
|
//}
|
|
|
|
|
|
}
|
|
} |