添加项目文件。
This commit is contained in:
253
Atomx.Data/CacheServices/AttributeCacheService.cs
Normal file
253
Atomx.Data/CacheServices/AttributeCacheService.cs
Normal file
@@ -0,0 +1,253 @@
|
||||
//using Atomx.Common.Entities;
|
||||
|
||||
//namespace Atomx.Data.CacheServices
|
||||
//{
|
||||
// public partial interface ICacheService
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// 获取产品属性值缓存列表
|
||||
// /// </summary>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<List<ProductAttribute>> GetProductAttributes(List<ProductAttribute>? data = null);
|
||||
|
||||
// /// <summary>
|
||||
// /// 通过ID获取或更新缓存
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<ProductAttribute> GetProductAttributeById(long id, ProductAttribute? data = null);
|
||||
|
||||
// /// <summary>
|
||||
// /// 从缓存中删除数据
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <returns></returns>
|
||||
// Task RemoveProductAttribute(long id);
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取产品预设值
|
||||
// /// </summary>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<List<ProductAttributeOption>> GetProductAttributeOptions(long attributeId, List<ProductAttributeOption>? data = null);
|
||||
|
||||
// /// <summary>
|
||||
// /// 通过ID获取或更新缓存
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<ProductAttributeOption> GetProductAttributeOptionById(long attributeId, long id, ProductAttributeOption? data = null);
|
||||
|
||||
// /// <summary>
|
||||
// /// 从缓存中删除数据
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <returns></returns>
|
||||
// Task RemoveProductAttributeOption(long attributeId, long id);
|
||||
|
||||
// /// <summary>
|
||||
// /// 根据ID获取属性树结构
|
||||
// /// </summary>
|
||||
// /// <param name="attributeId"></param>
|
||||
// /// <param name="reload"></param>
|
||||
// /// <returns></returns>
|
||||
// Task<AttributeTreeModel> GetAttributeTree(long attributeId);
|
||||
|
||||
// }
|
||||
// public partial class CacheService : ICacheService
|
||||
// {
|
||||
// public async Task<List<ProductAttribute>> GetProductAttributes(List<ProductAttribute>? data = null)
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<List<ProductAttribute>>(CacheKeys.ProductAttributes);
|
||||
// if (data != null)
|
||||
// {
|
||||
// cacheData = data;
|
||||
// await SetCacheAsync(CacheKeys.ProductAttributes, cacheData);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (cacheData == null)
|
||||
// {
|
||||
// return new List<ProductAttribute>();
|
||||
// }
|
||||
// }
|
||||
|
||||
// return cacheData;
|
||||
// }
|
||||
|
||||
// public async Task<ProductAttribute> GetProductAttributeById(long id, ProductAttribute? data = null)
|
||||
// {
|
||||
// var cacheData = await GetProductAttributes();
|
||||
// if (data != null)
|
||||
// {
|
||||
// var attribute = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// if (attribute != null)
|
||||
// {
|
||||
// cacheData.Remove(attribute);
|
||||
// cacheData.Add(data);
|
||||
// await SetCacheAsync(CacheKeys.ProductAttributes, cacheData);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// cacheData.Add(data);
|
||||
// await SetCacheAsync(CacheKeys.ProductAttributes, cacheData);
|
||||
// }
|
||||
// return data;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// var attribute = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// if (attribute != null)
|
||||
// {
|
||||
// return attribute;
|
||||
// }
|
||||
// return new ProductAttribute();
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// public async Task RemoveProductAttribute(long id)
|
||||
// {
|
||||
// var cacheData = await GetProductAttributes();
|
||||
// if (cacheData != null)
|
||||
// {
|
||||
// var data = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// if (data != null)
|
||||
// {
|
||||
// cacheData.Remove(data);
|
||||
// await SetCacheAsync(CacheKeys.ProductAttributes, cacheData);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取产品预设值
|
||||
// /// </summary>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<List<ProductAttributeOption>> GetProductAttributeOptions(long attributeId, List<ProductAttributeOption>? data = null)
|
||||
// {
|
||||
// var cacheData = await GetCacheAsync<List<ProductAttributeOption>>($"{CacheKeys.ProductAttributeOptionsPrefix}{attributeId}");
|
||||
// if (data != null)
|
||||
// {
|
||||
// cacheData = data;
|
||||
// await SetCacheAsync($"{CacheKeys.ProductAttributeOptionsPrefix}{attributeId}", cacheData);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (cacheData == null)
|
||||
// {
|
||||
// return new List<ProductAttributeOption>();
|
||||
// }
|
||||
// }
|
||||
|
||||
// return cacheData;
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 通过ID获取或更新缓存
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <param name="data"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<ProductAttributeOption> GetProductAttributeOptionById(long attributeId, long id, ProductAttributeOption? data = null)
|
||||
// {
|
||||
// var cacheData = await GetProductAttributeOptions(attributeId);
|
||||
// if (data != null)
|
||||
// {
|
||||
// var attribute = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// if (attribute != null)
|
||||
// {
|
||||
// cacheData.Remove(attribute);
|
||||
// cacheData.Add(data);
|
||||
// await SetCacheAsync($"{CacheKeys.ProductAttributeOptionsPrefix}{attributeId}", cacheData);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// cacheData.Add(data);
|
||||
// await SetCacheAsync($"{CacheKeys.ProductAttributeOptionsPrefix}{attributeId}", cacheData);
|
||||
// }
|
||||
// return data;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// var attribute = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// if (attribute != null)
|
||||
// {
|
||||
// return attribute;
|
||||
// }
|
||||
// return new ProductAttributeOption();
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 从缓存中删除数据
|
||||
// /// </summary>
|
||||
// /// <param name="id"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task RemoveProductAttributeOption(long attributeId, long id)
|
||||
// {
|
||||
// var cacheData = await GetProductAttributeOptions(attributeId);
|
||||
// if (cacheData != null)
|
||||
// {
|
||||
// var data = cacheData.SingleOrDefault(p => p.Id == id);
|
||||
// if (data != null)
|
||||
// {
|
||||
// cacheData.Remove(data);
|
||||
// await SetCacheAsync($"{CacheKeys.ProductAttributeOptionsPrefix}{attributeId}", cacheData);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// 获取属性结构缓存
|
||||
// /// </summary>
|
||||
// /// <param name="attributeId"></param>
|
||||
// /// <returns></returns>
|
||||
// public async Task<AttributeTreeModel> GetAttributeTree(long attributeId)
|
||||
// {
|
||||
// var attribute = await GetProductAttributeById(attributeId);
|
||||
// var options = await GetProductAttributeOptions(attributeId);
|
||||
|
||||
// if (attribute.Id ==0)
|
||||
// {
|
||||
// attribute = _dbContext.ProductAttributes.SingleOrDefault(p => p.Id == attributeId);
|
||||
// if (attribute != null)
|
||||
// {
|
||||
// await GetProductAttributeById(attribute.Id, attribute);
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (attribute == null)
|
||||
// {
|
||||
// return new AttributeTreeModel();
|
||||
// }
|
||||
|
||||
// if (!options.Any())
|
||||
// {
|
||||
// options = _dbContext.ProductAttributeOptions.Where(p => p.AttributeId == attributeId).ToList();
|
||||
// if (options.Any())
|
||||
// {
|
||||
// await GetProductAttributeOptions(attribute.Id, options);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// var data = new AttributeTreeModel()
|
||||
// {
|
||||
// Id = attribute.Id,
|
||||
// Name = attribute.Name,
|
||||
// ProductTypeId = attribute.ProductTypeId,
|
||||
// PredefinedValues = options
|
||||
// };
|
||||
// return data;
|
||||
// }
|
||||
|
||||
// }
|
||||
//}
|
||||
Reference in New Issue
Block a user