Выгрузка маршрутов: сборка таблицы перенесена на бэкенд, добавлены организация, комментарий и деление на согласующих/исполнителей
Бэкенд сам читает маршруты, шаги и справочники портала (сотрудники с должностями, компании, отделы), фронт шлёт только id типов заявок и скачивает файл. Колонки: №, Роль, Исполнитель, Организация, Условие, Комментарий. Согласующие и исполнители — отдельными таблицами. Условие по CompaniesJson показывается как «организация». Директор Tansu и Управляющий директор Tansu выводятся с ФИО. Комментарий «назначает согласующего/исполнителя» — при галочке переназначения. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,7 +15,7 @@ namespace Tnsu.ApprovalRoute.Api.Controllers;
|
||||
[ApiController]
|
||||
[Authorize(Policy = AuthPolicies.Any)]
|
||||
[Route("api/reports")]
|
||||
public sealed class ReportsController(VacancyReportService vacancies) : ControllerBase
|
||||
public sealed class ReportsController(VacancyReportService vacancies, RouteExportService routeExport) : ControllerBase
|
||||
{
|
||||
private const string XlsxContentType =
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
||||
@@ -54,19 +54,19 @@ public sealed class ReportsController(VacancyReportService vacancies) : Controll
|
||||
|
||||
/// <summary>
|
||||
/// Выгрузка маршрутов согласования выбранных типов заявок в xlsx (лист на тип).
|
||||
/// POST, потому что строки собирает админка — у неё уже есть справочники
|
||||
/// сотрудников и подписи шагов (см. RouteExportWorkbook).
|
||||
/// POST — потому что в теле список id типов (см. RouteExportService).
|
||||
/// </summary>
|
||||
[HttpPost("routes")]
|
||||
[Produces(XlsxContentType)]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public IActionResult Routes([FromBody] RouteExportRequest request)
|
||||
public async Task<IActionResult> Routes([FromBody] RouteExportRequest request, CancellationToken ct = default)
|
||||
{
|
||||
if (request.Sheets is not { Count: > 0 })
|
||||
return BadRequest(new { errors = new[] { "Не выбрано ни одного типа заявки." } });
|
||||
var result = await routeExport.BuildAsync(request.RequestTypeIds, ct);
|
||||
if (result.IsFailed)
|
||||
return BadRequest(new { errors = result.Errors.Select(e => e.Message) });
|
||||
|
||||
var file = RouteExportWorkbook.Build(request);
|
||||
var file = result.Value;
|
||||
|
||||
var disposition = new ContentDispositionHeaderValue("attachment");
|
||||
disposition.SetHttpFileName(RouteExportWorkbook.FileName);
|
||||
|
||||
@@ -28,6 +28,7 @@ public static class ApplicationServiceCollectionExtensions
|
||||
services.AddScoped<AutoApproveService>();
|
||||
services.AddScoped<AutoApproveJob>();
|
||||
services.AddScoped<VacancyReportService>();
|
||||
services.AddScoped<RouteExportService>();
|
||||
services.AddScoped<TemplateRouteService>();
|
||||
services.AddScoped<TemplateRouteStepService>();
|
||||
|
||||
|
||||
@@ -0,0 +1,249 @@
|
||||
using FluentResults;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Tnsu.ApprovalRoute.Domain.Entities;
|
||||
using Tnsu.ApprovalRoute.Domain.Enums;
|
||||
using Tnsu.ApprovalRoute.Infrastructure.Persistence;
|
||||
using Tnsu.ApprovalRoute.Infrastructure.TnsuPortal;
|
||||
|
||||
namespace Tnsu.ApprovalRoute.Application.Reports;
|
||||
|
||||
/// <summary>
|
||||
/// Выгрузка маршрутов согласования: читает маршруты и шаги выбранных типов
|
||||
/// заявок, превращает их в понятные человеку строки (роль, исполнитель,
|
||||
/// организация, условие, комментарий) и отдаёт на вёрстку в
|
||||
/// <see cref="RouteExportWorkbook"/>.
|
||||
///
|
||||
/// Шаги делятся на две таблицы — «Согласующие» и «Исполнители» (фаза шага,
|
||||
/// <see cref="RouteStepStatus"/>), у каждой своя нумерация.
|
||||
/// </summary>
|
||||
public sealed class RouteExportService(
|
||||
ApprovalRouteDbContext db,
|
||||
ITnsuPortalClient portalClient,
|
||||
IOptions<TnsuPortalOptions> portalOptions)
|
||||
{
|
||||
private const string Empty = "—";
|
||||
private const string Always = "Всегда";
|
||||
private const string AnyOrganization = "Любая";
|
||||
private const string AnyCompany = "любая компания";
|
||||
private const string AnyDepartment = "любой отдел";
|
||||
private const string ByRequest = "Определяется по заявке";
|
||||
|
||||
/// <summary>
|
||||
/// Технические имена колонок списка, которые в таблице показываем по-человечески
|
||||
/// (CompaniesJson — организации заявки).
|
||||
/// </summary>
|
||||
private static readonly Dictionary<string, string> ConditionFieldAliases = new(StringComparer.Ordinal)
|
||||
{
|
||||
["CompaniesJson"] = "организация"
|
||||
};
|
||||
|
||||
private static readonly Dictionary<ProjectRole, string> ProjectRoleLabels = new()
|
||||
{
|
||||
[ProjectRole.ProjectManager] = "Руководитель проекта",
|
||||
[ProjectRole.Planner] = "Планировщик",
|
||||
[ProjectRole.ManagerHSE] = "Менеджер HSE",
|
||||
[ProjectRole.Security] = "Безопасность",
|
||||
[ProjectRole.Keeper] = "Заведующий склада"
|
||||
};
|
||||
|
||||
private static readonly Dictionary<HeadType, string> HeadTypeLabels = new()
|
||||
{
|
||||
[HeadType.Chief] = "Непосредственный руководитель",
|
||||
[HeadType.DirectionHead] = "Руководитель направления",
|
||||
[HeadType.DirectorTansu] = "Директор Tansu",
|
||||
[HeadType.ManagingDirectorTansu] = "Управляющий директор Tansu",
|
||||
[HeadType.DepartmentHead] = "Руководитель указанного отдела",
|
||||
[HeadType.CompanyDirectors] = "Директора компаний инициатора"
|
||||
};
|
||||
|
||||
private static readonly Dictionary<ComparisonOperator, string> OperatorSymbols = new()
|
||||
{
|
||||
[ComparisonOperator.GreaterThan] = ">",
|
||||
[ComparisonOperator.LessThan] = "<",
|
||||
[ComparisonOperator.Equal] = "=",
|
||||
[ComparisonOperator.NotEqual] = "≠",
|
||||
[ComparisonOperator.Contains] = "содержит",
|
||||
[ComparisonOperator.NotContains] = "не содержит"
|
||||
};
|
||||
|
||||
public async Task<Result<byte[]>> BuildAsync(IReadOnlyList<int>? requestTypeIds, CancellationToken cancellationToken)
|
||||
{
|
||||
if (requestTypeIds is not { Count: > 0 })
|
||||
return Result.Fail("Не выбрано ни одного типа заявки.");
|
||||
|
||||
var types = await db.RequestTypes.AsNoTracking()
|
||||
.Where(x => requestTypeIds.Contains(x.Id))
|
||||
.OrderBy(x => x.Name)
|
||||
.ToListAsync(cancellationToken);
|
||||
if (types.Count == 0)
|
||||
return Result.Fail("Выбранные типы заявок не найдены.");
|
||||
|
||||
var routes = await db.TemplateRoutes.AsNoTracking()
|
||||
.Where(x => requestTypeIds.Contains(x.RequestTypeId))
|
||||
.Include(x => x.Steps).ThenInclude(s => s.Conditions)
|
||||
.OrderBy(x => x.Id)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
var directory = await LoadDirectoryAsync(cancellationToken);
|
||||
|
||||
var sheets = types
|
||||
.Select(type => BuildSheet(type, routes.Where(r => r.RequestTypeId == type.Id).ToList(), directory))
|
||||
.ToList();
|
||||
|
||||
return Result.Ok(RouteExportWorkbook.Build(sheets));
|
||||
}
|
||||
|
||||
private async Task<PortalDirectory> LoadDirectoryAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
// Справочники кешируются клиентом портала (см. CachingTnsuPortalClient).
|
||||
var employees = await portalClient.GetAllEmployeesAsync(cancellationToken);
|
||||
var companies = await portalClient.GetCompaniesAsync(cancellationToken);
|
||||
var departments = await portalClient.GetDepartmentsAsync(cancellationToken);
|
||||
|
||||
return new PortalDirectory(
|
||||
employees,
|
||||
companies.GroupBy(c => c.Id).ToDictionary(g => g.Key, g => g.First().Name),
|
||||
departments.GroupBy(d => d.Id).ToDictionary(g => g.Key, g => g.First().Name));
|
||||
}
|
||||
|
||||
private RouteExportSheet BuildSheet(RequestType type, IReadOnlyList<TemplateRoute> routes, PortalDirectory directory)
|
||||
{
|
||||
var sections = routes
|
||||
.Select(route =>
|
||||
{
|
||||
var organization = route.CompanyId is { } companyId
|
||||
? directory.CompanyName(companyId)
|
||||
: AnyOrganization;
|
||||
return new RouteExportSection(
|
||||
routes.Count < 2 ? null : RouteTitle(route, directory),
|
||||
BuildGroups(route.Steps, organization, directory));
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return new RouteExportSheet(type.Name, sections);
|
||||
}
|
||||
|
||||
private static string RouteTitle(TemplateRoute route, PortalDirectory directory)
|
||||
{
|
||||
var company = route.CompanyId is { } c ? directory.CompanyName(c) : AnyCompany;
|
||||
var department = route.DepartmentId is { } d ? directory.DepartmentName(d) : AnyDepartment;
|
||||
return $"Маршрут: {company} · {department}{(route.ByProject ? " · по проекту" : string.Empty)}";
|
||||
}
|
||||
|
||||
private List<RouteExportGroup> BuildGroups(IEnumerable<TemplateRouteStep> steps, string organization, PortalDirectory directory)
|
||||
{
|
||||
var ordered = steps.OrderBy(s => s.OrderNo).ToList();
|
||||
var approvers = ordered.Where(s => s.Status != RouteStepStatus.Execution).ToList();
|
||||
var executors = ordered.Where(s => s.Status == RouteStepStatus.Execution).ToList();
|
||||
|
||||
return new[]
|
||||
{
|
||||
new RouteExportGroup("Согласующие", BuildRows(approvers, organization, directory)),
|
||||
new RouteExportGroup("Исполнители", BuildRows(executors, organization, directory))
|
||||
}
|
||||
.Where(g => g.Rows.Count > 0)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
// Параллельные шаги (равный OrderNo) получают один и тот же номер.
|
||||
private List<RouteExportRow> BuildRows(IReadOnlyList<TemplateRouteStep> steps, string organization, PortalDirectory directory)
|
||||
{
|
||||
var orderNos = steps.Select(s => s.OrderNo).Distinct().OrderBy(n => n).ToList();
|
||||
|
||||
return steps
|
||||
.Select(step =>
|
||||
{
|
||||
var (role, executor) = DescribeRoleAndExecutor(step, directory);
|
||||
return new RouteExportRow(
|
||||
orderNos.IndexOf(step.OrderNo) + 1,
|
||||
role,
|
||||
executor,
|
||||
organization,
|
||||
DescribeCondition(step),
|
||||
DescribeComment(step));
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
// «Роль» — должность или тип руководителя, «исполнитель» — конкретный человек,
|
||||
// если он известен уже при настройке маршрута. Директор Tansu и Управляющий
|
||||
// директор Tansu — тоже конкретные люди (их email лежит в настройках).
|
||||
private (string Role, string Executor) DescribeRoleAndExecutor(TemplateRouteStep step, PortalDirectory directory)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(step.ExecutorEmail))
|
||||
{
|
||||
var employee = directory.FindByEmail(step.ExecutorEmail);
|
||||
return (EmptyIfBlank(employee?.Position), employee?.Fio ?? step.ExecutorEmail);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(step.Position))
|
||||
return (step.Position, directory.FindByPosition(step.Position)?.Fio ?? Empty);
|
||||
|
||||
if (step.ProjectRole is { } projectRole && projectRole != ProjectRole.None)
|
||||
return (ProjectRoleLabels[projectRole], ByRequest);
|
||||
|
||||
if (step.HeadType is { } headType && headType != HeadType.None)
|
||||
{
|
||||
var fixedEmail = headType switch
|
||||
{
|
||||
HeadType.DirectorTansu => portalOptions.Value.DirectorTansuEmail,
|
||||
HeadType.ManagingDirectorTansu => portalOptions.Value.ManagingDirectorTansuEmail,
|
||||
_ => null
|
||||
};
|
||||
if (fixedEmail is not null)
|
||||
// Нет в справочнике — лучше показать email, чем пустую ячейку.
|
||||
return (HeadTypeLabels[headType], directory.FindByEmail(fixedEmail)?.Fio ?? fixedEmail);
|
||||
|
||||
return (HeadTypeLabels[headType], ByRequest);
|
||||
}
|
||||
|
||||
return (Empty, Empty);
|
||||
}
|
||||
|
||||
private static string DescribeCondition(TemplateRouteStep step)
|
||||
{
|
||||
if (step.Conditions.Count == 0)
|
||||
return Always;
|
||||
|
||||
var joiner = step.ConditionsLogic == ConditionsLogic.Or ? " ИЛИ " : " И ";
|
||||
return string.Join(joiner, step.Conditions.OrderBy(c => c.OrderNo).Select(c =>
|
||||
{
|
||||
var field = ConditionFieldAliases.GetValueOrDefault(c.FieldName, c.FieldName);
|
||||
var symbol = OperatorSymbols.GetValueOrDefault(c.Operation, string.Empty);
|
||||
return $"{field} {symbol} {c.Value}";
|
||||
}));
|
||||
}
|
||||
|
||||
// Галочка «можно переназначить» — шаг может передать другому: согласующий
|
||||
// назначает согласующего, исполнитель — исполнителя.
|
||||
private static string DescribeComment(TemplateRouteStep step) =>
|
||||
!step.AllowReassignToOtherApprovers
|
||||
? string.Empty
|
||||
: step.Status == RouteStepStatus.Execution ? "назначает исполнителя" : "назначает согласующего";
|
||||
|
||||
private static string EmptyIfBlank(string? value) => string.IsNullOrWhiteSpace(value) ? Empty : value;
|
||||
|
||||
private sealed class PortalDirectory(
|
||||
IReadOnlyList<EmployeeContactInfo> employees,
|
||||
IReadOnlyDictionary<Guid, string> companies,
|
||||
IReadOnlyDictionary<Guid, string> departments)
|
||||
{
|
||||
// Справочник даёт строку на каждую компанию сотрудника — берём первую с
|
||||
// заполненной должностью, остальные для ФИО/должности ничего не добавляют.
|
||||
public EmployeeContactInfo? FindByEmail(string email) =>
|
||||
employees.Where(e => string.Equals(e.Email, email, StringComparison.OrdinalIgnoreCase))
|
||||
.OrderByDescending(e => !string.IsNullOrWhiteSpace(e.Position))
|
||||
.FirstOrDefault();
|
||||
|
||||
public EmployeeContactInfo? FindByPosition(string position) =>
|
||||
employees.FirstOrDefault(e => string.Equals(e.Position?.Trim(), position.Trim(), StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
// Пока справочник не отдал имя (или запись удалена) — усечённый Guid, как в админке.
|
||||
public string CompanyName(Guid id) => companies.GetValueOrDefault(id) ?? ShortGuid(id);
|
||||
|
||||
public string DepartmentName(Guid id) => departments.GetValueOrDefault(id) ?? ShortGuid(id);
|
||||
|
||||
private static string ShortGuid(Guid id) => id.ToString()[..8];
|
||||
}
|
||||
}
|
||||
@@ -4,28 +4,37 @@ using NPOI.XSSF.UserModel;
|
||||
|
||||
namespace Tnsu.ApprovalRoute.Application.Reports;
|
||||
|
||||
/// <summary>Строка выгрузки маршрута: шаг в понятном человеку виде (подписи уже собрала админка).</summary>
|
||||
public sealed record RouteExportRow(int Number, string Role, string Executor, string Condition);
|
||||
/// <summary>Строка выгрузки маршрута: шаг в понятном человеку виде.</summary>
|
||||
public sealed record RouteExportRow(
|
||||
int Number,
|
||||
string Role,
|
||||
string Executor,
|
||||
string Organization,
|
||||
string Condition,
|
||||
string Comment);
|
||||
|
||||
/// <summary>Таблица внутри маршрута — «Согласующие» или «Исполнители» (у каждой своя нумерация).</summary>
|
||||
public sealed record RouteExportGroup(string Caption, IReadOnlyList<RouteExportRow> Rows);
|
||||
|
||||
/// <summary>
|
||||
/// Один маршрут типа заявки. Заголовок задан, когда у типа несколько маршрутов
|
||||
/// (по компании/отделу) и их нужно различать на одном листе; у единственного
|
||||
/// маршрута он пуст — лист выглядит как в образце «Маршруты согласования».
|
||||
/// </summary>
|
||||
public sealed record RouteExportSection(string? Title, IReadOnlyList<RouteExportRow> Rows);
|
||||
public sealed record RouteExportSection(string? Title, IReadOnlyList<RouteExportGroup> Groups);
|
||||
|
||||
/// <summary>Лист выгрузки — один тип заявки.</summary>
|
||||
public sealed record RouteExportSheet(string Name, IReadOnlyList<RouteExportSection> Sections);
|
||||
|
||||
public sealed record RouteExportRequest(IReadOnlyList<RouteExportSheet> Sheets);
|
||||
/// <summary>Тело запроса POST api/reports/routes — какие типы заявок выгрузить.</summary>
|
||||
public sealed record RouteExportRequest(IReadOnlyList<int> RequestTypeIds);
|
||||
|
||||
/// <summary>
|
||||
/// Выгрузка маршрутов согласования в xlsx — по образцу, который HR ведёт руками:
|
||||
/// лист на тип заявки, колонки «№ / Роль / Исполнитель / Условие».
|
||||
///
|
||||
/// Подписи (роль, ФИО исполнителя, текст условия) приходят готовыми из админки:
|
||||
/// там уже есть справочники сотрудников и логика описания шага, дублировать их
|
||||
/// на бэкенде незачем. Здесь только вёрстка файла.
|
||||
/// Здесь только вёрстка файла; подписи (роль, ФИО, текст условия) собирает
|
||||
/// <see cref="RouteExportService"/>.
|
||||
/// </summary>
|
||||
public static class RouteExportWorkbook
|
||||
{
|
||||
@@ -37,12 +46,14 @@ public static class RouteExportWorkbook
|
||||
(" ", 6.0),
|
||||
("Роль ", 41.1),
|
||||
("Исполнитель ", 42.2),
|
||||
("Организация ", 28.0),
|
||||
("Условие ", 66.2),
|
||||
("Комментарий ", 36.0),
|
||||
];
|
||||
|
||||
public const string FileName = "Маршруты согласования.xlsx";
|
||||
|
||||
public static byte[] Build(RouteExportRequest request)
|
||||
public static byte[] Build(IReadOnlyList<RouteExportSheet> sheets)
|
||||
{
|
||||
var workbook = new XSSFWorkbook();
|
||||
|
||||
@@ -51,7 +62,7 @@ public static class RouteExportWorkbook
|
||||
var titleStyle = CreateStyle(workbook, bold: true, border: false);
|
||||
|
||||
var usedNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var sheetData in request.Sheets)
|
||||
foreach (var sheetData in sheets)
|
||||
{
|
||||
var sheet = workbook.CreateSheet(UniqueSheetName(sheetData.Name, usedNames));
|
||||
for (var i = 0; i < Columns.Length; i++)
|
||||
@@ -60,8 +71,6 @@ public static class RouteExportWorkbook
|
||||
var rowIndex = 0;
|
||||
foreach (var section in sheetData.Sections)
|
||||
{
|
||||
if (rowIndex > 0) rowIndex++; // пустая строка между маршрутами
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(section.Title))
|
||||
{
|
||||
var titleRow = sheet.CreateRow(rowIndex);
|
||||
@@ -72,23 +81,37 @@ public static class RouteExportWorkbook
|
||||
rowIndex++;
|
||||
}
|
||||
|
||||
var header = sheet.CreateRow(rowIndex++);
|
||||
for (var i = 0; i < Columns.Length; i++)
|
||||
foreach (var group in section.Groups)
|
||||
{
|
||||
var cell = header.CreateCell(i);
|
||||
cell.SetCellValue(Columns[i].Title);
|
||||
cell.CellStyle = headerStyle;
|
||||
}
|
||||
var captionRow = sheet.CreateRow(rowIndex);
|
||||
var captionCell = captionRow.CreateCell(0);
|
||||
captionCell.SetCellValue(group.Caption);
|
||||
captionCell.CellStyle = titleStyle;
|
||||
sheet.AddMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 0, Columns.Length - 1));
|
||||
rowIndex++;
|
||||
|
||||
foreach (var row in section.Rows)
|
||||
{
|
||||
var excelRow = sheet.CreateRow(rowIndex++);
|
||||
var numberCell = excelRow.CreateCell(0);
|
||||
numberCell.SetCellValue(row.Number);
|
||||
numberCell.CellStyle = cellStyle;
|
||||
WriteText(excelRow, 1, row.Role, cellStyle);
|
||||
WriteText(excelRow, 2, row.Executor, cellStyle);
|
||||
WriteText(excelRow, 3, row.Condition, cellStyle);
|
||||
var header = sheet.CreateRow(rowIndex++);
|
||||
for (var i = 0; i < Columns.Length; i++)
|
||||
{
|
||||
var cell = header.CreateCell(i);
|
||||
cell.SetCellValue(Columns[i].Title);
|
||||
cell.CellStyle = headerStyle;
|
||||
}
|
||||
|
||||
foreach (var row in group.Rows)
|
||||
{
|
||||
var excelRow = sheet.CreateRow(rowIndex++);
|
||||
var numberCell = excelRow.CreateCell(0);
|
||||
numberCell.SetCellValue(row.Number);
|
||||
numberCell.CellStyle = cellStyle;
|
||||
WriteText(excelRow, 1, row.Role, cellStyle);
|
||||
WriteText(excelRow, 2, row.Executor, cellStyle);
|
||||
WriteText(excelRow, 3, row.Organization, cellStyle);
|
||||
WriteText(excelRow, 4, row.Condition, cellStyle);
|
||||
WriteText(excelRow, 5, row.Comment, cellStyle);
|
||||
}
|
||||
|
||||
rowIndex++; // пустая строка между таблицами
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,12 @@ public sealed class CachingTnsuPortalClient(HttpTnsuPortalClient inner, IMemoryC
|
||||
public Task<IReadOnlyList<EmployeeContactInfo>> GetAllEmployeesAsync(CancellationToken cancellationToken) =>
|
||||
GetOrAddAsync("emp:all", () => inner.GetAllEmployeesAsync(cancellationToken));
|
||||
|
||||
public Task<IReadOnlyList<CompanyInfo>> GetCompaniesAsync(CancellationToken cancellationToken) =>
|
||||
GetOrAddAsync("dict:companies", () => inner.GetCompaniesAsync(cancellationToken));
|
||||
|
||||
public Task<IReadOnlyList<DepartmentInfo>> GetDepartmentsAsync(CancellationToken cancellationToken) =>
|
||||
GetOrAddAsync("dict:departments", () => inner.GetDepartmentsAsync(cancellationToken));
|
||||
|
||||
public Task<string?> GetManagerAsync(string email, string managerType, CancellationToken cancellationToken) =>
|
||||
GetOrAddAsync(
|
||||
$"mgr:{email.ToLowerInvariant()}|{managerType.ToLowerInvariant()}",
|
||||
|
||||
@@ -40,7 +40,27 @@ public sealed class HttpTnsuPortalClient(
|
||||
|
||||
return employees
|
||||
.Where(e => !string.IsNullOrWhiteSpace(e.Fio))
|
||||
.Select(e => new EmployeeContactInfo(e.Id, e.Fio!, e.Email, e.Company ?? string.Empty))
|
||||
.Select(e => new EmployeeContactInfo(e.Id, e.Fio!, e.Email, e.Company ?? string.Empty, e.Position))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
// /Dictionary/* отдаёт «голый» массив с ключами в PascalCase (Id/Name) —
|
||||
// PropertyNameCaseInsensitive в JsonOptions это покрывает.
|
||||
public async Task<IReadOnlyList<CompanyInfo>> GetCompaniesAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var companies = await GetAsync<List<DictionaryItemResponse>>("/Dictionary/Companies", cancellationToken);
|
||||
return (companies ?? [])
|
||||
.Where(c => c.Id is not null && !string.IsNullOrWhiteSpace(c.Name))
|
||||
.Select(c => new CompanyInfo(c.Id!.Value, c.Name!))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyList<DepartmentInfo>> GetDepartmentsAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var departments = await GetAsync<List<DictionaryItemResponse>>("/Dictionary/Departments", cancellationToken);
|
||||
return (departments ?? [])
|
||||
.Where(d => d.Id is not null && !string.IsNullOrWhiteSpace(d.Name))
|
||||
.Select(d => new DepartmentInfo(d.Id!.Value, d.Name!))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@@ -121,6 +141,10 @@ public sealed class HttpTnsuPortalClient(
|
||||
[property: JsonPropertyName("fio")] string? Fio,
|
||||
[property: JsonPropertyName("id")] Guid? Id = null);
|
||||
|
||||
private sealed record DictionaryItemResponse(
|
||||
[property: JsonPropertyName("id")] Guid? Id,
|
||||
[property: JsonPropertyName("name")] string? Name);
|
||||
|
||||
private sealed record ManagerResponse(
|
||||
[property: JsonPropertyName("managerEmail")] string? ManagerEmail);
|
||||
|
||||
|
||||
@@ -20,6 +20,12 @@ public interface ITnsuPortalClient
|
||||
/// </summary>
|
||||
Task<IReadOnlyList<EmployeeContactInfo>> GetAllEmployeesAsync(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>Справочник компаний — /Dictionary/Companies.</summary>
|
||||
Task<IReadOnlyList<CompanyInfo>> GetCompaniesAsync(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>Справочник отделов — /Dictionary/Departments.</summary>
|
||||
Task<IReadOnlyList<DepartmentInfo>> GetDepartmentsAsync(CancellationToken cancellationToken);
|
||||
|
||||
Task<string?> GetManagerAsync(string email, string managerType, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -30,4 +30,10 @@ public sealed record EmployeeFullBaseInfo(Guid? Id, string Fio, string Company,
|
||||
/// увольнения (в отличие от /Employee/FullBase). Связать одну базу с другой можно
|
||||
/// по <paramref name="Id"/> — он один и тот же в обоих ответах.
|
||||
/// </summary>
|
||||
public sealed record EmployeeContactInfo(Guid? Id, string Fio, string? Email, string Company);
|
||||
public sealed record EmployeeContactInfo(Guid? Id, string Fio, string? Email, string Company, string? Position = null);
|
||||
|
||||
/// <summary>Компания из справочника /Dictionary/Companies.</summary>
|
||||
public sealed record CompanyInfo(Guid Id, string Name);
|
||||
|
||||
/// <summary>Отдел из справочника /Dictionary/Departments.</summary>
|
||||
public sealed record DepartmentInfo(Guid Id, string Name);
|
||||
|
||||
Reference in New Issue
Block a user