From 513c14b73d1377ccc0110c915aff88e5a0aaf36a Mon Sep 17 00:00:00 2001 From: kotcheshir73 Date: Sat, 19 Mar 2022 11:53:10 +0400 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=BA=D0=B8=D0=BD=D1=85=D1=80=D0=BE?= =?UTF-8?q?=D0=BD=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D1=81=D0=BF=D0=B8?= =?UTF-8?q?=D1=81=D0=BA=D0=B0=20=D0=BF=D1=80=D0=B8=D0=BA=D0=B0=D0=B7=D0=BE?= =?UTF-8?q?=20=D1=81=D1=82=D1=83=D0=B4=D0=B5=D0=BD=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/SetBindingModel.cs | 12 +- .../BusinessLogics/GenericBusinessLogic.cs | 8 +- .../ToolsModule/BusinessLogics/Mapper.cs | 11 +- .../OrderSyncHistoryBusinessLogic.cs | 134 ++++++++++++++---- .../ControlOrderStudentRecordList.cs | 31 +++- 5 files changed, 153 insertions(+), 43 deletions(-) diff --git a/DepartmentPortal/Common/ToolsModule/BindingModels/SetBindingModel.cs b/DepartmentPortal/Common/ToolsModule/BindingModels/SetBindingModel.cs index 254a392..4eb50e8 100644 --- a/DepartmentPortal/Common/ToolsModule/BindingModels/SetBindingModel.cs +++ b/DepartmentPortal/Common/ToolsModule/BindingModels/SetBindingModel.cs @@ -1,17 +1,15 @@ -using ToolsModule.Attributes; -using System; +using System; namespace ToolsModule.BindingModels { - /// - /// Сохранение записи по идентификатору - /// - public class SetBindingModel : AccessBindingModel + /// + /// Сохранение записи по идентификатору + /// + public class SetBindingModel : AccessBindingModel { /// /// Идентификатор записи /// - [MapConfiguration("Id")] public Guid Id { get; set; } = Guid.NewGuid(); } } \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsModule/BusinessLogics/GenericBusinessLogic.cs b/DepartmentPortal/Common/ToolsModule/BusinessLogics/GenericBusinessLogic.cs index 8181a1f..706f2af 100644 --- a/DepartmentPortal/Common/ToolsModule/BusinessLogics/GenericBusinessLogic.cs +++ b/DepartmentPortal/Common/ToolsModule/BusinessLogics/GenericBusinessLogic.cs @@ -63,6 +63,7 @@ namespace ToolsModule.BusinessLogics catch (Exception ex) { Errors.Add(("Ошибка получения", ex.Message)); + Errors.Add(("Ошибка получения (Stack)", ex.StackTrace)); } return null; } @@ -93,6 +94,7 @@ namespace ToolsModule.BusinessLogics catch (Exception ex) { Errors.Add(("Ошибка получения", ex.Message)); + Errors.Add(("Ошибка получения (Stack)", ex.StackTrace)); } return null; } @@ -123,6 +125,7 @@ namespace ToolsModule.BusinessLogics catch (Exception ex) { Errors.Add(("Ошибка создания", ex.Message)); + Errors.Add(("Ошибка создания (Stack)", ex.StackTrace)); } return null; } @@ -153,6 +156,7 @@ namespace ToolsModule.BusinessLogics catch (Exception ex) { Errors.Add(("Ошибка изменения", ex.Message)); + Errors.Add(("Ошибка изменения (Stack)", ex.StackTrace)); } return null; } @@ -183,6 +187,7 @@ namespace ToolsModule.BusinessLogics catch (Exception ex) { Errors.Add(("Ошибка удаления", ex.Message)); + Errors.Add(("Ошибка удаления (Stack)", ex.StackTrace)); } return false; } @@ -212,7 +217,8 @@ namespace ToolsModule.BusinessLogics } catch (Exception ex) { - Errors.Add(("Ошибка удаления", ex.Message)); + Errors.Add(("Ошибка восстановления", ex.Message)); + Errors.Add(("Ошибка восстановления (Stack)", ex.StackTrace)); } return null; } diff --git a/DepartmentPortal/Common/ToolsModule/BusinessLogics/Mapper.cs b/DepartmentPortal/Common/ToolsModule/BusinessLogics/Mapper.cs index 4ecd251..0c85308 100644 --- a/DepartmentPortal/Common/ToolsModule/BusinessLogics/Mapper.cs +++ b/DepartmentPortal/Common/ToolsModule/BusinessLogics/Mapper.cs @@ -29,7 +29,7 @@ namespace ToolsModule.BusinessLogics /// /// /// - public static To MapToClass(From obj, To newObject, bool haveRigth) where To : class => FillObject(obj, newObject, haveRigth); + public static To MapToClass(From obj, To newObject, bool haveRigth) where To : class => FillObject(obj, newObject, haveRigth, true); /// /// Заполнение объекта @@ -39,24 +39,29 @@ namespace ToolsModule.BusinessLogics /// /// /// + /// /// - private static To FillObject(From obj, To newObject, bool haveRigth) + private static To FillObject(From obj, To newObject, bool haveRigth, bool exsistRecord = false) where To : class { if (obj == null) { return null; } - if (newObject == null) { return null; } + var typeFrom = typeof(From); var typeTo = typeof(To); var properties = typeTo.GetProperties().Where(x => x.CanWrite); foreach (var property in properties) { + if (property.Name == "Id" && exsistRecord) + { + continue; + } var checkRight = property.GetCustomAttribute(); if (!haveRigth && checkRight != null) { diff --git a/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/OrderSyncHistoryBusinessLogic.cs b/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/OrderSyncHistoryBusinessLogic.cs index bb945d7..f2de679 100644 --- a/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/OrderSyncHistoryBusinessLogic.cs +++ b/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/OrderSyncHistoryBusinessLogic.cs @@ -57,16 +57,9 @@ namespace DepartmentBusinessLogic.BusinessLogics return false; } - var address = _enviromentSettingLogic.GetList(new EnviromentSettingGetBindingModel { Key = "SyncStudentOrderIpAddress" })?.List?.FirstOrDefault(); - if (address == null || address.Value.IsEmpty()) + var address = GetAddress(history); + if (address == null) { - Errors = _enviromentSettingLogic.Errors; - Errors.Add(("Ошибка получения данных", "Не удалось получить адрес сервера для получения приказов по студентам")); - _recordLogic.Create(new OrderSyncHistoryRecordSetBindingModel - { - OrderSyncHistoryId = history.Id, - Information = string.Join(Environment.NewLine, Errors.Select(x => x.Message)) - }); return false; } @@ -76,8 +69,6 @@ namespace DepartmentBusinessLogic.BusinessLogics return false; } - // авторизация - // получение списка студентов HttpResponseMessage response = await client.GetAsync($"{address.Value}/univer/hs/Ulstu_StudentsInfo/v1/GetCurrentStudentsOfDepartment"); if (!response.IsSuccessStatusCode) @@ -217,6 +208,63 @@ namespace DepartmentBusinessLogic.BusinessLogics return true; } + public async Task SyncStudentOrders(Guid studentId) + { + InitLogics(); + + var history = Create(new OrderSyncHistorySetBindingModel { SyncDate = DateTime.Now }); + if (history == null) + { + Errors.Add(("Ошибка создание истории", "Не удалось создать историю")); + return false; + } + _recordLogic.Create(new OrderSyncHistoryRecordSetBindingModel + { + OrderSyncHistoryId = history.Id, + Information = $"Синхронизация приказов по студенту" + }); + + var address = GetAddress(history); + if (address == null) + { + return false; + } + + var client = GetClinet(history, address); + if (client == null) + { + return false; + } + + var groups = _groupsLogic.GetList(new StudentGroupGetBindingModel()); + if (groups == null || groups.List == null) + { + Errors = _groupsLogic.Errors; + Errors.Add(("Ошибка получения данных", "Не удалось получить список групп с базы")); + _recordLogic.Create(new OrderSyncHistoryRecordSetBindingModel + { + OrderSyncHistoryId = history.Id, + Information = string.Join(Environment.NewLine, Errors.Select(x => x.Message)) + }); + return false; + } + + var student = _studentLogic.GetElement(new StudentGetBindingModel { Id = studentId }); + if (student == null) + { + Errors = _studentLogic.Errors; + Errors.Add(("Ошибка получения данных", "Не удалось получить студента")); + _recordLogic.Create(new OrderSyncHistoryRecordSetBindingModel + { + OrderSyncHistoryId = history.Id, + Information = string.Join(Environment.NewLine, Errors.Select(x => x.Message)) + }); + return false; + } + await SyncStudentOrders(history, student, groups.List, client, address.Value); + return true; + } + private void InitLogics() { @@ -231,6 +279,23 @@ namespace DepartmentBusinessLogic.BusinessLogics _roleLogic = DependencyManager.Instance.Resolve(); } + private EnviromentSettingViewModel GetAddress(OrderSyncHistoryViewModel history) + { + var address = _enviromentSettingLogic.GetList(new EnviromentSettingGetBindingModel { Key = "SyncStudentOrderIpAddress" })?.List?.FirstOrDefault(); + if (address == null || address.Value.IsEmpty()) + { + Errors = _enviromentSettingLogic.Errors; + Errors.Add(("Ошибка получения данных", "Не удалось получить адрес сервера для получения приказов по студентам")); + _recordLogic.Create(new OrderSyncHistoryRecordSetBindingModel + { + OrderSyncHistoryId = history.Id, + Information = string.Join(Environment.NewLine, Errors.Select(x => x.Message)) + }); + return null; + } + return address; + } + /// /// Синхронизация приказов по студенту /// @@ -374,10 +439,15 @@ namespace DepartmentBusinessLogic.BusinessLogics info = $"Перевод студента {student} c группы {syncOrder.groupNameBefore} другой кафедры в группу {groups.FirstOrDefault(x => x.Id == studentGroupToId)}"; } else if (studentGroupFromId.HasValue && !studentGroupToId.HasValue) - { + { orderStudentMoveType = OrderStudentMoveType.УбратьПоПереводу; info = $"Перевод студента {student} из группы {groups.FirstOrDefault(x => x.Id == studentGroupFromId)} на другую кафедру"; } + if (syncOrder.reason == "на другой факультет") + { + orderStudentMoveType = OrderStudentMoveType.ОтчислитьВСвязиСПереводом; + info = $"Отчисление студента {student} из группы {groups.FirstOrDefault(x => x.Id == studentGroupFromId)} в связи с переводом"; + } break; case "Зачисление в вуз вне приемной кампании": orderStudentMoveType = OrderStudentMoveType.ЗачислитьПоПриказу; @@ -395,10 +465,6 @@ namespace DepartmentBusinessLogic.BusinessLogics orderStudentMoveType = OrderStudentMoveType.ПеревестиНаСтаршийКурс; info = $"Перевод студента {student} из группы {groups.FirstOrDefault(x => x.Id == studentGroupFromId)} на следующий курс в группу {groups.FirstOrDefault(x => x.Id == studentGroupToId)}"; break; - //case "Завершение обучения": // уточнить приказ - // orderStudentMoveType = OrderStudentMoveType.ОтчислитьПоСобственному; - // info = $"Отчисление студента {student} в связи с окончанием обучения"; - // break; case "Уход в академический отпуск": DateTime? date = null; if (syncOrder.dateEnd.IsNotEmpty()) @@ -416,20 +482,29 @@ namespace DepartmentBusinessLogic.BusinessLogics orderStudentMoveType = OrderStudentMoveType.ВосстановитьИзАкадема; info = $"Выход из АО студента {student} в группу {groups.FirstOrDefault(x => x.Id == studentGroupToId)}"; break; - //case "Отчисление по невыходу из академа": // уточнить приказ - // orderStudentMoveType = OrderStudentMoveType.ОтчислитьЗаНевыходСАкадема; - // info = $"Отчисление студента {student} по невыходу из академа"; - // break; case "Отчисление": - if (syncOrder.reason == "за невыполнение учебного плана") + switch(syncOrder.reason) { - orderStudentMoveType = OrderStudentMoveType.ОтчислитьЗаНеуспевамость; - info = $"Отчисление студента {student} из группы {groups.FirstOrDefault(x => x.Id == studentGroupFromId)} за неуспеваемость"; - } - if (syncOrder.reason == "по собственному желанию") - { - orderStudentMoveType = OrderStudentMoveType.ОтчислитьПоСобственному; - info = $"Отчисление студента {student} из группы {groups.FirstOrDefault(x => x.Id == studentGroupFromId)} по собственному желанию"; + case "за невыполнение учебного плана": + orderStudentMoveType = OrderStudentMoveType.ОтчислитьЗаНеуспевамость; + info = $"Отчисление студента {student} из группы {groups.FirstOrDefault(x => x.Id == studentGroupFromId)} за неуспеваемость"; + break; + case "по собственному желанию": + orderStudentMoveType = OrderStudentMoveType.ОтчислитьПоСобственному; + info = $"Отчисление студента {student} из группы {groups.FirstOrDefault(x => x.Id == studentGroupFromId)} по собственному желанию"; + break; + case "в связи с невыходом из академического отпуска": + orderStudentMoveType = OrderStudentMoveType.ОтчислитьЗаНевыходСАкадема; + info = $"Отчисление студента {student} из группы {groups.FirstOrDefault(x => x.Id == studentGroupFromId)} в связи с невыходм из академического отпуска"; + break; + case "за невыполнение обязанностей по добросовестному освоению образовательной программы и выполнению учебного плана": + orderStudentMoveType = OrderStudentMoveType.ОтчислитьЗаНеуспевамость; + info = $"Отчисление студента {student} из группы {groups.FirstOrDefault(x => x.Id == studentGroupFromId)} за неуспеваемость"; + break; + case "в связи с переводом в ___": + orderStudentMoveType = OrderStudentMoveType.ОтчислитьВСвязиСПереводом; + info = $"Отчисление студента {student} из группы {groups.FirstOrDefault(x => x.Id == studentGroupFromId)} в связи с переводом"; + break; } break; case "Восстановление": @@ -614,9 +689,6 @@ namespace DepartmentBusinessLogic.BusinessLogics "Продление академического отпуска" => OrderType.ДвижениеСтудентов, "Восстановление из академического отпуска" => OrderType.ДвижениеСтудентов, "Отчисление" => OrderType.Отчисление, - "Отчисление (за невыполнение обязанностей по добросовестному освоению образовательной программы и выполнению учебного плана)" => OrderType.Отчисление, - "Отчисление (в связи с переводом в ___)" => OrderType.Отчисление, - "Отчисление (в связи с невыходом из академического отпуска)" => OrderType.Отчисление, "Восстановление" => OrderType.Перевод, "Выпуск" => OrderType.ДвижениеСтудентов, "Утверждение тем ВКР" => OrderType.Игнорировать, diff --git a/DepartmentPortal/Department/DepartmentWindowsDesktop/EntityControls/OrderStudentRecord/ControlOrderStudentRecordList.cs b/DepartmentPortal/Department/DepartmentWindowsDesktop/EntityControls/OrderStudentRecord/ControlOrderStudentRecordList.cs index e91c302..9d971d9 100644 --- a/DepartmentPortal/Department/DepartmentWindowsDesktop/EntityControls/OrderStudentRecord/ControlOrderStudentRecordList.cs +++ b/DepartmentPortal/Department/DepartmentWindowsDesktop/EntityControls/OrderStudentRecord/ControlOrderStudentRecordList.cs @@ -6,6 +6,9 @@ using ToolsDesktop.Interfaces; using ToolsDesktop.Models; using ToolsModule.Enums; using System; +using System.Threading.Tasks; +using ToolsDesktop.Helpers; +using ToolsModule.BusinessLogics; namespace DepartmentWindowsDesktop.EntityControls { @@ -30,7 +33,33 @@ namespace DepartmentWindowsDesktop.EntityControls public ControlViewEntityListConfiguration GetConfigControl() => new() { - PaginationOn = false + PaginationOn = false, + ControlOnMoveElem = new() + { + { "ToolStripMenuItemSyncOrders", ("Синхронизировать приказы студента", async (object sender, EventArgs e) => { await SyncOrders(); }) } + } }; + + /// + /// Синхронизация приказов + /// + /// + private async Task SyncOrders() + { + if (!ParentId.HasValue) + { + return; + } + var orderSyncHistoryBusinessLogic = DependencyManager.Instance.Resolve(); + var flag = await orderSyncHistoryBusinessLogic.SyncStudentOrders(ParentId.Value); + if (!flag) + { + DialogHelper.MessageException(_businessLogic.Errors, "Ошибки при синхронизации"); + } + else + { + DialogHelper.MessageInformation("Завершено успешно", "Синхронизация приказов"); + } + } } } \ No newline at end of file