This commit is contained in:
Adam 2025-10-05 01:43:43 +02:00
commit f084c3ab7f
15 changed files with 84 additions and 58 deletions

View File

@ -160,7 +160,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
{
_logger.Detail($"GetShippingDocumentById invoked; id: {id}");
return await ctx.ShippingDocuments.GetByIdAsync(id);
return await ctx.ShippingDocuments.GetByIdAsync(id, true);
}
[SignalR(SignalRTags.UpdateShippingDocument)]
@ -171,7 +171,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
_logger.Detail($"UpdateShippingDocument invoked; id: {shippingDocument.Id}");
await ctx.ShippingDocuments.UpdateAsync(shippingDocument);
return await ctx.ShippingDocuments.GetByIdAsync(shippingDocument.Id, shippingDocument.Shipping != null);
return await ctx.ShippingDocuments.GetByIdAsync(shippingDocument.Id, shippingDocument.Shipping != null || shippingDocument.Partner != null);
}
[SignalR(SignalRTags.GetMeasuringUsers)]

View File

@ -0,0 +1,14 @@
using FruitBank.Common.Entities;
using Mango.Nop.Core.Repositories;
using Nop.Core.Caching;
using Nop.Core.Configuration;
using Nop.Core.Events;
using Nop.Data;
using Nop.Services.Logging;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
public class FilesDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings, ILogger logger) : MgDbTableBase<Files>(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger)
{
}

View File

@ -25,27 +25,37 @@ using Mango.Nop.Core.Dtos;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>, IShippingDbSet<ShippingDbTable>, IShippingDocumentDbSet<ShippingDocumentDbTable>, IShippingItemDbSet<ShippingItemDbTable>, IShippingItemPalletDbSet<ShippingItemPalletDbTable>
public class FruitBankDbContext : MgDbContextBase,
IPartnerDbSet<PartnerDbTable>,
IShippingDbSet<ShippingDbTable>,
IShippingDocumentDbSet<ShippingDocumentDbTable>,
IShippingItemDbSet<ShippingItemDbTable>,
IShippingItemPalletDbSet<ShippingItemPalletDbTable>,
IShippingDocumentToFilesDbSet<ShippingDocumentToFilesDbTable>,
IFilesDbSet<FilesDbTable>
{
private readonly FruitBankAttributeService _fruitBankAttributeService;
private readonly IStoreContext _storeContext;
private readonly IProductService _productService;
private readonly IStaticCacheManager _staticCacheManager;
public PartnerDbTable Partners { get; set; }
public ShippingDbTable Shippings { get; set; }
public ShippingDocumentDbTable ShippingDocuments { get; set; }
public ShippingItemDbTable ShippingItems { get; set; }
public ShippingItemPalletDbTable ShippingItemPallets { get; set; }
public FilesDbTable Files { get; set; }
public ShippingDocumentToFilesDbTable ShippingDocumentToFiles { get; set; }
public IRepository<Product> Products { get; set; }
public IRepository<Customer> Customers { get; set; }
public IRepository<CustomerRole> CustomerRoles { get; set; }
public IRepository<CustomerCustomerRoleMapping> CustomerRoleMappings { get; set; }
public FruitBankDbContext(INopDataProvider dataProvider, ILockService lockService, FruitBankAttributeService fruitBankAttributeService, IStoreContext storeContext,
PartnerDbTable partnerDbTable, ShippingDbTable shippingDbTable, ShippingDocumentDbTable shippingDocumentDbTable, ShippingItemDbTable shippingItemDbTable, ShippingItemPalletDbTable shippingItemPalletDbTable,
PartnerDbTable partnerDbTable, ShippingDbTable shippingDbTable, ShippingDocumentDbTable shippingDocumentDbTable, ShippingItemDbTable shippingItemDbTable,
ShippingItemPalletDbTable shippingItemPalletDbTable, FilesDbTable filesDbTable, ShippingDocumentToFilesDbTable shippingDocumentToFilesDbTable,
IProductService productService, IStaticCacheManager staticCacheManager,
IRepository<Product> productRepository,
IRepository<Customer> customerRepository,
@ -58,11 +68,13 @@ public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>
_staticCacheManager = staticCacheManager;
_fruitBankAttributeService = fruitBankAttributeService;
Files = filesDbTable;
Partners = partnerDbTable;
Shippings = shippingDbTable;
ShippingDocuments = shippingDocumentDbTable;
ShippingItems = shippingItemDbTable;
ShippingItemPallets = shippingItemPalletDbTable;
ShippingDocumentToFiles = shippingDocumentToFilesDbTable;
Products = productRepository;
Customers = customerRepository;

View File

@ -0,0 +1,10 @@
using FruitBank.Common.Entities;
using Mango.Nop.Core.Interfaces;
using Nop.Data;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer.Interfaces;
public interface IFilesDbSet<TDbTable> : IMgDbTableBase where TDbTable : IRepository<Files>
{
public TDbTable Files { get; set; }
}

View File

@ -0,0 +1,10 @@
using FruitBank.Common.Entities;
using Mango.Nop.Core.Interfaces;
using Nop.Data;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer.Interfaces;
public interface IShippingDocumentToFilesDbSet<TDbTable> : IMgDbTableBase where TDbTable : IRepository<ShippingDocumentToFiles>
{
public TDbTable ShippingDocumentToFiles { get; set; }
}

View File

@ -25,56 +25,10 @@ public class PartnerDbTable : MgDbTableBase<Partner>
? GetAll()
.LoadWith(sd => sd.ShippingDocuments).ThenLoad(s => s.Shipping)
.LoadWith(sd => sd.ShippingDocuments).ThenLoad(si => si.ShippingItems).ThenLoad(sip => sip.ShippingItemPallets)
.LoadWith(sd => sd.ShippingDocuments).ThenLoad(sdtof => sdtof.ShippingDocumentToFiles).ThenLoad(f => f.ShippingDocumentFile)
: GetAll();
}
public Task<Partner> GetByIdAsync(int id, bool loadRelations)
=> GetAll(loadRelations).FirstOrDefaultAsync(p => p.Id == id);
//public IOrderedQueryable<AuctionBid> GetAllLastBidByAuctionId(int auctionId)
//{
// return GetAllByAuctionId(auctionId)
// .OrderByDescending(x => x.Id)
// .GroupBy(x => x.AuctionId, (_, bids) => bids.FirstOrDefault())
// .OrderByDescending(percentGroup => percentGroup.Id);
//}
//public IOrderedQueryable<AuctionBid> GetLastAuctionBidByProductToAuctionId(int productToAuctionId)
// => GetAllByProductToAuctionId(productToAuctionId).OrderByDescending(x => x.Id);
//public Task<int> GetBidsCountByProductToAuctionIdAsync(int productToAuctionId)
// => Table.CountAsync(x => x.ProductAuctionMappingId == productToAuctionId);
//public IQueryable<AuctionBid> GetAllByAuctionId(int auctionId)
// => Table.Where(x => x.AuctionId == auctionId);
//public IQueryable<AuctionBid> GetAllByProductToAuctionId(int productToAuctionId)
// => Table.Where(x => x.ProductAuctionMappingId == productToAuctionId);
//public Task<bool> HasBidByProductToAuctionIdAsync(int productToAuctionId)
//{
// return Table.AnyAsync(x => x.ProductAuctionMappingId == productToAuctionId);
//}
//public async Task<AuctionBid> RevertByProductToAuctionIdAsync(int productToAuctionId)
//{
// var lastBid = await GetLastAuctionBidByProductToAuctionId(productToAuctionId).FirstOrDefaultAsync();
// if (lastBid == null)
// {
// await Logger.InformationAsync($"AuctionBidDbTable.RevertByProductToAuctionIdAsync(); (lastBid == null); productToAuction.Id: {productToAuctionId}");
// return null;
// }
// await DeleteAsync(lastBid);
// return await GetLastAuctionBidByProductToAuctionId(productToAuctionId).FirstOrDefaultAsync();
//}
//public async Task<int> DeleteAllByProductToAuctionIdAsync(int productToAuctionId)
//{
// var deletedBids = await DeleteAsync(x => x.ProductAuctionMappingId == productToAuctionId);
// await Logger.InformationAsync($"AuctionBidDbTable.DeleteAllByProductToAuctionIdAsync(); productToAuction.Id: {productToAuctionId}; deletedBids: {deletedBids}");
// return deletedBids;
//}
}

View File

@ -24,6 +24,7 @@ public class ShippingDbTable : MgDbTableBase<Shipping>
return loadRelations
? GetAll()
.LoadWith(sd => sd.ShippingDocuments).ThenLoad(si => si.ShippingItems).ThenLoad(sip => sip.ShippingItemPallets)
.LoadWith(sd => sd.ShippingDocuments).ThenLoad(sdtof => sdtof.ShippingDocumentToFiles).ThenLoad(f => f.ShippingDocumentFile)
.LoadWith(sd => sd.ShippingDocuments).ThenLoad(p => p.Partner)
: GetAll();
}

View File

@ -23,9 +23,10 @@ public class ShippingDocumentDbTable : MgDbTableBase<ShippingDocument>
{
return loadRelations
? GetAll()
.LoadWith(s => s.Shipping)
.LoadWith(si => si.ShippingItems).ThenLoad(sip => sip.ShippingItemPallets)
.LoadWith(p => p.Partner)
.LoadWith(sd => sd.Shipping)
.LoadWith(sd => sd.ShippingItems).ThenLoad(sip => sip.ShippingItemPallets)
.LoadWith(sd => sd.ShippingDocumentToFiles).ThenLoad(sdtof => sdtof.ShippingDocumentFile)
.LoadWith(sd => sd.Partner)
: GetAll();
}

View File

@ -0,0 +1,14 @@
using FruitBank.Common.Entities;
using Nop.Services.Logging;
using Mango.Nop.Core.Repositories;
using Nop.Core.Caching;
using Nop.Core.Configuration;
using Nop.Core.Events;
using Nop.Data;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
public class ShippingDocumentToFilesDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings, ILogger logger) : MgDbTableBase<ShippingDocumentToFiles>(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger)
{
}

View File

@ -36,6 +36,7 @@ public class ShippingItemDbTable : MgDbTableBase<ShippingItem>
? GetAll()
.LoadWith(si => si.ShippingDocument).ThenLoad(s => s.Shipping)
.LoadWith(si => si.ShippingDocument).ThenLoad(p => p.Partner)
.LoadWith(si => si.ShippingDocument).ThenLoad(sd => sd.ShippingDocumentToFiles).ThenLoad(sdtof => sdtof.ShippingDocumentFile)
.LoadWith(si => si.ShippingItemPallets)
.LoadWith(si => si.Product)
: GetAll();

View File

@ -36,6 +36,7 @@ public class ShippingItemPalletDbTable : MgDbTableBase<ShippingItemPallet>
? GetAll()
.LoadWith(sip => sip.ShippingItem).ThenLoad(si => si.ShippingDocument).ThenLoad(sd => sd.Shipping)
.LoadWith(sip => sip.ShippingItem).ThenLoad(si => si.ShippingDocument).ThenLoad(p => p.Partner)
.LoadWith(sip => sip.ShippingItem).ThenLoad(si => si.ShippingDocument).ThenLoad(sd => sd.ShippingDocumentToFiles).ThenLoad(sdtof => sdtof.ShippingDocumentFile)
.LoadWith(sip => sip.ShippingItem).ThenLoad(si => si.Product)
: GetAll();
}

View File

@ -30,6 +30,9 @@ public class FruitBankEventConsumer(IHttpContextAccessor httpContextAccessor, Fr
.Where(si => si.ProductId == product.Id && !si.IsMeasured && si.IsMeasurable != isMeasurableProduct)
.ToListAsync();
foreach (var shippingItem in shippingItems)
shippingItem.IsMeasurable = isMeasurableProduct;
await ctx.ShippingItems.UpdateAsync(shippingItems, false);
await base.HandleEventAsync(eventMessage);
}

View File

@ -60,6 +60,9 @@ public class PluginNopStartup : INopStartup
services.AddScoped<ShippingDocumentDbTable>();
services.AddScoped<ShippingItemDbTable>();
services.AddScoped<ShippingItemPalletDbTable>();
services.AddScoped<FilesDbTable>();
services.AddScoped<ShippingDocumentToFilesDbTable>();
services.AddScoped<FruitBankDbContext>();
services.AddScoped<IFruitBankDataControllerServer, FruitBankDataController>();

View File

@ -11,11 +11,13 @@ public partial class NameCompatibility : INameCompatibility
/// </summary>
public Dictionary<Type, string> TableNames => new Dictionary<Type, string>
{
{ typeof(Files), FruitBankConstClient.FilesDbTableName},
{ typeof(Partner), FruitBankConstClient.PartnerDbTableName },
{ typeof(Shipping), FruitBankConstClient.ShippingDbTableName },
{ typeof(ShippingDocument), FruitBankConstClient.ShippingDocumentDbTableName },
{ typeof(ShippingItem), FruitBankConstClient.ShippingItemDbTableName},
{ typeof(ShippingItemPallet), FruitBankConstClient.ShippingItemPalletDbTableName},
{ typeof(ShippingDocumentToFiles), FruitBankConstClient.ShippingDocumentToFilesDbTableName},
};

View File

@ -74,7 +74,7 @@ public class FruitBankAttributeService(IGenericAttributeService genericAttribute
public async Task InsertOrUpdateMeasuringAttributeValuesAsync<TEntity>(IMeasuringAttributeValues measuringAttributeValues, bool cumulativeWeightUpdate, int storeId)
{
if (!measuringAttributeValues.HasMeasuringValues()) throw new Exception($"FruitBankAttributeService->InsertOrUpdateMeasuringAttributeValuesAsync; measuringAttributeValues.HasMeasuringValues() == false; keyGroup: {typeof(TEntity).Name} values: {measuringAttributeValues}");
if (!measuringAttributeValues.HasMeasuringValues()) throw new Exception($"FruitBankAttributeService->InsertOrUpdateMeasuringAttributeValuesAsync; measuringAttributeValues.HasMeasuringValues() == false; keyGroup: {typeof(TEntity).Name}; values: {measuringAttributeValues}");
var entityId = measuringAttributeValues.Id;
var measuringAttributes = await GetMeasuringAttributesAsync<TEntity>(entityId, storeId);
@ -91,7 +91,7 @@ public class FruitBankAttributeService(IGenericAttributeService genericAttribute
await UpdateMeasuringWeightAttributeValueAsync(measuringAttributes.Single(ma => ma.Key == NET_WEIGHT_KEY), measuringAttributeValues.NetWeight, cumulativeWeightUpdate);
await UpdateMeasuringWeightAttributeValueAsync(measuringAttributes.Single(ma => ma.Key == GROSS_WEIGHT_KEY), measuringAttributeValues.GrossWeight, cumulativeWeightUpdate);
await UpdateGenericAttributeAsync(measuringAttributes.Single(ma => ma.Key == IS_MEASURABLE_KEY), measuringAttributeValues.IsMeasurable);
//var netWeightAttribute = measuringAttributes?.SingleOrDefault(ma => ma.Key == NET_WEIGHT_KEY);
//if (netWeightAttribute != null) await UpdateMeasuringWeightAttributeValueAsync(netWeightAttribute, measuringAttributeValues.NetWeight, cumulativeWeightUpdate);
//else await InsertGenericAttributeAsync<TEntity, double>(entityId, NET_WEIGHT_KEY, measuringAttributeValues.NetWeight, storeId);