Добавил диаграмму

This commit is contained in:
maxnes3 2023-05-20 05:04:42 +04:00
parent 636af51602
commit db5681fc25
14 changed files with 159 additions and 27 deletions

View File

@ -76,6 +76,11 @@ namespace CaseAccountingBusinessLogic.BusinessLogics
return list; return list;
} }
public List<SpecializationCasesViewModel> GetSpecializationCases()
{
return _caseStorage.GetSpecializationCases() ?? new List<SpecializationCasesViewModel>();
}
public bool Update(CaseBindingModel model) public bool Update(CaseBindingModel model)
{ {
CheckModel(model); CheckModel(model);

View File

@ -16,5 +16,6 @@ namespace CaseAccountingContracts.BusinessLogicContracts
bool Create(CaseBindingModel model); bool Create(CaseBindingModel model);
bool Update(CaseBindingModel model); bool Update(CaseBindingModel model);
bool Delete(CaseBindingModel model); bool Delete(CaseBindingModel model);
List<SpecializationCasesViewModel> GetSpecializationCases();
} }
} }

View File

@ -19,5 +19,6 @@ namespace CaseAccountingContracts.StoragesContracts
CaseViewModel? Delete(CaseBindingModel model); CaseViewModel? Delete(CaseBindingModel model);
List<HearingViewModel> GetCaseHearings(CaseSearchModel model); List<HearingViewModel> GetCaseHearings(CaseSearchModel model);
List<SpecializationCasesViewModel>? GetSpecializationCases();
} }
} }

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CaseAccountingContracts.ViewModels
{
public class SpecializationCasesViewModel
{
public int Count { get; set; }
public string Name { get; set; } = string.Empty;
}
}

View File

@ -185,5 +185,22 @@ namespace CaseAccountingDataBaseImplement.Implements
return hearings; return hearings;
} }
public List<SpecializationCasesViewModel>? GetSpecializationCases()
{
using var context = new CaseAccountingDatabase();
var result = context.Specializations
.GroupJoin(
context.Cases,
status => status.Id,
caseModel => caseModel.SpecializationId,
(status, caseModels) => new SpecializationCasesViewModel
{
Name = status.Name,
Count = caseModels.Count()
})
.ToList();
return result;
}
} }
} }

View File

@ -129,5 +129,15 @@ namespace CaseAccountingProviderView.Controllers
List<SpecializationViewModel>? specializationModel = APIUser.GetRequest<List<SpecializationViewModel>>($"api/case/getallspecializations"); List<SpecializationViewModel>? specializationModel = APIUser.GetRequest<List<SpecializationViewModel>>($"api/case/getallspecializations");
return specializationModel ?? new(); return specializationModel ?? new();
} }
public List<SpecializationCasesViewModel> GetSpecializationCases()
{
if (APIUser.User == null)
{
return new();
}
List<SpecializationCasesViewModel>? specializationCases = APIUser.GetRequest<List<SpecializationCasesViewModel>>($"api/case/getspecializationcases");
return specializationCases ?? new();
}
} }
} }

View File

@ -40,6 +40,11 @@ namespace CaseAccountingProviderView.Controllers
return View(); return View();
} }
public IActionResult Diagram()
{
return View();
}
[HttpPost] [HttpPost]
public int[]? SpecializationCaselist([FromBody] CaseSpecializationListBindingModel listModel) public int[]? SpecializationCaselist([FromBody] CaseSpecializationListBindingModel listModel)
{ {

View File

@ -0,0 +1,15 @@

<div class="text-center">
<h1 class="display-4">Круговая диаграмма</h1>
</div>
<div class="container">
<button class="btn btn-success mt-4" id="btnStatus">Статистика по специализации дел</button>
<div class="container col-8 mt-4">
<canvas id="myChart"></canvas>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="~/js/diagram/diagram.js" asp-append-version="true"></script>

View File

@ -23,6 +23,7 @@
<a class="nav-link text-white" asp-area="" asp-controller="Home" asp-action="Hearings">Слушания</a> <a class="nav-link text-white" asp-area="" asp-controller="Home" asp-action="Hearings">Слушания</a>
<a class="nav-link text-white" asp-area="" asp-controller="Home" asp-action="SpecializationCaselist">Получение список</a> <a class="nav-link text-white" asp-area="" asp-controller="Home" asp-action="SpecializationCaselist">Получение список</a>
<a class="nav-link text-white" asp-area="" asp-controller="Home" asp-action="GetReport">Получение отчёта</a> <a class="nav-link text-white" asp-area="" asp-controller="Home" asp-action="GetReport">Получение отчёта</a>
<a class="nav-link text-white" asp-area="" asp-controller="Home" asp-action="Diagram">Формирование диаграммы</a>
</div> </div>
</div> </div>
</div> </div>

View File

@ -19,7 +19,6 @@ const formatDate = (dateString) => {
window.addEventListener("load", async () => { window.addEventListener("load", async () => {
try { try {
let specializationId;
await $.ajax({ await $.ajax({
url: `/case/get?id=${caseId}`, url: `/case/get?id=${caseId}`,
type: "GET", type: "GET",
@ -30,11 +29,8 @@ window.addEventListener("load", async () => {
defendantInput.value = result.defendant; defendantInput.value = result.defendant;
annotationInput.value = result.annotation; annotationInput.value = result.annotation;
dateInput.value = formatDate(result.date); dateInput.value = formatDate(result.date);
specializationId = result.specializationId;
}); });
let specializationIndex;
await $.ajax({ await $.ajax({
url: `/case/getallspecializations`, url: `/case/getallspecializations`,
type: "GET", type: "GET",
@ -46,14 +42,9 @@ window.addEventListener("load", async () => {
option.value = specialization.id; option.value = specialization.id;
option.innerHTML = specialization.name; option.innerHTML = specialization.name;
specializationSelect.appendChild(option); specializationSelect.appendChild(option);
if(specialization.id === specializationId){
specializationIndex = specializationSelect.selectedIndex;
}
specializationSelect.selectedIndex = -1; specializationSelect.selectedIndex = -1;
}); });
}); });
specializationSelect.selectedIndex = specializationIndex;
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} }
@ -84,7 +75,7 @@ updateBtn.addEventListener("click", () => {
"Name": nameInput.value, "Name": nameInput.value,
"Applicant": applicantInput.value, "Applicant": applicantInput.value,
"Defendant": defendantInput.value, "Defendant": defendantInput.value,
"Date": new Date(dateInput.value), "Date": dateInput.value,
"Annotation": annotationInput.value, "Annotation": annotationInput.value,
"SpecializationId": parseInt(specializationSelect.value), "SpecializationId": parseInt(specializationSelect.value),
}; };

View File

@ -4,6 +4,14 @@ const responsibilitiesInput = document.getElementById("responsibilities-input");
const dateInput = document.getElementById("date-input"); const dateInput = document.getElementById("date-input");
const dealId = document.getElementById("vb-id").dataset.id; const dealId = document.getElementById("vb-id").dataset.id;
const formatDate = (dateString) => {
const date = new Date(dateString);
const year = date.getFullYear();
const month = ('0' + (date.getMonth() + 1)).slice(-2);
const day = ('0' + date.getDate()).slice(-2);
return `${year}-${month}-${day}`;
};
window.addEventListener("load", async () => { window.addEventListener("load", async () => {
try { try {
await $.ajax({ await $.ajax({
@ -13,7 +21,7 @@ window.addEventListener("load", async () => {
}).done((result) => { }).done((result) => {
subjectInput.value = result.subject; subjectInput.value = result.subject;
responsibilitiesInput.value = result.responsibilities; responsibilitiesInput.value = result.responsibilities;
dateInput.value = new Date(result.date); dateInput.value = formatDate(result.date);
}); });
} catch (error) { } catch (error) {
console.error(error); console.error(error);
@ -44,7 +52,7 @@ updateBtn.addEventListener("click", () => {
"Id": parseInt(dealId), "Id": parseInt(dealId),
"Subject": subjectInput.value, "Subject": subjectInput.value,
"Responsibilities": responsibilitiesInput.value, "Responsibilities": responsibilitiesInput.value,
"Date": new Date(dateInput.value) "Date": dateInput.value
}; };
console.log(dealModel) console.log(dealModel)
$.ajax({ $.ajax({

View File

@ -0,0 +1,52 @@
var btnStatus = document.getElementById('btnStatus');
var casespecializations = [];
window.addEventListener('load', async () => {
await $.ajax({
url: "/case/getspecializationcases",
type: "GET",
contentType: "json"
}).done((result) => {
casespecializations = result;
console.log(casespecializations);
});
})
var ctx = document.getElementById('myChart').getContext('2d');
var chart;
function drawStatusChart() {
var edStatus = [];
var edCount = [];
console.log(casespecializations)
casespecializations.forEach((item) => {
edStatus.push(item.name);
});
casespecializations.forEach((item) => {
edCount.push(item.count);
});
var statusData = {
labels: edStatus,
datasets: [{
data: edCount
}]
};
// Clear the previous chart if it exists
if (chart) {
chart.destroy();
}
chart = new Chart(ctx, {
type: 'pie',
data: statusData,
options: {
responsive: true
}
});
}
btnStatus.addEventListener('click', function () {
drawStatusChart();
});

View File

@ -6,21 +6,25 @@ const hearingId = document.getElementById("vb-id").dataset.id;
var cases = []; var cases = [];
const formatDate = (dateString) => {
const date = new Date(dateString);
const year = date.getFullYear();
const month = ('0' + (date.getMonth() + 1)).slice(-2);
const day = ('0' + date.getDate()).slice(-2);
return `${year}-${month}-${day}`;
};
window.addEventListener("load", async () => { window.addEventListener("load", async () => {
try { try {
let caseId;
await $.ajax({ await $.ajax({
url: `/hearing/get?id=${hearingId}`, url: `/hearing/get?id=${hearingId}`,
type: "GET", type: "GET",
contentType: "json" contentType: "json"
}).done((result) => { }).done((result) => {
informationInput.value = result.information; informationInput.value = result.information;
dateInput.value = new Date(result.date); dateInput.value = formatDate(result.date);
caseId = result.caseId;
}); });
await $.ajax({
let caseIndex;
$.ajax({
url: "/case/getallbyuser", url: "/case/getallbyuser",
type: "GET", type: "GET",
contentType: "json" contentType: "json"
@ -31,14 +35,9 @@ window.addEventListener("load", async () => {
option.value = element.id; option.value = element.id;
option.innerHTML = "Дело №" + element.id; option.innerHTML = "Дело №" + element.id;
caseSelect.appendChild(option); caseSelect.appendChild(option);
if(element.id === caseId){
caseIndex = caseSelect.selectedIndex;
}
caseSelect.selectedIndex = -1; caseSelect.selectedIndex = -1;
}); });
}); });
caseSelect.selectedIndex = caseIndex;
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} }
@ -68,7 +67,7 @@ updateBtn.addEventListener("click", () => {
"Id": parseInt(hearingId), "Id": parseInt(hearingId),
"Information": informationInput.value, "Information": informationInput.value,
"CaseId": parseInt(caseSelect.value), "CaseId": parseInt(caseSelect.value),
"Date": new Date(dateInput.value) "Date": dateInput.value
}; };
console.log(hearingModel) console.log(hearingModel)
$.ajax({ $.ajax({

View File

@ -59,6 +59,19 @@ namespace CaseAccountingRestApi.Controllers
} }
} }
[HttpGet]
public List<SpecializationCasesViewModel> GetSpecializationCases()
{
try
{
return _logic.GetSpecializationCases();
}
catch (Exception)
{
throw;
}
}
[HttpPost] [HttpPost]
public void Create(CaseBindingModel model) public void Create(CaseBindingModel model)
{ {