From a536d0745d4b87f5d2bc0e2d1825f4f512e9104c Mon Sep 17 00:00:00 2001 From: Mikhail Kuznetsov Date: Thu, 21 Aug 2025 14:05:35 +1000 Subject: [PATCH] =?UTF-8?q?feat(API):=20=D0=B2=D0=BE=D1=81=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D1=82=D0=B8=D1=81=D1=82=D0=B8=D0=BA=D0=B0=20=D0=BF=D0=BE?= =?UTF-8?q?=20=D1=88=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=D0=B0=D0=BC=20=D0=BF?= =?UTF-8?q?=D0=BE=D1=81=D0=BB=D0=B5=20=D0=BF=D0=B5=D1=80=D0=B5=D1=85=D0=BE?= =?UTF-8?q?=D0=B4=D0=B0=20=D0=BD=D0=B0=20Job?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../V1/Statistics/StatTemplateController.cs | 100 +++++++++--------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/PARR.API/Controllers/V1/Statistics/StatTemplateController.cs b/PARR.API/Controllers/V1/Statistics/StatTemplateController.cs index 3074bc59..aa308d21 100644 --- a/PARR.API/Controllers/V1/Statistics/StatTemplateController.cs +++ b/PARR.API/Controllers/V1/Statistics/StatTemplateController.cs @@ -32,66 +32,66 @@ namespace PARR.API.Controllers.V1.Statistics this.calendarService = calendarService; } - ///// - ///// Статистика по шаблонам - ///// - ///// - //[HttpGet(ApiRoutes.StatTemplate.Get)] - //public async Task Get() - //{ - // var response = new StatTemplateResponse - // { - // ActivateScheduleCount = await templateService.Get().CountAsync(t => t.IsActiveSchedule), - // ActivateTemplateCount = await templateService.Get().CountAsync(t => t.IsActiveTemplate), - // TemplateAgentCount = await templateService.Get().Include(t => t.ApplicationsInWork).CountAsync(t => t.ApplicationsInWork!.IsAgent), - // TemplateCount = await templateService.Get().CountAsync(), - // SyncEsppScheduleCount = await templateService.Get().Include(t => t.RobotConfigurations).CountAsync(t => t.RobotConfigurations.Any(c => c.RobotCode == (int)RobotsEnum.ScheduleOrder && c.TaskStatusCode == (int)TaskStatusEnum.Ok)), - // SyncEsppTemplatesCount = await templateService.Get().Include(t => t.RobotConfigurations).CountAsync(t => t.RobotConfigurations.Any(c => c.RobotCode == (int)RobotsEnum.TemplateOrder && c.TaskStatusCode == (int)TaskStatusEnum.Ok)) - // }; + /// + /// Статистика по шаблонам + /// + /// + [HttpGet(ApiRoutes.StatTemplate.Get)] + public async Task Get() + { + var response = new StatTemplateResponse + { + ActivateScheduleCount = await templateService.Get().CountAsync(t => t.IsActiveSchedule), + ActivateTemplateCount = await templateService.Get().CountAsync(t => t.IsActiveTemplate), + TemplateAgentCount = await templateService.Get().Include(t => t.Job).ThenInclude(t=>t.Group).CountAsync(t => t.Job!.Group!.IsAgent), + TemplateCount = await templateService.Get().CountAsync(), + SyncEsppScheduleCount = await templateService.Get().Include(t => t.RobotConfigurations).CountAsync(t => t.RobotConfigurations.Any(c => c.RobotCode == (int)RobotsEnum.ScheduleOrder && c.TaskStatusCode == (int)TaskStatusEnum.Ok)), + SyncEsppTemplatesCount = await templateService.Get().Include(t => t.RobotConfigurations).CountAsync(t => t.RobotConfigurations.Any(c => c.RobotCode == (int)RobotsEnum.TemplateOrder && c.TaskStatusCode == (int)TaskStatusEnum.Ok)) + }; - // return Ok(new Response(response, true)); - //} + return Ok(new Response(response, true)); + } - ///// - ///// Получить статистику созданных шаблонов (расписаний) в БД ПАРР - ///// - ///// - ///// - ///// - //[HttpGet(ApiRoutes.StatTemplate.GetForPeriod)] - //public async Task GetForPeriod([FromQuery] TimeZoneOffsetClient timeZoneQuery, [FromQuery] int startPeriodDays = 3) - //{ - // var endPeriod = calendarService.GetDateWithTimeZoneOffset(DateTimeOffset.UtcNow, timeZoneQuery.TimeZoneOffsetHours); - // var startPeriod = endPeriod.AddDays(-startPeriodDays); + /// + /// Получить статистику созданных шаблонов (расписаний) в БД ПАРР + /// + /// + /// + /// + [HttpGet(ApiRoutes.StatTemplate.GetForPeriod)] + public async Task GetForPeriod([FromQuery] TimeZoneOffsetClient timeZoneQuery, [FromQuery] int startPeriodDays = 3) + { + var endPeriod = calendarService.GetDateWithTimeZoneOffset(DateTimeOffset.UtcNow, timeZoneQuery.TimeZoneOffsetHours); + var startPeriod = endPeriod.AddDays(-startPeriodDays); - // var query = templateService.Get() - // .Where(t => - // t.DateCreated.DateTime.AddHours(timeZoneQuery.TimeZoneOffsetHours).Date >= startPeriod.Date - // && t.DateCreated.DateTime.AddHours(timeZoneQuery.TimeZoneOffsetHours).Date <= endPeriod.Date - // ).GroupBy(t => t.DateCreated.AddHours(timeZoneQuery.TimeZoneOffsetHours).Date) - // .Select(t => new - // { - // Date = t.Key, - // CreatedObjs = t.Count() - // }); + var query = templateService.Get() + .Where(t => + t.DateCreated.DateTime.AddHours(timeZoneQuery.TimeZoneOffsetHours).Date >= startPeriod.Date + && t.DateCreated.DateTime.AddHours(timeZoneQuery.TimeZoneOffsetHours).Date <= endPeriod.Date + ).GroupBy(t => t.DateCreated.AddHours(timeZoneQuery.TimeZoneOffsetHours).Date) + .Select(t => new + { + Date = t.Key, + CreatedObjs = t.Count() + }); - // var result = await query.ToListAsync(); + var result = await query.ToListAsync(); - // var daysList = calendarService.GetDatesForPeriod(startPeriod, endPeriod); + var daysList = calendarService.GetDatesForPeriod(startPeriod, endPeriod); - // var response = new List(); + var response = new List(); - // daysList.ForEach(date => response.Add(new StatTemplatePeriodResponse - // { - // Date = date, - // CreatedTemplatesCount = result.FirstOrDefault(t => DateOnly.FromDateTime(t.Date) == date)?.CreatedObjs ?? 0 - // })); + daysList.ForEach(date => response.Add(new StatTemplatePeriodResponse + { + Date = date, + CreatedTemplatesCount = result.FirstOrDefault(t => DateOnly.FromDateTime(t.Date) == date)?.CreatedObjs ?? 0 + })); - // response = response.OrderBy(t => t.Date).ToList(); + response = response.OrderBy(t => t.Date).ToList(); - // return Ok(new Response>(response, true)); - //} + return Ok(new Response>(response, true)); + } }