2024-11-06 09:07:50 +00:00
|
|
|
|
using Demo.Data.Repository;
|
|
|
|
|
using Demo.domain.Models;
|
2024-11-01 07:40:53 +00:00
|
|
|
|
using Demo.Domain.UseCase;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace Demo.UI
|
|
|
|
|
{
|
|
|
|
|
public class PresenceConsole
|
|
|
|
|
{
|
|
|
|
|
private readonly UseCaseGeneratePresence _presenceUseCase;
|
2024-11-06 09:07:50 +00:00
|
|
|
|
private readonly IPresenceRepository _presenceRepository;
|
2024-11-01 07:40:53 +00:00
|
|
|
|
|
2024-11-06 09:07:50 +00:00
|
|
|
|
public PresenceConsole(UseCaseGeneratePresence presenceUseCase, IPresenceRepository presenceRepository)
|
2024-11-01 07:40:53 +00:00
|
|
|
|
{
|
|
|
|
|
_presenceUseCase = presenceUseCase;
|
2024-11-06 09:07:50 +00:00
|
|
|
|
_presenceRepository = presenceRepository;
|
2024-11-01 07:40:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Метод для генерации посещаемости на день
|
|
|
|
|
public void GeneratePresenceForDay(DateTime date, int groupId, int firstLesson, int lastLesson)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_presenceUseCase.GeneratePresenceDaily(firstLesson, lastLesson, groupId, date);
|
|
|
|
|
Console.WriteLine("Посещаемость на день успешно сгенерирована.");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Ошибка при генерации посещаемости: {ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Метод для генерации посещаемости на неделю
|
|
|
|
|
public void GeneratePresenceForWeek(DateTime date, int groupId, int firstLesson, int lastLesson)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_presenceUseCase.GenerateWeeklyPresence(firstLesson, lastLesson, groupId, date);
|
|
|
|
|
Console.WriteLine("Посещаемость на неделю успешно сгенерирована.");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Ошибка при генерации посещаемости: {ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Метод для отображения посещаемости на конкретную дату и группу
|
|
|
|
|
public void DisplayPresence(DateTime date, int groupId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-11-05 18:36:49 +00:00
|
|
|
|
List<PresenceLocalEntity> presences = _presenceUseCase.GetPresenceByGroupAndDate(groupId, date);
|
2024-11-01 07:40:53 +00:00
|
|
|
|
|
|
|
|
|
if (presences == null || presences.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Нет данных о посещаемости на выбранную дату.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.WriteLine($"\n Посещаемость на {date:dd.MM.yyyy} ");
|
|
|
|
|
Console.WriteLine("-----------------------------------------------------");
|
|
|
|
|
|
|
|
|
|
// Сохраняем номер занятия для сравнения
|
|
|
|
|
int previousLessonNumber = -1;
|
|
|
|
|
|
|
|
|
|
foreach (var presence in presences)
|
|
|
|
|
{
|
|
|
|
|
// Проверяем, изменился ли номер занятия
|
|
|
|
|
if (previousLessonNumber != presence.LessonNumber)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("-----------------------------------------------------");
|
|
|
|
|
Console.WriteLine($" Занятие: {presence.LessonNumber} ");
|
|
|
|
|
Console.WriteLine("-----------------------------------------------------");
|
|
|
|
|
previousLessonNumber = presence.LessonNumber;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Форматируем статус присутствия
|
|
|
|
|
string status = presence.IsAttedance ? "Присутствует" : "Отсутствует";
|
|
|
|
|
Console.WriteLine($"Пользователь (ID: {presence.UserGuid}) - Статус: {status}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("-----------------------------------------------------");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Ошибка при отображении посещаемости: {ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-11-05 18:36:49 +00:00
|
|
|
|
public void MarkUserAsAbsent(DateTime date, int groupId, Guid userGuid, int firstLesson, int lastLesson)
|
2024-11-01 07:40:53 +00:00
|
|
|
|
{
|
2024-11-05 18:36:49 +00:00
|
|
|
|
_presenceUseCase.MarkUserAsAbsent(userGuid, groupId, firstLesson, lastLesson, date);
|
2024-11-01 07:40:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void DisplayAllPresenceByGroup(int groupId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var presences = _presenceUseCase.GetAllPresenceByGroup(groupId);
|
|
|
|
|
|
|
|
|
|
if (presences == null || !presences.Any())
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Нет данных о посещаемости для группы с ID: {groupId}.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Группируем записи посещаемости по дате
|
|
|
|
|
var groupedPresences = presences.GroupBy(p => p.Date);
|
|
|
|
|
|
|
|
|
|
foreach (var group in groupedPresences)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("===================================================");
|
|
|
|
|
Console.WriteLine($" Дата: {group.Key:dd.MM.yyyy} ");
|
|
|
|
|
Console.WriteLine("===================================================");
|
|
|
|
|
|
|
|
|
|
// Сохраняем номер занятия для сравнения
|
|
|
|
|
int previousLessonNumber = -1;
|
|
|
|
|
|
|
|
|
|
foreach (var presence in group)
|
|
|
|
|
{
|
|
|
|
|
// Проверяем, изменился ли номер занятия
|
|
|
|
|
if (previousLessonNumber != presence.LessonNumber)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("---------------------------------------------------");
|
|
|
|
|
Console.WriteLine($" Занятие: {presence.LessonNumber} ");
|
|
|
|
|
Console.WriteLine("---------------------------------------------------");
|
|
|
|
|
previousLessonNumber = presence.LessonNumber;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Форматируем статус присутствия
|
|
|
|
|
string status = presence.IsAttedance ? "✅ Присутствует" : "❌ Отсутствует";
|
|
|
|
|
Console.WriteLine($"Пользователь (ID: {presence.UserGuid}) - Статус: {status}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("---------------------------------------------------");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Ошибка при отображении посещаемости: {ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-06 09:07:50 +00:00
|
|
|
|
public void DisplayGeneralPresenceForGroup(int groupId)
|
|
|
|
|
{
|
|
|
|
|
var summary = _presenceRepository.GetGeneralPresenceForGroup(groupId);
|
|
|
|
|
|
|
|
|
|
Console.WriteLine($"Человек в группе: {summary.UserCount}, " +
|
|
|
|
|
$"Количество проведённых занятий: {summary.LessonCount}, " +
|
|
|
|
|
$"Общий процент посещаемости группы: {summary.TotalAttendancePercentage}%");
|
|
|
|
|
|
|
|
|
|
foreach (var user in summary.UserAttendances)
|
|
|
|
|
{
|
|
|
|
|
if (user.AttendanceRate < 40)
|
|
|
|
|
{
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.Red;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.WriteLine($"GUID Пользователя: {user.UserGuid}, " +
|
|
|
|
|
$"Посетил: {user.Attended}, " +
|
|
|
|
|
$"Пропустил: {user.Missed}, " +
|
|
|
|
|
$"Процент посещаемости: {user.AttendanceRate}%");
|
|
|
|
|
Console.ResetColor();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-07 07:35:57 +00:00
|
|
|
|
public void ExportAttendanceToExcel()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_presenceUseCase.ExportAttendanceToExcel();
|
|
|
|
|
Console.WriteLine("Данные посещаемости успешно экспортированы в Excel.");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Ошибка при экспорте посещаемости: {ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-11-01 07:40:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|