add all except ContractRepository logic
This commit is contained in:
parent
8ff6da0fe1
commit
c62dd35f93
@ -16,8 +16,14 @@ public class Contract
|
|||||||
[DisplayName("Заказчик")]
|
[DisplayName("Заказчик")]
|
||||||
public int CustomerName { get; private set; }
|
public int CustomerName { get; private set; }
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
|
public ExecutorPost ExecutorPost { get; private set; }
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
|
public string ExecutorName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
[DisplayName("Исполнитель")]
|
[DisplayName("Исполнитель")]
|
||||||
public int ExecutorName { get; private set; }
|
public string ExecutorFullName => $"{ExecutorPost} {ExecutorName}";
|
||||||
|
|
||||||
[DisplayName("Тип контракта")]
|
[DisplayName("Тип контракта")]
|
||||||
public ContractCategory Category { get; private set; }
|
public ContractCategory Category { get; private set; }
|
||||||
@ -68,4 +74,10 @@ public class Contract
|
|||||||
Services = services
|
Services = services
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetServices(IEnumerable<Service> services)
|
||||||
|
{
|
||||||
|
if (services != null && services.Any())
|
||||||
|
Services = services;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.ComponentModel;
|
using PIbd_23_Gutorov_I.A._IT_Company.Entities.Enums;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
namespace PIbd_23_Gutorov_I.A._IT_Company.Entities;
|
namespace PIbd_23_Gutorov_I.A._IT_Company.Entities;
|
||||||
|
|
||||||
@ -13,10 +14,16 @@ public class CustomerExecutorReview
|
|||||||
public int ExecutorId { get; private set; }
|
public int ExecutorId { get; private set; }
|
||||||
|
|
||||||
[DisplayName("Заказчик")]
|
[DisplayName("Заказчик")]
|
||||||
public int CustomerName { get; private set; }
|
public string CustomerName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
|
public ExecutorPost ExecutorPost { get; private set; }
|
||||||
|
|
||||||
|
[Browsable(false)]
|
||||||
|
public string ExecutorName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
[DisplayName("Исполнитель")]
|
[DisplayName("Исполнитель")]
|
||||||
public int ExecutorName { get; private set; }
|
public string ExecutorFullName => $"{ExecutorPost} {ExecutorName}";
|
||||||
|
|
||||||
[DisplayName("Отзыв")]
|
[DisplayName("Отзыв")]
|
||||||
public string Review { get; private set; } = string.Empty;
|
public string Review { get; private set; } = string.Empty;
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
using PIbd_23_Gutorov_I.A._IT_Company.Entities.Enums;
|
|
||||||
|
|
||||||
namespace PIbd_23_Gutorov_I.A._IT_Company.Entities;
|
|
||||||
|
|
||||||
public class TempServiceContract
|
|
||||||
{
|
|
||||||
public int Id { get; private set; }
|
|
||||||
|
|
||||||
public int CustomerID { get; private set; }
|
|
||||||
|
|
||||||
public int ExecutorID { get; private set; }
|
|
||||||
|
|
||||||
public ContractCategory Category { get; private set; }
|
|
||||||
|
|
||||||
public DateTime ConclusionDate { get; private set; }
|
|
||||||
|
|
||||||
public DateTime Deadline { get; private set; }
|
|
||||||
|
|
||||||
public int PaymentAmount { get; private set; }
|
|
||||||
|
|
||||||
public int ServiceId { get; private set; }
|
|
||||||
|
|
||||||
public string Description { get; private set; } = string.Empty;
|
|
||||||
}
|
|
@ -64,6 +64,8 @@ namespace PIbd_23_Gutorov_I.A._IT_Company.Forms
|
|||||||
{
|
{
|
||||||
dataGridViewData.DataSource = _contractRepository.ReadContracts();
|
dataGridViewData.DataSource = _contractRepository.ReadContracts();
|
||||||
dataGridViewData.Columns["Id"].Visible = false;
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
dataGridViewData.Columns["ConclusionDate"].DefaultCellStyle.Format = "dd MMMM yyyy hh:mm";
|
||||||
|
dataGridViewData.Columns["Deadline"].DefaultCellStyle.Format = "dd MMMM yyyy hh:mm";
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
|
@ -23,7 +23,7 @@ internal class ChartReport
|
|||||||
{
|
{
|
||||||
new PdfBuilder(filePath)
|
new PdfBuilder(filePath)
|
||||||
.AddHeader("Заключение контрактов")
|
.AddHeader("Заключение контрактов")
|
||||||
.AddPieChart("Услуги", GetData(dateTime))
|
.AddPieChart($"Оказанные услуги на {dateTime: dd MMMM yyyy}", GetData(dateTime))
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -38,8 +38,7 @@ internal class ChartReport
|
|||||||
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
||||||
{
|
{
|
||||||
return _contractRepository
|
return _contractRepository
|
||||||
.ReadContracts()
|
.ReadContracts(dateFrom: dateTime.Date, dateTo: dateTime.Date.AddDays(1))
|
||||||
.Where(x => x.ConclusionDate.Date == dateTime.Date)
|
|
||||||
.GroupBy(x => x.CustomerID, (key, group) => new
|
.GroupBy(x => x.CustomerID, (key, group) => new
|
||||||
{
|
{
|
||||||
Id = key,
|
Id = key,
|
||||||
|
@ -26,7 +26,7 @@ internal class TableReport
|
|||||||
{
|
{
|
||||||
new ExcelBuilder(filePath)
|
new ExcelBuilder(filePath)
|
||||||
.AddHeader("Сводка по заключениям контрактов", 0, 4)
|
.AddHeader("Сводка по заключениям контрактов", 0, 4)
|
||||||
.AddParagraph("за период", 0)
|
.AddParagraph($"за период с {startDate:dd.MM.yyyy} по {endDate:dd.MM.yyyy}", 0)
|
||||||
.AddTable([10, 10, 15, 15], GetData(customerId, startDate, endDate))
|
.AddTable([10, 10, 15, 15], GetData(customerId, startDate, endDate))
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
@ -42,10 +42,7 @@ internal class TableReport
|
|||||||
private List<string[]> GetData(int customerId, DateTime startDate, DateTime endDate)
|
private List<string[]> GetData(int customerId, DateTime startDate, DateTime endDate)
|
||||||
{
|
{
|
||||||
var data = _contractRepository
|
var data = _contractRepository
|
||||||
.ReadContracts()
|
.ReadContracts(customerId: customerId, dateFrom: startDate, dateTo: endDate)
|
||||||
.Where(x => x.ConclusionDate >= startDate
|
|
||||||
&& x.ConclusionDate <= endDate
|
|
||||||
&& x.CustomerID == customerId)
|
|
||||||
.GroupBy(x => x.ConclusionDate)
|
.GroupBy(x => x.ConclusionDate)
|
||||||
.Select(x => new
|
.Select(x => new
|
||||||
{
|
{
|
||||||
|
@ -83,20 +83,38 @@ public class ContractRepository : IContractRepository
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var builder = new QueryBuilder();
|
||||||
|
if (dateFrom.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("c.ConclusionDate >= @dateFrom");
|
||||||
|
builder.AddCondition("c.Deadline >= @dateFrom");
|
||||||
|
}
|
||||||
|
if (dateTo.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("c.ConclusionDate <= @dateTo");
|
||||||
|
builder.AddCondition("c.Deadline <= @dateTo");
|
||||||
|
}
|
||||||
|
if (customerId.HasValue)
|
||||||
|
builder.AddCondition("c.CustomerId >= @customerId");
|
||||||
|
if (executorId.HasValue)
|
||||||
|
builder.AddCondition("c.ExecutorId >= @executorId");
|
||||||
|
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @"
|
var querySelect = @$"
|
||||||
SELECT c.*, sc.ServiceId, s.Description
|
SELECT c.*, sc.ServiceId, s.Description,
|
||||||
|
CONCAT(cu.Name, ' ', cu.Contact) as CustomerName,
|
||||||
|
e.Post as ExecutorPost,
|
||||||
|
e.Name as ExecutorName
|
||||||
FROM Contracts c
|
FROM Contracts c
|
||||||
INNER JOIN ServiceContract sc ON sc.ContractId = c.Id
|
INNER JOIN ServiceContract sc ON sc.ContractId = c.Id
|
||||||
INNER JOIN Services s ON sc.ServiceId = s.Id
|
LEFT JOIN Services s ON sc.ServiceId = s.Id
|
||||||
|
LEFT JOIN Customers cu ON cu.Id = c.CustomerId
|
||||||
|
LEFT JOIN Executors e ON e.Id = c.ExecutorId
|
||||||
|
{builder.Build()};
|
||||||
";
|
";
|
||||||
var contracts = connection.Query<TempServiceContract>(querySelect);
|
var serviceDict = new Dictionary<int, List<Service>>();
|
||||||
|
var contracts = connection.Query<Contract, Service>(querySelect, new { dateFrom, dateTo, customerId, executorId });
|
||||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(contracts));
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(contracts));
|
||||||
return contracts
|
|
||||||
.GroupBy(x => x.Id, y => y, (key, value) =>
|
|
||||||
Contract.CreateEntity(value.First(), value.Select(z => Service.CreateEntity(z.ServiceId, z.Description))))
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Ошибка при чтении объектов");
|
_logger.LogError(ex, "Ошибка при чтении объектов");
|
||||||
|
@ -66,11 +66,24 @@ public class CustomerExecutorReviewRepository : ICustomerExecutorReviewRepositor
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var builder = new QueryBuilder();
|
||||||
|
if (customerId.HasValue)
|
||||||
|
builder.AddCondition("cer.CustomerId = @customerId");
|
||||||
|
if (executorId.HasValue)
|
||||||
|
builder.AddCondition("cer.ExecutorId = @executorId");
|
||||||
|
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @"
|
var querySelect = @$"
|
||||||
SELECT * FROM CustomerExecutorReviews;
|
SELECT cer.*,
|
||||||
|
CONCAT(c.Name, ' ', c.Contact) as CustomerName,
|
||||||
|
e.Post as ExecutorPost,
|
||||||
|
e.Name as ExecutorName
|
||||||
|
FROM CustomerExecutorReviews cer
|
||||||
|
LEFT JOIN Customers c ON c.Id = cer.CustomerId
|
||||||
|
LEFT JOIN Executors e ON e.Id = cer.ExecutorId
|
||||||
|
{builder.Build()};
|
||||||
";
|
";
|
||||||
var customerExecutorReviews = connection.Query<CustomerExecutorReview>(querySelect);
|
var customerExecutorReviews = connection.Query<CustomerExecutorReview>(querySelect, new { customerId, executorId });
|
||||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(customerExecutorReviews));
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(customerExecutorReviews));
|
||||||
return customerExecutorReviews;
|
return customerExecutorReviews;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
using System.Text;
|
||||||
|
|
||||||
|
internal class QueryBuilder
|
||||||
|
{
|
||||||
|
private readonly StringBuilder _builder;
|
||||||
|
|
||||||
|
public QueryBuilder()
|
||||||
|
{
|
||||||
|
_builder = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
public QueryBuilder AddCondition(string condition)
|
||||||
|
{
|
||||||
|
if (_builder.Length > 0)
|
||||||
|
{
|
||||||
|
_builder.Append(" AND ");
|
||||||
|
}
|
||||||
|
|
||||||
|
_builder.Append(condition);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Build()
|
||||||
|
{
|
||||||
|
if (_builder.Length == 0)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $"WHERE {_builder}";
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user