//using Atomx.Common.Entities; //using Microsoft.EntityFrameworkCore; //namespace Atomx.Data.CacheServices //{ // public partial interface ICacheService // { // /// // /// 获取每日热销产品数据 // /// // /// // /// // Task> GetDailyBestSells(bool? reload = false); // /// // /// 获取产品详情 // /// // /// // /// // /// // Task GetProductDetails(long id, bool reload = false); // /// // /// 获取营销产品 // /// // /// // /// // /// // Task GetMarketingProducts(long id, MarketingProductModel? data = null); // /// // /// 删除活动产品 // /// // /// // /// // Task RemoveMarketingProductByProductId(long marketingId, long productId); // /// // /// 删除指定营销活动产品缓存 // /// // /// // /// // Task RemoveMarketingProductByMarketingId(long marketingId); // /// // /// 获取营销产品 // /// // /// // Task> GetMarketingProducts(); // /// // /// 删除产品缓存 // /// // /// // /// // Task RemoveProduct(long id); // /// // /// 获取最新产品 // /// // /// // Task> GetNewProducts(bool? reload = false); // /// // /// 获取分类下的最新产品 // /// // /// // /// // Task> GetNewProductsByCategory(List categoryIds, bool? reload = false); // /// // /// 获取热销产品 // /// // /// // Task> GetHotProducts(bool? reload = false); // /// // /// 获取分类下热销产品 // /// // /// // /// // Task> GetHotProductsByCategory(List categoryIds, bool? reload = false); // /// // /// 获取首页推荐得精选产品 // /// // /// // /// // Task> GetIndexFeatured(bool? reload = false); // } // public partial class CacheService : ICacheService // { // /// // /// 获取每日热销产品数据 // /// // /// // /// // public async Task> GetDailyBestSells(bool? reload = false) // { // var key = $"{CacheKeys.DailyBestSellProductPrefix}{DateTime.UtcNow.Day}"; // var cacheData = await GetCacheAsync>(key); // var needReload = reload.HasValue ? reload.Value : false; // if (cacheData == null || needReload) // { // var query = from p in _dbContext.Products // where p.Status == (int)ProductStatus.Publish && p.StoreId == 0 // select p; // cacheData = query.OrderByDescending(p => EF.Functions.Random()).Take(100).ToList(); // await SetCacheAsync(key, cacheData); // } // return cacheData; // } // public async Task GetProductDetails(long id, bool reload = false) // { // if (id == 0) // { // return null; // } // var productData = await GetCacheAsync($"{CacheKeys.ProductPrefix}{id}"); // if (productData == null || reload) // { // productData = (from p in _dbContext.Products // where p.Id == id && p.Status == (int)ProductStatus.Publish // select new ProductDetailCachedModel // { // AllowExchange = p.AllowExchange, // AllowReturn = p.AllowReturn, // AvailableEndTime = p.AvailableEndTime, // AvailableStartTime = p.AvailableStartTime, // Body = p.Body, // CategoryId = p.CategoryId, // CategoryPath = p.CategoryPath, // CreateTime = p.CreateTime, // Deleted = p.Deleted, // Description = p.Description, // DisableCoupons = p.DisableCoupons, // DisplayOrder = p.DisplayOrder, // Feature = p.Feature, // IsFeatured = p.IsFeatured, // Id = p.Id, // Image = p.Image, // InHouse = p.InHouse, // IsWarehouse = p.IsWarehouse, // Localized = new(), // ManufacturerId = p.ManufacturerId, // MarketPrice = p.MarketPrice, // MetaDescription = p.MetaDescription, // MetaTitle = p.MetaTitle, // Photos = p.Photos, // PictureCount = p.PictureCount, // Price = p.Price, // ProductTypeId = p.ProductTypeId, // Remarks = p.Remarks, // ReviewStatus = p.ReviewStatus, // SaleAttribute = new(), // SalesQuantity = p.SalesQuantity, // ShippingId = p.ShippingId, // SingleShip = p.SingleShip, // Sku = p.Sku, // SKUCombinations = new(), // SkuPrices = p.SkuPrices, // Slug = p.Slug, // Specification = p.Specification, // Status = p.Status, // StockQuantity = p.StockQuantity, // StopSales = p.StopSales, // StoreId = p.StoreId, // Tags = p.Tags, // Title = p.Title, // UpdateTime = p.UpdateTime, // UserId = p.UserId, // VendorId = p.VendorId, // ViewsCount = p.ViewsCount, // WarehouseId = p.WarehouseId, // Weight = p.Weight, // FiveStars = p.FiveStars, // FourStars = p.FourStars, // IsBest = p.IsBest, // IsNew = p.IsNew, // OneStars = p.OneStars, // OrderMaximumQuantity = p.OrderMaximumQuantity, // OrderMinimumQuantity = p.OrderMinimumQuantity, // Ratings = p.Ratings, // ReviewsCount = p.ReviewsCount, // ShippingDays = p.ShippingDays, // ThreeStars = p.ThreeStars, // TwoStars = p.TwoStars // }).SingleOrDefault(); // if (productData == null) // { // return null; // } // var productSaleAttributes = (from p in _dbContext.ProductAttributeRelations // join sa in _dbContext.ProductAttributes on p.AttributeId equals sa.Id into table // from a in table.DefaultIfEmpty() // where p.ProductId == id && a.IsSpecification == false // orderby p.DisplayOrder descending // select new ProductSKUAttributeModel // { // AttributeId = p.AttributeId, // AttributeName = a.Name, // Items = new(), // ProductAttributeId = p.Id // }).ToList(); // if (productSaleAttributes.Any()) // { // var productAttributeIds = productSaleAttributes.Select(p => p.ProductAttributeId).ToList(); // var attributeValues = (from p in _dbContext.ProductAttributeValues // where productAttributeIds.Contains(p.ProductAttributeRelationId) // orderby p.DisplayOrder descending // select new ProductSKUAttributeValueModel // { // Id = p.OptionId, // Name = p.Name, // ProductAttributeId = p.ProductAttributeRelationId // } // ).ToList(); // foreach (var item in productSaleAttributes) // { // var values = attributeValues.Where(p => p.ProductAttributeId == item.ProductAttributeId).ToList(); // item.Items = values; // } // productData.SaleAttribute = productSaleAttributes; // var skuCombinations = _dbContext.ProductSKUCombinations.Where(p => p.ProductId == id).ToList(); // productData.SKUCombinations = skuCombinations; // } // await SetCacheAsync($"{CacheKeys.ProductPrefix}{id}", productData); // } // return productData; // } // /// // /// 获取营销产品 // /// // /// // /// // /// // public async Task GetMarketingProducts(long id, MarketingProductModel? data = null) // { // var cacheData = await GetMarketingProducts(); // if (data != null) // { // cacheData.RemoveAll(p => p.Id == id); // cacheData.Add(data); // await SetCacheAsync(CacheKeys.MarketingProduct, cacheData); // } // else // { // data = cacheData.SingleOrDefault(p => p.Id == id); // } // return data; // } // /// // /// 删除活动产品 // /// // /// // /// // public async Task RemoveMarketingProductByProductId(long marketingId, long productId) // { // var cacheData = await GetMarketingProducts(); // cacheData.RemoveAll(p => p.ProductId == productId && p.MarketingId == marketingId); // await SetCacheAsync(CacheKeys.MarketingProduct, cacheData); // } // /// // /// 删除指定营销活动产品缓存 // /// // /// // /// // public async Task RemoveMarketingProductByMarketingId(long marketingId) // { // var cacheData = await GetMarketingProducts(); // cacheData.RemoveAll(p => p.MarketingId == marketingId); // await SetCacheAsync(CacheKeys.MarketingProduct, cacheData); // } // /// // /// 获取营销产品 // /// // /// // public async Task> GetMarketingProducts() // { // var cacheData = await GetCacheAsync>(CacheKeys.MarketingProduct); // if (cacheData == null) // { // return new List(); // } // return cacheData; // } // public async Task RemoveProduct(long id) // { // var productData = await GetCacheAsync($"{CacheKeys.ProductPrefix}{id}"); // if (productData == null) // { // await Remove($"{CacheKeys.ProductPrefix}{id}"); // } // } // /// // /// 获取最新产品 // /// // /// // public async Task> GetNewProducts(bool? reload = false) // { // var cacheData = await GetCacheAsync>(CacheKeys.ProductNewList); // if (cacheData == null || reload.HasValue) // { // var data = _dbContext.Products.OrderByDescending(p => p.CreateTime).Take(100).ToList(); // cacheData = data; // await SetCacheAsync(CacheKeys.MarketingProduct, cacheData, 24); // } // return cacheData; // } // /// // /// 获取分类下的最新产品 // /// // /// // /// // public async Task> GetNewProductsByCategory(List categoryIds, bool? reload = false) // { // var key = string.Join(",", categoryIds.ToArray()).ToMD5(); // var cacheData = await GetCacheAsync>($"{CacheKeys.ProductNewListPrefix}.{key}"); // if (cacheData == null || reload.HasValue) // { // var data = _dbContext.Products.Where(p => categoryIds.Contains(p.CategoryId)).OrderByDescending(p => p.CreateTime).Take(100).ToList(); // cacheData = data; // await SetCacheAsync($"{CacheKeys.ProductNewListPrefix}.{key}", cacheData, 24); // } // return cacheData; // } // /// // /// 获取热销产品 // /// // /// // public async Task> GetHotProducts(bool? reload = false) // { // var cacheData = await GetCacheAsync>(CacheKeys.ProductHotList); // if (cacheData == null || reload.HasValue) // { // var data = _dbContext.Products.OrderByDescending(p => p.SalesQuantity).Take(100).ToList(); // cacheData = data; // await SetCacheAsync(CacheKeys.ProductHotList, cacheData, 24); // } // return cacheData; // } // /// // /// 获取分类下热销产品 // /// // /// // /// // public async Task> GetHotProductsByCategory(List categoryIds, bool? reload = false) // { // var key = string.Join(",", categoryIds.ToArray()).ToMD5(); // var cacheData = await GetCacheAsync>($"{CacheKeys.ProductHotListPrefix}.{key}"); // if (cacheData == null || reload.HasValue) // { // var data = _dbContext.Products.Where(p => categoryIds.Contains(p.CategoryId)).OrderByDescending(p => p.SalesQuantity).Take(100).ToList(); // cacheData = data; // await SetCacheAsync($"{CacheKeys.ProductNewListPrefix}.{key}", cacheData, 24); // } // return cacheData; // } // /// // /// 获取首页推荐得精选产品 // /// // /// // /// // public async Task> GetIndexFeatured(bool? reload = false) // { // var cacheData = await GetCacheAsync>(CacheKeys.ProductFeaturedList); // if (cacheData == null || reload.HasValue) // { // var data = _dbContext.Products.Where(p => p.IsFeatured).OrderByDescending(p => p.UpdateTime).Take(20).ToList(); // cacheData = data; // await SetCacheAsync(CacheKeys.ProductFeaturedList, cacheData, 24); // } // return cacheData; // } // } //}