ReportLogic - Поставщик
This commit is contained in:
parent
e5b2dcdab6
commit
c9df0ceb82
@ -8,35 +8,103 @@ using UniversityContracts.BusinessLogicContracts;
|
||||
using UniversityContracts.ViewModels;
|
||||
using UniversityContracts.SearchModels;
|
||||
using UniversityContracts.StoragesContracts;
|
||||
using UniversityBusinessLogic.OfficePackage;
|
||||
|
||||
namespace UniversityBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class ReportProviderLogic : IReportProviderLogic
|
||||
{
|
||||
private readonly IDocumentStorage _documentStorage;
|
||||
private readonly IStudentStorage _studentStorage;
|
||||
private readonly IEducationStatusStorage _educationStatusStorage;
|
||||
private readonly IEducationGroupStorage _educationGroupStorage;
|
||||
private readonly IDisciplineStorage _disciplineStorage;
|
||||
private readonly IStreamStorage _streamStorage;
|
||||
private readonly AbstractSaveToExcelProvider _saveToExcel;
|
||||
private readonly AbstractSaveToWordProvider _saveToWord;
|
||||
private readonly AbstractSaveToPdfProvider _saveToPdf;
|
||||
|
||||
public ReportProviderLogic(IDocumentStorage documentStorage,
|
||||
IStudentStorage studentStorage,
|
||||
IEducationStatusStorage educationStatusStorage,
|
||||
IEducationGroupStorage educationGroupStorage,
|
||||
IDisciplineStorage disciplineStorage,
|
||||
IStreamStorage streamStorage,
|
||||
AbstractSaveToExcelProvider saveToExcel,
|
||||
AbstractSaveToWordProvider saveToWord,
|
||||
AbstractSaveToPdfProvider saveToPdf)
|
||||
{
|
||||
_documentStorage = documentStorage;
|
||||
_studentStorage = studentStorage;
|
||||
_educationStatusStorage = educationStatusStorage;
|
||||
_educationGroupStorage = educationGroupStorage;
|
||||
_disciplineStorage = disciplineStorage;
|
||||
_streamStorage = streamStorage;
|
||||
_saveToExcel = saveToExcel;
|
||||
_saveToWord = saveToWord;
|
||||
_saveToPdf = saveToPdf;
|
||||
}
|
||||
|
||||
public List<ReportStudentsDisciplineViewModel> GetStudentsDiscipline(ReportBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var result = _studentStorage
|
||||
.GetFilteredList(new StudentSearchModel { UserId = model.UserId })
|
||||
.Select(student => new ReportStudentsDisciplineViewModel
|
||||
{
|
||||
StudentFIO = $"{student.Name} {student.Surname}",
|
||||
Disciplines = _streamStorage.GetFilteredList(new StreamSearchModel { UserId = model.UserId })
|
||||
.Where(stream => stream.StudentStream.ContainsKey(student.Id))
|
||||
.Join(_disciplineStorage.GetFilteredList(new DisciplineSearchModel { UserId = model.UserId }),
|
||||
stream => stream.Id,
|
||||
discipline => discipline.StreamId,
|
||||
(stream, discipline) => discipline.Name)
|
||||
.ToList()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return result;
|
||||
}
|
||||
public List<ReportStreamStudentEdStatPeriodViewModel> StreamStudentEdStatPeriod(ReportBindingModel model)
|
||||
public List<ReportStreamStudentEdStatPeriodViewModel> GetStreamStudentEdStatPeriod(ReportBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var result = _streamStorage
|
||||
.GetFilteredList(new StreamSearchModel { UserId = model.UserId })
|
||||
.Select(stream => new ReportStreamStudentEdStatPeriodViewModel
|
||||
{
|
||||
StreamName = stream.Name,
|
||||
StudentEdStatus = stream.StudentStream
|
||||
.Where(student => _documentStorage.GetFilteredList(new DocumentSearchModel
|
||||
{
|
||||
UserId = model.UserId,
|
||||
DateFrom = model.DateFrom,
|
||||
DateTo = model.DateTo,
|
||||
})
|
||||
.Any(document => document.StudentDocument.ContainsKey(student.Value.Id)))//Выбираем студентов, которые есть в приказах за выбранный промежуток времени
|
||||
.Select(student => (
|
||||
StudentFIO: $"{student.Value.Name} {student.Value.Surname}",
|
||||
EdStatus: _educationStatusStorage.GetFilteredList(new EducationStatusSearchModel { UserId = model.UserId })
|
||||
.First(x => x.Id == student.Value.EducationStatusId).Name))
|
||||
.ToList()
|
||||
})
|
||||
.ToList();
|
||||
return result;
|
||||
}
|
||||
|
||||
public void SaveBlanksToWordFile(ReportBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
//TODO
|
||||
}
|
||||
|
||||
public void SaveDocumentBlankToExcelFile(ReportBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
//TODO
|
||||
}
|
||||
|
||||
public void SaveOrdersToPdfFile(ReportBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,5 +13,6 @@ namespace UniversityContracts.BindingModels
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public DateTime Date { get; set; } = DateTime.Now;
|
||||
public int UserId { get; set; }
|
||||
public Dictionary<int, IStudentModel> StudentDocument { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -11,5 +11,6 @@ namespace UniversityContracts.BindingModels
|
||||
public string FileName { get; set; } = string.Empty;
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
public int? UserId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -16,5 +16,7 @@ namespace UniversityContracts.BindingModels
|
||||
public int UserId { get; set; }
|
||||
|
||||
public int Id { get; set; }
|
||||
public Dictionary<int, IStudentModel> StudentStream { get; set; } = new();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ namespace UniversityContracts.BusinessLogicContracts
|
||||
{
|
||||
List<ReportStudentsDisciplineViewModel> GetStudentsDiscipline(ReportBindingModel model);
|
||||
|
||||
List<ReportStreamStudentEdStatPeriodViewModel> StreamStudentEdStatPeriod(ReportBindingModel model);
|
||||
List<ReportStreamStudentEdStatPeriodViewModel> GetStreamStudentEdStatPeriod(ReportBindingModel model);
|
||||
|
||||
void SaveBlanksToWordFile(ReportBindingModel model);
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UniversityModels.Models;
|
||||
@ -16,5 +17,6 @@ namespace UniversityContracts.ViewModels
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[DisplayName("Дата создания документа")]
|
||||
public DateTime Date { get; set; } = DateTime.Now;
|
||||
public Dictionary<int, IStudentModel> StudentDocument { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ namespace UniversityContracts.ViewModels
|
||||
{
|
||||
public class ReportStreamStudentEdStatPeriodViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string StreamName { get; set; } = string.Empty;
|
||||
public List<(string StudentFIO, string EdStatus)> StudentEdStatus { get; set; } = new();
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UniversityModels.Models;
|
||||
|
||||
namespace UniversityContracts.ViewModels
|
||||
{
|
||||
@ -15,5 +16,6 @@ namespace UniversityContracts.ViewModels
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[DisplayName("Номер курса")]
|
||||
public int Course { get; set; }
|
||||
public Dictionary<int, IStudentModel> StudentStream { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UniversityDataBaseImplemet.Models;
|
||||
using Stream = UniversityDataBaseImplemet.Models.Stream;
|
||||
|
||||
namespace UniversityDataBaseImplemet
|
||||
{
|
||||
@ -20,9 +16,15 @@ namespace UniversityDataBaseImplemet
|
||||
}
|
||||
public virtual DbSet<User> User { get; set; }
|
||||
public virtual DbSet<Document> Documents { get; set; }
|
||||
public virtual DbSet<Discipline> Discipline { get; set; }
|
||||
public virtual DbSet<EducationStatus> EducationStatuses { get; set; }
|
||||
public virtual DbSet<EducationGroup> EducationGroups { get; set; }
|
||||
public virtual DbSet<EducationGroupDocument> EducationGroupsDocuments { get; set; }
|
||||
public virtual DbSet<EducationGroupStream> EducationGroupsStreams { get; set; }
|
||||
public virtual DbSet<Stream> Streams { get; set; }
|
||||
public virtual DbSet<Student> Students { get; set; }
|
||||
public virtual DbSet<StudentDocument> StudentDocuments { get; set; }
|
||||
public virtual DbSet<StudentStream> StudentStreams { get; set; }
|
||||
public virtual DbSet<Role> Roles { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UniversityContracts.BindingModels;
|
||||
@ -39,33 +41,19 @@ namespace UniversityDataBaseImplemet.Implements
|
||||
.Select(record => record.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else if (model.DateFrom != null && model.DateTo != null && model.UserId.HasValue) // фильтрация для отчета#2 Поставщик
|
||||
else if (model.DateFrom != null && model.DateTo != null && model.UserId.HasValue)
|
||||
{
|
||||
return context.Documents
|
||||
.Where(d => d.Date >= model.DateFrom && d.Date <= model.DateTo)
|
||||
.Join(context.StudentDocuments,
|
||||
doc => doc.Id,
|
||||
studDoc => studDoc.DocumentId,
|
||||
(doc, studDoc) => new { Document = doc, StudentDocument = studDoc })
|
||||
.Join(context.Students,
|
||||
studDoc => studDoc.StudentDocument.StudentId,
|
||||
stud => stud.Id,
|
||||
(studDoc, stud) => new { studDoc.Document, Student = stud })
|
||||
.Include(record => record.Student.EducationStatus)
|
||||
.Join(context.StudentStreams,
|
||||
studEdu => studEdu.Student.Id,
|
||||
studStream => studStream.StudentId,
|
||||
(studEdu, studStream) => new { studEdu.Document, studEdu.Student, studEdu.EducationStatus, StudentStream = studStream })
|
||||
.Join(context.Streams,
|
||||
studStream => studStream.StudentStream.StreamId,
|
||||
stream => stream.Id,
|
||||
(studStream, stream) => new { Stream = stream.Name, studStream.Student, studStream.EducationStatus.Name })
|
||||
.Select(result => new {
|
||||
result.Stream,
|
||||
result.Student,
|
||||
result.EducationStatus
|
||||
})
|
||||
.ToList();
|
||||
.Where(d => d.Date >= model.DateFrom && d.Date <= model.DateTo && d.UserId == model.UserId)
|
||||
.Include(d => d.Students)
|
||||
.ThenInclude(sd => sd.Student)
|
||||
.ThenInclude(s => s.StudentStream)
|
||||
.ThenInclude(ss => ss.Stream)
|
||||
.Include(d => d.Students)
|
||||
.ThenInclude(sd => sd.Student)
|
||||
.ThenInclude(s => s.EducationStatus)
|
||||
.Select(result => result.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else if (model.UserId.HasValue)
|
||||
{
|
||||
|
@ -25,7 +25,19 @@ namespace UniversityDataBaseImplemet.Models
|
||||
[ForeignKey("DocumentId")]
|
||||
public virtual List<EducationGroupDocument> EducationGroupDocument { get; set; } = new();
|
||||
public virtual User User { get; set; }
|
||||
|
||||
private Dictionary<int, IStudentModel>? _studentDocument = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, IStudentModel> StudentDocument
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_studentDocument == null)
|
||||
{
|
||||
_studentDocument = Students.ToDictionary(rec => rec.StudentId, rec => rec.Student as IStudentModel);
|
||||
}
|
||||
return _studentDocument;
|
||||
}
|
||||
}
|
||||
public static Document? Create(DocumentBindingModel model)
|
||||
{
|
||||
return new Document()
|
||||
@ -46,12 +58,44 @@ namespace UniversityDataBaseImplemet.Models
|
||||
Date = model.Date;
|
||||
UserId = model.UserId;
|
||||
}
|
||||
public void UpdateStudents(Database context, DocumentBindingModel model)
|
||||
{
|
||||
var studentDocument = context.StudentDocuments
|
||||
.Where(rec => rec.DocumentId == model.Id)
|
||||
.ToList();
|
||||
if (studentDocument != null)
|
||||
{
|
||||
context.StudentDocuments
|
||||
.RemoveRange(studentDocument
|
||||
.Where(rec => !model.StudentDocument
|
||||
.ContainsKey(rec.StudentId))
|
||||
);
|
||||
context.SaveChanges();
|
||||
var document = context.Documents
|
||||
.First(x => x.Id == Id);
|
||||
foreach (var sd in studentDocument)
|
||||
{
|
||||
model.StudentDocument.Remove(sd.StudentId);
|
||||
}
|
||||
foreach (var sd in model.StudentDocument)
|
||||
{
|
||||
context.StudentDocuments.Add(new StudentDocument
|
||||
{
|
||||
Document = document,
|
||||
Student = context.Students.First(x => x.Id == sd.Key),
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_studentDocument = null;
|
||||
}
|
||||
}
|
||||
public DocumentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Date = Date,
|
||||
UserId = UserId,
|
||||
UserId = UserId,
|
||||
StudentDocument = StudentDocument
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,19 @@ namespace UniversityDataBaseImplemet.Models
|
||||
[ForeignKey("StreamId")]
|
||||
public virtual List<StudentStream> StreamStudents { get; set; } = new();
|
||||
public virtual User User { get; set; }
|
||||
|
||||
private Dictionary<int, IStudentModel>? _studentStream = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, IStudentModel> StudentStream
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_studentStream == null)
|
||||
{
|
||||
_studentStream = StreamStudents.ToDictionary(rec => rec.StudentId, rec => rec.Student as IStudentModel);
|
||||
}
|
||||
return _studentStream;
|
||||
}
|
||||
}
|
||||
public static Stream Create(StreamBindingModel model)
|
||||
{
|
||||
return new Stream()
|
||||
@ -40,6 +52,37 @@ namespace UniversityDataBaseImplemet.Models
|
||||
Course = model.Course;
|
||||
UserId = model.UserId;
|
||||
}
|
||||
public void UpdateStreamStudents(Database context, StreamBindingModel model)
|
||||
{
|
||||
var studentStream = context.StudentStreams
|
||||
.Where(rec => rec.StreamId == model.Id)
|
||||
.ToList();
|
||||
if (studentStream != null)
|
||||
{
|
||||
context.StudentStreams
|
||||
.RemoveRange(studentStream
|
||||
.Where(rec => !model.StudentStream
|
||||
.ContainsKey(rec.StudentId))
|
||||
);
|
||||
context.SaveChanges();
|
||||
var stream = context.Streams
|
||||
.First(x => x.Id == Id);
|
||||
foreach (var sd in studentStream)
|
||||
{
|
||||
model.StudentStream.Remove(sd.StudentId);
|
||||
}
|
||||
foreach (var sd in model.StudentStream)
|
||||
{
|
||||
context.StudentStreams.Add(new StudentStream
|
||||
{
|
||||
Stream = stream,
|
||||
Student = context.Students.First(x => x.Id == sd.Key),
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_studentStream = null;
|
||||
}
|
||||
}
|
||||
public StreamViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
|
@ -11,5 +11,6 @@ namespace UniversityModels.Models
|
||||
string Name { get; }
|
||||
DateTime Date { get; }
|
||||
int UserId { get; }
|
||||
Dictionary <int, IStudentModel> StudentDocument { get; }
|
||||
}
|
||||
}
|
||||
|
@ -11,5 +11,7 @@ namespace UniversityModels.Models
|
||||
string Name { get; }
|
||||
int Course { get; }
|
||||
int UserId { get; }
|
||||
|
||||
Dictionary<int, IStudentModel> StudentStream { get; }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user