Графики для исполнителя

This commit is contained in:
Володя 2023-05-19 16:14:57 +03:00
parent 0d12590f78
commit 612a7c2780
11 changed files with 240 additions and 23 deletions

View File

@ -0,0 +1,77 @@
using SchoolAgainStudyBusinessLogic.OfficePackage;
using SchoolAgainStudyContracts.BusinessLogicContracts;
using SchoolAgainStudyContracts.SearchModel;
using SchoolAgainStudyContracts.StorageContracts;
using SchoolAgainStudyContracts.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolAgainStudyBusinessLogic.BusinessLogic
{
public class ChartLogic : IChartLogic
{
private readonly IInterestLogic _interest;
private readonly IProductLogic _product;
private readonly IDiyLogic _diy;
public ChartLogic(IInterestLogic interest, IProductLogic product, IDiyLogic diy)
{
_interest = interest;
_product = product;
_diy = diy;
}
public (int Products, int Diyes) GetDifferenceInCount(int StudentId)
{
var products = _product.ReadList(new ProductSearchModel
{
StudentId = StudentId,
DateFrom = DateTime.SpecifyKind(DateTime.Now.AddMonths(-1), DateTimeKind.Utc),
DateTo = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc),
});
var diyes = _diy.ReadList(new DiySearchModel
{
StudentId = StudentId,
DateFrom = DateTime.SpecifyKind(DateTime.Now.AddMonths(-1), DateTimeKind.Utc),
DateTo = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc),
});
return (products.Count, diyes.Count);
}
public List<ActivityChartViewModel> GetActivitys(int StudentId)
{
var products = _product.ReadList(new ProductSearchModel
{
StudentId = StudentId,
DateFrom = DateTime.SpecifyKind(DateTime.Now.AddMonths(-1), DateTimeKind.Utc),
DateTo = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc),
});
var diyes = _diy.ReadList(new DiySearchModel
{
StudentId = StudentId,
DateFrom = DateTime.SpecifyKind(DateTime.Now.AddMonths(-1), DateTimeKind.Utc),
DateTo = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc),
});
Dictionary<DateTime, int> list = new Dictionary<DateTime, int>();
for(DateTime date = DateTime.Now.AddMonths(-1); date<= DateTime.Now; date=date.AddDays(1))
{
list.Add(date, 0);
foreach(var product in products)
{
if (product.DateCreate.Date == date.Date)
list[date] += 1;
}
foreach (var diy in diyes)
{
if (diy.DateCreate.Date == date.Date)
list[date] += 1;
}
}
var actList = list.Select(g => new ActivityChartViewModel { dateOf = g.Key.ToString("dd/MM"), count = g.Value }).ToList();
return actList;
}
}
}

View File

@ -17,7 +17,6 @@
</ItemGroup>
<ItemGroup>
<Folder Include="BusinessLogic\" />
<Folder Include="OfficePackage\HelperEnums\" />
<Folder Include="OfficePackage\HelperModels\" />
<Folder Include="OfficePackage\Implements\" />

View File

@ -0,0 +1,15 @@
using SchoolAgainStudyContracts.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolAgainStudyContracts.BusinessLogicContracts
{
public interface IChartLogic
{
public (int Products, int Diyes) GetDifferenceInCount(int StudentId);
public List<ActivityChartViewModel> GetActivitys(int StudentId);
}
}

View File

@ -11,10 +11,8 @@
</ItemGroup>
<ItemGroup>
<Folder Include="BusinessLogicContracts\" />
<Folder Include="SearchModel\" />
<Folder Include="StorageContracts\" />
<Folder Include="ViewModel\" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SchoolAgainStudyContracts.ViewModel
{
public class ActivityChartViewModel
{
public string dateOf { get; set; } = string.Empty;
public int count { get; set; }
}
}

View File

@ -1,16 +1,17 @@
using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml.Drawing;
using DocumentFormat.OpenXml.Wordprocessing;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Newtonsoft.Json;
using SchoolAgainStudyBusinessLogic.MailWorker;
using SchoolAgainStudyContracts.BindingModel;
using SchoolAgainStudyContracts.BusinessLogicContracts;
using SchoolAgainStudyContracts.SearchModel;
using SchoolAgainStudyContracts.ViewModel;
using SchoolAgainStudyDataBaseImplements.Models;
using SchoolAgainStudyDataModels.Models;
using StudentWebClient.Models;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Linq.Expressions;
namespace StudentWebClient.Controllers
{
@ -23,9 +24,11 @@ namespace StudentWebClient.Controllers
private readonly IInterestLogic _interest;
private readonly IStudentLogic _student;
private readonly IReportLogic _report;
private readonly IChartLogic _chart;
private readonly AbstractMailWorker mailSender;
public HomeController(ILogger<HomeController> logger, IDiyLogic diy,
IProductLogic product , ITaskLogic task , IInterestLogic interest, IStudentLogic student, IReportLogic report, AbstractMailWorker abstractMailWorker)
IProductLogic product , ITaskLogic task , IInterestLogic interest,
IStudentLogic student, IReportLogic report, AbstractMailWorker abstractMailWorker, IChartLogic chartLogic)
{
_logger = logger;
_diy = diy;
@ -34,6 +37,7 @@ namespace StudentWebClient.Controllers
_interest = interest;
_student = student;
_report = report;
_chart = chartLogic;
try
{
@ -251,7 +255,7 @@ namespace StudentWebClient.Controllers
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
if (string.IsNullOrEmpty(title) && string.IsNullOrEmpty(description) || string.IsNullOrEmpty(dateCreate) || task <=0 || interests.Length==0)
if (string.IsNullOrEmpty(title) && string.IsNullOrEmpty(description) || string.IsNullOrEmpty(dateCreate) || task <=0 )
{
throw new Exception("Введите название и описане");
}
@ -305,10 +309,7 @@ namespace StudentWebClient.Controllers
{
throw new Exception("Нет задания");
}
if (interests.Length == 0)
{
throw new Exception("Нет интересов");
}
Dictionary<int, IInterest> diyInterests = new Dictionary<int, IInterest>();
foreach (int id in interests)
@ -364,7 +365,7 @@ namespace StudentWebClient.Controllers
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
if (string.IsNullOrEmpty(title) && string.IsNullOrEmpty(description) || string.IsNullOrEmpty(dateCreate)|| interests.Length == 0)
if (string.IsNullOrEmpty(title) && string.IsNullOrEmpty(description) || string.IsNullOrEmpty(dateCreate))
{
throw new Exception("Введите название и описане");
}
@ -411,10 +412,7 @@ namespace StudentWebClient.Controllers
{
throw new Exception("Нет даты");
}
if (interests.Length == 0)
{
throw new Exception("Нет интересов");
}
Dictionary<int, IInterest> productInterests = new Dictionary<int, IInterest>();
foreach (int id in interests)
@ -493,10 +491,33 @@ namespace StudentWebClient.Controllers
mailSender.MailSendAsync(new MailSendInfoBindingModel
{
MailAddress = APIClient.Student.Email,
Subject = "Заказ номер",
Subject = $"Отчет от {dateFrom} по {dateTo}",
Path = path
});
return PartialView("_LessonListPartial", items);
}
return PartialView("_InterestListPartial", items);
}
[HttpGet]
public IActionResult WorksCharts()
{
if (APIClient.Student == null)
{
return Redirect("~/Home/Enter");
}
return View(_chart.GetDifferenceInCount(APIClient.Student.Id));
}
[HttpGet]
public IActionResult ActivityCharts()
{
if (APIClient.Student == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.DataPoints = JsonConvert.SerializeObject(_chart.GetActivitys(APIClient.Student.Id),
new JsonSerializerSettings() {
NullValueHandling = NullValueHandling.Ignore});
return View();
}
}
}

View File

@ -32,6 +32,8 @@ builder.Services.AddTransient<IReportLogic, ReportLogic>();
builder.Services.AddTransient<ITeacherLogic, TeacherLogic>();
builder.Services.AddTransient<IMaterialLogic, MaterialLogic>();
builder.Services.AddTransient<ILessonLogic, LessonLogic>();
builder.Services.AddTransient<IChartLogic, ChartLogic>();
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();

View File

@ -0,0 +1,33 @@
@using SchoolAgainStudyContracts.ViewModel;
@model List<ActivityChartViewModel>
<script type="text/javascript">
var result = @Html.Raw(ViewBag.DataPoints);
var dataPoints = [];
for (var i = 0; i < result.length; i++) {
dataPoints.push({ label: result[i].dateOf, y: result[i].count });
}
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer", {
theme: "theme2",
animationEnabled: true,
title: {
text: "Отслеживание работы за послдений месяц"
},
data: [
{
// change type to bar, line, area, pie, etc.
type: "column",
dataPoints: dataPoints
}
]
});
chart.render();
};
</script>
<body>
<div id="chartContainer">
</div>
</body>

View File

@ -0,0 +1,30 @@
@model System.ValueTuple<int,int>
<script type="text/javascript">
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer", {
theme: "theme2",
animationEnabled: true,
title: {
text: "Соотношение кол-ва изделий и поделок"
},
data: [
{
// change type to bar, line, area, pie, etc.
type: "pie",
dataPoints: [
{ label: "Изделия", y: @Model.Item1 },
{ label: "Поделки", y: @Model.Item2 },
]
}
]
});
chart.render();
};
</script>
<body>
<div id="chartContainer">
</div>
</body>

View File

@ -9,12 +9,20 @@
<thead>
<tr>
<th>
Название
Интерес
</th>
<th>
Интересы
Изделие
</th>
<th>
Дата создания
</th>
<th>
Поделка
</th>
<th>
Дата создания
</th>
</tr>
</thead>
<tbody>
@ -24,6 +32,18 @@
<td>
@Html.DisplayFor(modelItem => item.InterestTitle)
</td>
<td>
@Html.DisplayFor(modelItem => item.ProductTitle)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateCreateProduct)
</td>
<td>
@Html.DisplayFor(modelItem => item.DiyTitle)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateCreateDiy)
</td>
</tr>
}

View File

@ -10,6 +10,7 @@
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
@await RenderSectionAsync("Scripts", required: false)
</head>
<body>
@ -47,6 +48,12 @@
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="SendingEmail">НаПочту</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="WorksCharts">Соотношение</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="ActivityCharts">Отслеживание</a>
</li>
</ul>
</div>