DepartmentProject/DepartmentPortal/AcademicProgressBusinessLogic/BusinessLogic/ReportLogic.cs

335 lines
17 KiB
C#
Raw Normal View History

using AcademicProgressBusinessLogic.BindingModels;
using AcademicProgressBusinessLogic.BusinessLogic;
using AcademicProgressBusinessLogic.Enums;
using AcademicProgressBusinessLogic.HelperModels;
using AcademicProgressBusinessLogic.Interfaces;
using AcademicProgressBusinessLogic.ViewModels;
using DepartmentBusinessLogic.BindingModels;
using DepartmentBusinessLogic.BusinessLogics;
using DepartmentBusinessLogic.Interfaces;
using ModuleTools.BusinessLogics;
using ModuleTools.Enums;
using ModuleTools.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AcademicProgressBusinessLogic.BusinessLogics
{
/// <summary>
/// Логика работы с отчетами
/// </summary>
public class ReportLogic : CoreBusinessLogic
{
/// <summary>
/// Логика для работы со студентами
/// </summary>
private readonly StudentBusinessLogic _studentlogic;
/// <summary>
/// Логика для работы с успеваемостью студента
/// </summary>
private readonly StudentAcademicProgressBusinessLogic _studentAcademicProgresslogic;
/// <summary>
/// Логика для работы с дисциплинами
/// </summary>
private readonly DisciplineBusinessLogic _disciplinelogic;
private readonly AcademicPlanRecordBusinessLogic _academicPlanRecordlogic;
private readonly StudentGroupBusinessLogic _studentGrouplogic;
private readonly EducationDirectionBusinessLogic _educationDirectionlogic;
private readonly AcademicPlanBusinessLogic _academicPlanlogic;
/// <summary>
/// Логика работы с отчетом
/// </summary>
/// <param name="service"></param>
public ReportLogic(AcademicPlanRecordBusinessLogic _academicPlanRecordlogic, EducationDirectionBusinessLogic _educationDirectionlogic, AcademicPlanBusinessLogic _academicPlanlogic,
StudentGroupBusinessLogic _studentGrouplogic, StudentBusinessLogic _studentlogic, StudentAcademicProgressBusinessLogic _studentAcademicProgressService, DisciplineBusinessLogic _disciplinelogic)
{
this._studentGrouplogic = _studentGrouplogic;
this._educationDirectionlogic = _educationDirectionlogic;
this._academicPlanlogic = _academicPlanlogic;
this._academicPlanRecordlogic = _academicPlanRecordlogic;
this._studentAcademicProgresslogic = _studentAcademicProgressService;
this._disciplinelogic = _disciplinelogic;
this._studentlogic = _studentlogic;
_serviceOperation = AccessOperation.Отчет_успеваемость;
_entity = "Отчеты для успеваемости";
}
public void SaveReportToWordFile(ReportBindingModel model)
{
SaveToWord.CreateDoc(new WordInfo
{
FileName = model.FolderName,
Title = "Приложение к диплому",
StudentScores = GetStudentScores(model.StudentId)
});
}
public void SaveReportToExcelFile(ReportBindingModel model)
{
SaveToExcel.CreateDoc(new ExcelInfo
{
FileName = model.FolderName,
Title = "Успеваемость",
StudentScores = GetStudentScoresForProgress(model.StudentId)
});
}
public List<StudentScoresViewModel> GetStudentScoresForProgress(Guid? studentId)
{
var academicProgress = _studentAcademicProgresslogic.GetList(new StudentAcademicProgressGetBindingModel());
var discipline = _disciplinelogic.GetList(new DisciplineGetBindingModel());
var academicPlanRecords = _academicPlanRecordlogic.GetList(new AcademicPlanRecordGetBindingModel());
var students = _studentlogic.GetList(new StudentGetBindingModel());
var educationDirections = _educationDirectionlogic.GetList(new EducationDirectionGetBindingModel());
var studentGroup = _studentGrouplogic.GetList(new StudentGroupGetBindingModel());
var academicPlans = _academicPlanlogic.GetList(new AcademicPlanGetBindingModel());
var list = new List<StudentScoresViewModel>();
double average = 0;
double count = 0;
string score = "";
foreach (var student in students.List.Where(rec => rec.Id == studentId))
{
foreach (var studGroup in studentGroup.List.Where(rec => rec.Id == student.StudentGroupId))
{
foreach (var educatDirection in educationDirections.List.Where(rec => rec.Id == studGroup.EducationDirectionId))
{
foreach (var academicPlan in academicPlans.List.Where(rec => rec.EducationDirectionId == educatDirection.Id))
{
foreach (var academicPlanRecord in academicPlanRecords.List.Where(rec => rec.AcademicPlanId == academicPlan.Id))
{
//является ли родителем
if (academicPlanRecord.IsParent)
{
bool hasScore = false;
//ищем всех детей
foreach (var academicPlanRecordChild in academicPlanRecords.List.Where(rec => rec.AcademicPlanRecordParentId == academicPlanRecord.Id))
{
//если есть оценки то заполняем
foreach (var studProgress in academicProgress.List.Where(rec => rec.StudentId == studentId && rec.DisciplineId == academicPlanRecordChild.DisciplineId && rec.Semester == academicPlanRecordChild.Semester))
{
var record = new StudentScoresViewModel
{
DisciplineName = academicPlanRecordChild.DisciplineName,
Scores = studProgress.ExamScoresTitle,
StudentLastName = student.LastName,
StudentFirstName = student.FirstName,
Semester = (int)academicPlanRecordChild.Semester,
Zet = academicPlanRecordChild.Zet
};
list.Add(record);
hasScore = true;
}
}
//если оценок нет, то вставляем имя родителя
if (!hasScore)
{
var record = new StudentScoresViewModel
{
DisciplineName = academicPlanRecord.DisciplineName,
Scores = " ",
Semester = (int)academicPlanRecord.Semester,
StudentLastName = student.LastName,
StudentFirstName = student.FirstName,
Zet = academicPlanRecord.Zet
};
list.Add(record);
}
}//если не имеет детей то записываем имя без оценки
else if (academicPlanRecord.IsChildValue == "Нет")
{
var record = new StudentScoresViewModel
{
DisciplineName = academicPlanRecord.DisciplineName,
Scores = " ",
Semester = (int)academicPlanRecord.Semester,
StudentLastName = student.LastName,
StudentFirstName = student.FirstName,
Zet = academicPlanRecord.Zet
};
list.Add(record);
}
}
}
}
}
}
//поставили оценки из успеваемости студента в лист
foreach (var l in list)
{
foreach (var studProgress in academicProgress.List.Where(rec => rec.StudentId == studentId && l.DisciplineName == rec.DisciplineName && l.Semester == (int)rec.Semester))
{
switch (studProgress.Score)
{
case ExamScores.Отлично:
average += 5;
score = "5";
count++;
break;
case ExamScores.Хорошо:
average += 4;
score = "4";
count++;
break;
case ExamScores.Удовлетворительно:
average += 3;
score = "3";
count++;
break;
case ExamScores.Зачет:
score = "+";
break;
}
l.Scores = score;
}
l.Average = Math.Round(((average) / count) , 2);
}
return list;
}
public List<StudentScoresViewModel> GetStudentScores(Guid? studentId)
{
var academicProgress = _studentAcademicProgresslogic.GetList(new StudentAcademicProgressGetBindingModel());
var discipline = _disciplinelogic.GetList(new DisciplineGetBindingModel());
var academicPlanRecords = _academicPlanRecordlogic.GetList(new AcademicPlanRecordGetBindingModel());
var students = _studentlogic.GetList(new StudentGetBindingModel());
var educationDirections = _educationDirectionlogic.GetList(new EducationDirectionGetBindingModel());
var studentGroup = _studentGrouplogic.GetList(new StudentGroupGetBindingModel());
var academicPlans = _academicPlanlogic.GetList(new AcademicPlanGetBindingModel());
var list = new List<StudentScoresViewModel>();
//записываем имена дисциплин в лист
foreach (var student in students.List.Where(rec => rec.Id == studentId))
{
foreach (var studGroup in studentGroup.List.Where(rec => rec.Id == student.StudentGroupId))
{
foreach (var educatDirection in educationDirections.List.Where(rec => rec.Id == studGroup.EducationDirectionId))
{
foreach (var academicPlan in academicPlans.List.Where(rec => rec.EducationDirectionId == educatDirection.Id))
{
foreach (var academicPlanRecord in academicPlanRecords.List.Where(rec => rec.AcademicPlanId == academicPlan.Id).OrderBy(rec => rec.DisciplineName).ThenByDescending(rec => rec.SemesterTitle))
{
//является ли родителем
if (academicPlanRecord.IsParent)
{
bool hasScore = false;
//ищем всех детей
foreach (var academicPlanRecordChild in academicPlanRecords.List.Where(rec => rec.AcademicPlanRecordParentId == academicPlanRecord.Id))
{
//если есть оценки то заполняем
foreach (var studProgress in academicProgress.List.Where(rec => rec.StudentId == studentId && rec.DisciplineId == academicPlanRecordChild.DisciplineId && rec.Semester == academicPlanRecordChild.Semester))
{
var record = new StudentScoresViewModel
{
DisciplineName = academicPlanRecordChild.DisciplineName,
Scores = studProgress.ExamScoresTitle,
StudentLastName = student.LastName,
StudentFirstName = student.FirstName,
Semester = (int)academicPlanRecordChild.Semester,
Zet = academicPlanRecordChild.Zet
};
list.Add(record);
hasScore = true;
}
}
//если оценок нет, то вставляем имя родителя
if (!hasScore)
{
var record = new StudentScoresViewModel
{
DisciplineName = academicPlanRecord.DisciplineName,
Scores = " ",
Semester = (int)academicPlanRecord.Semester,
StudentLastName = student.LastName,
StudentFirstName = student.FirstName,
Zet = academicPlanRecord.Zet
};
list.Add(record);
}
}//если не имеет детей то записываем имя без оценки
else if (academicPlanRecord.IsChildValue == "Нет")
{
var record = new StudentScoresViewModel
{
DisciplineName = academicPlanRecord.DisciplineName,
Scores = " ",
Semester = (int)academicPlanRecord.Semester,
StudentLastName = student.LastName,
StudentFirstName = student.FirstName,
Zet = academicPlanRecord.Zet
};
list.Add(record);
}
}
}
}
}
}
var list2 = new List<StudentScoresViewModel>();
list2.Add(list[0]);
int z = 0;
//в новый лист заносим только по одной дисциплине и складываем з.ешки у одинаковых дисциплин
foreach (var l in list)
{
if (l.DisciplineName != list2[list2.Count - 1].DisciplineName)
{
list2.Add(l);
z += l.Zet;
}
else
{
list2[list2.Count - 1].Zet += l.Zet;
z += l.Zet;
}
}
//записываем оценки в лист из успевамости
foreach (var l in list2)
{
foreach (var studProgress in academicProgress.List.Where(rec => rec.StudentId == studentId))
{
if (l.DisciplineName == studProgress.DisciplineName && l.Semester == (int)studProgress.Semester && l.Scores != null)
{
l.Scores = studProgress.Score.ToString();
}
}
}
list.Clear();
foreach (var l in list2.OrderBy(rec => rec.Semester))
{
list.Add(l);
}
list[list.Count - 1].Average = z;
return list;
}
}
}