troubles with names

This commit is contained in:
strwbrry1 2024-12-25 13:29:51 +04:00
parent 26787687f4
commit e10908f2ee
5 changed files with 33 additions and 5 deletions

View File

@ -63,5 +63,15 @@ namespace ProjectPublishing.Entities
OrderDate = DateTime.Now,
Description = tempOrderMaterials.Description ?? string.Empty };
}
public void SetOrderMaterials(IEnumerable<OrderMaterials> orderMaterials)
{
if (orderMaterials != null && orderMaterials.Any())
{
Materials = orderMaterials;
}
}
}
}

View File

@ -10,6 +10,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace ProjectPublishing.Repositories.Implementations
{
@ -89,8 +90,8 @@ WHERE Id=@id";
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
var querySelect = @"
SELECT o.*,
ma.MaterialId as MaterialsId,
ma.Amount as MaterialsAmount,
ma.MaterialId as MaterialsId,
CONCAT(c.LastName, ' ', c.FirstName) as CustomerName,
ph.Name as PrintingName
FROM PrintingOrder o
@ -98,11 +99,28 @@ LEFT JOIN OrderMaterials ma ON o.Id = ma.OrderId
LEFT JOIN Customer c ON o.CustomerId = c.Id
LEFT JOIN PrintingHouse ph ON o.PrintingId = ph.Id
"; // возможно сюда фикс
var printingOrders = connection.Query<TempOrderMaterials>(querySelect);
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(printingOrders));
//var printingOrders = connection.Query<TempOrderMaterials>(querySelect);
var ordersDict = new Dictionary<int, List<OrderMaterials>>();
var orders = connection.Query<Order, OrderMaterials, Order>(querySelect,
(order, orderMaterials) =>
{
if (!ordersDict.TryGetValue(order.Id, out var frr))
{
frr = [];
ordersDict.Add(order.Id,frr);
}
return printingOrders.GroupBy(x => x.Id, y => y, (key, value) =>
Order.CreateOrder(value.First(), value.Select(z => OrderMaterials.Create(0, z.MaterialsId, z.MaterialsAmount)))).ToList();
frr.Add(orderMaterials);
return order;
}, splitOn: "MaterialsId");
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(orders));
return ordersDict.Select(x =>
{
var o = orders.First(y => y.Id == x.Key);
o.SetOrderMaterials(x.Value);
return o;
}).ToArray();
}
catch (Exception ex)
{

BIN
Отчеты/otp-doc.docx Normal file

Binary file not shown.

BIN
Отчеты/otp-pdf.pdf Normal file

Binary file not shown.

BIN
Отчеты/otp-tab.xlsx Normal file

Binary file not shown.