Add EkaerHistory SignalR endpoints and service injection
Added IFruitBankEkaerService to FruitBankDataController and introduced two new SignalR methods: GenerateEkaerXmlDocument (generates/updates EkaerHistory for a shipping document) and CreateEkaerHistory (idempotently creates or returns EkaerHistory for a given key and direction). Both methods include detailed logging and entity validation.
This commit is contained in:
parent
9cdd65eebd
commit
c8ecbc94a2
|
|
@ -13,6 +13,7 @@ using FruitBank.Common.Loggers;
|
|||
using FruitBank.Common.Models;
|
||||
using FruitBank.Common.Server;
|
||||
using FruitBank.Common.Server.Interfaces;
|
||||
using FruitBank.Common.Server.Services.Ekaer;
|
||||
using FruitBank.Common.SignalRs;
|
||||
using LinqToDB;
|
||||
using Mango.Nop.Core.Dtos;
|
||||
|
|
@ -40,6 +41,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
|||
ICustomerRegistrationService customerRegistrationService,
|
||||
ILocalizationService localizationService,
|
||||
PreOrderConversionService preorderConversionService,
|
||||
IFruitBankEkaerService fruitBankEkaerService,
|
||||
IEnumerable<IAcLogWriterBase> logWriters)
|
||||
: BasePluginController, IFruitBankDataControllerServer
|
||||
{
|
||||
|
|
@ -307,6 +309,55 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
|||
return await ctx.EkaerHistories.GetByIdAsync(ekaerHistory.Id);
|
||||
}
|
||||
|
||||
[SignalR(SignalRTags.GenerateEkaerXmlDocument)]
|
||||
public async Task<EkaerHistory> GenerateEkaerXmlDocument(int shippingDocumentId)
|
||||
{
|
||||
_logger.Detail($"GenerateEkaerXmlDocument invoked; shippingDocumentId: {shippingDocumentId}");
|
||||
|
||||
// A GetAll(true) a mapperhez kellő teljes gráfot tölti: Partner, Items+ProductDto, Shipping→járművek/fuvarozó.
|
||||
var shippingDocument = await ctx.ShippingDocuments.GetByIdAsync(shippingDocumentId, true)
|
||||
?? throw new ArgumentException($"ShippingDocument not found; id: {shippingDocumentId}", nameof(shippingDocumentId));
|
||||
|
||||
// Upsert: dokumentumonként EGY bejövő rekord (ForeignKey + IsOutgoing) — az újragenerálás nem duplikál.
|
||||
var ekaerHistory = await ctx.EkaerHistories.GetByForeignKey(shippingDocumentId).FirstOrDefaultAsync(eh => !eh.IsOutgoing);
|
||||
ekaerHistory = fruitBankEkaerService.GenerateEkaerXmlDocument(shippingDocument, ekaerHistory);
|
||||
|
||||
if (ekaerHistory.Id > 0) await ctx.EkaerHistories.UpdateAsync(ekaerHistory);
|
||||
else await ctx.EkaerHistories.InsertAsync(ekaerHistory);
|
||||
|
||||
return await ctx.EkaerHistories.GetByIdAsync(ekaerHistory.Id) ?? ekaerHistory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Idempotens rekord-létrehozás: ha a (foreignKey, isOutgoing) párra már van EkaerHistory, azt adja vissza
|
||||
/// érintetlenül; különben új Pending rekordot hoz létre. A generálás (XmlDoc) külön lépés: GenerateEkaerXmlDocument.
|
||||
/// </summary>
|
||||
[SignalR(SignalRTags.CreateEkaerHistory)]
|
||||
public async Task<EkaerHistory> CreateEkaerHistory(int foreignKey, bool isOutgoing)
|
||||
{
|
||||
_logger.Detail($"CreateEkaerHistory invoked; foreignKey: {foreignKey}; isOutgoing: {isOutgoing}");
|
||||
|
||||
var existing = await ctx.EkaerHistories.GetByForeignKey(foreignKey).FirstOrDefaultAsync(eh => eh.IsOutgoing == isOutgoing);
|
||||
if (existing != null) return existing;
|
||||
|
||||
// A forrás-entitás léte irányfüggő: bejövő → ShippingDocument, kimenő → Order.
|
||||
if (!isOutgoing)
|
||||
{
|
||||
_ = await ctx.ShippingDocuments.GetByIdAsync(foreignKey, false)
|
||||
?? throw new ArgumentException($"ShippingDocument not found; id: {foreignKey}", nameof(foreignKey));
|
||||
}
|
||||
else
|
||||
{
|
||||
_ = await ctx.OrderDtos.GetByIdAsync(foreignKey, false)
|
||||
?? throw new ArgumentException($"Order not found; id: {foreignKey}", nameof(foreignKey));
|
||||
}
|
||||
|
||||
var ekaerHistory = new EkaerHistory { ForeignKey = foreignKey, IsOutgoing = isOutgoing, Status = EkaerStatus.Pending };
|
||||
await ctx.EkaerHistories.InsertAsync(ekaerHistory);
|
||||
|
||||
return await ctx.EkaerHistories.GetByIdAsync(ekaerHistory.Id) ?? ekaerHistory;
|
||||
}
|
||||
|
||||
[SignalR(SignalRTags.GetShippings)]
|
||||
public async Task<List<Shipping>> GetShippings()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue