первый этап сделан, проверить sql запрос ffr
This commit is contained in:
parent
288050d220
commit
aacae48a73
@ -11,6 +11,7 @@ public class FuelFuelReplenishment
|
||||
public int Id { get; private set; }
|
||||
public int FuelId { get; private set; }
|
||||
public int Amount { get; private set; }
|
||||
public string FuelName { get; private set; } = string.Empty;
|
||||
public static FuelFuelReplenishment CreateElement(int id, int fuelId, int amount)
|
||||
{
|
||||
return new FuelFuelReplenishment
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -9,10 +10,23 @@ namespace ProjectGarage.Entities;
|
||||
public class FuelReplenishment
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int DriverId { get; private set; }
|
||||
|
||||
[DisplayName("Водитель")]
|
||||
public string DriverName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Дата поставки")]
|
||||
public DateTime ReplenishmentDate { get; private set; }
|
||||
|
||||
[DisplayName("Топлива")]
|
||||
public string Fuel => FuelFuelReplenishments != null ?
|
||||
string.Join(", ", FuelFuelReplenishments.Select(x => $"{x.FuelName} {x.Amount}")) : string.Empty;
|
||||
|
||||
public IEnumerable<FuelFuelReplenishment> FuelFuelReplenishments { get; private set;} = [];
|
||||
|
||||
[Browsable(false)]
|
||||
public static FuelReplenishment CreateOpeartion(int id, int driverId, IEnumerable<FuelFuelReplenishment> fuelFuelReplenishments)
|
||||
{
|
||||
return new FuelReplenishment
|
||||
@ -24,14 +38,11 @@ public class FuelReplenishment
|
||||
};
|
||||
}
|
||||
|
||||
public static FuelReplenishment CreateOpeartion(TempFuelReplenishment tempFuelReplenishment, IEnumerable<FuelFuelReplenishment> fuelFuelReplenishments)
|
||||
public void SetFuelFuelReplenishments(IEnumerable<FuelFuelReplenishment> fuelFuelReplenishments)
|
||||
{
|
||||
return new FuelReplenishment
|
||||
if (fuelFuelReplenishments != null && fuelFuelReplenishments.Any())
|
||||
{
|
||||
Id = tempFuelReplenishment.Id,
|
||||
DriverId = tempFuelReplenishment.DriverId,
|
||||
ReplenishmentDate = tempFuelReplenishment.ReplenishmentDate,
|
||||
FuelFuelReplenishments = fuelFuelReplenishments
|
||||
};
|
||||
FuelFuelReplenishments = fuelFuelReplenishments;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -10,15 +11,29 @@ public class Transportation
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int FuelId { get; set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int RouteId { get; set; }
|
||||
|
||||
[Browsable(false)]
|
||||
public int DriverId { get; set; }
|
||||
|
||||
public int Amount { get; set; }
|
||||
[DisplayName("Топливо")]
|
||||
public string FuelName { get; private set; } = string.Empty;
|
||||
|
||||
public DateTime TransportationDate { get; set; }
|
||||
[DisplayName("Водитель")]
|
||||
public string DriverName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Маршрут")]
|
||||
public string RouteName { get; private set; } = string.Empty;
|
||||
|
||||
[DisplayName("Дата кормежки")]
|
||||
public DateTime TransportationDate { get; private set; }
|
||||
|
||||
[DisplayName("Кол-во топлива")]
|
||||
public int Amount { get; set; }
|
||||
|
||||
public static Transportation CreateTransportation(int id, int fuel_id, int route_id, int driver_id, int amount)
|
||||
{
|
||||
|
@ -35,11 +35,10 @@ public class ExcelBuilder
|
||||
public ExcelBuilder AddHeader(string header, int startIndex, int count)
|
||||
{
|
||||
CreateCell(startIndex, _rowIndex, header,
|
||||
StyleIndex.SimpleTextWithoutBorder);
|
||||
StyleIndex.BoldTextWithBorder);
|
||||
for (int i = startIndex + 1; i < startIndex + count; ++i)
|
||||
{
|
||||
CreateCell(i, _rowIndex, "",
|
||||
StyleIndex.SimpleTextWithoutBorder);
|
||||
CreateCell(i, _rowIndex, "", StyleIndex.SimpleTextWithoutBorder);
|
||||
}
|
||||
_mergeCells.Append(new MergeCell()
|
||||
{
|
||||
@ -54,7 +53,7 @@ public class ExcelBuilder
|
||||
public ExcelBuilder AddParagraph(string text, int columnIndex)
|
||||
{
|
||||
CreateCell(columnIndex, _rowIndex++, text,
|
||||
StyleIndex.SimpleTextWithoutBorder);
|
||||
StyleIndex.SimpleTextWithBorder);
|
||||
return this;
|
||||
}
|
||||
public ExcelBuilder AddTable(int[] columnsWidths, List<string[]> data)
|
||||
@ -83,7 +82,7 @@ public class ExcelBuilder
|
||||
for (var j = 0; j < data.First().Length; ++j)
|
||||
{
|
||||
CreateCell(j, _rowIndex, data.First()[j],
|
||||
StyleIndex.SimpleTextWithoutBorder);
|
||||
StyleIndex.BoldTextWithBorder);
|
||||
}
|
||||
_rowIndex++;
|
||||
for (var i = 1; i < data.Count - 1; ++i)
|
||||
@ -91,14 +90,14 @@ public class ExcelBuilder
|
||||
for (var j = 0; j < data[i].Length; ++j)
|
||||
{
|
||||
CreateCell(j, _rowIndex, data[i][j],
|
||||
StyleIndex.SimpleTextWithoutBorder);
|
||||
StyleIndex.SimpleTextWithBorder);
|
||||
}
|
||||
_rowIndex++;
|
||||
}
|
||||
for (var j = 0; j < data.Last().Length; ++j)
|
||||
{
|
||||
CreateCell(j, _rowIndex, data.Last()[j],
|
||||
StyleIndex.SimpleTextWithoutBorder);
|
||||
StyleIndex.BoldTextWithBorder);
|
||||
}
|
||||
_rowIndex++;
|
||||
return this;
|
||||
|
@ -7,6 +7,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Runtime.Intrinsics.X86;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -78,23 +79,46 @@ VALUES (@ReplenishmentId, @FuelId, @Amount)";
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<FuelReplenishment> ReadFuelReplenishment(DateTime? dateForm = null,
|
||||
DateTime? dateTo = null, int? fuelId = null, int? driverId = null, int? routeId = null)
|
||||
public IEnumerable<FuelReplenishment> ReadFuelReplenishment(DateTime? dateForm = null,
|
||||
DateTime? dateTo = null, int? fuelId = null, int? driverId = null, int? routeId = null)
|
||||
{
|
||||
_logger.LogInformation("Получение всех объектов");
|
||||
try
|
||||
{
|
||||
using var connection = new
|
||||
NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = @"SELECT fr.*, ffr.FuelId, ffr.Amount
|
||||
var querySelect = @"SELECT
|
||||
fr.*,
|
||||
CONCAT(d.Fname, ' ', d.Lname) as DriverName,
|
||||
ffr.FuelId,
|
||||
ffr.Amount,
|
||||
CONCAT(f.FuelName, ' ', f.Price) as FuelName
|
||||
FROM fuelreplenishment fr
|
||||
INNER JOIN fuel_fuelReplenishment ffr ON ffr.ReplenishmentId = fr.Id";
|
||||
var replenishments = connection.Query<TempFuelReplenishment>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(replenishments));
|
||||
return replenishments.GroupBy(x => x.Id, y => y,
|
||||
(key, value) => FuelReplenishment.CreateOpeartion(value.First(),
|
||||
value.Select(z => FuelFuelReplenishment.CreateElement(0, z.FuelId, z.Amount)))).ToList();
|
||||
LEFT JOIN driver d on d.Id = fr.DriverId
|
||||
INNER JOIN fuel_fuelreplenishment ffr ON ffr.ReplenishmentId = fr.Id
|
||||
LEFT JOIN fuel f on f.Id = ffr.FuelId";
|
||||
var replenishmentDict = new Dictionary<int, List<FuelFuelReplenishment>>();
|
||||
|
||||
var fuelReplenishment = connection.Query<FuelReplenishment, FuelFuelReplenishment, FuelReplenishment>(querySelect,
|
||||
(replenishment, fuelReplenishments) =>
|
||||
{
|
||||
if (!replenishmentDict.TryGetValue(replenishment.Id, out var ffr))
|
||||
{
|
||||
ffr = [];
|
||||
replenishmentDict.Add(replenishment.Id, ffr);
|
||||
}
|
||||
|
||||
ffr.Add(fuelReplenishments);
|
||||
return replenishment;
|
||||
}, splitOn: "FuelId", param: new { dateForm, dateTo, fuelId, driverId });
|
||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(fuelReplenishment));
|
||||
|
||||
return replenishmentDict.Select(x =>
|
||||
{
|
||||
var fr = fuelReplenishment.First(y => y.Id == x.Key);
|
||||
fr.SetFuelFuelReplenishments(x.Value);
|
||||
return fr;
|
||||
}).ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -51,7 +51,15 @@ VALUES (@DriverId, @RouteId, @FuelId, @Amount, @TransportationDate)";
|
||||
try
|
||||
{
|
||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||
var querySelect = "SELECT * FROM transportation";
|
||||
var querySelect = @"SELECT
|
||||
t.*,
|
||||
r.RouteName as RouteName,
|
||||
CONCAT(d.Fname, ' ', d.Lname) as DriverName,
|
||||
CONCAT(f.FuelName, ' ', f.Price) as FuelName
|
||||
FROM transportation t
|
||||
LEFT JOIN driver d ON d.Id = t.DriverId
|
||||
LEFT JOIN fuel f ON f.Id = t.FuelId
|
||||
LEFT JOIN route r ON r.Id = t.RouteId";
|
||||
var transportations = connection.Query<Transportation>(querySelect);
|
||||
_logger.LogDebug("Полученные объекты: {json}",
|
||||
JsonConvert.SerializeObject(transportations));
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user