PIbd-21 Permyakov R. G. Lab4 #4
@ -22,7 +22,7 @@ namespace RealEstateTransactions.Reports
|
||||
{
|
||||
new PdfBuilder(filePath)
|
||||
.AddHeader("Доход с продажи квартир")
|
||||
.AddPieChart("Проданные квартиры", GetData(dateTime))
|
||||
.AddPieChart($"Проданные квартиры {dateTime:dd.MM.yyyy}", GetData(dateTime))
|
||||
.Build();
|
||||
return true;
|
||||
}
|
||||
@ -36,8 +36,7 @@ namespace RealEstateTransactions.Reports
|
||||
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
||||
{
|
||||
return _dealRepository
|
||||
.ReadDeals()
|
||||
.Where(x => x.Deal_date.Date == dateTime.Date)
|
||||
.ReadDeals(dateFrom: dateTime.Date, dateTo: dateTime.Date.AddDays(1))
|
||||
.Select(x => (x.Apartment_ID.ToString(), (double)x.Deal_price))
|
||||
.ToList();
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ namespace RealEstateTransactions.Reports
|
||||
{
|
||||
new ExcelBuilder(filePath)
|
||||
.AddHeader("Сводка по доходу от продажи квартиры", 0, 4)
|
||||
.AddParagraph("за период", 0)
|
||||
.AddParagraph($"за период с {startDate:dd.MM.yyyy} по {endDate:dd.MM.yyyy}", 0)
|
||||
.AddTable([10, 10, 10, 15], GetData(apartmentId, startDate,
|
||||
endDate))
|
||||
.Build();
|
||||
@ -47,9 +47,7 @@ namespace RealEstateTransactions.Reports
|
||||
endDate)
|
||||
{
|
||||
var data = _dealRepository
|
||||
.ReadDeals()
|
||||
.Where(x => x.Deal_date >= startDate && x.Deal_date <= endDate &&
|
||||
x.Apartment_ID == apartmentId)
|
||||
.ReadDeals(startDate, endDate, apartmentId)
|
||||
.Select(x => new {
|
||||
DealId = (int?)x.Id, Date = (DateTime?)x.Deal_date, DealPrice = (float?)x.Deal_price, ServicesPrice = (float?)null
|
||||
})
|
||||
@ -67,7 +65,7 @@ namespace RealEstateTransactions.Reports
|
||||
.Union(
|
||||
data
|
||||
.Select(x => new string[] {
|
||||
x.DealId?.ToString() ?? string.Empty, x.Date?.ToString() ?? string.Empty,
|
||||
x.DealId?.ToString("N0") ?? string.Empty, x.Date?.ToString("dd.MM.yyyy") ?? string.Empty,
|
||||
x.DealPrice?.ToString() ?? string.Empty, x.ServicesPrice?.ToString() ?? string.Empty}))
|
||||
.Union(
|
||||
[["Всего", "", data.Sum(x => x.DealPrice ?? 0).ToString(),
|
||||
|
@ -4,8 +4,8 @@ namespace RealEstateTransactions.Repositories
|
||||
{
|
||||
public interface IDealRepository
|
||||
{
|
||||
IEnumerable<Deal> ReadDeals(DateTime? dateForm = null, DateTime? dateTo = null,
|
||||
int? servicesID = null, int? dealID = null);
|
||||
IEnumerable<Deal> ReadDeals(DateTime? dateFrom = null, DateTime? dateTo = null,
|
||||
int? apartmentId = null);
|
||||
|
||||
void CreateDeal(Deal deal);
|
||||
|
||||
|
@ -69,14 +69,22 @@ namespace RealEstateTransactions.Repositories.Implementations
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Deal> ReadDeals(DateTime? dateForm = null, DateTime? dateTo = null,
|
||||
int? servicesID = null, int? dealID = null)
|
||||
public IEnumerable<Deal> ReadDeals(DateTime? dateFrom = null, DateTime? dateTo = null,
|
||||
int? apartmentId = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
var builder = new QueryBuilder();
|
||||
if (dateFrom.HasValue)
|
||||
builder.AddCondition("de.Deal_date >= @dateFrom");
|
||||
if (dateTo.HasValue)
|
||||
builder.AddCondition("de.Deal_date <= @dateTo");
|
||||
if (apartmentId.HasValue)
|
||||
builder.AddCondition("de.Apartment_Id = @apartmentId");
|
||||
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var selectQuery = @"SELECT
|
||||
var selectQuery = $@"SELECT
|
||||
de.*,
|
||||
bu.Full_name BuyerName,
|
||||
sd.Deal_Id,
|
||||
@ -86,7 +94,8 @@ namespace RealEstateTransactions.Repositories.Implementations
|
||||
FROM Deal de
|
||||
LEFT JOIN Buyer bu on bu.Id = de.Buyer_Id
|
||||
INNER JOIN Services_Deal sd on sd.Deal_Id = de.Id
|
||||
LEFT JOIN Services ss on ss.Id = sd.Services_Id";
|
||||
LEFT JOIN Services ss on ss.Id = sd.Services_Id
|
||||
{builder.Build()}";
|
||||
var servicesDict = new Dictionary<int, List<ServicesDeal>>();
|
||||
|
||||
var deals = connection.Query<Deal, ServicesDeal, Deal>(selectQuery,
|
||||
@ -100,7 +109,7 @@ namespace RealEstateTransactions.Repositories.Implementations
|
||||
|
||||
sd.Add(servicesDeal);
|
||||
return deal;
|
||||
}, splitOn: "Deal_Id");
|
||||
}, splitOn: "Deal_Id", param: new {dateFrom, dateTo, apartmentId});
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(deals));
|
||||
|
||||
return servicesDict.Select(x =>
|
||||
|
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RealEstateTransactions.Repositories.Implementations
|
||||
{
|
||||
public class QueryBuilder
|
||||
{
|
||||
private readonly StringBuilder _builder;
|
||||
|
||||
public QueryBuilder()
|
||||
{
|
||||
_builder = new StringBuilder();
|
||||
}
|
||||
|
||||
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